Goby v2
application.cpp
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Goby Underwater Autonomy Project Libraries
8 // ("The Goby Libraries").
9 //
10 // The Goby Libraries are free software: you can redistribute them and/or modify
11 // them under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // The Goby Libraries are distributed in the hope that they will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
22 
23 #include <iostream>
24 
25 #include "goby/common/time.h"
26 
27 #include "application.h"
28 
29 using namespace goby::pb;
30 using namespace goby::common;
31 using namespace goby::util;
32 using namespace goby::common::logger;
33 using boost::shared_ptr;
34 using goby::glog;
35 using goby::common::operator<<;
36 
38  : ZeroMQApplicationBase(&zeromq_service_, cfg)
39 {
40  __set_up_sockets();
41 
42  // notify others of our configuration for logging purposes
43  if (cfg)
44  publish(*cfg);
45 }
46 
47 goby::pb::Application::~Application()
48 {
49  glog.is(DEBUG1) && glog << "Application destructing..." << std::endl;
50 }
51 
52 void goby::pb::Application::__set_up_sockets()
53 {
54  if (!(base_cfg().pubsub_config().has_publish_socket() &&
55  base_cfg().pubsub_config().has_subscribe_socket()))
56  {
57  glog.is(WARN) &&
58  glog
59  << "Not using publish subscribe config. You will need to set up your nodes manually"
60  << std::endl;
61  }
62  else
63  {
64  protobuf_node_.reset(new StaticProtobufNode(&zeromq_service_));
65  pubsub_node_.reset(
66  new StaticProtobufPubSubNodeWrapper(protobuf_node_.get(), base_cfg().pubsub_config()));
67  }
68 
69  zeromq_service_.merge_cfg(base_cfg().additional_socket_config());
70 }
71 
72 void goby::pb::Application::publish(const google::protobuf::Message& msg, const std::string& group)
73 {
74  glog.is(DEBUG3) && glog << "< [" << group << "]: " << msg << std::endl;
75 
76  if (pubsub_node_)
77  pubsub_node_->publish(msg, group);
78 }
Contains objects relating to the core publish / subscribe architecture provided by Goby...
Definition: application.h:46
Utility objects for performing functions such as logging, non-acoustic communication (ethernet / seri...
common::FlexOstream glog
Access the Goby logger through this object.
Application(google::protobuf::Message *cfg=0)
Definition: application.cpp:37