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 ------------------------------------------- */
26 #include <sys/types.h>
33 #include <sys/socket.h>
35 gs_retval_t main_csv(gs_int32_t devicenum, gs_sp_t device, gs_int32_t mapcnt, gs_sp_t map[]);
36 gs_retval_t main_gdat(gs_int32_t devicenum, gs_sp_t device, gs_int32_t mapcnt, gs_sp_t map[]);
37 gs_retval_t main_dproto(gs_int32_t devicenum, gs_sp_t device, gs_int32_t mapcnt, gs_sp_t map[]);
38 gs_retval_t main_kafka(gs_int32_t devicenum, gs_sp_t device, gs_int32_t mapcnt, gs_sp_t map[]);
40 int main (int argc, char* argv[]) {
51 gs_int32_t tip1,tip2,tip3,tip4;
53 gs_sp_t instance_name;
60 gslog(LOG_EMERG,"Could not set process group id of rts");
65 gslog(LOG_EMERG,"Wrong arguments at startup");
69 /* allocate more than enough for each array */
70 if ((device=(gs_sp_t*)malloc(sizeof(gs_sp_t*) * argc))==0) {
71 gslog(LOG_EMERG,"malloc error");
74 if ((mappings=(gs_sp_t*)malloc(sizeof(gs_sp_t*) * argc))==0) {
75 gslog(LOG_EMERG,"malloc error");
78 if ((lmap=(gs_sp_t*)malloc(sizeof(gs_sp_t*) * argc))==0) {
79 gslog(LOG_EMERG,"malloc error");
83 /* parse the arguments */
85 if ((sscanf(argv[1],"%u.%u.%u.%u:%hu",&tip1,&tip2,&tip3,&tip4,&(gshub.port))!=5)) {
86 gslog(LOG_EMERG,"HUB IP NOT DEFINED");
89 gshub.ip=htonl(tip1<<24|tip2<<16|tip3<<8|tip4);
90 gshub.port=htons(gshub.port);
91 instance_name=strdup(argv[2]);
92 if (set_hub(gshub)!=0) {
93 gslog(LOG_EMERG,"Could not set hub");
96 if (set_instance_name(instance_name)!=0) {
97 gslog(LOG_EMERG,"Could not set instance name");
101 for(x=3;x<argc;x++) {
102 if (strncmp("-D",argv[x],2)==0) {
103 /* macro definition */
105 while((y<(strlen(argv[x])-1))&&(argv[x][y]!='=')) y++;
108 if (y<(strlen(argv[x])-1)) {
109 /* if that is not true the define is empty and
110 we ignore it otherwise we set the = to 0 to
111 make two strings out of it*/
113 mappings[mapcnt]=&(argv[x][2]);
117 /* device definition */
118 device[devcnt]=argv[x];
124 gslog(LOG_EMERG,"at least one device has to be specified");
129 /* now startup all the device dependend processes. */
131 for (x=0;x<devcnt;x++) {
132 if ((pid=fork())==-1) {
133 gslog(LOG_EMERG,"fork error");
138 gs_sp_t interfacetype;
139 /* wait for clearinghouse to finish startup */
141 for(y=0;y<mapcnt;y++) {
142 if (strcmp(device[x],&mappings[y][strlen(mappings[y])+1])==0) {
143 /* point to the second string */
144 lmap[lmapcnt]=mappings[y];
148 /* the devicename always matches */
149 lmap[lmapcnt]=device[x];
152 if ((interfacetype=get_iface_properties(device[x],(gs_sp_t)"interfacetype"))==0) {
153 gslog(LOG_EMERG,"Interface Type not configured but required");
157 if ((kafka = get_iface_properties(device[x],(gs_sp_t)"kafka")) && !strcmp(kafka,"TRUE")) {
158 main_kafka(x,device[x],lmapcnt,lmap);
159 } else if (strcmp(interfacetype,"CSV")==0) {
160 main_csv(x,device[x],lmapcnt,lmap);
161 } else if (strncmp(interfacetype,"GDAT",4)==0) {
162 main_gdat(x,device[x],lmapcnt,lmap);
163 } else if (strncmp(interfacetype,"PROTO",5)==0) {
164 main_dproto(x,device[x],lmapcnt,lmap);
166 fprintf(stderr,"interface type %s not recognized\n",interfacetype);
167 gslog(LOG_ERR,"UNKNOWN InterfaceType\n");
171 /* should never return */
172 gslog(LOG_EMERG,"lfta init returned");
177 /* initalize host_lib */
179 gslog(LOG_INFO,"Init host lib in clearinghouse");
181 if (hostlib_init(CLEARINGHOUSE,0,DEFAULTDEV,0,0)<0) {
182 gslog(LOG_EMERG,"%s::error:could not initiate host lib for clearinghouse\n",
189 /* start processing messages should never return*/
190 if (fta_start_service(-1)<0) {
191 gslog(LOG_EMERG,"error in processing the msg queue");
194 gslog(LOG_EMERG,"%s::error:start service returned");