Some code fixes done to multicast service classes.
[tourist.git] / App / include / Tourist / App / PeerConnectionWorker.h
blob3b01927a091b3ca5385de99a4b5c3d8228f6cb3b
1 #ifndef PEERCONNECTIONWORKER_H
2 #define PEERCONNECTIONWORKER_H
5 #include "Tourist/AbstractPipe.h"
6 #include "Tourist/Message/MessageProcessor.h"
7 #include "Tourist/Message/RemoteNode.h"
8 #include "Tourist/Util/CallbackInterface.h"
9 #include "Poco/Runnable.h"
10 #include "Poco/Thread.h"
11 #include "Poco/Logger.h"
12 #include "Poco/Mutex.h"
13 #include "Poco/NotificationQueue.h"
15 using Tourist::Message::MessageProcessor;
16 using Tourist::Message::RemoteNode;
17 using Tourist::AbstractPipe;
19 using Poco::Runnable;
20 using Poco::Thread;
21 using Poco::FastMutex;
22 using Poco::NotificationQueue;
24 //forward declaration
25 namespace Tourist {
26 namespace Message {
30 namespace Tourist {
31 namespace App {
33 class Application;
35 /**
36 * Handle peer handshake in a new thread. Part of thread pool
37 * in Application class.
40 class PeerConnectionWorker : public Tourist::Util::CallbackInterface,
41 public Runnable
44 public:
45 PeerConnectionWorker (Application *app, AbstractPipe *pipe, RemoteNode &response,
46 bool isActive, int timeout=5);
49 ~PeerConnectionWorker();
51 bool isStopped();
53 bool isStatusOK();
55 void stopWorker();
57 //called upon the recept of MsgPeerAnnouncement message.
58 void handleHandshake();
60 //un-register pipe connect/disconnect handler
61 void cleanUp();
63 Tourist::Message::RemoteNode* getResult();
65 void run();
67 void callback(void *);
69 //reference counting
70 void duplicate();
72 void release();
75 private:
77 void handleHandshake(AbstractMessage *message);
79 int sendResponse(bool isAck);
81 Tourist::Message::MessageProcessor messageProcessor;
83 Tourist::Message::MessageTypeData msgTypeData;
85 AbstractPipe *pipe;
87 //true value indicates that we are initiating peer handshake
88 bool isActive;
90 bool shouldBeRunning;
92 bool stopped;
93 //Set if we successfuly resolved the peer info
94 bool statusOK;
96 //peer connection should be resolved before this timeout value.
97 int timeout;
99 //Information of the connected node.
100 Tourist::Message::RemoteNode *result;
102 Logger &logger;
104 static FastMutex mutex;
106 //The node that should be sent as a response in a handshake.
107 RemoteNode response;
109 Application *parent;
111 NotificationQueue queue;
113 //for reference counting purpose.
114 int rc;
116 static int ref_count;
118 }; //class PeerConnectionWorker
120 } //namespace Application
121 } //namespace Tourist
123 #endif /*PEERCONNECTIONWORKER_H*/