Fawkes API Fawkes Development Version
eclipse_debugger.cpp
1/***************************************************************************
2 * eclipse_debugger.cpp - Eclipse Debugger Tool
3 *
4 * Created: Mon Feb 25 14:22:00 2013
5 * Copyright 2013 Gesche Gierse
6 *
7 ****************************************************************************/
8
9/* This program is free software; you can redistribute it and/or modify
10 * it 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 * This program is distributed in the hope that it 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 Library General Public License for more details.
18 *
19 * Read the full text in the LICENSE.GPL file in the doc directory.
20 */
21
22#include "eclipse_debugger.h"
23
24#include <blackboard/remote.h>
25#include <gui_utils/interface_dispatcher.h>
26#include <gui_utils/logview.h>
27#include <gui_utils/service_chooser_dialog.h>
28#include <netcomm/fawkes/client.h>
29#include <utils/system/argparser.h>
30
31#include <cstring>
32#include <sstream>
33#include <string>
34
35using namespace fawkes;
36
37/** @class EclipseDebugger "eclipse_debugger.h"
38 * ECLiPSe-clp Debugger GUI Wrapper.
39 * Can connect remotely with (embedded) ECLiPSe-clp session and
40 * starts the tkeclipse-clp graphical debugger. Has to be supported
41 * from the ECLiPSe program.
42 * @author Gesche Gierse
43 */
44
45/** Constructor.
46 * @param cobject C base object
47 * @param builder Gtk Builder
48 */
49EclipseDebugger::EclipseDebugger(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &builder)
50{
51 bb = NULL;
52
53 connection_dispatcher.signal_connected().connect(
54 sigc::mem_fun(*this, &EclipseDebugger::on_connect));
55 connection_dispatcher.signal_disconnected().connect(
56 sigc::mem_fun(*this, &EclipseDebugger::on_disconnect));
57
58 establish_connection();
59}
60
61/** Destructor. */
63{
64}
65
66void
67EclipseDebugger::establish_connection()
68{
69 if (!connection_dispatcher.get_client()->connected()) {
70 ServiceChooserDialog ssd(*this, connection_dispatcher.get_client());
71 ssd.run_and_connect();
72 } else {
73 connection_dispatcher.get_client()->disconnect();
74 }
75}
76
77/** Event handler for connected event. */
78void
79EclipseDebugger::on_connect()
80{
81 try {
82 if (!bb) {
83 bb = new RemoteBlackBoard(connection_dispatcher.get_client());
84 debugger_if_ = bb->open_for_reading<EclipseDebuggerInterface>("readylog_connect");
87 debugger_if_->msgq_enqueue(cm);
88 sleep(1);
89 debugger_if_->read();
90 char * host = debugger_if_->host();
91 unsigned int port = debugger_if_->port();
92 std::stringstream portstr;
93 portstr << port;
94 execlp("tktools-clp", "tktools-clp", "-h", host, "-p", portstr.str().c_str(), (char *)0);
95 }
96
97 } catch (Exception &e) {
98 Glib::ustring message = *(e.begin());
99 Gtk::MessageDialog md(*this,
100 message,
101 /* markup */ false,
102 Gtk::MESSAGE_ERROR,
103 Gtk::BUTTONS_OK,
104 /* modal */ true);
105 md.set_title("BlackBoard connection failed");
106 md.run();
107
108 close_bb();
109 connection_dispatcher.get_client()->disconnect();
110 }
111}
112
113/** Event handler for disconnected event. */
114void
115EclipseDebugger::on_disconnect()
116{
117 close_bb();
118}
119
120void
121EclipseDebugger::close_bb()
122{
123 if (bb) {
124 delete bb;
125 bb = NULL;
126 }
127}
~EclipseDebugger()
Destructor.
EclipseDebugger(BaseObjectType *cobject, const Glib::RefPtr< Gtk::Builder > &builder)
Constructor.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
sigc::signal< void > signal_connected()
Get "connected" signal.
FawkesNetworkClient * get_client()
Get client.
sigc::signal< void > signal_disconnected()
Get "disconnected" signal.
ConnectionMessage Fawkes BlackBoard Interface Message.
EclipseDebuggerInterface Fawkes BlackBoard Interface.
char * host() const
Get host value.
uint16_t port() const
Get port value.
Base class for exceptions in Fawkes.
Definition: exception.h:36
iterator begin() noexcept
Get iterator for messages.
Definition: exception.cpp:676
void disconnect()
Disconnect socket.
Definition: client.cpp:539
bool connected() const noexcept
Check if connection is alive.
Definition: client.cpp:828
unsigned int msgq_enqueue(Message *message, bool proxy=false)
Enqueue message at end of queue.
Definition: interface.cpp:915
void read()
Read from BlackBoard into local copy.
Definition: interface.cpp:479
Remote BlackBoard.
Definition: remote.h:50
Fawkes library namespace.