int main(int argn, char* args[]) { ros::init(argn, args, "joint_state_to_peis"); peiskmt_initialize(&argn, args); JointStateToPeis _my_pub_; ROS_INFO("Main thread spinning..."); ros::spin(); return 0; }
int main(int argc,char **args) { if(argc > 1 && strcmp(args[1],"--help") == 0) printUsage(stderr,argc,args); /* Initialize everything */ peiskmt_initialize(&argc,args); while(1) { char c=fgetc(stdin); if(feof(stdin)) exit(0); printf("%c",c); } }
int main(int argn, char** args, char** env) { peiskmt_initialize(&argn, args, env); // PeisSubscriberHandle s = peiskmt_subscribe(1, "Simple.Publisher_tuple"); struct simple p; pthread_t id; pthread_create(&id, NULL, &valueThread, &p); printf("CALL\n"); //PeisCallbackHandle c; peiskmt_registerMetaTupleCallback(1, "simple", &p, &callback); int i = 20; while(i--) { sleep(1); } printf("NO CALL\n"); peiskmt_unregisterMetaTupleCallback(1, "simple"); i = 5; while(i--) { sleep(1); } printf("CALL AGAIN\n"); peiskmt_registerTupleCallback(1, "simple", &p, &callback); i = 20; while(i--) { sleep(1); } printf("NO CALL AGAIN\n"); // peiskmt_unsubscribe(s); pthread_join(id, NULL); return 0; }
int main(int argn, char* args[]) { ros::init(argn, args, "acquire_tabletop_server"); std::vector <std::string> peis_args; ros::removeROSArgs(argn, args, peis_args); std::vector <char*> peis_args_c_str; for(int i = 0; i < peis_args.size(); i++) { peis_args_c_str.push_back(new char[peis_args[i].size()+1]); strcpy(peis_args_c_str[i],peis_args[i].c_str()); } argn = peis_args.size(); args = peis_args_c_str.data(); for(int i = 0; i < argn; i++) { ROS_INFO("(%s)",args[i]); } peiskmt_initialize(&argn, args); acquire_tabletop::AcquireTabletopServer ATS; ros::MultiThreadedSpinner m_t_spinner(4); m_t_spinner.spin(); }
int main(int argc,char **args) { int i,j; int owner=-1; /* Default owner used when setting tuples */ int hold=0; /* If we should hold (stay alive) after settings tuples or quit */ int cited; /* True if we are currently processig a word within " mark's */ if(argc > 1 && strcmp(args[1],"--help") == 0) printUsage(stderr,argc,args); int myArgc=argc; char *myArgs[4096]; /* Initialize tuplespace */ peiskmt_initialize(&argc,args); sleep(3); /* Copy commandline args (translating leading -- to nothing) */ for(i=0;i<myArgc;i++) { if(strncmp(args[i],"--",2) == 0) myArgs[i]=strdup(args[i]+2); else myArgs[i]=strdup(args[i]); } /* Read all tuples from commandline */ for(i=1;i<myArgc;i++) { fflush(stdout); if(strcmp(myArgs[i],"load") == 0) { i++; FILE *fp; if(strcmp(myArgs[i],"-") == 0) fp = stdin; else fp = fopen(myArgs[i],"rb"); if(!fp) continue; i=i+1; int pos=i; while(!feof(fp)) { char c; char word[MAX_LEN]; c=fgetc(fp); if(feof(fp)) break; /* Remove all leading comments */ if(c == '#') do { c=fgetc(fp); } while(!feof(fp) && c != '\n'); /* Remove all leading whitespace */ else if(isspace(c)) { } else { /* Read a word */ if(c == '\"') { cited=1; c=fgetc(fp); } else cited=0; for(j=0;j<MAX_LEN && !feof(fp);) { if(feof(fp)) break; if(c == '\\') { /* Backquoted character - treat next character litteraly */ c=fgetc(fp); word[j++] = c; } else if(c == '\"') { /* It's a citation mark, might end a word */ if(cited) break; else { fprintf(stderr,"Error - bad word %s\"",word); exit(0); } } else if(isspace(c) && !cited) break; else word[j++]=c; c=fgetc(fp); } word[j++]=0; /* Add it to the current position of the arguments list */ myArgc++; for(j=pos+1;j<myArgc;j++) myArgs[j]=myArgs[j-1]; myArgs[pos]=strdup(word); pos++; } } i=i-1; } else if(strcmp(myArgs[i],"set") == 0) { char *key = myArgs[++i]; char *value = myArgs[++i]; if(owner == -1) peiskmt_setTuple(key,strlen(value)+1,value); else peiskmt_setRemoteTuple(owner,key,strlen(value)+1,value,"fake/mime",PEISK_ENCODING_ASCII); } else if(strcmp(myArgs[i],"owner") == 0) { errno=0; owner=strtol(myArgs[++i],NULL,10); if(errno) { fprintf(stderr,"Error - bad owner string '%s'\n",myArgs[i]); owner=-1; } } else if(strncmp(myArgs[i],"peis-",5) == 0) {} else if(strcmp(myArgs[i],"append") == 0) { char *key = myArgs[++i]; char *value = myArgs[++i]; PeisTuple abstract; peiskmt_initTuple(&abstract); peiskmt_setTupleName(&abstract,key); if(owner == -1) abstract.owner = peisk_peisid(); else abstract.owner = owner; /* TODO... should be MT!! */ abstract.creator = -1; abstract.ts_write[0] = -1; abstract.ts_write[1] = -1; abstract.ts_expire[0] = -1; abstract.ts_expire[1] = -1; abstract.ts_user[0] = -1; abstract.ts_user[1] = -1; peiskmt_appendTupleByAbstract(&abstract,strlen(value)+1,value); } else if(strcmp(myArgs[i],"hold") == 0) hold=1; else if(strcmp(myArgs[i],"dont-hold") == 0) hold=0; else if(strcmp(myArgs[i],"wait") == 0) { float f; int ti; char *time = myArgs[++i]; if(sscanf(time,"%f",&f) == 1) usleep((int)f*1000000); else if(sscanf(time,"%d",&ti) == 1) usleep(ti*1000000); } else { fprintf(stderr,"Error - unknown option '%s'\n",myArgs[i]); } } if(hold) while(peisk_isRunning) { usleep(100); } else sleep(3); peiskmt_shutdown(); }
int main(int argc,char **args) { char configfilename[MAXLENGTH]; char logfilename[MAXLENGTH]; FILE* logfile; int skipHeader = 0; char tuplename[MAXLENGTH]; int isRunning; int element_ready; PeisTuple* mytuple; int i; int ID, len; char* value; time_t now; struct tm ts; char date[MAXLENGTH]; float kernel_time; // handlers PeisSubscriberHandle subHandler[MAXKEYS]; PeisCallbackHandle callHandler[MAXKEYS]; // init isRunning isRunning = 1; // init the semaphore pthread_mutex_init(&tuple_processing, NULL); // init the tuple list initializeList(&tuples); // initial check for arguments memcpy(configfilename, CONFIGFILE, strlen(CONFIGFILE)+1); memcpy(logfilename, LOGFILE, strlen(CONFIGFILE)+1); for ( i = 0; i < argc; i++ ) { if (strcmp(args[i],"--help") == 0) { printUsage(stderr,argc,args); } if (strcmp(args[i],"--conf") == 0) { memcpy(configfilename, args[i+1], strlen(args[i+1])+1); } if (strcmp(args[i],"--log") == 0) { memcpy(logfilename, args[i+1], strlen(args[i+1])+1); } if (strcmp(args[i],"--skip") == 0) { skipHeader = 1; } } // instantiate & initialize the PEIS component peiskmt_initialize(&argc, args); // prepare the header of the log file // time: "ddd yyyy-mm-dd hh:mm:ss zzz" time(&now); ts = *localtime(&now); strftime(date, sizeof(date), "%a %Y-%m-%d %H:%M:%S %Z", &ts); kernel_time = peiskmt_gettimef(); // Printing the header for the log file if (skipHeader == 0) { if( !(logfile = fopen(logfilename, "w") ) ) { printf("Error opening the log file %s \n", logfilename); isRunning = 0; } ID = peiskmt_peisid(); PeisTuple* kernelTuple = peiskmt_getTuple(ID,"kernel.version",PEISK_KEEP_OLD|PEISK_NON_BLOCKING); fprintf(logfile, "; Kernel version %s\n", kernelTuple->data); fprintf(logfile, "; peislogger version 1.0\n"); fprintf(logfile, "; starting at %f kernel time, %s\n", kernel_time, date); fprintf(logfile, "%f\n", kernel_time); fprintf(logfile, "; structure of recorded data:\n"); fprintf(logfile, "; kernel_ts,write_ts,user_ts,expire_ts,owner,creator,keyDepth,keys,datalenght,data\n"); fclose(logfile); } // Reading the keys of the tuples to subscribe if (!readConfiguration(configfilename)) { printf("Problem reading from configuration file %s \n", configfilename); isRunning = 0; } // Subscribe to all the keys specified in the configuration file and attach a callback for( i = 0 ; i < keyscounter ; i++) { printf("Subscribing to tuple: \"%s\" ", keys[i]); printf("..."); subHandler[i] = peiskmt_subscribe(-1, keys[i]); callHandler[i] = peiskmt_registerTupleCallback(-1, keys[i], NULL, (void*)eventCallback); printf("DONE \n"); } while( isRunning && peiskmt_isRunning() ) { // get the tuple to write // not very elegant, but this way I can use the semaphores pthread_mutex_lock(&tuple_processing); element_ready = isNotEmpty(&tuples); pthread_mutex_unlock(&tuple_processing); if(element_ready) { pthread_mutex_lock(&tuple_processing); mytuple = getAndDeleteFirstElement(&tuples); pthread_mutex_unlock(&tuple_processing); peiskmt_printTuple(mytuple); printf("\n"); if ( !(logfile = fopen(logfilename, "a") ) ) { printf("Error appending to logfile file %s \n", logfilename); exit(0); } peiskmt_getTupleName(mytuple, tuplename, sizeof(tuplename)); fprintf(logfile, "%f %d.%d %d.%d %d.%d %d %d %d %d %d %s %d %s\n", peiskmt_gettimef(), mytuple->ts_write[0], mytuple->ts_write[1], mytuple->ts_user[0], mytuple->ts_user[1], mytuple->ts_expire[0], mytuple->ts_expire[1], mytuple->owner, mytuple->creator, mytuple->alloclen, mytuple->isNew, mytuple->keyDepth, tuplename, strlen(mytuple->data)+1, (char*)mytuple->data); fclose(logfile); } usleep(10000); } // unsubscribe for( i = 0 ; i < keyscounter ; i++) { peiskmt_unsubscribe(subHandler[i]); peiskmt_unregisterTupleCallback(callHandler[i]); } // free the memory of both the queue and the variables peiskmt_freeTuple(mytuple); emptyQueue(&tuples); pthread_mutex_destroy(&tuple_processing); peiskmt_shutdown(); }