25 #include <Wt/WHBoxLayout> 27 #include <Wt/WStackedWidget> 29 #include <Wt/WVBoxLayout> 31 #include "goby/common/time.h" 32 #include "goby/util/dynamic_protobuf_manager.h" 34 #include "liaison_home.h" 35 #include "liaison_wt_thread.h" 37 #include "goby/moos/moos_liaison_load.h" 43 goby::common::LiaisonWtThread::LiaisonWtThread(
const Wt::WEnvironment& env) :
Wt::WApplication(env)
47 Wt::WString title_text(
"goby liaison: " + liaison_cfg_.base().platform_name());
52 setCssTheme(
"default");
54 root()->setId(
"main");
59 WContainerWidget* header_div =
new WContainerWidget(root());
60 header_div->setId(
"header");
62 WText* header =
new WText(title_text, header_div);
63 header->setId(
"header");
65 WImage* goby_logo =
new WImage(
"images/gobysoft_logo_dot_org_small.png");
66 WAnchor* goby_logo_a =
67 new WAnchor(
"http://gobysoft.org/#/software/goby", goby_logo, header_div);
68 goby_logo_a->setId(
"goby_logo");
69 goby_logo_a->setStyleClass(
"no_ul");
70 goby_logo_a->setTarget(TargetNewWindow);
72 if (!liaison_cfg_.has_upper_right_logo())
74 WImage* goby_lp_image =
new WImage(
"images/mit-logo.gif");
75 WAnchor* goby_lp_image_a =
new WAnchor(
"http://lamss.mit.edu", goby_lp_image, header_div);
76 goby_lp_image_a->setId(
"lp_logo");
77 goby_lp_image_a->setStyleClass(
"no_ul");
78 goby_lp_image_a->setTarget(TargetNewWindow);
82 WImage* goby_lp_image =
new WImage(liaison_cfg_.upper_right_logo());
83 WAnchor* goby_lp_image_a =
new WAnchor(
84 liaison_cfg_.has_upper_right_logo_link() ? liaison_cfg_.upper_right_logo_link() :
"",
85 goby_lp_image, header_div);
86 goby_lp_image_a->setId(
"lp_logo");
87 goby_lp_image_a->setStyleClass(
"no_ul");
88 goby_lp_image_a->setTarget(TargetNewWindow);
91 new WText(
"<hr/>", root());
93 WContainerWidget* menu_div =
new WContainerWidget(root());
94 menu_div->setStyleClass(
"menu");
96 WContainerWidget* contents_div =
new WContainerWidget(root());
97 contents_div->setId(
"contents");
98 contents_stack_ =
new WStackedWidget(contents_div);
99 contents_stack_->setStyleClass(
"fill");
104 menu_ =
new WMenu(contents_stack_, Vertical, menu_div);
105 menu_->setRenderAsList(
true);
106 menu_->setStyleClass(
"menu");
107 menu_->setInternalPathEnabled();
108 menu_->setInternalBasePath(
"/");
110 add_to_menu(menu_,
new LiaisonHome);
112 typedef std::vector<goby::common::LiaisonContainer*> (*liaison_load_func)(
114 boost::shared_ptr<zmq::context_t> zmq_context);
116 for (
int i = 0, n = Liaison::plugin_handles_.size(); i < n; ++i)
118 liaison_load_func liaison_load_ptr =
119 (liaison_load_func)dlsym(Liaison::plugin_handles_[i],
"goby_liaison_load");
121 if (liaison_load_ptr)
123 std::vector<goby::common::LiaisonContainer*> containers =
124 (*liaison_load_ptr)(liaison_cfg_, Liaison::zmq_context());
125 for (
int j = 0, m = containers.size(); j < m; ++j) add_to_menu(menu_, containers[j]);
130 glog <<
"Liaison: Cannot find function 'goby_liaison_load' in plugin library." 135 menu_->itemSelected().connect(
this, &LiaisonWtThread::handle_menu_selection);
137 handle_menu_selection(menu_->currentItem());
140 goby::common::LiaisonWtThread::~LiaisonWtThread()
143 const std::vector<WMenuItem*>& items = menu_->items();
144 for (
int i = 0, n = items.size(); i < n; ++i)
146 LiaisonContainer* contents = menu_contents_[items[i]];
149 glog.is(DEBUG1) &&
glog <<
"Liaison: Cleanup : " << contents->name() << std::endl;
155 void goby::common::LiaisonWtThread::add_to_menu(WMenu* menu, LiaisonContainer* container)
157 Wt::WMenuItem* new_item = menu->addItem(container->name(), container);
158 menu_contents_.insert(std::make_pair(new_item, container));
161 void goby::common::LiaisonWtThread::handle_menu_selection(Wt::WMenuItem* item)
163 LiaisonContainer* contents = menu_contents_[item];
166 glog.is(DEBUG1) &&
glog <<
"Liaison: Focused : " << contents->name() << std::endl;
172 glog.is(WARN) &&
glog <<
"Liaison: Invalid menu item!" << std::endl;
176 const std::vector<WMenuItem*>& items = menu_->items();
177 for (
int i = 0, n = items.size(); i < n; ++i)
179 if (items[i] != item)
181 LiaisonContainer* other_contents = menu_contents_[items[i]];
184 glog.is(DEBUG1) &&
glog <<
"Liaison: Unfocused : " << other_contents->name()
186 other_contents->unfocus();
192 void goby::common::LiaisonWtThread::inbox(MarshallingScheme marshalling_scheme,
193 const std::string& identifier,
const void* data,
int size,
196 glog.is(DEBUG1) &&
glog <<
"LiaisonWtThread: got message with identifier: " << identifier
std::string goby_file_timestamp()
ISO string representation of goby_time()
common::FlexOstream glog
Access the Goby logger through this object.