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_csv2(gs_int32_t devicenum, gs_sp_t device, gs_int32_t mapcnt, gs_sp_t map[]);
37 gs_retval_t main_gdat(gs_int32_t devicenum, gs_sp_t device, gs_int32_t mapcnt, gs_sp_t map[]);
39 int main (int argc, char* argv[]) {
50 gs_int32_t tip1,tip2,tip3,tip4;
52 gs_sp_t instance_name;
58 gslog(LOG_EMERG,"Could not set process group id of rts");
63 gslog(LOG_EMERG,"Wrong arguments at startup");
67 /* allocate more than enough for each array */
68 if ((device=(gs_sp_t*)malloc(sizeof(gs_sp_t*) * argc))==0) {
69 gslog(LOG_EMERG,"malloc error");
72 if ((mappings=(gs_sp_t*)malloc(sizeof(gs_sp_t*) * argc))==0) {
73 gslog(LOG_EMERG,"malloc error");
76 if ((lmap=(gs_sp_t*)malloc(sizeof(gs_sp_t*) * argc))==0) {
77 gslog(LOG_EMERG,"malloc error");
81 /* parse the arguments */
83 if ((sscanf(argv[1],"%u.%u.%u.%u:%hu",&tip1,&tip2,&tip3,&tip4,&(gshub.port))!=5)) {
84 gslog(LOG_EMERG,"HUB IP NOT DEFINED");
87 gshub.ip=htonl(tip1<<24|tip2<<16|tip3<<8|tip4);
88 gshub.port=htons(gshub.port);
89 instance_name=strdup(argv[2]);
90 if (set_hub(gshub)!=0) {
91 gslog(LOG_EMERG,"Could not set hub");
94 if (set_instance_name(instance_name)!=0) {
95 gslog(LOG_EMERG,"Could not set instance name");
100 if (strncmp("-D",argv[x],2)==0) {
101 /* macro definition */
103 while((y<(strlen(argv[x])-1))&&(argv[x][y]!='=')) y++;
106 if (y<(strlen(argv[x])-1)) {
107 /* if that is not true the define is empty and
108 we ignore it otherwise we set the = to 0 to
109 make two strings out of it*/
111 mappings[mapcnt]=&(argv[x][2]);
115 /* device definition */
116 device[devcnt]=argv[x];
122 gslog(LOG_EMERG,"at least one device has to be specified");
127 /* now startup all the device dependend processes. */
129 for (x=0;x<devcnt;x++) {
130 if ((pid=fork())==-1) {
131 gslog(LOG_EMERG,"fork error");
136 gs_sp_t interfacetype;
137 /* wait for clearinghouse to finish startup */
139 for(y=0;y<mapcnt;y++) {
140 if (strcmp(device[x],&mappings[y][strlen(mappings[y])+1])==0) {
141 /* point to the second string */
142 lmap[lmapcnt]=mappings[y];
146 /* the devicename always matches */
147 lmap[lmapcnt]=device[x];
150 if ((interfacetype=get_iface_properties(device[x],(gs_sp_t)"interfacetype"))==0) {
151 gslog(LOG_EMERG,"Interface Type not configured but required");
155 if (strcmp(interfacetype,"CSV")==0) {
156 main_csv(x,device[x],lmapcnt,lmap);
158 if (strncmp(interfacetype,"GDAT",4)==0) {
159 main_gdat(x,device[x],lmapcnt,lmap);
161 gslog(LOG_ERR,"UNKNOWN InterfaceType\n");
166 /* should never return */
167 gslog(LOG_EMERG,"lfta init returned");
172 /* initalize host_lib */
174 gslog(LOG_INFO,"Init host lib in clearinghouse");
176 if (hostlib_init(CLEARINGHOUSE,0,DEFAULTDEV,0,0)<0) {
177 gslog(LOG_EMERG,"%s::error:could not initiate host lib for clearinghouse\n",
184 /* start processing messages should never return*/
185 if (fta_start_service(-1)<0) {
186 gslog(LOG_EMERG,"error in processing the msg queue");
189 gslog(LOG_EMERG,"%s::error:start service returned");