PSocket.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2018 Digital Barriers plc. All rights reserved.
3  * Contact: http://www.digitalbarriers.com/
4  *
5  * This file is part of the Papillon SDK.
6  *
7  * You can't use, modify or distribute any part of this file without
8  * the explicit written agreements of Digital Barriers.
9  */
10 
15 #pragma once
16 #include <PObject.h>
17 #include <PString.h>
18 
19 PAPILLON_BEGIN_NAMESPACE
20 
21 class PByteArray;
22 
26 class PAPILLON_API_CORE PSocket : public PObject
27 {
28 public:
33  {
44  E_STREAM
45  };
46 
48  {
50  E_BIND, // associate a socket with a local end-point
51  E_CONNECT // associate a socket with a remote end-point
52  };
53 
54 public:
60  PSocket();
61 
70  static PResult Open(PSocket& socket, ESocketType socketType, ESocketBinding binding = E_UNSPECIFIED, const PString& endPoint = PString::Empty());
71 
75  PSocket(const PSocket& other);
76 
80  virtual ~PSocket();
81 
85  PSocket& operator=(const PSocket& other);
86 
90  bool operator==(const PSocket& other) const;
91 
95  bool IsOpened() const;
96 
103  PResult Bind(const PString& endPoint);
104 
112  PResult Connnect(const PString& endPoint);
113 
124  PResult SetLingerPeriod(papillon::int32 periodInMs);
125 
140  PResult Subscribe(const PString& filter = PString::Empty());
141 
152  PResult Unsubscribe(const PString& filter);
153 
169  PResult Close();
170 
179  PResult Send(const PString& message, const PString& filter = PString::Empty());
180 
189  PResult Send(const PByteArray& message, const PString& filter = PString::Empty());
190 
198  PResult Send(const void* buffer, int32 lengthInBytes, const PString& filter = PString::Empty());
199 
206  PResult Receive(PString& message);
207 
214  PResult Receive(PByteArray& message);
215 
224  PResult Receive(void* buffer, papillon::int32 sizeofBufferInBytes, papillon::int32& sizeOfMessageInBytes);
225 
232  PResult IsPendingIncomingMessage(papillon::int32 timeOutMs = 0) const;
233 
240  PResult IsPendingOutgoingMessage(int32 timeOutMs = 0) const;
241 
247  PResult GetBoundPoint(PString& boundPoint) const;
248 
252  PResult GetBoundAddress(PString& boundAddress) const;
253 
257  PResult GetBoundPort(papillon::uint32& boundPort) const;
258 
259 };
260 
262 
263 PAPILLON_END_NAMESPACE
ESocketType
All available type of sockets, see http://api.zeromq.org/4-0:zmq-socket for details.
Definition: PSocket.h:32
ESocketBinding
Definition: PSocket.h:47
The PString class provides an Unicode character strings.
Definition: PString.h:37
traditional client/server; SERVER side
Definition: PSocket.h:35
publisher/subscriber pattern
Definition: PSocket.h:39
The PResult class represents the result returned by most of Papillon functions; this class is used to...
Definition: PResult.h:159
The PByteArray class represents a resizable array of bytes.
Definition: PByteArray.h:40
The PObject class is the root class of all Papillon classes; all PObject behaves like shared referenc...
Definition: PObject.h:27
Class PString: an unicode character strings (use copy-on-write idiom).
traditional client/server; CLIENT side
Definition: PSocket.h:36
publisher/subscriber pattern: subscriber must call Subscriber() to start receiving messages...
Definition: PSocket.h:40
static const PString & Empty()
Returns the constant holding the empty string "".
Definition: PString.h:64
The PSocket class represents a network socket which relies on 0-MQ distributed messaging library; NOT...
Definition: PSocket.h:26
push/pull pattern: messages are round-robined to all connected clients; can be used for load-balancin...
Definition: PSocket.h:42
Class PObject: the root class of all Papillon classes.
PObject & operator=(const PObject &obj)
Performs a shared copy of other to this object.
Definition: PObject.h:45
push/pull pattern: messages are round-robined to all connected clients; can be used for load-balancin...
Definition: PSocket.h:41