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 printNiceScriptRegister(int Width, std::string Text1, std::string Text2, std::string Text3, std::string Text4, std::string Text5);
00099 void signalShutdown();
00100
00101
00102 GizmoDaemon();
00103 virtual ~GizmoDaemon();
00104
00105 private:
00106
00107 void deleteGizmo(std::string FileName);
00108 void deserializeMessage(GizmoEventClass EventClass, std::string const & Message);
00109 void deserializeMessageATIX10(std::string const & Message);
00110 void deserializeMessageCPUUsage(std::string const & Message);
00111 void deserializeMessageLIRC(std::string const & Message);
00112 void deserializeMessagePowermate(std::string const & Message);
00113 void deserializeMessageSoundcard(std::string const & Message);
00114 void deserializeMessageSoundVisualization(std::string const & Message);
00115 void deserializeMessageStandard(std::string const & Message);
00116 void deserializeMessageWindowFocus(std::string const & Message);
00117 int getGizmoClassID(GizmoClass Class);
00118 std::string getProps();
00119 std::string getUserScriptDirPaths();
00120 void handleFileEventReadATIX10(GizmoATIX10 & pGizmo, DynamicBuffer<char> const & ReadBuffer);
00121 void handleFileEventReadLIRC(GizmoLIRC & pGizmo, DynamicBuffer<char> const & ReadBuffer);
00122 void handleFileEventReadPowermate(GizmoPowermate & pGizmo, DynamicBuffer<char> const & ReadBuffer);
00123 void handleFileEventReadStandard(GizmoStandard & pGizmo, DynamicBuffer<char> const & ReadBuffer);
00124 void initPython();
00125 void loadUserScripts();
00126 void loadUserScriptsFunctor(std::string UserScript);
00127 virtual void onAlsaEventMixerElementAttach(AlsaEvent const & Event, AlsaSoundCard const & SoundCard, AlsaMixer const & Mixer);
00128 virtual void onAlsaEventMixerElementChange(AlsaEvent const & Event, AlsaSoundCard const & SoundCard, AlsaMixer const & Mixer);
00129 virtual void onAlsaEventMixerElementDetach(AlsaEvent const & Event, AlsaSoundCard const & SoundCard, AlsaMixer const & Mixer);
00130 virtual void onAlsaEventSoundCardAttach(AlsaEvent const & Event, AlsaSoundCard const & SoundCard);
00131 virtual void onAlsaEventSoundCardDetach(AlsaEvent const & Event, AlsaSoundCard const & SoundCard);
00132 virtual void onCPUUsage(std::vector< boost::shared_ptr<CPUUsageInfo> > const & Event);
00133 virtual void onFileEventCreate(boost::shared_ptr<H::FileWatchee> pWatchee, std::string FullPath, std::string FileName);
00134 virtual void onFileEventDelete(boost::shared_ptr<H::FileWatchee> pWatchee, std::string FullPath, std::string FileName);
00135 virtual void onFileEventDisconnect(boost::shared_ptr<H::FileWatchee> pWatchee);
00136 virtual void onFileEventRead(boost::shared_ptr<H::FileWatchee> pWatchee, DynamicBuffer<char> const & ReadBuffer);
00137 virtual void onFileEventRegister(boost::shared_ptr<H::FileWatchee> pWatchee);
00138 virtual void onFileEventWatchBegin();
00139 virtual void onFileEventWatchEnd();
00140 virtual void onFocusIn(X11FocusEvent const & Event);
00141 virtual void onFocusOut(X11FocusEvent const & Event);
00142 virtual void onSignalSegv();
00143 virtual void onSignalInt();
00144 virtual void onSignalHup();
00145 virtual void onSignalQuit();
00146 virtual void onSignalKill();
00147 virtual void onSignalTerm();
00148 virtual void onSignalStop();
00149 virtual void onSignalUnknown(int Signal);
00150 virtual void onSocketClientConnect(Socket const & socket);
00151 virtual void onSocketClientDisconnect(Socket const & socket);
00152 virtual void onSocketClientMessage(Socket const & socket, std::string const & Message);
00153 virtual void onSocketClientRead(Socket const & socket, DynamicBuffer<char> & ReadBuffer);
00154 virtual void onSocketServerConnect(boost::shared_ptr<Socket> pSocket);
00155 virtual void onSocketServerDisconnect(Socket const & socket);
00156 virtual void onSocketServerMessage(Socket const & socket, std::string const & Message);
00157 virtual void onSocketServerRead(Socket const & socket, DynamicBuffer<char> & ReadBuffer);
00158 void registerDevices();
00159 void registerInputEventDevices();
00160 void registerLircDevice();
00161 void setConfigDir();
00162 void setVersionInfo();
00163
00164
00165 std::string mClientHost;
00166 int mClientPort;
00167 std::string mConfigDir;
00168 X11FocusEvent mCurrentFocus;
00169 bool mDisabledALSA;
00170 bool mDisabledCPUUsage;
00171 bool mDisabledX11;
00172 bool mDisableShutdownMessage;
00173 std::string mEventsDir;
00174 std::map< std::string, boost::shared_ptr<Gizmo> > mGizmos;
00175 bool mInitialized;
00176 std::string mLircDev;
00177 bool mLocalDisabled;
00178 GizmodEventHandlerInterface * mpPyDispatcher;
00179 boost::python::object mPyMainModule;
00180 boost::python::object mPyMainNamespace;
00181 bool mReloadConfig;
00182 bool mServerEnabled;
00183 int mServerPort;
00184 bool mShuttingDown;
00185 bool mUseKeyboardLEDs;
00186 bool mUseRemoteControl;
00187 double mVersion;
00188 int mVersionMajor;
00189 int mVersionMinor;
00190 };
00191
00192 #endif // __GizmoDaemon_h