You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by ab...@apache.org on 2011/07/11 10:26:53 UTC
svn commit: r1145065 - in /incubator/celix/trunk: ./ celix_test/
dependency_manager/ framework/private/include/ framework/private/src/
launcher/ log_service/private/include/ log_service/private/src/
log_service/public/include/ log_writer/ shell/ utils/...
Author: abroekhuis
Date: Mon Jul 11 08:26:52 2011
New Revision: 1145065
URL: http://svn.apache.org/viewvc?rev=1145065&view=rev
Log:
#CELIX-8: applied patch with APR usage updates
Added:
incubator/celix/trunk/celix_test/linked_list_test.c (with props)
Removed:
incubator/celix/trunk/celix_test/test.c
Modified:
incubator/celix/trunk/celix_test/CMakeLists.txt
incubator/celix/trunk/dependency_manager/service_component.c
incubator/celix/trunk/dependency_manager/service_component_private.h
incubator/celix/trunk/framework/private/include/attribute.h
incubator/celix/trunk/framework/private/include/manifest_parser.h
incubator/celix/trunk/framework/private/src/attribute.c
incubator/celix/trunk/framework/private/src/bundle_archive.c
incubator/celix/trunk/framework/private/src/framework.c
incubator/celix/trunk/framework/private/src/manifest_parser.c
incubator/celix/trunk/framework/private/src/module.c
incubator/celix/trunk/framework/private/src/resolver.c
incubator/celix/trunk/launcher/launcher.c
incubator/celix/trunk/log_service/private/include/log.h
incubator/celix/trunk/log_service/private/include/log_reader_service_impl.h
incubator/celix/trunk/log_service/private/src/log.c
incubator/celix/trunk/log_service/private/src/log_reader_service_impl.c
incubator/celix/trunk/log_service/public/include/log_reader_service.h
incubator/celix/trunk/log_writer/log_writer.c
incubator/celix/trunk/shell/log_command.c
incubator/celix/trunk/target.cmake
incubator/celix/trunk/utils/CMakeLists.txt
incubator/celix/trunk/utils/private/include/linked_list_private.h
incubator/celix/trunk/utils/private/src/linkedlist.c
incubator/celix/trunk/utils/public/include/linkedlist.h
Modified: incubator/celix/trunk/celix_test/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix_test/CMakeLists.txt?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/celix_test/CMakeLists.txt (original)
+++ incubator/celix/trunk/celix_test/CMakeLists.txt Mon Jul 11 08:26:52 2011
@@ -30,6 +30,9 @@ target_link_libraries(hash_map_test_hash
add_executable(array_list_test array_list_test.c)
target_link_libraries(array_list_test utils ${CUNIT_LIBRARIES})
+add_executable(linked_list_test linked_list_test.c)
+target_link_libraries(linked_list_test utils ${CUNIT_LIBRARIES})
+
#add_executable(framework_test framework_test.c)
#target_link_libraries(framework_test utils ${CUNIT_LIBRARIES})
@@ -38,4 +41,5 @@ enable_testing()
add_test (hash_map_test ${EXECUTABLE_OUTPUT_PATH}/hash_map_test)
add_test (hash_map_test_hash ${EXECUTABLE_OUTPUT_PATH}/hash_map_test_hash)
add_test (array_list_test ${EXECUTABLE_OUTPUT_PATH}/array_list_test)
+add_test (linked_list_test ${EXECUTABLE_OUTPUT_PATH}/linked_list_test)
#add_test (framework_test ${EXECUTABLE_OUTPUT_PATH}/framework_test)
\ No newline at end of file
Added: incubator/celix/trunk/celix_test/linked_list_test.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix_test/linked_list_test.c?rev=1145065&view=auto
==============================================================================
--- incubator/celix/trunk/celix_test/linked_list_test.c (added)
+++ incubator/celix/trunk/celix_test/linked_list_test.c Mon Jul 11 08:26:52 2011
@@ -0,0 +1,101 @@
+/**
+ *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.
+ */
+/*
+ * linked_list_test.c
+ *
+ * Created on: Jul 16, 2010
+ * Author: alexanderb
+ */
+#include <stdio.h>
+#include <apr_pools.h>
+
+#include "Basic.h"
+#include "linkedlist.h"
+
+apr_pool_t *memory_pool;
+LINKED_LIST list;
+
+int setup(void) {
+ apr_initialize();
+ apr_pool_create(&memory_pool, NULL);
+
+ linkedList_create(memory_pool, &list);
+ if (list) {
+ return 0;
+ } else {
+ // failure during setup
+ return 1;
+ }
+}
+
+int teardown(void) {
+ apr_pool_destroy(memory_pool);
+ apr_terminate();
+ return 0;
+}
+
+void test_linkedList_create(void) {
+ CU_ASSERT_PTR_NOT_NULL_FATAL(list);
+ CU_ASSERT_EQUAL(linkedList_size(list), 0);
+}
+
+void test_linkedList_add(void) {
+ CU_ASSERT_EQUAL(linkedList_size(list), 0);
+ linkedList_addElement(list, "element");
+ CU_ASSERT_EQUAL(linkedList_size(list), 1);
+}
+
+void test_linkedList_remove(void) {
+ CU_ASSERT_EQUAL(linkedList_size(list), 0);
+ linkedList_addElement(list, "element");
+ CU_ASSERT_EQUAL(linkedList_size(list), 1);
+
+ linkedList_removeElement(list, "element");
+ CU_ASSERT_EQUAL(linkedList_size(list), 0);
+}
+
+int main (int argc, char** argv) {
+ CU_pSuite pSuite = NULL;
+
+ /* initialize the CUnit test registry */
+ if (CUE_SUCCESS != CU_initialize_registry())
+ return CU_get_error();
+
+ /* add a suite to the registry */
+ pSuite = CU_add_suite("Suite_1", setup, teardown);
+ if (NULL == pSuite) {
+ CU_cleanup_registry();
+ return CU_get_error();
+ }
+
+ /* add the tests to the suite */
+ if (NULL == CU_add_test(pSuite, "List Creation Test", test_linkedList_create) ||
+ NULL == CU_add_test(pSuite, "List Add Test", test_linkedList_add) ||
+ NULL == CU_add_test(pSuite, "List Remove Test", test_linkedList_remove))
+ {
+ CU_cleanup_registry();
+ return CU_get_error();
+ }
+
+ /* Run all tests using the CUnit Basic interface */
+ CU_basic_set_mode(CU_BRM_VERBOSE);
+ CU_basic_run_tests();
+ CU_cleanup_registry();
+ return CU_get_error();
+}
Propchange: incubator/celix/trunk/celix_test/linked_list_test.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/celix/trunk/dependency_manager/service_component.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/dependency_manager/service_component.c?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/dependency_manager/service_component.c (original)
+++ incubator/celix/trunk/dependency_manager/service_component.c Mon Jul 11 08:26:52 2011
@@ -59,24 +59,33 @@ struct executor {
};
SERVICE serviceComponent_create(BUNDLE_CONTEXT context, DEPENDENCY_MANAGER manager) {
- SERVICE service = (SERVICE) malloc(sizeof(*service));
+ SERVICE service;
+ apr_pool_t *pool;
- service->impl = NULL;
- service->serviceName = NULL;
- service->serviceRegistration = NULL;
- service->dependencies = arrayList_create();
-
- service->init = service_init;
- service->start= service_start;
- service->stop = service_stop;
- service->destroy = service_destroy;
-
- service->context = context;
- service->manager = manager;
- service->state = state_create(arrayList_clone(service->dependencies), false);
- service->executor = executor_create();
+ bundleContext_getMemoryPool(context, &pool);
- pthread_mutex_init(&service->mutex, NULL);
+ apr_pool_t *mypool;
+ apr_pool_create(&mypool, pool);
+
+ if (mypool) {
+ service = (SERVICE) apr_pcalloc(mypool, sizeof(*service));
+ service->impl = NULL;
+ service->serviceName = NULL;
+ service->serviceRegistration = NULL;
+ service->dependencies = arrayList_create();
+
+ service->init = service_init;
+ service->start= service_start;
+ service->stop = service_stop;
+ service->destroy = service_destroy;
+
+ service->context = context;
+ service->manager = manager;
+ service->state = state_create(arrayList_clone(service->dependencies), false);
+ service->executor = executor_create(mypool);
+
+ pthread_mutex_init(&service->mutex, NULL);
+ }
return service;
}
@@ -398,11 +407,16 @@ ARRAY_LIST state_getDependencies(STATE s
return state->dependencies;
}
-EXECUTOR executor_create() {
- EXECUTOR executor = (EXECUTOR) malloc(sizeof(*executor));
- executor->workQueue = linkedList_create();
- executor->active = NULL;
- pthread_mutex_init(&executor->mutex, NULL);
+EXECUTOR executor_create(apr_pool_t *memory_pool) {
+ EXECUTOR executor;
+
+ executor = (EXECUTOR) apr_pcalloc(memory_pool, sizeof(*executor));
+ if (executor) {
+ linkedList_create(memory_pool, &executor->workQueue);
+ executor->active = NULL;
+ pthread_mutex_init(&executor->mutex, NULL);
+ }
+
return executor;
}
Modified: incubator/celix/trunk/dependency_manager/service_component_private.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/dependency_manager/service_component_private.h?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/dependency_manager/service_component_private.h (original)
+++ incubator/celix/trunk/dependency_manager/service_component_private.h Mon Jul 11 08:26:52 2011
@@ -92,7 +92,7 @@ bool state_isWaitingForRequired(STATE st
bool state_isTrackingOptional(STATE state);
ARRAY_LIST state_getDependencies(STATE state);
-EXECUTOR executor_create();
+EXECUTOR executor_create(apr_pool_t *memory_pool);
void executor_enqueue(EXECUTOR executor, SERVICE service, void (*function), void * argument);
void executor_execute(EXECUTOR executor);
void executor_scheduleNext(EXECUTOR executor);
Modified: incubator/celix/trunk/framework/private/include/attribute.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/attribute.h?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/attribute.h (original)
+++ incubator/celix/trunk/framework/private/include/attribute.h Mon Jul 11 08:26:52 2011
@@ -26,6 +26,9 @@
#ifndef ATTRIBUTE_H_
#define ATTRIBUTE_H_
+#include <apr_general.h>
+#include "celix_errno.h"
+
struct attribute {
char * key;
char * value;
@@ -33,7 +36,7 @@ struct attribute {
typedef struct attribute * ATTRIBUTE;
-ATTRIBUTE attribute_create(char * key, char * value);
+celix_status_t attribute_create(char * key, char * value, apr_pool_t *memory_pool, ATTRIBUTE *attribute);
void attribute_destroy(ATTRIBUTE attribute);
Modified: incubator/celix/trunk/framework/private/include/manifest_parser.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/manifest_parser.h?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/manifest_parser.h (original)
+++ incubator/celix/trunk/framework/private/include/manifest_parser.h Mon Jul 11 08:26:52 2011
@@ -43,13 +43,6 @@ struct manifestParser {
typedef struct manifestParser * MANIFEST_PARSER;
-MANIFEST_PARSER manifestParser_createManifestParser(MODULE owner, MANIFEST manifest);
-celix_status_t manifestParser_destroy(MANIFEST_PARSER parser);
-
-LINKED_LIST manifestParser_parseImportHeader(char * header);
-LINKED_LIST manifestParser_parseExportHeader(MODULE module, char * header);
-LINKED_LIST manifestParser_parseDelimitedString(char * value, char * delim);
-LINKED_LIST manifestParser_parseStandardHeaderClause(char * clauseString);
-LINKED_LIST manifestParser_parseStandardHeader(char * header);
+celix_status_t manifestParser_create(MODULE owner, MANIFEST manifest, apr_pool_t *memory_pool, MANIFEST_PARSER *manifest_parser);
#endif /* MANIFEST_PARSER_H_ */
Modified: incubator/celix/trunk/framework/private/src/attribute.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/attribute.c?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/attribute.c (original)
+++ incubator/celix/trunk/framework/private/src/attribute.c Mon Jul 11 08:26:52 2011
@@ -27,15 +27,22 @@
#include "attribute.h"
-ATTRIBUTE attribute_create(char * key, char * value) {
- ATTRIBUTE attribute = malloc(sizeof(*attribute));
- attribute->key = key;
- attribute->value = value;
- return attribute;
+celix_status_t attribute_create(char * key, char * value, apr_pool_t *memory_pool, ATTRIBUTE *attribute) {
+ ATTRIBUTE attr = apr_palloc(memory_pool, sizeof(*attr));
+ if (attr) {
+ attr->key = key;
+ attr->value = value;
+
+ *attribute = attr;
+
+ return CELIX_SUCCESS;
+ } else {
+ return CELIX_ENOMEM;
+ }
}
void attribute_destroy(ATTRIBUTE attribute) {
- free(attribute->key);
- free(attribute->value);
- free(attribute);
+ //free(attribute->key);
+ //free(attribute->value);
+ //free(attribute);
}
Modified: incubator/celix/trunk/framework/private/src/bundle_archive.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle_archive.c?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_archive.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_archive.c Mon Jul 11 08:26:52 2011
@@ -52,6 +52,7 @@ struct bundleArchive {
celix_status_t bundleArchive_createSystemBundleArchive(apr_pool_t *mp, BUNDLE_ARCHIVE *bundle_archive) {
celix_status_t status;
BUNDLE_ARCHIVE archive;
+ apr_pool_t *revisions_pool;
if (!mp || *bundle_archive) {
status = CELIX_ILLEGAL_ARGUMENT;
@@ -60,17 +61,25 @@ celix_status_t bundleArchive_createSyste
if (archive == NULL) {
status = CELIX_ENOMEM;
} else {
- archive->id = 0l;
- archive->location = "System Bundle";
- archive->mp = mp;
- archive->archiveRoot = NULL;
- archive->archiveRootDir = NULL;
- archive->revisions = linkedList_create();
- archive->refreshCount = -1;
- time(&archive->lastModified);
-
- *bundle_archive = archive;
- status = CELIX_SUCCESS;
+ if (apr_pool_create(&revisions_pool, mp) == APR_SUCCESS) {
+ if (linkedList_create(revisions_pool, &archive->revisions) == CELIX_SUCCESS) {
+ archive->id = 0l;
+ archive->location = "System Bundle";
+ archive->mp = mp;
+ archive->archiveRoot = NULL;
+ archive->archiveRootDir = NULL;
+ archive->refreshCount = -1;
+ time(&archive->lastModified);
+
+ *bundle_archive = archive;
+ status = CELIX_SUCCESS;
+ } else {
+ status = CELIX_ENOMEM;
+ apr_pool_destroy(revisions_pool);
+ }
+ } else {
+ status = CELIX_ENOMEM;
+ }
}
}
@@ -91,26 +100,34 @@ time_t bundleArchive_readLastModified(BU
void bundleArchive_writeLastModified(BUNDLE_ARCHIVE archive);
celix_status_t bundleArchive_create(char * archiveRoot, long id, char * location, apr_pool_t *mp, BUNDLE_ARCHIVE *bundle_archive) {
- celix_status_t status = CELIX_SUCCESS;
+ apr_pool_t *revisions_pool;
+ celix_status_t status;
+ BUNDLE_ARCHIVE archive;
- BUNDLE_ARCHIVE archive = NULL;
+ status = CELIX_SUCCESS;
archive = (BUNDLE_ARCHIVE) apr_pcalloc(mp, sizeof(*archive));
if (archive != NULL) {
- archive->id = id;
- archive->location = location;
- archive->archiveRootDir = NULL;
- archive->archiveRoot = archiveRoot;
- archive->revisions = linkedList_create();
- archive->refreshCount = -1;
- time(&archive->lastModified);
+ if (apr_pool_create(&revisions_pool, mp) == APR_SUCCESS) {
+ if (linkedList_create(revisions_pool, &archive->revisions) == CELIX_SUCCESS) {
+ archive->id = id;
+ archive->location = location;
+ archive->archiveRootDir = NULL;
+ archive->archiveRoot = archiveRoot;
+ archive->refreshCount = -1;
+ time(&archive->lastModified);
- archive->mp = mp;
+ archive->mp = mp;
- bundleArchive_initialize(archive);
+ bundleArchive_initialize(archive);
- bundleArchive_revise(archive, location, NULL);
+ bundleArchive_revise(archive, location, NULL);
- *bundle_archive = archive;
+ *bundle_archive = archive;
+ } else {
+ apr_pool_destroy(revisions_pool);
+ status = CELIX_ENOMEM;
+ }
+ }
} else {
status = CELIX_ENOMEM;
}
@@ -130,7 +147,6 @@ celix_status_t bundleArchive_destroy(BUN
bundleRevision_destroy(revision);
}
linkedListIterator_destroy(iter);
- linkedList_destroy(archive->revisions);
}
archive = NULL;
@@ -138,40 +154,52 @@ celix_status_t bundleArchive_destroy(BUN
}
celix_status_t bundleArchive_recreate(char * archiveRoot, apr_pool_t *mp, BUNDLE_ARCHIVE *bundle_archive) {
- celix_status_t status = CELIX_SUCCESS;
- BUNDLE_ARCHIVE archive = NULL;
+ apr_pool_t *revisions_pool;
+ celix_status_t status;
+ BUNDLE_ARCHIVE archive;
+
+ status = CELIX_SUCCESS;
archive = (BUNDLE_ARCHIVE) apr_pcalloc(mp, sizeof(*archive));
if (archive != NULL) {
- archive->archiveRoot = archiveRoot;
- apr_dir_open(&archive->archiveRootDir, archiveRoot, mp);
- archive->id = -1;
- archive->persistentState = -1;
- archive->location = NULL;
- archive->revisions = linkedList_create();
- archive->mp = mp;
- archive->refreshCount = -1;
- archive->lastModified = (time_t) NULL;
-
- apr_dir_t *dir;
- if (apr_dir_open(&dir, archiveRoot, mp) == APR_SUCCESS) {
- apr_finfo_t dp;
- while ((apr_dir_read(&dp, APR_FINFO_DIRENT|APR_FINFO_TYPE, dir)) == APR_SUCCESS) {
- if (dp.filetype == APR_DIR && (strncmp(dp.name, "version", 7) == 0)) {
- long idx;
- sscanf(dp.name, "version%*d.%ld", &idx);
+ if (apr_pool_create(&revisions_pool, mp) == APR_SUCCESS) {
+ if (linkedList_create(revisions_pool, &archive->revisions) == CELIX_SUCCESS) {
+ archive->archiveRoot = archiveRoot;
+ apr_dir_open(&archive->archiveRootDir, archiveRoot, mp);
+ archive->id = -1;
+ archive->persistentState = -1;
+ archive->location = NULL;
+ archive->mp = mp;
+ archive->refreshCount = -1;
+ archive->lastModified = (time_t) NULL;
+
+ apr_dir_t *dir;
+ if (apr_dir_open(&dir, archiveRoot, mp) == APR_SUCCESS) {
+ apr_finfo_t dp;
+ while ((apr_dir_read(&dp, APR_FINFO_DIRENT|APR_FINFO_TYPE, dir)) == APR_SUCCESS) {
+ if (dp.filetype == APR_DIR && (strncmp(dp.name, "version", 7) == 0)) {
+ long idx;
+ sscanf(dp.name, "version%*d.%ld", &idx);
+ }
+ }
+
+ char *location;
+ status = bundleArchive_getRevisionLocation(archive, 0, &location);
+ if (status == CELIX_SUCCESS) {
+ bundleArchive_revise(archive, location, NULL);
+
+ *bundle_archive = archive;
+ }
+ } else {
+ apr_pool_destroy(revisions_pool);
+ status = CELIX_FILE_IO_EXCEPTION;
}
- }
-
- char *location;
- status = bundleArchive_getRevisionLocation(archive, 0, &location);
- if (status == CELIX_SUCCESS) {
- bundleArchive_revise(archive, location, NULL);
-
- *bundle_archive = archive;
- }
- } else {
- status = CELIX_FILE_IO_EXCEPTION;
- }
+ } else {
+ apr_pool_destroy(revisions_pool);
+ status = CELIX_ENOMEM;
+ }
+ } else {
+ status = CELIX_ENOMEM;
+ }
} else {
status = CELIX_ENOMEM;
}
Modified: incubator/celix/trunk/framework/private/src/framework.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/framework.c?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/framework.c (original)
+++ incubator/celix/trunk/framework/private/src/framework.c Mon Jul 11 08:26:52 2011
@@ -185,7 +185,6 @@ celix_status_t framework_destroy(FRAMEWO
wire_destroy(wire);
}
linkedListIterator_destroy(iter);
- linkedList_destroy(wires);
}
bundleArchive_destroy(bundle->archive);
Modified: incubator/celix/trunk/framework/private/src/manifest_parser.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/manifest_parser.c?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/manifest_parser.c (original)
+++ incubator/celix/trunk/framework/private/src/manifest_parser.c Mon Jul 11 08:26:52 2011
@@ -24,6 +24,7 @@
*/
#include <stdlib.h>
#include <string.h>
+#include <apr_strings.h>
#include "utils.h"
#include "constants.h"
@@ -35,273 +36,313 @@
#include "celix_errno.h"
#include "linked_list_iterator.h"
-MANIFEST_PARSER manifestParser_createManifestParser(MODULE owner, MANIFEST manifest) {
- MANIFEST_PARSER parser = (MANIFEST_PARSER) malloc(sizeof(*parser));
- parser->manifest = manifest;
- parser->owner = owner;
-
- char * bundleVersion = manifest_getValue(manifest, BUNDLE_VERSION);
- if (bundleVersion != NULL) {
- parser->bundleVersion = version_createVersionFromString(bundleVersion);
- } else {
- parser->bundleVersion = version_createEmptyVersion();
- }
- char * bundleSymbolicName = manifest_getValue(manifest, BUNDLE_SYMBOLICNAME);
- if (bundleSymbolicName != NULL) {
- parser->bundleSymbolicName = bundleSymbolicName;
- }
+static LINKED_LIST manifestParser_parseImportHeader(char * header, apr_pool_t *memory_pool);
+static LINKED_LIST manifestParser_parseExportHeader(MODULE module, char * header, apr_pool_t *memory_pool);
+static LINKED_LIST manifestParser_parseDelimitedString(char * value, char * delim, apr_pool_t *memory_pool);
+static LINKED_LIST manifestParser_parseStandardHeaderClause(char * clauseString, apr_pool_t *memory_pool);
+static LINKED_LIST manifestParser_parseStandardHeader(char * header, apr_pool_t *memory_pool);
+
+celix_status_t manifestParser_create(MODULE owner, MANIFEST manifest, apr_pool_t *memory_pool, MANIFEST_PARSER *manifest_parser) {
+ celix_status_t status;
+ MANIFEST_PARSER parser;
+
+ status = CELIX_SUCCESS;
+ parser = (MANIFEST_PARSER) apr_pcalloc(memory_pool, sizeof(*parser));
+ if (parser) {
+ parser->manifest = manifest;
+ parser->owner = owner;
+
+ char * bundleVersion = manifest_getValue(manifest, BUNDLE_VERSION);
+ if (bundleVersion != NULL) {
+ parser->bundleVersion = version_createVersionFromString(bundleVersion);
+ } else {
+ parser->bundleVersion = version_createEmptyVersion();
+ }
+ char * bundleSymbolicName = manifest_getValue(manifest, BUNDLE_SYMBOLICNAME);
+ if (bundleSymbolicName != NULL) {
+ parser->bundleSymbolicName = bundleSymbolicName;
+ }
- parser->capabilities = manifestParser_parseExportHeader(owner, manifest_getValue(manifest, EXPORT_PACKAGE));
- parser->requirements = manifestParser_parseImportHeader(manifest_getValue(manifest, IMPORT_PACKAGE));
- return parser;
-}
-
-celix_status_t manifestParser_destroy(MANIFEST_PARSER parser) {
-// version_destroy(parser->bundleVersion);
- parser->bundleSymbolicName = NULL;
- parser->bundleVersion = NULL;
- parser->owner = NULL;
- parser->capabilities = NULL;
- parser->manifest = NULL;
- parser->requirements = NULL;
- free(parser);
- return CELIX_SUCCESS;
-}
+ parser->capabilities = manifestParser_parseExportHeader(owner, manifest_getValue(manifest, EXPORT_PACKAGE), memory_pool);
+ parser->requirements = manifestParser_parseImportHeader(manifest_getValue(manifest, IMPORT_PACKAGE), memory_pool);
-LINKED_LIST manifestParser_parseDelimitedString(char * value, char * delim) {
- if (value == NULL) {
- value = strdup("");
- }
+ *manifest_parser = parser;
- LINKED_LIST list = linkedList_create();
- int CHAR = 1;
- int DELIMITER = 2;
- int STARTQUOTE = 4;
- int ENDQUOTE = 8;
-
- char * buffer = malloc(sizeof(char) * 512);
- buffer[0] = '\0';
-
- int expecting = (CHAR | DELIMITER | STARTQUOTE);
-
- int i;
- for (i = 0; i < strlen(value); i++) {
- char c = value[i];
-
- bool isDelimiter = (strchr(delim, c) != NULL);
- bool isQuote = (c == '"');
-
- if (isDelimiter && ((expecting & DELIMITER) > 0)) {
- linkedList_addElement(list, strdup(buffer));
- free(buffer);
- buffer = malloc(sizeof(char) * 512);
- buffer[0] = '\0';
- expecting = (CHAR | DELIMITER | STARTQUOTE);
- } else if (isQuote && ((expecting & STARTQUOTE) > 0)) {
- char tmp[2];
- tmp[0] = c;
- tmp[1] = '\0';
- strcat(buffer, tmp);
- expecting = CHAR | ENDQUOTE;
- } else if (isQuote && ((expecting & ENDQUOTE) > 0)) {
- char tmp[2];
- tmp[0] = c;
- tmp[1] = '\0';
- strcat(buffer, tmp);
- expecting = (CHAR | STARTQUOTE | DELIMITER);
- } else if ((expecting & CHAR) > 0) {
- char tmp[2];
- tmp[0] = c;
- tmp[1] = '\0';
- strcat(buffer, tmp);
- } else {
- return NULL;
- }
+ status = CELIX_SUCCESS;
+ } else {
+ status = CELIX_ENOMEM;
}
- free(value);
+ return status;
+}
- if (strlen(buffer) > 0) {
- linkedList_addElement(list, strdup(buffer));
- }
- free(buffer);
+static LINKED_LIST manifestParser_parseDelimitedString(char * value, char * delim, apr_pool_t *memory_pool) {
+ LINKED_LIST list;
+ apr_pool_t *temp_pool;
+
+ if (linkedList_create(memory_pool, &list) == CELIX_SUCCESS) {
+ if (value != NULL) {
+ if (apr_pool_create(&temp_pool, NULL) == APR_SUCCESS) {
+ int CHAR = 1;
+ int DELIMITER = 2;
+ int STARTQUOTE = 4;
+ int ENDQUOTE = 8;
+
+ char * buffer = (char *) apr_pcalloc(temp_pool, sizeof(char) * 512);
+ if (buffer != NULL) {
+ buffer[0] = '\0';
+
+ int expecting = (CHAR | DELIMITER | STARTQUOTE);
+
+ int i;
+ for (i = 0; i < strlen(value); i++) {
+ char c = value[i];
+
+ bool isDelimiter = (strchr(delim, c) != NULL);
+ bool isQuote = (c == '"');
+
+ if (isDelimiter && ((expecting & DELIMITER) > 0)) {
+ linkedList_addElement(list, apr_pstrdup(memory_pool, buffer));
+ buffer[0] = '\0';
+ expecting = (CHAR | DELIMITER | STARTQUOTE);
+ } else if (isQuote && ((expecting & STARTQUOTE) > 0)) {
+ char tmp[2];
+ tmp[0] = c;
+ tmp[1] = '\0';
+ strcat(buffer, tmp);
+ expecting = CHAR | ENDQUOTE;
+ } else if (isQuote && ((expecting & ENDQUOTE) > 0)) {
+ char tmp[2];
+ tmp[0] = c;
+ tmp[1] = '\0';
+ strcat(buffer, tmp);
+ expecting = (CHAR | STARTQUOTE | DELIMITER);
+ } else if ((expecting & CHAR) > 0) {
+ char tmp[2];
+ tmp[0] = c;
+ tmp[1] = '\0';
+ strcat(buffer, tmp);
+ } else {
+ apr_pool_destroy(temp_pool);
+ return NULL;
+ }
+ }
+
+ if (strlen(buffer) > 0) {
+ linkedList_addElement(list, apr_pstrdup(memory_pool, buffer));
+ }
+ }
+
+ if (temp_pool) {
+ apr_pool_destroy(temp_pool);
+ }
+ }
+ }
+ }
return list;
}
-LINKED_LIST manifestParser_parseStandardHeaderClause(char * clauseString) {
- LINKED_LIST pieces = manifestParser_parseDelimitedString(clauseString, ";");
-
- LINKED_LIST paths = linkedList_create();
- int pathCount = 0;
- int pieceIdx;
- for (pieceIdx = 0; pieceIdx < linkedList_size(pieces); pieceIdx++) {
- char * piece = linkedList_get(pieces, pieceIdx);
- if (strchr(piece, '=') != NULL) {
- break;
- } else {
- linkedList_addElement(paths, piece);
- pathCount++;
- }
- }
-
- if (pathCount == 0) {
- return NULL;
- }
-
- HASH_MAP dirsMap = hashMap_create(string_hash, NULL, string_equals, NULL);
- HASH_MAP attrsMap = hashMap_create(string_hash, NULL, string_equals, NULL);
-
- char * sepPtr;
- char * sep;
- for (pieceIdx = pathCount; pieceIdx < linkedList_size(pieces); pieceIdx++) {
- char * DIRECTIVE_SEP = ":=";
- char * ATTRIBUTE_SEP = "=";
- char * piece = linkedList_get(pieces, pieceIdx);
- if ((sepPtr = strstr(piece, DIRECTIVE_SEP)) != NULL) {
- sep = DIRECTIVE_SEP;
- } else if ((sepPtr = strstr(piece, ATTRIBUTE_SEP)) != NULL) {
- sep = ATTRIBUTE_SEP;
- } else {
- return NULL;
- }
-
- char * key = string_ndup(piece, sepPtr - piece);
- char * value = strdup(sepPtr+strlen(sep));
-
- if (value[0] == '"' && value[strlen(value) -1] == '"') {
- char * oldV = strdup(value);
- free(value);
- int len = strlen(oldV) - 2;
- value = (char *) malloc(sizeof(char) * len+1);
- value[0] = '\0';
- value = strncpy(value, oldV+1, strlen(oldV) - 2);
- value[len] = '\0';
- }
-
- if (strcmp(sep, DIRECTIVE_SEP) == 0) {
- // Not implemented
- } else {
- if (hashMap_containsKey(attrsMap, key)) {
- return NULL;
- }
- ATTRIBUTE attr = attribute_create(key, value);
- hashMap_put(attrsMap, key, attr);
- }
- }
-
- linkedList_destroy(pieces);
-
- LINKED_LIST clause = linkedList_create();
- linkedList_addElement(clause, paths);
- linkedList_addElement(clause, dirsMap);
- linkedList_addElement(clause, attrsMap);
+static LINKED_LIST manifestParser_parseStandardHeaderClause(char * clauseString, apr_pool_t *memory_pool) {
+ LINKED_LIST paths;
+ apr_pool_t *temp_pool;
+ LINKED_LIST clause;
+ LINKED_LIST pieces;
+
+ clause = NULL;
+ pieces = NULL;
+ if (apr_pool_create(&temp_pool, memory_pool) == APR_SUCCESS) {
+ pieces = manifestParser_parseDelimitedString(clauseString, ";", temp_pool);
+
+ if (linkedList_create(memory_pool, &paths) == CELIX_SUCCESS) {
+ int pathCount = 0;
+ int pieceIdx;
+ for (pieceIdx = 0; pieceIdx < linkedList_size(pieces); pieceIdx++) {
+ char * piece = linkedList_get(pieces, pieceIdx);
+ if (strchr(piece, '=') != NULL) {
+ break;
+ } else {
+ linkedList_addElement(paths, apr_pstrdup(memory_pool, piece));
+ pathCount++;
+ }
+ }
+
+ if (pathCount == 0) {
+ return NULL;
+ }
+
+ HASH_MAP dirsMap = hashMap_create(string_hash, NULL, string_equals, NULL);
+ HASH_MAP attrsMap = hashMap_create(string_hash, NULL, string_equals, NULL);
+
+ char * sepPtr;
+ char * sep;
+ for (pieceIdx = pathCount; pieceIdx < linkedList_size(pieces); pieceIdx++) {
+ char * DIRECTIVE_SEP = ":=";
+ char * ATTRIBUTE_SEP = "=";
+ char * piece = linkedList_get(pieces, pieceIdx);
+ if ((sepPtr = strstr(piece, DIRECTIVE_SEP)) != NULL) {
+ sep = DIRECTIVE_SEP;
+ } else if ((sepPtr = strstr(piece, ATTRIBUTE_SEP)) != NULL) {
+ sep = ATTRIBUTE_SEP;
+ } else {
+ return NULL;
+ }
+
+ char * key = string_ndup(piece, sepPtr - piece);
+ char * value = apr_pstrdup(temp_pool, sepPtr+strlen(sep));
+
+ if (value[0] == '"' && value[strlen(value) -1] == '"') {
+ char * oldV = apr_pstrdup(memory_pool, value);
+ int len = strlen(oldV) - 2;
+ value = (char *) apr_pcalloc(memory_pool, sizeof(char) * len+1);
+ value[0] = '\0';
+ value = strncpy(value, oldV+1, strlen(oldV) - 2);
+ value[len] = '\0';
+ }
+
+ if (strcmp(sep, DIRECTIVE_SEP) == 0) {
+ // Not implemented
+ } else {
+ if (hashMap_containsKey(attrsMap, key)) {
+ return NULL;
+ }
+ ATTRIBUTE attr = NULL;
+ if (attribute_create(key, value, memory_pool, &attr) == CELIX_SUCCESS) {
+ hashMap_put(attrsMap, key, attr);
+ }
+ }
+ }
+
+ if (linkedList_create(memory_pool, &clause) == CELIX_SUCCESS) {
+ linkedList_addElement(clause, paths);
+ linkedList_addElement(clause, dirsMap);
+ linkedList_addElement(clause, attrsMap);
+ }
+ }
+ }
+
+ if (temp_pool != NULL) {
+ apr_pool_destroy(temp_pool);
+ }
return clause;
}
-LINKED_LIST manifestParser_parseStandardHeader(char * header) {
- LINKED_LIST completeList = linkedList_create();
- if (header != NULL) {
- if (strlen(header) == 0) {
- return NULL;
- }
-
- LINKED_LIST clauseStrings = manifestParser_parseDelimitedString(strdup(header), ",");
- int i;
- for (i = 0; (clauseStrings != NULL) && (i < linkedList_size(clauseStrings)); i++) {
- char * clauseString = (char *) linkedList_get(clauseStrings, i);
- linkedList_addElement(completeList, manifestParser_parseStandardHeaderClause(clauseString));
+static LINKED_LIST manifestParser_parseStandardHeader(char * header, apr_pool_t *memory_pool) {
+ int i;
+ char *clauseString;
+ LINKED_LIST clauseStrings = NULL;
+ LINKED_LIST completeList = NULL;
+
+ if (linkedList_create(memory_pool, &completeList) == CELIX_SUCCESS) {
+ if (header != NULL) {
+ if (strlen(header) == 0) {
+ return NULL;
+ }
+
+ clauseStrings = manifestParser_parseDelimitedString(apr_pstrdup(memory_pool, header), ",", memory_pool);
+ if (clauseStrings != NULL) {
+ for (i = 0; i < linkedList_size(clauseStrings); i++) {
+ clauseString = (char *) linkedList_get(clauseStrings, i);
+ linkedList_addElement(completeList, manifestParser_parseStandardHeaderClause(clauseString, memory_pool));
+ }
+ }
}
- linkedList_destroy(clauseStrings);
- return completeList;
}
+
return completeList;
}
-LINKED_LIST manifestParser_parseImportHeader(char * header) {
- LINKED_LIST clauses = manifestParser_parseStandardHeader(header);
- LINKED_LIST requirements = linkedList_create();
-
- int clauseIdx;
- for (clauseIdx = 0; clauseIdx < linkedList_size(clauses); clauseIdx++) {
- LINKED_LIST clause = linkedList_get(clauses, clauseIdx);
-
- LINKED_LIST paths = linkedList_get(clause, 0);
- HASH_MAP directives = linkedList_get(clause, 1);
- HASH_MAP attributes = linkedList_get(clause, 2);
-
- int pathIdx;
- for (pathIdx = 0; pathIdx < linkedList_size(paths); pathIdx++) {
- char * path = (char *) linkedList_get(paths, pathIdx);
- if (strlen(path) == 0) {
- return NULL;
- }
-
- ATTRIBUTE name = attribute_create(strdup("service"), path);
- hashMap_put(attributes, name->key, name);
-
- REQUIREMENT req = requirement_create(directives, attributes);
- linkedList_addElement(requirements, req);
- }
- }
-
- LINKED_LIST_ITERATOR iter = linkedListIterator_create(clauses, 0);
- while(linkedListIterator_hasNext(iter)) {
- LINKED_LIST clause = linkedListIterator_next(iter);
+static LINKED_LIST manifestParser_parseImportHeader(char * header, apr_pool_t *memory_pool) {
+ apr_pool_t *temp_pool;
+ LINKED_LIST clauses;
+ LINKED_LIST requirements;
+
+ if (apr_pool_create(&temp_pool, memory_pool) == APR_SUCCESS) {
+ clauses = manifestParser_parseStandardHeader(header, memory_pool);
+ linkedList_create(memory_pool, &requirements);
+
+ int clauseIdx;
+ for (clauseIdx = 0; clauseIdx < linkedList_size(clauses); clauseIdx++) {
+ LINKED_LIST clause = linkedList_get(clauses, clauseIdx);
+
+ LINKED_LIST paths = linkedList_get(clause, 0);
+ HASH_MAP directives = linkedList_get(clause, 1);
+ HASH_MAP attributes = linkedList_get(clause, 2);
+
+ int pathIdx;
+ for (pathIdx = 0; pathIdx < linkedList_size(paths); pathIdx++) {
+ char * path = (char *) linkedList_get(paths, pathIdx);
+ if (strlen(path) == 0) {
+ return NULL;
+ }
+
+ ATTRIBUTE name = NULL;
+ if (attribute_create(apr_pstrdup(memory_pool, "service"), path, memory_pool, &name) == CELIX_SUCCESS) {
+ hashMap_put(attributes, name->key, name);
+ }
+
+ REQUIREMENT req = requirement_create(directives, attributes);
+ linkedList_addElement(requirements, req);
+ }
+ }
+
+ LINKED_LIST_ITERATOR iter = linkedListIterator_create(clauses, 0);
+ while(linkedListIterator_hasNext(iter)) {
+ LINKED_LIST clause = linkedListIterator_next(iter);
+
+ LINKED_LIST paths = linkedList_get(clause, 0);
+
+ linkedListIterator_remove(iter);
+ }
+ linkedListIterator_destroy(iter);
- LINKED_LIST paths = linkedList_get(clause, 0);
-
- linkedList_destroy(paths);
-
- linkedListIterator_remove(iter);
- linkedList_destroy(clause);
- }
- linkedListIterator_destroy(iter);
- linkedList_destroy(clauses);
+ apr_pool_destroy(temp_pool);
+ }
return requirements;
}
-LINKED_LIST manifestParser_parseExportHeader(MODULE module, char * header) {
- LINKED_LIST clauses = manifestParser_parseStandardHeader(header);
- LINKED_LIST capabilities = linkedList_create();
-
- int clauseIdx;
- for (clauseIdx = 0; clauseIdx < linkedList_size(clauses); clauseIdx++) {
- LINKED_LIST clause = linkedList_get(clauses, clauseIdx);
-
- LINKED_LIST paths = linkedList_get(clause, 0);
- HASH_MAP directives = linkedList_get(clause, 1);
- HASH_MAP attributes = linkedList_get(clause, 2);
-
- int pathIdx;
- for (pathIdx = 0; pathIdx < linkedList_size(paths); pathIdx++) {
- char * path = (char *) linkedList_get(paths, pathIdx);
- if (strlen(path) == 0) {
- return NULL;
- }
-
- ATTRIBUTE name = attribute_create(strdup("service"), path);
- hashMap_put(attributes, name->key, name);
-
- CAPABILITY cap = capability_create(module, directives, attributes);
- linkedList_addElement(capabilities, cap);
- }
- }
- LINKED_LIST_ITERATOR iter = linkedListIterator_create(clauses, 0);
- while(linkedListIterator_hasNext(iter)) {
- LINKED_LIST clause = linkedListIterator_next(iter);
-
- LINKED_LIST paths = linkedList_get(clause, 0);
-
- linkedList_destroy(paths);
-
- linkedListIterator_remove(iter);
- linkedList_destroy(clause);
- }
- linkedListIterator_destroy(iter);
- linkedList_destroy(clauses);
+static LINKED_LIST manifestParser_parseExportHeader(MODULE module, char * header, apr_pool_t *memory_pool) {
+ LINKED_LIST clauses;
+ LINKED_LIST capabilities;
+
+ clauses = manifestParser_parseStandardHeader(header, memory_pool);
+ linkedList_create(memory_pool, &capabilities);
+
+ int clauseIdx;
+ for (clauseIdx = 0; clauseIdx < linkedList_size(clauses); clauseIdx++) {
+ LINKED_LIST clause = linkedList_get(clauses, clauseIdx);
+
+ LINKED_LIST paths = linkedList_get(clause, 0);
+ HASH_MAP directives = linkedList_get(clause, 1);
+ HASH_MAP attributes = linkedList_get(clause, 2);
+
+ int pathIdx;
+ for (pathIdx = 0; pathIdx < linkedList_size(paths); pathIdx++) {
+ char * path = (char *) linkedList_get(paths, pathIdx);
+ if (strlen(path) == 0) {
+ return NULL;
+ }
+
+ ATTRIBUTE name = NULL;
+ if (attribute_create(apr_pstrdup(memory_pool, "service"), path, memory_pool, &name) == CELIX_SUCCESS) {
+ hashMap_put(attributes, name->key, name);
+ }
+
+ CAPABILITY cap = capability_create(module, directives, attributes);
+ linkedList_addElement(capabilities, cap);
+ }
+ }
+ LINKED_LIST_ITERATOR iter = linkedListIterator_create(clauses, 0);
+ while(linkedListIterator_hasNext(iter)) {
+ LINKED_LIST clause = linkedListIterator_next(iter);
+
+ LINKED_LIST paths = linkedList_get(clause, 0);
+
+ linkedListIterator_remove(iter);
+ }
+ linkedListIterator_destroy(iter);
return capabilities;
}
Modified: incubator/celix/trunk/framework/private/src/module.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/module.c?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/module.c (original)
+++ incubator/celix/trunk/framework/private/src/module.c Mon Jul 11 08:26:52 2011
@@ -51,8 +51,15 @@ struct module {
};
MODULE module_create(MANIFEST headerMap, char * moduleId, BUNDLE bundle) {
+ MODULE module;
+ MANIFEST_PARSER mp;
+ apr_pool_t *pool;
+
+ module = NULL;
+ pool = NULL;
+
if (headerMap != NULL) {
- MODULE module = (MODULE) malloc(sizeof(*module));
+ module = (MODULE) apr_palloc(bundle->memoryPool, sizeof(*module));
module->headerMap = headerMap;
module->id = apr_pstrdup(bundle->memoryPool, moduleId);
module->bundle = bundle;
@@ -60,33 +67,47 @@ MODULE module_create(MANIFEST headerMap,
module->dependentImporters = arrayList_create();
- MANIFEST_PARSER mp = manifestParser_createManifestParser(module, headerMap);
- module->symbolicName = apr_pstrdup(bundle->memoryPool, mp->bundleSymbolicName);
- module->version = mp->bundleVersion;
- module->capabilities = mp->capabilities;
- module->requirements = mp->requirements;
- manifestParser_destroy(mp);
-
- module->wires = NULL;
-
- return module;
- } else {
- return NULL;
+ if (apr_pool_create(&pool, bundle->memoryPool) == APR_SUCCESS) {
+ if (manifestParser_create(module, headerMap, pool, &mp) == CELIX_SUCCESS) {
+ module->symbolicName = apr_pstrdup(bundle->memoryPool, mp->bundleSymbolicName);
+ module->version = mp->bundleVersion;
+ module->capabilities = mp->capabilities;
+ module->requirements = mp->requirements;
+ module->wires = NULL;
+ } else {
+ apr_pool_destroy(pool);
+ }
+ }
}
+
+ return module;
}
MODULE module_createFrameworkModule(BUNDLE bundle) {
- MODULE module = (MODULE) malloc(sizeof(*module));
- module->id = apr_pstrdup(bundle->memoryPool, "0");
- module->symbolicName = apr_pstrdup(bundle->memoryPool, "framework");
- module->version = version_createVersion(1, 0, 0, "");
- module->capabilities = linkedList_create();
- module->requirements = linkedList_create();
- module->dependentImporters = arrayList_create();
- module->wires = NULL;
- module->headerMap = NULL;
- module->resolved = false;
- module->bundle = NULL;
+ MODULE module;
+ apr_pool_t *capabilities_pool;
+ apr_pool_t *requirements_pool;
+ apr_pool_t *dependentImporters_pool;
+
+ module = (MODULE) apr_palloc(bundle->memoryPool, sizeof(*module));
+ if (module) {
+ if (apr_pool_create(&capabilities_pool, bundle->memoryPool) == APR_SUCCESS) {
+ if (apr_pool_create(&requirements_pool, bundle->memoryPool) == APR_SUCCESS) {
+ if (apr_pool_create(&dependentImporters_pool, bundle->memoryPool) == APR_SUCCESS) {
+ module->id = apr_pstrdup(bundle->memoryPool, "0");
+ module->symbolicName = apr_pstrdup(bundle->memoryPool, "framework");
+ module->version = version_createVersion(1, 0, 0, "");
+ linkedList_create(capabilities_pool, &module->capabilities);
+ linkedList_create(requirements_pool, &module->requirements);
+ module->dependentImporters = arrayList_create();
+ module->wires = NULL;
+ module->headerMap = NULL;
+ module->resolved = false;
+ module->bundle = bundle;
+ }
+ }
+ }
+ }
return module;
}
@@ -105,9 +126,6 @@ void module_destroy(MODULE module) {
}
linkedListIterator_destroy(reqIter);
- linkedList_destroy(module->capabilities);
- linkedList_destroy(module->requirements);
-
arrayList_destroy(module->dependentImporters);
version_destroy(module->version);
@@ -116,8 +134,6 @@ void module_destroy(MODULE module) {
manifest_destroy(module->headerMap);
}
module->headerMap = NULL;
-
- free(module);
}
WIRE module_getWire(MODULE module, char * serviceName) {
Modified: incubator/celix/trunk/framework/private/src/resolver.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/resolver.c?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/resolver.c (original)
+++ incubator/celix/trunk/framework/private/src/resolver.c Mon Jul 11 08:26:52 2011
@@ -25,6 +25,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <apr_strings.h>
#include "resolver.h"
#include "linked_list_iterator.h"
@@ -75,14 +76,10 @@ HASH_MAP resolver_resolve(MODULE root) {
LINKED_LIST_ITERATOR candSetIter = linkedListIterator_create(value, 0);
while (linkedListIterator_hasNext(candSetIter)) {
CANDIDATE_SET set = linkedListIterator_next(candSetIter);
- if (set->candidates != NULL) {
- linkedList_destroy(set->candidates);
- }
free(set);
linkedListIterator_remove(candSetIter);
}
linkedListIterator_destroy(candSetIter);
- linkedList_destroy(value);
}
}
hashMapIterator_destroy(iter);
@@ -102,13 +99,9 @@ HASH_MAP resolver_resolve(MODULE root) {
LINKED_LIST_ITERATOR candSetIter = linkedListIterator_create(value, 0);
while (linkedListIterator_hasNext(candSetIter)) {
CANDIDATE_SET set = linkedListIterator_next(candSetIter);
- if (set->candidates != NULL) {
- linkedList_destroy(set->candidates);
- }
free(set);
}
linkedListIterator_destroy(candSetIter);
- linkedList_destroy(value);
}
}
hashMapIterator_destroy(iter);
@@ -117,66 +110,82 @@ HASH_MAP resolver_resolve(MODULE root) {
}
int resolver_populateCandidatesMap(HASH_MAP candidatesMap, MODULE targetModule) {
+ LINKED_LIST candSetList;
+ apr_pool_t *candSetList_pool;
+ LINKED_LIST candidates;
+ apr_pool_t *candidates_pool;
+ LINKED_LIST invalid;
+ apr_pool_t *invalid_pool;
+ int i;
+ int c;
+ REQUIREMENT req;
+ CAPABILITY_LIST capList;
+
if (hashMap_containsKey(candidatesMap, targetModule)) {
return 0;
}
hashMap_put(candidatesMap, targetModule, NULL);
- LINKED_LIST candSetList = linkedList_create();
-
- int i = 0;
- for (i = 0; i < linkedList_size(module_getRequirements(targetModule)); i++) {
- REQUIREMENT req = (REQUIREMENT) linkedList_get(module_getRequirements(targetModule), i);
- CAPABILITY_LIST capList = resolver_getCapabilityList(m_resolvedServices, requirement_getTargetName(req));
-
- LINKED_LIST candidates = linkedList_create();
-
- int c;
- for (c = 0; (capList != NULL) && (c < linkedList_size(capList->capabilities)); c++) {
- CAPABILITY cap = (CAPABILITY) linkedList_get(capList->capabilities, c);
- if (requirement_isSatisfied(req, cap)) {
- linkedList_addElement(candidates, cap);
- }
- }
- capList = resolver_getCapabilityList(m_unresolvedServices, requirement_getTargetName(req));
- for (c = 0; (capList != NULL) && (c < linkedList_size(capList->capabilities)); c++) {
- CAPABILITY cap = (CAPABILITY) linkedList_get(capList->capabilities, c);
- if (requirement_isSatisfied(req, cap)) {
- linkedList_addElement(candidates, cap);
- }
- }
-
- if (linkedList_size(candidates) > 0) {
- LINKED_LIST_ITERATOR iterator = NULL;
- for (iterator = linkedListIterator_create(candidates, 0); linkedListIterator_hasNext(iterator); ) {
- CAPABILITY candidate = (CAPABILITY) linkedListIterator_next(iterator);
- if (!module_isResolved(capability_getModule(candidate))) {
- if (resolver_populateCandidatesMap(candidatesMap, capability_getModule(candidate)) != 0) {
- linkedListIterator_remove(iterator);
- }
- }
- }
- linkedListIterator_destroy(iterator);
- }
-
- if (linkedList_size(candidates) == 0) {
- LINKED_LIST invalid = linkedList_create();
- resolver_removeInvalidCandidate(targetModule, candidatesMap, invalid);
- linkedList_destroy(invalid);
- linkedList_destroy(candidates);
- printf("Unable to resolve: %s, %s\n", module_getSymbolicName(targetModule), requirement_getTargetName(req));
- return -1;
- } else if (linkedList_size(candidates) > 0) {
- CANDIDATE_SET cs = (CANDIDATE_SET) malloc(sizeof(*cs));
- cs->candidates = candidates;
- cs->module = targetModule;
- cs->requirement = req;
- linkedList_addElement(candSetList, cs);
- }
+ if (apr_pool_create(&candSetList_pool, module_getBundle(targetModule)->memoryPool) == APR_SUCCESS) {
+ if (linkedList_create(candSetList_pool, &candSetList) == CELIX_SUCCESS) {
+ for (i = 0; i < linkedList_size(module_getRequirements(targetModule)); i++) {
+ req = (REQUIREMENT) linkedList_get(module_getRequirements(targetModule), i);
+ capList = resolver_getCapabilityList(m_resolvedServices, requirement_getTargetName(req));
+
+ if (apr_pool_create(&candidates_pool, module_getBundle(targetModule)->memoryPool) == APR_SUCCESS) {
+ if (linkedList_create(candidates_pool, &candidates) == CELIX_SUCCESS) {
+ for (c = 0; (capList != NULL) && (c < linkedList_size(capList->capabilities)); c++) {
+ CAPABILITY cap = (CAPABILITY) linkedList_get(capList->capabilities, c);
+ if (requirement_isSatisfied(req, cap)) {
+ linkedList_addElement(candidates, cap);
+ }
+ }
+ capList = resolver_getCapabilityList(m_unresolvedServices, requirement_getTargetName(req));
+ for (c = 0; (capList != NULL) && (c < linkedList_size(capList->capabilities)); c++) {
+ CAPABILITY cap = (CAPABILITY) linkedList_get(capList->capabilities, c);
+ if (requirement_isSatisfied(req, cap)) {
+ linkedList_addElement(candidates, cap);
+ }
+ }
+
+ if (linkedList_size(candidates) > 0) {
+ LINKED_LIST_ITERATOR iterator = NULL;
+ for (iterator = linkedListIterator_create(candidates, 0); linkedListIterator_hasNext(iterator); ) {
+ CAPABILITY candidate = (CAPABILITY) linkedListIterator_next(iterator);
+ if (!module_isResolved(capability_getModule(candidate))) {
+ if (resolver_populateCandidatesMap(candidatesMap, capability_getModule(candidate)) != 0) {
+ linkedListIterator_remove(iterator);
+ }
+ }
+ }
+ linkedListIterator_destroy(iterator);
+ }
+
+ if (linkedList_size(candidates) == 0) {
+ if (apr_pool_create(&invalid_pool, module_getBundle(targetModule)->memoryPool) == APR_SUCCESS) {
+ if (linkedList_create(invalid_pool, &invalid) == CELIX_SUCCESS) {
+ resolver_removeInvalidCandidate(targetModule, candidatesMap, invalid);
+ apr_pool_destroy(invalid_pool);
+ apr_pool_destroy(candidates_pool);
+ printf("Unable to resolve: %s, %s\n", module_getSymbolicName(targetModule), requirement_getTargetName(req));
+ }
+ }
+ return -1;
+ } else if (linkedList_size(candidates) > 0) {
+ CANDIDATE_SET cs = (CANDIDATE_SET) malloc(sizeof(*cs));
+ cs->candidates = candidates;
+ cs->module = targetModule;
+ cs->requirement = req;
+ linkedList_addElement(candSetList, cs);
+ }
+ }
+ }
+ }
+ hashMap_put(candidatesMap, targetModule, candSetList);
+ }
}
- hashMap_put(candidatesMap, targetModule, candSetList);
return 0;
}
@@ -220,25 +229,45 @@ void resolver_removeInvalidCandidate(MOD
}
void resolver_addModule(MODULE module) {
- if (m_modules == NULL) {
- m_modules = linkedList_create();
- m_unresolvedServices = linkedList_create();
- m_resolvedServices = linkedList_create();
- }
- linkedList_addElement(m_modules, module);
-
- int i = 0;
- for (i = 0; i < linkedList_size(module_getCapabilities(module)); i++) {
- CAPABILITY cap = (CAPABILITY) linkedList_get(module_getCapabilities(module), i);
- CAPABILITY_LIST list = resolver_getCapabilityList(m_unresolvedServices, capability_getServiceName(cap));
- if (list == NULL) {
- list = (CAPABILITY_LIST) malloc(sizeof(*list));
- list->serviceName = strdup(capability_getServiceName(cap));
- list->capabilities = linkedList_create();
+ apr_pool_t *modules_pool;
+ apr_pool_t *unresolvedServices_pool;
+ apr_pool_t *resolvedServices_pool;
+ int i;
+ CAPABILITY cap;
+ CAPABILITY_LIST list;
+ apr_pool_t *capabilities_pool;
- linkedList_addElement(m_unresolvedServices, list);
- }
- linkedList_addElement(list->capabilities, cap);
+ if (m_modules == NULL) {
+ if (apr_pool_create(&modules_pool, module_getBundle(module)->memoryPool) == APR_SUCCESS) {
+ if (apr_pool_create(&unresolvedServices_pool, module_getBundle(module)->memoryPool) == APR_SUCCESS) {
+ if (apr_pool_create(&resolvedServices_pool, module_getBundle(module)->memoryPool) == APR_SUCCESS) {
+ linkedList_create(modules_pool, &m_modules);
+ linkedList_create(unresolvedServices_pool, &m_unresolvedServices);
+ linkedList_create(resolvedServices_pool, &m_resolvedServices);
+ }
+ }
+ }
+ }
+
+ if (m_modules != NULL && m_unresolvedServices != NULL) {
+ linkedList_addElement(m_modules, module);
+
+ for (i = 0; i < linkedList_size(module_getCapabilities(module)); i++) {
+ cap = (CAPABILITY) linkedList_get(module_getCapabilities(module), i);
+ list = resolver_getCapabilityList(m_unresolvedServices, capability_getServiceName(cap));
+ if (list == NULL) {
+ if (apr_pool_create(&capabilities_pool, module_getBundle(module)->memoryPool) == APR_SUCCESS) {
+ list = (CAPABILITY_LIST) apr_palloc(capabilities_pool, sizeof(*list));
+ if (list != NULL) {
+ list->serviceName = apr_pstrdup(capabilities_pool, capability_getServiceName(cap));
+ if (linkedList_create(capabilities_pool, &list->capabilities) == APR_SUCCESS) {
+ linkedList_addElement(m_unresolvedServices, list);
+ }
+ }
+ }
+ }
+ linkedList_addElement(list->capabilities, cap);
+ }
}
}
@@ -263,49 +292,60 @@ void resolver_removeModule(MODULE module
}
void resolver_moduleResolved(MODULE module) {
- if (module_isResolved(module)) {
- int capIdx;
- LINKED_LIST capsCopy = linkedList_create();
- for (capIdx = 0; (module_getCapabilities(module) != NULL) && (capIdx < linkedList_size(module_getCapabilities(module))); capIdx++) {
- CAPABILITY cap = (CAPABILITY) linkedList_get(module_getCapabilities(module), capIdx);
- CAPABILITY_LIST list = resolver_getCapabilityList(m_unresolvedServices, capability_getServiceName(cap));
- linkedList_removeElement(list->capabilities, cap);
-
- linkedList_addElement(capsCopy, cap);
- }
+ int capIdx;
+ LINKED_LIST capsCopy;
+ apr_pool_t *capsCopy_pool;
+ apr_pool_t *capabilities_pool;
- LINKED_LIST wires = module_getWires(module);
- for (capIdx = 0; (capsCopy != NULL) && (capIdx < linkedList_size(capsCopy)); capIdx++) {
- CAPABILITY cap = linkedList_get(capsCopy, capIdx);
-
- int wireIdx = 0;
- for (wireIdx = 0; (wires != NULL) && (wireIdx < linkedList_size(wires)); wireIdx++) {
- WIRE wire = (WIRE) linkedList_get(wires, wireIdx);
-
- if (requirement_isSatisfied(wire_getRequirement(wire), cap)) {
- linkedList_set(capsCopy, capIdx, NULL);
- break;
- }
- }
- }
-
- for (capIdx = 0; (capsCopy != NULL) && (capIdx < linkedList_size(capsCopy)); capIdx++) {
- CAPABILITY cap = linkedList_get(capsCopy, capIdx);
-
- if (cap != NULL) {
- CAPABILITY_LIST list = resolver_getCapabilityList(m_resolvedServices, capability_getServiceName(cap));
- if (list == NULL) {
- list = (CAPABILITY_LIST) malloc(sizeof(*list));
- list->serviceName = strdup(capability_getServiceName(cap));
- list->capabilities = linkedList_create();
-
- linkedList_addElement(m_resolvedServices, list);
- }
- linkedList_addElement(list->capabilities, cap);
- }
- }
-
- linkedList_destroy(capsCopy);
+ if (module_isResolved(module)) {
+ if (apr_pool_create(&capsCopy_pool, module_getBundle(module)->memoryPool) == APR_SUCCESS) {
+ if (linkedList_create(capsCopy_pool, &capsCopy) == APR_SUCCESS) {
+ for (capIdx = 0; (module_getCapabilities(module) != NULL) && (capIdx < linkedList_size(module_getCapabilities(module))); capIdx++) {
+ CAPABILITY cap = (CAPABILITY) linkedList_get(module_getCapabilities(module), capIdx);
+ CAPABILITY_LIST list = resolver_getCapabilityList(m_unresolvedServices, capability_getServiceName(cap));
+ linkedList_removeElement(list->capabilities, cap);
+
+ linkedList_addElement(capsCopy, cap);
+ }
+
+ LINKED_LIST wires = module_getWires(module);
+ for (capIdx = 0; (capsCopy != NULL) && (capIdx < linkedList_size(capsCopy)); capIdx++) {
+ CAPABILITY cap = linkedList_get(capsCopy, capIdx);
+
+ int wireIdx = 0;
+ for (wireIdx = 0; (wires != NULL) && (wireIdx < linkedList_size(wires)); wireIdx++) {
+ WIRE wire = (WIRE) linkedList_get(wires, wireIdx);
+
+ if (requirement_isSatisfied(wire_getRequirement(wire), cap)) {
+ linkedList_set(capsCopy, capIdx, NULL);
+ break;
+ }
+ }
+ }
+
+ for (capIdx = 0; (capsCopy != NULL) && (capIdx < linkedList_size(capsCopy)); capIdx++) {
+ CAPABILITY cap = linkedList_get(capsCopy, capIdx);
+
+ if (cap != NULL) {
+ CAPABILITY_LIST list = resolver_getCapabilityList(m_resolvedServices, capability_getServiceName(cap));
+ if (list == NULL) {
+ if (apr_pool_create(&capabilities_pool, module_getBundle(module)->memoryPool) == APR_SUCCESS) {
+ list = (CAPABILITY_LIST) apr_palloc(capabilities_pool, sizeof(*list));
+ if (list != NULL) {
+ list->serviceName = apr_pstrdup(capabilities_pool, capability_getServiceName(cap));
+ if (linkedList_create(capabilities_pool, &list->capabilities) == APR_SUCCESS) {
+ linkedList_addElement(m_resolvedServices, list);
+ }
+ }
+ }
+ }
+ linkedList_addElement(list->capabilities, cap);
+ }
+ }
+
+ apr_pool_destroy(capsCopy_pool);
+ }
+ }
}
}
@@ -324,37 +364,47 @@ CAPABILITY_LIST resolver_getCapabilityLi
}
HASH_MAP resolver_populateWireMap(HASH_MAP candidates, MODULE importer, HASH_MAP wireMap) {
- if (module_isResolved(importer) || (hashMap_get(wireMap, importer))) {
- return wireMap;
- }
-
- LINKED_LIST candSetList = (LINKED_LIST) hashMap_get(candidates, importer);
-
- LINKED_LIST serviceWires = linkedList_create();
- LINKED_LIST emptyWires = linkedList_create();
-
- hashMap_put(wireMap, importer, emptyWires);
-
- int candSetIdx = 0;
- for (candSetIdx = 0; candSetIdx < linkedList_size(candSetList); candSetIdx++) {
- CANDIDATE_SET cs = (CANDIDATE_SET) linkedList_get(candSetList, candSetIdx);
-
-
- if (importer != capability_getModule(((CAPABILITY) linkedList_get(cs->candidates, 0)))) {
- WIRE wire = wire_create(importer, cs->requirement,
- capability_getModule(((CAPABILITY) linkedList_get(cs->candidates, 0))),
- ((CAPABILITY) linkedList_get(cs->candidates, 0)));
- linkedList_addElement(serviceWires, wire);
- }
+ LINKED_LIST serviceWires;
+ apr_pool_t *serviceWires_pool;
+ LINKED_LIST emptyWires;
+ apr_pool_t *emptyWires_pool;
+
+ if (candidates && importer && wireMap) {
+ if (module_isResolved(importer) || (hashMap_get(wireMap, importer))) {
+ return wireMap;
+ }
- wireMap = resolver_populateWireMap(candidates,
- capability_getModule(((CAPABILITY) linkedList_get(cs->candidates, 0))),
- wireMap);
- }
+ LINKED_LIST candSetList = (LINKED_LIST) hashMap_get(candidates, importer);
- //hashMap_remove(wireMap, importer);
- LINKED_LIST empty = hashMap_put(wireMap, importer, serviceWires);
- linkedList_destroy(empty);
+ if (apr_pool_create(&serviceWires_pool, module_getBundle(importer)->memoryPool) == APR_SUCCESS) {
+ if (apr_pool_create(&emptyWires_pool, module_getBundle(importer)->memoryPool) == APR_SUCCESS) {
+ if (linkedList_create(serviceWires_pool, &serviceWires) == APR_SUCCESS) {
+ if (linkedList_create(emptyWires_pool, &emptyWires) == APR_SUCCESS) {
+ hashMap_put(wireMap, importer, emptyWires);
+
+ int candSetIdx = 0;
+ for (candSetIdx = 0; candSetIdx < linkedList_size(candSetList); candSetIdx++) {
+ CANDIDATE_SET cs = (CANDIDATE_SET) linkedList_get(candSetList, candSetIdx);
+
+
+ if (importer != capability_getModule(((CAPABILITY) linkedList_get(cs->candidates, 0)))) {
+ WIRE wire = wire_create(importer, cs->requirement,
+ capability_getModule(((CAPABILITY) linkedList_get(cs->candidates, 0))),
+ ((CAPABILITY) linkedList_get(cs->candidates, 0)));
+ linkedList_addElement(serviceWires, wire);
+ }
+
+ wireMap = resolver_populateWireMap(candidates,
+ capability_getModule(((CAPABILITY) linkedList_get(cs->candidates, 0))),
+ wireMap);
+ }
+
+ hashMap_put(wireMap, importer, serviceWires);
+ }
+ }
+ }
+ }
+ }
- return wireMap;
+ return wireMap;
}
Modified: incubator/celix/trunk/launcher/launcher.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/launcher/launcher.c?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/launcher/launcher.c (original)
+++ incubator/celix/trunk/launcher/launcher.c Mon Jul 11 08:26:52 2011
@@ -62,36 +62,40 @@ int main(void) {
char delims[] = " ";
char * result;
- LINKED_LIST bundles = linkedList_create();
- result = strtok(autoStart, delims);
- while (result != NULL) {
- char * location = apr_pstrdup(memoryPool, result);
- linkedList_addElement(bundles, location);
- result = strtok(NULL, delims);
- }
- // First install all bundles
- // Afterwards start them
- ARRAY_LIST installed = arrayList_create();
- BUNDLE_CONTEXT context = bundle_getContext(framework->bundle);
- LINKED_LIST_ITERATOR iter = linkedListIterator_create(bundles, 0);
- while (linkedListIterator_hasNext(iter)) {
- BUNDLE current = NULL;
- char * location = linkedListIterator_next(iter);
- bundleContext_installBundle(context, location, ¤t);
- arrayList_add(installed, current);
- linkedListIterator_remove(iter);
- }
- linkedListIterator_destroy(iter);
- linkedList_destroy(bundles);
+ apr_pool_t *pool;
+ if (apr_pool_create(&pool, memoryPool) == APR_SUCCESS) {
+ LINKED_LIST bundles;
+ linkedList_create(pool, &bundles);
+ result = strtok(autoStart, delims);
+ while (result != NULL) {
+ char * location = apr_pstrdup(memoryPool, result);
+ linkedList_addElement(bundles, location);
+ result = strtok(NULL, delims);
+ }
+ // First install all bundles
+ // Afterwards start them
+ ARRAY_LIST installed = arrayList_create();
+ BUNDLE_CONTEXT context = bundle_getContext(framework->bundle);
+ LINKED_LIST_ITERATOR iter = linkedListIterator_create(bundles, 0);
+ while (linkedListIterator_hasNext(iter)) {
+ BUNDLE current = NULL;
+ char * location = linkedListIterator_next(iter);
+ bundleContext_installBundle(context, location, ¤t);
+ arrayList_add(installed, current);
+ linkedListIterator_remove(iter);
+ }
+ linkedListIterator_destroy(iter);
+ apr_pool_destroy(pool);
+
+ int i;
+ for (i = 0; i < arrayList_size(installed); i++) {
+ BUNDLE bundle = (BUNDLE) arrayList_get(installed, i);
+ startBundle(bundle, 0);
+ }
- int i;
- for (i = 0; i < arrayList_size(installed); i++) {
- BUNDLE bundle = (BUNDLE) arrayList_get(installed, i);
- startBundle(bundle, 0);
+ arrayList_destroy(installed);
}
- arrayList_destroy(installed);
-
framework_waitForStop(framework);
framework_destroy(framework);
properties_destroy(config);
Modified: incubator/celix/trunk/log_service/private/include/log.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/log_service/private/include/log.h?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/log_service/private/include/log.h (original)
+++ incubator/celix/trunk/log_service/private/include/log.h Mon Jul 11 08:26:52 2011
@@ -26,6 +26,7 @@
#ifndef LOG_H_
#define LOG_H_
+#include <apr_general.h>
#include "headers.h"
#include "linkedlist.h"
#include "log_entry.h"
@@ -35,7 +36,7 @@ typedef struct log * log_t;
celix_status_t log_create(apr_pool_t *pool, log_t *logger);
celix_status_t log_addEntry(log_t log, log_entry_t entry);
-celix_status_t log_getEntries(log_t log, LINKED_LIST *list);
+celix_status_t log_getEntries(log_t log, apr_pool_t *memory_pool, LINKED_LIST *list);
celix_status_t log_addLogListener(log_t logger, log_listener_t listener);
celix_status_t log_removeLogListener(log_t logger, log_listener_t listener);
Modified: incubator/celix/trunk/log_service/private/include/log_reader_service_impl.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/log_service/private/include/log_reader_service_impl.h?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/log_service/private/include/log_reader_service_impl.h (original)
+++ incubator/celix/trunk/log_service/private/include/log_reader_service_impl.h Mon Jul 11 08:26:52 2011
@@ -31,7 +31,7 @@
celix_status_t logReaderService_create(log_t log, apr_pool_t *pool, log_reader_data_t *reader);
-celix_status_t logReaderService_getLog(log_reader_data_t reader, LINKED_LIST *list);
+celix_status_t logReaderService_getLog(log_reader_data_t reader, apr_pool_t *memory_pool, LINKED_LIST *list);
celix_status_t logReaderService_addLogListener(log_reader_data_t reader, log_listener_t listener);
celix_status_t logReaderService_removeLogListener(log_reader_data_t reader, log_listener_t listener);
Modified: incubator/celix/trunk/log_service/private/src/log.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/log_service/private/src/log.c?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/log_service/private/src/log.c (original)
+++ incubator/celix/trunk/log_service/private/src/log.c Mon Jul 11 08:26:52 2011
@@ -61,7 +61,7 @@ celix_status_t log_create(apr_pool_t *po
} else {
apr_status_t apr_status;
- (*logger)->entries = linkedList_create();
+ linkedList_create(pool, &(*logger)->entries);
apr_thread_mutex_create(&(*logger)->lock, APR_THREAD_MUTEX_UNNESTED, pool);
(*logger)->pool = pool;
@@ -105,20 +105,26 @@ celix_status_t log_addEntry(log_t log, l
return CELIX_SUCCESS;
}
-celix_status_t log_getEntries(log_t log, LINKED_LIST *list) {
- *list = linkedList_create();
- LINKED_LIST_ITERATOR iter = NULL;
+celix_status_t log_getEntries(log_t log, apr_pool_t *memory_pool, LINKED_LIST *list) {
+ LINKED_LIST entries = NULL;
+ if (linkedList_create(memory_pool, &entries) == CELIX_SUCCESS) {
+ LINKED_LIST_ITERATOR iter = NULL;
- apr_thread_mutex_lock(log->lock);
+ apr_thread_mutex_lock(log->lock);
- iter = linkedListIterator_create(log->entries, 0);
- while (linkedListIterator_hasNext(iter)) {
- linkedList_addElement(*list, linkedListIterator_next(iter));
- }
+ iter = linkedListIterator_create(log->entries, 0);
+ while (linkedListIterator_hasNext(iter)) {
+ linkedList_addElement(entries, linkedListIterator_next(iter));
+ }
- apr_thread_mutex_unlock(log->lock);
+ *list = entries;
- return CELIX_SUCCESS;
+ apr_thread_mutex_unlock(log->lock);
+
+ return CELIX_SUCCESS;
+ } else {
+ return CELIX_ENOMEM;
+ }
}
celix_status_t log_addLogListener(log_t logger, log_listener_t listener) {
@@ -215,7 +221,7 @@ celix_status_t log_stopListenerThread(lo
if (status != APR_SUCCESS) {
status = CELIX_INVALID_SYNTAX;
} else {
- apr_thread_join(&stat, logger->listenerThread);
+ //apr_thread_join(&stat, logger->listenerThread);
logger->listenerThread = NULL;
}
Modified: incubator/celix/trunk/log_service/private/src/log_reader_service_impl.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/log_service/private/src/log_reader_service_impl.c?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/log_service/private/src/log_reader_service_impl.c (original)
+++ incubator/celix/trunk/log_service/private/src/log_reader_service_impl.c Mon Jul 11 08:26:52 2011
@@ -46,10 +46,10 @@ celix_status_t logReaderService_create(l
return status;
}
-celix_status_t logReaderService_getLog(log_reader_data_t reader, LINKED_LIST *list) {
+celix_status_t logReaderService_getLog(log_reader_data_t reader, apr_pool_t *memory_pool, LINKED_LIST *list) {
celix_status_t status = CELIX_SUCCESS;
- status = log_getEntries(reader->log, list);
+ status = log_getEntries(reader->log, memory_pool, list);
return status;
}
Modified: incubator/celix/trunk/log_service/public/include/log_reader_service.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/log_service/public/include/log_reader_service.h?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/log_service/public/include/log_reader_service.h (original)
+++ incubator/celix/trunk/log_service/public/include/log_reader_service.h Mon Jul 11 08:26:52 2011
@@ -26,6 +26,7 @@
#ifndef LOG_READER_SERVICE_H_
#define LOG_READER_SERVICE_H_
+#include <apr_general.h>
#include "celix_errno.h"
#include "linkedlist.h"
#include "log_listener.h"
@@ -36,7 +37,7 @@ typedef struct log_reader_data * log_rea
struct log_reader_service {
log_reader_data_t reader;
- celix_status_t (*getLog)(log_reader_data_t reader, LINKED_LIST *list);
+ celix_status_t (*getLog)(log_reader_data_t reader, apr_pool_t *memory_pool, LINKED_LIST *list);
celix_status_t (*addLogListener)(log_reader_data_t reader, log_listener_t listener);
celix_status_t (*removeLogListener)(log_reader_data_t reader, log_listener_t listener);
celix_status_t (*removeAllLogListener)(log_reader_data_t reader);
Modified: incubator/celix/trunk/log_writer/log_writer.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/log_writer/log_writer.c?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/log_writer/log_writer.c (original)
+++ incubator/celix/trunk/log_writer/log_writer.c Mon Jul 11 08:26:52 2011
@@ -69,7 +69,9 @@ void service_destroy(void * userData) {
}
celix_status_t logListener_logged(log_listener_t listener, log_entry_t entry) {
- printf("LogWriter: %s from %s\n", entry->message, module_getSymbolicName(bundle_getCurrentModule(entry->reference->bundle)));
+ MODULE module = bundle_getCurrentModule(entry->bundle);
+ char *sName = module_getSymbolicName(module);
+ printf("LogWriter: %s from %s\n", entry->message, sName);
return CELIX_SUCCESS;
}
Modified: incubator/celix/trunk/shell/log_command.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/log_command.c?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/shell/log_command.c (original)
+++ incubator/celix/trunk/shell/log_command.c Mon Jul 11 08:26:52 2011
@@ -51,6 +51,8 @@ void logCommand_destroy(COMMAND command)
void logCommand_execute(COMMAND command, char *line, void (*out)(char *), void (*err)(char *)) {
SERVICE_REFERENCE readerService = NULL;
SERVICE_REFERENCE logService = NULL;
+ apr_pool_t *memory_pool = NULL;
+ apr_pool_t *bundle_memory_pool = NULL;
bundleContext_getServiceReference(command->bundleContext, (char *) LOG_READER_SERVICE_NAME, &readerService);
if (readerService != NULL) {
@@ -58,15 +60,22 @@ void logCommand_execute(COMMAND command,
LINKED_LIST list = NULL;
LINKED_LIST_ITERATOR iter = NULL;
log_reader_service_t reader = NULL;
- bundleContext_getService(command->bundleContext, readerService, (void **) &reader);
- reader->getLog(reader->reader, &list);
- iter = linkedListIterator_create(list, 0);
- while (linkedListIterator_hasNext(iter)) {
- log_entry_t entry = linkedListIterator_next(iter);
- sprintf(line, "%s\n", entry->message);
- out(line);
- }
+ bundleContext_getMemoryPool(command->bundleContext, &bundle_memory_pool);
+ apr_pool_create(&memory_pool, bundle_memory_pool);
+ if (memory_pool) {
+ bundleContext_getService(command->bundleContext, readerService, (void **) &reader);
+ reader->getLog(reader->reader, memory_pool, &list);
+ iter = linkedListIterator_create(list, 0);
+ while (linkedListIterator_hasNext(iter)) {
+ log_entry_t entry = linkedListIterator_next(iter);
+ sprintf(line, "%s\n", entry->message);
+ out(line);
+ }
+ apr_pool_destroy(memory_pool);
+ } else {
+ out("Log reader service: out of memory!\n");
+ }
} else {
out("No log reader available\n");
}
Modified: incubator/celix/trunk/target.cmake
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/target.cmake?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/target.cmake (original)
+++ incubator/celix/trunk/target.cmake Mon Jul 11 08:26:52 2011
@@ -19,6 +19,6 @@
#deploy("shell test" BUNDLES shell)
deploy("hello_world" BUNDLES shell shell_tui hello_world celix.mongoose log_service log_writer)
#deploy("deployer" BUNDLES shell shell_tui deployer)
-deploy("wb" BUNDLES tracker publisherA publisherB shell shell_tui)
+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)
\ No newline at end of file
Modified: incubator/celix/trunk/utils/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/utils/CMakeLists.txt?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/utils/CMakeLists.txt (original)
+++ incubator/celix/trunk/utils/CMakeLists.txt Mon Jul 11 08:26:52 2011
@@ -25,5 +25,6 @@ add_library(utils SHARED ${SRC})
IF(UNIX)
target_link_libraries(utils m)
ENDIF(UNIX)
+target_link_libraries(utils ${APR_LIBRARY})
install(TARGETS utils LIBRARY DESTINATION lib ARCHIVE DESTINATION lib COMPONENT framework)
Modified: incubator/celix/trunk/utils/private/include/linked_list_private.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/utils/private/include/linked_list_private.h?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/utils/private/include/linked_list_private.h (original)
+++ incubator/celix/trunk/utils/private/include/linked_list_private.h Mon Jul 11 08:26:52 2011
@@ -29,12 +29,14 @@
#include "linkedlist.h"
struct linkedListEntry {
+ apr_pool_t *memory_pool; // this is the (sub)memory pool specific for this linked list entry
void * element;
struct linkedListEntry * next;
struct linkedListEntry * previous;
};
struct linkedList {
+ apr_pool_t *memory_pool;
LINKED_LIST_ENTRY header;
size_t size;
int modificationCount;
Modified: incubator/celix/trunk/utils/private/src/linkedlist.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/utils/private/src/linkedlist.c?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/utils/private/src/linkedlist.c (original)
+++ incubator/celix/trunk/utils/private/src/linkedlist.c Mon Jul 11 08:26:52 2011
@@ -29,25 +29,25 @@
#include "linkedlist.h"
#include "linked_list_private.h"
-LINKED_LIST linkedList_create(void) {
- LINKED_LIST list = (LINKED_LIST) malloc(sizeof(*list));
- list->header = (LINKED_LIST_ENTRY) malloc(sizeof(*(list->header)));
- list->header->element = NULL;
- list->header->next = list->header;
- list->header->previous = list->header;
- list->size = 0;
- list->modificationCount = 0;
+celix_status_t linkedList_create(apr_pool_t *pool, LINKED_LIST *list) {
+ LINKED_LIST linked_list = (LINKED_LIST) apr_pcalloc(pool, sizeof(*linked_list));
+ if (linked_list) {
+ linked_list->header = (LINKED_LIST_ENTRY) apr_pcalloc(pool, sizeof(*(linked_list->header)));
+ if (linked_list->header) {
+ linked_list->header->element = NULL;
+ linked_list->header->next = linked_list->header;
+ linked_list->header->previous = linked_list->header;
+ linked_list->size = 0;
+ linked_list->modificationCount = 0;
+ linked_list->memory_pool = pool;
- return list;
-}
+ *list = linked_list;
-void linkedList_destroy(LINKED_LIST list) {
- linkedList_clear(list);
- free(list->header);
- list->header = NULL;
- list->modificationCount = 0;
- list->size = 0;
- free(list);
+ return CELIX_SUCCESS;
+ }
+ }
+
+ return CELIX_ENOMEM;
}
void * linkedList_getFirst(LINKED_LIST list) {
@@ -193,19 +193,23 @@ int linkedList_indexOf(LINKED_LIST list,
return -1;
}
-// int linkedList_lastIndexOf(LINKED_LIST list, void * element);
-
LINKED_LIST_ENTRY linkedList_addBefore(LINKED_LIST list, void * element, LINKED_LIST_ENTRY entry) {
- LINKED_LIST_ENTRY new = (LINKED_LIST_ENTRY) malloc(sizeof(*new));
- new->element = element;
- new->next = entry;
- new->previous = entry->previous;
+ LINKED_LIST_ENTRY new = NULL;
+ apr_pool_t *sub_pool = NULL;
- new->previous->next = new;
- new->next->previous = new;
-
- list->size++;
- list->modificationCount++;
+ if (apr_pool_create(&sub_pool, list->memory_pool) == APR_SUCCESS) {
+ new = (LINKED_LIST_ENTRY) apr_palloc(sub_pool, sizeof(*new));
+ new->memory_pool = sub_pool;
+ new->element = element;
+ new->next = entry;
+ new->previous = entry->previous;
+
+ new->previous->next = new;
+ new->next->previous = new;
+
+ list->size++;
+ list->modificationCount++;
+ }
return new;
}
@@ -222,7 +226,7 @@ void * linkedList_removeEntry(LINKED_LIS
entry->next->previous = entry->previous;
entry->next = entry->previous = NULL;
- free(entry);
+ apr_pool_destroy(entry->memory_pool);
list->size--;
list->modificationCount++;
Modified: incubator/celix/trunk/utils/public/include/linkedlist.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/utils/public/include/linkedlist.h?rev=1145065&r1=1145064&r2=1145065&view=diff
==============================================================================
--- incubator/celix/trunk/utils/public/include/linkedlist.h (original)
+++ incubator/celix/trunk/utils/public/include/linkedlist.h Mon Jul 11 08:26:52 2011
@@ -26,14 +26,16 @@
#ifndef LINKEDLIST_H_
#define LINKEDLIST_H_
+#include <apr_pools.h>
+
#include "celixbool.h"
+#include "celix_errno.h"
#include "exports.h"
typedef struct linkedListEntry * LINKED_LIST_ENTRY;
typedef struct linkedList * LINKED_LIST;
-UTILS_EXPORT LINKED_LIST linkedList_create(void);
-void linkedList_destroy(LINKED_LIST list);
+UTILS_EXPORT celix_status_t linkedList_create(apr_pool_t *pool, LINKED_LIST *list);
UTILS_EXPORT void * linkedList_getFirst(LINKED_LIST list);
UTILS_EXPORT void * linkedList_getLast(LINKED_LIST list);
UTILS_EXPORT void * linkedList_removeFirst(LINKED_LIST list);