Changeset 90

Show
Ignore:
Timestamp:
07/23/08 17:42:16 (4 months ago)
Author:
enrgar
Message:

2008-07-23 Enrique Garcia <kike+glkm@…>

  • gui/src/host.* :

+ Now adds and synchronized process by using atribute synchronized.
+ Now delete processes.
+ Debug info added for printing processes.

  • gui/src/hal-parser.* :

+ Now parse and adds and synchronized process. Now adding and

deleting processes is a Host resposability.

  • gui/src/linux-kernel-monitor-client.* :

+ Added class LinuxKernelMonitorClient?.

Implements get_all_processes D-Bus method from hal addon interface
org::freedesktop::Hal::Device::LinuxKernelMonitor? .

  • gui/src/linux-kernel-monitor-client-proxy.hpp:

+ Added class LinuxKernelMonitorClientProxy?.

This file is generated using dbusmm-xml2cpp from xml hal addon interface
(org::freedesktop::Hal::Device::LinuxKernelMonitor?).

  • gui/src/tree-view-host.* :

+ Added TreeStore? column to support PPID.
+ Added on_process_deleted signal action.
+ Remodeled on_process_added signal action.
+ Added find_process, find_process_parent, find_process_by_PID_from_here.

  • gui/src/hal-controller.* :

+ Takes control of LinuxKernelMonitorClient? .

  • gui/src/hal-manager-proxy.* :

+ Lost responsability get_all_processes.
+ Added get_device_udi.

  • gui/src/notebook-page-host.cpp :

+ Now connects on_process_removed signal.

  • gui/src/process.* :

+ Now implements synchronized attribute.

  • gui/src/hal-device-proxy.* :

+ Now implements get_property_string from hal device interface.

  • gui/src/controller.* :

+ Minor edits.

  • gui/src/main-window.* :

+ Minor edits.

  • gui/src/Makefile.am :

+ Added new classes to glkm objetive.

  • gui/data/glkm.glade :

+ Minor edits.

Location:
trunk/gui/src
Files:
3 added
20 modified

Legend:

Unmodified
Added
Removed
  • trunk/gui/src/Makefile.am

    r87 r90  
    5959        notebook-page-host.cpp \ 
    6060        hal-parser.hpp \ 
    61         hal-parser.cpp 
     61        hal-parser.cpp \ 
     62        linux-kernel-monitor-client.hpp \ 
     63        linux-kernel-monitor-client.cpp 
    6264 
    6365#glkm_CFLAGS= \ 
  • trunk/gui/src/controller.cpp

    r87 r90  
    6060} 
    6161 
    62 void Controller::action_host_refresh() { 
     62void Controller::action_host_synchronize() { 
    6363        Gtk::Notebook::PageList::iterator current_page_it; 
    6464        current_page_it = _pNotebookHosts->get_current(); 
     
    6868        Host * present_host;     
    6969        present_host = current_page->get_my_Host(); 
    70         PRINTD("Controller:: refresh=" + present_host->get__hostname()); 
     70        PRINTD("Controller:: synchronize=" + present_host->get__hostname()); 
    7171        present_host->get_all_processes(); 
    7272} 
  • trunk/gui/src/controller.hpp

    r87 r90  
    3232        void action_host_selected(); 
    3333        void action_host_connect(); 
    34         void action_host_refresh(); 
     34        void action_host_synchronize(); 
    3535        static Controller & instance(); 
    3636        void set__pIconViewHosts(IconViewHosts * value); 
  • trunk/gui/src/hal-controller.cpp

    r87 r90  
    2525#include "hal-manager-proxy.hpp" 
    2626#include "host.hpp" 
     27#include "linux-kernel-monitor-client.hpp" 
    2728 
    2829HalController::HalController(): 
    29 //      _connection(DBus::Connection::SystemBus()) 
    3030        _dispatcher() 
    3131{ 
     
    4040        } 
    4141        catch (const DBus::Error& exception){ 
    42                 std::cerr << "Connection" << std::endl; 
     42                std::cerr << "HalController(): Connection" << std::endl; 
    4343                std::cerr << exception.what() << std::endl; 
    4444                std::cerr << exception.name() << std::endl; 
     
    5656        _connection->exit_on_disconnect (false); 
    5757        _hal_manager = new HalManagerProxy(*_connection); 
     58     
     59        DBus::Path procmon_udi = _hal_manager->get_device_udi(); 
     60        try { 
     61                _lkm_client = new LinuxKernelMonitorClient(*_connection, procmon_udi); 
     62        } 
     63        catch (const DBus::Error& exception){ 
     64                std::cerr << "HalController() : LinuxKernelMonitorClient" << std::endl; 
     65                std::cerr << exception.what() << std::endl; 
     66                std::cerr << exception.name() << std::endl; 
     67                std::cerr << exception.message() << std::endl; 
     68        } 
     69 
     70 
    5871} 
    5972 
     
    6578 
    6679bool HalController::get_all_processes(Host & host) { 
    67         return _hal_manager->get_all_processes(host); 
     80        return _lkm_client->get_all_processes(host); 
    6881} 
  • trunk/gui/src/hal-controller.hpp

    r87 r90  
    2626class Host; 
    2727class HalManagerProxy; 
     28class LinuxKernelMonitorClient; 
    2829 
    2930class HalController { 
     
    3738        HalManagerProxy * _hal_manager; 
    3839        DBus::Glib::BusDispatcher _dispatcher; 
     40 
     41  private: 
     42        LinuxKernelMonitorClient * _lkm_client; 
    3943}; 
    4044 
  • trunk/gui/src/hal-device-proxy.cpp

    r87 r90  
    8686 
    8787/**  
    88  *  get_property: 
     88 *  get_property_string: 
    8989 *  @key: 
    9090 * 
    9191 *  HAL INFO 
    9292 *  ======== 
    93  *      Method:                 GetProperty 
    94  *  Returns:            Variant       
     93 *      Method:                 GetPropertyString 
     94 *  Returns:            String 
    9595 *  Parameters:         String key 
    9696 *  Throws:                     NoSuchProperty 
     
    105105 * 
    106106 */ 
    107 DBus::Variant HalDeviceProxy::get_property(const DBus::String & key) { 
     107DBus::String HalDeviceProxy::get_property_string(const DBus::String & key) { 
    108108        DBus::CallMessage call; 
    109109        DBus::MessageIter wi = call.writer(); 
    110110         
    111111        wi << key; 
    112         call.member("GetProperty"); 
     112        call.member("GetPropertyString"); 
    113113 
    114114        //declaret out of try. scope solution  
     
    116116        try { 
    117117                        DBus::Message reply = invoke_method(call); 
    118                 it = reply.reader(); 
     118                        it = reply.reader(); 
    119119        } 
    120120        catch (const DBus::Error& exception){ 
    121                         std::cerr << "GetProperty" << std::endl; 
     121                        std::cerr << "GetPropertyString" << std::endl; 
    122122                        std::cerr << exception.what() << std::endl; 
    123                 std::cerr << exception.name() << std::endl; 
     123                        std::cerr << exception.name() << std::endl; 
    124124                std::cerr << exception.message() << std::endl; 
    125125        } 
    126126 
    127         DBus::Variant argout; 
    128     it >> argout; 
     127        DBus::String argout; 
     128        it >> argout;    
    129129 
    130130        return argout;   
  • trunk/gui/src/hal-device-proxy.hpp

    r87 r90  
    4040        virtual ~HalDeviceProxy(); 
    4141 
    42         DBus::Variant get_property(const DBus::String & key); 
     42        DBus::String get_property_string(const DBus::String & key); 
    4343        VectorString get_property_string_list(const DBus::String & key); 
    4444        bool rescan(); 
    4545        bool get_all_properties() throw(DBus::Error); 
    46          
     46 
    4747private: 
    4848        void on_property_modified(const DBus::SignalMessage & sig ); 
  • trunk/gui/src/hal-manager-proxy.cpp

    r87 r90  
    1919#include <dbusmm/types.h> 
    2020 
     21 
    2122#include "hal-manager-proxy.hpp" 
    22 #include "host.hpp" 
    23 #include "hal-parser.hpp" 
    2423 
    2524#include "config.h" 
    2625#include "debug.hpp" 
    27  
    28  
    29 #define DBUS_TYPE_STRUCT        ((int) 'r') 
    30 #define DBUS_TYPE_STRING        ((int) 's') 
    31 #define DBUS_TYPE_ARRAY         ((int) 'a') 
    32 #define DBUS_TYPE_VARIANT       ((int) 'v') 
    33 #define DBUS_TYPE_DICT_ENTRY    ((int) 'e') 
    3426 
    3527/**  
     
    9890 
    9991/**  
    100  *  get_all_processes: 
     92 *  get_device_udi: 
    10193 * 
    10294 *  Returns: 
     
    10799 * 
    108100 */ 
    109 bool HalManagerProxy::get_all_processes(Host & host) { 
     101DBus::Path HalManagerProxy::get_device_udi() { 
     102        DBus::Path udi; 
    110103        if (_device){ 
    111 //              PRINTD("refreshing properties"); 
    112 //              _device->rescan(); 
    113                 PRINTD("getting all processess"); 
    114                 VectorString task_list = _device->get_property_string_list ("misc.task_list"); 
    115                 HalParser h; 
    116                 h.parse_add_processes (task_list, host); 
     104                udi = _device->path(); 
    117105        } else { 
    118                 PRINTD("no linux-kernel-monitor device found"); 
    119         } 
    120 } 
     106                PRINTD ("No procmon decive to get udi"); 
     107        } 
     108 
     109    return udi; 
     110} 
     111 
    121112 
    122113/**  
     
    154145} 
    155146 
     147 
    156148/**  
    157149 *  find_device_by_capability: 
  • trunk/gui/src/hal-manager-proxy.hpp

    r87 r90  
    3131#include "utils.hpp" 
    3232 
    33 class Host; 
    34 class HalParser; 
    35  
    3633class HalManagerProxy : public DBus::ObjectProxy, public DBus::InterfaceProxy { 
    3734 
     
    3936        HalManagerProxy(DBus::Connection& connection ); 
    4037        virtual ~HalManagerProxy(); 
    41         bool get_all_processes(Host & host); 
     38 
     39        DBus::Path get_device_udi(); 
    4240 
    4341  protected: 
     
    5351 
    5452#endif //_HAL_MANAGER_PROXY_HPP 
     53 
     54 
     55 
  • trunk/gui/src/hal-parser.cpp

    r87 r90  
    2323#include "hal-parser.hpp" 
    2424#include "host.hpp" 
    25 //#include "process.hpp" 
     25#include "process.hpp" 
    2626 
    2727#include "config.h" 
     
    3636 
    3737/**  
    38  *  parse_add_processes: 
    39  *  @hal_vs_processes: 
     38 *  parse_synchronize_processes: 
     39 *  @hal_task_list: 
    4040 *  @host: 
    4141 * 
     
    5252 * 
    5353 */ 
    54 void HalParser::parse_add_processes(VectorString & hal_task_list, Host & host) { 
    55  
    56 //      VectorString::iterator hal_task_list_it; 
    57 //      for(hal_task_list_it = hal_task_list.begin(); hal_task_list_it != hal_task_list.end(); ++hal_task_list_it) { 
     54void HalParser::parse_synchronize_processes(VectorString & hal_task_list, Host & host) { 
     55 
     56        host.print_processes(); 
     57        VectorString::iterator hal_task_list_it; 
     58        for(hal_task_list_it = hal_task_list.begin(); hal_task_list_it != hal_task_list.end(); ++hal_task_list_it) { 
    5859        /*  
    5960           We're going to loop processes reversed as hal_task_list goes from mayor  
     
    6162           previously created parent 
    6263         */ 
    63         VectorString::reverse_iterator hal_task_list_it; 
    64         for(hal_task_list_it = hal_task_list.rbegin(); hal_task_list_it != hal_task_list.rend(); ++hal_task_list_it) { 
     64//      VectorString::reverse_iterator hal_task_list_it; 
     65//      for(hal_task_list_it = hal_task_list.rbegin(); hal_task_list_it != hal_task_list.rend(); ++hal_task_list_it) { 
    6566                VectorString parsed_process; 
    6667                // TODO 
     
    9495                        std::cerr << exception.what() << std::endl; 
    9596                } 
     97 
     98                Process process_tmp; 
     99                process_tmp.set__PID(PID); 
     100                process_tmp.set__PPID(PPID); 
     101                process_tmp.set__name(process_name); 
     102                host.add_and_synchronize_process(process_tmp);           
     103        } 
     104        host.print_processes(); 
     105        host.delete_all_not_synchronized(); 
     106} 
     107 
     108/**  
     109 *  parse_add_processes: 
     110 *  @hal_vs_processes: 
     111 *  @host: 
     112 * 
     113 *  Returns: 
     114 * 
     115 *  Exceptions: 
     116 * 
     117 *  Example: 
     118 *           Line format gets defined in kernel module with this format: 
     119 *                              "%s:%d:%d\n", 
     120 *                              task->comm, 
     121 *                              task->pid, 
     122 *                              task->parent->pid 
     123 * 
     124 * / 
     125void HalParser::parse_add_processes(VectorString & hal_task_list, Host & host) { 
     126 
     127        VectorString::iterator hal_task_list_it; 
     128        for(hal_task_list_it = hal_task_list.begin(); hal_task_list_it != hal_task_list.end(); ++hal_task_list_it) { 
     129        /*  
     130           We're going to loop processes reversed as hal_task_list goes from mayor  
     131           to minor PID and we want to parented processes to be able to find its  
     132           previously created parent 
     133         * / 
     134//      VectorString::reverse_iterator hal_task_list_it; 
     135//      for(hal_task_list_it = hal_task_list.rbegin(); hal_task_list_it != hal_task_list.rend(); ++hal_task_list_it) { 
     136                VectorString parsed_process; 
     137                // TODO 
     138                // We use iss and iss2 because working with just one doesn't work  
     139                // as expected. This shoul be looked up. 
     140                std::istringstream iss;          
     141                std::istringstream iss2; 
     142                Glib::ustring process_name; 
     143                int PID; 
     144            int PPID; 
     145 
     146                tokenize(*hal_task_list_it, ":", parsed_process); 
     147                 
     148                //When we get a line without all of our process parameters, skip it 
     149                if (parsed_process.size() < 3) { 
     150                        std::cerr << "ERROR:: Bad formed hal line" << std::endl; 
     151                        PRINTD("HalParser ERROR:: Bad formed hal line "); 
     152                        continue; 
     153                } 
     154 
     155                // Get each process parameter into their proper variable type and look 
     156                // for errors without broken program. 
     157                // We use at() instead of [] becuase it provide us exceptions 
     158                try { 
     159                        process_name = parsed_process.at(0); 
     160                        iss.str (parsed_process.at(1)); 
     161                        iss >> PID; 
     162                        iss2.str (parsed_process.at(2)); 
     163                        iss2 >> PPID; 
     164                } catch (std::out_of_range exception){ 
     165                        std::cerr << exception.what() << std::endl; 
     166                } 
    96167                         
    97168                // Search for element with a value of PID and returns an iterator to it 
     
    112183 
    113184} 
    114  
     185*/ 
     186                 
    115187/**  
    116188 *  tokenize:       
  • trunk/gui/src/hal-parser.hpp

    r87 r90  
    2626 
    2727class Host; 
     28class Process; 
    2829 
    2930class HalParser { 
     
    3132        HalParser(); 
    3233        virtual ~HalParser(); 
    33         void parse_add_processes(VectorString & hal_task_list, Host & host); 
     34        void parse_synchronize_processes(VectorString & hal_task_list, Host & host); 
    3435 
    3536  private: 
  • trunk/gui/src/host.cpp

    r87 r90  
    6868void Host::get_all_processes() { 
    6969        bool result; 
     70        PRINTD ("Host:: getting processes " + _hostname); 
    7071        result = _hal_controller->get_all_processes(*this); 
     72} 
     73 
     74void Host::add_and_synchronize_process(Process & process) { 
     75         
     76        int PID = process.get__PID(); 
     77 
     78        // Search for element with a value of PID and returns an iterator to it 
     79        // if found. Otherwise it returns an iterator to map::end (the 
     80        // element past the end of the container). 
     81        std::map<int, Process>::iterator process_iterator; 
     82        process_iterator = _task_list.find(PID); 
     83        if ( process_iterator == _task_list.end() ) { 
     84                //Process does not exists so we have to add it 
     85                _task_list[PID] = process; 
     86                _task_list[PID].set__synchronized(true); 
     87 
     88                PRINTD("Host:: process added and sync " + _task_list[PID].get__name()); 
     89                signal_process_added.emit(_task_list[PID]); 
     90        } else { 
     91                //Process exists so we just mark it as synchonized 
     92                PRINTD("Host:: process synchronized " + _task_list[PID].get__name()); 
     93                _task_list[PID].set__synchronized(true); 
     94        } 
     95} 
     96 
     97void Host::delete_all_not_synchronized() { 
     98 
     99        std::map<int, Process>::iterator process_iterator; 
     100        for(process_iterator = _task_list.begin(); process_iterator != _task_list.end(); ) { 
     101                bool synchronized = (*process_iterator).second.get__synchronized(); 
     102                if (synchronized) { 
     103                        (*process_iterator).second.set__synchronized(false); 
     104                        ++process_iterator; 
     105                } else { 
     106                        PRINTD("Host:: process removed " + (*process_iterator).second.get__name()); 
     107                        signal_process_removed.emit( (*process_iterator).second ); 
     108                        _task_list.erase(process_iterator++); 
     109                } 
     110        } 
     111/*      for(process_iterator = _task_list.begin(); process_iterator != _task_list.end(); ++process_iterator) { 
     112                (*process_iterator).second.set__synchronized(false); 
     113        }*/ 
     114 
     115} 
     116 
     117void Host::print_processes() { 
     118        std::cout << "Host::print_processes() " << std::endl; 
     119        std::map<int, Process>::iterator process_iterator; 
     120        for(process_iterator = _task_list.begin(); process_iterator != _task_list.end(); ++process_iterator ) { 
     121                std::string sync(""); 
     122                if  ( (*process_iterator).second.get__synchronized() ){ 
     123                        sync = "true"; 
     124                } else { 
     125                        sync = "false"; 
     126                } 
     127                std::cout << (*process_iterator).first << " => ["  
     128                                        << (*process_iterator).second.get__name() << ":" 
     129                                        << (*process_iterator).second.get__PPID() << ":" 
     130                                        << sync  
     131                                        << "]" << std::endl; 
     132        } 
    71133} 
    72134 
  • trunk/gui/src/host.hpp

    r87 r90  
    4242        void connect(); 
    4343        void get_all_processes(); 
     44        void add_and_synchronize_process(Process & process); 
     45        void delete_all_not_synchronized(); 
     46 
     47        void print_processes(); 
     48 
    4449        bool get_process(int PID, Process & process); 
    4550 
     
    5459        Glib::ustring _description; 
    5560 
    56         typedef sigc::signal<void, Process> type_signal_Process_added; 
    57  
    5861        Filesystem * _filesystems; 
    5962        std::map<int, Process> _task_list; 
     
    6164        HalController * _hal_controller; 
    6265 
    63   friend class HalParser; 
    64    
     66//      friend class HalParser; 
     67 
     68        typedef sigc::signal<void, Process> type_signal_process_added; 
     69        typedef sigc::signal<void, Process> type_signal_process_removed; 
     70 
    6571  public: 
    66         type_signal_Process_added signal_Process_added; 
    67  
    68  
     72        type_signal_process_added signal_process_added; 
     73        type_signal_process_removed signal_process_removed; 
    6974}; 
    7075inline const Glib::ustring Host::get__hostname() const { 
  • trunk/gui/src/main-window.cpp

    r87 r90  
    154154                std::cerr << "** ERROR ** Maybe an error loading glade file?" << std::endl; 
    155155        }        
    156         _refPtrGlademmXml->get_widget("toolbutton_refresh", _pToolButton_Refresh); 
    157         if (_pToolButton_Refresh){ 
    158                 _pToolButton_Refresh->signal_clicked().connect( sigc::mem_fun(*this,     
    159                                                                                                                                    &MainWindow::on_clicked_toolbar_refresh) ); 
     156        _refPtrGlademmXml->get_widget("toolbutton_synchronize", _pToolButton_Synchronize); 
     157        if (_pToolButton_Synchronize){ 
     158                _pToolButton_Synchronize->signal_clicked().connect( sigc::mem_fun(*this,         
     159                                                                                                                                   &MainWindow::on_clicked_toolbar_synchronize) ); 
    160160        } else{ 
    161161                std::cerr << "** ERROR ** Maybe an error loading glade file?" << std::endl; 
     
    284284} 
    285285 
    286 void MainWindow::on_clicked_toolbar_refresh(){ 
    287         PRINTD("on_clicked_toolbar_refresh"); 
     286void MainWindow::on_clicked_toolbar_synchronize(){ 
     287        PRINTD("on_clicked_toolbar_synchronize"); 
    288288        Controller& c = Controller::instance(); 
    289         c.action_host_refresh(); 
    290 } 
    291  
     289        c.action_host_synchronize(); 
     290} 
     291 
  • trunk/gui/src/main-window.hpp

    r87 r90  
    7979        void on_clicked_toolbar_select(); 
    8080        void on_clicked_toolbar_connect(); 
    81         void on_clicked_toolbar_refresh(); 
     81        void on_clicked_toolbar_synchronize(); 
    8282                 
    8383        Gtk::Toolbar *          _pToolbar; 
    8484        Gtk::ToolButton *       _pToolButton_Select; 
    8585        Gtk::ToolButton *       _pToolButton_Connect; 
    86         Gtk::ToolButton *       _pToolButton_Refresh; 
     86        Gtk::ToolButton *       _pToolButton_Synchronize; 
    8787 
    8888        //              Main Window (Important stuff) 
  • trunk/gui/src/notebook-page-host.cpp

    r8