1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
 * @file MessageQueue4Process.h
 * @author <a href="mailto:xu@informatik.hu-berlin.de">Xu, Yuan</a>
 * 
 * A message queue for communicating between processes
 */
 
#ifndef _MESSAGE_QUEUE_4_PROCESS_H_
#define _MESSAGE_QUEUE_4_PROCESS_H_

#include "MessageQueue.h"
#include <glib.h>
#include <gio/gio.h>
#include "Tools/Communication/SocketStream/SocketStream.h"

class MessageQueue4Process: public MessageQueue
{
public:
  MessageQueue4Process(const std::string& name);
  virtual ~MessageQueue4Process();
  
  /* write message to the channel */
  virtual void write(const std::string& msg);
  
  /* is there any message in the channel */
  virtual bool empty();

  virtual void setReader(MessageReader* reader);

  virtual void setWriter(MessageWriter* writer);

protected:
  void connect();

  bool isFixedLengthDataAvailable(unsigned int len);
  
private:
  std::string theName;
  GSocketAddress* addr;

  GSocket* serverSocket;
  PrefixedSocketStream theReadStream;
  PrefixedSocketStream theWriteStream;
  GSocket* readSocket;
  GSocket* writeSocket;
};

#endif // _MESSAGE_QUEUE_4_PROCESS_H_