}
void Calendar::AddBatch(const picojson::object& args,
- picojson::object& out) {
+ picojson::array& array) {
LoggerD("enter");
-
if (!CalendarManager::GetInstance().IsConnected()) {
throw UnknownException("DB Connection failed.");
}
int type = CalendarRecord::TypeToInt(FromJson<std::string>(args, "type"));
const char* view_uri = CalendarRecord::TypeToUri(type);
+ calendar_list_h list = NULL;
+ if (CALENDAR_ERROR_NONE != calendar_list_create(&list)) {
+ LoggerE("Could not create list for batch operation");
+ throw UnknownException("Could not create list for batch operation");
+ }
+ CalendarListPtr list_ptr =
+ CalendarListPtr(list, CalendarRecord::ListDeleter);
- auto batch_func = [=](const JsonValuePtr & response)->void {
- picojson::object& response_obj = response->get<picojson::object>();
-
- try {
- calendar_list_h list = NULL;
- if (CALENDAR_ERROR_NONE != calendar_list_create(&list)) {
- LoggerE("Could not create list for batch operation");
- throw UnknownException("Could not create list for batch operation");
- }
- CalendarListPtr list_ptr =
- CalendarListPtr(list, CalendarRecord::ListDeleter);
-
- int ret;
- calendar_record_h record;
-
- for (auto& item : items) {
- ret = calendar_record_create(view_uri, &record);
- if (CALENDAR_ERROR_NONE != ret) {
- LoggerW("Can't create platform record %d", ret);
- throw UnknownException("Can't create platform record");
- }
- CalendarItem::FromJson(type, record, item.get<picojson::object>());
-
- if (CALENDAR_ERROR_NONE != calendar_list_add(list_ptr.get(), record)) {
- LoggerE("Could not add record to list events");
- throw InvalidValuesException("Could not add record to list");
- }
- }
-
- int* ids;
- int count;
- ret = calendar_db_insert_records(list_ptr.get(), &ids, &count);
- if (CALENDAR_ERROR_NONE != ret) {
- LoggerE("calendar_db_insert_records failed.");
- if (CALENDAR_ERROR_INVALID_PARAMETER == ret) {
- LoggerE("CALENDAR_ERROR_INVALID_PARAMETER.");
- throw InvalidValuesException("Parameter is invalid");
- } else {
- LoggerE("CALENDAR_ERROR_DB_FAILED");
- throw UnknownException("CALENDAR_ERROR_DB_FAILED occurred");
- }
- }
+ int ret;
+ calendar_record_h record;
- picojson::value result = picojson::value(picojson::array());
- picojson::array& array = result.get<picojson::array>();
+ for (auto& item : items) {
+ ret = calendar_record_create(view_uri, &record);
+ if (CALENDAR_ERROR_NONE != ret) {
+ LoggerW("Can't create platform record %d", ret);
+ throw UnknownException("Can't create platform record");
+ }
+ CalendarItem::FromJson(type, record, item.get<picojson::object>());
- for (int i = 0; i < count; i++) {
- picojson::value id = picojson::value(picojson::object());
- picojson::object& id_obj = id.get<picojson::object>();
+ if (CALENDAR_ERROR_NONE != calendar_list_add(list_ptr.get(), record)) {
+ LoggerE("Could not add record to list events");
+ throw InvalidValuesException("Could not add record to list");
+ }
+ }
- id_obj.insert(std::make_pair("uid", std::to_string(ids[i])));
+ int* ids;
+ int count;
+ ret = calendar_db_insert_records(list_ptr.get(), &ids, &count);
+ if (CALENDAR_ERROR_NONE != ret) {
+ LoggerE("calendar_db_insert_records failed.");
+ if (CALENDAR_ERROR_INVALID_PARAMETER == ret) {
+ LoggerE("CALENDAR_ERROR_INVALID_PARAMETER.");
+ throw InvalidValuesException("Parameter is invalid");
+ } else {
+ LoggerE("CALENDAR_ERROR_DB_FAILED");
+ throw UnknownException("CALENDAR_ERROR_DB_FAILED occurred");
+ }
+ }
- if (type == CALENDAR_BOOK_TYPE_EVENT) {
- id_obj.insert(std::make_pair("rid", picojson::value()));
- }
+ for (int i = 0; i < count; i++) {
+ picojson::value id = picojson::value(picojson::object());
+ picojson::object& id_obj = id.get<picojson::object>();
- array.push_back(id);
- }
- free(ids);
+ id_obj.insert(std::make_pair("uid", std::to_string(ids[i])));
+ if (type == CALENDAR_BOOK_TYPE_EVENT) {
+ id_obj.insert(std::make_pair("rid", picojson::value()));
}
- catch(...) {//(const BasePlatformException& e) {
- }
- };
- int callback_handle;// = NativePlugin::GetAsyncCallbackHandle(args);
- auto after_batch_func = [callback_handle](const JsonValuePtr& response) {
- };
-
- TaskQueue::GetInstance().Queue<picojson::value>(
- batch_func, after_batch_func,
- JsonValuePtr(new picojson::value(picojson::object())));
+ array.push_back(id);
+ }
+ free(ids);
}
void Calendar::Update(const picojson::object& args,
}
void Calendar::UpdateBatch(const picojson::object& args,
- picojson::object& out) {
+ picojson::array& array) {
LoggerD("enter");
if (!CalendarManager::GetInstance().IsConnected()) {
int type = CalendarRecord::TypeToInt(FromJson<std::string>(args, "type"));
const char* view_uri = CalendarRecord::TypeToUri(type);
+ calendar_list_h list = NULL;
+ if (CALENDAR_ERROR_NONE != calendar_list_create(&list)) {
+ LoggerE("Could not create list for batch operation");
+ throw UnknownException("Could not create list for batch operation");
+ }
+ CalendarListPtr list_ptr =
+ CalendarListPtr(list, CalendarRecord::ListDeleter);
- auto batch_func = [=](const JsonValuePtr & response)->void {
- picojson::object& response_obj = response->get<picojson::object>();
-
- try {
- calendar_list_h list = NULL;
- if (CALENDAR_ERROR_NONE != calendar_list_create(&list)) {
- LoggerE("Could not create list for batch operation");
- throw UnknownException("Could not create list for batch operation");
- }
- CalendarListPtr list_ptr =
- CalendarListPtr(list, CalendarRecord::ListDeleter);
-
- int ret, id;
- calendar_record_h record;
-
- for (auto& item : items) {
- const picojson::object& item_obj = item.get<picojson::object>();
- if (type == CALENDAR_BOOK_TYPE_EVENT) {
- id = common::stol(FromJson<std::string>(item_obj, "id", "uid"));
- } else {
- id = common::stol(FromJson<std::string>(item_obj, "id"));
- }
-
- ret = calendar_db_get_record(view_uri, id, &record);
- if (CALENDAR_ERROR_NONE != ret) {
- LoggerW("Can't get platform record %d", ret);
- throw UnknownException("Can't get platform record");
- }
- CalendarItem::FromJson(type, record, item.get<picojson::object>());
-
- if (CALENDAR_ERROR_NONE != calendar_list_add(list_ptr.get(), record)) {
- LoggerE("Could not add record to list events");
- throw InvalidValuesException("Could not add record to list");
- }
- }
-
- if (type == CALENDAR_BOOK_TYPE_TODO || update_all) {
- if (CALENDAR_ERROR_NONE != calendar_db_update_records(list_ptr.get())) {
- LoggerE("Can't update calendar items");
- throw UnknownException("Can't update calendar items");
- }
- } else {
- // @todo update the exdate for a recurring parent event and add a new
- // child event
- }
+ int ret, id;
+ calendar_record_h record;
+ for (auto& item : items) {
+ const picojson::object& item_obj = item.get<picojson::object>();
+ if (type == CALENDAR_BOOK_TYPE_EVENT) {
+ id = common::stol(FromJson<std::string>(item_obj, "id", "uid"));
+ } else {
+ id = common::stol(FromJson<std::string>(item_obj, "id"));
}
- catch (...) {//const BasePlatformException& e) {
+
+ ret = calendar_db_get_record(view_uri, id, &record);
+ if (CALENDAR_ERROR_NONE != ret) {
+ LoggerW("Can't get platform record %d", ret);
+ throw UnknownException("Can't get platform record");
}
- };
+ CalendarItem::FromJson(type, record, item.get<picojson::object>());
- int callback_handle; //= NativePlugin::GetAsyncCallbackHandle(args);
- auto after_batch_func = [callback_handle](const JsonValuePtr& response) {
- };
+ if (CALENDAR_ERROR_NONE != calendar_list_add(list_ptr.get(), record)) {
+ LoggerE("Could not add record to list events");
+ throw InvalidValuesException("Could not add record to list");
+ }
+ }
- TaskQueue::GetInstance().Queue<picojson::value>(
- batch_func, after_batch_func,
- JsonValuePtr(new picojson::value(picojson::object())));
+ if (type == CALENDAR_BOOK_TYPE_TODO || update_all) {
+ if (CALENDAR_ERROR_NONE != calendar_db_update_records(list_ptr.get())) {
+ LoggerE("Can't update calendar items");
+ throw UnknownException("Can't update calendar items");
+ }
+ } else {
+ // @todo update the exdate for a recurring parent event and add a new
+ // child event
+ }
}
void Calendar::Remove(const picojson::object& args,
CalendarItem::Remove(type, id);
}
-void Calendar::Find(const picojson::object& args, picojson::object& out) {
+void Calendar::Find(const picojson::object& args, picojson::array& array) {
LoggerD("enter");
if (!CalendarManager::GetInstance().IsConnected()) {
// TODO implement calendar filter and sorting in native code.
int calendar_id = common::stol(FromJson<std::string>(args, "calendarId"));
- int callback_handle; //=NativePlugin::GetAsyncCallbackHandle(args);
-
- auto get = [calendar_id](const std::shared_ptr<picojson::value> & response)
- ->void {
- LoggerD("Entered");
- try {
- int error_code = 0;
- CalendarRecordPtr calendar_ptr =
- CalendarRecord::GetById(calendar_id, _calendar_book._uri);
- int type =
- CalendarRecord::GetInt(calendar_ptr.get(), _calendar_book.store_type);
- calendar_query_h calendar_query = nullptr;
- if (type == CALENDAR_BOOK_TYPE_EVENT) {
- error_code =
- calendar_query_create(_calendar_event._uri, &calendar_query);
- } else {
- error_code =
- calendar_query_create(_calendar_todo._uri, &calendar_query);
- }
- if (CALENDAR_ERROR_NONE != error_code) {
- throw UnknownException("calendar_query_create failed");
- }
+ int error_code = 0;
+ CalendarRecordPtr calendar_ptr =
+ CalendarRecord::GetById(calendar_id, _calendar_book._uri);
+ int type =
+ CalendarRecord::GetInt(calendar_ptr.get(), _calendar_book.store_type);
+ calendar_query_h calendar_query = nullptr;
+ if (type == CALENDAR_BOOK_TYPE_EVENT) {
+ error_code =
+ calendar_query_create(_calendar_event._uri, &calendar_query);
+ } else {
+ error_code =
+ calendar_query_create(_calendar_todo._uri, &calendar_query);
+ }
+ if (CALENDAR_ERROR_NONE != error_code) {
+ throw UnknownException("calendar_query_create failed");
+ }
- CalendarQueryPtr calendar_query_ptr(calendar_query,
- CalendarRecord::QueryDeleter);
+ CalendarQueryPtr calendar_query_ptr(calendar_query,
+ CalendarRecord::QueryDeleter);
- calendar_list_h record_list = nullptr;
- error_code = calendar_db_get_records_with_query(calendar_query, 0, 0,
- &record_list);
- if (CALENDAR_ERROR_NONE != error_code) {
- throw UnknownException("calendar_db_get_records_with_query failed");
- }
- CalendarListPtr record_list_ptr(record_list, CalendarRecord::ListDeleter);
+ calendar_list_h record_list = nullptr;
+ error_code = calendar_db_get_records_with_query(calendar_query, 0, 0,
+ &record_list);
+ if (CALENDAR_ERROR_NONE != error_code) {
+ throw UnknownException("calendar_db_get_records_with_query failed");
+ }
+ CalendarListPtr record_list_ptr(record_list, CalendarRecord::ListDeleter);
- int record_count = 0;
- error_code = calendar_list_get_count(record_list, &record_count);
- if (CALENDAR_ERROR_NONE != error_code) {
- throw UnknownException("calendar_list_get_count failed");
- }
- error_code = calendar_list_first(record_list);
- if (CALENDAR_ERROR_NONE != error_code) {
- throw UnknownException("calendar_list_first failed");
- }
+ int record_count = 0;
+ error_code = calendar_list_get_count(record_list, &record_count);
+ if (CALENDAR_ERROR_NONE != error_code) {
+ throw UnknownException("calendar_list_get_count failed");
+ }
+ error_code = calendar_list_first(record_list);
+ if (CALENDAR_ERROR_NONE != error_code) {
+ throw UnknownException("calendar_list_first failed");
+ }
- picojson::value result{picojson::array{}};
- picojson::array& calendarItems = result.get<picojson::array>();
- calendarItems.reserve(record_count);
- for (int i = 0; i < record_count; ++i) {
- calendar_record_h current_record = NULL;
- error_code =
- calendar_list_get_current_record_p(record_list, ¤t_record);
- if (CALENDAR_ERROR_NONE != error_code) {
- throw UnknownException("calendar_list_get_current_record_p failed");
- }
- picojson::value record_obj = picojson::value(picojson::object());
- CalendarItem::ToJson(type, current_record,
- &record_obj.get<picojson::object>());
- calendarItems.push_back(record_obj);
-
- error_code = calendar_list_next(record_list);
- if (CALENDAR_ERROR_NONE != error_code) {
- LoggerE("calendar_list_next failed (%i/%i)", i, record_count);
- break;
- }
- }
+ array.reserve(record_count);
+ for (int i = 0; i < record_count; ++i) {
+ calendar_record_h current_record = NULL;
+ error_code =
+ calendar_list_get_current_record_p(record_list, ¤t_record);
+ if (CALENDAR_ERROR_NONE != error_code) {
+ throw UnknownException("calendar_list_get_current_record_p failed");
}
- catch (...) {//const BasePlatformException& e) {
- // LoggerE("error: %s: %s", e.name().c_str(), e.message().c_str());
+ picojson::value record_obj = picojson::value(picojson::object());
+ CalendarItem::ToJson(type, current_record,
+ &record_obj.get<picojson::object>());
+ array.push_back(record_obj);
+
+ error_code = calendar_list_next(record_list);
+ if (CALENDAR_ERROR_NONE != error_code) {
+ LoggerE("calendar_list_next failed (%i/%i)", i, record_count);
+ break;
}
- };
-
- auto get_response = [callback_handle](const std::shared_ptr<picojson::value> &
- response)->void {
- };
-
- TaskQueue::GetInstance().Queue<picojson::value>(
- get, get_response,
- std::shared_ptr<picojson::value>(new picojson::value(picojson::object())));
-
-// NativePlugin::ReportSuccess(out);
+ }
}
void Calendar::RemoveBatch(const picojson::object& args,
- picojson::object& out) {
+ picojson::array& array) {
LoggerD("enter");
if (!CalendarManager::GetInstance().IsConnected()) {
int type = CalendarRecord::TypeToInt(FromJson<std::string>(args, "type"));
const char* view_uri = CalendarRecord::TypeToUri(type);
- auto batch_func = [=](const JsonValuePtr & response)->void {
- picojson::object& response_obj = response->get<picojson::object>();
+ std::vector<int> ids_to_remove;
+ int id;
+ for (int i = 0, size = ids.size(); i < size; i++) {
+ if (type == CALENDAR_BOOK_TYPE_EVENT) {
+ id = common::stol(
+ FromJson<std::string>(ids.at(i).get<picojson::object>(), "uid"));
+ } else {
+ id = common::stol(ids.at(i).get<std::string>());
+ }
- try {
- std::vector<int> ids_to_remove;
- int id;
- for (int i = 0, size = ids.size(); i < size; i++) {
- if (type == CALENDAR_BOOK_TYPE_EVENT) {
- id = common::stol(
- FromJson<std::string>(ids.at(i).get<picojson::object>(), "uid"));
- } else {
- id = common::stol(ids.at(i).get<std::string>());
- }
-
- CalendarRecordPtr record_ptr = CalendarItem::GetById(id, view_uri);
-
- if (type == CALENDAR_BOOK_TYPE_EVENT) {
- const std::string& rid = CalendarRecord::GetString(
- record_ptr.get(), _calendar_event.recurrence_id);
- if (rid.empty()) {
- ids_to_remove.push_back(id);
- } else {
- // @todo handle recurrence_id
- }
- } else {
- ids_to_remove.push_back(id);
- }
- }
+ CalendarRecordPtr record_ptr = CalendarItem::GetById(id, view_uri);
- int ret;
- if (ids_to_remove.size() > 0) {
- ret = calendar_db_delete_records(view_uri, &ids_to_remove[0],
- ids_to_remove.size());
-
- if (CALENDAR_ERROR_NONE != ret) {
- LoggerE("calendar_db_delete_records failed.");
- if (CALENDAR_ERROR_INVALID_PARAMETER == ret) {
- LoggerE("CALENDAR_ERROR_INVALID_PARAMETER");
- throw InvalidValuesException("Parameter is invalid");
- } else {
- LoggerE("CALENDAR_ERROR_DB_FAILED");
- throw UnknownException("UnknownError");
- }
- }
+ if (type == CALENDAR_BOOK_TYPE_EVENT) {
+ const std::string& rid = CalendarRecord::GetString(
+ record_ptr.get(), _calendar_event.recurrence_id);
+ if (rid.empty()) {
+ ids_to_remove.push_back(id);
+ } else {
+ // @todo handle recurrence_id
}
+ } else {
+ ids_to_remove.push_back(id);
}
- catch(...) { //(const BasePlatformException& e) {
- }
- };
-
- int callback_handle;// = NativePlugin::GetAsyncCallbackHandle(args);
- auto after_batch_func = [callback_handle](const JsonValuePtr& response) {
- };
+ }
- TaskQueue::GetInstance().Queue<picojson::value>(
- batch_func, after_batch_func,
- JsonValuePtr(new picojson::value(picojson::object())));
+ int ret;
+ if (ids_to_remove.size() > 0) {
+ ret = calendar_db_delete_records(view_uri, &ids_to_remove[0],
+ ids_to_remove.size());
+ if (CALENDAR_ERROR_NONE != ret) {
+ LoggerE("calendar_db_delete_records failed.");
+ if (CALENDAR_ERROR_INVALID_PARAMETER == ret) {
+ LoggerE("CALENDAR_ERROR_INVALID_PARAMETER");
+ throw InvalidValuesException("Parameter is invalid");
+ } else {
+ LoggerE("CALENDAR_ERROR_DB_FAILED");
+ throw UnknownException("UnknownError");
+ }
+ }
+ }
}
void Calendar::AddChangeListener(const picojson::object& args, picojson::object& out) {
throw UnknownException("Can't get new version");
}
current_db_version_ = updated_version;
-
-// wrt::common::NativeContext::GetInstance()->FireEvent(
-// listeners_registered_[CalendarRecord::TypeToString(type)],
-// response.serialize());
}
} // namespace calendar
// Calendar
REGISTER_SYNC("Calendar_get", Calendar_get);
REGISTER_SYNC("Calendar_add", Calendar_add);
- REGISTER_SYNC("Calendar_addBatch", Calendar_addBatch);
REGISTER_SYNC("Calendar_update", Calendar_update);
- REGISTER_SYNC("Calendar_updateBatch", Calendar_updateBatch);
REGISTER_SYNC("Calendar_remove", Calendar_remove);
- REGISTER_SYNC("Calendar_removeBatch", Calendar_removeBatch);
- REGISTER_SYNC("Calendar_find", Calendar_find);
REGISTER_SYNC("Calendar_addChangeListener", Calendar_addChangeListener);
REGISTER_SYNC("Calendar_removeChangeListener", Calendar_removeChangeListener);
#undef REGISTER_SYNC
#define REGISTER_ASYNC(c, x) \
RegisterHandler(c, std::bind(&CalendarInstance::x, this, _1, _2));
+ REGISTER_ASYNC("Calendar_addBatch", Calendar_addBatch);
+ REGISTER_ASYNC("Calendar_updateBatch", Calendar_updateBatch);
+ REGISTER_ASYNC("Calendar_removeBatch", Calendar_removeBatch);
+ REGISTER_ASYNC("Calendar_updateBatch", Calendar_updateBatch);
REGISTER_ASYNC("CalendarManager_getCalendars", CalendarManager_getCalendars);
+ REGISTER_ASYNC("Calendar_find", Calendar_find);
#undef REGISTER_ASYNC
}
void CalendarInstance::Calendar_addBatch(const JsonValue& args,
JsonObject& out) {
- JsonValue val{JsonObject{}};
- Calendar::GetInstance().AddBatch(common::JsonCast<JsonObject>(args),
- val.get<JsonObject>());
- ReportSuccess(val, out);
+ const double callback_id = args.get("callbackId").get<double>();
+ auto get = [=](const std::shared_ptr<JsonValue>& response) -> void {
+ try {
+ JsonValue result = JsonValue(JsonArray());
+ Calendar::GetInstance().AddBatch(common::JsonCast<JsonObject>(args),
+ result.get<JsonArray>());
+ ReportSuccess(result, response->get<picojson::object>());
+ } catch (const PlatformException& e) {
+ ReportError(e, response->get<picojson::object>());
+ }
+ };
+
+ auto get_response =
+ [callback_id, this](const std::shared_ptr<JsonValue>& response) -> void {
+ picojson::object& obj = response->get<picojson::object>();
+ obj.insert(std::make_pair("callbackId", callback_id));
+ LoggerD("callback is %s", response->serialize().c_str());
+ PostMessage(response->serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Queue<JsonValue>(
+ get, get_response,
+ std::shared_ptr<JsonValue>(new JsonValue(JsonObject())));
}
void CalendarInstance::Calendar_update(const JsonValue& args, JsonObject& out) {
void CalendarInstance::Calendar_updateBatch(const JsonValue& args,
JsonObject& out) {
- JsonValue val{JsonObject{}};
- Calendar::GetInstance().UpdateBatch(common::JsonCast<JsonObject>(args),
- val.get<JsonObject>());
- ReportSuccess(val, out);
+ const double callback_id = args.get("callbackId").get<double>();
+ auto get = [=](const std::shared_ptr<JsonValue>& response) -> void {
+ try {
+ JsonValue result = JsonValue(JsonArray());
+ Calendar::GetInstance().UpdateBatch(common::JsonCast<JsonObject>(args),
+ result.get<JsonArray>());
+ ReportSuccess(result, response->get<picojson::object>());
+ } catch (const PlatformException& e) {
+ ReportError(e, response->get<picojson::object>());
+ }
+ };
+
+ auto get_response =
+ [callback_id, this](const std::shared_ptr<JsonValue>& response) -> void {
+ picojson::object& obj = response->get<picojson::object>();
+ obj.insert(std::make_pair("callbackId", callback_id));
+ LoggerD("callback is %s", response->serialize().c_str());
+ PostMessage(response->serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Queue<JsonValue>(
+ get, get_response,
+ std::shared_ptr<JsonValue>(new JsonValue(JsonObject())));
}
void CalendarInstance::Calendar_remove(const JsonValue& args, JsonObject& out) {
void CalendarInstance::Calendar_removeBatch(const JsonValue& args,
JsonObject& out) {
- JsonValue val{JsonObject{}};
- Calendar::GetInstance().RemoveBatch(common::JsonCast<JsonObject>(args),
- val.get<JsonObject>());
- ReportSuccess(out);
+ const double callback_id = args.get("callbackId").get<double>();
+ auto get = [=](const std::shared_ptr<JsonValue>& response) -> void {
+ try {
+ JsonValue result = JsonValue(JsonArray());
+ Calendar::GetInstance().RemoveBatch(common::JsonCast<JsonObject>(args),
+ result.get<JsonArray>());
+ ReportSuccess(result, response->get<picojson::object>());
+ } catch (const PlatformException& e) {
+ ReportError(e, response->get<picojson::object>());
+ }
+ };
+
+ auto get_response =
+ [callback_id, this](const std::shared_ptr<JsonValue>& response) -> void {
+ picojson::object& obj = response->get<picojson::object>();
+ obj.insert(std::make_pair("callbackId", callback_id));
+ LoggerD("callback is %s", response->serialize().c_str());
+ PostMessage(response->serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Queue<JsonValue>(
+ get, get_response,
+ std::shared_ptr<JsonValue>(new JsonValue(JsonObject())));
}
void CalendarInstance::Calendar_find(const JsonValue& args, JsonObject& out) {
- JsonValue val{JsonObject{}};
- Calendar::GetInstance().Find(common::JsonCast<JsonObject>(args),
- val.get<JsonObject>());
- ReportSuccess(out);
+ const double callback_id = args.get("callbackId").get<double>();
+ auto get = [=](const std::shared_ptr<JsonValue>& response) -> void {
+ try {
+ JsonValue result = JsonValue(JsonArray());
+ Calendar::GetInstance().Find(common::JsonCast<JsonObject>(args),
+ result.get<JsonArray>());
+ ReportSuccess(result, response->get<picojson::object>());
+ } catch (const PlatformException& e) {
+ ReportError(e, response->get<picojson::object>());
+ }
+ };
+
+ auto get_response =
+ [callback_id, this](const std::shared_ptr<JsonValue>& response) -> void {
+ picojson::object& obj = response->get<picojson::object>();
+ obj.insert(std::make_pair("callbackId", callback_id));
+ LoggerD("callback isssssss %s", response->serialize().c_str());
+ PostMessage(response->serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Queue<JsonValue>(
+ get, get_response,
+ std::shared_ptr<JsonValue>(new JsonValue(JsonObject())));
}
void CalendarInstance::Calendar_addChangeListener(const JsonValue& args,
[callback_id, this](const std::shared_ptr<JsonValue>& response) -> void {
picojson::object& obj = response->get<picojson::object>();
obj.insert(std::make_pair("callbackId", callback_id));
- LoggerD("callback isssssss %s", response->serialize().c_str());
+ LoggerD("callback is %s", response->serialize().c_str());
PostMessage(response->serialize().c_str());
};