Author: abroekhuis
Date: Tue May 17 05:14:42 2011
New Revision: 1104001
URL: http://svn.apache.org/viewvc?rev=1104001&view=rev
Log:
Updated error handling
Modified:
incubator/celix/trunk/framework/CMakeLists.txt
incubator/celix/trunk/framework/private/include/bundle_context.h
incubator/celix/trunk/framework/private/src/bundle_context.c
incubator/celix/trunk/framework/private/src/framework.c
incubator/celix/trunk/hello_world/activator.c
incubator/celix/trunk/launcher/launcher.c
incubator/celix/trunk/mongoose/activator.c
incubator/celix/trunk/shell/install_command.c
incubator/celix/trunk/shell/ps_command.c
incubator/celix/trunk/shell_tui/shell_tui.c
incubator/celix/trunk/utils/CMakeLists.txt
Modified: incubator/celix/trunk/framework/CMakeLists.txt
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/CMakeLists.txt?rev=1104001&r1=1104000&r2=1104001&view=diff
==============================================================================
--- incubator/celix/trunk/framework/CMakeLists.txt (original)
+++ incubator/celix/trunk/framework/CMakeLists.txt Tue May 17 05:14:42 2011
@@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 2.6)
include(FindZLIB)
IF(ZLIB_FOUND)
Modified: incubator/celix/trunk/framework/private/include/bundle_context.h
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/bundle_context.h?rev=1104001&r1=1104000&r2=1104001&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/bundle_context.h (original)
+++ incubator/celix/trunk/framework/private/include/bundle_context.h Tue May 17
05:14:42 2011
@@ -28,14 +28,14 @@
#include "headers.h"
-BUNDLE_CONTEXT bundleContext_create(FRAMEWORK framework, BUNDLE bundle);
+celix_status_t bundleContext_create(FRAMEWORK framework, BUNDLE bundle,
BUNDLE_CONTEXT *bundle_context);
+celix_status_t bundleContext_destroy(BUNDLE_CONTEXT context);
-BUNDLE bundleContext_getBundle(BUNDLE_CONTEXT context);
-FRAMEWORK bundleContext_getFramework(BUNDLE_CONTEXT context);
+celix_status_t bundleContext_getBundle(BUNDLE_CONTEXT context, BUNDLE *bundle);
+celix_status_t bundleContext_getFramework(BUNDLE_CONTEXT context, FRAMEWORK
*framework);
+celix_status_t bundleContext_getMemoryPool(BUNDLE_CONTEXT context, apr_pool_t
**memory_pool);
-apr_pool_t *bundleContext_getMemoryPool(BUNDLE_CONTEXT context);
-
-BUNDLE bundleContext_installBundle(BUNDLE_CONTEXT context, char * location);
+celix_status_t bundleContext_installBundle(BUNDLE_CONTEXT context, char *
location, BUNDLE *bundle);
SERVICE_REGISTRATION bundleContext_registerService(BUNDLE_CONTEXT context,
char * serviceName, void * svcObj, PROPERTIES properties);
@@ -45,7 +45,7 @@ SERVICE_REFERENCE bundleContext_getServi
void * bundleContext_getService(BUNDLE_CONTEXT context, SERVICE_REFERENCE
reference);
bool bundleContext_ungetService(BUNDLE_CONTEXT context, SERVICE_REFERENCE
reference);
-ARRAY_LIST bundleContext_getBundles(BUNDLE_CONTEXT context);
+celix_status_t bundleContext_getBundles(BUNDLE_CONTEXT context, ARRAY_LIST
*bundles);
BUNDLE bundleContext_getBundleById(BUNDLE_CONTEXT context, long id);
void bundleContext_addServiceListener(BUNDLE_CONTEXT context, SERVICE_LISTENER
listener, char * filter);
Modified: incubator/celix/trunk/framework/private/src/bundle_context.c
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle_context.c?rev=1104001&r1=1104000&r2=1104001&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_context.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_context.c Tue May 17
05:14:42 2011
@@ -37,41 +37,102 @@ struct bundleContext {
apr_pool_t *pool;
};
-BUNDLE_CONTEXT bundleContext_create(FRAMEWORK framework, BUNDLE bundle) {
- BUNDLE_CONTEXT context = malloc(sizeof(*context));
- context->framework = framework;
- context->bundle = bundle;
+celix_status_t bundleContext_create(FRAMEWORK framework, BUNDLE bundle,
BUNDLE_CONTEXT *bundle_context) {
+ celix_status_t status = CELIX_SUCCESS;
+ BUNDLE_CONTEXT context = NULL;
- apr_pool_create(&context->pool, bundle->memoryPool);
+ if (*bundle_context == NULL) {
+ context = malloc(sizeof(*context));
- return context;
+ if (context != NULL) {
+ context->framework = framework;
+ context->bundle = bundle;
+
+ if (apr_pool_create(&context->pool, bundle->memoryPool)
!= APR_SUCCESS) {
+ status = CELIX_ENOMEM;
+ }
+
+ *bundle_context = context;
+ } else {
+ status = CELIX_ENOMEM;
+ }
+ } else {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ return status;
}
-void bundleContext_destroy(BUNDLE_CONTEXT context) {
- context->bundle = NULL;
- context->framework = NULL;
- apr_pool_destroy(context->pool);
- context->pool = NULL;
- free(context);
- context = NULL;
+celix_status_t bundleContext_destroy(BUNDLE_CONTEXT context) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (context != NULL) {
+ context->bundle = NULL;
+ context->framework = NULL;
+ if (context->pool) {
+ apr_pool_destroy(context->pool);
+ context->pool = NULL;
+ }
+ free(context);
+ context = NULL;
+ } else {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ return status;
}
-BUNDLE bundleContext_getBundle(BUNDLE_CONTEXT context) {
- return context->bundle;
+celix_status_t bundleContext_getBundle(BUNDLE_CONTEXT context, BUNDLE *bundle)
{
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (context == NULL) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ } else {
+ *bundle = context->bundle;
+ }
+
+ return status;
}
-FRAMEWORK bundleContext_getFramework(BUNDLE_CONTEXT context) {
- return context->framework;
+celix_status_t bundleContext_getFramework(BUNDLE_CONTEXT context, FRAMEWORK
*framework) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (context == NULL) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ } else {
+ *framework = context->framework;
+ }
+
+ return status;
}
-apr_pool_t * bundleContext_getMemoryPool(BUNDLE_CONTEXT context) {
- return context->pool;
+celix_status_t bundleContext_getMemoryPool(BUNDLE_CONTEXT context, apr_pool_t
**memory_pool) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (context == NULL) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ } else {
+ *memory_pool = context->pool;
+ }
+
+ return status;
}
-BUNDLE bundleContext_installBundle(BUNDLE_CONTEXT context, char * location) {
- BUNDLE bundle = NULL;
- fw_installBundle(context->framework, &bundle, location);
- return bundle;
+celix_status_t bundleContext_installBundle(BUNDLE_CONTEXT context, char *
location, BUNDLE *bundle) {
+ celix_status_t status = CELIX_SUCCESS;
+ BUNDLE b = NULL;
+
+ if (*bundle == NULL) {
+ if (fw_installBundle(context->framework, &b, location) !=
CELIX_SUCCESS) {
+ status = CELIX_FRAMEWORK_EXCEPTION;
+ } else {
+ *bundle = b;
+ }
+ } else {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ return status;
}
SERVICE_REGISTRATION bundleContext_registerService(BUNDLE_CONTEXT context,
char * serviceName, void * svcObj, PROPERTIES properties) {
@@ -101,8 +162,16 @@ bool bundleContext_ungetService(BUNDLE_C
return framework_ungetService(context->framework, context->bundle,
reference);
}
-ARRAY_LIST bundleContext_getBundles(BUNDLE_CONTEXT context) {
- return framework_getBundles(context->framework);
+celix_status_t bundleContext_getBundles(BUNDLE_CONTEXT context, ARRAY_LIST
*bundles) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (context == NULL) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ } else {
+ *bundles = framework_getBundles(context->framework);
+ }
+
+ return status;
}
BUNDLE bundleContext_getBundleById(BUNDLE_CONTEXT context, long id) {
Modified: incubator/celix/trunk/framework/private/src/framework.c
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/framework.c?rev=1104001&r1=1104000&r2=1104001&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/framework.c (original)
+++ incubator/celix/trunk/framework/private/src/framework.c Tue May 17 05:14:42
2011
@@ -216,7 +216,10 @@ celix_status_t fw_init(FRAMEWORK framewo
return CELIX_START_ERROR;
}
- BUNDLE_CONTEXT context = bundleContext_create(framework,
framework->bundle);
+ BUNDLE_CONTEXT context = NULL;
+ if (bundleContext_create(framework, framework->bundle, &context) !=
CELIX_SUCCESS) {
+ return CELIX_START_ERROR;
+ }
bundle_setContext(framework->bundle, context);
bundle_setHandle(framework->bundle, handle);
@@ -355,7 +358,7 @@ celix_status_t fw_startBundle(FRAMEWORK
HASH_MAP wires;
void * handle;
- BUNDLE_CONTEXT context;
+ BUNDLE_CONTEXT context = NULL;
switch (bundle_getState(bundle)) {
case BUNDLE_UNINSTALLED:
@@ -384,7 +387,9 @@ celix_status_t fw_startBundle(FRAMEWORK
hashMap_destroy(wires, false, false);
// no break
case BUNDLE_RESOLVED:
- context = bundleContext_create(framework, bundle);
+ if (bundleContext_create(framework, bundle, &context)
!= CELIX_SUCCESS) {
+ return CELIX_ENOMEM;
+ }
bundle_setContext(bundle, context);
MANIFEST manifest =
getManifest(bundle_getArchive(bundle));
@@ -994,12 +999,18 @@ celix_status_t bundleActivator_start(voi
celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
pthread_t shutdownThread;
- int err = pthread_create(&shutdownThread, NULL, framework_shutdown,
bundleContext_getFramework(context));
- if (err != 0) {
- celix_log("Could not create shutdown thread, normal exit not
possible.");
- return CELIX_BUNDLE_EXCEPTION;
+ FRAMEWORK framework;
+
+ if (bundleContext_getFramework(context, &framework) == CELIX_SUCCESS) {
+ int err = pthread_create(&shutdownThread, NULL,
framework_shutdown, framework);
+ if (err != 0) {
+ celix_log("Could not create shutdown thread, normal
exit not possible.");
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+ return CELIX_SUCCESS;
+ } else {
+ return CELIX_FRAMEWORK_EXCEPTION;
}
- return CELIX_SUCCESS;
}
celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT
context) {
Modified: incubator/celix/trunk/hello_world/activator.c
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/hello_world/activator.c?rev=1104001&r1=1104000&r2=1104001&view=diff
==============================================================================
--- incubator/celix/trunk/hello_world/activator.c (original)
+++ incubator/celix/trunk/hello_world/activator.c Tue May 17 05:14:42 2011
@@ -34,15 +34,25 @@ struct userData {
};
celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData)
{
- *userData = apr_palloc(bundleContext_getMemoryPool(context),
sizeof(struct userData));
- ((struct userData *)(*userData))->word = "World";
+ apr_pool_t *pool;
+ celix_status_t status = bundleContext_getMemoryPool(context, &pool);
+ if (status == CELIX_SUCCESS) {
+ *userData = apr_palloc(pool, sizeof(struct userData));
+ ((struct userData *)(*userData))->word = "World";
+ } else {
+ status = CELIX_START_ERROR;
+ }
return CELIX_SUCCESS;
}
celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+ BUNDLE bundle;
+ celix_status_t status = CELIX_SUCCESS;
+
struct userData * data = (struct userData *) userData;
printf("Hello %s\n", data->word);
- return CELIX_SUCCESS;
+
+ return status;
}
celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
Modified: incubator/celix/trunk/launcher/launcher.c
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/launcher/launcher.c?rev=1104001&r1=1104000&r2=1104001&view=diff
==============================================================================
--- incubator/celix/trunk/launcher/launcher.c (original)
+++ incubator/celix/trunk/launcher/launcher.c Tue May 17 05:14:42 2011
@@ -65,8 +65,9 @@ int main(void) {
BUNDLE_CONTEXT context = bundle_getContext(framework->bundle);
LINKED_LIST_ITERATOR iter = linkedListIterator_create(bundles, 0);
while (linkedListIterator_hasNext(iter)) {
+ BUNDLE current = NULL;
char * location = linkedListIterator_next(iter);
- BUNDLE current = bundleContext_installBundle(context, location);
+ bundleContext_installBundle(context, location, ¤t);
arrayList_add(installed, current);
linkedListIterator_remove(iter);
}
Modified: incubator/celix/trunk/mongoose/activator.c
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/mongoose/activator.c?rev=1104001&r1=1104000&r2=1104001&view=diff
==============================================================================
--- incubator/celix/trunk/mongoose/activator.c (original)
+++ incubator/celix/trunk/mongoose/activator.c Tue May 17 05:14:42 2011
@@ -35,26 +35,33 @@ struct userData {
};
celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData)
{
- *userData = apr_palloc(bundleContext_getMemoryPool(context),
sizeof(struct userData));
+ apr_pool_t *pool;
+ celix_status_t status = bundleContext_getMemoryPool(context, &pool);
+ *userData = apr_palloc(pool, sizeof(struct userData));
return CELIX_SUCCESS;
}
celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+ BUNDLE bundle;
+ celix_status_t status = CELIX_SUCCESS;
struct userData * data = (struct userData *) userData;
- BUNDLE b = bundleContext_getBundle(context);
- char *entry = NULL;
- bundle_getEntry(b, "root", &entry);
-
- const char *options[] = {
- "document_root", entry,
- NULL
- };
- data->ctx = mg_start(NULL, options);
+ if (bundleContext_getBundle(context, &bundle) == CELIX_SUCCESS) {
+ char *entry = NULL;
+ bundle_getEntry(bundle, "root", &entry);
+
+ const char *options[] = {
+ "document_root", entry,
+ NULL
+ };
+ data->ctx = mg_start(NULL, options);
+
+ printf("Mongoose startet on: %s\n", mg_get_option(data->ctx,
"listening_ports"));
+ } else {
+ status = CELIX_START_ERROR;
+ }
- printf("Mongoose startet on: %s\n", mg_get_option(data->ctx,
"listening_ports"));
-
- return CELIX_SUCCESS;
+ return status;
}
celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
Modified: incubator/celix/trunk/shell/install_command.c
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/shell/install_command.c?rev=1104001&r1=1104000&r2=1104001&view=diff
==============================================================================
--- incubator/celix/trunk/shell/install_command.c (original)
+++ incubator/celix/trunk/shell/install_command.c Tue May 17 05:14:42 2011
@@ -83,5 +83,5 @@ void installCommand_execute(COMMAND comm
}
void installCommand_install(COMMAND command, BUNDLE *bundle, char * location,
void (*out)(char *), void (*err)(char *)) {
- *bundle = bundleContext_installBundle(command->bundleContext, location);
+ bundleContext_installBundle(command->bundleContext, location, bundle);
}
Modified: incubator/celix/trunk/shell/ps_command.c
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/shell/ps_command.c?rev=1104001&r1=1104000&r2=1104001&view=diff
==============================================================================
--- incubator/celix/trunk/shell/ps_command.c (original)
+++ incubator/celix/trunk/shell/ps_command.c Tue May 17 05:14:42 2011
@@ -49,52 +49,55 @@ void psCommand_destroy(COMMAND command)
}
void psCommand_execute(COMMAND command, char * commandline, void (*out)(char
*), void (*err)(char *)) {
- ARRAY_LIST bundles = bundleContext_getBundles(command->bundleContext);
+ ARRAY_LIST bundles = NULL;
+ celix_status_t status =
bundleContext_getBundles(command->bundleContext, &bundles);
- bool showLocation = false;
- bool showSymbolicName = false;
- bool showUpdateLocation = false;
- char * msg = "Name";
-
- char delims[] = " ";
- char * sub = NULL;
- sub = strtok(commandline, delims);
- sub = strtok(NULL, delims);
- while (sub != NULL) {
- if (strcmp(sub, "-l") == 0) {
- showLocation = true;
- msg = "Location";
- } else if (strcmp(sub, "-s") == 0) {
- showSymbolicName = true;
- msg = "Symbolic name";
- } else if (strcmp(sub, "-u") == 0) {
- showUpdateLocation = true;
- msg = "Update location";
- }
+ if (status == CELIX_SUCCESS) {
+ bool showLocation = false;
+ bool showSymbolicName = false;
+ bool showUpdateLocation = false;
+ char * msg = "Name";
+
+ char delims[] = " ";
+ char * sub = NULL;
+ sub = strtok(commandline, delims);
sub = strtok(NULL, delims);
- }
-
- char line[256];
- sprintf(line, " %-5s %-12s %s\n", "ID", "State", msg);
- int i;
- out(line);
- for (i = 0; i < arrayList_size(bundles); i++) {
- BUNDLE bundle = arrayList_get(bundles, i);
- long id = bundleArchive_getId(bundle_getArchive(bundle));
- char * state = psCommand_stateString(bundle_getState(bundle));
- char * name =
module_getSymbolicName(bundle_getCurrentModule(bundle));
- if (showLocation) {
- name =
bundleArchive_getLocation(bundle_getArchive(bundle));
- } else if (showSymbolicName) {
- name =
module_getSymbolicName(bundle_getCurrentModule(bundle));
- } else if (showUpdateLocation) {
- name =
bundleArchive_getLocation(bundle_getArchive(bundle));
+ while (sub != NULL) {
+ if (strcmp(sub, "-l") == 0) {
+ showLocation = true;
+ msg = "Location";
+ } else if (strcmp(sub, "-s") == 0) {
+ showSymbolicName = true;
+ msg = "Symbolic name";
+ } else if (strcmp(sub, "-u") == 0) {
+ showUpdateLocation = true;
+ msg = "Update location";
+ }
+ sub = strtok(NULL, delims);
}
- sprintf(line, " %-5ld %-12s %s\n", id, state, name);
+ char line[256];
+ sprintf(line, " %-5s %-12s %s\n", "ID", "State", msg);
+ int i;
out(line);
+ for (i = 0; i < arrayList_size(bundles); i++) {
+ BUNDLE bundle = arrayList_get(bundles, i);
+ long id =
bundleArchive_getId(bundle_getArchive(bundle));
+ char * state =
psCommand_stateString(bundle_getState(bundle));
+ char * name =
module_getSymbolicName(bundle_getCurrentModule(bundle));
+ if (showLocation) {
+ name =
bundleArchive_getLocation(bundle_getArchive(bundle));
+ } else if (showSymbolicName) {
+ name =
module_getSymbolicName(bundle_getCurrentModule(bundle));
+ } else if (showUpdateLocation) {
+ name =
bundleArchive_getLocation(bundle_getArchive(bundle));
+ }
+
+ sprintf(line, " %-5ld %-12s %s\n", id, state, name);
+ out(line);
+ }
+ arrayList_destroy(bundles);
}
- arrayList_destroy(bundles);
}
char * psCommand_stateString(BUNDLE_STATE state) {
Modified: incubator/celix/trunk/shell_tui/shell_tui.c
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/shell_tui/shell_tui.c?rev=1104001&r1=1104000&r2=1104001&view=diff
==============================================================================
--- incubator/celix/trunk/shell_tui/shell_tui.c (original)
+++ incubator/celix/trunk/shell_tui/shell_tui.c Tue May 17 05:14:42 2011
@@ -97,7 +97,9 @@ void shellTui_serviceChanged(SERVICE_LIS
}
celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData)
{
- SHELL_TUI_ACTIVATOR activator =
apr_palloc(bundleContext_getMemoryPool(context), sizeof(*activator));
+ apr_pool_t *pool = NULL;
+ celix_status_t status = bundleContext_getMemoryPool(context, &pool);
+ SHELL_TUI_ACTIVATOR activator = apr_palloc(pool, sizeof(*activator));
//SHELL_TUI_ACTIVATOR activator = (SHELL_TUI_ACTIVATOR)
malloc(sizeof(*activator));
activator->shell = NULL;
(*userData) = activator;
Modified: incubator/celix/trunk/utils/CMakeLists.txt
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/utils/CMakeLists.txt?rev=1104001&r1=1104000&r2=1104001&view=diff
==============================================================================
--- incubator/celix/trunk/utils/CMakeLists.txt (original)
+++ incubator/celix/trunk/utils/CMakeLists.txt Tue May 17 05:14:42 2011
@@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 2.6)
add_definitions(-DUSE_FILE32API)
aux_source_directory("private/src" SRC)