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