diff options
| author | manuel <manuel@mausz.at> | 2013-03-09 15:14:01 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2013-03-09 15:14:01 +0100 |
| commit | 41f7119d8631a142fa5a97285a8443f9d7eb7e14 (patch) | |
| tree | 75e35bffcfc8e82c989331335e11bac0c86da131 /CallbackDispatcher.cpp | |
| download | steamcmd-41f7119d8631a142fa5a97285a8443f9d7eb7e14.tar.gz steamcmd-41f7119d8631a142fa5a97285a8443f9d7eb7e14.tar.bz2 steamcmd-41f7119d8631a142fa5a97285a8443f9d7eb7e14.zip | |
initial import of UpdateTool 0.4
Diffstat (limited to 'CallbackDispatcher.cpp')
| -rw-r--r-- | CallbackDispatcher.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/CallbackDispatcher.cpp b/CallbackDispatcher.cpp new file mode 100644 index 0000000..12b4906 --- /dev/null +++ b/CallbackDispatcher.cpp | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | /* | ||
| 2 | This file is a part of "Didrole's Update Tool" | ||
| 3 | ©2k12, Didrole | ||
| 4 | |||
| 5 | License : Public domain | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "../../Open Steamworks/Steamworks.h" | ||
| 9 | #include <map> | ||
| 10 | |||
| 11 | extern HSteamPipe g_hPipe; | ||
| 12 | |||
| 13 | |||
| 14 | std::multimap<int, CCallbackBase *> g_callbacksMap; | ||
| 15 | |||
| 16 | class Callback : public CCallbackBase | ||
| 17 | { | ||
| 18 | public: | ||
| 19 | void AddRegisteredFlag() | ||
| 20 | { | ||
| 21 | m_nCallbackFlags |= k_ECallbackFlagsRegistered; | ||
| 22 | } | ||
| 23 | }; | ||
| 24 | |||
| 25 | void STEAM_CALL SteamAPI_RegisterCallback( class CCallbackBase *pCallback, int iCallback ) | ||
| 26 | { | ||
| 27 | ((Callback*)pCallback)->AddRegisteredFlag(); | ||
| 28 | g_callbacksMap.insert(std::pair<int, CCallbackBase *>(iCallback, pCallback)); | ||
| 29 | } | ||
| 30 | |||
| 31 | void STEAM_CALL SteamAPI_UnregisterCallback( class CCallbackBase *pCallback ) | ||
| 32 | { | ||
| 33 | for(std::multimap<int, CCallbackBase *>::iterator i = g_callbacksMap.begin(); i != g_callbacksMap.end();) | ||
| 34 | { | ||
| 35 | if(i->second == pCallback) | ||
| 36 | { | ||
| 37 | g_callbacksMap.erase(i++); | ||
| 38 | } | ||
| 39 | else | ||
| 40 | i++; | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | void STEAM_CALL SteamAPI_RunCallbacks() | ||
| 45 | { | ||
| 46 | CallbackMsg_t callbackMsg; | ||
| 47 | while(Steam_BGetCallback(g_hPipe, &callbackMsg)) | ||
| 48 | { | ||
| 49 | // We are making a copy of the data to be able to call Steam_FreeLastCallback before sending the data to the callback handlers | ||
| 50 | // That will allow recursive calls to this function to work properly (ie: no infinite processing of the same callback) | ||
| 51 | |||
| 52 | unsigned char* pubData = new unsigned char[callbackMsg.m_cubParam]; | ||
| 53 | memcpy(pubData, callbackMsg.m_pubParam, callbackMsg.m_cubParam); | ||
| 54 | |||
| 55 | Steam_FreeLastCallback(g_hPipe); | ||
| 56 | |||
| 57 | std::pair<std::multimap<int,CCallbackBase *>::iterator, std::multimap<int, CCallbackBase *>::iterator> range = g_callbacksMap.equal_range(callbackMsg.m_iCallback); | ||
| 58 | |||
| 59 | for(std::multimap<int, CCallbackBase *>::const_iterator i = range.first; i != range.second; ++i) | ||
| 60 | { | ||
| 61 | i->second->Run(pubData); | ||
| 62 | } | ||
| 63 | |||
| 64 | delete[] pubData; | ||
| 65 | } | ||
| 66 | } | ||
