vrpn_Tracker_JsonNet::vrpn_Tracker_JsonNet(const char* name,vrpn_Connection* c,int udp_port) :
	vrpn_Tracker(name, c),
	vrpn_Button(name, c),
	vrpn_Analog(name, c),
	_socket(INVALID_SOCKET),
	_pJsonReader(0)
{
	fprintf(stderr, "vrpn_Tracker_JsonNet : Device %s listen on port udp port %d\n", name, udp_port);
	if (! _network_init(udp_port)) {
		exit(EXIT_FAILURE);
	}

	// Buttons part

	num_buttons = vrpn_BUTTON_MAX_BUTTONS;
	num_channel = vrpn_CHANNEL_MAX;

	_pJsonReader = new Json::Reader();
}
Exemple #2
0
/* allocate a new connection context.  this keeps track of the working state
 * between the transport and network layers for a particular connection.  the
 * context is subsequently freed on the network layer's exit.
 */
static mysock_context_t *_mysock_allocate_context(void)
{
    mysock_context_t *ctx = 0;

    ctx = (mysock_context_t *) calloc(1, sizeof(mysock_context_t));
    assert(ctx);

    /* by default, sockets are active */
    ctx->listen_sd = -1;

    /* initialise connection condition variable.  this is signaled when the
     * connection is established, i.e. myconnect() or myaccept() should
     * unblock and return to the calling application.
     */
    PTHREAD_CALL(pthread_cond_init(&ctx->blocking_cond, NULL));
    PTHREAD_CALL(pthread_mutex_init(&ctx->blocking_lock, NULL));

    /* initialise data ready condition variable.  this is signaled when
     * data is ready from the application or the network.
     */
    PTHREAD_CALL(pthread_cond_init(&ctx->data_ready_cond, NULL));
    PTHREAD_CALL(pthread_mutex_init(&ctx->data_ready_lock, NULL));

    ctx->blocking = TRUE;   /* we unblock once we're connected */


    /* initialise underlying network state.  this includes creating the actual
     * socket used for communication to the peer--this is analogous to the
     * underlying raw IP socket used by a real TCP implementation.
     */
    if (_network_init(ctx, &ctx->network_state) < 0)
    {
        _mysock_free_context(ctx);
        return NULL;
    }

    return ctx;
}