Example #1
0
/**
	@brief Create a new port and associate it with the monitor.
	@param portName The name to give the new port.
	@return true on success, false on failure.
*/
bool
PortMonitor::AddPort(const wchar_t* portName)
{
	if (!this->AddPortToRegistry(portName))
		return false;
		
	Loki::ScopeGuard registryGuard = Loki::MakeGuard(
		&PortMonitor::RemovePortFromRegistry, *this, portName
	);
	
	AddPortIpcRequest request(portName);

	PipeClient pipeClient;
	if (!pipeClient.Send(&request))
		return false;

	AddPortIpcResponse* response = request.GetExactResponse();

	if (response->GetReturnCode())
	{
		registryGuard.Dismiss();
		this->portNames.push_back(std::wstring(portName));
		return true;
	}
	else
	{
		SetLastError(response->GetErrorCode());
		return false;
	}
}
Example #2
0
void clientProcess(PipeClient<int> &pipe)
{
    int array[100] = {0};
    std::vector<int> data;

    while (!pipe.waitForServer(5000));
    pipe.connect();

   //std::cout << "Bytes available: " << pipe.bytesAvailable() << std::endl;

    while (pipe.bytesAvailable() < 400)
    {
        std::cout << "Waiting!" << std::endl;
    }

    //data = pipe.read(100);
    std::cout << (data = pipe.read(100)).size()*sizeof(int) << " bytes read!\n";

    for (int i : data)
        std::cout << i << std::endl;
}
Example #3
0
/**
	@brief Delete the port matching the given name.
	@return true on success, false on failure.
*/
bool 
PortMonitor::DeletePort(const wchar_t* portName)
{
	std::vector<std::wstring>::iterator it;
	for (it = this->portNames.begin(); it != this->portNames.end(); ++it)
	{
		if (wcscmp(it->c_str(), portName) == 0)
		{
			if (!this->RemovePortFromRegistry(portName))
				return false;
				
			Loki::ScopeGuard registryGuard = Loki::MakeGuard(&PortMonitor::AddPortToRegistry, *this, portName);
				
			DeletePortIpcRequest request(portName);

			PipeClient pipeClient;
			if (!pipeClient.Send(&request))
				return false;

			DeletePortIpcResponse* response = request.GetExactResponse();

			if (response->GetReturnCode())
			{
				registryGuard.Dismiss();
				this->portNames.erase(it);
				return true;
			}
			else
			{
				SetLastError(response->GetErrorCode());
				return false;
			}
		}
	}
	return false;
}
Example #4
0
Transport *TransportFactory::createPipeClientTransport(const TCHAR *name)
{
  PipeClient factory;

  return new NamedPipeTransport(factory.connect(name));
}