You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2017/11/20 20:32:59 UTC
[02/46] celix git commit: CELIX-417: Initial refactoring for CMake
usage
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/public/include/exports.h
----------------------------------------------------------------------
diff --git a/utils/public/include/exports.h b/utils/public/include/exports.h
deleted file mode 100644
index b128c88..0000000
--- a/utils/public/include/exports.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- *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.
- */
-/*
- * exports.h
- *
- * \date Jun 16, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef EXPORTS_H_
-#define EXPORTS_H_
-
-/* Cmake will define utils_EXPORTS on Windows when it
-configures to build a shared library. If you are going to use
-another build system on windows or create the visual studio
-projects by hand you need to define utils_EXPORTS when
-building a DLL on windows.
-
-We are using the Visual Studio Compiler and building Shared libraries
-*/
-
-#if defined (_WIN32)
- #if defined(celix_utils_EXPORTS)
- #define UTILS_EXPORT __declspec(dllexport)
- #else
- #define UTILS_EXPORT __declspec(dllimport)
- #endif /* celix_utils_EXPORTS */
-#else /* defined (_WIN32) */
- #define UTILS_EXPORT __attribute__((visibility("default")))
-#endif
-
-#endif /* EXPORTS_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/public/include/hash_map.h
----------------------------------------------------------------------
diff --git a/utils/public/include/hash_map.h b/utils/public/include/hash_map.h
deleted file mode 100644
index 28d386b..0000000
--- a/utils/public/include/hash_map.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- *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.
- */
-/*
- * hash_map.h
- *
- * \date Jul 21, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef HASH_MAP_H_
-#define HASH_MAP_H_
-
-#include "celixbool.h"
-#include "exports.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct hashMapEntry* hash_map_entry_pt;
-typedef struct hasMapEntry hash_map_entry_t;
-
-typedef struct hashMap* hash_map_pt;
-typedef struct hashMap hash_map_t;
-
-struct hashMapIterator {
- hash_map_pt map;
- hash_map_entry_pt next;
- hash_map_entry_pt current;
- int expectedModCount;
- int index;
-};
-
-typedef struct hashMapIterator hash_map_iterator_t;
-typedef hash_map_iterator_t *hash_map_iterator_pt;
-
-typedef struct hashMapKeySet *hash_map_key_set_pt;
-typedef struct hashMapValues *hash_map_values_pt;
-typedef struct hashMapEntrySet *hash_map_entry_set_pt;
-
-UTILS_EXPORT hash_map_pt hashMap_create(unsigned int (*keyHash)(const void *), unsigned int (*valueHash)(const void *),
- int (*keyEquals)(const void *, const void *),
- int (*valueEquals)(const void *, const void *));
-
-UTILS_EXPORT void hashMap_destroy(hash_map_pt map, bool freeKeys, bool freeValues);
-
-UTILS_EXPORT int hashMap_size(hash_map_pt map);
-
-UTILS_EXPORT bool hashMap_isEmpty(hash_map_pt map);
-
-UTILS_EXPORT void *hashMap_get(hash_map_pt map, const void *key);
-
-UTILS_EXPORT bool hashMap_containsKey(hash_map_pt map, const void *key);
-
-UTILS_EXPORT hash_map_entry_pt hashMap_getEntry(hash_map_pt map, const void *key);
-
-UTILS_EXPORT void *hashMap_put(hash_map_pt map, void *key, void *value);
-
-UTILS_EXPORT void *hashMap_remove(hash_map_pt map, const void *key);
-
-UTILS_EXPORT void hashMap_clear(hash_map_pt map, bool freeKey, bool freeValue);
-
-UTILS_EXPORT bool hashMap_containsValue(hash_map_pt map, const void *value);
-
-UTILS_EXPORT hash_map_iterator_pt hashMapIterator_create(hash_map_pt map);
-
-UTILS_EXPORT void hashMapIterator_destroy(hash_map_iterator_pt iterator);
-
-UTILS_EXPORT hash_map_iterator_pt hashMapIterator_alloc(void);
-
-UTILS_EXPORT void hashMapIterator_dealloc(hash_map_iterator_pt iterator);
-
-UTILS_EXPORT void hashMapIterator_init(hash_map_pt map, hash_map_iterator_pt iterator);
-
-UTILS_EXPORT void hashMapIterator_deinit(hash_map_iterator_pt iterator);
-
-UTILS_EXPORT hash_map_iterator_t hashMapIterator_construct(hash_map_pt map);
-
-
-UTILS_EXPORT bool hashMapIterator_hasNext(hash_map_iterator_pt iterator);
-
-UTILS_EXPORT void hashMapIterator_remove(hash_map_iterator_pt iterator);
-
-UTILS_EXPORT void *hashMapIterator_nextValue(hash_map_iterator_pt iterator);
-
-UTILS_EXPORT void *hashMapIterator_nextKey(hash_map_iterator_pt iterator);
-
-UTILS_EXPORT hash_map_entry_pt hashMapIterator_nextEntry(hash_map_iterator_pt iterator);
-
-UTILS_EXPORT hash_map_key_set_pt hashMapKeySet_create(hash_map_pt map);
-
-UTILS_EXPORT void hashMapKeySet_destroy(hash_map_key_set_pt keySet);
-
-UTILS_EXPORT int hashMapKeySet_size(hash_map_key_set_pt keySet);
-
-UTILS_EXPORT bool hashMapKeySet_contains(hash_map_key_set_pt keySet, const void *key);
-
-UTILS_EXPORT bool hashMapKeySet_remove(hash_map_key_set_pt keySet, const void *key);
-
-UTILS_EXPORT void hashMapKeySet_clear(hash_map_key_set_pt keySet);
-
-UTILS_EXPORT bool hashMapKeySet_isEmpty(hash_map_key_set_pt keySet);
-
-UTILS_EXPORT hash_map_values_pt hashMapValues_create(hash_map_pt map);
-
-UTILS_EXPORT void hashMapValues_destroy(hash_map_values_pt values);
-
-UTILS_EXPORT hash_map_iterator_pt hashMapValues_iterator(hash_map_values_pt values);
-
-UTILS_EXPORT int hashMapValues_size(hash_map_values_pt values);
-
-UTILS_EXPORT bool hashMapValues_contains(hash_map_values_pt values, const void *o);
-
-UTILS_EXPORT void hashMapValues_toArray(hash_map_values_pt values, void **array[], unsigned int *size);
-
-UTILS_EXPORT bool hashMapValues_remove(hash_map_values_pt values, const void *o);
-
-UTILS_EXPORT void hashMapValues_clear(hash_map_values_pt values);
-
-UTILS_EXPORT bool hashMapValues_isEmpty(hash_map_values_pt values);
-
-UTILS_EXPORT hash_map_entry_set_pt hashMapEntrySet_create(hash_map_pt map);
-
-UTILS_EXPORT void hashMapEntrySet_destroy(hash_map_entry_set_pt entrySet);
-
-UTILS_EXPORT int hashMapEntrySet_size(hash_map_entry_set_pt entrySet);
-
-UTILS_EXPORT bool hashMapEntrySet_contains(hash_map_entry_set_pt entrySet, hash_map_entry_pt entry);
-
-UTILS_EXPORT bool hashMapEntrySet_remove(hash_map_entry_set_pt entrySet, hash_map_entry_pt entry);
-
-UTILS_EXPORT void hashMapEntrySet_clear(hash_map_entry_set_pt entrySet);
-
-UTILS_EXPORT bool hashMapEntrySet_isEmpty(hash_map_entry_set_pt entrySet);
-
-UTILS_EXPORT void *hashMapEntry_getKey(hash_map_entry_pt entry);
-
-UTILS_EXPORT void *hashMapEntry_getValue(hash_map_entry_pt entry);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* HASH_MAP_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/public/include/linked_list.h
----------------------------------------------------------------------
diff --git a/utils/public/include/linked_list.h b/utils/public/include/linked_list.h
deleted file mode 100644
index cbf650c..0000000
--- a/utils/public/include/linked_list.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- *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.h
- *
- * \date Jul 16, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef LINKED_LIST_H_
-#define LINKED_LIST_H_
-
-
-#include "celixbool.h"
-#include "celix_errno.h"
-#include "exports.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-typedef struct linked_list_entry *linked_list_entry_pt;
-typedef struct linked_list *linked_list_pt;
-
-UTILS_EXPORT celix_status_t linkedList_create(linked_list_pt *list);
-
-UTILS_EXPORT celix_status_t linkedList_destroy(linked_list_pt list);
-
-UTILS_EXPORT celix_status_t linkedList_clone(linked_list_pt list, linked_list_pt *clone);
-
-UTILS_EXPORT void *linkedList_getFirst(linked_list_pt list);
-
-UTILS_EXPORT void *linkedList_getLast(linked_list_pt list);
-
-UTILS_EXPORT void *linkedList_removeFirst(linked_list_pt list);
-
-UTILS_EXPORT void *linkedList_removeLast(linked_list_pt list);
-
-UTILS_EXPORT void linkedList_addFirst(linked_list_pt list, void *element);
-
-UTILS_EXPORT void linkedList_addLast(linked_list_pt list, void *element);
-
-UTILS_EXPORT bool linkedList_contains(linked_list_pt list, void *element);
-
-UTILS_EXPORT int linkedList_size(linked_list_pt list);
-
-UTILS_EXPORT bool linkedList_isEmpty(linked_list_pt list);
-
-UTILS_EXPORT bool linkedList_addElement(linked_list_pt list, void *element);
-
-UTILS_EXPORT bool linkedList_removeElement(linked_list_pt list, void *element);
-
-UTILS_EXPORT void linkedList_clear(linked_list_pt list);
-
-UTILS_EXPORT void *linkedList_get(linked_list_pt list, int index);
-
-UTILS_EXPORT void *linkedList_set(linked_list_pt list, int index, void *element);
-
-UTILS_EXPORT void linkedList_addIndex(linked_list_pt list, int index, void *element);
-
-UTILS_EXPORT void *linkedList_removeIndex(linked_list_pt list, int index);
-
-UTILS_EXPORT linked_list_entry_pt linkedList_entry(linked_list_pt list, int index);
-
-UTILS_EXPORT int linkedList_indexOf(linked_list_pt list, void *element);
-
-UTILS_EXPORT linked_list_entry_pt linkedList_addBefore(linked_list_pt list, void *element, linked_list_entry_pt entry);
-
-UTILS_EXPORT void *linkedList_removeEntry(linked_list_pt list, linked_list_entry_pt entry);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* LINKED_LIST_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/public/include/linked_list_iterator.h
----------------------------------------------------------------------
diff --git a/utils/public/include/linked_list_iterator.h b/utils/public/include/linked_list_iterator.h
deleted file mode 100644
index f765d5d..0000000
--- a/utils/public/include/linked_list_iterator.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- *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_iterator.h
- *
- * \date Jul 16, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef LINKED_LIST_ITERATOR_H_
-#define LINKED_LIST_ITERATOR_H_
-
-#include "celixbool.h"
-
-#include "linked_list.h"
-#include "exports.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-typedef struct linkedListIterator *linked_list_iterator_pt;
-
-UTILS_EXPORT linked_list_iterator_pt linkedListIterator_create(linked_list_pt list, unsigned int index);
-
-UTILS_EXPORT void linkedListIterator_destroy(linked_list_iterator_pt iterator);
-
-UTILS_EXPORT bool linkedListIterator_hasNext(linked_list_iterator_pt iterator);
-
-UTILS_EXPORT void *linkedListIterator_next(linked_list_iterator_pt iterator);
-
-UTILS_EXPORT bool linkedListIterator_hasPrevious(linked_list_iterator_pt iterator);
-
-UTILS_EXPORT void *linkedListIterator_previous(linked_list_iterator_pt iterator);
-
-UTILS_EXPORT int linkedListIterator_nextIndex(linked_list_iterator_pt iterator);
-
-UTILS_EXPORT int linkedListIterator_previousIndex(linked_list_iterator_pt iterator);
-
-UTILS_EXPORT void linkedListIterator_remove(linked_list_iterator_pt iterator);
-
-UTILS_EXPORT void linkedListIterator_set(linked_list_iterator_pt iterator, void *element);
-
-UTILS_EXPORT void linkedListIterator_add(linked_list_iterator_pt iterator, void *element);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* LINKED_LIST_ITERATOR_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/public/include/memstream/README.md
----------------------------------------------------------------------
diff --git a/utils/public/include/memstream/README.md b/utils/public/include/memstream/README.md
deleted file mode 100644
index 476810e..0000000
--- a/utils/public/include/memstream/README.md
+++ /dev/null
@@ -1,49 +0,0 @@
-fmemopen for Mac OS and iOS
-===========================
-
-Originally ported from [ingenuitas python-tesseract](https://github.com/ingenuitas/python-tesseract/blob/master/fmemopen.c). Ported by Jeff Verkoeyen under the Apache 2.0 License.
-
-From the fmemopen man page:
-
-> FILE *fmemopen(void *buf, size_t size, const char *mode);
->
-> The fmemopen() function opens a stream that permits the access specified by mode. The stream
-> allows I/O to be performed on the string or memory buffer pointed to by buf. This buffer must be
-> at least size bytes long.
-
-Alas, this method does not exist on BSD operating systems (specifically Mac OS X and iOS). It is
-possible to recreate this functionality using a BSD-specific method called `funopen`.
-
-From the funopen man page:
-
-> FILE * funopen(const void *cookie, int (*readfn)(void *, char *, int),
-> int (*writefn)(void *, const char *, int), fpos_t (*seekfn)(void *, fpos_t, int),
-> int (*closefn)(void *));
->
-> The funopen() function associates a stream with up to four ``I/O functions''. Either readfn or
-> writefn must be specified; the others can be given as an appropriately-typed NULL pointer. These
-> I/O functions will be used to read, write, seek and close the new stream.
-
-fmemopen.c provides a simple implementation of fmemopen using funopen so that you can create FILE
-pointers to blocks of memory.
-
-Adding it to your Project
-=========================
-
-Drag fmemopen.h and fmemopen.c to your project and add them to your target. `#include "fmemopen.h"`
-wherever you need to use `fmemopen`.
-
-Examples
-========
-
-```obj-c
-#import "fmemopen.h"
-
-NSString* string = @"fmemopen in Objective-C";
-const char* cstr = [string UTF8String];
-FILE* file = fmemopen((void *)cstr, sizeof(char) * (string.length + 1), "r");
-
-// fread on file will now read the contents of the NSString
-
-fclose(file);
-```
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/public/include/memstream/fmemopen.h
----------------------------------------------------------------------
diff --git a/utils/public/include/memstream/fmemopen.h b/utils/public/include/memstream/fmemopen.h
deleted file mode 100644
index 3d06b20..0000000
--- a/utils/public/include/memstream/fmemopen.h
+++ /dev/null
@@ -1,52 +0,0 @@
-//
-// Copyright 2012 Jeff Verkoeyen
-// Originally ported from https://github.com/ingenuitas/python-tesseract/blob/master/fmemopen.c
-//
-// Licensed 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.
-//
-
-#ifndef FMEMOPEN_H_
-#define FMEMOPEN_H_
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/**
- * A BSD port of the fmemopen Linux method using funopen.
- *
- * man docs for fmemopen:
- * http://linux.die.net/man/3/fmemopen
- *
- * man docs for funopen:
- * https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/funopen.3.html
- *
- * This method is ported from ingenuitas' python-tesseract project.
- *
- * You must call fclose on the returned file pointer or memory will be leaked.
- *
- * @param buf The data that will be used to back the FILE* methods. Must be at least
- * @c size bytes.
- * @param size The size of the @c buf data.
- * @param mode The permitted stream operation modes.
- * @returns A pointer that can be used in the fread/fwrite/fseek/fclose family of methods.
- * If a failure occurred NULL will be returned.
- */
-FILE *fmemopen(void *buf, size_t size, const char *mode);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // #ifndef FMEMOPEN_H_
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/public/include/memstream/open_memstream.h
----------------------------------------------------------------------
diff --git a/utils/public/include/memstream/open_memstream.h b/utils/public/include/memstream/open_memstream.h
deleted file mode 100644
index e87bb0a..0000000
--- a/utils/public/include/memstream/open_memstream.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef OPEN_MEMSTREAM_H_
-#define OPEN_MEMSTREAM_H_
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-FILE *open_memstream(char **cp, size_t *lenp);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // #ifndef FMEMOPEN_H_
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/public/include/properties.h
----------------------------------------------------------------------
diff --git a/utils/public/include/properties.h b/utils/public/include/properties.h
deleted file mode 100644
index cf93ca0..0000000
--- a/utils/public/include/properties.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- *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.
- */
-/*
- * properties.h
- *
- * \date Apr 27, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PROPERTIES_H_
-#define PROPERTIES_H_
-
-#include <stdio.h>
-
-#include "hash_map.h"
-#include "exports.h"
-#include "celix_errno.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-typedef hash_map_pt properties_pt;
-typedef hash_map_t properties_t;
-
-UTILS_EXPORT properties_pt properties_create(void);
-
-UTILS_EXPORT void properties_destroy(properties_pt properties);
-
-UTILS_EXPORT properties_pt properties_load(const char *filename);
-
-UTILS_EXPORT properties_pt properties_loadWithStream(FILE *stream);
-
-UTILS_EXPORT void properties_store(properties_pt properties, const char *file, const char *header);
-
-UTILS_EXPORT const char *properties_get(properties_pt properties, const char *key);
-
-UTILS_EXPORT const char *properties_getWithDefault(properties_pt properties, const char *key, const char *defaultValue);
-
-UTILS_EXPORT void properties_set(properties_pt properties, const char *key, const char *value);
-
-UTILS_EXPORT celix_status_t properties_copy(properties_pt properties, properties_pt *copy);
-
-#define PROPERTIES_FOR_EACH(props, key) \
- for(hash_map_iterator_t iter = hashMapIterator_construct(props); \
- hashMapIterator_hasNext(&iter), (key) = (const char*)hashMapIterator_nextKey(&iter);)
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* PROPERTIES_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/public/include/thpool.h
----------------------------------------------------------------------
diff --git a/utils/public/include/thpool.h b/utils/public/include/thpool.h
deleted file mode 100644
index 0180aa6..0000000
--- a/utils/public/include/thpool.h
+++ /dev/null
@@ -1,168 +0,0 @@
-/**********************************
- * @author Johan Hanssen Seferidis
- * License: MIT
- *
- **********************************/
-
-#ifndef _THPOOL_
-#define _THPOOL_
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* =================================== API ======================================= */
-
-
-typedef struct thpool_ *threadpool;
-
-
-/**
- * @brief Initialize threadpool
- *
- * Initializes a threadpool. This function will not return untill all
- * threads have initialized successfully.
- *
- * @example
- *
- * ..
- * threadpool thpool; //First we declare a threadpool
- * thpool = thpool_init(4); //then we initialize it to 4 threads
- * ..
- *
- * @param num_threads number of threads to be created in the threadpool
- * @return threadpool created threadpool on success,
- * NULL on error
- */
-threadpool thpool_init(int num_threads);
-
-
-/**
- * @brief Add work to the job queue
- *
- * Takes an action and its argument and adds it to the threadpool's job queue.
- * If you want to add to work a function with more than one arguments then
- * a way to implement this is by passing a pointer to a structure.
- *
- * NOTICE: You have to cast both the function and argument to not get warnings.
- *
- * @example
- *
- * void print_num(int num){
- * printf("%d\n", num);
- * }
- *
- * int main() {
- * ..
- * int a = 10;
- * thpool_add_work(thpool, (void*)print_num, (void*)a);
- * ..
- * }
- *
- * @param threadpool threadpool to which the work will be added
- * @param function_p pointer to function to add as work
- * @param arg_p pointer to an argument
- * @return nothing
- */
-int thpool_add_work(threadpool, void *(*function_p)(void *), void *arg_p);
-
-
-/**
- * @brief Wait for all queued jobs to finish
- *
- * Will wait for all jobs - both queued and currently running to finish.
- * Once the queue is empty and all work has completed, the calling thread
- * (probably the main program) will continue.
- *
- * Smart polling is used in wait. The polling is initially 0 - meaning that
- * there is virtually no polling at all. If after 1 seconds the threads
- * haven't finished, the polling interval starts growing exponentially
- * untill it reaches max_secs seconds. Then it jumps down to a maximum polling
- * interval assuming that heavy processing is being used in the threadpool.
- *
- * @example
- *
- * ..
- * threadpool thpool = thpool_init(4);
- * ..
- * // Add a bunch of work
- * ..
- * thpool_wait(thpool);
- * puts("All added work has finished");
- * ..
- *
- * @param threadpool the threadpool to wait for
- * @return nothing
- */
-void thpool_wait(threadpool);
-
-
-/**
- * @brief Pauses all threads immediately
- *
- * The threads will be paused no matter if they are idle or working.
- * The threads return to their previous states once thpool_resume
- * is called.
- *
- * While the thread is being paused, new work can be added.
- *
- * @example
- *
- * threadpool thpool = thpool_init(4);
- * thpool_pause(thpool);
- * ..
- * // Add a bunch of work
- * ..
- * thpool_resume(thpool); // Let the threads start their magic
- *
- * @param threadpool the threadpool where the threads should be paused
- * @return nothing
- */
-void thpool_pause(threadpool);
-
-
-/**
- * @brief Unpauses all threads if they are paused
- *
- * @example
- * ..
- * thpool_pause(thpool);
- * sleep(10); // Delay execution 10 seconds
- * thpool_resume(thpool);
- * ..
- *
- * @param threadpool the threadpool where the threads should be unpaused
- * @return nothing
- */
-void thpool_resume(threadpool);
-
-
-/**
- * @brief Destroy the threadpool
- *
- * This will wait for the currently active threads to finish and then 'kill'
- * the whole threadpool to free up memory.
- *
- * @example
- * int main() {
- * threadpool thpool1 = thpool_init(2);
- * threadpool thpool2 = thpool_init(2);
- * ..
- * thpool_destroy(thpool1);
- * ..
- * return 0;
- * }
- *
- * @param threadpool the threadpool to destroy
- * @return nothing
- */
-void thpool_destroy(threadpool);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/public/include/utils.h
----------------------------------------------------------------------
diff --git a/utils/public/include/utils.h b/utils/public/include/utils.h
deleted file mode 100644
index 2fc7d44..0000000
--- a/utils/public/include/utils.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- *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.
- */
-/*
- * utils.h
- *
- * \date Jul 27, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef UTILS_H_
-#define UTILS_H_
-
-#include <ctype.h>
-
-#include "celix_errno.h"
-#include "celixbool.h"
-#include "exports.h"
-#include "celix_threads.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-UTILS_EXPORT unsigned int utils_stringHash(const void *string);
-
-UTILS_EXPORT int utils_stringEquals(const void *string, const void *toCompare);
-
-UTILS_EXPORT char *string_ndup(const char *s, size_t n);
-
-UTILS_EXPORT char *utils_stringTrim(char *string);
-
-UTILS_EXPORT bool utils_isStringEmptyOrNull(const char *const str);
-
-UTILS_EXPORT int
-utils_compareServiceIdsAndRanking(unsigned long servId, long servRank, unsigned long otherServId, long otherServRank);
-
-UTILS_EXPORT celix_status_t thread_equalsSelf(celix_thread_t thread, bool *equals);
-
-UTILS_EXPORT celix_status_t utils_isNumeric(const char *number, bool *ret);
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* UTILS_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/public/include/version.h
----------------------------------------------------------------------
diff --git a/utils/public/include/version.h b/utils/public/include/version.h
deleted file mode 100644
index 88e146a..0000000
--- a/utils/public/include/version.h
+++ /dev/null
@@ -1,186 +0,0 @@
-/**
- *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.
- */
-/*
- * version.h
- *
- * \date Jul 12, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef VERSION_H_
-#define VERSION_H_
-
-#include "celix_errno.h"
-#include <stdbool.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * The definition of the version_pt abstract data type.
- */
-typedef struct version *version_pt;
-
-/**
- * Creates a new version_pt using the supplied arguments.
- *
- * @param major Major component of the version identifier.
- * @param minor Minor component of the version identifier.
- * @param micro Micro component of the version identifier.
- * @param qualifier Qualifier component of the version identifier. If
- * <code>null</code> is specified, then the qualifier will be set to
- * the empty string.
- * @param version The created version_pt
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ENOMEM If allocating memory for <code>version</code> failed.
- * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative
- * or the qualifier string is invalid.
- */
-celix_status_t version_createVersion(int major, int minor, int micro, char *qualifier, version_pt *version);
-
-celix_status_t version_destroy(version_pt version);
-
-/**
- * Creates a clone of <code>version</code>.
- *
- * @param version The version to clone
- * @param clone The cloned version
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ENOMEM If allocating memory for <code>version</code> failed.
- * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative
- * or the qualifier string is invalid.
- */
-celix_status_t version_clone(version_pt version, version_pt *clone);
-
-/**
- * Creates a version identifier from the specified string.
- *
- * <p>
- * Here is the grammar for version strings.
- *
- * <pre>
- * version ::= major('.'minor('.'micro('.'qualifier)?)?)?
- * major ::= digit+
- * minor ::= digit+
- * micro ::= digit+
- * qualifier ::= (alpha|digit|'_'|'-')+
- * digit ::= [0..9]
- * alpha ::= [a..zA..Z]
- * </pre>
- *
- * There must be no whitespace in version.
- *
- * @param versionStr String representation of the version identifier.
- * @param version The created version_pt
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ENOMEM If allocating memory for <code>version</code> failed.
- * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative,
- * the qualifier string is invalid or <code>versionStr</code> is improperly formatted.
- */
-celix_status_t version_createVersionFromString(const char *versionStr, version_pt *version);
-
-/**
- * The empty version "0.0.0".
- *
- * @param version The created version_pt
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ENOMEM If allocating memory for <code>version</code> failed.
- * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative,
- * the qualifier string is invalid or <code>versionStr</code> is improperly formatted.
- */
-celix_status_t version_createEmptyVersion(version_pt *version);
-
-celix_status_t version_getMajor(version_pt version, int *major);
-
-celix_status_t version_getMinor(version_pt version, int *minor);
-
-celix_status_t version_getMicro(version_pt version, int *micro);
-
-celix_status_t version_getQualifier(version_pt version, const char **qualifier);
-
-/**
- * Compares this <code>Version</code> object to another object.
- *
- * <p>
- * A version is considered to be <b>less than </b> another version if its
- * major component is less than the other version's major component, or the
- * major components are equal and its minor component is less than the other
- * version's minor component, or the major and minor components are equal
- * and its micro component is less than the other version's micro component,
- * or the major, minor and micro components are equal and it's qualifier
- * component is less than the other version's qualifier component (using
- * <code>String.compareTo</code>).
- *
- * <p>
- * A version is considered to be <b>equal to</b> another version if the
- * major, minor and micro components are equal and the qualifier component
- * is equal (using <code>String.compareTo</code>).
- *
- * @param version The <code>version_pt</code> to be compared with <code>compare</code>.
- * @param compare The <code>version_pt</code> to be compared with <code>version</code>.
- * @param result A negative integer, zero, or a positive integer if <code>version</code> is
- * less than, equal to, or greater than the <code>compare</code>.
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- */
-celix_status_t version_compareTo(version_pt version, version_pt compare, int *result);
-
-/**
- * Returns the string representation of <code>version</code> identifier.
- *
- * <p>
- * The format of the version string will be <code>major.minor.micro</code>
- * if qualifier is the empty string or
- * <code>major.minor.micro.qualifier</code> otherwise.
- *
- * @return The string representation of this version identifier.
- * @param version The <code>version_pt</code> to get the string representation from.
- * @param string Pointer to the string (char *) in which the result will be placed.
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- */
-celix_status_t version_toString(version_pt version, char **string);
-
-/**
- * Check if two versions are semantically compatible.
- *
- * <p>
- * The user version is compatible with the provider version if the provider version is in the range
- * [user_version, next_macro_from_user_version)
- *
- * @return Boolean indicating if the versions are compatible
- * @param version The user <code>version_pt</code> .
- * @param version The reference provider <code>version_pt</code> .
- * @param Boolean indicating if the versions are compatible
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- */
-celix_status_t version_isCompatible(version_pt user, version_pt provider, bool *isCompatible);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* VERSION_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/public/include/version_range.h
----------------------------------------------------------------------
diff --git a/utils/public/include/version_range.h b/utils/public/include/version_range.h
deleted file mode 100644
index b661cd3..0000000
--- a/utils/public/include/version_range.h
+++ /dev/null
@@ -1,160 +0,0 @@
-/**
- *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.
- */
-/*
- * version_range.h
- *
- * \date Jul 12, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef VERSION_RANGE_H_
-#define VERSION_RANGE_H_
-
-/**
- * @defgroup VersionRange Version Range functions
- * @ingroup framework
- * @{
- */
-
-#include "celixbool.h"
-#include "celix_errno.h"
-#include "version.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-/**
- * Type definition for the version_range_pt abstract data type.
- */
-typedef struct versionRange *version_range_pt;
-
-/**
- * Creates a new <code>version_range_pt</code>.
- *
- * @param low Lower bound version
- * @param isLowInclusive True if lower bound should be included in the range
- * @param high Upper bound version
- * @param isHighInclusive True if upper bound should be included in the range
- * @param versionRange The created range
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ENOMEM If allocating memory for <code>versionRange</code> failed.
- */
-celix_status_t
-versionRange_createVersionRange(version_pt low, bool isLowInclusive, version_pt high, bool isHighInclusive,
- version_range_pt *versionRange);
-
-/**
- * Creates an infinite version range using ::version_createEmptyVersion for the low version,
- * NULL for the high version and high and low inclusive set to true.
- *
- * @param range The created range
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ENOMEM If allocating memory for <code>range</code> failed.
- */
-celix_status_t versionRange_createInfiniteVersionRange(version_range_pt *range);
-
-celix_status_t versionRange_destroy(version_range_pt range);
-
-/**
- * Determine if the specified version is part of the version range or not.
- *
- * @param versionRange The range to check <code>version</code> against.
- * @param version The version to check.
- * @param inRange True if the specified version is included in this version range, false otherwise.
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- */
-celix_status_t versionRange_isInRange(version_range_pt versionRange, version_pt version, bool *inRange);
-
-/**
- * Determines whether the lower bound is included in the given range
- *
- * @param versionRange The range to check
- * @param isLowInclusive is set to true in case, the lower bound the lower bound is included, otherwise false
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ILLEGAL_ARGUMENT in case the versionRange is NULL
- */
-celix_status_t versionRange_isLowInclusive(version_range_pt versionRange, bool *isLowInclusive);
-
-/**
- * Determines whether the higher bound is included in the given range
- *
- * @param versionRange The range to check
- * @param isHighInclusive is set to true in case, the lower bound the higher bound is included, otherwise false
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ILLEGAL_ARGUMENT in case the versionRange is NULL
- */
-celix_status_t versionRange_isHighInclusive(version_range_pt versionRange, bool *isHighInclusive);
-
-/**
- * Retrieves whether the lower bound version from the given range
- *
- * @param versionRange The range
- * @param highVersion is set to the lower bound version
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ILLEGAL_ARGUMENT in case the versionRange is NULL
- */
-celix_status_t versionRange_getLowVersion(version_range_pt versionRange, version_pt *lowVersion);
-
-/**
- * Retrieves whether the upper bound version from the given range
- *
- * @param versionRange The range
- * @param highVersion is set to the upper bound version
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ILLEGAL_ARGUMENT in case the versionRange is NULL
- */
-celix_status_t versionRange_getHighVersion(version_range_pt versionRange, version_pt *highVersion);
-
-/**
- * Parses a version range from the specified string.
- *
- * <p>
- * Here is the grammar for version range strings.
- *
- * <pre>
- * version-range ::= interval | atleast
- * interval ::= ( '[' | '(' ) floor ',' ceiling ( ']' | ')' )
- * atleast ::= version
- * floor ::= version
- * ceiling ::= version
- * </pre>
- *
- * @param rangeStr String representation of the version range.
- * @param range The created version_range_pt.
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ENOMEM If allocating memory for <code>versionRange</code> failed.
- * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative,
- * the qualifier string is invalid or <code>versionStr</code> is impropertly formatted.
- */
-celix_status_t versionRange_parse(const char *rangeStr, version_range_pt *range);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* VERSION_RANGE_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/src/array_list.c
----------------------------------------------------------------------
diff --git a/utils/src/array_list.c b/utils/src/array_list.c
new file mode 100644
index 0000000..e7a2e30
--- /dev/null
+++ b/utils/src/array_list.c
@@ -0,0 +1,337 @@
+/**
+ *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.
+ */
+/*
+ * array_list.c
+ *
+ * \date Aug 4, 2010
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "array_list.h"
+#include "array_list_private.h"
+
+static celix_status_t arrayList_elementEquals(const void *a, const void *b, bool *equals);
+
+celix_status_t arrayList_create(array_list_pt *list) {
+ return arrayList_createWithEquals(arrayList_elementEquals, list);
+}
+
+ celix_status_t arrayList_createWithEquals(array_list_element_equals_pt equals, array_list_pt *list) {
+ *list = (array_list_pt) malloc(sizeof(**list));
+
+ (*list)->equals = equals;
+ (*list)->size = 0;
+ (*list)->capacity = 10;
+ (*list)->modCount = 0;
+ (*list)->elementData = (void **) malloc(sizeof(void*) * (*list)->capacity);
+
+ return CELIX_SUCCESS;
+}
+
+void arrayList_destroy(array_list_pt list) {
+ list->size = 0;
+ free(list->elementData);
+ list->elementData = NULL;
+ free(list);
+}
+
+static celix_status_t arrayList_elementEquals(const void *a, const void *b, bool *equals) {
+ *equals = (a == b);
+ return CELIX_SUCCESS;
+}
+
+void arrayList_trimToSize(array_list_pt list) {
+ unsigned int oldCapacity;
+ list->modCount++;
+ oldCapacity = list->capacity;
+ if (list->size < oldCapacity) {
+ void ** newList = (void **) realloc(list->elementData, sizeof(void *) * list->size);
+ list->capacity = list->size;
+ list->elementData = newList;
+ }
+}
+
+void arrayList_ensureCapacity(array_list_pt list, int capacity) {
+ void ** newList;
+ unsigned int oldCapacity;
+ list->modCount++;
+ oldCapacity = list->capacity;
+ if (capacity > oldCapacity) {
+ unsigned int newCapacity = (oldCapacity * 3) / 2 + 1;
+ if (newCapacity < capacity) {
+ newCapacity = capacity;
+ }
+ newList = (void **) realloc(list->elementData, sizeof(void *) * newCapacity);
+ list->capacity = newCapacity;
+ list->elementData = newList;
+ }
+}
+
+unsigned int arrayList_size(array_list_pt list) {
+ return list->size;
+}
+
+bool arrayList_isEmpty(array_list_pt list) {
+ return list->size == 0;
+}
+
+bool arrayList_contains(array_list_pt list, void * element) {
+ int index = arrayList_indexOf(list, element);
+ return index >= 0;
+}
+
+int arrayList_indexOf(array_list_pt list, void * element) {
+ if (element == NULL) {
+ unsigned int i = 0;
+ for (i = 0; i < list->size; i++) {
+ if (list->elementData[i] == NULL) {
+ return i;
+ }
+ }
+ } else {
+ unsigned int i = 0;
+ for (i = 0; i < list->size; i++) {
+ bool equals = false;
+ list->equals(element, list->elementData[i], &equals);
+ if (equals) {
+ return i;
+ }
+ }
+ }
+ return -1;
+}
+
+int arrayList_lastIndexOf(array_list_pt list, void * element) {
+ if (element == NULL) {
+ int i = 0;
+ for (i = list->size - 1; i >= 0; i--) {
+ if (list->elementData[i] == NULL) {
+ return i;
+ }
+ }
+ } else {
+ int i = 0;
+ for (i = list->size - 1; i >= 0; i--) {
+ bool equals = false;
+ list->equals(element, list->elementData[i], &equals);
+ if (equals) {
+ return i;
+ }
+ }
+ }
+ return -1;
+}
+
+void * arrayList_get(array_list_pt list, unsigned int index) {
+ if (index >= list->size) {
+ return NULL;
+ }
+
+ return list->elementData[index];
+}
+
+void * arrayList_set(array_list_pt list, unsigned int index, void * element) {
+ void * oldElement;
+ if (index >= list->size) {
+ return NULL;
+ }
+
+ oldElement = list->elementData[index];
+ list->elementData[index] = element;
+ return oldElement;
+}
+
+bool arrayList_add(array_list_pt list, void * element) {
+ arrayList_ensureCapacity(list, list->size + 1);
+ list->elementData[list->size++] = element;
+ return true;
+}
+
+int arrayList_addIndex(array_list_pt list, unsigned int index, void * element) {
+ unsigned int numMoved;
+ if (index > list->size) {
+ return -1;
+ }
+ arrayList_ensureCapacity(list, list->size+1);
+ numMoved = list->size - index;
+ memmove(list->elementData+(index+1), list->elementData+index, sizeof(void *) * numMoved);
+
+ list->elementData[index] = element;
+ list->size++;
+ return 0;
+}
+
+void * arrayList_remove(array_list_pt list, unsigned int index) {
+ void * oldElement;
+ unsigned int numMoved;
+ if (index >= list->size) {
+ return NULL;
+ }
+
+ list->modCount++;
+ oldElement = list->elementData[index];
+ numMoved = list->size - index - 1;
+ memmove(list->elementData+index, list->elementData+index+1, sizeof(void *) * numMoved);
+ list->elementData[--list->size] = NULL;
+
+ return oldElement;
+}
+
+void arrayList_fastRemove(array_list_pt list, unsigned int index) {
+ unsigned int numMoved;
+ list->modCount++;
+
+ numMoved = list->size - index - 1;
+ memmove(list->elementData+index, list->elementData+index+1, sizeof(void *) * numMoved);
+ list->elementData[--list->size] = NULL;
+}
+
+bool arrayList_removeElement(array_list_pt list, void * element) {
+ if (element == NULL) {
+ unsigned int i = 0;
+ for (i = 0; i < list->size; i++) {
+ if (list->elementData[i] == NULL) {
+ arrayList_fastRemove(list, i);
+ return true;
+ }
+ }
+ } else {
+ unsigned int i = 0;
+ for (i = 0; i < list->size; i++) {
+ bool equals = false;
+ list->equals(element, list->elementData[i], &equals);
+ if (equals) {
+ arrayList_fastRemove(list, i);
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+void arrayList_clear(array_list_pt list) {
+ unsigned int i;
+ list->modCount++;
+
+ for (i = 0; i < list->size; i++) {
+ // free(list->elementData[i]);
+ list->elementData[i] = NULL;
+ }
+ list->size = 0;
+}
+
+bool arrayList_addAll(array_list_pt list, array_list_pt toAdd) {
+ unsigned int i;
+ unsigned int size = arrayList_size(toAdd);
+ arrayList_ensureCapacity(list, list->size + size);
+// memcpy(list->elementData+list->size, *toAdd->elementData, size);
+// list->size += size;
+ for (i = 0; i < arrayList_size(toAdd); i++) {
+ arrayList_add(list, arrayList_get(toAdd, i));
+ }
+ return size != 0;
+}
+
+array_list_pt arrayList_clone(array_list_pt list) {
+ unsigned int i;
+ array_list_pt new = NULL;
+ arrayList_create(&new);
+// arrayList_ensureCapacity(new, list->size);
+// memcpy(new->elementData, list->elementData, list->size);
+// new->size = list->size;
+
+ for (i = 0; i < arrayList_size(list); i++) {
+ arrayList_add(new, arrayList_get(list, i));
+ }
+ new->modCount = 0;
+ return new;
+}
+
+array_list_iterator_pt arrayListIterator_create(array_list_pt list) {
+ array_list_iterator_pt iterator = (array_list_iterator_pt) malloc(sizeof(*iterator));
+
+ iterator->lastReturned = -1;
+ iterator->cursor = 0;
+ iterator->list = list;
+ iterator->expectedModificationCount = list->modCount;
+
+ return iterator;
+}
+
+void arrayListIterator_destroy(array_list_iterator_pt iterator) {
+ iterator->lastReturned = -1;
+ iterator->cursor = 0;
+ iterator->expectedModificationCount = 0;
+ iterator->list = NULL;
+ free(iterator);
+}
+
+bool arrayListIterator_hasNext(array_list_iterator_pt iterator) {
+ return iterator->cursor != iterator->list->size;
+}
+
+void * arrayListIterator_next(array_list_iterator_pt iterator) {
+ void * next;
+ if (iterator->expectedModificationCount != iterator->list->modCount) {
+ return NULL;
+ }
+ next = arrayList_get(iterator->list, iterator->cursor);
+ iterator->lastReturned = iterator->cursor++;
+ return next;
+}
+
+bool arrayListIterator_hasPrevious(array_list_iterator_pt iterator) {
+ return iterator->cursor != 0;
+}
+
+void * arrayListIterator_previous(array_list_iterator_pt iterator) {
+ int i;
+ void * previous;
+ if (iterator->expectedModificationCount != iterator->list->modCount) {
+ return NULL;
+ }
+ i = iterator->cursor - 1;
+ previous = arrayList_get(iterator->list, i);
+ iterator->lastReturned = iterator->cursor = i;
+ return previous;
+}
+
+void arrayListIterator_remove(array_list_iterator_pt iterator) {
+ if (iterator->lastReturned == -1) {
+ return;
+ }
+ if (iterator->expectedModificationCount != iterator->list->modCount) {
+ return;
+ }
+ if (arrayList_remove(iterator->list, iterator->lastReturned) != NULL) {
+ if (iterator->lastReturned < iterator->cursor) {
+ iterator->cursor--;
+ }
+ iterator->lastReturned = -1;
+ iterator->expectedModificationCount = iterator->list->modCount;
+ }
+}
+
+
+
+
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/src/array_list_private.h
----------------------------------------------------------------------
diff --git a/utils/src/array_list_private.h b/utils/src/array_list_private.h
new file mode 100644
index 0000000..bea2712
--- /dev/null
+++ b/utils/src/array_list_private.h
@@ -0,0 +1,52 @@
+/**
+ *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.
+ */
+/*
+ * array_list_private.h
+ *
+ * \date Aug 4, 2010
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef array_list_t_PRIVATE_H_
+#define array_list_t_PRIVATE_H_
+
+#include "array_list.h"
+
+struct arrayList {
+ void ** elementData;
+ unsigned int size;
+ unsigned int capacity;
+
+ unsigned int modCount;
+
+ array_list_element_equals_pt equals;
+};
+
+struct arrayListIterator {
+ array_list_pt list;
+ unsigned int cursor;
+ int lastReturned;
+ unsigned int expectedModificationCount;
+};
+
+void * arrayList_remove(array_list_pt list, unsigned int index);
+
+
+#endif /* array_list_t_PRIVATE_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/src/celix_threads.c
----------------------------------------------------------------------
diff --git a/utils/src/celix_threads.c b/utils/src/celix_threads.c
new file mode 100644
index 0000000..64bdf5b
--- /dev/null
+++ b/utils/src/celix_threads.c
@@ -0,0 +1,184 @@
+/**
+ *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.
+ */
+/*
+ * celix_threads.c
+ *
+ * \date 4 Jun 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include "signal.h"
+#include "celix_threads.h"
+
+
+celix_status_t celixThread_create(celix_thread_t *new_thread, celix_thread_attr_t *attr, celix_thread_start_t func, void *data) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (pthread_create(&(*new_thread).thread, attr, func, data) != 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+ else {
+ (*new_thread).threadInitialized = true;
+ }
+
+ return status;
+}
+
+// Returns void, since pthread_exit does exit the thread and never returns.
+void celixThread_exit(void *exitStatus) {
+ pthread_exit(exitStatus);
+}
+
+celix_status_t celixThread_detach(celix_thread_t thread) {
+ return pthread_detach(thread.thread);
+}
+
+celix_status_t celixThread_join(celix_thread_t thread, void **retVal) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (pthread_join(thread.thread, retVal) != 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+
+ // #TODO make thread a pointer? Now this statement has no effect
+ // thread.threadInitialized = false;
+
+ return status;
+}
+
+celix_status_t celixThread_kill(celix_thread_t thread, int sig) {
+ return pthread_kill(thread.thread, sig);
+}
+
+celix_thread_t celixThread_self() {
+ celix_thread_t thread;
+
+ thread.thread = pthread_self();
+ thread.threadInitialized = true;
+
+ return thread;
+}
+
+int celixThread_equals(celix_thread_t thread1, celix_thread_t thread2) {
+ return pthread_equal(thread1.thread, thread2.thread);
+}
+
+bool celixThread_initalized(celix_thread_t thread) {
+ return thread.threadInitialized;
+}
+
+
+celix_status_t celixThreadMutex_create(celix_thread_mutex_t *mutex, celix_thread_mutexattr_t *attr) {
+ return pthread_mutex_init(mutex, attr);
+}
+
+celix_status_t celixThreadMutex_destroy(celix_thread_mutex_t *mutex) {
+ return pthread_mutex_destroy(mutex);
+}
+
+celix_status_t celixThreadMutex_lock(celix_thread_mutex_t *mutex) {
+ return pthread_mutex_lock(mutex);
+}
+
+celix_status_t celixThreadMutex_unlock(celix_thread_mutex_t *mutex) {
+ return pthread_mutex_unlock(mutex);
+}
+
+celix_status_t celixThreadMutexAttr_create(celix_thread_mutexattr_t *attr) {
+ return pthread_mutexattr_init(attr);
+}
+
+celix_status_t celixThreadMutexAttr_destroy(celix_thread_mutexattr_t *attr) {
+ return pthread_mutexattr_destroy(attr);
+}
+
+celix_status_t celixThreadMutexAttr_settype(celix_thread_mutexattr_t *attr, int type) {
+ celix_status_t status;
+ switch(type) {
+ case CELIX_THREAD_MUTEX_NORMAL :
+ status = pthread_mutexattr_settype(attr, PTHREAD_MUTEX_NORMAL);
+ break;
+ case CELIX_THREAD_MUTEX_RECURSIVE :
+ status = pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE);
+ break;
+ case CELIX_THREAD_MUTEX_ERRORCHECK :
+ status = pthread_mutexattr_settype(attr, PTHREAD_MUTEX_ERRORCHECK);
+ break;
+ case CELIX_THREAD_MUTEX_DEFAULT :
+ status = pthread_mutexattr_settype(attr, PTHREAD_MUTEX_DEFAULT);
+ break;
+ default:
+ status = pthread_mutexattr_settype(attr, PTHREAD_MUTEX_DEFAULT);
+ break;
+ }
+ return status;
+}
+
+celix_status_t celixThreadCondition_init(celix_thread_cond_t *condition, celix_thread_condattr_t *attr) {
+ return pthread_cond_init(condition, attr);
+}
+
+celix_status_t celixThreadCondition_destroy(celix_thread_cond_t *condition) {
+ return pthread_cond_destroy(condition);
+}
+
+celix_status_t celixThreadCondition_wait(celix_thread_cond_t *cond, celix_thread_mutex_t *mutex) {
+ return pthread_cond_wait(cond, mutex);
+}
+
+celix_status_t celixThreadCondition_broadcast(celix_thread_cond_t *cond) {
+ return pthread_cond_broadcast(cond);
+}
+
+celix_status_t celixThreadCondition_signal(celix_thread_cond_t *cond) {
+ return pthread_cond_signal(cond);
+}
+
+celix_status_t celixThreadRwlock_create(celix_thread_rwlock_t *lock, celix_thread_rwlockattr_t *attr) {
+ return pthread_rwlock_init(lock, attr);
+}
+
+celix_status_t celixThreadRwlock_destroy(celix_thread_rwlock_t *lock) {
+ return pthread_rwlock_destroy(lock);
+}
+
+celix_status_t celixThreadRwlock_readLock(celix_thread_rwlock_t *lock) {
+ return pthread_rwlock_rdlock(lock);
+}
+
+celix_status_t celixThreadRwlock_writeLock(celix_thread_rwlock_t *lock) {
+ return pthread_rwlock_wrlock(lock);
+}
+
+celix_status_t celixThreadRwlock_unlock(celix_thread_rwlock_t *lock) {
+ return pthread_rwlock_unlock(lock);
+}
+
+celix_status_t celixThreadRwlockAttr_create(celix_thread_rwlockattr_t *attr) {
+ return pthread_rwlockattr_init(attr);
+}
+
+celix_status_t celixThreadRwlockAttr_destroy(celix_thread_rwlockattr_t *attr) {
+ return pthread_rwlockattr_destroy(attr);
+}
+
+celix_status_t celixThread_once(celix_thread_once_t *once_control, void (*init_routine)(void)) {
+ return pthread_once(once_control, init_routine);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/src/hash_map.c
----------------------------------------------------------------------
diff --git a/utils/src/hash_map.c b/utils/src/hash_map.c
new file mode 100644
index 0000000..bc514a7
--- /dev/null
+++ b/utils/src/hash_map.c
@@ -0,0 +1,607 @@
+/**
+ *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.
+ */
+/*
+ * hash_map.c
+ *
+ * \date Jul 21, 2010
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include "celixbool.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "hash_map.h"
+#include "hash_map_private.h"
+
+static unsigned int DEFAULT_INITIAL_CAPACITY = 16;
+static float DEFAULT_LOAD_FACTOR = 0.75f;
+static unsigned int MAXIMUM_CAPACITY = 1 << 30;
+
+unsigned int hashMap_hashCode(const void * toHash) {
+ intptr_t address = (intptr_t) toHash;
+ return address;
+}
+
+int hashMap_equals(const void * toCompare, const void * compare) {
+ return toCompare == compare;
+}
+
+int hashMap_entryEquals(hash_map_pt map, hash_map_entry_pt entry, hash_map_entry_pt compare) {
+ if (entry->key == compare->key || map->equalsKey(entry->key, compare->key)) {
+ if (entry->value == compare->value || map->equalsValue(entry->value, compare->value)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+static unsigned int hashMap_hash(unsigned int h) {
+ h += ~(h << 9);
+ h ^= ((h >> 14) | (h << 18)); /* >>> */
+ h += (h << 4);
+ h ^= ((h >> 10) | (h << 22)); /* >>> */
+ return h;
+}
+
+static unsigned int hashMap_indexFor(unsigned int h, unsigned int length) {
+ return h & (length - 1);
+}
+
+hash_map_pt hashMap_create(unsigned int (*keyHash)(const void *), unsigned int (*valueHash)(const void *),
+ int (*keyEquals)(const void *, const void *), int (*valueEquals)(const void *, const void *)) {
+ hash_map_pt map = (hash_map_pt) malloc(sizeof(*map));
+ map->treshold = (unsigned int) (DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR);
+ map->table = (hash_map_entry_pt *) calloc(DEFAULT_INITIAL_CAPACITY, sizeof(hash_map_entry_pt));
+ map->size = 0;
+ map->modificationCount = 0;
+ map->tablelength = DEFAULT_INITIAL_CAPACITY;
+ map->hashKey = hashMap_hashCode;
+ map->hashValue = hashMap_hashCode;
+ map->equalsKey = hashMap_equals;
+ map->equalsValue = hashMap_equals;
+
+ if (keyHash != NULL) {
+ map->hashKey = keyHash;
+ }
+ if (valueHash != NULL) {
+ map->hashValue = valueHash;
+ }
+ if (keyEquals != NULL) {
+ map->equalsKey = keyEquals;
+ }
+ if (valueEquals != NULL) {
+ map->equalsValue = valueEquals;
+ }
+
+ return map;
+}
+
+void hashMap_destroy(hash_map_pt map, bool freeKeys, bool freeValues) {
+ hashMap_clear(map, freeKeys, freeValues);
+ free(map->table);
+ free(map);
+}
+
+int hashMap_size(hash_map_pt map) {
+ return map->size;
+}
+
+bool hashMap_isEmpty(hash_map_pt map) {
+ return hashMap_size(map) == 0;
+}
+
+void * hashMap_get(hash_map_pt map, const void* key) {
+ unsigned int hash;
+ if (key == NULL) {
+ hash_map_entry_pt entry;
+ for (entry = map->table[0]; entry != NULL; entry = entry->next) {
+ if (entry->key == NULL) {
+ return entry->value;
+ }
+ }
+ return NULL;
+ }
+
+ hash = hashMap_hash(map->hashKey(key));
+ hash_map_entry_pt entry = NULL;
+ for (entry = map->table[hashMap_indexFor(hash, map->tablelength)]; entry != NULL; entry = entry->next) {
+ if (entry->hash == hash && (entry->key == key || map->equalsKey(key, entry->key))) {
+ return entry->value;
+ }
+ }
+ return NULL;
+}
+
+bool hashMap_containsKey(hash_map_pt map, const void* key) {
+ return hashMap_getEntry(map, key) != NULL;
+}
+
+hash_map_entry_pt hashMap_getEntry(hash_map_pt map, const void* key) {
+ unsigned int hash = (key == NULL) ? 0 : hashMap_hash(map->hashKey(key));
+ hash_map_entry_pt entry;
+ int index = hashMap_indexFor(hash, map->tablelength);
+ for (entry = map->table[index]; entry != NULL; entry = entry->next) {
+ if (entry->hash == hash && (entry->key == key || map->equalsKey(key, entry->key))) {
+ return entry;
+ }
+ }
+ return NULL;
+}
+
+void * hashMap_put(hash_map_pt map, void * key, void * value) {
+ unsigned int hash;
+ int i;
+ if (key == NULL) {
+ hash_map_entry_pt entry;
+ for (entry = map->table[0]; entry != NULL; entry = entry->next) {
+ if (entry->key == NULL) {
+ void * oldValue = entry->value;
+ entry->value = value;
+ return oldValue;
+ }
+ }
+ map->modificationCount++;
+ hashMap_addEntry(map, 0, NULL, value, 0);
+ return NULL;
+ }
+ hash = hashMap_hash(map->hashKey(key));
+ i = hashMap_indexFor(hash, map->tablelength);
+
+ hash_map_entry_pt entry;
+ for (entry = map->table[i]; entry != NULL; entry = entry->next) {
+ if (entry->hash == hash && (entry->key == key || map->equalsKey(key, entry->key))) {
+ void * oldValue = entry->value;
+ entry->value = value;
+ return oldValue;
+ }
+ }
+ map->modificationCount++;
+ hashMap_addEntry(map, hash, key, value, i);
+ return NULL;
+}
+
+void hashMap_resize(hash_map_pt map, int newCapacity) {
+ hash_map_entry_pt * newTable;
+ unsigned int j;
+ if (map->tablelength == MAXIMUM_CAPACITY) {
+ return;
+ }
+
+ newTable = (hash_map_entry_pt *) calloc(newCapacity, sizeof(hash_map_entry_pt));
+
+ for (j = 0; j < map->tablelength; j++) {
+ hash_map_entry_pt entry = map->table[j];
+ if (entry != NULL) {
+ map->table[j] = NULL;
+ do {
+ hash_map_entry_pt next = entry->next;
+ int i = hashMap_indexFor(entry->hash, newCapacity);
+ entry->next = newTable[i];
+ newTable[i] = entry;
+ entry = next;
+ } while (entry != NULL);
+ }
+ }
+ free(map->table);
+ map->table = newTable;
+ map->tablelength = newCapacity;
+ map->treshold = (unsigned int) ceil(newCapacity * DEFAULT_LOAD_FACTOR);
+}
+
+void * hashMap_remove(hash_map_pt map, const void* key) {
+ hash_map_entry_pt entry = hashMap_removeEntryForKey(map, key);
+ void * value = (entry == NULL ? NULL : entry->value);
+ if (entry != NULL) {
+ entry->key = NULL;
+ entry->value = NULL;
+ free(entry);
+ }
+ return value;
+}
+
+hash_map_entry_pt hashMap_removeEntryForKey(hash_map_pt map, const void* key) {
+ unsigned int hash = (key == NULL) ? 0 : hashMap_hash(map->hashKey(key));
+ int i = hashMap_indexFor(hash, map->tablelength);
+ hash_map_entry_pt prev = map->table[i];
+ hash_map_entry_pt entry = prev;
+
+ while (entry != NULL) {
+ hash_map_entry_pt next = entry->next;
+ if (entry->hash == hash && (entry->key == key || (key != NULL && map->equalsKey(key, entry->key)))) {
+ map->modificationCount++;
+ map->size--;
+ if (prev == entry) {
+ map->table[i] = next;
+ } else {
+ prev->next = next;
+ }
+ return entry;
+ }
+ prev = entry;
+ entry = next;
+ }
+
+ return entry;
+}
+
+hash_map_entry_pt hashMap_removeMapping(hash_map_pt map, hash_map_entry_pt entry) {
+ unsigned int hash;
+ hash_map_entry_pt prev;
+ hash_map_entry_pt e;
+ int i;
+ if (entry == NULL) {
+ return NULL;
+ }
+ hash = (entry->key == NULL) ? 0 : hashMap_hash(map->hashKey(entry->key));
+ i = hashMap_indexFor(hash, map->tablelength);
+ prev = map->table[i];
+ e = prev;
+
+ while (e != NULL) {
+ hash_map_entry_pt next = e->next;
+ if (e->hash == hash && hashMap_entryEquals(map, e, entry)) {
+ map->modificationCount++;
+ map->size--;
+ if (prev == e) {
+ map->table[i] = next;
+ } else {
+ prev->next = next;
+ }
+ return e;
+ }
+ prev = e;
+ e = next;
+ }
+
+ return e;
+}
+
+void hashMap_clear(hash_map_pt map, bool freeKey, bool freeValue) {
+ unsigned int i;
+ hash_map_entry_pt * table;
+ map->modificationCount++;
+ table = map->table;
+
+ for (i = 0; i < map->tablelength; i++) {
+ hash_map_entry_pt entry = table[i];
+ while (entry != NULL) {
+ hash_map_entry_pt f = entry;
+ entry = entry->next;
+ if (freeKey && f->key != NULL)
+ free(f->key);
+ if (freeValue && f->value != NULL)
+ free(f->value);
+ free(f);
+ }
+ table[i] = NULL;
+ }
+ map->size = 0;
+}
+
+bool hashMap_containsValue(hash_map_pt map, const void* value) {
+ unsigned int i;
+ if (value == NULL) {
+ for (i = 0; i < map->tablelength; i++) {
+ hash_map_entry_pt entry;
+ for (entry = map->table[i]; entry != NULL; entry = entry->next) {
+ if (entry->value == NULL) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ for (i = 0; i < map->tablelength; i++) {
+ hash_map_entry_pt entry;
+ for (entry = map->table[i]; entry != NULL; entry = entry->next) {
+ if (entry->value == value || map->equalsValue(entry->value, value)) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+void hashMap_addEntry(hash_map_pt map, int hash, void* key, void* value, int bucketIndex) {
+ hash_map_entry_pt entry = map->table[bucketIndex];
+ hash_map_entry_pt new = (hash_map_entry_pt) malloc(sizeof(*new));
+ new->hash = hash;
+ new->key = key;
+ new->value = value;
+ new->next = entry;
+ map->table[bucketIndex] = new;
+ if (map->size++ >= map->treshold) {
+ hashMap_resize(map, 2 * map->tablelength);
+ }
+}
+
+hash_map_iterator_pt hashMapIterator_alloc(void) {
+ return calloc(1, sizeof(hash_map_iterator_t));
+}
+
+void hashMapIterator_dealloc(hash_map_iterator_pt iterator) {
+ free(iterator);
+}
+
+hash_map_iterator_pt hashMapIterator_create(hash_map_pt map) {
+ hash_map_iterator_pt iterator = hashMapIterator_alloc();
+ hashMapIterator_init(map, iterator);
+ return iterator;
+}
+
+UTILS_EXPORT hash_map_iterator_t hashMapIterator_construct(hash_map_pt map) {
+ hash_map_iterator_t iter;
+ memset(&iter, 0, sizeof(iter));
+ hashMapIterator_init(map, &iter);
+ return iter;
+}
+
+void hashMapIterator_init(hash_map_pt map, hash_map_iterator_pt iterator) {
+ iterator->map = map;
+ iterator->expectedModCount = map->modificationCount;
+ iterator->index = 0;
+ iterator->next = NULL;
+ iterator->current = NULL;
+ if (map->size > 0) {
+ while (iterator->index < map->tablelength && (iterator->next = map->table[iterator->index++]) == NULL) {
+ }
+ }
+}
+
+void hashMapIterator_deinit(hash_map_iterator_pt iterator) {
+ iterator->current = NULL;
+ iterator->expectedModCount = 0;
+ iterator->index = 0;
+ iterator->map = NULL;
+ iterator->next = NULL;
+}
+
+void hashMapIterator_destroy(hash_map_iterator_pt iterator) {
+ hashMapIterator_deinit(iterator);
+ hashMapIterator_dealloc(iterator);
+}
+
+bool hashMapIterator_hasNext(hash_map_iterator_pt iterator) {
+ return iterator->next != NULL;
+}
+
+void hashMapIterator_remove(hash_map_iterator_pt iterator) {
+ void * key;
+ hash_map_entry_pt entry;
+ if (iterator->current == NULL) {
+ return;
+ }
+ if (iterator->expectedModCount != iterator->map->modificationCount) {
+ return;
+ }
+ key = iterator->current->key;
+ iterator->current = NULL;
+ entry = hashMap_removeEntryForKey(iterator->map, key);
+ free(entry);
+ iterator->expectedModCount = iterator->map->modificationCount;
+}
+
+void * hashMapIterator_nextValue(hash_map_iterator_pt iterator) {
+ hash_map_entry_pt entry;
+ if (iterator->expectedModCount != iterator->map->modificationCount) {
+ return NULL;
+ }
+ entry = iterator->next;
+ if (entry == NULL) {
+ return NULL;
+ }
+ if ((iterator->next = entry->next) == NULL) {
+ while (iterator->index < iterator->map->tablelength && (iterator->next = iterator->map->table[iterator->index++]) == NULL) {
+ }
+ }
+ iterator->current = entry;
+ return entry->value;
+}
+
+void * hashMapIterator_nextKey(hash_map_iterator_pt iterator) {
+ hash_map_entry_pt entry;
+ if (iterator->expectedModCount != iterator->map->modificationCount) {
+ return NULL;
+ }
+ entry = iterator->next;
+ if (entry == NULL) {
+ return NULL;
+ }
+ if ((iterator->next = entry->next) == NULL) {
+ while (iterator->index < iterator->map->tablelength && (iterator->next = iterator->map->table[iterator->index++]) == NULL) {
+ }
+ }
+ iterator->current = entry;
+ return entry->key;
+}
+
+hash_map_entry_pt hashMapIterator_nextEntry(hash_map_iterator_pt iterator) {
+ hash_map_entry_pt entry;
+ if (iterator->expectedModCount != iterator->map->modificationCount) {
+ return NULL;
+ }
+ entry = iterator->next;
+ if (entry == NULL) {
+ return NULL;
+ }
+ if ((iterator->next = entry->next) == NULL) {
+ while (iterator->index < iterator->map->tablelength && (iterator->next = iterator->map->table[iterator->index++]) == NULL) {
+ }
+ }
+ iterator->current = entry;
+ return entry;
+}
+
+hash_map_key_set_pt hashMapKeySet_create(hash_map_pt map) {
+ hash_map_key_set_pt keySet = (hash_map_key_set_pt) malloc(sizeof(*keySet));
+ keySet->map = map;
+
+ return keySet;
+}
+
+void hashMapKeySet_destroy(hash_map_key_set_pt keySet){
+ keySet->map = NULL;
+ free(keySet);
+}
+
+int hashMapKeySet_size(hash_map_key_set_pt keySet) {
+ return keySet->map->size;
+}
+
+bool hashMapKeySet_contains(hash_map_key_set_pt keySet, const void* key) {
+ return hashMap_containsKey(keySet->map, key);
+}
+
+bool hashMapKeySet_remove(hash_map_key_set_pt keySet, const void* key) {
+ hash_map_entry_pt entry = hashMap_removeEntryForKey(keySet->map, key);
+ bool removed = entry != NULL;
+ free(entry);
+ return removed;
+}
+
+void hashMapKeySet_clear(hash_map_key_set_pt keySet) {
+ hashMap_clear(keySet->map, false, false);
+}
+
+bool hashMapKeySet_isEmpty(hash_map_key_set_pt keySet) {
+ return hashMapKeySet_size(keySet) == 0;
+}
+
+hash_map_values_pt hashMapValues_create(hash_map_pt map) {
+ hash_map_values_pt values = (hash_map_values_pt) malloc(sizeof(*values));
+ values->map = map;
+
+ return values;
+}
+
+void hashMapValues_destroy(hash_map_values_pt values) {
+ values->map = NULL;
+ free(values);
+}
+
+hash_map_iterator_pt hashMapValues_iterator(hash_map_values_pt values) {
+ return hashMapIterator_create(values->map);
+}
+
+int hashMapValues_size(hash_map_values_pt values) {
+ return values->map->size;
+}
+
+bool hashMapValues_contains(hash_map_values_pt values, const void* value) {
+ return hashMap_containsValue(values->map, value);
+}
+
+void hashMapValues_toArray(hash_map_values_pt values, void* *array[], unsigned int *size) {
+ hash_map_iterator_pt it;
+ int i = 0;
+ int vsize = hashMapValues_size(values);
+ *size = vsize;
+ *array = malloc(vsize * sizeof(**array));
+ it = hashMapValues_iterator(values);
+ while(hashMapIterator_hasNext(it) && i<vsize){
+ (*array)[i++] = hashMapIterator_nextValue(it);
+ }
+ hashMapIterator_destroy(it);
+}
+
+bool hashMapValues_remove(hash_map_values_pt values, const void* value) {
+ hash_map_iterator_pt iterator = hashMapValues_iterator(values);
+ if (value == NULL) {
+ while (hashMapIterator_hasNext(iterator)) {
+ if (hashMapIterator_nextValue(iterator) == NULL) {
+ hashMapIterator_remove(iterator);
+ hashMapIterator_destroy(iterator);
+ return true;
+ }
+ }
+ } else {
+ while (hashMapIterator_hasNext(iterator)) {
+ if (values->map->equalsValue(value, hashMapIterator_nextValue(iterator))) {
+ hashMapIterator_remove(iterator);
+ hashMapIterator_destroy(iterator);
+ return true;
+ }
+ }
+ }
+ hashMapIterator_destroy(iterator);
+ return false;
+}
+
+void hashMapValues_clear(hash_map_values_pt values) {
+ hashMap_clear(values->map, false, false);
+}
+
+bool hashMapValues_isEmpty(hash_map_values_pt values) {
+ return hashMapValues_size(values) == 0;
+}
+
+hash_map_entry_set_pt hashMapEntrySet_create(hash_map_pt map) {
+ hash_map_entry_set_pt entrySet = (hash_map_entry_set_pt) malloc(sizeof(*entrySet));
+ entrySet->map = map;
+
+ return entrySet;
+}
+
+void hashMapEntrySet_destroy(hash_map_entry_set_pt entrySet){
+ entrySet->map = NULL;
+ free(entrySet);
+}
+
+int hashMapEntrySet_size(hash_map_entry_set_pt entrySet) {
+ return entrySet->map->size;
+}
+
+bool hashMapEntrySet_contains(hash_map_entry_set_pt entrySet, hash_map_entry_pt entry) {
+ return hashMap_containsValue(entrySet->map, entry);
+}
+
+bool hashMapEntrySet_remove(hash_map_entry_set_pt entrySet, hash_map_entry_pt entry) {
+ hash_map_entry_pt temp = hashMap_removeMapping(entrySet->map, entry);
+ if (temp != NULL) {
+ free(temp);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+void hashMapEntrySet_clear(hash_map_entry_set_pt entrySet) {
+ hashMap_clear(entrySet->map, false, false);
+}
+
+bool hashMapEntrySet_isEmpty(hash_map_entry_set_pt entrySet) {
+ return hashMapEntrySet_size(entrySet) == 0;
+}
+
+void * hashMapEntry_getKey(hash_map_entry_pt entry) {
+ return entry->key;
+}
+
+void * hashMapEntry_getValue(hash_map_entry_pt entry) {
+ return entry->value;
+}
+
+
+
+
+
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/src/hash_map_private.h
----------------------------------------------------------------------
diff --git a/utils/src/hash_map_private.h b/utils/src/hash_map_private.h
new file mode 100644
index 0000000..cddf7a1
--- /dev/null
+++ b/utils/src/hash_map_private.h
@@ -0,0 +1,74 @@
+/**
+ *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.
+ */
+/*
+ * hash_map_private.h
+ *
+ * \date Jul 21, 2010
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef HASH_MAP_PRIVATE_H_
+#define HASH_MAP_PRIVATE_H_
+
+#include "exports.h"
+#include "hash_map.h"
+
+UTILS_EXPORT unsigned int hashMap_hashCode(const void* toHash);
+UTILS_EXPORT int hashMap_equals(const void* toCompare, const void* compare);
+
+void hashMap_resize(hash_map_pt map, int newCapacity);
+hash_map_entry_pt hashMap_removeEntryForKey(hash_map_pt map, const void* key);
+UTILS_EXPORT hash_map_entry_pt hashMap_removeMapping(hash_map_pt map, hash_map_entry_pt entry);
+void hashMap_addEntry(hash_map_pt map, int hash, void* key, void* value, int bucketIndex);
+
+struct hashMapEntry {
+ void* key;
+ void* value;
+ hash_map_entry_pt next;
+ unsigned int hash;
+};
+
+struct hashMap {
+ hash_map_entry_pt * table;
+ unsigned int size;
+ unsigned int treshold;
+ unsigned int modificationCount;
+ unsigned int tablelength;
+
+ unsigned int (*hashKey)(const void* key);
+ unsigned int (*hashValue)(const void* value);
+ int (*equalsKey)(const void* key1, const void* key2);
+ int (*equalsValue)(const void* value1, const void* value2);
+};
+
+struct hashMapKeySet {
+ hash_map_pt map;
+};
+
+struct hashMapValues {
+ hash_map_pt map;
+};
+
+struct hashMapEntrySet {
+ hash_map_pt map;
+};
+
+
+#endif /* HASH_MAP_PRIVATE_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/src/linked_list.c
----------------------------------------------------------------------
diff --git a/utils/src/linked_list.c b/utils/src/linked_list.c
new file mode 100644
index 0000000..235c3e7
--- /dev/null
+++ b/utils/src/linked_list.c
@@ -0,0 +1,268 @@
+/**
+ *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.c
+ *
+ * \date Jul 16, 2010
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include "celixbool.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "linked_list.h"
+#include "linked_list_private.h"
+
+celix_status_t linkedList_create(linked_list_pt *list) {
+ linked_list_pt linked_list = malloc(sizeof(*linked_list));
+ if (linked_list) {
+ linked_list->header = (linked_list_entry_pt) malloc(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;
+
+ *list = linked_list;
+
+ return CELIX_SUCCESS;
+ }
+ }
+
+ return CELIX_ENOMEM;
+}
+
+UTILS_EXPORT celix_status_t linkedList_destroy(linked_list_pt list) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ linked_list_entry_pt current = NULL;
+ linked_list_entry_pt next = NULL;
+
+ current = list->header->next;
+
+ while (current != list->header) {
+ next = current->next;
+ free(current);
+ current = next;
+ }
+
+ free(list->header);
+ free(list);
+
+ return status;
+}
+
+celix_status_t linkedList_clone(linked_list_pt list, linked_list_pt *clone) {
+ celix_status_t status;
+
+ status = linkedList_create(clone);
+ if (status == CELIX_SUCCESS) {
+ struct linked_list_entry *e;
+ for (e = list->header->next; e != list->header; e = e->next) {
+ linkedList_addElement(*clone, e->element);
+ }
+ }
+
+ return status;
+}
+
+void * linkedList_getFirst(linked_list_pt list) {
+ if (list->size == 0) {
+ return NULL;
+ }
+ return list->header->next->element;
+}
+
+void * linkedList_getLast(linked_list_pt list) {
+ if (list->size == 0) {
+ return NULL;
+ }
+ return list->header->previous->element;
+}
+
+void * linkedList_removeFirst(linked_list_pt list) {
+ return linkedList_removeEntry(list, list->header->next);
+}
+
+void * linkedList_removeLast(linked_list_pt list) {
+ return linkedList_removeEntry(list, list->header->previous);
+}
+
+void linkedList_addFirst(linked_list_pt list, void * element) {
+ linkedList_addBefore(list, element, list->header->next);
+}
+
+void linkedList_addLast(linked_list_pt list, void * element) {
+ linkedList_addBefore(list, element, list->header);
+}
+
+bool linkedList_contains(linked_list_pt list, void * element) {
+ return linkedList_indexOf(list, element) != -1;
+}
+
+int linkedList_size(linked_list_pt list) {
+ return list->size;
+}
+
+bool linkedList_isEmpty(linked_list_pt list) {
+ return linkedList_size(list) == 0;
+}
+
+bool linkedList_addElement(linked_list_pt list, void * element) {
+ linkedList_addBefore(list, element, list->header);
+ return true;
+}
+
+bool linkedList_removeElement(linked_list_pt list, void * element) {
+ if (element == NULL) {
+ linked_list_entry_pt entry;
+ for (entry = list->header->next; entry != list->header; entry = entry->next) {
+ if (entry->element == NULL) {
+ linkedList_removeEntry(list, entry);
+ return true;
+ }
+ }
+ } else {
+ linked_list_entry_pt entry;
+ for (entry = list->header->next; entry != list->header; entry = entry->next) {
+ if (element == entry->element) {
+ linkedList_removeEntry(list, entry);
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+void linkedList_clear(linked_list_pt list) {
+ linked_list_entry_pt entry = list->header->next;
+ while (entry != list->header) {
+ linked_list_entry_pt next = entry->next;
+ entry->next = entry->previous = NULL;
+ // free(entry->element);
+ entry->element = NULL;
+ free(entry);
+ entry = next;
+ }
+ list->header->next = list->header->previous = list->header;
+ list->size = 0;
+ list->modificationCount++;
+}
+
+void * linkedList_get(linked_list_pt list, int index) {
+ return linkedList_entry(list, index)->element;
+}
+void * linkedList_set(linked_list_pt list, int index, void * element) {
+ linked_list_entry_pt entry = linkedList_entry(list, index);
+ void * old = entry->element;
+ entry->element = element;
+ return old;
+}
+
+void linkedList_addIndex(linked_list_pt list, int index, void * element) {
+ linkedList_addBefore(list, element, (index == list->size ? list->header : linkedList_entry(list, index)));
+}
+
+void * linkedList_removeIndex(linked_list_pt list, int index) {
+ return linkedList_removeEntry(list, linkedList_entry(list, index));
+}
+
+linked_list_entry_pt linkedList_entry(linked_list_pt list, int index) {
+ linked_list_entry_pt entry;
+ int i;
+ if (index < 0 || index >= list->size) {
+ return NULL;
+ }
+
+ entry = list->header;
+ if (index < (list->size >> 1)) {
+ for (i = 0; i <= index; i++) {
+ entry = entry->next;
+ }
+ } else {
+ for (i = list->size; i > index; i--) {
+ entry = entry->previous;
+ }
+ }
+ return entry;
+}
+
+int linkedList_indexOf(linked_list_pt list, void * element) {
+ int index = 0;
+ if (element == NULL) {
+ linked_list_entry_pt entry;
+ for (entry = list->header->next; entry != list->header; entry = entry->next) {
+ if (entry->element == NULL) {
+ return index;
+ }
+ index++;
+ }
+ } else {
+ linked_list_entry_pt entry;
+ for (entry = list->header->next; entry != list->header; entry = entry->next) {
+ if (element == entry->element) {
+ return index;
+ }
+ index++;
+ }
+ }
+ return -1;
+}
+
+linked_list_entry_pt linkedList_addBefore(linked_list_pt list, void * element, linked_list_entry_pt entry) {
+ linked_list_entry_pt new = NULL;
+
+ new = malloc(sizeof(*new));
+ if (new != NULL) {
+
+ new->element = element;
+ new->next = entry;
+ new->previous = entry->previous;
+
+ new->previous->next = new;
+ new->next->previous = new;
+
+ list->size++;
+ list->modificationCount++;
+ }
+
+ return new;
+}
+
+void * linkedList_removeEntry(linked_list_pt list, linked_list_entry_pt entry) {
+ void * result;
+ if (entry == list->header) {
+ return NULL;
+ }
+
+ result = entry->element;
+
+ entry->previous->next = entry->next;
+ entry->next->previous = entry->previous;
+
+ entry->next = entry->previous = NULL;
+ free(entry);
+
+ list->size--;
+ list->modificationCount++;
+
+ return result;
+}