Added quantiling UDAFs
[com/gs-lite.git] / src / lib / gscphost / lappregistries.c
index 0ef78bd..f81b108 100644 (file)
-/* ------------------------------------------------
- Copyright 2014 AT&T Intellectual Property
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- ------------------------------------------- */
-
-#include <lappregistries.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-/* datastructure to keep track of streamids used by the lapp */
-struct streamregistry {
-    gs_int32_t used;
-    FTAID ftaid;
-    struct ringbuf * r;
-};
-
-struct streamregistry * sreg =0;
-gs_int32_t lsreg=0;
-
-struct ringbuf ** rbr=0;
-gs_int32_t lrbr=0;
-
-FTAID ** rms=0;
-gs_int32_t lrms=0;
-
-/* adds the remote streamid with its associated msgid and ringbuf
- */
-gs_retval_t streamregistry_add(FTAID ftaid,struct ringbuf * r)
-{
-    gs_int32_t x;
-    if (lsreg == 0) {
-        if ((sreg = malloc(sizeof(struct streamregistry)*STARTSZ))==0) {
-            gslog(LOG_EMERG,"ERROR:Out of memory streanregistry\n");
-            return -1;
-        }
-        memset(sreg,0,sizeof(struct streamregistry)*STARTSZ);
-        lsreg = STARTSZ;
-    }
-    for(x=0;(x<lsreg)&&(sreg[x].used!=0);x++);
-    if (x == lsreg) {
-        gs_int32_t y;
-        lsreg = 2*lsreg;
-        if ((sreg = realloc(sreg,lsreg*sizeof(struct streamregistry)))==0) {
-            gslog(LOG_EMERG,"ERROR:Out of memory streamregistry\n");
-            return -1;
-        }
-        for (y=x;y<lsreg;y++)
-            sreg[y].used=0;
-    }
-    sreg[x].ftaid=ftaid;
-    sreg[x].r=r;
-    sreg[x].used=1;
-    return 0;
-}
-
-/* removes streamid from registry for specific msgid and ringbuf */
-void streamregistry_remove(FTAID ftaid)
-{
-    gs_int32_t x;
-    for(x=0;x<lsreg;x++) {
-        if ((sreg[x].ftaid.ip==ftaid.ip)
-            && (sreg[x].ftaid.port==ftaid.port)
-            && (sreg[x].ftaid.index==ftaid.index)
-            && (sreg[x].ftaid.streamid==ftaid.streamid)) {
-            sreg[x].used=0;
-        }
-    }
-    return;
-}
-
-
-
-/* the following two functions are used to cycle
- through all ringbuffers
- */
-gs_retval_t streamregistry_getactiveringbuf_reset()
-{
-    gs_int32_t x,y;
-    /* XXXOS this is not the most effective way of doing
-     this needs improvment. */
-    /* Build a list of all ringbufs make sure they
-     are unique since multiple entrys could share
-     a ringbuf
-     */
-    if (rbr!=0) (free(rbr));
-    if ((rbr=malloc(sizeof(struct ringbuf *)*lsreg))==0) {
-        gslog(LOG_EMERG,"Can't allocate memory in ftaregistry\n");
-        return -1;
-    }
-    memset(rbr,0,sizeof(struct ringbuf *)*lsreg);
-    lrbr=0;
-    for(x=0;x<lsreg;x++) {
-        if (sreg[x].used) {
-            for(y=0;(y<lrbr)&&(rbr[y]!=sreg[x].r);y++);
-            if (y>=lrbr) {
-                rbr[y]=sreg[x].r;
-                lrbr++;
-            }
-        }
-    }
-    return 0;
-}
-
-struct ringbuf * streamregistry_getactiveringbuf()
-{
-    if (lrbr>0) {
-        lrbr --;
-        return rbr[lrbr];
-    }
-    return 0;
-}
-
-
-gs_retval_t streamregistry_getactiveftaid_reset()
-{
-    gs_int32_t x,y;
-    /* XXXOS this is not the most effective way of doing
-     this needs improvment. */
-    /* Build a list of at least one ftaid per process
-     */
-    if (rms!=0) (free(rms));
-    if ((rms=malloc(sizeof(FTAID *)*lsreg))==0) {
-        gslog(LOG_EMERG,"Can't allocate memory in ftaregistry\n");
-        return -1;
-    }
-    memset(rms,0,sizeof(gs_int32_t *)*lsreg);
-    lrms=0;
-    for(x=0;x<lsreg;x++) {
-        if (sreg[x].used) {
-            for(y=0;(y<lrms)
-                &&(rms[y]->ip!=sreg[x].ftaid.ip)
-                &&(rms[y]->port!=sreg[x].ftaid.port);y++);
-            if (y>=lrms) {
-                rms[y]=&(sreg[x].ftaid);
-                lrms++;
-            }
-        }
-    }
-    return 0;
-}
-
-FTAID * streamregistry_getactiveftaid()
-{
-    if (lrms>0) {
-        lrms --;
-        return rms[lrms];
-    }
-    return 0;    
-}
+/* ------------------------------------------------\r
+ Copyright 2014 AT&T Intellectual Property\r
+ Licensed under the Apache License, Version 2.0 (the "License");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+ ------------------------------------------- */\r
+\r
+#include <lappregistries.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+\r
+/* datastructure to keep track of streamids used by the lapp */\r
+struct streamregistry {\r
+    gs_int32_t used;\r
+    FTAID ftaid;\r
+    struct ringbuf * r;\r
+};\r
+\r
+struct streamregistry * sreg =0;\r
+gs_int32_t lsreg=0;\r
+\r
+struct ringbuf ** rbr=0;\r
+gs_int32_t lrbr=0;\r
+\r
+FTAID ** rms=0;\r
+gs_int32_t lrms=0;\r
+\r
+/* adds the remote streamid with its associated msgid and ringbuf\r
+ */\r
+gs_retval_t streamregistry_add(FTAID ftaid,struct ringbuf * r)\r
+{\r
+    gs_int32_t x;\r
+    if (lsreg == 0) {\r
+        if ((sreg = malloc(sizeof(struct streamregistry)*STARTSZ))==0) {\r
+            gslog(LOG_EMERG,"ERROR:Out of memory streanregistry\n");\r
+            return -1;\r
+        }\r
+        memset(sreg,0,sizeof(struct streamregistry)*STARTSZ);\r
+        lsreg = STARTSZ;\r
+    }\r
+    for(x=0;(x<lsreg)&&(sreg[x].used!=0);x++);\r
+    if (x == lsreg) {\r
+        gs_int32_t y;\r
+        lsreg = 2*lsreg;\r
+        if ((sreg = realloc(sreg,lsreg*sizeof(struct streamregistry)))==0) {\r
+            gslog(LOG_EMERG,"ERROR:Out of memory streamregistry\n");\r
+            return -1;\r
+        }\r
+        for (y=x;y<lsreg;y++)\r
+            sreg[y].used=0;\r
+    }\r
+    sreg[x].ftaid=ftaid;\r
+    sreg[x].r=r;\r
+    sreg[x].used=1;\r
+    return 0;\r
+}\r
+\r
+/* removes streamid from registry for specific msgid and ringbuf */\r
+void streamregistry_remove(FTAID ftaid)\r
+{\r
+    gs_int32_t x;\r
+    for(x=0;x<lsreg;x++) {\r
+        if ((sreg[x].ftaid.ip==ftaid.ip)\r
+            && (sreg[x].ftaid.port==ftaid.port)\r
+            && (sreg[x].ftaid.index==ftaid.index)\r
+            && (sreg[x].ftaid.streamid==ftaid.streamid)) {\r
+            sreg[x].used=0;\r
+        }\r
+    }\r
+    return;\r
+}\r
+\r
+\r
+\r
+/* the following two functions are used to cycle\r
+ through all ringbuffers\r
+ */\r
+gs_retval_t streamregistry_getactiveringbuf_reset()\r
+{\r
+    gs_int32_t x,y;\r
+    /* XXXOS this is not the most effective way of doing\r
+     this needs improvment. */\r
+    /* Build a list of all ringbufs make sure they\r
+     are unique since multiple entrys could share\r
+     a ringbuf\r
+     */\r
+    if (rbr!=0) (free(rbr));\r
+    if ((rbr=malloc(sizeof(struct ringbuf *)*lsreg))==0) {\r
+        gslog(LOG_EMERG,"Can't allocate memory in ftaregistry\n");\r
+        return -1;\r
+    }\r
+    memset(rbr,0,sizeof(struct ringbuf *)*lsreg);\r
+    lrbr=0;\r
+    for(x=0;x<lsreg;x++) {\r
+        if (sreg[x].used) {\r
+            for(y=0;(y<lrbr)&&(rbr[y]!=sreg[x].r);y++);\r
+            if (y>=lrbr) {\r
+                rbr[y]=sreg[x].r;\r
+                lrbr++;\r
+            }\r
+        }\r
+    }\r
+    return 0;\r
+}\r
+\r
+struct ringbuf * streamregistry_getactiveringbuf()\r
+{\r
+    if (lrbr>0) {\r
+        lrbr --;\r
+        return rbr[lrbr];\r
+    }\r
+    return 0;\r
+}\r
+\r
+\r
+gs_retval_t streamregistry_getactiveftaid_reset()\r
+{\r
+    gs_int32_t x,y;\r
+    /* XXXOS this is not the most effective way of doing\r
+     this needs improvment. */\r
+    /* Build a list of at least one ftaid per process\r
+     */\r
+    if (rms!=0) (free(rms));\r
+    if ((rms=malloc(sizeof(FTAID *)*lsreg))==0) {\r
+        gslog(LOG_EMERG,"Can't allocate memory in ftaregistry\n");\r
+        return -1;\r
+    }\r
+    memset(rms,0,sizeof(gs_int32_t *)*lsreg);\r
+    lrms=0;\r
+    for(x=0;x<lsreg;x++) {\r
+        if (sreg[x].used) {\r
+            for(y=0;(y<lrms)\r
+                &&(rms[y]->ip!=sreg[x].ftaid.ip)\r
+                &&(rms[y]->port!=sreg[x].ftaid.port);y++);\r
+            if (y>=lrms) {\r
+                rms[y]=&(sreg[x].ftaid);\r
+                lrms++;\r
+            }\r
+        }\r
+    }\r
+    return 0;\r
+}\r
+\r
+FTAID * streamregistry_getactiveftaid()\r
+{\r
+    if (lrms>0) {\r
+        lrms --;\r
+        return rms[lrms];\r
+    }\r
+    return 0;    \r
+}\r