TEST_F(WCP, UpdateRequestCb)
{
- int callback_id;
- EXPECT_EQ(complication_provider_update_request_cb_add(providerId.c_str(), on_update_request_cb, &callback_id, NULL), 0);
- EXPECT_EQ(complication_provider_update_request_cb_del(callback_id), 0);
+ EXPECT_EQ(complication_provider_update_request_cb_add(providerId.c_str(), on_update_request_cb, NULL), 0);
+ EXPECT_EQ(complication_provider_update_request_cb_del(providerId.c_str(), on_update_request_cb, NULL), 0);
}
TEST_F(WCP, GetSupportTypes)
bundle *share_data, void *user_data);
int complication_provider_update_request_cb_add(const char *provider_id,
- on_update_request cb, int *callback_id, void *user_data);
-int complication_provider_update_request_cb_del(int callback_id);
+ on_update_request cb, void *user_data);
+int complication_provider_update_request_cb_del(const char *provider_id,
+ on_update_request cb, void *user_data);
int complication_provider_get_support_types(const char *provider_id,
int *types);
int complication_provider_notify_update(const char *provider_id);
public:
CallbackInfo(on_update_request cb, void* user_data)
: cb_(cb), user_data_(user_data) {
- callback_id = CreateCallbackID();
}
void Invoke(const std::string& provider_id, const std::string& sender_appid,
static_cast<complication_type>(type), context_data,
shared_data->GetRaw(), user_data_);
}
- int GetCallbackID() {
- return callback_id;
- }
private:
on_update_request cb_;
void* user_data_;
- int callback_id;
- static int CreateCallbackID(void) {
- static int id = 0;
- g_atomic_int_inc(&id);
-
- return id;
- }
};
class WatchComplicationProviderStub : public ComplicationProvider {
cb_list_.emplace_back(ci);
}
- bool RemoveCallbackInfo(int callback_id) {
+ void RemoveCallbackInfo(CallbackInfo* ci) {
for (auto& i : cb_list_) {
- if (i.get()->GetCallbackID() == callback_id) {
+ if (i.get() == ci) {
cb_list_.remove(i);
- return true;
+ break;
}
}
- return false;
}
private:
static std::map<std::string, WatchComplicationProviderStub*> __providers;
extern "C" EXPORT_API int complication_provider_update_request_cb_add(
- const char *provider_id, on_update_request cb, int *callback_id, void *user_data) {
- if (provider_id == NULL || cb == NULL || callback_id == NULL)
+ const char *provider_id, on_update_request cb, void *user_data) {
+ if (provider_id == NULL || cb == NULL)
return COMPLICATION_ERROR_INVALID_PARAMETER;
// TODO(?): Provider ID validation
auto ci = new CallbackInfo(cb, user_data);
ws->AddCallbackInfo(ci);
- *callback_id = ci->GetCallbackID();
- LOGI("provider_id [%s] callback_id : %d", provider_id, *callback_id);
- return COMPLICATION_ERROR_NONE;
+ return 0;
}
extern "C" EXPORT_API int complication_provider_update_request_cb_del(
- int callback_id) {
- if (callback_id <= 0)
+ const char *provider_id, on_update_request cb, void *user_data) {
+ if (provider_id == NULL || cb == NULL)
return COMPLICATION_ERROR_INVALID_PARAMETER;
- for(auto provider = __providers.begin(); provider != __providers.end(); provider++) {
- auto ps = provider->second;
- if (ps->RemoveCallbackInfo(callback_id))
- return COMPLICATION_ERROR_NONE;
- }
- LOGI("callback id [%d] is not exist", callback_id);
-
- return COMPLICATION_ERROR_INVALID_PARAMETER;
+ return 0;
}
extern "C" EXPORT_API int complication_provider_get_support_types(