control_ret_t control_init_xscope(const char *host_str, const char *port_str)
{
  if (xscope_ep_set_print_cb(xscope_print) != XSCOPE_EP_SUCCESS) {
    fprintf(stderr, "xscope_ep_set_print_cb failed\n");
    return CONTROL_ERROR;
  }

  if (xscope_ep_set_register_cb(register_callback) != XSCOPE_EP_SUCCESS) {
    fprintf(stderr, "xscope_ep_set_register_cb failed\n");
    return CONTROL_ERROR;
  }

  if (xscope_ep_set_record_cb(record_callback) != XSCOPE_EP_SUCCESS) {
    fprintf(stderr, "xscope_ep_set_record_cb failed\n");
    return CONTROL_ERROR;
  }

  if (xscope_ep_connect(host_str, port_str) != XSCOPE_EP_SUCCESS) {
    return CONTROL_ERROR;
  }

  DBG(printf("connected to server at port %s\n", port_str));

  // wait for xSCOPE probe registration
  while (probe_id == -1) {
    pause_short();
  }

  return CONTROL_SUCCESS;
}
JNIEXPORT jint JNICALL Java_com_synapticon_somanetconnect_XscopeSocket_initializeSocket
  (JNIEnv *env, jobject obj, jstring address, jstring port) {
	// IMPORTANT: Initialize (global) class object
	classObject = (*env)->NewGlobalRef(env, obj);

	// Initialize the socket connection itself
	return xscope_ep_connect((*env)->GetStringUTFChars(env, address, 0), (*env)->GetStringUTFChars(env, port, 0));
}