var callbacks = {};
extension.setMessageListener(function(json) {
- console.log('[Package][extension.setMessageListener] Enter');
var result = JSON.parse(json);
var callback = callbacks[result['callbackId']];
callback(result);
}
function callNative(cmd, args) {
- console.log('[Package][callNative] Enter');
-
var json = {'cmd': cmd, 'args': args};
var argjson = JSON.stringify(json);
- console.log('[Package][callNative] argjson: ' + argjson);
var resultString = extension.internal.sendSyncMessage(argjson);
- console.log('[Package][callNative] resultString: ' + resultString);
var result = JSON.parse(resultString);
if (typeof result !== 'object') {
function callNativeWithCallback(cmd, args, callback) {
- console.log('[Package][callNativeWithCallback] Enter');
-
if (callback) {
var id = nextCallbackId();
args['callbackId'] = id;
callbacks[id] = callback;
- console.log('[Package][callNativeWithCallback] callbackId: ' + id);
}
return callNative(cmd, args);
function SetReadOnlyProperty(obj, n, v) {
if (arguments.length > 2)
- Object.defineProperty(obj, n, {value: v, writable: false, configurable: false});
+ Object.defineProperty(
+ obj, n, {value: v, writable: false, enumerable: true, configurable: true});
else
- Object.defineProperty(obj, n, {writable: false, configurable: false});
+ Object.defineProperty(obj, n, {writable: false, enumerable: true, configurable: true});
}
function PackageInformation(obj) {
PackageManager.prototype.install = function(packageFileURI, progressCallback) {
- console.log('[Package][install] Enter');
-
var args = validator_.validateArgs(arguments, [
{'name' : 'packageFileURI', 'type' : types_.STRING},
{'name' : 'progressCallback',
var nativeParam = {
'packageFileURI': args.packageFileURI
};
- console.log('[Package][install] packageFileURI: [' + nativeParam.packageFileURI + ']');
try {
var syncResult = callNativeWithCallback(
'PackageManager_install',
nativeParam,
function(result) {
- console.log('[Package][installCB] Enter');
- console.log('[Package][installCB] status: ' + result.status);
-
if (result.status == 'progress') {
- console.log('[Package][installCB] Call onprogress');
args.progressCallback.onprogress(result.id, result.progress);
} else if (result.status == 'complete') {
- console.log('[Package][installCB] Call oncomplete');
args.progressCallback.oncomplete(result.id);
} else if (result.status == 'error') {
- console.log('[Package][installCB] Call errorCallback');
-
var err = result['error'];
if (err) {
args.errorCallback(new tizen.WebAPIError(err.name, err.message));
}
if (result.status == 'complete' || result.status == 'error') {
- console.log('[Package][installCB] Delete callback');
delete callbacks[result['callbackId']];
}
});
};
PackageManager.prototype.uninstall = function(id, progressCallback) {
- console.log('[Package][uninstall] Enter');
-
var args = validator_.validateArgs(arguments, [
{'name' : 'id', 'type' : types_.STRING},
{'name' : 'progressCallback',
var nativeParam = {
'id': args.id
};
- console.log('[Package][uninstall] id: [' + nativeParam.id + ']');
try {
var syncResult = callNativeWithCallback(
'PackageManager_uninstall',
nativeParam,
function(result) {
- console.log('[Package][uninstallCB] Enter');
- console.log('[Package][uninstallCB] status: ' + result.status);
-
if (result.status == 'progress') {
- console.log('[Package][uninstallCB] Call onprogress');
args.progressCallback.onprogress(result.id, result.progress);
} else if (result.status == 'complete') {
- console.log('[Package][uninstallCB] Call oncomplete');
args.progressCallback.oncomplete(result.id);
} else if (result.status == 'error') {
- console.log('[Package][uninstallCB] Call errorCallback');
-
var err = result['error'];
if (err) {
args.errorCallback(new tizen.WebAPIError(err.name, err.message));
}
if (result.status == 'complete' || result.status == 'error') {
- console.log('[Package][uninstallCB] Delete callback');
delete callbacks[result['callbackId']];
}
});
};
PackageManager.prototype.getPackagesInfo = function(successCallback, errorCallback) {
- console.log('[Package][getPackagesInfo] Enter');
-
var args = validator_.validateArgs(arguments, [
{'name' : 'successCallback', 'type' : types_.FUNCTION},
{'name' : 'errorCallback', 'type' : types_.FUNCTION, 'optional' : true, 'nullable' : true}
'PackageManager_getPackagesInfo',
nativeParam,
function(result) {
- console.log('[Package][getPackagesInfoCB] Enter');
- console.log('[Package][getPackagesInfoCB] status: ' + result.status);
-
if (result.status == 'success') {
for (var i = 0; i < result.informationArray.length; i++) {
result.informationArray[i] = PackageInformation(result.informationArray[i]);
}
-
- console.log('[Package][getPackagesInfo] Call successCallback: ' +
- result.informationArray.length);
args.successCallback(result.informationArray);
} else if (result.status == 'error') {
- console.log('[Package][getPackagesInfo] Call errorCallback');
-
var err = result['error'];
if (err) {
args.errorCallback(new tizen.WebAPIError(err.name, err.message));
}
}
- console.log('[Package][getPackagesInfoCB] Delete callback');
delete callbacks[result['callbackId']];
});
} catch (e) {
};
PackageManager.prototype.getPackageInfo = function() {
- console.log('[Package][getPackageInfo] Enter');
-
var args = validator_.validateArgs(arguments, [
{'name': 'id', 'type': types_.STRING, 'optional' : true, 'nullable' : true}
]);
};
PackageManager.prototype.setPackageInfoEventListener = function(eventCallback) {
- console.log('[Package][setPackageInfoEventListener] Enter');
-
var args = validator_.validateArgs(
arguments,
[
'PackageManager_setPackageInfoEventListener',
nativeParam,
function(result) {
- console.log('[Package][PackageInfoEventListener] Enter');
- console.log('[Package][PackageInfoEventListener] status: ' + result.status);
-
if (result.status == 'installed') {
args.eventCallback.oninstalled(PackageInformation(result.info));
}
};
PackageManager.prototype.unsetPackageInfoEventListener = function() {
- console.log('[Package][unsetPackageInfoEventListener] Enter');
-
var nativeParam = {
};
try {
var syncResult = callNative('PackageManager_unsetPackageInfoEventListener', nativeParam);
if (typeof syncResult != 'boolean') {
- console.log('[Package][unsetPackageInfoEventListenerCB] Delete callback ' + syncResult);
delete callbacks[syncResult];
}
} catch (e) {
switch ( userData->work_ ) {
case PackageThreadWorkGetPackagesInfo: {
- LoggerD("Start PackageThreadWorkGetPackagesInfo");
picojson::object output;
PackageInfoProvider::GetPackagesInfo(output);
userData->data_ = output;
package_manager_event_type_e event_type,
package_manager_event_state_e event_state, int progress,
package_manager_error_e error, void *user_data) {
- LoggerD("Enter [%s]", package);
PackageInstance* instance = static_cast<PackageInstance*>(user_data);
if ( !instance ) {
}
if ( event_state == PACKAGE_MANAGER_EVENT_STATE_STARTED ) {
- LoggerD("[Started] Do not invoke JS callback");
return;
}
picojson::object param;
if ( event_state == PACKAGE_MANAGER_EVENT_STATE_FAILED ) {
- LoggerD("[Failed]");
+ LoggerE("[Failed]");
param["status"] = picojson::value("error");
param["error"] = UnknownException(
"It is not allowed to install the package by the platform or " \
"any other platform error occurs").ToJSON();
} else if ( event_state == PACKAGE_MANAGER_EVENT_STATE_PROCESSING ) {
- LoggerD("[Onprogress] %d %", progress);
param["status"] = picojson::value("progress");
param["progress"] = picojson::value(static_cast<double>(progress));
param["id"] = picojson::value(std::string(package));
} else if ( event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED ) {
- LoggerD("[Oncomplete]");
param["status"] = picojson::value("complete");
param["id"] = picojson::value(std::string(package));
}
instance->InvokeCallback(id, param);
- if ( event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED ) {
+ if ( event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED
+ || event_state == PACKAGE_MANAGER_EVENT_STATE_FAILED ) {
LoggerD("Request has been completed");
instance->DeregisterCallback(id);
}
result = str;
}
- LoggerD("URI [%s]", result.c_str());
return result;
}
}
void PackageInstance::RegisterCallback(
- int requestId, int callback_id) {
+ int request_id, int callback_id) {
LoggerD("Enter");
- callbacks_map_[requestId] = callback_id;
+ callbacks_map_[request_id] = callback_id;
}
-void PackageInstance::DeregisterCallback(int requestId) {
- LoggerD("Enter [%d]", requestId);
- callbacks_map_.erase(requestId);
+void PackageInstance::DeregisterCallback(int request_id) {
+ callbacks_map_.erase(request_id);
}
void PackageInstance::InvokeCallback(
- int requestId, picojson::object& param) {
- LoggerD("Enter [%d]", requestId);
+ int request_id, picojson::object& param) {
+ LoggerD("Enter");
- int callback_id = callbacks_map_[requestId];
- LoggerD("callbackId: %d", callback_id);
+ int callback_id = callbacks_map_[request_id];
param["callbackId"] = picojson::value(
static_cast<double>(callback_id));
int callback_id = static_cast<int>(
args.get("callbackId").get<double>());
- LoggerD("callbackId: %d", callback_id);
const std::string& packageFileURI =
convertUriToPath(args.get("packageFileURI").get<std::string>());
- LoggerD("packageFileURI: %s", packageFileURI.c_str());
/* Need to check privilege
ReportError(
return;
}
- int requestId = 0;
+ int request_id = 0;
int ret = package_manager_request_install(
- request_, packageFileURI.c_str(), &requestId);
+ request_, packageFileURI.c_str(), &request_id);
if ( ret != PACKAGE_MANAGER_ERROR_NONE ) {
if ( ret == PACKAGE_MANAGER_ERROR_INVALID_PARAMETER ) {
LoggerE("The package is not found at the specified location");
"the platform or any other platform error occurs"));
}
} else {
- RegisterCallback(requestId, callback_id);
+ RegisterCallback(request_id, callback_id);
}
ReportSuccess(out);
int callback_id =
static_cast<int>(args.get("callbackId").get<double>());
- LoggerD("callbackId: %d", callback_id);
const std::string& id = args.get("id").get<std::string>();
- LoggerD("id: %s", id.c_str());
/* Need to check privilege
ReportError(
return;
}
- int requestId = 0;
- int ret = package_manager_request_uninstall(request_, id.c_str(), &requestId);
+ int request_id = 0;
+ int ret = package_manager_request_uninstall(request_, id.c_str(), &request_id);
if ( ret != PACKAGE_MANAGER_ERROR_NONE ) {
if ( ret == PACKAGE_MANAGER_ERROR_INVALID_PARAMETER ) {
LoggerE("The package is not found at the specified location");
"any other platform error occurs"));
}
} else {
- RegisterCallback(requestId, callback_id);
+ RegisterCallback(request_id, callback_id);
}
ReportSuccess(out);
CHECK_EXIST(args, "callbackId", out)
int callback_id =
static_cast<int>(args.get("callbackId").get<double>());
- LoggerD("callbackId: %d", callback_id);
/* Need to check privilege
ReportError(
if ( args.contains("id") ) {
std::string id = args.get("id").get<std::string>();
- LoggerD("package id : [%s]", id.c_str());
PackageInfoProvider::GetPackageInfo(id.c_str(), out);
} else {
PackageInfoProvider::GetPackageInfo(out);
CHECK_EXIST(args, "callbackId", out)
int callback_id =
static_cast<int>(args.get("callbackId").get<double>());
- LoggerD("callbackId: %d", callback_id);
/* Need to check privilege
ReportError(