コード例 #1
0
ファイル: RequestHandler.cpp プロジェクト: yonick/ghost
void RequestHandler::send_event(g_pid process, uint32_t listener_id, uint8_t* data, uint32_t length) {

	// lock
	g_atomic_lock(&process_map_lock);

	if (processMap.count(process) > 0) {
		UIRegisteredProcessData& procdat = processMap.at(process);

		// add event data to dispatcher queue
		UIEventDispatchData event_data;
		event_data.output = procdat.output;
		event_data.listener = listener_id;
		event_data.data = data;
		event_data.length = length;
		event_dispatch_queue_add(event_data);
	}

	// unlock
	process_map_lock = false;
}
コード例 #2
0
ファイル: ui.cpp プロジェクト: emcifuntik/ghost
/**
 * Waits for responses from the window manager and stores them
 * in the transaction message map.
 */
void g_ui::asynchronous_receiver_thread() {

	while (true) {

		// TODO properly check if each read/write was successful & validate the data length

		// read the id
		uint32_t idlen = sizeof(g_ui_transaction_id);
		uint8_t id[idlen];
		g_read(g_ui_channel_in, &id, idlen);
		g_ui_transaction_id transaction = *((g_ui_transaction_id*) id);

		// read the length
		uint32_t lenlen = sizeof(uint32_t);
		uint8_t len[lenlen];
		g_read(g_ui_channel_in, &len, lenlen);
		uint32_t length = *((uint32_t*) len);

		// read the data
		uint8_t* data = new uint8_t[length];
		int32_t data_read = 0;
		while (data_read < length) {
			data_read += g_read(g_ui_channel_in, &data[data_read], length - data_read);
		}

		// no transaction? -> event
		if (transaction == 0) {

			// get id from data
			g_value_placer data_reader(data);
			uint32_t listener_id = data_reader.get<uint32_t>();

			// notify listener
			if (listeners.count(listener_id) > 0) {
				g_listener* listener = listeners.at(listener_id);

				// add event to dispatch queue
				g_ui_event_dispatch_data ldata;
				ldata.listener = listener;
				ldata.data = data;
				ldata.length = length;
				event_dispatch_queue_add(ldata);
			}

		} else {
			// does map even exist?
			if (transaction_map == 0) {
				g_logger::log("transaction map did not exist when receiving request");
				break;
			}

			// check if data exists
			if (transaction_map->count(transaction) < 1) {
				g_logger::log("transaction map did not contain data for a request that was received");
				break;
			}

			// update the data
			g_ui_transaction_data* transaction_data = transaction_map->at(transaction);
			transaction_data->data = data;
			transaction_data->length = length;
			transaction_data->waiting = false;
		}
	}
}