celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1543336 - in /incubator/celix/trunk: framework/private/src/framework.c framework/public/include/celix_errno.h framework/public/include/framework.h launcher/private/src/launcher.c
Date Tue, 19 Nov 2013 07:43:47 GMT
Author: abroekhuis
Date: Tue Nov 19 07:43:47 2013
New Revision: 1543336

URL: http://svn.apache.org/r1543336
Log:
CELIX-87: Added example for returning status struct instead of only a error_code.

Modified:
    incubator/celix/trunk/framework/private/src/framework.c
    incubator/celix/trunk/framework/public/include/celix_errno.h
    incubator/celix/trunk/framework/public/include/framework.h
    incubator/celix/trunk/launcher/private/src/launcher.c

Modified: incubator/celix/trunk/framework/private/src/framework.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/framework.c?rev=1543336&r1=1543335&r2=1543336&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/framework.c (original)
+++ incubator/celix/trunk/framework/private/src/framework.c Tue Nov 19 07:43:47 2013
@@ -194,8 +194,9 @@ struct request {
 
 typedef struct request *request_pt;
 
-celix_status_t framework_create(framework_pt *framework, apr_pool_t *memoryPool, properties_pt
config) {
+struct celix_status framework_create(framework_pt *framework, apr_pool_t *memoryPool, properties_pt
config) {
     celix_status_t status = CELIX_SUCCESS;
+    char *error = NULL;
 
     *framework = (framework_pt) apr_palloc(memoryPool, sizeof(**framework));
     if (*framework != NULL) {
@@ -240,11 +241,15 @@ celix_status_t framework_create(framewor
             fw_logCode(FW_LOG_ERROR, status, "Could not create framework");
         }
     } else {
+        error = "FW exception";
         status = CELIX_FRAMEWORK_EXCEPTION;
         fw_logCode(FW_LOG_ERROR, CELIX_ENOMEM, "Could not create framework");
     }
 
-    return status;
+    struct celix_status stat;
+    stat.code = status;
+    stat.error = error;
+    return stat;
 }
 
 celix_status_t framework_destroy(framework_pt framework) {
@@ -557,22 +562,22 @@ celix_status_t fw_installBundle2(framewo
 
         if (status == CELIX_SUCCESS) {
             locked = framework_acquireGlobalLock(framework);
-            if (locked) {
-                status = CELIX_DO_IF(status, bundle_createFromArchive(bundle, framework,
archive, bundlePool));
-            } else {
+            if (!locked) {
                 status = CELIX_BUNDLE_EXCEPTION;
-            }
-
-            status = CELIX_DO_IF(status, framework_releaseGlobalLock(framework));
-            if (status == CELIX_SUCCESS) {
-                hashMap_put(framework->installedBundleMap, location, *bundle);
             } else {
-                status = CELIX_BUNDLE_EXCEPTION;
-                status = CELIX_DO_IF(status, bundleArchive_closeAndDelete(archive));
-                apr_pool_destroy(bundlePool);
+                status = CELIX_DO_IF(status, bundle_createFromArchive(bundle, framework,
archive, bundlePool));
+
+                framework_releaseGlobalLock(framework);
+                if (status == CELIX_SUCCESS) {
+                    hashMap_put(framework->installedBundleMap, location, *bundle);
+                } else {
+                    status = CELIX_BUNDLE_EXCEPTION;
+                    status = CELIX_DO_IF(status, bundleArchive_closeAndDelete(archive));
+                    apr_pool_destroy(bundlePool);
+                }
             }
-            status = CELIX_DO_IF(status, framework_releaseInstallLock(framework, location));
         }
+        status = CELIX_DO_IF(status, framework_releaseInstallLock(framework, location));
   	}
 
     if (status != CELIX_SUCCESS) {
@@ -1802,6 +1807,7 @@ celix_status_t framework_acquireBundleLo
 	bool locked;
 	apr_os_thread_t lockingThread = 0;
 
+	printf("Acq bundle lock\n");
 	int err = apr_thread_mutex_lock(framework->bundleLock);
 	if (err != APR_SUCCESS) {
 		fw_log(FW_LOG_ERROR,  "Failed to lock");
@@ -1862,6 +1868,7 @@ bool framework_releaseBundleLock(framewo
     bool unlocked;
     apr_os_thread_t lockingThread = 0;
 
+    printf("Rel bundle lock\n");
     apr_thread_mutex_lock(framework->bundleLock);
 
     bundle_unlock(bundle, &unlocked);

Modified: incubator/celix/trunk/framework/public/include/celix_errno.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/public/include/celix_errno.h?rev=1543336&r1=1543335&r2=1543336&view=diff
==============================================================================
--- incubator/celix/trunk/framework/public/include/celix_errno.h (original)
+++ incubator/celix/trunk/framework/public/include/celix_errno.h Tue Nov 19 07:43:47 2013
@@ -48,6 +48,11 @@
  * \{
  */
 
+struct celix_status {
+    int code;
+    char *error;
+};
+
 /*!
  * Status type returned by all functions in Celix
  */

Modified: incubator/celix/trunk/framework/public/include/framework.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/public/include/framework.h?rev=1543336&r1=1543335&r2=1543336&view=diff
==============================================================================
--- incubator/celix/trunk/framework/public/include/framework.h (original)
+++ incubator/celix/trunk/framework/public/include/framework.h Tue Nov 19 07:43:47 2013
@@ -36,7 +36,7 @@ typedef struct framework * framework_pt;
 #include "properties.h"
 
 // #TODO: Move to FrameworkFactory according the OSGi Spec
-FRAMEWORK_EXPORT celix_status_t framework_create(framework_pt *framework, apr_pool_t *memoryPool,
properties_pt config);
+FRAMEWORK_EXPORT struct celix_status framework_create(framework_pt *framework, apr_pool_t
*memoryPool, properties_pt config);
 // #TODO: Replace with a pool hook when this is possible
 FRAMEWORK_EXPORT celix_status_t framework_destroy(framework_pt framework);
 

Modified: incubator/celix/trunk/launcher/private/src/launcher.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/launcher/private/src/launcher.c?rev=1543336&r1=1543335&r2=1543336&view=diff
==============================================================================
--- incubator/celix/trunk/launcher/private/src/launcher.c (original)
+++ incubator/celix/trunk/launcher/private/src/launcher.c Tue Nov 19 07:43:47 2013
@@ -68,8 +68,9 @@ int main(void) {
     config = properties_load("config.properties");
     autoStart = properties_get(config, "cosgi.auto.start.1");
     framework = NULL;
-    celix_status_t status = framework_create(&framework, memoryPool, config);
-    if (status == CELIX_SUCCESS) {
+    celix_status_t status = CELIX_SUCCESS;
+    struct celix_status stat = framework_create(&framework, memoryPool, config);
+    if (stat.code == CELIX_SUCCESS) {
 		status = fw_init(framework);
 		if (status == CELIX_SUCCESS) {
             // Start the system bundle
@@ -127,6 +128,8 @@ int main(void) {
             framework_destroy(framework);
             properties_destroy(config);
 		}
+    } else {
+        printf("Error: %s,%s\n", stat.error);
     }
 
     if (status != CELIX_SUCCESS) {



Mime
View raw message