hlit-mon  0.5.2
 All Classes Functions Groups Pages
Subscriber Class Reference

This class receives data from the broker. More...

#include <Subscriber.h>

Public Member Functions

 Subscriber (char *addr_sub)
 
 Subscriber ()
 
pair< string, string > Get_Cluster_Json ()
 
void Recv_Message ()
 
void Connect ()
 
void Set_Addr (char *addr)
 

Detailed Description

This class receives data from the broker.

Author
Mayorov

The class receives data from the broker and passes it out. The data are stored only until a new message is received.

Definition at line 23 of file Subscriber.h.

Constructor & Destructor Documentation

Subscriber::Subscriber ( char *  addr_sub)

The constructor creates class 'Subscriber' with the specified address

Parameters
[in]addr_subAddress of the broker

Definition at line 3 of file Subscriber.cpp.

4 {
5  addr_sub = addr;
6 }
Subscriber::Subscriber ( )

The default constructor creates class 'Subscriber' with address 'tcp://localhost:5001'

Definition at line 8 of file Subscriber.cpp.

9 {
10  addr_sub = strdup(">tcp://localhost:5001");
11 }

Member Function Documentation

void Subscriber::Connect ( )

Connects to the broker.

Definition at line 19 of file Subscriber.cpp.

20 {
21  sub = zsock_new_sub(addr_sub, "");
22  printf("Subscriber is connected to %s\n", &addr_sub[1]);
23 }
pair< string, string > Subscriber::Get_Cluster_Json ( )

Returns broker information about the cluster.

Returns
Pair <[type of node], [json]>

Definition at line 46 of file Subscriber.cpp.

47 {
48  return pair<string, string>(cluster, json);
49 }
void Subscriber::Recv_Message ( )

Waiting for a message from broker.

Definition at line 30 of file Subscriber.cpp.

31 {
32  zmsg_t* msg = zmsg_recv(sub);
33  if (msg) {
34  char* sub_str = zmsg_popstr(msg);
35  free(sub_str);
36  char* clstr = zmsg_popstr(msg);
37  char* jsn = zmsg_popstr(msg);
38  cluster = clstr;
39  json = jsn;
40  free(clstr);
41  free(jsn);
42  }
43  zmsg_destroy(&msg);
44 }
void Subscriber::Set_Addr ( char *  addr)

Sets address of broker

Parameters
[in]addrAddress of the broker
Warning
Use before establishing connection with broker

Definition at line 25 of file Subscriber.cpp.

26 {
27  addr_sub = addr;
28 }

The documentation for this class was generated from the following files: