-
-
[求助]大家帮我分析一下这几个类
-
发表于: 2011-1-21 09:13 2719
-
这只是一个注册表的添加删除用的。不知道为什么要多加入两个基类
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
// -=- RegConfig.h
// Class which monitors the registry and reads in the registry settings
// whenever they change, or are added or removed.
#ifndef __RFB_WIN32_REG_CONFIG_H__
#define __RFB_WIN32_REG_CONFIG_H__
#include <rfb/Threading.h>
#include <rfb/Configuration.h>
#include <rfb_win32/Registry.h>
#include <rfb_win32/EventManager.h>
#include <rfb_win32/Handle.h>
namespace rfb {
namespace win32 {
class RegConfig : EventHandler {
public:
RegConfig(EventManager* em);
~RegConfig();
// Specify the registry key to read Configuration items from
bool setKey(const HKEY rootkey, const TCHAR* keyname);
// Support for a callback, run in the RegConfig host thread whenever
// the registry configuration changes
// 这里说是回调,不明白他是怎么回调的。回调的哪个函数。
class Callback {
public:
virtual ~Callback() {}
virtual void regConfigChanged() = 0;
};
void setCallback(Callback* cb) { callback = cb; }
// Read entries from the specified key into the Configuration
static void loadRegistryConfig(RegKey& key);
protected:
// EventHandler interface and trigger event
virtual void processEvent(HANDLE event);
EventManager* eventMgr;
Handle event;
Callback* callback;
RegKey key;
};
class RegConfigThread : Thread {
public:
RegConfigThread();
~RegConfigThread();
// Start the thread, reading from the specified key
bool start(const HKEY rootkey, const TCHAR* keyname);
protected:
void run();
Thread* join();
EventManager eventMgr;
RegConfig config;
};
};
};
#endif // __RFB_WIN32_REG_CONFIG_H__
***************************************************8
下面是EventHandler,EventManager两个类。
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
// -=- EventManager.h
// Win32 event manager. Caller supplies event & handler pairs and
// then uses getMessage() in place of ::GetMessage() in the main
// loop. EventManager calls the event handler whenever the event
// is set.
// Ownership of events remains with the caller.
// It is the responsibility of handlers to reset events.
#ifndef __RFB_WIN32_EVENT_MGR_H__
#define __RFB_WIN32_EVENT_MGR_H__
#include <rfb_win32/Win32Util.h>
namespace rfb {
namespace win32 {
class EventHandler {
public:
virtual ~EventHandler() {}
virtual void processEvent(HANDLE event) = 0;
};
class EventManager {
public:
EventManager();
virtual ~EventManager();
// Add a Win32 event & handler for it
// NB: The handler must call ResetEvent on the event.
// NB: The caller retains ownership of the event.
// 添加一个事件
virtual bool addEvent(HANDLE event, EventHandler* ecb);
// Remove a Win32 event
virtual void removeEvent(HANDLE event);
// getMessage
// Waits for a message to become available on the thread's message queue,
// and returns it. If any registered events become set while waiting then
// their handlers are called before returning.
// Returns zero if the message is WM_QUIT, -1 in case of error, >0 otherwise.
virtual BOOL getMessage(MSG* msg, HWND hwnd, UINT minMsg, UINT maxMsg);
protected:
// checkTimeouts
// Derived classes should override this to perform any extra processing,
// returning the maximum number of milliseconds after which the callback
// should be called again.
virtual int checkTimeouts();
HANDLE events[MAXIMUM_WAIT_OBJECTS];
EventHandler* handlers[MAXIMUM_WAIT_OBJECTS-1];
int eventCount;
};
};
};
#endif
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
// -=- RegConfig.h
// Class which monitors the registry and reads in the registry settings
// whenever they change, or are added or removed.
#ifndef __RFB_WIN32_REG_CONFIG_H__
#define __RFB_WIN32_REG_CONFIG_H__
#include <rfb/Threading.h>
#include <rfb/Configuration.h>
#include <rfb_win32/Registry.h>
#include <rfb_win32/EventManager.h>
#include <rfb_win32/Handle.h>
namespace rfb {
namespace win32 {
class RegConfig : EventHandler {
public:
RegConfig(EventManager* em);
~RegConfig();
// Specify the registry key to read Configuration items from
bool setKey(const HKEY rootkey, const TCHAR* keyname);
// Support for a callback, run in the RegConfig host thread whenever
// the registry configuration changes
// 这里说是回调,不明白他是怎么回调的。回调的哪个函数。
class Callback {
public:
virtual ~Callback() {}
virtual void regConfigChanged() = 0;
};
void setCallback(Callback* cb) { callback = cb; }
// Read entries from the specified key into the Configuration
static void loadRegistryConfig(RegKey& key);
protected:
// EventHandler interface and trigger event
virtual void processEvent(HANDLE event);
EventManager* eventMgr;
Handle event;
Callback* callback;
RegKey key;
};
class RegConfigThread : Thread {
public:
RegConfigThread();
~RegConfigThread();
// Start the thread, reading from the specified key
bool start(const HKEY rootkey, const TCHAR* keyname);
protected:
void run();
Thread* join();
EventManager eventMgr;
RegConfig config;
};
};
};
#endif // __RFB_WIN32_REG_CONFIG_H__
***************************************************8
下面是EventHandler,EventManager两个类。
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
// -=- EventManager.h
// Win32 event manager. Caller supplies event & handler pairs and
// then uses getMessage() in place of ::GetMessage() in the main
// loop. EventManager calls the event handler whenever the event
// is set.
// Ownership of events remains with the caller.
// It is the responsibility of handlers to reset events.
#ifndef __RFB_WIN32_EVENT_MGR_H__
#define __RFB_WIN32_EVENT_MGR_H__
#include <rfb_win32/Win32Util.h>
namespace rfb {
namespace win32 {
class EventHandler {
public:
virtual ~EventHandler() {}
virtual void processEvent(HANDLE event) = 0;
};
class EventManager {
public:
EventManager();
virtual ~EventManager();
// Add a Win32 event & handler for it
// NB: The handler must call ResetEvent on the event.
// NB: The caller retains ownership of the event.
// 添加一个事件
virtual bool addEvent(HANDLE event, EventHandler* ecb);
// Remove a Win32 event
virtual void removeEvent(HANDLE event);
// getMessage
// Waits for a message to become available on the thread's message queue,
// and returns it. If any registered events become set while waiting then
// their handlers are called before returning.
// Returns zero if the message is WM_QUIT, -1 in case of error, >0 otherwise.
virtual BOOL getMessage(MSG* msg, HWND hwnd, UINT minMsg, UINT maxMsg);
protected:
// checkTimeouts
// Derived classes should override this to perform any extra processing,
// returning the maximum number of milliseconds after which the callback
// should be called again.
virtual int checkTimeouts();
HANDLE events[MAXIMUM_WAIT_OBJECTS];
EventHandler* handlers[MAXIMUM_WAIT_OBJECTS-1];
int eventCount;
};
};
};
#endif
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课
赞赏
他的文章
看原图
赞赏
雪币:
留言: