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 
35 using 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  */
49 EclipseDebugger::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 
66 void
67 EclipseDebugger::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. */
78 void
79 EclipseDebugger::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. */
114 void
115 EclipseDebugger::on_disconnect()
116 {
117  close_bb();
118 }
119 
120 void
121 EclipseDebugger::close_bb()
122 {
123  if (bb) {
124  delete bb;
125  bb = NULL;
126  }
127 }
EclipseDebugger::~EclipseDebugger
~EclipseDebugger()
Destructor.
Definition: eclipse_debugger.cpp:62
EclipseDebugger::EclipseDebugger
EclipseDebugger(BaseObjectType *cobject, const Glib::RefPtr< Gtk::Builder > &builder)
Constructor.
Definition: eclipse_debugger.cpp:49
fawkes::RemoteBlackBoard
Definition: remote.h:51
fawkes
fawkes::EclipseDebuggerInterface
Definition: EclipseDebuggerInterface.h:37
fawkes::ServiceChooserDialog
Definition: service_chooser_dialog.h:49
fawkes::Exception::begin
iterator begin()
Get iterator for messages.
Definition: exception.cpp:675
fawkes::EclipseDebuggerInterface::ConnectionMessage
Definition: EclipseDebuggerInterface.h:63
fawkes::RemoteBlackBoard::open_for_reading
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)
Definition: remote.cpp:270
fawkes::ServiceChooserDialog::run_and_connect
void run_and_connect()
Run dialog and try to connect.
Definition: service_chooser_dialog.cpp:280
fawkes::Exception
Definition: exception.h:39