UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hds_messenger_ls.hpp
1 /* hds_messenger_ls.hpp */
2 /* $Id$ */
3 #ifndef __hds_messenger_ls_hpp
4 #define __hds_messenger_ls_hpp
5 
6 #include <QObject>
7 #include <QLocalServer>
8 #include <QLocalSocket>
9 
10 #include <hds_batch/defines.hpp>
11 #include <hds_batch/errors.hpp>
12 #include <hds_batch/hds_messenger.hpp>
13 
15 namespace hds
16 {
19  class MessengerLS : public QObject, public hds::Messenger
20  {
21  Q_OBJECT
22 
23  public:
24 
26  enum State
27  {
28  SERVER = 0,
31  };
32 
34  MessengerLS(QObject *parent = 0x0);
35 
40  MessengerLS(const QString &sock_name,
41  State state = CLIENT,
42  int connection_time_out = 0,
43  QObject *parent = 0x0 );
44 
46  virtual ~MessengerLS();
47 
48 
52  State init(const QString &sock_name,
53  State state = CLIENT,
54  int connection_time_out = 0 );
55 
56 
59  virtual void sendMsg(const hds::Messenger::Message &msg) const;
60 
64  virtual hds::Messenger::Message getMsg() const;
65 
66 
68  const QString& socketName() const {return m_socket_name;}
69 
71  int waitConnectionTimeOut() const{return m_connection_wait_time_out;}
72 
74  void setConnectionTimeOut(int dt)
75  {m_connection_wait_time_out = dt;}
76 
78  State state() const {return m_state;}
79 
82  bool hasMessages();
83 
84 
85  protected slots:
86 
87  // socket / server slots
88  virtual void socket_connection_error(QLocalSocket::LocalSocketError socketError);
89  virtual void socket_connected();
90  virtual void socket_disconnected();
91 
92  protected:
93 
95  mutable QLocalServer m_server;
96 
98  mutable QLocalSocket m_socket;
99 
101  QString m_socket_name;
102 
105 
107  int m_connection_wait_time_out;
108 
109  private:
110 
111  void get_message_from_sock(QLocalSocket *pls, hds::Messenger::Message &msg) const;
112  void send_message_to_sock(const hds::Messenger::Message &msg, QLocalSocket &sock) const;
113 
114  void debug_to_file(const QString &fname, const QByteArray &array) const;
115  };
116 };
117 
118 #endif /* hds_messenger_ls.hpp */
State m_state
Definition: hds_messenger_ls.hpp:104
MessengerLS(QObject *parent=0x0)
int waitConnectionTimeOut() const
Definition: hds_messenger_ls.hpp:71
virtual hds::Messenger::Message getMsg() const
virtual ~MessengerLS()
QLocalServer m_server
Definition: hds_messenger_ls.hpp:95
State init(const QString &sock_name, State state=CLIENT, int connection_time_out=0)
Definition: hds_messenger_ls.hpp:30
Definition: hds_messenger_ls.hpp:29
Definition: hds_messenger_ls.hpp:28
Definition: hds_messenger.hpp:16
State
Definition: hds_messenger_ls.hpp:26
const QString & socketName() const
Definition: hds_messenger_ls.hpp:68
virtual void sendMsg(const hds::Messenger::Message &msg) const
Definition: hds_messenger_ls.hpp:19
void setConnectionTimeOut(int dt)
Definition: hds_messenger_ls.hpp:74
State state() const
Definition: hds_messenger_ls.hpp:78
QLocalSocket m_socket
Definition: hds_messenger_ls.hpp:98
Definition: hds_messenger.hpp:38