Hi,

The echo echo-example  was not working. I made a fix. It does not rely any
more an apr but on posix threads.

I added also a small error message fix and enabled compiler warnings.


The fix is a patcn on current trunk. If you lke to have it in another
format please let me know.

Regards,
Erjan
From 1dbf5dbf227d28c0f4ada4264f424fb028168e1f Mon Sep 17 00:00:00 2001
From: Erjan <[email protected]>
Date: Sat, 27 Sep 2014 23:06:21 +0200
Subject: [PATCH 1/2] Fixed echo example, added warning-option to Makefiles,
 error on using a function without  prototype and compiler optimalization
 Removed APR form the echo example

---
 CMakeLists.txt                                     |  2 +-
 cmake/cmake_celix/Packaging.cmake                  |  2 +-
 echo_example_patch                                 |  0
 examples/CMakeLists.txt                            |  2 +-
 examples/deploy.cmake                              |  2 +-
 examples/echo_service/CMakeLists.txt               |  1 +
 examples/echo_service/client/CMakeLists.txt        |  4 ++++
 .../client/private/include/echo_client_private.h   |  7 +++---
 .../echo_service/client/private/src/echo_client.c  | 25 +++++++++++++---------
 .../client/private/src/echo_client_activator.c     | 14 +++++++-----
 examples/echo_service/server/CMakeLists.txt        |  4 ++++
 log_service/private/src/log_factory.c              |  3 +--
 shell/private/src/inspect_command.c                |  2 +-
 13 files changed, 42 insertions(+), 26 deletions(-)
 create mode 100644 echo_example_patch

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 87c3058..5e141c4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,7 +29,7 @@ set(CMAKE_INSTALL_NAME_DIR "@rpath")
 
 SET(CMAKE_BUILD_TYPE "Debug")
 IF(UNIX)
-	SET(CMAKE_C_FLAGS "-D_GNU_SOURCE -std=gnu99 ${CMAKE_C_FLAGS}")
+	SET(CMAKE_C_FLAGS "-D_GNU_SOURCE -std=gnu99 -pthread -Wall -Werror-implicit-function-declaration -O2 ${CMAKE_C_FLAGS}")
 ENDIF()
 IF(WIN32)
 	SET(CMAKE_C_FLAGS "-D_CRT_SECURE_NO_WARNINGS ${CMAKE_C_FLAGS}")
diff --git a/cmake/cmake_celix/Packaging.cmake b/cmake/cmake_celix/Packaging.cmake
index f2b35c1..f321c2f 100644
--- a/cmake/cmake_celix/Packaging.cmake
+++ b/cmake/cmake_celix/Packaging.cmake
@@ -82,7 +82,7 @@ add_custom_target(bundles ALL)
 
 MACRO(CHECK_HEADERS)
     if (NOT BUNDLE_SYMBOLICNAME)
-        MESSAGE(FATAL_ERROR "Bundle Symbolic Name not set, please set it using \"SET(BUNDLE_SYMBOLIC_NAME \"bundle_symbolic_name\")\".")
+        MESSAGE(FATAL_ERROR "Bundle Symbolic Name not set, please set it using \"SET(BUNDLE_SYMBOLICNAME \"bundle_symbolic_name\")\".")
     endif (NOT BUNDLE_SYMBOLICNAME)
     
     if (NOT BUNDLE_VERSION)
diff --git a/echo_example_patch b/echo_example_patch
new file mode 100644
index 0000000..e69de29
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 555b72e..86d8d85 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -21,7 +21,7 @@ if (EXAMPLES)
     #add_subdirectory(mongoose)
     
     #add_subdirectory(whiteboard)
-    #add_subdirectory(echo_service)
+    add_subdirectory(echo_service)
     
     add_subdirectory(osgi-in-action/chapter04-correct-lookup)
     add_subdirectory(osgi-in-action/chapter04-correct-listener)
diff --git a/examples/deploy.cmake b/examples/deploy.cmake
index 29c7736..894d572 100644
--- a/examples/deploy.cmake
+++ b/examples/deploy.cmake
@@ -22,5 +22,5 @@ if (EXAMPLES)
 	deploy("hello_world" BUNDLES shell shell_tui org.apache.incubator.celix.helloworld hello_world_test log_service)
 	#deploy("wb" BUNDLES tracker publisherA publisherB shell shell_tui log_service log_writer)
 	#deploy("wb_dp" BUNDLES tracker_depman publisherA publisherB shell shell_tui log_service log_writer)
-	#deploy("echo" BUNDLES echo_server echo_client shell shell_tui log_service log_writer)
+	deploy("echo" BUNDLES echo_server echo_client shell shell_tui)
 endif (EXAMPLES)
\ No newline at end of file
diff --git a/examples/echo_service/CMakeLists.txt b/examples/echo_service/CMakeLists.txt
index 0b4682c..7f2d4ac 100644
--- a/examples/echo_service/CMakeLists.txt
+++ b/examples/echo_service/CMakeLists.txt
@@ -15,5 +15,6 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set(CMAKE_CXX_FLAGS "-O2 -Wall") 
 add_subdirectory(server)
 add_subdirectory(client)
diff --git a/examples/echo_service/client/CMakeLists.txt b/examples/echo_service/client/CMakeLists.txt
index a1900ce..db512e6 100644
--- a/examples/echo_service/client/CMakeLists.txt
+++ b/examples/echo_service/client/CMakeLists.txt
@@ -15,6 +15,10 @@
 # specific language governing permissions and limitations
 # under the License.
 
+SET(BUNDLE_SYMBOLICNAME "apache_celix_examples_echo_client")
+SET(BUNDLE_VERSION "0.0.1")
+SET(BUNDLE_NAME "Apache Celix Echo Client")
+
 bundle(echo_client SOURCES 
 	private/src/echo_client_activator 
 	private/src/echo_client
diff --git a/examples/echo_service/client/private/include/echo_client_private.h b/examples/echo_service/client/private/include/echo_client_private.h
index 1fa82e5..461e7a2 100644
--- a/examples/echo_service/client/private/include/echo_client_private.h
+++ b/examples/echo_service/client/private/include/echo_client_private.h
@@ -32,14 +32,13 @@
 struct echoClient {
 	service_tracker_pt tracker;
 	bool running;
-	apr_pool_t *pool;
-
-	apr_thread_t *sender;
+	pthread_t sender_thread;
+	char *ident;
 };
 
 typedef struct echoClient * echo_client_pt;
 
-echo_client_pt echoClient_create(service_tracker_pt context, apr_pool_t *pool);
+echo_client_pt echoClient_create(service_tracker_pt context);
 
 void echoClient_start(echo_client_pt client);
 void echoClient_stop(echo_client_pt client);
diff --git a/examples/echo_service/client/private/src/echo_client.c b/examples/echo_service/client/private/src/echo_client.c
index 26011fa..b202b66 100644
--- a/examples/echo_service/client/private/src/echo_client.c
+++ b/examples/echo_service/client/private/src/echo_client.c
@@ -24,49 +24,54 @@
  *  \copyright	Apache License, Version 2.0
  */
 #include <stdlib.h>
+#include <pthread.h>
+#include <unistd.h>
 
 #include "service_tracker.h"
 
 #include "echo_client_private.h"
 #include "echo_server.h"
 
-static void *APR_THREAD_FUNC trk_send(apr_thread_t *thd, void *handle) {
+static void *trk_send(void *handle) {
+
 	echo_client_pt client = (echo_client_pt) handle;
+
 	while (client->running) {
 		echo_service_pt service = (echo_service_pt) serviceTracker_getService(client->tracker);
 		if (service != NULL) {
-			service->echo(service->server, "hi");
+			service->echo(service->server, client->ident);
 		}
-		apr_sleep(1000000);
+		sleep(1);
 	}
-	apr_thread_exit(thd, APR_SUCCESS);
+
+	pthread_exit(NULL);
+
 	return NULL;
 }
 
-echo_client_pt echoClient_create(service_tracker_pt echoServiceTracker, apr_pool_t *pool) {
+echo_client_pt echoClient_create(service_tracker_pt echoServiceTracker) {
 	echo_client_pt client = malloc(sizeof(*client));
 
 	client->tracker = echoServiceTracker;
 	client->running = false;
-	client->pool = pool;
+	client->ident = "Linux rules";
 
 	return client;
 }
 
 void echoClient_start(echo_client_pt client) {
 	client->running = true;
-	apr_thread_create(&client->sender, NULL, trk_send, client, client->pool);
+	pthread_create(&client->sender_thread, NULL, trk_send, client);
 }
 
 void echoClient_stop(echo_client_pt client) {
-	apr_status_t status;
 	client->running = false;
-	apr_thread_join(&status, client->sender);
+	pthread_join(client->sender_thread, NULL);
 }
 
 void echoClient_destroy(echo_client_pt client) {
 	client->tracker = NULL;
-	client->sender = 0;
+	client->sender_thread = 0;
 	free(client);
 	client = NULL;
 }
diff --git a/examples/echo_service/client/private/src/echo_client_activator.c b/examples/echo_service/client/private/src/echo_client_activator.c
index cf60f02..cdfa2c0 100644
--- a/examples/echo_service/client/private/src/echo_client_activator.c
+++ b/examples/echo_service/client/private/src/echo_client_activator.c
@@ -41,7 +41,6 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData
 	struct echoActivator * act = malloc(sizeof(*act));
 	act->client = NULL;
 	act->tracker = NULL;
-
 	*userData = act;
 
 	return CELIX_SUCCESS;
@@ -50,15 +49,20 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData
 celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
 	struct echoActivator * act = (struct echoActivator *) userData;
 
-	apr_pool_t *pool = NULL;
+	//apr_pool_t *pool = NULL;
 	service_tracker_pt tracker = NULL;
 	echo_client_pt client = NULL;
 
-	bundleContext_getMemoryPool(context, &pool);
-	serviceTracker_create(pool, context, ECHO_SERVICE_NAME, NULL, &tracker);
+	//bundleContext_getMemoryPool(context, &pool);
+	//serviceTracker_create(pool, context, ECHO_SERVICE_NAME, NULL, &tracker);
+	printf("Tracker voor %p\n", tracker);
+
+	serviceTracker_create(context, ECHO_SERVICE_NAME, NULL, &tracker);
+
+	printf("Tracker na   %p\n", tracker);
 	act->tracker = tracker;
 
-	client = echoClient_create(tracker, pool);
+	client = echoClient_create(tracker);
 	act->client = client;
 
 	echoClient_start(act->client);
diff --git a/examples/echo_service/server/CMakeLists.txt b/examples/echo_service/server/CMakeLists.txt
index 826454e..b2f3001 100644
--- a/examples/echo_service/server/CMakeLists.txt
+++ b/examples/echo_service/server/CMakeLists.txt
@@ -15,6 +15,10 @@
 # specific language governing permissions and limitations
 # under the License.
 
+SET(BUNDLE_SYMBOLICNAME "apache_celix_examples_echo_server")
+SET(BUNDLE_VERSION "0.0.1")
+SET(BUNDLE_NAME "Apache Celix Echo Server")
+
 bundle(echo_server SOURCES 
 	private/src/echo_server_activator 
 	private/src/echo_server
diff --git a/log_service/private/src/log_factory.c b/log_service/private/src/log_factory.c
index d590795..8bc7680 100644
--- a/log_service/private/src/log_factory.c
+++ b/log_service/private/src/log_factory.c
@@ -55,7 +55,7 @@ celix_status_t logFactory_create(apr_pool_t *pool, log_pt log, service_factory_p
         }
     }
 
-    return CELIX_SUCCESS;
+    return status;
 }
 
 celix_status_t logFactory_getService(void *factory, bundle_pt bundle, service_registration_pt registration, void **service) {
@@ -76,6 +76,5 @@ celix_status_t logFactory_getService(void *factory, bundle_pt bundle, service_re
 }
 
 celix_status_t logFactory_ungetService(void *factory, bundle_pt bundle, service_registration_pt registration) {
-    log_service_factory_pt log_factory = ((service_factory_pt) factory)->factory;
     return CELIX_SUCCESS;
 }
diff --git a/shell/private/src/inspect_command.c b/shell/private/src/inspect_command.c
index d99521e..019d4c8 100644
--- a/shell/private/src/inspect_command.c
+++ b/shell/private/src/inspect_command.c
@@ -204,7 +204,7 @@ celix_status_t inspectCommand_printImportedServices(command_pt command, array_li
     array_list_pt bundles = NULL;
 
     if (arrayList_isEmpty(ids)) {
-        celix_status_t status = bundleContext_getBundles(command->bundleContext, &bundles);
+        status = bundleContext_getBundles(command->bundleContext, &bundles);
     } else {
         unsigned int i;
 
-- 
2.1.1


From 70c3b5b821423ed66448423e0af8d6fc1ce2cd07 Mon Sep 17 00:00:00 2001
From: Erjan <[email protected]>
Date: Sat, 27 Sep 2014 23:46:26 +0200
Subject: [PATCH 2/2] Removed debug printfs

---
 examples/echo_service/client/private/src/echo_client_activator.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/examples/echo_service/client/private/src/echo_client_activator.c b/examples/echo_service/client/private/src/echo_client_activator.c
index cdfa2c0..4a31c45 100644
--- a/examples/echo_service/client/private/src/echo_client_activator.c
+++ b/examples/echo_service/client/private/src/echo_client_activator.c
@@ -49,17 +49,11 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData
 celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
 	struct echoActivator * act = (struct echoActivator *) userData;
 
-	//apr_pool_t *pool = NULL;
 	service_tracker_pt tracker = NULL;
 	echo_client_pt client = NULL;
 
-	//bundleContext_getMemoryPool(context, &pool);
-	//serviceTracker_create(pool, context, ECHO_SERVICE_NAME, NULL, &tracker);
-	printf("Tracker voor %p\n", tracker);
-
 	serviceTracker_create(context, ECHO_SERVICE_NAME, NULL, &tracker);
 
-	printf("Tracker na   %p\n", tracker);
 	act->tracker = tracker;
 
 	client = echoClient_create(tracker);
-- 
2.1.1

Reply via email to