Added: 
incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c?rev=1352863&view=auto
==============================================================================
--- 
incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c
 (added)
+++ 
incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c
 Fri Jun 22 12:39:56 2012
@@ -0,0 +1,105 @@
+/*
+ * remote_service_admin_activator.c
+ *
+ *  Created on: Sep 30, 2011
+ *      Author: alexander
+ */
+#include <stdlib.h>
+
+#include "bundle_activator.h"
+#include "service_registration.h"
+
+#include "remote_service_admin_impl.h"
+#include "export_registration_impl.h"
+#include "import_registration_impl.h"
+
+struct activator {
+       apr_pool_t *pool;
+       remote_service_admin_t admin;
+       SERVICE_REGISTRATION registration;
+};
+
+celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData) 
{
+       celix_status_t status = CELIX_SUCCESS;
+       apr_pool_t *parentPool = NULL;
+       apr_pool_t *pool = NULL;
+       struct activator *activator;
+
+       status = bundleContext_getMemoryPool(context, &parentPool);
+       if (status == CELIX_SUCCESS) {
+               if (apr_pool_create(&pool, parentPool) != APR_SUCCESS) {
+                       status = CELIX_BUNDLE_EXCEPTION;
+               } else {
+                       activator = apr_palloc(pool, sizeof(*activator));
+                       if (!activator) {
+                               status = CELIX_ENOMEM;
+                       } else {
+                               activator->pool = pool;
+                               activator->admin = NULL;
+                               activator->registration = NULL;
+
+                               *userData = activator;
+                       }
+               }
+       }
+
+       return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+       celix_status_t status = CELIX_SUCCESS;
+       struct activator *activator = userData;
+       remote_service_admin_service_t remoteServiceAdmin = NULL;
+
+       status = remoteServiceAdmin_create(activator->pool, context, 
&activator->admin);
+       if (status == CELIX_SUCCESS) {
+               remoteServiceAdmin = apr_palloc(activator->pool, 
sizeof(*remoteServiceAdmin));
+               if (!remoteServiceAdmin) {
+                       status = CELIX_ENOMEM;
+               } else {
+                       remoteServiceAdmin->admin = activator->admin;
+                       remoteServiceAdmin->exportService = 
remoteServiceAdmin_exportService;
+                       remoteServiceAdmin->getExportedServices = 
remoteServiceAdmin_getExportedServices;
+                       remoteServiceAdmin->getImportedEndpoints = 
remoteServiceAdmin_getImportedEndpoints;
+                       remoteServiceAdmin->importService = 
remoteServiceAdmin_importService;
+
+                       remoteServiceAdmin->exportReference_getExportedEndpoint 
= exportReference_getExportedEndpoint;
+                       remoteServiceAdmin->exportReference_getExportedService 
= exportReference_getExportedService;
+
+                       remoteServiceAdmin->exportRegistration_close = 
exportRegistration_close;
+                       remoteServiceAdmin->exportRegistration_getException = 
exportRegistration_getException;
+                       
remoteServiceAdmin->exportRegistration_getExportReference = 
exportRegistration_getExportReference;
+
+                       remoteServiceAdmin->importReference_getImportedEndpoint 
= importReference_getImportedEndpoint;
+                       remoteServiceAdmin->importReference_getImportedService 
= importReference_getImportedService;
+
+                       remoteServiceAdmin->importRegistration_close = 
importRegistration_close;
+                       remoteServiceAdmin->importRegistration_getException = 
importRegistration_getException;
+                       
remoteServiceAdmin->importRegistration_getImportReference = 
importRegistration_getImportReference;
+
+                       status = bundleContext_registerService(context, 
REMOTE_SERVICE_ADMIN, remoteServiceAdmin, NULL, &activator->registration);
+               }
+       }
+
+       return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+       celix_status_t status = CELIX_SUCCESS;
+       struct activator *activator = userData;
+
+       remoteServiceAdmin_stop(activator->admin);
+       serviceRegistration_unregister(activator->registration);
+       activator->registration = NULL;
+
+
+       return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT 
context) {
+       celix_status_t status = CELIX_SUCCESS;
+       struct activator *activator = userData;
+       return status;
+}
+
+

Added: 
incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_http_impl.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_http_impl.c?rev=1352863&view=auto
==============================================================================
--- 
incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_http_impl.c
 (added)
+++ 
incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_http_impl.c
 Fri Jun 22 12:39:56 2012
@@ -0,0 +1,105 @@
+/*
+ * remote_service_admin_http.c
+ *
+ *  Created on: May 24, 2012
+ *      Author: alexander
+ */
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <celix_errno.h>
+
+typedef struct remote_service_admin_http *remote_service_admin_http_t;
+
+struct remote_service_admin_http {
+       apr_pool_t *pool;
+       BUNDLE_CONTEXT context;
+
+       struct mg_context *ctx;
+};
+
+static const char *ajax_reply_start =
+  "HTTP/1.1 200 OK\r\n"
+  "Cache: no-cache\r\n"
+  "Content-Type: application/x-javascript\r\n"
+  "\r\n";
+
+void *remoteServiceAdminHttp_callback(enum mg_event event, struct 
mg_connection *conn, const struct mg_request_info *request_info);
+
+celix_status_t remoteServiceAdminHttp_create(apr_pool_t *pool, BUNDLE_CONTEXT 
context, remote_service_admin_http_t *httpAdmin) {
+       celix_status_t status = CELIX_SUCCESS;
+
+       *httpAdmin = apr_palloc(pool, sizeof(**httpAdmin));
+       if (!*httpAdmin) {
+               status = CELIX_ENOMEM;
+       } else {
+               (*httpAdmin)->pool = pool;
+               (*httpAdmin)->context = context;
+
+               // Start webserver
+               char *port = NULL;
+               bundleContext_getProperty(context, "RSA_PORT", &port);
+               if (port == NULL) {
+                       printf("No RemoteServiceAdmin port set, set it using 
RSA_PORT!\n");
+               }
+               const char *options[] = {"listening_ports", port, NULL};
+               (*httpAdmin)->ctx = mg_start(remoteServiceAdminHttp_callback, 
(*httpAdmin), options);
+       }
+
+       return status;
+}
+
+/**
+ * Request: http://host:port/services/{service}/{request}
+ */
+void *remoteServiceAdminHttp_callback(enum mg_event event, struct 
mg_connection *conn, const struct mg_request_info *request_info) {
+       if (request_info->uri != NULL) {
+               printf("REMOTE_SERVICE_ADMIN: Handle request: %s\n", 
request_info->uri);
+               remote_service_admin_t rsa = request_info->user_data;
+
+               if (strncmp(request_info->uri, "/services/", 10) == 0) {
+                       // uri = /services/myservice/call
+                       char *uri = request_info->uri;
+                       // rest = myservice/call
+                       char *rest = uri+10;
+                       int length = strlen(rest);
+                       char *callStart = strchr(rest, '/');
+                       int pos = callStart - rest;
+                       char service[pos+1];
+                       strncpy(service, rest, pos);
+                       service[pos] = '\0';
+
+                       char request[length - pos];
+                       strncpy(request, rest + pos + 1, length - pos);
+
+                       const char *lengthStr = mg_get_header(conn, (const char 
*) "Content-Length");
+                       int datalength = apr_atoi64(lengthStr);
+                       char data[datalength+1];
+                       mg_read(conn, data, datalength);
+                       data[datalength] = '\0';
+
+                       char *reply = NULL;
+                       remoteServiceAdmin_handleRequest(rsa, service, request, 
data, &reply);
+
+                       HASH_MAP_ITERATOR iter = 
hashMapIterator_create(rsa->exportedServices);
+                       while (hashMapIterator_hasNext(iter)) {
+                               HASH_MAP_ENTRY entry = 
hashMapIterator_nextEntry(iter);
+                               ARRAY_LIST exports = 
hashMapEntry_getValue(entry);
+                               int expIt = 0;
+                               for (expIt = 0; expIt < 
arrayList_size(exports); expIt++) {
+                                       export_registration_t export = 
arrayList_get(exports, expIt);
+                                       if (strcmp(service, 
export->endpointDescription->service) == 0) {
+                                               char *reply = NULL;
+                                               
export->endpoint->handleRequest(export->endpoint->endpoint, request, data, 
&reply);
+                                               if (reply != NULL) {
+                                                       mg_printf(conn, "%s", 
ajax_reply_start);
+                                                       mg_printf(conn, "%s", 
reply);
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       return "";
+}

Copied: 
incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
 (from r1352045, 
incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c)
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c?p2=incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c&p1=incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c&r1=1352045&r2=1352863&rev=1352863&view=diff
==============================================================================
--- 
incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c
 (original)
+++ 
incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
 Fri Jun 22 12:39:56 2012
@@ -21,11 +21,7 @@
 #include "service_reference.h"
 #include "service_registration.h"
 
-static const char *ajax_reply_start =
-  "HTTP/1.1 200 OK\r\n"
-  "Cache: no-cache\r\n"
-  "Content-Type: application/x-javascript\r\n"
-  "\r\n";
+
 
 void *remoteServiceAdmin_callback(enum mg_event event, struct mg_connection 
*conn, const struct mg_request_info *request_info);
 celix_status_t remoteServiceAdmin_installEndpoint(remote_service_admin_t 
admin, export_registration_t registration, SERVICE_REFERENCE reference, char 
*interface);
@@ -82,56 +78,22 @@ celix_status_t remoteServiceAdmin_stop(r
        return status;
 }
 
-/**
- * Request: http://host:port/services/{service}/{request}
- */
-void *remoteServiceAdmin_callback(enum mg_event event, struct mg_connection 
*conn, const struct mg_request_info *request_info) {
-       if (request_info->uri != NULL) {
-               printf("REMOTE_SERVICE_ADMIN: Handle request: %s\n", 
request_info->uri);
-               remote_service_admin_t rsa = request_info->user_data;
-
-               if (strncmp(request_info->uri, "/services/", 10) == 0) {
-                       // uri = /services/myservice/call
-                       char *uri = request_info->uri;
-                       // rest = myservice/call
-                       char *rest = uri+10;
-                       int length = strlen(rest);
-                       char *callStart = strchr(rest, '/');
-                       int pos = callStart - rest;
-                       char service[pos+1];
-                       strncpy(service, rest, pos);
-                       service[pos] = '\0';
-
-                       char request[length - pos];
-                       strncpy(request, rest + pos + 1, length - pos);
-
-                       const char *lengthStr = mg_get_header(conn, (const char 
*) "Content-Length");
-                       int datalength = apr_atoi64(lengthStr);
-                       char data[datalength+1];
-                       mg_read(conn, data, datalength);
-                       data[datalength] = '\0';
-
-                       HASH_MAP_ITERATOR iter = 
hashMapIterator_create(rsa->exportedServices);
-                       while (hashMapIterator_hasNext(iter)) {
-                               HASH_MAP_ENTRY entry = 
hashMapIterator_nextEntry(iter);
-                               ARRAY_LIST exports = 
hashMapEntry_getValue(entry);
-                               int expIt = 0;
-                               for (expIt = 0; expIt < 
arrayList_size(exports); expIt++) {
-                                       export_registration_t export = 
arrayList_get(exports, expIt);
-                                       if (strcmp(service, 
export->endpointDescription->service) == 0) {
-                                               char *reply = NULL;
-                                               
export->endpoint->handleRequest(export->endpoint->endpoint, request, data, 
&reply);
-                                               if (reply != NULL) {
-                                                       mg_printf(conn, "%s", 
ajax_reply_start);
-                                                       mg_printf(conn, "%s", 
reply);
-                                               }
-                                       }
-                               }
+
+
+celix_status_t remoteServiceAdmin_handleRequest(remote_service_admin_t rsa, 
char *service, char *request, char *data, char **reply) {
+       HASH_MAP_ITERATOR iter = hashMapIterator_create(rsa->exportedServices);
+       while (hashMapIterator_hasNext(iter)) {
+               HASH_MAP_ENTRY entry = hashMapIterator_nextEntry(iter);
+               ARRAY_LIST exports = hashMapEntry_getValue(entry);
+               int expIt = 0;
+               for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
+                       export_registration_t export = arrayList_get(exports, 
expIt);
+                       if (strcmp(service, 
export->endpointDescription->service) == 0) {
+                               
export->endpoint->handleRequest(export->endpoint->endpoint, request, data, 
reply);
                        }
                }
        }
-
-       return "";
+       return CELIX_SUCCESS;
 }
 
 celix_status_t remoteServiceAdmin_exportService(remote_service_admin_t admin, 
SERVICE_REFERENCE reference, PROPERTIES properties, ARRAY_LIST *registrations) {
@@ -233,10 +195,7 @@ celix_status_t remoteServiceAdmin_create
                PROPERTIES endpointProperties, char *interface, 
endpoint_description_t *description) {
        celix_status_t status = CELIX_SUCCESS;
 
-       apr_pool_t *childPool = NULL;
-       apr_pool_create(&childPool, admin->pool);
-
-       *description = apr_palloc(childPool, sizeof(*description));
+       *description = apr_palloc(admin->pool, sizeof(*description));
 //     *description = malloc(sizeof(*description));
        if (!*description) {
                status = CELIX_ENOMEM;


Reply via email to