1 /* ------------------------------------------------
2 Copyright 2014 AT&T Intellectual Property
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ------------------------------------------- */
16 #include <lappregistries.h>
20 /* datastructure to keep track of streamids used by the lapp */
21 struct streamregistry {
27 struct streamregistry * sreg =0;
30 struct ringbuf ** rbr=0;
36 /* adds the remote streamid with its associated msgid and ringbuf
38 gs_retval_t streamregistry_add(FTAID ftaid,struct ringbuf * r)
42 if ((sreg = malloc(sizeof(struct streamregistry)*STARTSZ))==0) {
43 gslog(LOG_EMERG,"ERROR:Out of memory streanregistry\n");
46 memset(sreg,0,sizeof(struct streamregistry)*STARTSZ);
49 for(x=0;(x<lsreg)&&(sreg[x].used!=0);x++);
53 if ((sreg = realloc(sreg,lsreg*sizeof(struct streamregistry)))==0) {
54 gslog(LOG_EMERG,"ERROR:Out of memory streamregistry\n");
66 /* removes streamid from registry for specific msgid and ringbuf */
67 void streamregistry_remove(FTAID ftaid)
70 for(x=0;x<lsreg;x++) {
71 if ((sreg[x].ftaid.ip==ftaid.ip)
72 && (sreg[x].ftaid.port==ftaid.port)
73 && (sreg[x].ftaid.index==ftaid.index)
74 && (sreg[x].ftaid.streamid==ftaid.streamid)) {
83 /* the following two functions are used to cycle
84 through all ringbuffers
86 gs_retval_t streamregistry_getactiveringbuf_reset()
89 /* XXXOS this is not the most effective way of doing
90 this needs improvment. */
91 /* Build a list of all ringbufs make sure they
92 are unique since multiple entrys could share
95 if (rbr!=0) (free(rbr));
96 if ((rbr=malloc(sizeof(struct ringbuf *)*lsreg))==0) {
97 gslog(LOG_EMERG,"Can't allocate memory in ftaregistry\n");
100 memset(rbr,0,sizeof(struct ringbuf *)*lsreg);
102 for(x=0;x<lsreg;x++) {
104 for(y=0;(y<lrbr)&&(rbr[y]!=sreg[x].r);y++);
114 struct ringbuf * streamregistry_getactiveringbuf()
124 gs_retval_t streamregistry_getactiveftaid_reset()
127 /* XXXOS this is not the most effective way of doing
128 this needs improvment. */
129 /* Build a list of at least one ftaid per process
131 if (rms!=0) (free(rms));
132 if ((rms=malloc(sizeof(FTAID *)*lsreg))==0) {
133 gslog(LOG_EMERG,"Can't allocate memory in ftaregistry\n");
136 memset(rms,0,sizeof(gs_int32_t *)*lsreg);
138 for(x=0;x<lsreg;x++) {
141 &&(rms[y]->ip!=sreg[x].ftaid.ip)
142 &&(rms[y]->port!=sreg[x].ftaid.port);y++);
144 rms[y]=&(sreg[x].ftaid);
152 FTAID * streamregistry_getactiveftaid()