Exemplo n.º 1
0
// Ensure that we're connected to the PIME input method server
// If we are already connected, the method simply returns true;
// otherwise, it tries to establish the connection.
bool Client::connectServerPipe() {
	if (pipe_ == INVALID_HANDLE_VALUE) { // the pipe is not connected
		connectingServerPipe_ = true;
		wstring serverPipeName = getPipeName(L"Launcher");
		// try to connect to the server
		pipe_ = connectPipe(serverPipeName.c_str());

		if (pipe_ != INVALID_HANDLE_VALUE) { // successfully connected to the server
			init(); // send initialization info to the server
			if (isActivated_) {
				// we lost connection while being activated previously
				// re-initialize the whole text service.

				// cleanup for the previous instance.
				// remove all buttons
				for (auto& item: buttons_) {
					textService_->removeButton(item.second);
				}
				buttons_.clear();

				// FIXME: other cleanup might also be needed

				// activate the text service again.
				onActivate();
			}
		}
		connectingServerPipe_ = false;
		return (pipe_ != INVALID_HANDLE_VALUE);
	}
	return true;
}
Exemplo n.º 2
0
	void IpcNode::sendData(const uint32_t address, const unsigned char * buffer, const std::size_t length)
	{
		auto it = activeClientPipes_.find(address);
		if (it != activeClientPipes_.end())
		{
			ClientPipePtr pipe = it->second;
			pipe->startSend(buffer, length);
		}
		else
		{
			//Create new client
			ClientPipePtr pipe(new ClientPipe(mainIoService_, getPipeName(address).c_str(), address_));
			
			pipe->setCallbacks(boost::bind(&IpcNode::onServerConnected, shared_from_this(), _1),
				boost::bind(&IpcNode::onServerDisconnected, shared_from_this(), _1, _2),
				boost::bind(&IpcNode::onClientSent, shared_from_this()));
			pipe->ConnectToServer();

			if (pipe->isOpen())
			{	
				activeClientPipes_.insert(std::make_pair(address, pipe));
				pipe->startSend(buffer, length);
			}
		}
	}
Exemplo n.º 3
0
	void IpcNode::createServerPipe()
	{
		ServerPipePtr pipe(new ServerPipe(mainIoService_, getPipeName(address_).c_str()));

		if (pipe->isOpen())
		{
			pipe->setCallbacks(boost::bind(&IpcNode::onClientConnected, shared_from_this(), _1, _2),
				boost::bind(&IpcNode::onClientDisconnected, shared_from_this(), _1, _2),
				boost::bind(&IpcNode::onServerReceived, shared_from_this(), _1, _2));

			if (pipe->waitForConnection())
			{
				pendingConnections_.push_back(pipe);
			}
		}
		else
		{
			LOG_ERR_R(IPC_PIPE_LOG_TAG, _T("Ipc server pipe cannot be created"));
		}
	}