[Contact] ContactManager addChangeListener fix
authorKarol Pawlowski <k.pawlowski@samsung.com>
Tue, 23 Dec 2014 12:19:38 +0000 (13:19 +0100)
committerRafal Galka <r.galka@samsung.com>
Tue, 23 Dec 2014 13:42:12 +0000 (22:42 +0900)
[Verification]

exports.onRequest = function() {

console.log("Service Start~!");
try {
watcher = {
        onpersonsadded: function (persons) {
            console.log("Contact manager works");
            tizen.contact.removeChangeListener(watcherId);
            console.log("Listener removed");
        },
        onpersonsupdated: function (persons) {
        },
        onpersonsremoved: function (ids) {
        }
    };
    watcherId = tizen.contact.addChangeListener(watcher);
    contact = new tizen.Contact({
        addresses: [new tizen.ContactAddress({
            country: "London"
        })]
    });
    defaultAddressBook = tizen.contact.getDefaultAddressBook();
    defaultAddressBook.add(contact);
}catch (e) {
        console.log(e.name + ': ' + e.message);
        console.log(e.stack);
}
};

Change-Id: I8555031e16dbc769546d712b5b616a7f7ecce8c5
Signed-off-by: Karol Pawlowski <k.pawlowski@samsung.com>
src/contact/addressbook.cc
src/contact/contact_instance.cc
src/contact/contact_instance.h
src/contact/contact_manager.cc
src/contact/contact_manager.h
src/contact/js/tizen.contact.ContactManager.js

index 9b49b078528f7428e87344a3ed5cf48d831911dc..72e6aadde194d5e02302d0b6bdc70a0f3255787e 100644 (file)
@@ -617,7 +617,7 @@ void AddressBook_listenerCallback(const char* view_uri, void* user_data) {
 }
 }
 
-void AddressBook_startListening(const JsonObject& args, JsonObject& out) {
+void AddressBook_startListening(const JsonObject&, JsonObject& out) {
   ContactUtil::CheckDBConnection();
   // Set the initial latest version before registering the callback.
   // The callback should only be registered once so no race can occur.
@@ -636,7 +636,7 @@ void AddressBook_startListening(const JsonObject& args, JsonObject& out) {
   }
 }
 
-void AddressBook_stopListening(const JsonObject& args, JsonObject& out) {
+void AddressBook_stopListening(const JsonObject&, JsonObject& out) {
   ContactUtil::CheckDBConnection();
   int error_code = contacts_db_remove_changed_cb(
       _contacts_contact._uri, AddressBook_listenerCallback, &ContactInstance::current_state);
index 17a146a98f2c5c5e8cde5080eeee0f06ecf8c021..819ac2ef94061beecaac49306b056c25e00ff67d 100644 (file)
@@ -43,6 +43,8 @@ ContactInstance::ContactInstance() {
   REGISTER_SYNC("ContactManager_removeBatch", ContactManager_removeBatch);
   REGISTER_SYNC("ContactManager_find", ContactManager_find);
   REGISTER_SYNC("ContactManager_importFromVCard", ContactManager_importFromVCard);
+  REGISTER_SYNC("ContactManager_startListening", ContactManager_startListening);
+  REGISTER_SYNC("ContactManager_stopListening", ContactManager_stopListening);
 
   // AddressBook
   REGISTER_ASYNC("AddressBook_addBatch", AddressBook_addBatch);
@@ -269,6 +271,20 @@ void ContactInstance::ContactManager_importFromVCard(const JsonValue& args,
   ReportSuccess(val, out);
 }
 
+void ContactInstance::ContactManager_startListening(const JsonValue& args, JsonObject& out) {
+  JsonValue val{JsonObject{}};
+  ContactManager::ContactManager_startListening(common::JsonCast<JsonObject>(args),
+                               val.get<JsonObject>());
+  ReportSuccess(val, out);
+}
+
+void ContactInstance::ContactManager_stopListening(const JsonValue& args, JsonObject& out) {
+  JsonValue val{JsonObject{}};
+  ContactManager::ContactManager_stopListening(common::JsonCast<JsonObject>(args),
+                               val.get<JsonObject>());
+  ReportSuccess(val, out);
+}
+
 void ContactInstance::Person_link(const JsonValue& args, JsonObject& out) {
   JsonValue val{JsonObject{}};
   Person::Person_link(common::JsonCast<JsonObject>(args),
index 237cd58b872d1f20fcc0420305975b34b892efe0..e8645aa42ef26390c7c627213c25ee7c7c8db482 100644 (file)
@@ -176,6 +176,33 @@ class ContactInstance : public common::ParsedInstance {
    */
   void ContactManager_importFromVCard(const JsonValue& args, JsonObject& out);
 
+  /**
+   * Signature: @code void getAddressBook(contactString); @endcode
+   * JSON: @code data: {method: 'ContactManager_startListening',
+   *                    args: {}} @endcode
+   * Invocation: @code native.callSync(request); @endcode
+   * Return:
+   * @code
+   * {status: 'error', error: {name, message}}
+   * {status: 'success'}
+   * @endcode
+   */
+  void ContactManager_startListening(const JsonValue& args, JsonObject& out);
+
+  /**
+   * Signature: @code void getAddressBook(contactString); @endcode
+   * JSON: @code data: {method: 'ContactManager_stopListening',
+   *                    args: {}} @endcode
+   * Invocation: @code native.callSync(request); @endcode
+   * Return:
+   * @code
+   * {status: 'error', error: {name, message}}
+   * {status: 'success'}
+   * @endcode
+   */
+  void ContactManager_stopListening(const JsonValue& args, JsonObject& out);
+
+
   void Person_link(const JsonValue& args, JsonObject& out);
   void Person_unlink(const JsonValue& args, JsonObject& out);
 };
index b758731badc8e7a01131d2db93fa8f42e6e32a34..4f8006a972710d3895fc166df39c25fb48e2ffe0 100644 (file)
@@ -335,7 +335,7 @@ void ContactManager_listenerCallback(const char* view_uri, char* changes,
 }
 }
 
-void ContactManager_startListening(/*const JsonObject&, JsonObject& out*/) {
+void ContactManager_startListening(const JsonObject& /*args*/, JsonObject& /*out*/) {
   ContactUtil::CheckDBConnection();
   int error_code = contacts_db_add_changed_cb_with_info(
       _contacts_person._uri, ContactManager_listenerCallback, nullptr);
@@ -347,7 +347,7 @@ void ContactManager_startListening(/*const JsonObject&, JsonObject& out*/) {
   }
 }
 
-void ContactManager_stopListening(/*const JsonObject&, JsonObject& out*/) {
+void ContactManager_stopListening(const JsonObject& /*args*/, JsonObject& /*out*/) {
   ContactUtil::CheckDBConnection();
   int error_code = contacts_db_remove_changed_cb_with_info(
       _contacts_person._uri, ContactManager_listenerCallback, nullptr);
index d2ed46101afd0e1320e63e268b6efb9ecc5fd4f9..49ca1824a59a3e3aaa3e567cdbe050a17f1f3029 100644 (file)
@@ -55,7 +55,7 @@ void ContactManager_importFromVCard(const JsonObject& args, JsonObject& out);
  * {status: 'success'}
  * @endcode
  */
-void ContactManager_startListening(/*const JsonObject& args, JsonObject& out*/);
+void ContactManager_startListening(const JsonObject& args, JsonObject& out);
 
 /**
  * Signature: @code void getAddressBook(contactString); @endcode
@@ -68,7 +68,7 @@ void ContactManager_startListening(/*const JsonObject& args, JsonObject& out*/);
  * {status: 'success'}
  * @endcode
  */
-void ContactManager_stopListening(/*const JsonObject& args, JsonObject& out*/);
+void ContactManager_stopListening(const JsonObject& args, JsonObject& out);
 
 }  // namespace ContactManager
 }  // namespace contact
index 30895b79a72939ded3f173bb1cc978131559b959..dfd93d5e6202071cc0acc2132f8b7981b6a6e6da 100644 (file)
@@ -6,7 +6,6 @@
 var _personListenerRegistered = false;
 var _personCallbackMap = {};
 var _personChangeListener = function(result) {
-  result = JSON.parse(result);
   for (var key in _personCallbackMap) {
     if (_personCallbackMap.hasOwnProperty(key)) {
       if (result.added.length) {