Goby v2
pAcommsHandlerMain.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 "pAcommsHandler.h"
23 
24 std::vector<void*> plugin_handles_;
25 
26 using goby::glog;
27 using namespace goby::common::logger;
28 
29 int main(int argc, char* argv[])
30 {
31  goby::glog.add_group("pAcommsHandler", goby::common::Colors::yellow);
32 
33  // load plugins from environmental variable
34  char* plugins = getenv("PACOMMSHANDLER_PLUGINS");
35  if (plugins)
36  {
37  std::string s_plugins(plugins);
38  std::vector<std::string> plugin_vec;
39  boost::split(plugin_vec, s_plugins, boost::is_any_of(";:,"));
40 
41  for (int i = 0, n = plugin_vec.size(); i < n; ++i)
42  {
43  std::cout << "Loading pAcommsHandler plugin library: " << plugin_vec[i] << std::endl;
44  void* handle = dlopen(plugin_vec[i].c_str(), RTLD_LAZY);
45 
46  if (handle)
47  plugin_handles_.push_back(handle);
48  else
49  {
50  std::cerr << "Failed to open library: " << plugin_vec[i] << std::endl;
51  exit(EXIT_FAILURE);
52  }
53 
54  const char* (*name_function)(void) =
55  (const char* (*)(void))dlsym(handle, "goby_driver_name");
56  if (name_function)
57  CpAcommsHandler::driver_plugins_.insert(
58  std::make_pair(std::string((*name_function)()), handle));
59  }
60  }
61 
62  int return_value = goby::moos::run<CpAcommsHandler>(argc, argv);
63 
64  goby::transitional::DCCLAlgorithmPerformer::deleteInstance();
65  CpAcommsHandler::delete_instance();
66  goby::util::DynamicProtobufManager::protobuf_shutdown();
67 
68  for (int i = 0, n = plugin_handles_.size(); i < n; ++i) dlclose(plugin_handles_[i]);
69 
70  return return_value;
71 }
STL namespace.
int run(int argc, char *argv[], Config *cfg)
Run a Goby application derived from MinimalApplicationBase. blocks caller until MinimalApplicationBas...
void add_group(const std::string &name, Colors::Color color=Colors::nocolor, const std::string &description="")
Add another group to the logger. A group provides related manipulator for categorizing log messages...
common::FlexOstream glog
Access the Goby logger through this object.
The global namespace for the Goby project.