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[]);
38 gs_retval_t main_dproto(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;
59 gslog(LOG_EMERG,"Could not set process group id of rts");
64 gslog(LOG_EMERG,"Wrong arguments at startup");
68 /* allocate more than enough for each array */
69 if ((device=(gs_sp_t*)malloc(sizeof(gs_sp_t*) * argc))==0) {
70 gslog(LOG_EMERG,"malloc error");
73 if ((mappings=(gs_sp_t*)malloc(sizeof(gs_sp_t*) * argc))==0) {
74 gslog(LOG_EMERG,"malloc error");
77 if ((lmap=(gs_sp_t*)malloc(sizeof(gs_sp_t*) * argc))==0) {
78 gslog(LOG_EMERG,"malloc error");
82 /* parse the arguments */
84 if ((sscanf(argv[1],"%u.%u.%u.%u:%hu",&tip1,&tip2,&tip3,&tip4,&(gshub.port))!=5)) {
85 gslog(LOG_EMERG,"HUB IP NOT DEFINED");
88 gshub.ip=htonl(tip1<<24|tip2<<16|tip3<<8|tip4);
89 gshub.port=htons(gshub.port);
90 instance_name=strdup(argv[2]);
91 if (set_hub(gshub)!=0) {
92 gslog(LOG_EMERG,"Could not set hub");
95 if (set_instance_name(instance_name)!=0) {
96 gslog(LOG_EMERG,"Could not set instance name");
100 for(x=3;x<argc;x++) {
101 if (strncmp("-D",argv[x],2)==0) {
102 /* macro definition */
104 while((y<(strlen(argv[x])-1))&&(argv[x][y]!='=')) y++;
107 if (y<(strlen(argv[x])-1)) {
108 /* if that is not true the define is empty and
109 we ignore it otherwise we set the = to 0 to
110 make two strings out of it*/
112 mappings[mapcnt]=&(argv[x][2]);
116 /* device definition */
117 device[devcnt]=argv[x];
123 gslog(LOG_EMERG,"at least one device has to be specified");
128 /* now startup all the device dependend processes. */
130 for (x=0;x<devcnt;x++) {
131 if ((pid=fork())==-1) {
132 gslog(LOG_EMERG,"fork error");
137 gs_sp_t interfacetype;
138 /* wait for clearinghouse to finish startup */
140 for(y=0;y<mapcnt;y++) {
141 if (strcmp(device[x],&mappings[y][strlen(mappings[y])+1])==0) {
142 /* point to the second string */
143 lmap[lmapcnt]=mappings[y];
147 /* the devicename always matches */
148 lmap[lmapcnt]=device[x];
151 if ((interfacetype=get_iface_properties(device[x],(gs_sp_t)"interfacetype"))==0) {
152 gslog(LOG_EMERG,"Interface Type not configured but required");
156 if (strcmp(interfacetype,"CSV")==0) {
157 main_csv(x,device[x],lmapcnt,lmap);
159 if (strncmp(interfacetype,"GDAT",4)==0) {
160 main_gdat(x,device[x],lmapcnt,lmap);
162 if (strncmp(interfacetype,"PROTO",5)==0) {
163 main_dproto(x,device[x],lmapcnt,lmap);
165 fprintf(stderr,"interface type %s not recognized\n",interfacetype);
166 gslog(LOG_ERR,"UNKNOWN InterfaceType\n");
172 /* should never return */
173 gslog(LOG_EMERG,"lfta init returned");
178 /* initalize host_lib */
180 gslog(LOG_INFO,"Init host lib in clearinghouse");
182 if (hostlib_init(CLEARINGHOUSE,0,DEFAULTDEV,0,0)<0) {
183 gslog(LOG_EMERG,"%s::error:could not initiate host lib for clearinghouse\n",
190 /* start processing messages should never return*/
191 if (fta_start_service(-1)<0) {
192 gslog(LOG_EMERG,"error in processing the msg queue");
195 gslog(LOG_EMERG,"%s::error:start service returned");