示例#1
0
int main(int argc, char *argv[]) {
    if(argc < 2) {
        printf("Usage: %s <name>\n", argv[0]);
        return -1;
    }
    /*copy the id to the global variable so that it could be used later in the handler*/
    strncpy(id, argv[1], 20); 
    /* connect to IPC server */
    IPC_connect(id);
    /*Check if the following message format is already defined in central*/
    IPC_defineFormat(MESSAGE_NAME_DRIVE_ARC_COMMAND, MESSAGE_FMT_1); 
    /*Define the message*/
    IPC_defineMsg(MESSAGE_NAME_DRIVE_ARC_COMMAND, IPC_VARIABLE_LENGTH, MESSAGE_FMT_1);
    IPC_defineFormat(MESSAGE_NAME_DRIVE_ARC_RESPONSE, MESSAGE_FMT_2); 
    /*Define the message*/
    IPC_defineMsg(MESSAGE_NAME_DRIVE_ARC_RESPONSE, IPC_VARIABLE_LENGTH, MESSAGE_FMT_2);
    /*Register the function that will get invoked when this message is published by someone */ 
    IPC_subscribe(MESSAGE_NAME_DRIVE_ARC_COMMAND, msgHandler, id);
    /*IPC wait and spin*/
    IPC_dispatch();
    return 0;
}
示例#2
0
JNIEXPORT jint JNICALL
Java_ipc_java_IPC_IPC_1defineFormat (JNIEnv *env, jclass theClass, 
			    jstring formatName, jstring formatString)
{
  const char *cformatName, *cformatString;
  int retVal;

  cformatName = (*env)->GetStringUTFChars(env, formatName, 0);
  cformatString = (*env)->GetStringUTFChars(env, formatString, 0);
  retVal = IPC_defineFormat(cformatName, cformatString);
  (*env)->ReleaseStringUTFChars(env, formatName, cformatName);
  (*env)->ReleaseStringUTFChars(env, formatString, cformatString);

  return (jint)retVal;
}