-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into iserialization
- Loading branch information
Showing
13 changed files
with
372 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "precomp.h" | ||
|
||
#include "appcmd.h" | ||
#include "util/assert.h" | ||
#include "panitentapp.h" | ||
|
||
int AppCmd_KeyCompare(void* pKey1, void* pKey2) { | ||
if ((UINT)pKey1 == (UINT)pKey2) { | ||
return 0; | ||
} | ||
else if ((UINT)pKey1 > (UINT)pKey2) { | ||
return 1; | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
void AppCmd_Init(AppCmd* pAppCmd) { | ||
ASSERT(pAppCmd); | ||
memset(pAppCmd, 0, sizeof(AppCmd)); | ||
|
||
HashMap* pHashMap = HashMap_Create(16, &AppCmd_KeyCompare); | ||
ASSERT(pHashMap); | ||
pAppCmd->pCmdMap = pHashMap; | ||
} | ||
|
||
void AppCmd_AddCommand(AppCmd* pAppCmd, UINT cmdId, PFNAppCmdCallback* pfnCallback) { | ||
ASSERT(pAppCmd); | ||
ASSERT(pfnCallback); | ||
HashMap_Put(pAppCmd->pCmdMap, (void*)cmdId, (void*)pfnCallback); | ||
} | ||
|
||
void AppCmd_Execute(AppCmd* pAppCmd, UINT cmdId, PanitentApp* pPanitentApp) { | ||
ASSERT(pAppCmd); | ||
PFNAppCmdCallback *pfnCallback = (PFNAppCmdCallback*)HashMap_Get(pAppCmd->pCmdMap, (void*)cmdId); | ||
ASSERT(pfnCallback); | ||
pfnCallback(pPanitentApp); | ||
} | ||
|
||
void AppCmd_Destroy(AppCmd* pAppCmd) { | ||
ASSERT(pAppCmd); | ||
HashMap_Destroy(pAppCmd->pCmdMap); | ||
pAppCmd->pCmdMap = NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef PANITENT_APPCMD_H | ||
#define PANITENT_APPCMD_H | ||
|
||
#include "util/hashmap.h" | ||
|
||
typedef struct PanitentApp PanitentApp; | ||
|
||
typedef void (PFNAppCmdCallback)(PanitentApp*); | ||
|
||
typedef struct AppCmd AppCmd; | ||
typedef struct AppCmd { | ||
HashMap* pCmdMap; | ||
}; | ||
|
||
/* Public Interface */ | ||
void AppCmd_Init(AppCmd* pAppCmd); | ||
void AppCmd_AddCommand(AppCmd* pAppCmd, UINT cmdId, PFNAppCmdCallback* pfnCallback); | ||
void AppCmd_Execute(AppCmd* pAppCmd, UINT cmdId, PanitentApp* pPanitentApp); | ||
void AppCmd_Destroy(AppCmd* pAppCmd); | ||
|
||
#endif /* PANITENT_APPCMD_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.