Return-Path: X-Original-To: apmail-incubator-celix-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-celix-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 977529648 for ; Fri, 22 Jun 2012 12:40:24 +0000 (UTC) Received: (qmail 30987 invoked by uid 500); 22 Jun 2012 12:40:24 -0000 Delivered-To: apmail-incubator-celix-commits-archive@incubator.apache.org Received: (qmail 30943 invoked by uid 500); 22 Jun 2012 12:40:24 -0000 Mailing-List: contact celix-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: celix-dev@incubator.apache.org Delivered-To: mailing list celix-commits@incubator.apache.org Received: (qmail 30899 invoked by uid 99); 22 Jun 2012 12:40:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jun 2012 12:40:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jun 2012 12:40:19 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 23E2C23889E1; Fri, 22 Jun 2012 12:39:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1352863 [3/3] - in /incubator/celix/trunk/remote_services: remote_service_admin/private/src/ remote_service_admin_http/ remote_service_admin_http/META-INF/ remote_service_admin_http/private/ remote_service_admin_http/private/include/ remot... Date: Fri, 22 Jun 2012 12:39:57 -0000 To: celix-commits@incubator.apache.org From: abroekhuis@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120622123958.23E2C23889E1@eris.apache.org> 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 + +#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 +#include + +#include + +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;