Fawkes API  Fawkes Development Version
handler.h
1 
2 /***************************************************************************
3  * handler.h - Fawkes plugin network handler
4  *
5  * Created: Thu Feb 12 10:23:02 2009
6  * Copyright 2006-2009 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef _PLUGIN_NET_HANDLER_H_
25 #define _PLUGIN_NET_HANDLER_H_
26 
27 #include <config/change_handler.h>
28 #include <core/threading/thread.h>
29 #include <core/utils/lock_list.h>
30 #include <core/utils/lock_map.h>
31 #include <core/utils/lock_queue.h>
32 #include <netcomm/fawkes/handler.h>
33 #include <plugin/listener.h>
34 #include <utils/system/fam.h>
35 
36 #include <list>
37 #include <map>
38 #include <string>
39 #include <utility>
40 
41 namespace fawkes {
42 
43 class ThreadCollector;
44 class FawkesNetworkHub;
45 class Plugin;
46 class PluginLoader;
47 class PluginListMessage;
48 class Configuration;
49 class FamThread;
50 
51 class PluginNetworkHandler : public fawkes::Thread,
54 {
55 public:
58 
60  virtual void client_connected(unsigned int clid);
61  virtual void client_disconnected(unsigned int clid);
62 
63  virtual void loop();
64 
65  virtual void plugin_loaded(const char *plugin_name);
66  virtual void plugin_unloaded(const char *plugin_name);
67 
68 private:
69  PluginListMessage *list_avail();
70  PluginListMessage *list_loaded();
71  void send_load_failure(const char *plugin_name, unsigned int client_id);
72  void send_load_success(const char *plugin_name, unsigned int client_id);
73  void send_unload_failure(const char *plugin_name, unsigned int client_id);
74  void send_unload_success(const char *plugin_name, unsigned int client_id);
75  void send_loaded(const char *plugin_name);
76  void send_unloaded(const char *plugin_name);
77 
78  void load(const char *plugin_list, unsigned int clid);
79  void unload(const char *plugin_list, unsigned int clid);
80 
81  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
82 protected:
83  virtual void
84  run()
85  {
86  Thread::run();
87  }
88 
89 private:
90  PluginManager * manager_;
91  FawkesNetworkHub *hub_;
92 
93  LockQueue<FawkesNetworkMessage *> inbound_queue_;
94 
95  LockList<unsigned int> subscribers_;
97 };
98 
99 } // end namespace fawkes
100 
101 #endif
fawkes::PluginManager
Definition: manager.h:51
fawkes::LockList< unsigned int >
fawkes::PluginNetworkHandler::loop
virtual void loop()
Process all network messages that have been received.
Definition: handler.cpp:265
fawkes::PluginManagerListener
Definition: listener.h:33
fawkes::FawkesNetworkHandler
Definition: handler.h:35
fawkes::PluginNetworkHandler::PluginNetworkHandler
PluginNetworkHandler(PluginManager *manager, FawkesNetworkHub *hub)
Constructor.
Definition: handler.cpp:65
fawkes::PluginNetworkHandler::~PluginNetworkHandler
~PluginNetworkHandler()
Destructor.
Definition: handler.cpp:77
fawkes::PluginNetworkHandler::handle_network_message
virtual void handle_network_message(FawkesNetworkMessage *msg)
Definition: handler.cpp:354
fawkes::PluginNetworkHandler::run
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: handler.h:88
fawkes::PluginNetworkHandler::plugin_loaded
virtual void plugin_loaded(const char *plugin_name)
Definition: handler.cpp:373
fawkes::PluginNetworkHandler::client_connected
virtual void client_connected(unsigned int clid)
Definition: handler.cpp:362
fawkes
Plugin
Plugin representation for JSON transfer.
Definition: Plugin.h:25
fawkes::PluginNetworkHandler::plugin_unloaded
virtual void plugin_unloaded(const char *plugin_name)
Definition: handler.cpp:379
fawkes::PluginListMessage
Definition: list_message.h:38
fawkes::Thread::run
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:922
fawkes::LockQueue< FawkesNetworkMessage * >
fawkes::Thread
Definition: thread.h:44
fawkes::FawkesNetworkMessage
Definition: message.h:80
fawkes::FawkesNetworkHub
Definition: hub.h:37
fawkes::PluginNetworkHandler::client_disconnected
virtual void client_disconnected(unsigned int clid)
Definition: handler.cpp:367