00001
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __GizmoDaemon_h
00030 #define __GizmoDaemon_h
00031
00032 #if HAVE_CONFIG_H
00033 #include "config.h"
00034 #endif
00035
00036 #include "GizmodEventHandlerInterface.hpp"
00037 #include "GizmoUtils.hpp"
00038 #include "../libGizmod/Alsa.hpp"
00039 #include "../libGizmod/CPUUsage.hpp"
00040 #include "../libGizmod/Gizmo.hpp"
00041 #include "../libGizmod/GizmoClient.hpp"
00042 #include "../libGizmod/GizmodShared.hpp"
00043 #include "../libGizmod/Processes.hpp"
00044 #include "../libGizmod/X11FocusWatcher.hpp"
00045 #include "../libH/FileEventWatcher.hpp"
00046 #include "../libH/SignalHandler.hpp"
00047 #include "../libH/SocketServer.hpp"
00048 #include <ext/hash_map>
00049 #include <map>
00050 #include <string>
00051 #include <boost/python.hpp>
00052 #include <boost/shared_ptr.hpp>
00053 #include <boost/thread/mutex.hpp>
00054
00055 using namespace Gizmod;
00056
00058
00060
00062
00064
00070 class GizmoDaemon :
00071 public GizmodShared,
00072 public H::FileEventWatcher,
00073 private H::SignalHandler,
00074 public X11FocusWatcher,
00075 public Alsa,
00076 public Processes,
00077 public CPUUsage,
00078 public SocketServer,
00079 public GizmoClient,
00080 public GizmoUtils
00081 {
00082 public:
00083
00084 bool checkVersion(double Version, bool Strict);
00085 void enterLoop();
00086 X11FocusEvent getCurrentFocus();
00087 bool getDebugEnabled();
00088 GizmodEventHandlerInterface * getDispatcher();
00089 boost::shared_ptr<Gizmo> getGizmoByFileName(std::string FileName);
00090 int getNumGizmosByClass(GizmoClass Class);
00091 bool getReloadConfig();
00092 bool getUseKeyboardLEDs();
00093 bool getUseRemoteControl();
00094 double getVersion();
00095 void initGizmod();
00096 bool initialize(int argc, char ** argv);
00097 void printNiceScriptInit(int Width, std::string Text1, std::string Text2, std::string Text3);
00098 void signalShutdown();
00099
00100
00101 GizmoDaemon();
00102 virtual ~GizmoDaemon();
00103
00104 private:
00105
00106 void deleteGizmo(std::string FileName);
00107 void deserializeMessage(GizmoEventClass EventClass, std::string const & Message);
00108 void deserializeMessageATIX10(std::string const & Message);
00109 void deserializeMessageCPUUsage(std::string const & Message);
00110 void deserializeMessageLIRC(std::string const & Message);
00111 void deserializeMessagePowermate(std::string const & Message);
00112 void deserializeMessageSoundcard(std::string const & Message);
00113 void deserializeMessageSoundVisualization(std::string const & Message);
00114 void deserializeMessageStandard(std::string const & Message);
00115 void deserializeMessageWindowFocus(std::string const & Message);
00116 int getGizmoClassID(GizmoClass Class);
00117 std::string getProps();
00118 std::string getUserScriptDirPaths();
00119 void handleFileEventReadATIX10(GizmoATIX10 & pGizmo, DynamicBuffer<char> const & ReadBuffer);
00120 void handleFileEventReadLIRC(GizmoLIRC & pGizmo, DynamicBuffer<char> const & ReadBuffer);
00121 void handleFileEventReadPowermate(GizmoPowermate & pGizmo, DynamicBuffer<char> const & ReadBuffer);
00122 void handleFileEventReadStandard(GizmoStandard & pGizmo, DynamicBuffer<char> const & ReadBuffer);
00123 void initPython();
00124 void loadUserScripts();
00125 void loadUserScriptsFunctor(std::string UserScript);
00126 virtual void onAlsaEventMixerElementAttach(AlsaEvent const & Event, AlsaSoundCard const & SoundCard, AlsaMixer const & Mixer);
00127 virtual void onAlsaEventMixerElementChange(AlsaEvent const & Event, AlsaSoundCard const & SoundCard, AlsaMixer const & Mixer);
00128 virtual void onAlsaEventMixerElementDetach(AlsaEvent const & Event, AlsaSoundCard const & SoundCard, AlsaMixer const & Mixer);
00129 virtual void onAlsaEventSoundCardAttach(AlsaEvent const & Event, AlsaSoundCard const & SoundCard);
00130 virtual void onAlsaEventSoundCardDetach(AlsaEvent const & Event, AlsaSoundCard const & SoundCard);
00131 virtual void onCPUUsage(std::vector< boost::shared_ptr<CPUUsageInfo> > const & Event);
00132 virtual void onFileEventCreate(boost::shared_ptr<H::FileWatchee> pWatchee, std::string FullPath, std::string FileName);
00133 virtual void onFileEventDelete(boost::shared_ptr<H::FileWatchee> pWatchee, std::string FullPath, std::string FileName);
00134 virtual void onFileEventDisconnect(boost::shared_ptr<H::FileWatchee> pWatchee);
00135 virtual void onFileEventRead(boost::shared_ptr<H::FileWatchee> pWatchee, DynamicBuffer<char> const & ReadBuffer);
00136 virtual void onFileEventRegister(boost::shared_ptr<H::FileWatchee> pWatchee);
00137 virtual void onFileEventWatchBegin();
00138 virtual void onFileEventWatchEnd();
00139 virtual void onFocusIn(X11FocusEvent const & Event);
00140 virtual void onFocusOut(X11FocusEvent const & Event);
00141 virtual void onSignalSegv();
00142 virtual void onSignalInt();
00143 virtual void onSignalHup();
00144 virtual void onSignalQuit();
00145 virtual void onSignalKill();
00146 virtual void onSignalTerm();
00147 virtual void onSignalStop();
00148 virtual void onSignalUnknown(int Signal);
00149 virtual void onSocketClientConnect(Socket const & socket);
00150 virtual void onSocketClientDisconnect(Socket const & socket);
00151 virtual void onSocketClientMessage(Socket const & socket, std::string const & Message);
00152 virtual void onSocketClientRead(Socket const & socket, DynamicBuffer<char> & ReadBuffer);
00153 virtual void onSocketServerConnect(boost::shared_ptr<Socket> pSocket);
00154 virtual void onSocketServerDisconnect(Socket const & socket);
00155 virtual void onSocketServerMessage(Socket const & socket, std::string const & Message);
00156 virtual void onSocketServerRead(Socket const & socket, DynamicBuffer<char> & ReadBuffer);
00157 void registerDevices();
00158 void registerInputEventDevices();
00159 void registerLircDevice();
00160 void setConfigDir();
00161 void setVersionInfo();
00162
00163
00164 std::string mClientHost;
00165 int mClientPort;
00166 std::string mConfigDir;
00167 X11FocusEvent mCurrentFocus;
00168 bool mDisabledALSA;
00169 bool mDisabledCPUUsage;
00170 bool mDisabledX11;
00171 bool mDisableShutdownMessage;
00172 std::string mEventsDir;
00173 std::map< std::string, boost::shared_ptr<Gizmo> > mGizmos;
00174 bool mInitialized;
00175 std::string mLircDev;
00176 bool mLocalDisabled;
00177 GizmodEventHandlerInterface * mpPyDispatcher;
00178 boost::python::object mPyMainModule;
00179 boost::python::object mPyMainNamespace;
00180 bool mReloadConfig;
00181 bool mServerEnabled;
00182 int mServerPort;
00183 bool mShuttingDown;
00184 bool mUseKeyboardLEDs;
00185 bool mUseRemoteControl;
00186 double mVersion;
00187 int mVersionMajor;
00188 int mVersionMinor;
00189 };
00190
00191 #endif // __GizmoDaemon_h