Goby v2
pGobyMOOSAppTemplate.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 //
5 //
6 // This file is part of the Goby Underwater Autonomy Project Binaries
7 // ("The Goby Binaries").
8 //
9 // The Goby Binaries are free software: you can redistribute them and/or modify
10 // them under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // The Goby Binaries are distributed in the hope that they will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
21 
22 #include "pGobyMOOSAppTemplate.h"
23 
24 using goby::glog;
25 using namespace goby::common::logger;
26 using goby::moos::operator<<;
27 
28 boost::shared_ptr<GobyMOOSAppTemplateConfig> master_config;
29 GobyMOOSAppTemplate* GobyMOOSAppTemplate::inst_ = 0;
30 
31 int main(int argc, char* argv[]) { return goby::moos::run<GobyMOOSAppTemplate>(argc, argv); }
32 
33 GobyMOOSAppTemplate* GobyMOOSAppTemplate::get_instance()
34 {
35  if (!inst_)
36  {
37  master_config.reset(new GobyMOOSAppTemplateConfig);
38  inst_ = new GobyMOOSAppTemplate(*master_config);
39  }
40  return inst_;
41 }
42 
43 void GobyMOOSAppTemplate::delete_instance() { delete inst_; }
44 
45 GobyMOOSAppTemplate::GobyMOOSAppTemplate(GobyMOOSAppTemplateConfig& cfg)
46  : GobyMOOSApp(&cfg), cfg_(cfg)
47 {
48  // example subscription -
49  // handle_db_time called each time mail from DB_TIME is received
50  subscribe("DB_TIME", &GobyMOOSAppTemplate::handle_db_time, this);
51 }
52 
53 GobyMOOSAppTemplate::~GobyMOOSAppTemplate() {}
54 
55 void GobyMOOSAppTemplate::loop()
56 {
57  // example publication
58  publish("TEST", MOOSTime());
59 }
60 
61 void GobyMOOSAppTemplate::handle_db_time(const CMOOSMsg& msg)
62 {
63  glog.is(VERBOSE) && glog << "Time is: " << std::setprecision(15) << msg.GetDouble()
64  << std::endl;
65 }
common::FlexOstream glog
Access the Goby logger through this object.