AccountListeners.prototype.instances = {};
+AccountListeners.prototype.nextID = 0;
-AccountListeners.prototype.addListener = function(accountListenerId, callback) {
+AccountListeners.prototype.addListener = function(callback) {
+ var id = ++this.nextID;
+
if (T_.isEmptyObject(this.instances)) {
+ var result = native_.callSync('AccountManager_addAccountListener');
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
native_.addListener(ACCOUNT_LISTENER, this.appCallback);
}
- this.instances[accountListenerId] = callback;
+ this.instances[id] = callback;
+
+ return id;
};
delete this.instances[accountListenerId];
if (T_.isEmptyObject(this.instances)) {
native_.removeListener(ACCOUNT_LISTENER, this.appCallback);
+
+ var result = native_.callSync('AccountManager_removeListener');
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
}
};
{ name: 'callback', type: types_.LISTENER, values: ['onadded', 'onremoved', 'onupdated'] }
]);
- var result = native_.callSync('AccountManager_addAccountListener');
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
-
- var accountListenerId = native_.getResultObject(result);
- _accountListeners.addListener(accountListenerId, args.callback);
- return accountListenerId;
+ return _accountListeners.addListener(args.callback);
}
]);
_accountListeners.removeListener(args.accountListenerId);
-
- if (T_.isEmptyObject(_accountListeners.instances)) {
- var result = native_.callSync('AccountManager_removeListener');
-
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- }
-
- return;
}
tizen.Account = Account;
int ret = 0;
if (!subscribe_) {
+ LoggerD("Creating subscription");
ret = account_subscribe_create(&subscribe_);
if (ret != ACCOUNT_ERROR_NONE) {
LoggerE("Failed to create account subscribe");
return;
}
+ LoggerD("Subscribing for notification");
ret = account_subscribe_notification(subscribe_, AccountEventCb, this);
if (ret != ACCOUNT_ERROR_NONE) {
LoggerE("Failed to subscribe notification");
ReportError(UnknownException(manager_->GetErrorMsg(ret)), out);
return;
}
+
+ LoggerD("Success");
}
ReportSuccess(out);
CheckAccess(kPrivilegeAccountRead, &out);
if (subscribe_) {
+ LoggerD("Removing subscription");
+
if (account_unsubscribe_notification(subscribe_) != ACCOUNT_ERROR_NONE) {
LoggerE("Failed to unsubscribe notification");
}
+
+ subscribe_ = nullptr;
}
ReportSuccess(out);