FairRoot/PandaRoot
PndMQExample1Sampler.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
15 #include <memory> // unique_ptr
16 
17 #include <boost/thread.hpp>
18 #include <boost/bind.hpp>
19 #include <PndMQExample1Sampler.h>
20 
21 #include "FairMQLogger.h"
22 
23 using namespace std;
24 
26  : fText()
27 {
28 }
29 
30 void PndMQExample1Sampler::CustomCleanup(void *data, void *object)
31 {
32  delete (string*)object;
33 }
34 
36 {
37  while (CheckCurrentState(RUNNING))
38  {
39  boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
40 
41  string* text = new string(fText);
42 
43  unique_ptr<FairMQMessage> msg(fTransportFactory->CreateMessage(const_cast<char*>(text->c_str()), text->length(), CustomCleanup, text));
44 
45  LOG(INFO) << "Sending \"" << fText << "\"";
46 
47  fChannels.at("data-out").at(0).Send(msg);
48  }
49 }
50 
52 {
53 }
54 
55 void PndMQExample1Sampler::SetProperty(const int key, const string& value)
56 {
57  switch (key)
58  {
59  case Text:
60  fText = value;
61  break;
62  default:
63  FairMQDevice::SetProperty(key, value);
64  break;
65  }
66 }
67 
68 string PndMQExample1Sampler::GetProperty(const int key, const string& default_ /*= ""*/)
69 {
70  switch (key)
71  {
72  case Text:
73  return fText;
74  break;
75  default:
76  return FairMQDevice::GetProperty(key, default_);
77  }
78 }
79 
80 void PndMQExample1Sampler::SetProperty(const int key, const int value)
81 {
82  switch (key)
83  {
84  default:
85  FairMQDevice::SetProperty(key, value);
86  break;
87  }
88 }
89 
90 int PndMQExample1Sampler::GetProperty(const int key, const int default_ /*= 0*/)
91 {
92  switch (key)
93  {
94  default:
95  return FairMQDevice::GetProperty(key, default_);
96  }
97 }
static void CustomCleanup(void *data, void *hint)
virtual void SetProperty(const int key, const std::string &value)
virtual std::string GetProperty(const int key, const std::string &default_="")