Ejemplo n.º 1
0
std::string g_titled_component::getTitle() {

    if (!g_ui_initialized) {
        return 0;
    }

    // send initialization request
    uint32_t tx = g_ipc_next_topic();

    g_ui_component_get_title_request request;
    request.header.id = G_UI_PROTOCOL_SET_TITLE;
    request.id = this->id;
    g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_component_get_title_request), tx);

    // read response
    size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_component_get_title_response);
    g_local<uint8_t> buffer(new uint8_t[bufferSize]);

    if (g_receive_message_t(buffer(), bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) {
        g_ui_component_get_title_response* response = (g_ui_component_get_title_response*) G_MESSAGE_CONTENT(buffer());
        if (response->status == G_UI_PROTOCOL_SUCCESS) {
            return std::string(response->title);
        }
    }

    return std::string();

}
Ejemplo n.º 2
0
Archivo: ui.cpp Proyecto: maxdev1/ghost
bool g_ui::get_screen_dimension(g_dimension* out) {

	if (!g_ui_initialized) {
		return false;
	}

	g_message_transaction tx = g_get_message_tx_id();

	// send request
	g_ui_get_screen_dimension_request request;
	request.header.id = G_UI_PROTOCOL_GET_SCREEN_DIMENSION;
	g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_get_screen_dimension_request), tx);

	// read response
	size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_get_screen_dimension_response);
	g_local<uint8_t> buffer(new uint8_t[bufferSize]);

	if (g_receive_message_t(buffer(), bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) {
		g_ui_get_screen_dimension_response* response = (g_ui_get_screen_dimension_response*) G_MESSAGE_CONTENT(buffer());
		*out = response->size;
		return true;
	}

	return false;
}
Ejemplo n.º 3
0
g_rectangle g_component::getBounds() {

	if (!g_ui_initialized) {
		return g_rectangle();
	}

	// send initialization request
	g_message_transaction tx = g_get_message_tx_id();

	g_ui_component_get_bounds_request request;
	request.header.id = G_UI_PROTOCOL_GET_BOUNDS;
	request.id = this->id;
	g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_component_get_bounds_request), tx);

	// read response
	size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_component_get_bounds_response);
	g_local<uint8_t> buffer(new uint8_t[bufferSize]);

	if (g_receive_message_t(buffer(), bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) {
		g_ui_component_get_bounds_response* response = (g_ui_component_get_bounds_response*) G_MESSAGE_CONTENT(buffer());

		if (response->status == G_UI_PROTOCOL_SUCCESS) {
			return response->bounds;
		}
	}

	return g_rectangle();

}
Ejemplo n.º 4
0
Archivo: ui.cpp Proyecto: maxdev1/ghost
bool g_ui::register_desktop_canvas(g_canvas* c) {

	if (!g_ui_initialized) {
		return false;
	}

	g_message_transaction tx = g_get_message_tx_id();

	// send registration request
	g_ui_register_desktop_canvas_request request;
	request.header.id = G_UI_PROTOCOL_REGISTER_DESKTOP_CANVAS;
	request.canvas_id = c->getId();
	g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_register_desktop_canvas_request), tx);

	// read response
	size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_register_desktop_canvas_response);
	g_local<uint8_t> buffer(new uint8_t[bufferSize]);

	if (g_receive_message_t(buffer(), bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) {
		g_ui_register_desktop_canvas_response* response = (g_ui_register_desktop_canvas_response*) G_MESSAGE_CONTENT(buffer());

		if (response->status == G_UI_PROTOCOL_SUCCESS) {
			return true;
		}
	}

	return false;
}
Ejemplo n.º 5
0
bool g_component::addChild(g_component* child) {

	if (!g_ui_initialized) {
		return 0;
	}

	// send initialization request
	g_message_transaction tx = g_get_message_tx_id();

	g_ui_component_add_child_request request;
	request.header.id = G_UI_PROTOCOL_ADD_COMPONENT;
	request.parent = this->id;
	request.child = child->id;
	g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_component_add_child_request), tx);

	// read response
	size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_component_add_child_response);
	uint8_t buffer[bufferSize];

	if (g_receive_message_t(buffer, bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) {
		g_ui_component_add_child_response* response = (g_ui_component_add_child_response*) G_MESSAGE_CONTENT(buffer);
		if (response->status == G_UI_PROTOCOL_SUCCESS) {
			return true;
		}
	}

	return false;

}
Ejemplo n.º 6
0
bool g_component::getNumericProperty(int property, uint32_t* out) {

	if (!g_ui_initialized) {
		return false;
	}

	// send initialization request
	g_message_transaction tx = g_get_message_tx_id();

	g_ui_component_get_numeric_property_request request;
	request.header.id = G_UI_PROTOCOL_GET_NUMERIC_PROPERTY;
	request.id = this->id;
	request.property = property;
	g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_component_get_numeric_property_request), tx);

	// read response
	size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_component_get_numeric_property_response);
	g_local<uint8_t> buffer(new uint8_t[bufferSize]);

	if (g_receive_message_t(buffer(), bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) {
		g_ui_component_get_numeric_property_response* response = (g_ui_component_get_numeric_property_response*) G_MESSAGE_CONTENT(buffer());

		if (response->status == G_UI_PROTOCOL_SUCCESS) {
			*out = response->value;
			return true;
		}
	}

	return false;
}
Ejemplo n.º 7
0
bool g_component::setVisible(bool visible) {

	if (!g_ui_initialized) {
		return 0;
	}

	// send initialization request
	g_message_transaction tx = g_get_message_tx_id();

	g_ui_component_set_visible_request request;
	request.header.id = G_UI_PROTOCOL_SET_VISIBLE;
	request.id = this->id;
	request.visible = visible;
	g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_component_set_visible_request), tx);

	// read response
	size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_component_set_visible_response);
	uint8_t buffer[bufferSize];

	if (g_receive_message_t(buffer, bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) {
		g_ui_component_set_visible_response* response = (g_ui_component_set_visible_response*) G_MESSAGE_CONTENT(buffer);
		if (response->status == G_UI_PROTOCOL_SUCCESS) {
			return true;
		}
	}

	return false;

}
Ejemplo n.º 8
0
Archivo: ui.cpp Proyecto: maxdev1/ghost
/**
 * Opens a connection to the window server.
 */
g_ui_open_status g_ui::open() {

	// check if already open
	if (g_ui_initialized) {
		return G_UI_OPEN_STATUS_EXISTING;
	}

	// get window managers id
	g_tid window_mgr = g_task_get_id(G_UI_REGISTRATION_THREAD_IDENTIFIER);
	if (window_mgr == -1) {
		klog("failed to retrieve task id of window server with identifier '%s'", G_UI_REGISTRATION_THREAD_IDENTIFIER);
		return G_UI_OPEN_STATUS_COMMUNICATION_FAILED;
	}

	// start event dispatcher
	g_ui_event_dispatcher_tid = g_create_thread((void*) &event_dispatch_thread);

	// send initialization request
	g_message_transaction init_tx = g_get_message_tx_id();

	g_ui_initialize_request request;
	request.header.id = G_UI_PROTOCOL_INITIALIZATION;
	g_send_message_t(window_mgr, &request, sizeof(g_ui_initialize_request), init_tx);

	// receive initialization response
	uint32_t response_buffer_size = sizeof(g_message_header) + sizeof(g_ui_initialize_response);
	g_local<uint8_t> response_buffer(new uint8_t[response_buffer_size]);
	if (g_receive_message_t(response_buffer(), response_buffer_size, init_tx) != G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) {
		klog("failed to communicate with the window server");
		return G_UI_OPEN_STATUS_COMMUNICATION_FAILED;
	}

	// check response
	g_ui_initialize_response* response = (g_ui_initialize_response*) G_MESSAGE_CONTENT(response_buffer());
	if (response->status != G_UI_PROTOCOL_SUCCESS) {
		klog("failed to open UI");
		return G_UI_OPEN_STATUS_FAILED;
	}

	// mark UI as ready
	g_ui_initialized = true;
	g_ui_delegate_tid = response->window_server_delegate_thread;
	return G_UI_OPEN_STATUS_SUCCESSFUL;
}
Ejemplo n.º 9
0
g_mouse_info g_mouse::readMouse() {

	if (mouseTopic == -1) {
		registerMouse();
	}

	size_t buflen = sizeof(g_message_header) + sizeof(g_ps2_mouse_packet);
	uint8_t buf[buflen];

	g_mouse_info e;
	if (g_receive_message_t(buf, buflen, mouseTopic) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) {
		g_ps2_mouse_packet* packet = (g_ps2_mouse_packet*) G_MESSAGE_CONTENT(buf);

		e.x = packet->x;
		e.y = packet->y;
		e.button1 = (packet->flags & (1 << 0));
		e.button2 = (packet->flags & (1 << 1));
		e.button3 = (packet->flags & (1 << 2));
	}
	return e;
}
Ejemplo n.º 10
0
bool g_titled_component::setTitle(std::string title) {

    if (!g_ui_initialized) {
        return 0;
    }

    // send initialization request
    uint32_t tx = g_ipc_next_topic();

    g_local<g_ui_component_set_title_request> request(new g_ui_component_set_title_request());
    request()->header.id = G_UI_PROTOCOL_SET_TITLE;
    request()->id = this->id;

    // fill text (truncate if necessary)
    const char* title_str = title.c_str();
    size_t title_len;
    if (title.length() >= G_UI_COMPONENT_TITLE_MAXIMUM) {
        title_len = G_UI_COMPONENT_TITLE_MAXIMUM;
    } else {
        title_len = title.length();
    }
    memcpy(request()->title, title.c_str(), title_len);
    request()->title[title_len] = 0;

    g_send_message_t(g_ui_delegate_tid, request(), sizeof(g_ui_component_set_title_request), tx);

    // read response
    size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_component_set_title_response);
    uint8_t buffer[bufferSize];

    if (g_receive_message_t(buffer, bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) {
        g_ui_component_set_title_response* response = (g_ui_component_set_title_response*) G_MESSAGE_CONTENT(buffer);
        if (response->status == G_UI_PROTOCOL_SUCCESS) {
            return true;
        }
    }

    return false;

}
Ejemplo n.º 11
0
bool g_component::setListener(g_ui_component_event_type eventType, g_listener* new_listener) {

	if (!g_ui_initialized) {
		return false;
	}

	// set new
	listeners[eventType] = new_listener;

	// check
	if (new_listener == 0) {
		return false;
	}

	// send request
	g_message_transaction tx = g_get_message_tx_id();

	g_ui_component_set_listener_request request;
	request.header.id = G_UI_PROTOCOL_SET_LISTENER;
	request.id = this->id;
	request.target_thread = g_ui_event_dispatcher_tid;
	request.event_type = eventType;
	g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_component_set_listener_request), tx);

	// read response
	size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_component_set_listener_response);
	uint8_t buffer[bufferSize];

	if (g_receive_message_t(buffer, bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) {
		g_ui_component_set_listener_response* response = (g_ui_component_set_listener_response*) G_MESSAGE_CONTENT(buffer);
		if (response->status == G_UI_PROTOCOL_SUCCESS) {
			return true;
		}
	}

	return false;
}
Ejemplo n.º 12
0
g_spawn_status g_spawn_poi(const char* path, const char* args, const char* workdir, g_security_level securityLevel, g_pid* pid, g_fd out_stdio[3],
		g_fd in_stdio[3]) {

	g_spawn_status res = G_SPAWN_STATUS_UNKNOWN;
	uint32_t tid = g_get_tid();

	// get spawner task identifier
	g_tid spawner_tid = g_task_get_id(G_SPAWNER_IDENTIFIER);
	if (spawner_tid == -1) {
		return res;
	}

	// create transaction
	g_message_transaction tx = g_get_message_tx_id();

	// create request
	size_t path_bytes = __g_strlen(path) + 1;
	size_t args_bytes = __g_strlen(args) + 1;
	size_t workdir_bytes = __g_strlen(workdir) + 1;
	size_t requestlen = sizeof(g_spawn_command_spawn_request) + path_bytes + args_bytes + workdir_bytes;
	g_local<uint8_t> _request(new uint8_t[requestlen]);
	uint8_t* request = _request();

	// copy request contents
	g_spawn_command_spawn_request* req = (g_spawn_command_spawn_request*) request;
	req->header.command = G_SPAWN_COMMAND_SPAWN_REQUEST;
	req->security_level = securityLevel;
	req->path_bytes = path_bytes;
	req->args_bytes = args_bytes;
	req->workdir_bytes = workdir_bytes;

	if (in_stdio != nullptr) {
		req->stdin = in_stdio[0];
		req->stdout = in_stdio[1];
		req->stderr = in_stdio[2];
	} else {
		req->stdin = G_FD_NONE;
		req->stdout = G_FD_NONE;
		req->stderr = G_FD_NONE;
	}

	uint8_t* insert = request;
	insert += sizeof(g_spawn_command_spawn_request);
	__g_memcpy(insert, path, path_bytes);
	insert += path_bytes;
	__g_memcpy(insert, args, args_bytes);
	insert += args_bytes;
	__g_memcpy(insert, workdir, workdir_bytes);

	// send request to spawner
	g_send_message_t(spawner_tid, request, requestlen, tx);

	// receive response
	size_t resp_len = sizeof(g_message_header) + sizeof(g_spawn_command_spawn_response);
	g_local<uint8_t> resp_buf(new uint8_t[resp_len]);
	g_receive_message_t(resp_buf(), resp_len, tx);

	g_spawn_command_spawn_response* response = (g_spawn_command_spawn_response*) G_MESSAGE_CONTENT(resp_buf());

	// if successful, take response parameters
	if (response->status == G_SPAWN_STATUS_SUCCESSFUL) {

		if (pid != nullptr) {
			*pid = response->spawned_process_id;
		}

		if (out_stdio != nullptr) {
			out_stdio[0] = response->stdin_write;
			out_stdio[1] = response->stdout_read;
			out_stdio[2] = response->stderr_read;
		}
	}

	return response->status;
}