int main (void) { IPC_initialize(); checkIt(NULL, NULL); checkIt("", ""); checkIt(NULL, ""); checkIt(INT_FORMAT, INT_FORMAT); checkIt(STRING_FORMAT, STRING_FORMAT); checkIt(SAMPLE_FORMAT, SAMPLE_FORMAT); checkIt(MATRIX_LIST_FORMAT, MATRIX_LIST_FORMAT); checkIt(MATRIX_FORMAT, MATRIX_FORMAT); checkIt(PTR1_FORMAT, PTR1_FORMAT); checkIt(T1_FORMAT, T1_FORMAT); checkIt(T2_FORMAT, T2_FORMAT); fprintf(stderr, "\n"); checkIt(INT_FORMAT, STRING_FORMAT); checkIt(INT_FORMAT, SAMPLE_FORMAT); checkIt(SAMPLE_FORMAT, MATRIX_LIST_FORMAT); checkIt(SAMPLE_FORMAT, MATRIX_FORMAT); checkIt(PTR1_FORMAT, PTR2_FORMAT); checkIt(T1_FORMAT, T1A_FORMAT); checkIt(T1_FORMAT, T1B_FORMAT); checkIt(T2_FORMAT, T2A_FORMAT); checkIt(T2_FORMAT, T2B_FORMAT); return 0; }
/* TNgo, 5/22/97, added another variable to this function so that it can be called by IPC_connectModule */ IPC_RETURN_TYPE _IPC_connect (const char *taskName, const char *serverName, BOOLEAN willListen) { const char *serverHost; char *colon = NULL; int i, serverPort; struct timeval wait; /* Added by Bob Goode/Tam Ngo, 5/21/97, for WINSOCK option. */ #ifdef OS2 sock_init(); #elif defined(_WINSOCK_) startWinsock(); #endif /* Winsock DLL loading */ if (ipcVerbosity > IPC_Silent) { printf("NMP IPC Version %d.%d.%d (%s)\n", IPC_VERSION_MAJOR, IPC_VERSION_MINOR, IPC_VERSION_MICRO, IPC_VERSION_DATE); } /* Modified by TNgo, 5/22/97 */ serverHost = ((serverName != NULL && strlen(serverName) > 0) ? serverName : x_ipcServerMachine()); for (i=0; i<MAX_RECONNECT_TRIES; i++) { if (i > 0 && ipcVerbosity > IPC_Silent) printf(" Trying again %s to connect with the central server on %s\n", taskName, serverHost); IPC_initialize(); x_ipcWillListen(willListen); x_ipcConnectModule(taskName, serverHost); if (X_IPC_CONNECTED()) { x_ipcWaitUntilReady(); if (ipcVerbosity > IPC_Silent) { colon = (serverHost ? (char *)index((char *)serverHost, ':') : NULL); serverPort = (colon == NULL ? SERVER_PORT : atoi(colon+1)); X_IPC_MOD_WARNING1("... IPC Connected on port %d\n", serverPort); } return IPC_OK; } else { /* Need to do this, rather than sleep, because of SIGALRM's */ wait.tv_sec = RECONNECT_WAIT; wait.tv_usec = 0; select(0, 0, 0, 0, &wait); } } /* At this point, we've been unable to connect */ RETURN_ERROR(IPC_Not_Connected); }
int main (int argc, char **argv) #endif { #ifndef VXWORKS int numTrials; char *formatString; #endif int i; FORMATTER_PTR format; char data[MAX_DATA_SIZE]; /* No error checking if the format is too big */ void *dataPtr; IPC_VARCONTENT_TYPE vc; bzero(data, MAX_DATA_SIZE); #ifndef VXWORKS if (argc == 1) { fprintf(stderr, "Usage %s: <format_string> [num_trials]\n", argv[0]); exit(-1); } formatString = argv[1]; numTrials = (argc > 2 ? atoi(argv[2]) : DEFAULT_TRIALS); #endif IPC_initialize(); format = IPC_parseFormat(formatString); if (!format) { fprintf(stderr, "Illegal format string: %s\n", formatString); exit(-1); } /* Marshall tests */ printf("Marshalling trial with %s\n", formatString); printf(" Struct Size: %d, Buffer Size: %d (%s size)\n", x_ipc_dataStructureSize(format), (formatContainsPointers(format) ? -1 : x_ipc_bufferSize(format, NULL)), (x_ipc_sameFixedSizeDataBuffer(format) ? "fixed" : "variable")); TIME_TRIAL({ IPC_marshall(format, &data, &vc); IPC_freeByteArray(vc.content);})
/** * Start up IPC. TODO: status messages * * @param char *module_name displayed by Central when messages received/sent * @param char *host_name of valid host running Central to connect to * * @return int 0 on successful connect */ int init_ipc(char* module_name, char* host_name) { if(host_name == NULL) { if( IPC_connect(module_name) != IPC_OK ) { // print Unable to connect to central. return(-1); } } else { if(IPC_connectModule(module_name, host_name) != IPC_OK) { // print Unable to connect to central. return(-1); } } //sprintf(buffer,"Connected to IPC as module %s", module_name); printf("%s IPC connect to %s success\n",module_name,host_name); IPC_initialize(); define_command_ipc_types(); return(0); }// end init_ipc
int initIPC(char * moduleName, char * server, GCM_Common_RobotState *curState) { GCM_Module_IPC_Data mid; // gethostname(central,255); if(IPC_connectModule(moduleName,server)!=IPC_OK){ printf("Unable to connect to IPC server on %s! D'oh. Make sure central has been started on the IPC host.\n",server); return(-1); } printf("Connected to IPC server on %s as %s\n", server, moduleName); IPC_initialize(); GCM_defineCommonIPCTypes(); mid.threadID=getpid(); strcpy(mid.moduleName,moduleName); IPC_publishData(GCM_COMMON_STARTUP,&mid); // IPC_subscribeData( GCM_COMMON_ROBOTSTATE, robotStateHandler, curState ); return 0; }
JNIEXPORT jint JNICALL Java_ipc_java_IPC_IPC_1initialize (JNIEnv *env, jclass theClass) { return (jint)IPC_initialize(); }