incubator-celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1101360 [5/5] - in /incubator/celix/trunk: ./ .settings/ celix_test/ dependency_manager/ echo_service/client/ framework/ framework/private/include/ framework/private/src/ hello_world/ hello_world/root/ launcher/ mongoose/ mongoose/MANIFEST...
Date Tue, 10 May 2011 08:21:27 GMT
Propchange: incubator/celix/trunk/mongoose/mongoose.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/mongoose/mongoose.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/mongoose/mongoose.h?rev=1101360&view=auto
==============================================================================
--- incubator/celix/trunk/mongoose/mongoose.h (added)
+++ incubator/celix/trunk/mongoose/mongoose.h Tue May 10 08:21:24 2011
@@ -0,0 +1,218 @@
+// Copyright (c) 2004-2010 Sergey Lyubka
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#ifndef MONGOOSE_HEADER_INCLUDED
+#define  MONGOOSE_HEADER_INCLUDED
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+struct mg_context;     // Handle for the HTTP service itself
+struct mg_connection;  // Handle for the individual connection
+
+
+// This structure contains information about the HTTP request.
+struct mg_request_info {
+  char *request_method;  // "GET", "POST", etc
+  char *uri;             // URL-decoded URI
+  char *http_version;    // E.g. "1.0", "1.1"
+  char *query_string;    // \0 - terminated
+  char *remote_user;     // Authenticated user
+  char *log_message;     // Mongoose error log message
+  long remote_ip;        // Client's IP address
+  int remote_port;       // Client's port
+  int status_code;       // HTTP reply status code
+  int is_ssl;            // 1 if SSL-ed, 0 if not
+  int num_headers;       // Number of headers
+  struct mg_header {
+    char *name;          // HTTP header name
+    char *value;         // HTTP header value
+  } http_headers[64];    // Maximum 64 headers
+};
+
+// Various events on which user-defined function is called by Mongoose.
+enum mg_event {
+  MG_NEW_REQUEST,   // New HTTP request has arrived from the client
+  MG_HTTP_ERROR,    // HTTP error must be returned to the client
+  MG_EVENT_LOG,     // Mongoose logs an event, request_info.log_message
+  MG_INIT_SSL,      // Mongoose initializes SSL. Instead of mg_connection *,
+                    // SSL context is passed to the callback function.
+};
+
+// Prototype for the user-defined function. Mongoose calls this function
+// on every event mentioned above.
+//
+// Parameters:
+//   event: which event has been triggered.
+//   conn: opaque connection handler. Could be used to read, write data to the
+//         client, etc. See functions below that accept "mg_connection *".
+//   request_info: Information about HTTP request.
+//
+// Return:
+//   If handler returns non-NULL, that means that handler has processed the
+//   request by sending appropriate HTTP reply to the client. Mongoose treats
+//   the request as served.
+//   If callback returns NULL, that means that callback has not processed
+//   the request. Handler must not send any data to the client in this case.
+//   Mongoose proceeds with request handling as if nothing happened.
+typedef void * (*mg_callback_t)(enum mg_event event,
+                                struct mg_connection *conn,
+                                const struct mg_request_info *request_info);
+  
+
+// Start web server.
+//
+// Parameters:
+//   callback: user defined event handling function or NULL.
+//   options: NULL terminated list of option_name, option_value pairs that
+//            specify Mongoose configuration parameters.
+//
+// Example:
+//   const char *options[] = {
+//     "document_root", "/var/www",
+//     "listening_ports", "80,443s",
+//     NULL
+//   };
+//   struct mg_context *ctx = mg_start(&my_func, options);
+//
+// Please refer to http://code.google.com/p/mongoose/wiki/MongooseManual
+// for the list of valid option and their possible values.
+//
+// Return:
+//   web server context, or NULL on error.
+struct mg_context *mg_start(mg_callback_t callback, const char **options);
+
+
+// Stop the web server.
+//
+// Must be called last, when an application wants to stop the web server and
+// release all associated resources. This function blocks until all Mongoose
+// threads are stopped. Context pointer becomes invalid.
+void mg_stop(struct mg_context *);
+
+
+// Get the value of particular configuration parameter.
+// The value returned is read-only. Mongoose does not allow changing
+// configuration at run time.
+// If given parameter name is not valid, NULL is returned. For valid
+// names, return value is guaranteed to be non-NULL. If parameter is not
+// set, zero-length string is returned.
+const char *mg_get_option(const struct mg_context *ctx, const char *name);
+
+
+// Return array of strings that represent valid configuration options.
+// For each option, a short name, long name, and default value is returned.
+// Array is NULL terminated.
+const char **mg_get_valid_option_names(void);
+
+
+// Add, edit or delete the entry in the passwords file.
+//
+// This function allows an application to manipulate .htpasswd files on the
+// fly by adding, deleting and changing user records. This is one of the
+// several ways of implementing authentication on the server side. For another,
+// cookie-based way please refer to the examples/chat.c in the source tree.
+//
+// If password is not NULL, entry is added (or modified if already exists).
+// If password is NULL, entry is deleted.
+//
+// Return:
+//   1 on success, 0 on error.
+int mg_modify_passwords_file(struct mg_context *ctx, 
+    const char *passwords_file_name, const char *user, const char *password);
+
+// Send data to the client.
+int mg_write(struct mg_connection *, const void *buf, size_t len);
+
+
+// Send data to the browser using printf() semantics.
+//
+// Works exactly like mg_write(), but allows to do message formatting.
+// Note that mg_printf() uses internal buffer of size IO_BUF_SIZE
+// (8 Kb by default) as temporary message storage for formatting. Do not
+// print data that is bigger than that, otherwise it will be truncated.
+int mg_printf(struct mg_connection *, const char *fmt, ...);
+
+
+// Read data from the remote end, return number of bytes read.
+int mg_read(struct mg_connection *, void *buf, size_t len);
+
+
+// Get the value of particular HTTP header.
+//
+// This is a helper function. It traverses request_info->http_headers array,
+// and if the header is present in the array, returns its value. If it is
+// not present, NULL is returned.
+const char *mg_get_header(const struct mg_connection *, const char *name);
+
+
+// Get a value of particular form variable.
+//
+// Parameters:
+//   data: pointer to form-uri-encoded buffer. This could be either POST data,
+//         or request_info.query_string.
+//   data_len: length of the encoded data.
+//   var_name: variable name to decode from the buffer
+//   buf: destination buffer for the decoded variable
+//   buf_len: length of the destination buffer
+//
+// Return:
+//   On success, length of the decoded variable.
+//   On error, -1 (variable not found, or destination buffer is too small).
+//
+// Destination buffer is guaranteed to be '\0' - terminated. In case of
+// failure, dst[0] == '\0'.
+int mg_get_var(const char *data, size_t data_len,
+    const char *var_name, char *buf, size_t buf_len);
+
+// Fetch value of certain cookie variable into the destination buffer.
+//
+// Destination buffer is guaranteed to be '\0' - terminated. In case of
+// failure, dst[0] == '\0'. Note that RFC allows many occurrences of the same
+// parameter. This function returns only first occurrence.
+//
+// Return:
+//   On success, value length.
+//   On error, -1 (either "Cookie:" header is not present at all, or the
+//   requested parameter is not found, or destination buffer is too small
+//   to hold the value).
+int mg_get_cookie(const struct mg_connection *,
+    const char *cookie_name, char *buf, size_t buf_len);
+
+
+// Return Mongoose version.
+const char *mg_version(void);
+
+
+// MD5 hash given strings.
+// Buffer 'buf' must be 33 bytes long. Varargs is a NULL terminated list of
+// asciiz strings. When function returns, buf will contain human-readable
+// MD5 hash. Example:
+//   char buf[33];
+//   mg_md5(buf, "aa", "bb", NULL);
+void mg_md5(char *buf, ...);
+
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#endif // MONGOOSE_HEADER_INCLUDED

Propchange: incubator/celix/trunk/mongoose/mongoose.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/mongoose/root/index.html
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/mongoose/root/index.html?rev=1101360&view=auto
==============================================================================
--- incubator/celix/trunk/mongoose/root/index.html (added)
+++ incubator/celix/trunk/mongoose/root/index.html Tue May 10 08:21:24 2011
@@ -0,0 +1,5 @@
+<div align="center"><FONT 
+color="#ffffff" size="+1"><MARQUEE bgcolor="#000080" 
+direction="right" loop="20" width="75%"><STRONG>
+Serving content from within a bundle works!!1!11!!
+</STRONG></MARQUEE></FONT></DIV>
\ No newline at end of file

Propchange: incubator/celix/trunk/mongoose/root/index.html
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/celix/trunk/shell/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/CMakeLists.txt?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/shell/CMakeLists.txt (original)
+++ incubator/celix/trunk/shell/CMakeLists.txt Tue May 10 08:21:24 2011
@@ -15,9 +15,9 @@
 # specific language governing permissions and limitations
 # under the License.
 
-add_library(shell SHARED shell command ps_command start_command stop_command)
+add_library(shell SHARED shell command ps_command start_command stop_command install_command update_command)
 include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
-target_link_libraries(shell framework)
+target_link_libraries(shell framework curl)
 
 bundle(shell)
 package(shell FILES shell.h command.h)
\ No newline at end of file

Added: incubator/celix/trunk/shell/install_command.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/install_command.c?rev=1101360&view=auto
==============================================================================
--- incubator/celix/trunk/shell/install_command.c (added)
+++ incubator/celix/trunk/shell/install_command.c Tue May 10 08:21:24 2011
@@ -0,0 +1,87 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership.  The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+/*
+ * install_command.c
+ *
+ *  Created on: Apr 4, 2011
+ *      Author: alexanderb
+ */
+#include <stdlib.h>
+
+#include "command_private.h"
+#include "array_list.h"
+#include "bundle_context.h"
+#include "bundle_archive.h"
+#include "module.h"
+#include "bundle.h"
+#include "install_command.h"
+
+void installCommand_execute(COMMAND command, char * line, void (*out)(char *), void (*err)(char *));
+void installCommand_install(COMMAND command, BUNDLE *bundle, char * location, void (*out)(char *), void (*err)(char *));
+
+COMMAND installCommand_create(BUNDLE_CONTEXT context) {
+	COMMAND command = (COMMAND) malloc(sizeof(*command));
+	command->bundleContext = context;
+	command->name = "install";
+	command->shortDescription = "install bundle(s).";
+	command->usage = "install <file> [<file> ...]";
+	command->executeCommand = installCommand_execute;
+	return command;
+}
+
+void installCommand_destroy(COMMAND command) {
+	free(command);
+}
+
+void installCommand_execute(COMMAND command, char * line, void (*out)(char *), void (*err)(char *)) {
+	char delims[] = " ";
+	char * sub = NULL;
+	// ignore the command
+	sub = strtok(line, delims);
+	sub = strtok(NULL, delims);
+	char info[256];
+	info[0] = '\0';
+	while (sub != NULL) {
+		BUNDLE bundle = NULL;
+		installCommand_install(command, &bundle, strdup(sub), out, err);
+		if (bundle != NULL) {
+			if (strlen(info) > 0) {
+				strcat(info, ", ");
+			}
+			long id = bundleArchive_getId(bundle_getArchive(bundle));
+			char bundleId[sizeof(id) + 1];
+			sprintf(bundleId, "%ld", id);
+			strcat(info, bundleId);
+		}
+		sub = strtok(NULL, delims);
+	}
+	if (strchr(info, ',') != NULL) {
+		out("Bundle IDs: ");
+		out(info);
+		out("\n");
+	} else if (strlen(info) > 0) {
+		out("Bundle ID: ");
+		out(info);
+		out("\n");
+	}
+}
+
+void installCommand_install(COMMAND command, BUNDLE *bundle, char * location, void (*out)(char *), void (*err)(char *)) {
+	*bundle = bundleContext_installBundle(command->bundleContext, location);
+}

Propchange: incubator/celix/trunk/shell/install_command.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/shell/install_command.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/install_command.h?rev=1101360&view=auto
==============================================================================
--- incubator/celix/trunk/shell/install_command.h (added)
+++ incubator/celix/trunk/shell/install_command.h Tue May 10 08:21:24 2011
@@ -0,0 +1,32 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership.  The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+/*
+ * install_command.h
+ *
+ *  Created on: Apr 4, 2011
+ *      Author: alexanderb
+ */
+
+#ifndef INSTALL_COMMAND_H_
+#define INSTALL_COMMAND_H_
+
+COMMAND installCommand_create(BUNDLE_CONTEXT context);
+void installCommand_destroy(COMMAND command);
+
+#endif /* INSTALL_COMMAND_H_ */

Propchange: incubator/celix/trunk/shell/install_command.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/celix/trunk/shell/ps_command.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/ps_command.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/shell/ps_command.c (original)
+++ incubator/celix/trunk/shell/ps_command.c Tue May 10 08:21:24 2011
@@ -44,21 +44,57 @@ COMMAND psCommand_create(BUNDLE_CONTEXT 
 	return command;
 }
 
+void psCommand_destroy(COMMAND command) {
+	free(command);
+}
+
 void psCommand_execute(COMMAND command, char * commandline, void (*out)(char *), void (*err)(char *)) {
 	ARRAY_LIST bundles = bundleContext_getBundles(command->bundleContext);
 
+	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";
+		}
+		sub = strtok(NULL, delims);
+	}
+
 	char line[256];
-	sprintf(line, "  %-5s %-12s %s\n", "ID", "State", "Name");
+	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 * name = module_getSymbolicName(bundle_getModule(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);
 }
 
 char * psCommand_stateString(BUNDLE_STATE state) {

Modified: incubator/celix/trunk/shell/ps_command.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/ps_command.h?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/shell/ps_command.h (original)
+++ incubator/celix/trunk/shell/ps_command.h Tue May 10 08:21:24 2011
@@ -27,5 +27,6 @@
 #define PS_COMMAND_H_
 
 COMMAND psCommand_create(BUNDLE_CONTEXT context);
+void psCommand_destroy(COMMAND command);
 
 #endif /* PS_COMMAND_H_ */

Modified: incubator/celix/trunk/shell/shell.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/shell.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/shell/shell.c (original)
+++ incubator/celix/trunk/shell/shell.c Tue May 10 08:21:24 2011
@@ -35,12 +35,28 @@
 #include "ps_command.h"
 #include "start_command.h"
 #include "stop_command.h"
+#include "install_command.h"
+#include "update_command.h"
 
 #include "utils.h"
 
 struct shellServiceActivator {
 	SHELL shell;
+	SHELL_SERVICE shellService;
 	SERVICE_REGISTRATION registration;
+	SERVICE_LISTENER listener;
+
+	SERVICE_REGISTRATION psCommand;
+	SERVICE_REGISTRATION startCommand;
+	SERVICE_REGISTRATION stopCommand;
+	SERVICE_REGISTRATION installCommand;
+	SERVICE_REGISTRATION updateCommand;
+
+	COMMAND psCmd;
+	COMMAND startCmd;
+	COMMAND stopCmd;
+	COMMAND installCmd;
+	COMMAND updateCmd;
 };
 
 SHELL shell_create() {
@@ -50,6 +66,12 @@ SHELL shell_create() {
 	return shell;
 }
 
+void shell_destroy(SHELL shell) {
+	hashMap_destroy(shell->commandNameMap, false, false);
+	hashMap_destroy(shell->commandReferenceMap, false, false);
+	free(shell);
+}
+
 ARRAY_LIST shell_getCommands(SHELL shell) {
 	ARRAY_LIST commands = arrayList_create();
 	HASH_MAP_ITERATOR iter = hashMapIterator_create(shell->commandNameMap);
@@ -84,11 +106,12 @@ SERVICE_REFERENCE shell_getCommandRefere
 
 void shell_executeCommand(SHELL shell, char * commandLine, void (*out)(char *), void (*error)(char *)) {
 	unsigned int pos = strcspn(commandLine, " ");
-	char * commandName = (pos != strlen(commandLine)) ? string_ndup((char *)commandLine, pos) : commandLine;
+	char * commandName = (pos != strlen(commandLine)) ? string_ndup((char *)commandLine, pos) : strdup(commandLine);
 	COMMAND command = shell_getCommand(shell, commandName);
 	if (command != NULL) {
 		command->executeCommand(command, commandLine, out, error);
 	}
+	free(commandName);
 }
 
 COMMAND shell_getCommand(SHELL shell, char * commandName) {
@@ -117,47 +140,91 @@ void shell_serviceChanged(SERVICE_LISTEN
 	}
 }
 
-void * bundleActivator_create() {
-	struct shellServiceActivator * activator = malloc(sizeof(*activator));
+celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData) {
+	*userData = malloc(sizeof(struct shellServiceActivator));
 	SHELL shell = shell_create();
-	activator->shell = shell;
-	return activator;
+//	struct shellServiceActivator * activator = (struct shellServiceActivator *) (*userData);
+	((struct shellServiceActivator *) (*userData))->shell = shell;
+	((struct shellServiceActivator *) (*userData))->listener = NULL;
+	((struct shellServiceActivator *) (*userData))->psCommand = NULL;
+	((struct shellServiceActivator *) (*userData))->startCommand = NULL;
+	((struct shellServiceActivator *) (*userData))->stopCommand = NULL;
+	((struct shellServiceActivator *) (*userData))->installCommand = NULL;
+	((struct shellServiceActivator *) (*userData))->updateCommand = NULL;
+	((struct shellServiceActivator *) (*userData))->registration = NULL;
+
+	//(*userData) = &(*activator);
+
+	return CELIX_SUCCESS;
 }
 
-void bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
 	struct shellServiceActivator * activator = (struct shellServiceActivator *) userData;
 	activator->shell->bundleContext = context;
 
-	SHELL_SERVICE shellService = (SHELL_SERVICE) malloc(sizeof(*shellService));
-	shellService->shell = activator->shell;
-	shellService->getCommands = shell_getCommands;
-	shellService->getCommandDescription = shell_getCommandDescription;
-	shellService->getCommandUsage = shell_getCommandUsage;
-	shellService->getCommandReference = shell_getCommandReference;
-	shellService->executeCommand = shell_executeCommand;
+	activator->shellService = (SHELL_SERVICE) malloc(sizeof(*activator->shellService));
+	activator->shellService->shell = activator->shell;
+	activator->shellService->getCommands = shell_getCommands;
+	activator->shellService->getCommandDescription = shell_getCommandDescription;
+	activator->shellService->getCommandUsage = shell_getCommandUsage;
+	activator->shellService->getCommandReference = shell_getCommandReference;
+	activator->shellService->executeCommand = shell_executeCommand;
 
-	activator->registration = bundleContext_registerService(context, (char *) SHELL_SERVICE_NAME, shellService, NULL);
+	activator->registration = bundleContext_registerService(context, (char *) SHELL_SERVICE_NAME, activator->shellService, NULL);
 
 	SERVICE_LISTENER listener = (SERVICE_LISTENER) malloc(sizeof(*listener));
+	activator->listener = listener;
 	listener->handle = activator->shell;
 	listener->serviceChanged = (void *) shell_serviceChanged;
-	addServiceListener(context, listener, "(objectClass=commandService)");
+	bundleContext_addServiceListener(context, listener, "(objectClass=commandService)");
+
+	activator->psCmd = psCommand_create(context);
+	activator->psCommand = bundleContext_registerService(context, (char *) COMMAND_SERVICE_NAME, activator->psCmd, NULL);
+
+	activator->startCmd = startCommand_create(context);
+	activator->startCommand = bundleContext_registerService(context, (char *) COMMAND_SERVICE_NAME, activator->startCmd, NULL);
 
-	COMMAND psCommand = psCommand_create(context);
-	bundleContext_registerService(context, (char *) COMMAND_SERVICE_NAME, psCommand, NULL);
+	activator->stopCmd = stopCommand_create(context);
+	activator->stopCommand = bundleContext_registerService(context, (char *) COMMAND_SERVICE_NAME, activator->stopCmd, NULL);
 
-	COMMAND startCommand = startCommand_create(context);
-	bundleContext_registerService(context, (char *) COMMAND_SERVICE_NAME, startCommand, NULL);
+	activator->installCmd = installCommand_create(context);
+	activator->installCommand = bundleContext_registerService(context, (char *) COMMAND_SERVICE_NAME, activator->installCmd, NULL);
 
-	COMMAND stopCommand = stopCommand_create(context);
-	bundleContext_registerService(context, (char *) COMMAND_SERVICE_NAME, stopCommand, NULL);
+	activator->updateCmd = updateCommand_create(context);
+	activator->updateCommand = bundleContext_registerService(context, (char *) COMMAND_SERVICE_NAME, activator->updateCmd, NULL);
+
+	return CELIX_SUCCESS;
 }
 
-void bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
 	struct shellServiceActivator * activator = (struct shellServiceActivator *) userData;
 	serviceRegistration_unregister(activator->registration);
+	serviceRegistration_unregister(activator->psCommand);
+	serviceRegistration_unregister(activator->startCommand);
+	serviceRegistration_unregister(activator->stopCommand);
+	serviceRegistration_unregister(activator->installCommand);
+	serviceRegistration_unregister(activator->updateCommand);
+	bundleContext_removeServiceListener(context, activator->listener);
+
+	psCommand_destroy(activator->psCmd);
+	startCommand_destroy(activator->startCmd);
+	stopCommand_destroy(activator->stopCmd);
+	installCommand_destroy(activator->installCmd);
+	updateCommand_destroy(activator->updateCmd);
+
+	free(activator->shellService);
+	activator->shellService = NULL;
+
+	free(activator->listener);
+	activator->listener = NULL;
+
+	return CELIX_SUCCESS;
 }
 
-void bundleActivator_destroy(void * userData) {
+celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT context) {
+	struct shellServiceActivator * activator = (struct shellServiceActivator *) userData;
+	shell_destroy(activator->shell);
+	free(activator);
 
+	return CELIX_SUCCESS;
 }

Modified: incubator/celix/trunk/shell/start_command.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/start_command.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/shell/start_command.c (original)
+++ incubator/celix/trunk/shell/start_command.c Tue May 10 08:21:24 2011
@@ -42,6 +42,10 @@ COMMAND startCommand_create(BUNDLE_CONTE
 	return command;
 }
 
+void startCommand_destroy(COMMAND command) {
+	free(command);
+}
+
 
 void startCommand_execute(COMMAND command, char * line, void (*out)(char *), void (*err)(char *)) {
 	char delims[] = " ";

Modified: incubator/celix/trunk/shell/start_command.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/start_command.h?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/shell/start_command.h (original)
+++ incubator/celix/trunk/shell/start_command.h Tue May 10 08:21:24 2011
@@ -27,5 +27,6 @@
 #define START_COMMAND_H_
 
 COMMAND startCommand_create(BUNDLE_CONTEXT context);
+void startCommand_destroy(COMMAND command);
 
 #endif /* START_COMMAND_H_ */

Modified: incubator/celix/trunk/shell/stop_command.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/stop_command.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/shell/stop_command.c (original)
+++ incubator/celix/trunk/shell/stop_command.c Tue May 10 08:21:24 2011
@@ -42,6 +42,9 @@ COMMAND stopCommand_create(BUNDLE_CONTEX
 	return command;
 }
 
+void stopCommand_destroy(COMMAND command) {
+	free(command);
+}
 
 void stopCommand_execute(COMMAND command, char * line, void (*out)(char *), void (*err)(char *)) {
 	char delims[] = " ";

Modified: incubator/celix/trunk/shell/stop_command.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/stop_command.h?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/shell/stop_command.h (original)
+++ incubator/celix/trunk/shell/stop_command.h Tue May 10 08:21:24 2011
@@ -27,5 +27,6 @@
 #define STOP_COMMAND_H_
 
 COMMAND stopCommand_create(BUNDLE_CONTEXT context);
+void stopCommand_destroy(COMMAND command);
 
 #endif /* STOP_COMMAND_H_ */

Added: incubator/celix/trunk/shell/update_command.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/update_command.c?rev=1101360&view=auto
==============================================================================
--- incubator/celix/trunk/shell/update_command.c (added)
+++ incubator/celix/trunk/shell/update_command.c Tue May 10 08:21:24 2011
@@ -0,0 +1,131 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership.  The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+/*
+ * start_command.c
+ *
+ *  Created on: Aug 20, 2010
+ *      Author: alexanderb
+ */
+#include <stdlib.h>
+#include <string.h>
+#include <curl/curl.h>
+#include <curl/types.h>
+#include <curl/easy.h>
+
+#include "command_private.h"
+#include "array_list.h"
+#include "bundle_context.h"
+#include "bundle.h"
+#include "update_command.h"
+#include "inputstream.h"
+
+void updateCommand_execute(COMMAND command, char * line, void (*out)(char *), void (*err)(char *));
+celix_status_t updateCommand_download(COMMAND command, char * url, char **inputFile);
+size_t updateCommand_writeData(void *ptr, size_t size, size_t nmemb, FILE *stream);
+int updateCommand_downloadProgress(void *ptr, double dltotal, double dlnow, double ultotal, double ulnow);
+
+COMMAND updateCommand_create(BUNDLE_CONTEXT context) {
+	COMMAND command = (COMMAND) malloc(sizeof(*command));
+	command->bundleContext = context;
+	command->name = "update";
+	command->shortDescription = "update bundle.";
+	command->usage = "update <id> [<URL>]";
+	command->executeCommand = updateCommand_execute;
+	return command;
+}
+
+void updateCommand_destroy(COMMAND command) {
+	free(command);
+}
+
+
+void updateCommand_execute(COMMAND command, char * line, void (*out)(char *), void (*err)(char *)) {
+	char delims[] = " ";
+	char * sub = NULL;
+	sub = strtok(line, delims);
+	// Read bundle id
+	sub = strtok(NULL, delims);
+	if (sub != NULL) {
+		long id = atol(sub);
+		BUNDLE bundle = bundleContext_getBundleById(command->bundleContext, id);
+		if (bundle != NULL) {
+			sub = strtok(NULL, delims);
+			char inputFile[MAXNAMLEN];
+			inputFile[0] = '\0';
+			if (sub != NULL) {
+				printf("URL: %s\n", sub);
+				char *test = inputFile;
+
+				if (updateCommand_download(command, sub, &test) == CELIX_SUCCESS) {
+					printf("Update bundle with stream\n");
+					bundle_update(bundle, inputFile);
+				} else {
+					char error[256];
+					sprintf(error, "Unable to download from %s\n", sub);
+					err(error);
+				}
+			} else {
+				bundle_update(bundle, NULL);
+			}
+		} else {
+			err("Bundle id is invalid.\n");
+		}
+	}
+}
+
+celix_status_t updateCommand_download(COMMAND command, char * url, char **inputFile) {
+	CURL *curl;
+	CURLcode res;
+	curl = curl_easy_init();
+	if (curl) {
+		tmpnam(*inputFile);
+		printf("Temp file: %s\n", *inputFile);
+		FILE *fp = fopen(*inputFile, "wb+");
+		curl_easy_setopt(curl, CURLOPT_URL, url);
+		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, updateCommand_writeData);
+		curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
+		//curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
+		//curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, updateCommand_downloadProgress);
+		res = curl_easy_perform(curl);
+		printf("Error: %d\n", res);
+		/* always cleanup */
+		curl_easy_cleanup(curl);
+		fclose(fp);
+	}
+	if (res != CURLE_OK) {
+		*inputFile[0] = '\0';
+		return CELIX_ILLEGAL_STATE;
+	} else {
+		return CELIX_SUCCESS;
+	}
+}
+
+size_t updateCommand_writeData(void *ptr, size_t size, size_t nmemb, FILE *stream) {
+    size_t written = fwrite(ptr, size, nmemb, stream);
+    return written;
+}
+
+//int updateCommand_downloadProgress(void *ptr,
+//                     double t, /* dltotal */
+//                     double d, /* dlnow */
+//                     double ultotal,
+//                     double ulnow) {
+//	printf("\r%f / %f (%g %%)", d, t, d*100.0/t);
+//	return 0;
+//}

Propchange: incubator/celix/trunk/shell/update_command.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/shell/update_command.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/update_command.h?rev=1101360&view=auto
==============================================================================
--- incubator/celix/trunk/shell/update_command.h (added)
+++ incubator/celix/trunk/shell/update_command.h Tue May 10 08:21:24 2011
@@ -0,0 +1,34 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership.  The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+/*
+ * start_command.h
+ *
+ *  Created on: Aug 20, 2010
+ *      Author: alexanderb
+ */
+
+#ifndef UPDATE_COMMAND_H_
+#define UPDATE_COMMAND_H_
+
+#include "command.h"
+
+COMMAND updateCommand_create(BUNDLE_CONTEXT context);
+void updateCommand_destroy(COMMAND command);
+
+#endif /* UPDATE_COMMAND_H_ */

Propchange: incubator/celix/trunk/shell/update_command.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/celix/trunk/shell_tui/shell_tui.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell_tui/shell_tui.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/shell_tui/shell_tui.c (original)
+++ incubator/celix/trunk/shell_tui/shell_tui.c Tue May 10 08:21:24 2011
@@ -36,6 +36,7 @@ struct shellTuiActivator {
 	BUNDLE_CONTEXT context;
 	SHELL_SERVICE shell;
 	SERVICE_REFERENCE reference;
+	struct serviceListener * listener;
 	bool running;
 	pthread_t runnable;
 };
@@ -58,7 +59,8 @@ void * shellTui_runnable(void * data) {
 		}
 		fgets(in, 256, stdin);
 		needPrompt = true;
-		char * line = string_trim(strdup(in));
+		char * dline = strdup(in);
+		char * line = string_trim(dline);
 		if (strlen(line) == 0) {
 			continue;
 		}
@@ -66,8 +68,10 @@ void * shellTui_runnable(void * data) {
 			continue;
 		}
 		act->shell->executeCommand(act->shell->shell, line, shellTui_write, shellTui_write);
+		free(dline);
 	}
 	pthread_exit(NULL);
+	return NULL;
 }
 
 void shellTui_initializeService(SHELL_TUI_ACTIVATOR activator) {
@@ -84,7 +88,7 @@ void shellTui_serviceChanged(SERVICE_LIS
 	if ((event->type == REGISTERED) && (act->reference == NULL)) {
 		shellTui_initializeService(act);
 	} else if ((event->type == UNREGISTERING) && (act->reference == event->reference)) {
-		// bundleContext_ungetService(act->reference);
+		bundleContext_ungetService(act->context, act->reference);
 		act->reference = NULL;
 		act->shell = NULL;
 
@@ -92,30 +96,41 @@ void shellTui_serviceChanged(SERVICE_LIS
 	}
 }
 
-void * bundleActivator_create() {
-	SHELL_TUI_ACTIVATOR activator = (SHELL_TUI_ACTIVATOR) malloc(sizeof(*activator));
+celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData) {
+	SHELL_TUI_ACTIVATOR activator = apr_palloc(bundleContext_getMemoryPool(context), sizeof(*activator));
+	//SHELL_TUI_ACTIVATOR activator = (SHELL_TUI_ACTIVATOR) malloc(sizeof(*activator));
 	activator->shell = NULL;
-	return activator;
+	(*userData) = activator;
+	return CELIX_SUCCESS;
 }
 
-void bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
 	SHELL_TUI_ACTIVATOR act = (SHELL_TUI_ACTIVATOR) userData;
 	act->context = context;
 	act->running = true;
 
 	SERVICE_LISTENER listener = (SERVICE_LISTENER) malloc(sizeof(*listener));
-	listener->handle = act;
-	listener->serviceChanged = (void *) shellTui_serviceChanged;
-	addServiceListener(context, listener, "(objectClass=shellService)");
+	act->listener = listener;
+	act->listener->handle = act;
+	act->listener->serviceChanged = (void *) shellTui_serviceChanged;
+	bundleContext_addServiceListener(context, act->listener, "(objectClass=shellService)");
 
 	shellTui_initializeService(act);
 	pthread_create(&act->runnable, NULL, shellTui_runnable, act);
+	return CELIX_SUCCESS;
 }
 
-void bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
 	SHELL_TUI_ACTIVATOR act = (SHELL_TUI_ACTIVATOR) userData;
+	bundleContext_removeServiceListener(context, act->listener);
+	free(act->listener);
+	act->listener = NULL;
+	act->context = NULL;
+	act->running = false;
+	pthread_detach(act->runnable);
+	return CELIX_SUCCESS;
 }
 
-void bundleActivator_destroy(void * userData) {
-
+celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT context) {
+	return CELIX_SUCCESS;
 }

Modified: incubator/celix/trunk/target.cmake
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/target.cmake?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/target.cmake (original)
+++ incubator/celix/trunk/target.cmake Tue May 10 08:21:24 2011
@@ -15,9 +15,9 @@
 # specific language governing permissions and limitations
 # under the License.
 
-deploy("name" BUNDLES receiver receiver-2.0 sender shell shell_tui)
-deploy("shell test" BUNDLES shell)
-deploy("hello_world" BUNDLES hello_world shell shell_tui)
-deploy("wb" BUNDLES tracker publisherA publisherB shell shell_tui)
-deploy("wb_dp" BUNDLES tracker_depman publisherA publisherB shell shell_tui)
-deploy("echo" BUNDLES echo_server echo_client shell shell_tui)
\ No newline at end of file
+#deploy("name" BUNDLES receiver receiver-2.0 sender shell shell_tui)
+#deploy("shell test" BUNDLES shell)
+deploy("hello_world" BUNDLES shell shell_tui hello_world celix.mongoose)
+#deploy("wb" BUNDLES tracker publisherA publisherB shell shell_tui)
+#deploy("wb_dp" BUNDLES tracker_depman publisherA publisherB shell shell_tui)
+#deploy("echo" BUNDLES echo_server echo_client shell shell_tui)
\ No newline at end of file

Modified: incubator/celix/trunk/utils/private/src/array_list.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/utils/private/src/array_list.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/utils/private/src/array_list.c (original)
+++ incubator/celix/trunk/utils/private/src/array_list.c Tue May 10 08:21:24 2011
@@ -34,11 +34,20 @@ ARRAY_LIST arrayList_create(void) {
 
 	list->size = 0;
 	list->capacity = 10;
+	list->modCount = 0;
 	list->elementData = (void **) malloc(sizeof(void*) * list->capacity);
 
 	return list;
 }
 
+void arrayList_destroy(ARRAY_LIST list) {
+	list->size = 0;
+	free(list->elementData);
+	list->elementData = NULL;
+	free(list);
+	list = NULL;
+}
+
 void arrayList_trimToSize(ARRAY_LIST list) {
 	list->modCount++;
 	int oldCapacity = list->capacity;
@@ -228,6 +237,15 @@ ARRAY_LIST_ITERATOR arrayListIterator_cr
 	return iterator;
 }
 
+void arrayListIterator_destroy(ARRAY_LIST_ITERATOR iterator) {
+	iterator->lastReturned = -1;
+	iterator->cursor = 0;
+	iterator->expectedModificationCount = 0;
+	iterator->list = NULL;
+	free(iterator);
+	iterator = NULL;
+}
+
 bool arrayListIterator_hasNext(ARRAY_LIST_ITERATOR iterator) {
 	return iterator->cursor != iterator->list->size;
 }

Modified: incubator/celix/trunk/utils/private/src/hash_map.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/utils/private/src/hash_map.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/utils/private/src/hash_map.c (original)
+++ incubator/celix/trunk/utils/private/src/hash_map.c Tue May 10 08:21:24 2011
@@ -96,6 +96,13 @@ HASH_MAP hashMap_create(unsigned int (*k
 	return map;
 }
 
+void hashMap_destroy(HASH_MAP map, bool freeKeys, bool freeValues) {
+	hashMap_clear(map, freeKeys, freeValues);
+	free(map->table);
+	free(map);
+	map = NULL;
+}
+
 int hashMap_size(HASH_MAP map) {
 	return map->size;
 }
@@ -198,7 +205,14 @@ void hashMap_resize(HASH_MAP map, int ne
 
 void * hashMap_remove(HASH_MAP map, void * key) {
 	HASH_MAP_ENTRY entry = hashMap_removeEntryForKey(map, key);
-	return (entry == NULL ? NULL : entry->value);
+	void * value = (entry == NULL ? NULL : entry->value);
+	if (entry != NULL) {
+		entry->key = NULL;
+		entry->value = NULL;
+		free(entry);
+		entry = NULL;
+	}
+	return value;
 }
 
 void * hashMap_removeEntryForKey(HASH_MAP map, void * key) {
@@ -209,7 +223,7 @@ void * hashMap_removeEntryForKey(HASH_MA
 
 	while (entry != NULL) {
 		HASH_MAP_ENTRY next = entry->next;
-		if (entry->hash == hash && (entry->key == key || key != NULL && map->equalsKey(key, entry->key))) {
+		if (entry->hash == hash && (entry->key == key || (key != NULL && map->equalsKey(key, entry->key)))) {
 			map->modificationCount++;
 			map->size--;
 			if (prev == entry) {
@@ -254,7 +268,7 @@ HASH_MAP_ENTRY hashMap_removeMapping(HAS
 	return e;
 }
 
-void hashMap_clear(HASH_MAP map) {
+void hashMap_clear(HASH_MAP map, bool freeKey, bool freeValue) {
 	map->modificationCount++;
 	HASH_MAP_ENTRY * table = map->table;
 	int i;
@@ -263,6 +277,10 @@ void hashMap_clear(HASH_MAP map) {
 		while (entry != NULL) {
 			HASH_MAP_ENTRY f = entry;
 			entry = entry->next;
+			if (freeKey && f->key != NULL)
+				free(f->key);
+			if (freeValue && f->value != NULL)
+				free(f->value);
 			free(f);
 		}
 		table[i] = NULL;
@@ -314,6 +332,7 @@ HASH_MAP_ITERATOR hashMapIterator_create
 	iterator->expectedModCount = map->modificationCount;
 	iterator->index = 0;
 	iterator->next = NULL;
+	iterator->current = NULL;
 	if (map->size > 0) {
 		while (iterator->index < map->tablelength && (iterator->next = map->table[iterator->index++]) == NULL) {
 		}
@@ -321,6 +340,16 @@ HASH_MAP_ITERATOR hashMapIterator_create
 	return iterator;
 }
 
+void hashMapIterator_destroy(HASH_MAP_ITERATOR iterator) {
+	iterator->current = NULL;
+	iterator->expectedModCount = 0;
+	iterator->index = 0;
+	iterator->map = NULL;
+	iterator->next = NULL;
+	free(iterator);
+	iterator = NULL;
+}
+
 bool hashMapIterator_hasNext(HASH_MAP_ITERATOR iterator) {
 	return iterator->next != NULL;
 }
@@ -334,7 +363,8 @@ void hashMapIterator_remove(HASH_MAP_ITE
 	}
 	void * key = iterator->current->key;
 	iterator->current = NULL;
-	hashMap_removeEntryForKey(iterator->map, key);
+	HASH_MAP_ENTRY entry = hashMap_removeEntryForKey(iterator->map, key);
+	free(entry);
 	iterator->expectedModCount = iterator->map->modificationCount;
 }
 
@@ -402,11 +432,14 @@ bool hashMapKeySet_contains(HASH_MAP_KEY
 }
 
 bool hashMapKeySet_remove(HASH_MAP_KEY_SET keySet, void * key) {
-	return hashMap_removeEntryForKey(keySet->map, key) != NULL;
+	HASH_MAP_ENTRY entry = hashMap_removeEntryForKey(keySet->map, key);
+	bool removed = entry != NULL;
+	free(entry);
+	return removed;
 }
 
 void hashMapKeySet_clear(HASH_MAP_KEY_SET keySet) {
-	hashMap_clear(keySet->map);
+	hashMap_clear(keySet->map, false, false);
 }
 
 bool hashMapKeySet_isEmpty(HASH_MAP_KEY_SET keySet) {
@@ -420,6 +453,12 @@ HASH_MAP_VALUES hashMapValues_create(HAS
 	return values;
 }
 
+void hashMapValues_destroy(HASH_MAP_VALUES values) {
+	values->map = NULL;
+	free(values);
+	values = NULL;
+}
+
 HASH_MAP_ITERATOR hashMapValues_iterator(HASH_MAP_VALUES values) {
 	return hashMapIterator_create(values->map);
 }
@@ -453,7 +492,7 @@ bool hashMapValues_remove(HASH_MAP_VALUE
 }
 
 void hashMapValues_clear(HASH_MAP_VALUES values) {
-	hashMap_clear(values->map);
+	hashMap_clear(values->map, false, false);
 }
 
 bool hashMapValues_isEmpty(HASH_MAP_VALUES values) {
@@ -480,7 +519,7 @@ bool hashMapEntrySet_remove(HASH_MAP_VAL
 }
 
 void hashMapEntrySet_clear(HASH_MAP_ENTRY_SET entrySet) {
-	hashMap_clear(entrySet->map);
+	hashMap_clear(entrySet->map, false, false);
 }
 
 bool hashMapEntrySet_isEmpty(HASH_MAP_ENTRY_SET entrySet) {

Modified: incubator/celix/trunk/utils/private/src/linked_list_iterator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/utils/private/src/linked_list_iterator.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/utils/private/src/linked_list_iterator.c (original)
+++ incubator/celix/trunk/utils/private/src/linked_list_iterator.c Tue May 10 08:21:24 2011
@@ -58,6 +58,15 @@ LINKED_LIST_ITERATOR linkedListIterator_
 	return iterator;
 }
 
+void linkedListIterator_destroy(LINKED_LIST_ITERATOR iterator) {
+	iterator->expectedModificationCount = 0;
+	iterator->lastReturned = NULL;
+	iterator->list = NULL;
+	iterator->next = NULL;
+	iterator->nextIndex = 0;
+	free(iterator);
+}
+
 bool linkedListIterator_hasNext(LINKED_LIST_ITERATOR iterator) {
 	return iterator->nextIndex != iterator->list->size;
 }

Modified: incubator/celix/trunk/utils/private/src/linkedlist.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/utils/private/src/linkedlist.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/utils/private/src/linkedlist.c (original)
+++ incubator/celix/trunk/utils/private/src/linkedlist.c Tue May 10 08:21:24 2011
@@ -37,6 +37,17 @@ LINKED_LIST linkedList_create(void) {
 	list->header->previous = list->header;
 	list->size = 0;
 	list->modificationCount = 0;
+
+	return list;
+}
+
+void linkedList_destroy(LINKED_LIST list) {
+	linkedList_clear(list);
+	free(list->header);
+	list->header = NULL;
+	list->modificationCount = 0;
+	list->size = 0;
+	free(list);
 }
 
 void * linkedList_getFirst(LINKED_LIST list) {
@@ -112,8 +123,9 @@ void linkedList_clear(LINKED_LIST list) 
 	while (entry != list->header) {
 		LINKED_LIST_ENTRY next = entry->next;
 		entry->next = entry->previous = NULL;
-		free(entry->element);
+		// free(entry->element);
 		entry->element = NULL;
+		free(entry);
 		entry = next;
 	}
 	list->header->next = list->header->previous = list->header;

Modified: incubator/celix/trunk/utils/public/include/array_list.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/utils/public/include/array_list.h?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/utils/public/include/array_list.h (original)
+++ incubator/celix/trunk/utils/public/include/array_list.h Tue May 10 08:21:24 2011
@@ -50,6 +50,7 @@ void arrayList_clear(ARRAY_LIST list);
 ARRAY_LIST arrayList_clone(ARRAY_LIST list);
 
 ARRAY_LIST_ITERATOR arrayListIterator_create(ARRAY_LIST list);
+void arrayListIterator_destroy(ARRAY_LIST_ITERATOR iterator);
 bool arrayListIterator_hasNext(ARRAY_LIST_ITERATOR iterator);
 void * arrayListIterator_next(ARRAY_LIST_ITERATOR iterator);
 bool arrayListIterator_hasPrevious(ARRAY_LIST_ITERATOR iterator);

Modified: incubator/celix/trunk/utils/public/include/hash_map.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/utils/public/include/hash_map.h?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/utils/public/include/hash_map.h (original)
+++ incubator/celix/trunk/utils/public/include/hash_map.h Tue May 10 08:21:24 2011
@@ -39,6 +39,7 @@ typedef struct hashMapEntrySet * HASH_MA
 
 HASH_MAP hashMap_create(unsigned int (*keyHash)(void *), unsigned int (*valueHash)(void *),
 		int (*keyEquals)(void *, void *), int (*valueEquals)(void *, void *));
+void hashMap_destroy(HASH_MAP map, bool freeKeys, bool freeValues);
 int hashMap_size(HASH_MAP map);
 bool hashMap_isEmpty(HASH_MAP map);
 void * hashMap_get(HASH_MAP map, void * key);
@@ -46,10 +47,11 @@ bool hashMap_containsKey(HASH_MAP map, v
 HASH_MAP_ENTRY hashMap_getEntry(HASH_MAP map, void * key);
 void * hashMap_put(HASH_MAP map, void * key, void * value);
 void * hashMap_remove(HASH_MAP map, void * key);
-void hashMap_clear(HASH_MAP map);
+void hashMap_clear(HASH_MAP map, bool freeKey, bool freeValue);
 bool hashMap_containsValue(HASH_MAP map, void * value);
 
 HASH_MAP_ITERATOR hashMapIterator_create(HASH_MAP map);
+void hashMapIterator_destroy(HASH_MAP_ITERATOR iterator);
 bool hashMapIterator_hasNext(HASH_MAP_ITERATOR iterator);
 void hashMapIterator_remove(HASH_MAP_ITERATOR iterator);
 void * hashMapIterator_nextValue(HASH_MAP_ITERATOR iterator);
@@ -64,6 +66,7 @@ void hashMapKeySet_clear(HASH_MAP_KEY_SE
 bool hashMapKeySet_isEmpty(HASH_MAP_KEY_SET keySet);
 
 HASH_MAP_VALUES hashMapValues_create(HASH_MAP map);
+void hashMapValues_destroy(HASH_MAP_VALUES values);
 HASH_MAP_ITERATOR hashMapValues_iterator(HASH_MAP_VALUES values);
 int hashMapValues_size(HASH_MAP_VALUES values);
 bool hashMapValues_contains(HASH_MAP_VALUES values, void * o);

Modified: incubator/celix/trunk/utils/public/include/linked_list_iterator.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/utils/public/include/linked_list_iterator.h?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/utils/public/include/linked_list_iterator.h (original)
+++ incubator/celix/trunk/utils/public/include/linked_list_iterator.h Tue May 10 08:21:24 2011
@@ -33,6 +33,7 @@
 typedef struct linkedListIterator * LINKED_LIST_ITERATOR;
 
 LINKED_LIST_ITERATOR linkedListIterator_create(LINKED_LIST list, int index);
+void linkedListIterator_destroy(LINKED_LIST_ITERATOR iterator);
 bool linkedListIterator_hasNext(LINKED_LIST_ITERATOR iterator);
 void * linkedListIterator_next(LINKED_LIST_ITERATOR iterator);
 bool linkedListIterator_hasPrevious(LINKED_LIST_ITERATOR iterator);

Modified: incubator/celix/trunk/whiteboard/publisherA/activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/whiteboard/publisherA/activator.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/whiteboard/publisherA/activator.c (original)
+++ incubator/celix/trunk/whiteboard/publisherA/activator.c Tue May 10 08:21:24 2011
@@ -28,23 +28,36 @@
 #include "bundle_context.h"
 #include "publisher_private.h"
 
+struct activatorData {
+	PUBLISHER_SERVICE ps;
+	PUBLISHER pub;
+};
+
 void * bundleActivator_create() {
-	return NULL;
+	struct activatorData * data = (struct activatorData *) malloc(sizeof(*data));
+	return data;
 }
 
 void bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
-	PUBLISHER_SERVICE ps = malloc(sizeof(*ps));
-	PUBLISHER pub = malloc(sizeof(*pub));
-	ps->invoke = publisher_invoke;
-	ps->publisher = pub;
+	struct activatorData * data = (struct activatorData *) userData;
+	data->ps = malloc(sizeof(*(data->ps)));
+	data->pub = malloc(sizeof(*(data->pub)));
+	data->ps->invoke = publisher_invoke;
+	data->ps->publisher = data->pub;
 
-	bundleContext_registerService(context, PUBLISHER_NAME, ps, NULL);
+	bundleContext_registerService(context, PUBLISHER_NAME, data->ps, NULL);
 }
 
 void bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
-
+	struct activatorData * data = (struct activatorData *) userData;
+	data->ps->publisher = NULL;
+	data->ps->invoke = NULL;
+	free(data->pub);
+	free(data->ps);
+	data->pub = NULL;
+	data->ps = NULL;
 }
 
 void bundleActivator_destroy(void * userData) {
-
+	free(userData);
 }

Modified: incubator/celix/trunk/whiteboard/publisherA/publisher.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/whiteboard/publisherA/publisher.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/whiteboard/publisherA/publisher.c (original)
+++ incubator/celix/trunk/whiteboard/publisherA/publisher.c Tue May 10 08:21:24 2011
@@ -27,6 +27,6 @@
 #include "publisher_private.h"
 
 void publisher_invoke(PUBLISHER publisher, char * text) {
-	printf("Hello from A %s\n", text);
+	printf("Publisher A received: %s\n", text);
 }
 

Modified: incubator/celix/trunk/whiteboard/publisherB/activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/whiteboard/publisherB/activator.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/whiteboard/publisherB/activator.c (original)
+++ incubator/celix/trunk/whiteboard/publisherB/activator.c Tue May 10 08:21:24 2011
@@ -28,23 +28,36 @@
 #include "bundle_context.h"
 #include "publisher_private.h"
 
+struct activatorData {
+	PUBLISHER_SERVICE ps;
+	PUBLISHER pub;
+};
+
 void * bundleActivator_create() {
-	return NULL;
+	struct activatorData * data = (struct activatorData *) malloc(sizeof(*data));
+	return data;
 }
 
 void bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
-	PUBLISHER_SERVICE ps = malloc(sizeof(*ps));
-	PUBLISHER pub = malloc(sizeof(*pub));
-	ps->invoke = publisher_invoke;
-	ps->publisher = pub;
+	struct activatorData * data = (struct activatorData *) userData;
+	data->ps = malloc(sizeof(*(data->ps)));
+	data->pub = malloc(sizeof(*(data->pub)));
+	data->ps->invoke = publisher_invoke;
+	data->ps->publisher = data->pub;
 
-	bundleContext_registerService(context, PUBLISHER_NAME, ps, NULL);
+	bundleContext_registerService(context, PUBLISHER_NAME, data->ps, NULL);
 }
 
 void bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
-
+	struct activatorData * data = (struct activatorData *) userData;
+	data->ps->publisher = NULL;
+	data->ps->invoke = NULL;
+	free(data->pub);
+	free(data->ps);
+	data->pub = NULL;
+	data->ps = NULL;
 }
 
 void bundleActivator_destroy(void * userData) {
-
+	free(userData);
 }

Modified: incubator/celix/trunk/whiteboard/publisherB/publisher.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/whiteboard/publisherB/publisher.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/whiteboard/publisherB/publisher.c (original)
+++ incubator/celix/trunk/whiteboard/publisherB/publisher.c Tue May 10 08:21:24 2011
@@ -27,6 +27,6 @@
 #include "publisher_private.h"
 
 void publisher_invoke(PUBLISHER publisher, char * text) {
-	printf("Hello from B %s\n", text);
+	printf("Publisher B received: %s\n", text);
 }
 

Modified: incubator/celix/trunk/whiteboard/tracker/activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/whiteboard/tracker/activator.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/whiteboard/tracker/activator.c (original)
+++ incubator/celix/trunk/whiteboard/tracker/activator.c Tue May 10 08:21:24 2011
@@ -51,6 +51,7 @@ void * trk_send(void * handle) {
 		sleep(1);
 	}
 	pthread_exit(NULL);
+	return NULL;
 }
 
 void * addingServ(void * handle, SERVICE_REFERENCE ref) {

Modified: incubator/celix/trunk/whiteboard/tracker_depman/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/whiteboard/tracker_depman/CMakeLists.txt?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/whiteboard/tracker_depman/CMakeLists.txt (original)
+++ incubator/celix/trunk/whiteboard/tracker_depman/CMakeLists.txt Tue May 10 08:21:24 2011
@@ -15,7 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
-add_library(tracker_depman SHARED dependency_activator)
+add_library(tracker_depman SHARED dependency_activator tracker)
 include_directories("${PROJECT_SOURCE_DIR}/celix")
 include_directories("${PROJECT_SOURCE_DIR}/dependency_manager")
 include_directories("../publisherService")

Modified: incubator/celix/trunk/whiteboard/tracker_depman/dependency_activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/whiteboard/tracker_depman/dependency_activator.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/whiteboard/tracker_depman/dependency_activator.c (original)
+++ incubator/celix/trunk/whiteboard/tracker_depman/dependency_activator.c Tue May 10 08:21:24 2011
@@ -30,69 +30,16 @@
 
 #include "dependency_activator_base.h"
 #include "service_component_private.h"
-#include "service.h"
 #include "publisher.h"
-
-struct data {
-	SERVICE service;
-	BUNDLE_CONTEXT context;
-	ARRAY_LIST publishers;
-	pthread_t sender;
-	bool running;
-};
-
-void * dp_send(void * handle) {
-	struct data * data = (struct data *) handle;
-	while (data->running) {
-		int i;
-		for (i = 0; i < arrayList_size(data->publishers); i++) {
-			PUBLISHER_SERVICE pub = (PUBLISHER_SERVICE) arrayList_get(data->publishers, i);
-			pub->invoke(pub->publisher, "test");
-		}
-		sleep(1);
-	}
-	pthread_exit(NULL);
-}
-
-void service_init(void * userData) {
-
-}
-
-void service_start(void * userData) {
-	struct data * data = (struct data *) userData;
-	data->running = true;
-	pthread_create(&data->sender, NULL, dp_send, data);
-}
-
-void service_stop(void * userData) {
-	struct data * data = (struct data *) userData;
-	data->running = false;
-}
-
-void service_destroy(void * userData) {
-
-}
-
-void addedServ(void * handle, SERVICE_REFERENCE ref, void * service) {
-	struct data * data = (struct data *) handle;
-	arrayList_add(data->publishers, service);
-	printf("Service Added\n");
-}
-
-void modifiedServ(void * handle, SERVICE_REFERENCE ref, void * service) {
-	struct data * data = (struct data *) handle;
-	printf("Service Changed\n");
-}
-
-void removedServ(void * handle, SERVICE_REFERENCE ref, void * service) {
-	struct data * data = (struct data *) handle;
-	arrayList_removeElement(data->publishers, service);
-	printf("Service Removed\n");
-}
+#include "tracker.h"
 
 void * dm_create() {
 	struct data * data = malloc(sizeof(*data));
 	data->publishers = arrayList_create();
+	data->context = NULL;
+	data->running = false;
+	data->sender = NULL;
+	data->service = NULL;
 	return data;
 }
 
@@ -105,7 +52,7 @@ void dm_init(void * userData, BUNDLE_CON
 	SERVICE_DEPENDENCY dep = dependencyActivatorBase_createServiceDependency(manager);
 	serviceDependency_setRequired(dep, false);
 	serviceDependency_setService(dep, PUBLISHER_NAME, NULL);
-	serviceDependency_setCallbacks(dep, addedServ, modifiedServ, removedServ);
+	serviceDependency_setCallbacks(dep, tracker_addedServ, tracker_modifiedServ, tracker_removedServ);
 	serviceComponent_addServiceDependency(service, dep);
 
 	data->service = service;
@@ -115,5 +62,9 @@ void dm_init(void * userData, BUNDLE_CON
 void dm_destroy(void * userData, BUNDLE_CONTEXT context, DEPENDENCY_MANAGER manager) {
 	struct data * data = (struct data *) userData;
 	dependencyManager_remove(manager, data->service);
+	arrayList_destroy(data->publishers);
+	data->publishers = NULL;
+	free(data);
+	data = NULL;
 }
 

Added: incubator/celix/trunk/whiteboard/tracker_depman/tracker.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/whiteboard/tracker_depman/tracker.c?rev=1101360&view=auto
==============================================================================
--- incubator/celix/trunk/whiteboard/tracker_depman/tracker.c (added)
+++ incubator/celix/trunk/whiteboard/tracker_depman/tracker.c Tue May 10 08:21:24 2011
@@ -0,0 +1,66 @@
+/*
+ * tracker.c
+ *
+ *  Created on: Mar 7, 2011
+ *      Author: alexanderb
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <stdbool.h>
+
+#include "service.h"
+#include "publisher.h"
+#include "tracker.h"
+
+void * dp_send(void * handle) {
+	struct data * data = (struct data *) handle;
+	while (data->running) {
+		int i;
+		for (i = 0; i < arrayList_size(data->publishers); i++) {
+			PUBLISHER_SERVICE pub = (PUBLISHER_SERVICE) arrayList_get(data->publishers, i);
+			pub->invoke(pub->publisher, "Tracker message");
+		}
+		sleep(1);
+	}
+	pthread_exit(NULL);
+	return NULL;
+}
+
+void service_init(void * userData) {
+
+}
+
+void service_start(void * userData) {
+	struct data * data = (struct data *) userData;
+	data->running = true;
+	pthread_create(&data->sender, NULL, dp_send, data);
+}
+
+void service_stop(void * userData) {
+	struct data * data = (struct data *) userData;
+	data->running = false;
+}
+
+void service_destroy(void * userData) {
+
+}
+
+void tracker_addedServ(void * handle, SERVICE_REFERENCE ref, void * service) {
+	struct data * data = (struct data *) handle;
+	arrayList_add(data->publishers, service);
+	printf("Service Added\n");
+}
+
+void tracker_modifiedServ(void * handle, SERVICE_REFERENCE ref, void * service) {
+	struct data * data = (struct data *) handle;
+	printf("Service Changed\n");
+}
+
+void tracker_removedServ(void * handle, SERVICE_REFERENCE ref, void * service) {
+	struct data * data = (struct data *) handle;
+	arrayList_removeElement(data->publishers, service);
+	printf("Service Removed\n");
+}
+

Propchange: incubator/celix/trunk/whiteboard/tracker_depman/tracker.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/whiteboard/tracker_depman/tracker.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/whiteboard/tracker_depman/tracker.h?rev=1101360&view=auto
==============================================================================
--- incubator/celix/trunk/whiteboard/tracker_depman/tracker.h (added)
+++ incubator/celix/trunk/whiteboard/tracker_depman/tracker.h Tue May 10 08:21:24 2011
@@ -0,0 +1,27 @@
+/*
+ * tracker.h
+ *
+ *  Created on: Mar 7, 2011
+ *      Author: alexanderb
+ */
+
+#ifndef TRACKER_H_
+#define TRACKER_H_
+
+#include "headers.h"
+#include "service_component.h"
+
+struct data {
+	SERVICE service;
+	BUNDLE_CONTEXT context;
+	ARRAY_LIST publishers;
+	pthread_t sender;
+	bool running;
+};
+
+void tracker_addedServ(void * handle, SERVICE_REFERENCE ref, void * service);
+void tracker_modifiedServ(void * handle, SERVICE_REFERENCE ref, void * service);
+void tracker_removedServ(void * handle, SERVICE_REFERENCE ref, void * service);
+
+
+#endif /* TRACKER_H_ */

Propchange: incubator/celix/trunk/whiteboard/tracker_depman/tracker.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message