LOGD("Destroyed client");
}
-void Client::start()
+void Client::connect()
{
- LOGD("Starting client...");
-
// Initialize the connection with the server
LOGD("Connecting to " + mSocketPath);
auto socketPtr = std::make_shared<Socket>(Socket::connectSocket(mSocketPath));
mServiceFD = mProcessor.addPeer(socketPtr);
+}
+
+void Client::start()
+{
+ LOGD("Starting client...");
- // Start listening
+ connect();
+
+ // Start polling thread
mProcessor.start();
LOGD("Started client");
LOGD("Stopped");
}
+std::vector<FileDescriptor> Client::getFDs()
+{
+ std::vector<FileDescriptor> fds;
+ fds.push_back(mProcessor.getEventFD());
+ fds.push_back(mServiceFD);
+
+ return fds;
+}
+
+void Client::handle(const FileDescriptor fd, const short pollEvent)
+{
+ if (fd == mProcessor.getEventFD() && (pollEvent & POLLIN)) {
+ mProcessor.handleEvent();
+ return;
+
+ } else if (pollEvent & POLLIN) {
+ mProcessor.handleInput(fd);
+ return;
+
+ } else if (pollEvent & POLLHUP) {
+ mProcessor.handleLostConnection(fd);
+ return;
+ }
+}
+
void Client::setNewPeerCallback(const PeerCallback& newPeerCallback)
{
mProcessor.setNewPeerCallback(newPeerCallback);