]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MONITOR/AliThreadedSocket.h
ATO-65 - replace FitSlicesY with robust fit function (commit after one run test ...
[u/mrichter/AliRoot.git] / MONITOR / AliThreadedSocket.h
1 // Main authors: Mihai Niculescu 2014
2
3 /**************************************************************************
4  * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
5  * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
6  * full copyright notice.                                                 *
7  **************************************************************************/
8
9 #ifndef AliThreadedSocket_H
10 #define AliThreadedSocket_H
11
12 #include <TQObject.h>
13
14 class TThread;
15 class AliNetMessage;
16
17 namespace zmq {
18         class context_t;
19 }
20
21 class AliThreadedSocket : public TQObject
22 {
23 public:
24         enum EOpenMode{kREAD, kWRITE};
25
26         AliThreadedSocket(zmq::context_t *context, EOpenMode mode);
27         virtual ~AliThreadedSocket();
28
29         Bool_t Start();
30         Bool_t Stop();
31         Bool_t Kill();
32         void Wait();
33         
34         zmq::context_t* GetContext() const;
35         TThread* GetThread() const;
36         EOpenMode GetMode() const { return fOpenMode; }
37                 
38         void Started(); // *SIGNAL*
39         void Stopped(); // *SIGNAL*
40
41         void Continue();
42         
43 protected:
44   AliThreadedSocket(const AliThreadedSocket&);            // Not implemented
45   AliThreadedSocket& operator=(const AliThreadedSocket&); // Not implemented
46
47         // Reimplement these in a derived Class
48         virtual void RunThrdRead(); // function to run in a thread when in Read mode
49         virtual void RunThrdWrite(); // function to run in a thread when in Write mode
50
51         TThread* fThread;
52         zmq::context_t* fContext;
53         EOpenMode fOpenMode;
54
55 private:
56         static void* Dispatch(void* arg)
57         {
58                 AliThreadedSocket* th = static_cast<AliThreadedSocket*>(arg);
59                 
60                 if(th->GetMode()==kREAD)
61                         th->RunThrdRead();
62                 else
63                         th->RunThrdWrite();
64                         
65                         return NULL;
66         }
67
68   ClassDef(AliThreadedSocket, 0);  
69 };
70 #endif