コード例 #1
0
ファイル: ip_connection.c プロジェクト: HinterhausEmil/tinker
int ipcon_handle_enumerate(IPConnection *ipcon, const unsigned char *buffer) {
	uint16_t length = ipcon_get_length_from_data(buffer);

	if(ipcon->enumerate_callback == NULL) {
		return length;
	}

	ipcon_callback_queue_enqueue(ipcon, buffer);

	return length;
}
コード例 #2
0
ファイル: ip_connection.c プロジェクト: jforge/tinker-pong
void ipcon_handle_message(IPConnection *ipcon, const unsigned char *buffer) {
	uint8_t function_id = ipcon_get_function_id_from_data(buffer);
	if(function_id == FUNCTION_GET_STACK_ID) {
		ipcon_handle_add_device(ipcon, buffer);
		return;
	}

	if(function_id == FUNCTION_ENUMERATE_CALLBACK) {
		ipcon_handle_enumerate(ipcon, buffer);
		return;
	}

	uint8_t stack_id = ipcon_get_stack_id_from_data(buffer);
	uint16_t length = ipcon_get_length_from_data(buffer);
	if(ipcon->devices[stack_id] == NULL) {
		// Response from an unknown device, ignoring it
		return;
	}

	Device *device = ipcon->devices[stack_id];
	DeviceResponse *response = &device->response;

	if(response->function_id == function_id) {
		if(response->length != length) {
			fprintf(stderr,
			        "Received malformed message from %d, ignoring it\n",
			        stack_id);
			return;
		}

		memcpy(response->buffer, buffer, length);
		response->length = length;

#ifdef _WIN32
		ReleaseSemaphore(device->response_semaphore, 1, NULL);
#else
		pthread_mutex_lock(&device->response_mutex);
		device->response_flag = true;
		pthread_cond_signal(&device->response_cond);
		pthread_mutex_unlock(&device->response_mutex);
#endif
		return;
	}

	if(device->registered_callbacks[function_id] != NULL) {
		ipcon_callback_queue_enqueue(ipcon, buffer);
		return;
	}

	// Message seems to be OK, but can't be handled, most likely
	// a callback without registered function
}
コード例 #3
0
ファイル: ip_connection.c プロジェクト: jforge/tinker-pong
void ipcon_handle_enumerate(IPConnection *ipcon, const unsigned char *buffer) {
	if(ipcon->enumerate_callback != NULL) {
		ipcon_callback_queue_enqueue(ipcon, buffer);
	}
}