Skip to content

Commit

Permalink
Use abstract function pointer instead of c-style casting
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai-Zhang committed Sep 14, 2015
1 parent 32e91b5 commit f4af5fa
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sdk/ins_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ extern "C" {
typedef void (*SessionTimeoutCallback)(void*);
typedef void (*CWatchCallback)(WatchParam*, long, SDKError);
typedef void (*CTimeoutCallback)(long, void*);
typedef void (*AbstractFunc)();

struct CallbackPack {
void* callback_wrapper;
AbstractFunc callback_wrapper;
long callback_id;
void* ctx;
};
Expand Down Expand Up @@ -115,7 +116,7 @@ bool SDKWatch(InsSDK* sdk, const char* key, CWatchCallback wrapper,
return false;
}
CallbackPack* pack = new CallbackPack;
pack->callback_wrapper = (void*)(wrapper);
pack->callback_wrapper = reinterpret_cast<AbstractFunc>(wrapper);
pack->callback_id = callback_id;
pack->ctx = context;
return sdk->Watch(key, WatchCallbackWrapper, pack, error);
Expand Down Expand Up @@ -198,7 +199,7 @@ void SDKRegisterSessionTimeout(InsSDK* sdk, SessionTimeoutCallback handle_sessio
return;
}
CallbackPack* pack = new CallbackPack();
pack->callback_wrapper = (void*)(handle_session_timeout);
pack->callback_wrapper = reinterpret_cast<AbstractFunc>(handle_session_timeout);
pack->callback_id = callback_id;
pack->ctx = ctx;
sdk->RegisterSessionTimeout(handle_session_timeout, ctx);
Expand Down

0 comments on commit f4af5fa

Please sign in to comment.