window3.cc
Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *---------------------           WMPSNIFFER          --------------------
00003  *------------------------------------------------------------------------
00004  *                                                         V7.0B  11/05/10
00005  *
00006  *
00007  *  File: window3.cc
00008  *  Authors: Danilo Tardioli
00009  *  ----------------------------------------------------------------------
00010  *  Copyright (C) 2000-2012, Universidad de Zaragoza, SPAIN
00011  *
00012  *  Contact Addresses: Danilo Tardioli                   dantard@unizar.es
00013  *
00014  *  RT-WMP is free software; you can  redistribute it and/or  modify it
00015  *  under the terms of the GNU General Public License  as published by the
00016  *  Free Software Foundation;  either  version 2, or (at  your option) any
00017  *  later version.
00018  *
00019  *  RT-WMP  is distributed  in the  hope  that  it will be   useful, but
00020  *  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
00021  *  MERCHANTABILITY  or  FITNESS FOR A  PARTICULAR PURPOSE.    See the GNU
00022  *  General Public License for more details.
00023  *
00024  *  You should have received  a  copy of  the  GNU General Public  License
00025  *  distributed with RT-WMP;  see file COPYING.   If not,  write to the
00026  *  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
00027  *  02111-1307, USA.
00028  *
00029  *  As a  special exception, if you  link this  unit  with other  files to
00030  *  produce an   executable,   this unit  does  not  by  itself cause  the
00031  *  resulting executable to be covered by the  GNU General Public License.
00032  *  This exception does  not however invalidate  any other reasons why the
00033  *  executable file might be covered by the GNU Public License.
00034  *
00035  *----------------------------------------------------------------------*/
00036 
00037 #include "config.h"
00038 /*
00039  * Standard gettext macros.
00040  */
00041 #ifdef ENABLE_NLS
00042 #  include <libintl.h>
00043 #  undef _
00044 #  define _(String) dgettext (GETTEXT_PACKAGE, String)
00045 #  ifdef gettext_noop
00046 #    define N_(String) gettext_noop (String)
00047 #  else
00048 #    define N_(String) (String)
00049 #  endif
00050 #else
00051 #  define textdomain(String) (String)
00052 #  define gettext(String) (String)
00053 #  define dgettext(Domain,Message) (Message)
00054 #  define dcgettext(Domain,Message,Type) (Message)
00055 #  define bindtextdomain(Domain,Directory) (Domain)
00056 #  define _(String) (String)
00057 #  define N_(String) (String)
00058 #endif
00059 #include <gtkmmconfig.h>
00060 #if GTKMM_MAJOR_VERSION==2 && GTKMM_MINOR_VERSION>2
00061 #define GMM_GTKMM_22_24(a,b) b
00062 #else //gtkmm 2.2
00063 #define GMM_GTKMM_22_24(a,b) a
00064 #endif //
00065 #include "window3_glade.hh"
00066 #include <gdk/gdkkeysyms.h>
00067 #include <gtkmm/accelgroup.h>
00068 #include <gtkmm/alignment.h>
00069 #include <gtkmm/label.h>
00070 #include <gtkmm/frame.h>
00071 #if GTKMM_MAJOR_VERSION==2 && GTKMM_MINOR_VERSION>2
00072 #include <gtkmm/expander.h>
00073 #else //
00074 #include <gtkmm/handlebox.h>
00075 #endif //
00076 #include "window3.hh"
00077 #include <vte-0.0/vte/vte.h>
00078 #include <ostream>
00079 #include <sys/types.h>
00080 #include <sys/wait.h>
00081 
00082 void func(GtkWidget *widget, gpointer * data){
00083 //      int exit_code = vte_terminal_get_child_exit_status((VteTerminal*)w3->vte);
00084 }
00085 
00086 void window3::die(){
00087         char txt[]={3,0};
00088         for (int i=0;i<nn;i++){
00089                 vte_terminal_feed_child(VTE_TERMINAL(vtes[i]), txt, strlen(txt));
00090         }
00091         return;
00092 //      g_signal_handler_disconnect(vte, handler);
00093 //      gtk_widget_destroy(vte);
00094 }
00095 
00096 void window3::compile_and_execute(bool docompile, bool doexecute, bool dolog,int nn,std::string command,std::string args){
00097         this->nn = nn;
00098         this->command = command;
00099         this->doexecute = doexecute;
00100         this->dolog = dolog;
00101         this->args = args;
00102         int pos = command.find_last_of("/");
00103         s = command.substr(0, pos + 1);
00104         std::string cd("cd"), touch("touch");
00105         cd = cd + " " + s + "\n";
00106         touch = touch + " " + s;
00107         std::string alias = "";
00108         if (docompile){
00109                 int ret = system(touch.c_str());
00110                 if (ret !=0){
00111                         fprintf(stderr,"Error executing %s\n",touch.c_str());
00112                 }
00113                 vte_terminal_feed_child(VTE_TERMINAL(vte), cd.c_str(), strlen(cd.c_str()));
00114                 std::string alias = "alias make=\"touch lock && make && sleep 2 && rm lock\"\n";
00115                 vte_terminal_feed_child(VTE_TERMINAL(vte), alias.c_str(), strlen(alias.c_str()));
00116                 vte_terminal_feed_child(VTE_TERMINAL(vte), "make\n", strlen("make\n"));
00117         }
00118         if (doexecute){
00119                 alias = "alias wce=\"while test -f lock ; do echo waiting compilation; sleep 1 ; done\"\n";
00120                 for (int i=0;i<used;i++){
00121                         std::string cmd = command;
00122                         std::ostringstream s1,s2;
00123                         s1 << i;
00124                         s2 << nn;
00125                         std::string rep = args;
00126                         int pos = rep.find_first_of("%i",0);
00127                         rep.replace(pos,2,s1.str());
00128                         pos = rep.find_first_of("%n",0);
00129                         rep.replace(pos,2,s2.str());
00130                         cmd = "wce && " + cmd + " " + rep + "\n";
00131                         vte_terminal_feed_child(VTE_TERMINAL(vtes[i]), alias.c_str(), strlen(alias.c_str()));
00132                         vte_terminal_feed_child(VTE_TERMINAL(vtes[i]), cd.c_str(), strlen(cd.c_str()));
00133                         vte_terminal_feed_child(VTE_TERMINAL(vtes[i]), cmd.c_str(), strlen(cmd.c_str()));
00134                 }
00135         }
00136 }
00137 
00138 void window3::execute(){
00139 }
00140 
00141 window3::window3() : window3_glade(){
00142         vte = vte_terminal_new();
00143         vte_terminal_set_background_transparent(VTE_TERMINAL(vte), FALSE);
00144         vte_terminal_set_size(VTE_TERMINAL(vte), 80, 25);
00145         vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL (vte), TRUE);
00146         gtk_container_add(GTK_CONTAINER(align->gobj()), vte);
00147         gtk_widget_show(vte);
00148         //handler = g_signal_connect(vte, "child-exited", G_CALLBACK(func), (void *) this);
00149         vte_terminal_fork_command(VTE_TERMINAL(vte), NULL, NULL, NULL,
00150                                                         NULL, FALSE, FALSE, FALSE);
00151         created = used = 0;
00152         for (int i=0;i<20;i++){
00153                 vtes[i] = vte_terminal_new();
00154                 vte_terminal_fork_command(VTE_TERMINAL(vtes[i]), NULL, NULL, NULL,
00155                                                                 NULL, FALSE, FALSE, FALSE);
00156         }
00157 
00158 }
00159 
00160 
00161 void window3::create(int nn) {
00162         for (int i = created; i < nn ; i++){
00163 
00164                 std::ostringstream oss;
00165                 oss << "N#" << i;
00166 
00167                 Gtk::Alignment * align;
00168                 Gtk::Label * label;
00169                 Gtk::Label * nblabel;
00170 
00171                 align = Gtk::manage(new class Gtk::Alignment(0.5, 0.5, 1, 1));
00172                 label = Gtk::manage(new class Gtk::Label(_("")));
00173                 Gtk::Frame *frame15 = Gtk::manage(new class Gtk::Frame());
00174                 nblabel = Gtk::manage(new class Gtk::Label(_(oss.str())));
00175                 label->set_alignment(0.5, 0.5);
00176                 label->set_padding(0, 0);
00177                 label->set_justify(Gtk::JUSTIFY_LEFT);
00178                 label->set_line_wrap(false);
00179                 label->set_use_markup(true);
00180                 label->set_selectable(false);
00181                 frame15->set_shadow_type(Gtk::SHADOW_NONE);
00182                 frame15->set_label_align(0, 0.5);
00183                 frame15->add(*align);
00184                 frame15->set_label_widget(*label);
00185                 nblabel->set_alignment(0.5, 0.5);
00186                 nblabel->set_padding(0, 0);
00187                 nblabel->set_justify(Gtk::JUSTIFY_LEFT);
00188                 nblabel->set_line_wrap(false);
00189                 nblabel->set_use_markup(false);
00190                 nblabel->set_selectable(false);
00191                 notebook1->set_flags(Gtk::CAN_FOCUS);
00192                 notebook1->set_show_tabs(true);
00193                 notebook1->set_show_border(true);
00194                 notebook1->set_tab_pos(Gtk::POS_TOP);
00195                 notebook1->set_scrollable(false);
00196                 notebook1->append_page(*frame15, *nblabel);
00197                 notebook1->pages().back().set_tab_label_packing(false, true,
00198                                 Gtk::PACK_START);
00199                 align->show();
00200                 label->show();
00201                 frame15->show();
00202                 nblabel->show();
00203                 notebook1->show();
00204 
00205                 //vtes[i] = vte_terminal_new();
00206                 vte_terminal_set_background_transparent(VTE_TERMINAL(vtes[i]), FALSE);
00207         vte_terminal_set_size(VTE_TERMINAL(vtes[i]), 80, 25);
00208                 vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL (vtes[i]), TRUE);
00209                 gtk_container_add(GTK_CONTAINER(align->gobj()), vtes[i]);
00210                 gtk_widget_show(vtes[i]);
00211 
00212 //              vte_terminal_fork_command(VTE_TERMINAL(vtes[i]), NULL, NULL, NULL,
00213 //                                              NULL, FALSE, FALSE, FALSE);
00214 
00215 /*              int idx = 0, j = 0, pos;
00216                 std::string args = this->args;
00217                 pos = args.find_first_of(' ', idx);
00218                 while (pos != std::string::npos) {
00219                         std::string val = args.substr(idx, pos - idx);
00220                         argv[j + 1] = (char *) malloc(256 * sizeof(char));
00221                         if (val.compare("%i") == 0) {
00222                                 sprintf(argv[j + 1], "%d", i);
00223                         } else if (val.compare("%n") == 0) {
00224                                 sprintf(argv[j + 1], "%d", nn);
00225                         } else {
00226                                 sprintf(argv[j + 1], "%s", val.c_str());
00227                         }
00228                         idx = pos + 1;
00229                         pos = args.find_first_of(' ', idx);
00230 
00231                         j++;
00232                 }
00233                 argv[j + 1] = 0;
00234                 fprintf(stderr, "argv[%d]=0\n", i);
00235                 //pids[i] = vte_terminal_fork_command(VTE_TERMINAL(vtes[i]), command.c_str(), argv, NULL,
00236                 //s.c_str(), FALSE, FALSE, FALSE);
00237         */
00238         }
00239         used = nn;
00240         created = nn;
00241 }


ros_rt_wmp_sniffer
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Mon Oct 6 2014 08:27:57