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 
23 #include "eclipse_debugger.h"
24 
25 #include <utils/system/argparser.h>
26 #include <blackboard/remote.h>
27 #include <netcomm/fawkes/client.h>
28 
29 #include <gui_utils/logview.h>
30 #include <gui_utils/service_chooser_dialog.h>
31 #include <gui_utils/interface_dispatcher.h>
32 
33 #include <cstring>
34 #include <string>
35 #include <sstream>
36 
37 using namespace fawkes;
38 
39 /** @class EclipseDebugger "eclipse_debugger.h"
40  * ECLiPSe-clp Debugger GUI Wrapper.
41  * Can connect remotely with (embedded) ECLiPSe-clp session and
42  * starts the tkeclipse-clp graphical debugger. Has to be supported
43  * from the ECLiPSe program.
44  * @author Gesche Gierse
45  */
46 
47 
48 /** Constructor.
49  * @param cobject C base object
50  * @param builder Gtk Builder
51  */
52 EclipseDebugger::EclipseDebugger(BaseObjectType* cobject,
53  const Glib::RefPtr<Gtk::Builder> &builder)
54 {
55  bb = NULL;
56 
57  connection_dispatcher.signal_connected().connect(sigc::mem_fun(*this, &EclipseDebugger::on_connect));
58  connection_dispatcher.signal_disconnected().connect(sigc::mem_fun(*this, &EclipseDebugger::on_disconnect));
59 
60  establish_connection();
61 }
62 
63 /** Destructor. */
65 {
66 
67 }
68 
69 void
70 EclipseDebugger::establish_connection()
71 {
72  if ( ! connection_dispatcher.get_client()->connected() ) {
73  ServiceChooserDialog ssd(*this, connection_dispatcher.get_client());
74  ssd.run_and_connect();
75  } else {
76  connection_dispatcher.get_client()->disconnect();
77  }
78 }
79 
80 /** Event handler for connected event. */
81 void
82 EclipseDebugger::on_connect()
83 {
84  try {
85  if ( ! bb ) {
86  bb = new RemoteBlackBoard(connection_dispatcher.get_client());
87  __debugger_if = bb->open_for_reading<EclipseDebuggerInterface>("readylog_connect");
89  __debugger_if->msgq_enqueue(cm);
90  sleep(1);
91  __debugger_if->read();
92  char* host = __debugger_if->host();
93  unsigned int port = __debugger_if->port();
94  std::stringstream portstr;
95  portstr << port;
96  execlp("tktools-clp", "tktools-clp", "-h", host, "-p", portstr.str().c_str(), (char *) 0);
97  }
98 
99  } catch (Exception &e) {
100  Glib::ustring message = *(e.begin());
101  Gtk::MessageDialog md(*this, message, /* markup */ false,
102  Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK,
103  /* modal */ true);
104  md.set_title("BlackBoard connection failed");
105  md.run();
106 
107  close_bb();
108  connection_dispatcher.get_client()->disconnect();
109  }
110 }
111 
112 
113 /** Event handler for disconnected event. */
114 void
115 EclipseDebugger::on_disconnect()
116 {
117  close_bb();
118 }
119 
120 
121 void
122 EclipseDebugger::close_bb()
123 {
124  if ( bb ) {
125  delete bb;
126  bb = NULL;
127  }
128 }
Fawkes library namespace.
EclipseDebugger(BaseObjectType *cobject, const Glib::RefPtr< Gtk::Builder > &builder)
Constructor.
Base class for exceptions in Fawkes.
Definition: exception.h:36
EclipseDebuggerInterface Fawkes BlackBoard Interface.
void run_and_connect()
Run dialog and try to connect.
iterator begin()
Get iterator for messages.
Definition: exception.cpp:700
Remote BlackBoard.
Definition: remote.h:48
ConnectionMessage Fawkes BlackBoard Interface Message.
~EclipseDebugger()
Destructor.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)
Open interface for reading.
Definition: remote.cpp:272