[Package] Modify coding style by cpplint and gjslint.
authorByungWoo Lee <bw1212.lee@samsung.com>
Fri, 23 Jan 2015 01:48:31 +0000 (10:48 +0900)
committerByungWoo Lee <bw1212.lee@samsung.com>
Fri, 23 Jan 2015 01:48:31 +0000 (10:48 +0900)
Change-Id: I6b1ada76407eb66e298bb5cc45f923c90ce70e2c

src/package/package.gyp
src/package/package_api.js
src/package/package_extension.cc
src/package/package_extension.h
src/package/package_info_provider.cc
src/package/package_info_provider.h
src/package/package_instance.cc
src/package/package_instance.h

index 2ac5f6495a718bf91068745a8277565ec19ea24b..3d2121375ef16d2ea3e01d43f87fac1e10cdaeb5 100644 (file)
@@ -22,7 +22,6 @@
               'capi-appfw-package-manager',
               'capi-appfw-app-manager',
               'pkgmgr-info',
-              'glib-2.0',
               'pkgmgr'
             ]
           },
index b6aab3b815306af274014d9ae3011824252bdde6..d3e3ad0700902cf857ce315a632788ec2397bc90 100644 (file)
@@ -8,289 +8,308 @@ var callbackId = 0;
 var callbacks = {};
 
 extension.setMessageListener(function(json) {
-    console.log("[Package][extension.setMessageListener] Enter");
-    var result = JSON.parse(json);
-    var callback = callbacks[result['callbackId']];
-    callback(result);
+  console.log('[Package][extension.setMessageListener] Enter');
+  var result = JSON.parse(json);
+  var callback = callbacks[result['callbackId']];
+  callback(result);
 });
 
 function nextCallbackId() {
-    return callbackId++;
+  return callbackId++;
 }
 
 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') {
-        throw new tizen.WebAPIException(tizen.WebAPIException.UNKNOWN_ERR);
+  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') {
+    throw new tizen.WebAPIException(tizen.WebAPIException.UNKNOWN_ERR);
+  }
+
+  if (result['status'] == 'success') {
+    if (result['result']) {
+      return result['result'];
     }
-
-    if (result['status'] == 'success') {
-        if(result['result']) {
-            return result['result'];
-        }
-        return true;
-    } else if (result['status'] == 'error') {
-        var err = result['error'];
-        if(err) {
-            throw new tizen.WebAPIException(err.name, err.message);
-        }
-        return false;
+    return true;
+  } else if (result['status'] == 'error') {
+    var err = result['error'];
+    if (err) {
+      throw new tizen.WebAPIException(err.name, err.message);
     }
+    return false;
+  }
 }
 
 
 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);
-    }
+  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);
+  return callNative(cmd, args);
 }
 
-function SetReadOnlyProperty(obj, n, v){
-    if(arguments.length > 2)
-        Object.defineProperty(obj, n, {value:v, writable: false});
-    else
-        Object.defineProperty(obj, n, {writable: false});
+function SetReadOnlyProperty(obj, n, v) {
+  if (arguments.length > 2)
+    Object.defineProperty(obj, n, {value: v, writable: false, configurable: false});
+  else
+    Object.defineProperty(obj, n, {writable: false, configurable: false});
 }
 
 function PackageInformation(obj) {
-    var lastModified = obj.lastModified;
-    obj.lastModified = new Date(lastModified);
-    SetReadOnlyProperty(obj, 'id'); // read only property 
-    SetReadOnlyProperty(obj, 'name'); // read only property 
-    SetReadOnlyProperty(obj, 'iconPath'); // read only property 
-    SetReadOnlyProperty(obj, 'version'); // read only property 
-    SetReadOnlyProperty(obj, 'totalSize'); // read only property 
-    SetReadOnlyProperty(obj, 'dataSize'); // read only property 
-    SetReadOnlyProperty(obj, 'lastModified'); // read only property 
-    SetReadOnlyProperty(obj, 'author'); // read only property 
-    SetReadOnlyProperty(obj, 'description'); // read only property 
-    SetReadOnlyProperty(obj, 'appIds'); // read only property
-
-    return obj;
+  var lastModified = obj.lastModified;
+  obj.lastModified = new Date(lastModified);
+  SetReadOnlyProperty(obj, 'id'); // read only property
+  SetReadOnlyProperty(obj, 'name'); // read only property
+  SetReadOnlyProperty(obj, 'iconPath'); // read only property
+  SetReadOnlyProperty(obj, 'version'); // read only property
+  SetReadOnlyProperty(obj, 'totalSize'); // read only property
+  SetReadOnlyProperty(obj, 'dataSize'); // read only property
+  SetReadOnlyProperty(obj, 'lastModified'); // read only property
+  SetReadOnlyProperty(obj, 'author'); // read only property
+  SetReadOnlyProperty(obj, 'description'); // read only property
+  SetReadOnlyProperty(obj, 'appIds'); // read only property
+
+  return obj;
 }
 
 function PackageManager() {
-    // constructor of PackageManager
+  // constructor of PackageManager
 }
 
 
 PackageManager.prototype.install = function(packageFileURI, progressCallback) {
-    console.log("[Package][install] Enter");
-
-    var args = validator_.validateArgs(arguments, [
-        {'name' : 'packageFileURI', 'type': types_.STRING},  
-        {'name' : 'progressCallback', 'type': types_.LISTENER, 'values' : ['onprogress', 'oncomplete']},  
-        {'name' : 'errorCallback', 'type': types_.FUNCTION, optional : true, nullable : true}
-    ]);
-
-    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));
-                    return;
-                }
+  console.log('[Package][install] Enter');
+
+  var args = validator_.validateArgs(arguments, [
+    {'name' : 'packageFileURI', 'type' : types_.STRING},
+    {'name' : 'progressCallback',
+      'type' : types_.LISTENER,
+      'values' : ['onprogress', 'oncomplete']},
+    {'name' : 'errorCallback', 'type' : types_.FUNCTION, 'optional' : true, 'nullable' : true}
+  ]);
+
+  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));
+              return;
             }
-            
-            if(result.status == 'complete' || result.status == 'error') {
-                console.log("[Package][installCB] Delete callback");  
-                delete callbacks[result['callbackId']];
-            }
-        });
-    } catch(e) {
-        throw e;
-    }
+          }
 
-}
+          if (result.status == 'complete' || result.status == 'error') {
+            console.log('[Package][installCB] Delete callback');
+            delete callbacks[result['callbackId']];
+          }
+        });
+  } catch (e) {
+    throw e;
+  }
+};
 
 PackageManager.prototype.uninstall = function(id, progressCallback) {
-    console.log("[Package][uninstall] Enter");
-    
-    var args = validator_.validateArgs(arguments, [
-        {'name' : 'id', 'type': types_.STRING},  
-        {'name' : 'progressCallback', 'type': types_.LISTENER, 'values' : ['onprogress', 'oncomplete']},  
-        {'name' : 'errorCallback', 'type': types_.FUNCTION, optional : true, nullable : true}
-    ]);
-
-    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));
-                    return;
-                }
+  console.log('[Package][uninstall] Enter');
+
+  var args = validator_.validateArgs(arguments, [
+    {'name' : 'id', 'type' : types_.STRING},
+    {'name' : 'progressCallback',
+      'type' : types_.LISTENER,
+      'values' : ['onprogress', 'oncomplete']},
+    {'name' : 'errorCallback', 'type' : types_.FUNCTION, 'optional' : true, 'nullable' : true}
+  ]);
+
+  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));
+              return;
             }
+          }
 
-            if(result.status == 'complete' || result.status == 'error') {
-                console.log("[Package][uninstallCB] Delete callback");  
-                delete callbacks[result['callbackId']];
-            }
+          if (result.status == 'complete' || result.status == 'error') {
+            console.log('[Package][uninstallCB] Delete callback');
+            delete callbacks[result['callbackId']];
+          }
         });
-    } catch(e) {
-        throw e;
-    }
+  } catch (e) {
+    throw e;
+  }
 
-}
+};
 
 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} 
-    ]);
-
-    var nativeParam = {
-    };
-
-    try {
-        var syncMsg = callNativeWithCallback('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));
-                    return;
-                }
+  console.log('[Package][getPackagesInfo] Enter');
+
+  var args = validator_.validateArgs(arguments, [
+    {'name' : 'successCallback', 'type' : types_.FUNCTION},
+    {'name' : 'errorCallback', 'type' : types_.FUNCTION, 'optional' : true, 'nullable' : true}
+  ]);
+
+  var nativeParam = {
+  };
+
+  try {
+    var syncMsg = callNativeWithCallback(
+        '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][getPackagesInfoCB] Delete callback");
-            delete callbacks[result['callbackId']];
-        });
-    } catch(e) {
-        throw e;
-    }
+            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));
+              return;
+            }
+          }
+
+          console.log('[Package][getPackagesInfoCB] Delete callback');
+          delete callbacks[result['callbackId']];
+        });
+  } catch (e) {
+    throw e;
+  }
+};
 
 PackageManager.prototype.getPackageInfo = function() {
-    console.log("[Package][getPackageInfo] Enter");
-    
-    var args = validator_.validateArgs(arguments, [
-        {'name' : 'id', 'type': types_.STRING, optional : true, nullable : true} 
-    ]);
-
-    var nativeParam = {
-    };
-    
-    if (args['id']) {
-        nativeParam['id'] = args.id;
-    }
-    
-    try {
-        var resultObject = callNative('PackageManager_getPackageInfo', nativeParam);
-        return PackageInformation(resultObject);
-    } catch(e) {
-        throw e;
-    }
-}
+  console.log('[Package][getPackageInfo] Enter');
+
+  var args = validator_.validateArgs(arguments, [
+    {'name': 'id', 'type': types_.STRING, 'optional' : true, 'nullable' : true}
+  ]);
+
+  var nativeParam = {
+  };
+
+  if (args['id']) {
+    nativeParam['id'] = args.id;
+  }
+
+  try {
+    var resultObject = callNative('PackageManager_getPackageInfo', nativeParam);
+    return PackageInformation(resultObject);
+  } catch (e) {
+    throw e;
+  }
+};
 
 PackageManager.prototype.setPackageInfoEventListener = function(eventCallback) {
-    console.log("[Package][setPackageInfoEventListener] Enter");
-    
-    var args = validator_.validateArgs(arguments, [
-        {'name' : 'eventCallback', 'type': types_.LISTENER, 'values' : ['oninstalled', 'onupdated', 'onuninstalled']} 
-    ]);
-
-    var nativeParam = {
-    };
-    
-    try {
-        var syncResult = callNativeWithCallback('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));
-            }
-            if (result.status == 'updated') {
-                args.eventCallback.onupdated(PackageInformation(result.info));
-            }
-            if (result.status == 'uninstalled') {
-                args.eventCallback.onuninstalled(result.id);
-            }
+  console.log('[Package][setPackageInfoEventListener] Enter');
+
+  var args = validator_.validateArgs(
+      arguments,
+      [
+        {'name' : 'eventCallback',
+          'type' : types_.LISTENER,
+          'values' : ['oninstalled', 'onupdated', 'onuninstalled']}
+      ]);
+
+  var nativeParam = {
+  };
+
+  try {
+    var syncResult = callNativeWithCallback(
+        '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));
+          }
+          if (result.status == 'updated') {
+            args.eventCallback.onupdated(PackageInformation(result.info));
+          }
+          if (result.status == 'uninstalled') {
+            args.eventCallback.onuninstalled(result.id);
+          }
         });
-    } catch(e) {
-        throw e;
-    }
-}
+  } catch (e) {
+    throw e;
+  }
+};
 
 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) {
-        throw e;
+  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) {
+    throw e;
+  }
+};
 
 exports = new PackageManager();
 
index 765194c5a9005e3edd34580e250bd5813e9ab3c4..a59e982127cb6585730bc38604b63a0eb22d2979 100644 (file)
@@ -28,4 +28,4 @@ PackageExtension::~PackageExtension() {
 common::Instance* PackageExtension::CreateInstance() {
   LoggerD("Enter");
   return new extension::package::PackageInstance;
-}
\ No newline at end of file
+}
index b08ea1713f892ea1737e31cfd3bab46132925167..74adf5f486f989f674ca7e983c286259efbc251b 100644 (file)
@@ -16,4 +16,4 @@ class PackageExtension : public common::Extension {
   virtual common::Instance* CreateInstance();
 };
 
-#endif // PACKAGE_PACKAGE_EXTENSION_H_
+#endif  // PACKAGE_PACKAGE_EXTENSION_H_
index dc1a9fce8107d0410677efe20d32cb6cac2a34d1..4f264b924d8df95638b4bf7716e32c1115d52e0a 100644 (file)
@@ -5,7 +5,6 @@
 #include "package/package_info_provider.h"
 
 #include <string.h>
-#include <glib.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <time.h>
 namespace extension {
 namespace package {
 
-using namespace common;
-using namespace extension::package;
+using common::UnknownException;
+using common::NotFoundException;
 
 #define REPORT_ERROR(out, exception) \
   out["status"] = picojson::value("error"); \
   out["error"] = exception.ToJSON();
 
-static int PackageInfoGetListCb(const pkgmgrinfo_pkginfo_h info, void *user_data) {
+static int PackageInfoGetListCb(
+    const pkgmgrinfo_pkginfo_h info, void *user_data) {
   picojson::array* array_data = static_cast<picojson::array*>(user_data);
-  if(!array_data) {
+  if ( !array_data ) {
     LoggerE("user_data is NULL");
     return PMINFO_R_ERROR;
   }
 
   picojson::object object_info;
-  if(PackageInfoProvider::GetPackageInfo(info, object_info)) {
+  if ( PackageInfoProvider::GetPackageInfo(info, object_info) ) {
     array_data->push_back(picojson::value(object_info));
   }
 
   return PMINFO_R_OK;
 }
 
-void PackageInfoProvider::GetPackagesInfo(picojson::object& out) {
+void PackageInfoProvider::GetPackagesInfo(
+    picojson::object& out) {
   LoggerD("Enter");
 
   clock_t start_time, end_time;
   start_time = clock();
 
   picojson::array array_data;
-  if(pkgmgrinfo_pkginfo_get_list(PackageInfoGetListCb, &array_data) != PMINFO_R_OK) {
+  if ( pkgmgrinfo_pkginfo_get_list(PackageInfoGetListCb, &array_data)
+      != PMINFO_R_OK ) {
     LoggerE("Failed to get package information");
-    REPORT_ERROR(out, UnknownException("Any other platform error occurs"));
+    REPORT_ERROR(out, UnknownException(
+        "Any other platform error occurs"));
     return;
   }
 
   end_time = clock();
-  LoggerD(">>>>>>>>>>>>>>> GetPackagesInfo Time : %f s\n",((double)(end_time-start_time)) / CLOCKS_PER_SEC);
+  LoggerD(">>>>>>>>>>>>>>> GetPackagesInfo Time : %f s\n",
+      (static_cast<double>(end_time-start_time)) / CLOCKS_PER_SEC);
 
   LoggerD("status: success");
   out["status"] = picojson::value("success");
@@ -65,52 +69,61 @@ void PackageInfoProvider::GetPackagesInfo(picojson::object& out) {
 
 void PackageInfoProvider::GetPackageInfo(picojson::object& out) {
   LoggerD("Enter");
-  
-  char* packageId = NULL;
-  if(GetCurrentPackageId(&packageId)) {
-    GetPackageInfo(packageId, out);
-    free(packageId);
+
+  char* package_id = NULL;
+  if ( GetCurrentPackageId(&package_id) ) {
+    GetPackageInfo(package_id, out);
+    free(package_id);
   } else {
     LoggerE("Failed to get current package ID");
-    REPORT_ERROR(out, NotFoundException("The package with the specified ID is not found"));
-  }  
+    REPORT_ERROR(out, NotFoundException(
+        "The package with the specified ID is not found"));
+  }
 }
 
-void PackageInfoProvider::GetPackageInfo(const char* packageId, picojson::object& out) {
+void PackageInfoProvider::GetPackageInfo(
+    const char* package_id, picojson::object& out) {
   LoggerD("Enter");
 
-  if(strlen(packageId) <= 0) {
+  if ( strlen(package_id) <= 0 ) {
     LoggerE("Wrong Package ID");
-    REPORT_ERROR(out, NotFoundException("The package with the specified ID is not found"));
-    return;    
+    REPORT_ERROR(out, NotFoundException(
+        "The package with the specified ID is not found"));
+    return;
   }
 
   pkgmgrinfo_pkginfo_h info;
-  if (pkgmgrinfo_pkginfo_get_pkginfo(packageId, &info) != PMINFO_R_OK) {
+  if ( pkgmgrinfo_pkginfo_get_pkginfo(package_id, &info)
+      != PMINFO_R_OK ) {
     LoggerE("Failed to get pkginfo");
-    REPORT_ERROR(out, NotFoundException("The package with the specified ID is not found"));
+    REPORT_ERROR(out, NotFoundException(
+        "The package with the specified ID is not found"));
     return;
   }
 
   picojson::object object_info;
-  if(!GetPackageInfo(info, object_info)) {
+  if ( !GetPackageInfo(info, object_info) ) {
     LoggerE("Failed to convert pkginfo to object");
     REPORT_ERROR(out, UnknownException(
-      "The package information cannot be retrieved because of a platform error"));
+        "The package information cannot be retrieved " \
+        "because of a platform error"));
     return;
   }
 
-  pkgmgrinfo_pkginfo_destroy_pkginfo(info);  
+  pkgmgrinfo_pkginfo_destroy_pkginfo(info);
   out["status"] = picojson::value("success");
   out["result"] = picojson::value(object_info);
 }
 
 static bool PackageAppInfoCb(
-  package_info_app_component_type_e comp_type, const char *app_id, void *user_data) {
+    package_info_app_component_type_e comp_type,
+    const char *app_id,
+    void *user_data) {
   LoggerD("Enter");
-  
-  picojson::array* array_data = static_cast<picojson::array*>(user_data);
-  if(!array_data) {
+
+  picojson::array* array_data =
+      static_cast<picojson::array*>(user_data);
+  if ( !array_data ) {
     LoggerE("user_data is NULL");
     return false;
   }
@@ -120,12 +133,13 @@ static bool PackageAppInfoCb(
   return true;
 }
 
-bool PackageInfoProvider:: GetPackageInfo(const pkgmgrinfo_pkginfo_h info, picojson::object& out) {
+bool PackageInfoProvider:: GetPackageInfo(
+    const pkgmgrinfo_pkginfo_h info, picojson::object& out) {
   int ret = 0;
 
   char* id = NULL;
   ret = pkgmgrinfo_pkginfo_get_pkgid(info, &id);
-  if((ret != PMINFO_R_OK) || (id == NULL)) {
+  if ( (ret != PMINFO_R_OK) || (id == NULL) ) {
     LoggerE("Failed to get package id");
     return false;
   }
@@ -133,7 +147,7 @@ bool PackageInfoProvider:: GetPackageInfo(const pkgmgrinfo_pkginfo_h info, picoj
 
   char* name = NULL;
   ret = pkgmgrinfo_pkginfo_get_label(info, &name);
-  if((ret != PMINFO_R_OK) || (name == NULL)) {
+  if ( (ret != PMINFO_R_OK) || (name == NULL) ) {
     LoggerE("[%s] Failed to get package name", id);
     return false;
   }
@@ -141,7 +155,7 @@ bool PackageInfoProvider:: GetPackageInfo(const pkgmgrinfo_pkginfo_h info, picoj
 
   char* iconPath = NULL;
   ret = pkgmgrinfo_pkginfo_get_icon(info, &iconPath);
-  if((ret != PMINFO_R_OK) || (iconPath == NULL)) {
+  if ( (ret != PMINFO_R_OK) || (iconPath == NULL) ) {
     LoggerE("[%s] Failed to get package iconPath", id);
     return false;
   }
@@ -149,7 +163,7 @@ bool PackageInfoProvider:: GetPackageInfo(const pkgmgrinfo_pkginfo_h info, picoj
 
   char* version = NULL;
   ret = pkgmgrinfo_pkginfo_get_version(info, &version);
-  if((ret != PMINFO_R_OK) || (version == NULL)) {
+  if ( (ret != PMINFO_R_OK) || (version == NULL) ) {
     LoggerE("[%s] Failed to get package version", id);
     return false;
   }
@@ -157,17 +171,17 @@ bool PackageInfoProvider:: GetPackageInfo(const pkgmgrinfo_pkginfo_h info, picoj
 
   int lastModified = 0;
   ret = pkgmgrinfo_pkginfo_get_installed_time(info, &lastModified);
-  if((ret != PMINFO_R_OK)) {
+  if ( (ret != PMINFO_R_OK) ) {
     LoggerE("[%s] Failed to get package lastModified", id);
     return false;
   }
-  // This value will be converted into JavaScript Date object in js file
+  // This value will be converted into JavaScript Date object
   double lastModified_double = lastModified * 1000.0;
   out["lastModified"] = picojson::value(lastModified_double);
 
   char* author = NULL;
   ret = pkgmgrinfo_pkginfo_get_author_name(info, &author);
-  if((ret != PMINFO_R_OK) || (author == NULL)) {
+  if ( (ret != PMINFO_R_OK) || (author == NULL) ) {
     LoggerE("[%s] Failed to get package author", id);
     return false;
   }
@@ -175,7 +189,7 @@ bool PackageInfoProvider:: GetPackageInfo(const pkgmgrinfo_pkginfo_h info, picoj
 
   char* description = NULL;
   ret = pkgmgrinfo_pkginfo_get_description(info, &description);
-  if((ret != PMINFO_R_OK) || (description == NULL)) {
+  if ( (ret != PMINFO_R_OK) || (description == NULL) ) {
     LoggerE("[%s] Failed to get package description", id);
     return false;
   }
@@ -183,18 +197,19 @@ bool PackageInfoProvider:: GetPackageInfo(const pkgmgrinfo_pkginfo_h info, picoj
 
   package_info_h package_info;
   ret = package_info_create(id, &package_info);
-  if (ret != PACKAGE_MANAGER_ERROR_NONE) {
+  if ( ret != PACKAGE_MANAGER_ERROR_NONE ) {
     LoggerE("Failed to create package info");
     return false;
   }
 
   pkgmgr_client *pc = pkgmgr_client_new(PC_REQUEST);
-  if (pc == NULL) {
+  if ( pc == NULL ) {
     LoggerE("Fail to create pkgmgr client");
     return false;
   } else {
-    int ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, PM_GET_TOTAL_SIZE, pc, NULL, id, NULL, NULL, NULL);
-    if (ret < 0) {
+    int ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE,
+        PM_GET_TOTAL_SIZE, pc, NULL, id, NULL, NULL, NULL);
+    if ( ret < 0 ) {
       LoggerE("Fail to get total size");
       return false;
     } else {
@@ -202,8 +217,9 @@ bool PackageInfoProvider:: GetPackageInfo(const pkgmgrinfo_pkginfo_h info, picoj
       out["totalSize"] = picojson::value(static_cast<double>(ret));
     }
 
-    ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, PM_GET_DATA_SIZE, pc, NULL, id, NULL, NULL, NULL);
-    if (ret < 0) {
+    ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, PM_GET_DATA_SIZE,
+        pc, NULL, id, NULL, NULL, NULL);
+    if ( ret < 0 ) {
       LoggerE("Fail to get data size");
       return false;
     } else {
@@ -213,22 +229,24 @@ bool PackageInfoProvider:: GetPackageInfo(const pkgmgrinfo_pkginfo_h info, picoj
   }
 
   picojson::array array_data;
-  ret = package_info_foreach_app_from_package(package_info, PACKAGE_INFO_ALLAPP, PackageAppInfoCb, &array_data);
-  if (ret != PACKAGE_MANAGER_ERROR_NONE) {
+  ret = package_info_foreach_app_from_package(package_info,
+      PACKAGE_INFO_ALLAPP, PackageAppInfoCb, &array_data);
+  if ( ret != PACKAGE_MANAGER_ERROR_NONE ) {
     LoggerE("Failed to get app info");
     return false;
   }
   out["appIds"] = picojson::value(array_data);
 
   ret = package_info_destroy(package_info);
-  if (ret != PACKAGE_MANAGER_ERROR_NONE) {
+  if ( ret != PACKAGE_MANAGER_ERROR_NONE ) {
     LoggerE("Failed to destroy package info");
   }
 
   return true;
 }
 
-bool PackageInfoProvider::GetCurrentPackageId(char** packageId) {
+bool PackageInfoProvider::GetCurrentPackageId(
+    char** package_id) {
   LoggerD("Enter");
 
   int ret = 0;
@@ -237,7 +255,7 @@ bool PackageInfoProvider::GetCurrentPackageId(char** packageId) {
   int pid = getpid();
   LoggerD("pid: %d", pid);
   ret = app_manager_get_app_id(pid, &app_id);
-  if (ret != APP_MANAGER_ERROR_NONE) {
+  if ( ret != APP_MANAGER_ERROR_NONE ) {
     LoggerE("Failed to get app id");
     return false;
   }
@@ -245,14 +263,14 @@ bool PackageInfoProvider::GetCurrentPackageId(char** packageId) {
   app_info_h handle;
   ret = app_info_create(app_id, &handle);
   free(app_id);
-  if (ret != APP_MANAGER_ERROR_NONE) {
-    LoggerE("Fail to get app info");    
+  if ( ret != APP_MANAGER_ERROR_NONE ) {
+    LoggerE("Fail to get app info");
     return false;
   }
 
-  ret = app_info_get_package(handle, packageId);
+  ret = app_info_get_package(handle, package_id);
   app_info_destroy(handle);
-  if ((ret != APP_MANAGER_ERROR_NONE) || (*packageId == NULL)) {
+  if ( (ret != APP_MANAGER_ERROR_NONE) || (*package_id == NULL) ) {
     LoggerE("Fail to get pkg id");
     return false;
   }
@@ -264,5 +282,5 @@ bool PackageInfoProvider::GetCurrentPackageId(char** packageId) {
 
 #undef REPORT_ERROR
 
-} // namespace package
-} // namespace extension
+}  // namespace package
+}  // namespace extension
index 10c6e645975a5da02228ecd60b9367e485e2e4eb..9e91afa257dddbefe4cb6ab9d547e367045b5092 100644 (file)
@@ -20,24 +20,30 @@ class PackageInfoProvider {
   virtual ~PackageInfoProvider();
 
   /* out["status"] = "success" or "error"
-  * If status is "success", then the result(picojson::value) will be stored in out["informationArray"].
-  * If status is "error", then the error(picojson::value) will be stored in out["error"].
+  * If status is "success", then the result(picojson::value)
+  * will be stored in out["informationArray"].
+  * If status is "error", then the error(picojson::value)
+  * will be stored in out["error"].
   */
   static void GetPackagesInfo(picojson::object& out);
 
   /* out["status"] = "success" or "error"
-  * If status is "success", then the result(picojson::value) will be stored in out["result"].
-  * If status is "error", then the error(picojson::value) will be stored in out["error"].
+  * If status is "success", then the result(picojson::value)
+  * will be stored in out["result"].
+  * If status is "error", then the error(picojson::value)
+  * will be stored in out["error"].
   */
-  static void GetPackageInfo(picojson::object& out);  
-  static void GetPackageInfo(const char* packageId, picojson::object& out);
-  static bool GetPackageInfo(const pkgmgrinfo_pkginfo_h info, picojson::object& out);
-  
+  static void GetPackageInfo(picojson::object& out);
+  static void GetPackageInfo(const char* package_id,
+      picojson::object& out);
+  static bool GetPackageInfo(const pkgmgrinfo_pkginfo_h info,
+      picojson::object& out);
+
  private:
-  static bool GetCurrentPackageId(char** packageId);
+  static bool GetCurrentPackageId(char** package_id);
 };
 
-} // namespace package
-} // namespace extension
+}  // namespace package
+}  // namespace extension
 
-#endif // PACKAGE_PACKAGE_INFO_PROVIDER_H_
+#endif  // PACKAGE_PACKAGE_INFO_PROVIDER_H_
index b88e633ffc0cffebe6736b4c406594ad09122758..e63e7be6067731c5dd715ec028f262c4b62af1bd 100644 (file)
@@ -4,9 +4,8 @@
 
 #include "package/package_instance.h"
 
-#include <glib.h>
-
 #include <functional>
+#include <string>
 
 #include "package/package_info_provider.h"
 #include "common/logger.h"
 namespace extension {
 namespace package {
 
+using common::TaskQueue;
+using common::PlatformException;
+using common::UnknownException;
+using common::NotFoundException;
+using common::TypeMismatchException;
+using common::SecurityException;
+
 namespace {
 // The privileges that required in Package API
-const std::string kPrivilegePackageInstall = "http://tizen.org/privilege/packagemanager.install";
-const std::string kPrivilegePackageInfo = "http://tizen.org/privilege/package.info";
-} // namespace
-
-using namespace common;
-using namespace extension::package;
+const std::string kPrivilegePackageInstall =
+    "http://tizen.org/privilege/packagemanager.install";
+const std::string kPrivilegePackageInfo =
+    "http://tizen.org/privilege/package.info";
+}  // namespace
 
 typedef enum _PackageThreadWorkType {
-  PackageThreadWorkNone = 0, 
-  PackageThreadWorkGetPackagesInfo, 
+  PackageThreadWorkNone = 0,
+  PackageThreadWorkGetPackagesInfo,
 } PackageThreadWorkType;
 
 class PackageUserData {
  public:
-  PackageUserData(PackageInstance* ins, int id, PackageThreadWorkType task) {
-    instance = ins;
-    callbackId = id;
-    work = task;
-  }  
-  
-  PackageInstance* instance;
-  int callbackId;  
-  PackageThreadWorkType work;
-  picojson::object data;
+  PackageUserData(PackageInstance* ins,
+      int id,
+      PackageThreadWorkType task) {
+    instance_ = ins;
+    callback_id_ = id;
+    work_ = task;
+  }
+
+  PackageInstance* instance_;
+  int callback_id_;
+  PackageThreadWorkType work_;
+  picojson::object data_;
 };
 typedef std::shared_ptr<PackageUserData> PackageUserDataPtr;
 
-static void* PackageThreadWork(const PackageUserDataPtr& userData) {
+static void* PackageThreadWork(
+    const PackageUserDataPtr& userData) {
   LoggerD("Enter");
 
-  PackageInstance* instance = userData->instance;
+  PackageInstance* instance = userData->instance_;
 
-  switch(userData->work) {
+  switch ( userData->work_ ) {
     case PackageThreadWorkGetPackagesInfo: {
-      LoggerD("Start PackageThreadWorkGetPackagesInfo");      
+      LoggerD("Start PackageThreadWorkGetPackagesInfo");
       picojson::object output;
       PackageInfoProvider::GetPackagesInfo(output);
-      userData->data = output;
+      userData->data_ = output;
       break;
     }
     default: {
@@ -66,86 +74,96 @@ static void* PackageThreadWork(const PackageUserDataPtr& userData) {
   return NULL;
 }
 
-static gboolean PackageAfterWork(const PackageUserDataPtr& userData) {
+static gboolean PackageAfterWork(
+    const PackageUserDataPtr& userData) {
   LoggerD("Enter");
-  
-  userData->data["callbackId"] = picojson::value(static_cast<double>(userData->callbackId));  
-  picojson::value result = picojson::value(userData->data);
-  userData->instance->PostMessage(result.serialize().c_str());
+
+  userData->data_["callbackId"] =
+      picojson::value(static_cast<double>(userData->callback_id_));
+  picojson::value result = picojson::value(userData->data_);
+  userData->instance_->PostMessage(result.serialize().c_str());
 
   return FALSE;
 }
 
 static void PackageRequestCb(
-    int id, const char *type, const char *package, package_manager_event_type_e event_type, 
-    package_manager_event_state_e event_state, int progress, package_manager_error_e error, void *user_data) {
+    int id, const char *type, const char *package,
+    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 ( !instance ) {
     LoggerE("instance is NULL");
     return;
   }
 
-  if(event_state == PACKAGE_MANAGER_EVENT_STATE_STARTED) {
+  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) {
+  if ( event_state == PACKAGE_MANAGER_EVENT_STATE_FAILED ) {
     LoggerD("[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) {
+        "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) {
+  } 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 ) {
     LoggerD("Request has been completed");
     instance->DeregisterCallback(id);
   }
 }
 
 static void PackageListenerCb(
-    const char *type, const char *package, package_manager_event_type_e event_type, 
-    package_manager_event_state_e event_state, int progress, package_manager_error_e error, void *user_data) {
+    const char *type, const char *package,
+    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");
 
   PackageInstance* instance = static_cast<PackageInstance*>(user_data);
-  if(!instance) {
+  if ( !instance ) {
     LoggerE("instance is NULL");
     return;
   }
 
-  if(error != PACKAGE_MANAGER_ERROR_NONE) {
+  if ( error != PACKAGE_MANAGER_ERROR_NONE ) {
     LoggerE("Failed");
-    return;    
+    return;
   }
 
   picojson::object param;
-  if(event_type == PACKAGE_MANAGER_EVENT_TYPE_INSTALL && event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED) {
+  if ( event_type == PACKAGE_MANAGER_EVENT_TYPE_INSTALL
+      && event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED ) {
     LoggerD("[Installed]");
     param["status"] = picojson::value("installed");
     picojson::object info;
     PackageInfoProvider::GetPackageInfo(package, info);
     param["info"] = picojson::value(info["result"]);
     instance->InvokeListener(param);
-  } else if(event_type == PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL && event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED) {
+  } else if ( event_type == PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL
+      && event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED ) {
     LoggerD("[Uninstalled]");
     param["status"] = picojson::value("uninstalled");
     param["id"] = picojson::value(std::string(package));
     instance->InvokeListener(param);
-  } else if(event_type == PACKAGE_MANAGER_EVENT_TYPE_UPDATE && event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED) {
+  } else if ( event_type == PACKAGE_MANAGER_EVENT_TYPE_UPDATE
+      && event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED ) {
     LoggerD("[Updated]");
     param["status"] = picojson::value("updated");
     picojson::object info;
@@ -155,172 +173,254 @@ static void PackageListenerCb(
   }
 }
 
+static std::string ltrim(const std::string& s) {
+    std::string str = s;
+    std::string::iterator i;
+    for (i = str.begin(); i != str.end(); i++) {
+        if ( !isspace(*i) ) {
+            break;
+        }
+    }
+    if ( i == str.end() ) {
+        str.clear();
+    } else {
+        str.erase(str.begin(), i);
+    }
+    return str;
+}
+
+static std::string convertUriToPath(const std::string& uri) {
+    std::string result;
+    std::string schema("file://");
+    std::string str = ltrim(uri);
+
+    std::string _schema = str.substr(0, schema.size());
+    if ( _schema == schema ) {
+        result = str.substr(schema.size());
+    } else {
+        result = str;
+    }
+
+    LoggerD("URI [%s]", result.c_str());
+    return result;
+}
+
 PackageInstance::PackageInstance() {
   LoggerD("Enter");
 
-  if(package_manager_request_create(&pRequest) != PACKAGE_MANAGER_ERROR_NONE) {
+  if ( package_manager_request_create(&request_)
+      != PACKAGE_MANAGER_ERROR_NONE ) {
     LoggerE("Failed to created package manager request");
-    pRequest = NULL;
-  } 
+    request_ = NULL;
+  }
 
-  if(package_manager_request_set_event_cb(pRequest, PackageRequestCb, static_cast<void*>(this))
-      != PACKAGE_MANAGER_ERROR_NONE) {
+  if ( package_manager_request_set_event_cb(request_, PackageRequestCb,
+      static_cast<void*>(this)) != PACKAGE_MANAGER_ERROR_NONE ) {
     LoggerE("Failed to set request event callback");
   }
 
-  if(package_manager_create(&pManager) != PACKAGE_MANAGER_ERROR_NONE) {
+  if ( package_manager_create(&manager_) != PACKAGE_MANAGER_ERROR_NONE ) {
     LoggerE("Failed to created package manager");
-    pManager = NULL;
+    manager_ = NULL;
   }
 
-  listenerId = -1;
-  
-  using namespace std::placeholders;
-  #define REGISTER_SYNC(c,x) \
+  listener_id_ = -1;
+
+  using std::placeholders::_1;
+  using std::placeholders::_2;
+  #define REGISTER_SYNC(c, x) \
     RegisterSyncHandler(c, std::bind(&PackageInstance::x, this, _1, _2));
-  REGISTER_SYNC("PackageManager_setPackageInfoEventListener", PackageManagerSetpackageinfoeventlistener);
-  REGISTER_SYNC("PackageManager_install", PackageManagerInstall);
-  REGISTER_SYNC("PackageManager_getPackagesInfo", PackageManagerGetpackagesinfo);
-  REGISTER_SYNC("PackageManager_uninstall", PackageManagerUninstall);
-  REGISTER_SYNC("PackageManager_unsetPackageInfoEventListener", PackageManagerUnsetpackageinfoeventlistener);
-  REGISTER_SYNC("PackageManager_getPackageInfo", PackageManagerGetpackageinfo);
+  REGISTER_SYNC("PackageManager_setPackageInfoEventListener",
+      PackageManagerSetpackageinfoeventlistener);
+  REGISTER_SYNC("PackageManager_install",
+      PackageManagerInstall);
+  REGISTER_SYNC("PackageManager_getPackagesInfo",
+      PackageManagerGetpackagesinfo);
+  REGISTER_SYNC("PackageManager_uninstall",
+      PackageManagerUninstall);
+  REGISTER_SYNC("PackageManager_unsetPackageInfoEventListener",
+      PackageManagerUnsetpackageinfoeventlistener);
+  REGISTER_SYNC("PackageManager_getPackageInfo",
+      PackageManagerGetpackageinfo);
   #undef REGISTER_SYNC
 }
 
 PackageInstance::~PackageInstance() {
   LoggerD("Enter");
-  package_manager_request_unset_event_cb(pRequest);
-  package_manager_request_destroy(pRequest);
-  package_manager_destroy(pManager);
+  package_manager_request_unset_event_cb(request_);
+  package_manager_request_destroy(request_);
+  package_manager_destroy(manager_);
 }
 
 #define CHECK_EXIST(args, name, out) \
-    if (!args.contains(name)) {\
+    if (  !args.contains(name) ) {\
       ReportError(TypeMismatchException(name" is required argument"), out);\
       return;\
     }
 
-void PackageInstance::RegisterCallback(int requestId, int callbackId) {
+void PackageInstance::RegisterCallback(
+    int requestId, int callback_id) {
   LoggerD("Enter");
-  callbacksMap[requestId] = callbackId;
+  callbacks_map_[requestId] = callback_id;
 }
 
 void PackageInstance::DeregisterCallback(int requestId) {
   LoggerD("Enter [%d]", requestId);
-  callbacksMap.erase(requestId);
+  callbacks_map_.erase(requestId);
 }
 
-void PackageInstance::InvokeCallback(int requestId, picojson::object& param) {
+void PackageInstance::InvokeCallback(
+    int requestId, picojson::object& param) {
   LoggerD("Enter [%d]", requestId);
 
-  int callbackId = callbacksMap[requestId];
-  LoggerD("callbackId: %d", callbackId);
+  int callback_id = callbacks_map_[requestId];
+  LoggerD("callbackId: %d", callback_id);
 
-  param["callbackId"] = picojson::value(static_cast<double>(callbackId));  
+  param["callbackId"] = picojson::value(
+      static_cast<double>(callback_id));
   picojson::value result = picojson::value(param);
   PostMessage(result.serialize().c_str());
 }
 
-void PackageInstance::PackageManagerInstall(const picojson::value& args, picojson::object& out) {
+void PackageInstance::PackageManagerInstall(
+    const picojson::value& args, picojson::object& out) {
   LoggerD("Enter");
-  
+
   CHECK_EXIST(args, "callbackId", out)
   CHECK_EXIST(args, "packageFileURI", out)
 
-  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
-  LoggerD("callbackId: %d", callbackId);
-  const std::string& packageFileURI = args.get("packageFileURI").get<std::string>();
+  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
-  // throw new SecurityException("This application does not have the privilege to call this method");
 
-  if(!pRequest) {
+  /* Need to check privilege
+  ReportError(
+      SecurityException("This application does not have " \
+      "the privilege to call this method"),
+      out);
+  return;
+  */
+
+  if ( !request_ ) {
     LoggerE("package_manager_request_h is NULL");
-    InvokeErrorCallbackAsync(callbackId, 
-      UnknownException("It is not allowed to install the package by the platform or any other platform error occurs"));
+    InvokeErrorCallbackAsync(callback_id,
+      UnknownException("It is not allowed to install the package by " \
+          "the platform or any other platform error occurs"));
     return;
   }
 
   int requestId = 0;
-  int ret = package_manager_request_install(pRequest, packageFileURI.c_str(), &requestId);
-  if(ret != PACKAGE_MANAGER_ERROR_NONE) {
-    if(ret == PACKAGE_MANAGER_ERROR_INVALID_PARAMETER) {
+  int ret = package_manager_request_install(
+      request_, packageFileURI.c_str(), &requestId);
+  if ( ret != PACKAGE_MANAGER_ERROR_NONE ) {
+    if ( ret == PACKAGE_MANAGER_ERROR_INVALID_PARAMETER ) {
       LoggerE("The package is not found at the specified location");
-      InvokeErrorCallbackAsync(callbackId, 
-        NotFoundException("The package is not found at the specified location"));
+      InvokeErrorCallbackAsync(callback_id,
+          NotFoundException(
+          "The package is not found at the specified location"));
     } else {
-      LoggerE("It is not allowed to install the package by the platform or any other platform error occurs");
-      InvokeErrorCallbackAsync(callbackId, 
-        UnknownException("It is not allowed to install the package by the platform or any other platform error occurs"));
+      LoggerE("It is not allowed to install the package by " \
+          "the platform or any other platform error occurs");
+      InvokeErrorCallbackAsync(callback_id,
+          UnknownException("It is not allowed to install the package by " \
+          "the platform or any other platform error occurs"));
     }
   } else {
-    RegisterCallback(requestId, callbackId);
+    RegisterCallback(requestId, callback_id);
   }
-  
+
   ReportSuccess(out);
 }
 
-void PackageInstance::PackageManagerUninstall(const picojson::value& args, picojson::object& out) {
+void PackageInstance::PackageManagerUninstall(
+    const picojson::value& args, picojson::object& out) {
   LoggerD("Enter");
-  
+
   CHECK_EXIST(args, "callbackId", out)
   CHECK_EXIST(args, "id", out)
-  
-  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
-  LoggerD("callbackId: %d", callbackId);
+
+  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
-  // throw new SecurityException("This application does not have the privilege to call this method");
+  /* Need to check privilege
+  ReportError(
+      SecurityException("This application does not have " \
+      "the privilege to call this method"),
+      out);
+  return;
+  */
 
-  if(!pRequest) {
+  if ( !request_ ) {
     LoggerE("package_manager_request_h is NULL");
-    InvokeErrorCallbackAsync(callbackId, 
-      UnknownException("It is not allowed to install the package by the platform or any other platform error occurs"));
+    InvokeErrorCallbackAsync(callback_id,
+        UnknownException("It is not allowed to install the package by " \
+        "the platform or any other platform error occurs"));
     return;
   }
 
   int requestId = 0;
-  int ret = package_manager_request_uninstall(pRequest, id.c_str(), &requestId);
-  if(ret != PACKAGE_MANAGER_ERROR_NONE) {
-    if(ret == PACKAGE_MANAGER_ERROR_INVALID_PARAMETER) {
+  int ret = package_manager_request_uninstall(request_, id.c_str(), &requestId);
+  if ( ret != PACKAGE_MANAGER_ERROR_NONE ) {
+    if ( ret == PACKAGE_MANAGER_ERROR_INVALID_PARAMETER ) {
       LoggerE("The package is not found at the specified location");
-      InvokeErrorCallbackAsync(callbackId, 
-        NotFoundException("The package is not found at the specified location"));
+      InvokeErrorCallbackAsync(callback_id,
+        NotFoundException(
+            "The package is not found at the specified location"));
     } else {
-      LoggerE("It is not allowed to install the package by the platform or any other platform error occurs");
-      InvokeErrorCallbackAsync(callbackId, 
-        UnknownException("It is not allowed to install the package by the platform or any other platform error occurs"));
+      LoggerE("It is not allowed to install the package by the " \
+          "platform or any other platform error occurs");
+      InvokeErrorCallbackAsync(callback_id, UnknownException(
+          "It is not allowed to install the package by the platform or " \
+          "any other platform error occurs"));
     }
   } else {
-    RegisterCallback(requestId, callbackId);
+    RegisterCallback(requestId, callback_id);
   }
-  
+
   ReportSuccess(out);
 }
-void PackageInstance::PackageManagerGetpackagesinfo(const picojson::value& args, picojson::object& out) {
+void PackageInstance::PackageManagerGetpackagesinfo(
+    const picojson::value& args, picojson::object& out) {
   LoggerD("Enter");
 
   CHECK_EXIST(args, "callbackId", out)
-  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
-  LoggerD("callbackId: %d", callbackId);
-
-  // Need to check privilege
-  // throw new SecurityException("This application does not have the privilege to call this method");
-
-  PackageUserDataPtr userData(new PackageUserData(this, callbackId, PackageThreadWorkGetPackagesInfo));
-  TaskQueue::GetInstance().Queue<PackageUserData>(PackageThreadWork, PackageAfterWork, userData);
+  int callback_id =
+      static_cast<int>(args.get("callbackId").get<double>());
+  LoggerD("callbackId: %d", callback_id);
+
+  /* Need to check privilege
+  ReportError(
+      SecurityException("This application does not have " \
+      "the privilege to call this method"),
+      out);
+  return;
+  */
+
+  PackageUserDataPtr userData(new PackageUserData(
+      this, callback_id, PackageThreadWorkGetPackagesInfo));
+  TaskQueue::GetInstance().Queue<PackageUserData>(
+      PackageThreadWork, PackageAfterWork, userData);
   ReportSuccess(out);
 }
-void PackageInstance::PackageManagerGetpackageinfo(const picojson::value& args, picojson::object& out) {
+void PackageInstance::PackageManagerGetpackageinfo(
+    const picojson::value& args, picojson::object& out) {
   LoggerD("Enter");
 
-  // Need to check privilege
-  // throw new SecurityException("This application does not have the privilege to call this method");
+  /* Need to check privilege
+  ReportError(
+      SecurityException("This application does not have " \
+      "the privilege to call this method"),
+      out);
+  return;
+  */
 
-  if(args.contains("id")) {
+  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);
@@ -332,78 +432,109 @@ void PackageInstance::PackageManagerGetpackageinfo(const picojson::value& args,
 void PackageInstance::InvokeListener(picojson::object& param) {
   LoggerD("Enter");
 
-  param["callbackId"] = picojson::value(static_cast<double>(listenerId));  
+  param["callbackId"] = picojson::value(static_cast<double>(listener_id_));
   picojson::value result = picojson::value(param);
   PostMessage(result.serialize().c_str());
 }
 
-void PackageInstance::PackageManagerSetpackageinfoeventlistener(const picojson::value& args, picojson::object& out) {
+void PackageInstance::
+    PackageManagerSetpackageinfoeventlistener(
+    const picojson::value& args, picojson::object& out) {
   LoggerD("Enter");
-  
-  CHECK_EXIST(args, "callbackId", out)
-  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
-  LoggerD("callbackId: %d", callbackId);
 
-  // Need to check privilege
-  // throw new SecurityException("This application does not have the privilege to call this method");
-
-  if(!pManager) {
+  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(
+      SecurityException("This application does not have " \
+      "the privilege to call this method"),
+      out);
+  return;
+  */
+
+  if ( !manager_ ) {
     LoggerE("package_manager_h is NULL");
-    throw new UnknownException(
-      "The package list change event cannot be generated because of a platform error");
+    ReportError(
+        UnknownException("The package list change event cannot be " \
+        "generated because of a platform error"),
+        out);
+    return;
   }
 
-  if(package_manager_set_event_cb(pManager, PackageListenerCb, static_cast<void*>(this))
-      != PACKAGE_MANAGER_ERROR_NONE) {
+  if ( package_manager_set_event_cb(
+      manager_, PackageListenerCb, static_cast<void*>(this))
+      != PACKAGE_MANAGER_ERROR_NONE ) {
     LoggerE("Failed to set event callback");
-    throw new UnknownException(
-      "The package list change event cannot be generated because of a platform error");    
+    ReportError(
+        UnknownException("The package list change event cannot be " \
+        "generated because of a platform error"),
+        out);
+    return;
   }
 
-  listenerId = callbackId;  
+  listener_id_ = callback_id;
   ReportSuccess(out);
 }
 
-void PackageInstance::PackageManagerUnsetpackageinfoeventlistener(const picojson::value& args, picojson::object& out) {
+void PackageInstance::
+    PackageManagerUnsetpackageinfoeventlistener(
+    const picojson::value& args, picojson::object& out) {
   LoggerD("Enter");
 
-  // Need to check privilege
-  // throw new SecurityException("This application does not have the privilege to call this method");
+  /* Need to check privilege
+  ReportError(
+      SecurityException("This application does not have " \
+      "the privilege to call this method"),
+      out);
+  return;
+  */
 
-  if(listenerId == -1) {
+  if ( listener_id_ == -1 ) {
     LoggerD("Listener is not set");
     ReportSuccess(out);
     return;
   }
 
-  if(!pManager) {
+  if ( !manager_ ) {
     LoggerE("package_manager_h is NULL");
-    throw new UnknownException(
-      "Tthe listener removal request fails because of a platform error");
+    ReportError(
+        UnknownException("The listener removal request fails" \
+        "because of a platform error"),
+        out);
+    return;
   }
 
-  if(package_manager_unset_event_cb(pManager)
-      != PACKAGE_MANAGER_ERROR_NONE) {
+  if ( package_manager_unset_event_cb(manager_)
+      != PACKAGE_MANAGER_ERROR_NONE ) {
     LoggerE("Failed to unset event callback");
-    throw new UnknownException(
-      "Tthe listener removal request fails because of a platform error");    
+    ReportError(
+        UnknownException("The listener removal request fails" \
+        "because of a platform error"),
+        out);
+    return;
   }
 
-  ReportSuccess(picojson::value(static_cast<double>(listenerId)), out);
-  listenerId = -1;
+  ReportSuccess(picojson::value(static_cast<double>(listener_id_)), out);
+  listener_id_ = -1;
 }
 
-void PackageInstance::InvokeErrorCallbackAsync(int callbackId, const PlatformException& ex) {
+void PackageInstance::InvokeErrorCallbackAsync(
+    int callback_id, const PlatformException& ex) {
   LoggerD("Enter");
 
   picojson::object param;
   ReportError(ex, param);
-  PackageUserDataPtr userData(new PackageUserData(this, callbackId, PackageThreadWorkNone));
-  userData->data = param;
-  TaskQueue::GetInstance().Async<PackageUserData>(PackageAfterWork, userData);
+  PackageUserDataPtr userData(new PackageUserData(
+      this, callback_id, PackageThreadWorkNone));
+  userData->data_ = param;
+  TaskQueue::GetInstance().Async
+    <PackageUserData>(PackageAfterWork, userData);
 }
 
 #undef CHECK_EXIST
 
-} // namespace package
-} // namespace extension
+}  // namespace package
+}  // namespace extension
index 16ffbbedfc3d5c5a5fe6e7bf47516bf5c3309553..1b440cc525de38b3a2eccdff5f859ca72dcd302d 100644 (file)
@@ -25,23 +25,30 @@ class PackageInstance : public common::ParsedInstance {
   void DeregisterCallback(int requestId);
 
  private:
-  package_manager_request_h pRequest;
-  package_manager_h pManager;
-  int listenerId;
-  std::map<int, int> callbacksMap;  // <requestId, callbackId>
-
-  void RegisterCallback(int requestId, int callbackId);
-  void InvokeErrorCallbackAsync(int callbackId, const common::PlatformException& ex);
-  
-  void PackageManagerInstall(const picojson::value& args, picojson::object& out);
-  void PackageManagerUninstall(const picojson::value& args, picojson::object& out);
-  void PackageManagerGetpackagesinfo(const picojson::value& args, picojson::object& out);
-  void PackageManagerGetpackageinfo(const picojson::value& args, picojson::object& out);
-  void PackageManagerSetpackageinfoeventlistener(const picojson::value& args, picojson::object& out);
-  void PackageManagerUnsetpackageinfoeventlistener(const picojson::value& args, picojson::object& out);
+  package_manager_request_h request_;
+  package_manager_h manager_;
+  int listener_id_;
+  std::map<int, int> callbacks_map_;  // <requestId, callbackId>
+
+  void RegisterCallback(int requestId, int callback_id);
+  void InvokeErrorCallbackAsync
+    (int callback_id, const common::PlatformException& ex);
+
+  void PackageManagerInstall
+    (const picojson::value& args, picojson::object& out);
+  void PackageManagerUninstall(
+    const picojson::value& args, picojson::object& out);
+  void PackageManagerGetpackagesinfo
+    (const picojson::value& args, picojson::object& out);
+  void PackageManagerGetpackageinfo
+    (const picojson::value& args, picojson::object& out);
+  void PackageManagerSetpackageinfoeventlistener
+    (const picojson::value& args, picojson::object& out);
+  void PackageManagerUnsetpackageinfoeventlistener
+    (const picojson::value& args, picojson::object& out);
 };
 
-} // namespace package
-} // namespace extension
+}  // namespace package
+}  // namespace extension
 
-#endif // PACKAGE_PACKAGE_INSTANCE_H_
+#endif  // PACKAGE_PACKAGE_INSTANCE_H_