http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/include/celix_threads.h ---------------------------------------------------------------------- diff --git a/utils/include/celix_threads.h b/utils/include/celix_threads.h new file mode 100644 index 0000000..6af57bb --- /dev/null +++ b/utils/include/celix_threads.h @@ -0,0 +1,135 @@ +/** + *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.h + * + * \date 4 Jun 2014 + * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> + * \copyright Apache License, Version 2.0 + */ + +#ifndef CELIX_THREADS_H_ +#define CELIX_THREADS_H_ + +#include <pthread.h> +#include <stdbool.h> + +#include "celix_errno.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct celix_thread { + bool threadInitialized; + pthread_t thread; +}; + +typedef pthread_once_t celix_thread_once_t; +#define CELIX_THREAD_ONCE_INIT PTHREAD_ONCE_INIT + +typedef struct celix_thread celix_thread_t; +typedef pthread_attr_t celix_thread_attr_t; + +typedef void *(*celix_thread_start_t)(void *); + +static const celix_thread_t celix_thread_default = {0, 0}; + +celix_status_t +celixThread_create(celix_thread_t *new_thread, celix_thread_attr_t *attr, celix_thread_start_t func, void *data); + +void celixThread_exit(void *exitStatus); + +celix_status_t celixThread_detach(celix_thread_t thread); + +celix_status_t celixThread_join(celix_thread_t thread, void **status); + +celix_status_t celixThread_kill(celix_thread_t thread, int sig); + +celix_thread_t celixThread_self(void); + +int celixThread_equals(celix_thread_t thread1, celix_thread_t thread2); + +bool celixThread_initalized(celix_thread_t thread); + + +typedef pthread_mutex_t celix_thread_mutex_t; +typedef pthread_mutexattr_t celix_thread_mutexattr_t; + +//MUTEX TYPES +enum { + CELIX_THREAD_MUTEX_NORMAL, + CELIX_THREAD_MUTEX_RECURSIVE, + CELIX_THREAD_MUTEX_ERRORCHECK, + CELIX_THREAD_MUTEX_DEFAULT +}; + + +celix_status_t celixThreadMutex_create(celix_thread_mutex_t *mutex, celix_thread_mutexattr_t *attr); + +celix_status_t celixThreadMutex_destroy(celix_thread_mutex_t *mutex); + +celix_status_t celixThreadMutex_lock(celix_thread_mutex_t *mutex); + +celix_status_t celixThreadMutex_unlock(celix_thread_mutex_t *mutex); + +celix_status_t celixThreadMutexAttr_create(celix_thread_mutexattr_t *attr); + +celix_status_t celixThreadMutexAttr_destroy(celix_thread_mutexattr_t *attr); + +celix_status_t celixThreadMutexAttr_settype(celix_thread_mutexattr_t *attr, int type); + +typedef pthread_rwlock_t celix_thread_rwlock_t; +typedef pthread_rwlockattr_t celix_thread_rwlockattr_t; + +celix_status_t celixThreadRwlock_create(celix_thread_rwlock_t *lock, celix_thread_rwlockattr_t *attr); + +celix_status_t celixThreadRwlock_destroy(celix_thread_rwlock_t *lock); + +celix_status_t celixThreadRwlock_readLock(celix_thread_rwlock_t *lock); + +celix_status_t celixThreadRwlock_writeLock(celix_thread_rwlock_t *lock); + +celix_status_t celixThreadRwlock_unlock(celix_thread_rwlock_t *lock); + +celix_status_t celixThreadRwlockAttr_create(celix_thread_rwlockattr_t *attr); + +celix_status_t celixThreadRwlockAttr_destroy(celix_thread_rwlockattr_t *attr); +//NOTE: No support yet for setting specific rw lock attributes + + +typedef pthread_cond_t celix_thread_cond_t; +typedef pthread_condattr_t celix_thread_condattr_t; + +celix_status_t celixThreadCondition_init(celix_thread_cond_t *condition, celix_thread_condattr_t *attr); + +celix_status_t celixThreadCondition_destroy(celix_thread_cond_t *condition); + +celix_status_t celixThreadCondition_wait(celix_thread_cond_t *cond, celix_thread_mutex_t *mutex); + +celix_status_t celixThreadCondition_broadcast(celix_thread_cond_t *cond); + +celix_status_t celixThreadCondition_signal(celix_thread_cond_t *cond); + +celix_status_t celixThread_once(celix_thread_once_t *once_control, void (*init_routine)(void)); + +#ifdef __cplusplus +} +#endif +#endif /* CELIX_THREADS_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/include/celixbool.h ---------------------------------------------------------------------- diff --git a/utils/include/celixbool.h b/utils/include/celixbool.h new file mode 100644 index 0000000..526392b --- /dev/null +++ b/utils/include/celixbool.h @@ -0,0 +1,61 @@ +/* + *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. + */ +/* + * celixbool.h + * + * \date Jun 16, 2011 + * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> + * \copyright Apache License, Version 2.0 + */ + +#ifndef CELIXBOOL_H_ +#define CELIXBOOL_H_ + + +#if defined(__STDC__) +# define C89 +# if defined(__STDC_VERSION__) +# define C90 +# if (__STDC_VERSION__ >= 199409L) +# define C94 +# endif +# if (__STDC_VERSION__ >= 199901L) +# define C99 +# endif +# endif +#endif + + +#if __STDC_VERSION__ < 199901L && __GNUC__ < 3 +// #ifndef C99 + +typedef int _Bool; + +#define bool _Bool +#define false 0 +#define true 1 + + +#else + +#include <stdbool.h> + +#endif + +#endif /* CELIXBOOL_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/include/exports.h ---------------------------------------------------------------------- diff --git a/utils/include/exports.h b/utils/include/exports.h new file mode 100644 index 0000000..b128c88 --- /dev/null +++ b/utils/include/exports.h @@ -0,0 +1,49 @@ +/** + *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:[email protected]">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/include/hash_map.h ---------------------------------------------------------------------- diff --git a/utils/include/hash_map.h b/utils/include/hash_map.h new file mode 100644 index 0000000..28d386b --- /dev/null +++ b/utils/include/hash_map.h @@ -0,0 +1,161 @@ +/** + *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:[email protected]">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/include/linked_list.h ---------------------------------------------------------------------- diff --git a/utils/include/linked_list.h b/utils/include/linked_list.h new file mode 100644 index 0000000..cbf650c --- /dev/null +++ b/utils/include/linked_list.h @@ -0,0 +1,91 @@ +/** + *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:[email protected]">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/include/linked_list_iterator.h ---------------------------------------------------------------------- diff --git a/utils/include/linked_list_iterator.h b/utils/include/linked_list_iterator.h new file mode 100644 index 0000000..f765d5d --- /dev/null +++ b/utils/include/linked_list_iterator.h @@ -0,0 +1,66 @@ +/** + *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:[email protected]">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/include/memstream/README.md ---------------------------------------------------------------------- diff --git a/utils/include/memstream/README.md b/utils/include/memstream/README.md new file mode 100644 index 0000000..476810e --- /dev/null +++ b/utils/include/memstream/README.md @@ -0,0 +1,49 @@ +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/include/memstream/fmemopen.h ---------------------------------------------------------------------- diff --git a/utils/include/memstream/fmemopen.h b/utils/include/memstream/fmemopen.h new file mode 100644 index 0000000..3d06b20 --- /dev/null +++ b/utils/include/memstream/fmemopen.h @@ -0,0 +1,52 @@ +// +// 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/include/memstream/open_memstream.h ---------------------------------------------------------------------- diff --git a/utils/include/memstream/open_memstream.h b/utils/include/memstream/open_memstream.h new file mode 100644 index 0000000..e87bb0a --- /dev/null +++ b/utils/include/memstream/open_memstream.h @@ -0,0 +1,15 @@ +#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/include/properties.h ---------------------------------------------------------------------- diff --git a/utils/include/properties.h b/utils/include/properties.h new file mode 100644 index 0000000..cf93ca0 --- /dev/null +++ b/utils/include/properties.h @@ -0,0 +1,66 @@ +/** + *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:[email protected]">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/include/thpool.h ---------------------------------------------------------------------- diff --git a/utils/include/thpool.h b/utils/include/thpool.h new file mode 100644 index 0000000..0180aa6 --- /dev/null +++ b/utils/include/thpool.h @@ -0,0 +1,168 @@ +/********************************** + * @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/include/utils.h ---------------------------------------------------------------------- diff --git a/utils/include/utils.h b/utils/include/utils.h new file mode 100644 index 0000000..2fc7d44 --- /dev/null +++ b/utils/include/utils.h @@ -0,0 +1,61 @@ +/** + *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:[email protected]">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/include/version.h ---------------------------------------------------------------------- diff --git a/utils/include/version.h b/utils/include/version.h new file mode 100644 index 0000000..88e146a --- /dev/null +++ b/utils/include/version.h @@ -0,0 +1,186 @@ +/** + *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:[email protected]">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/include/version_range.h ---------------------------------------------------------------------- diff --git a/utils/include/version_range.h b/utils/include/version_range.h new file mode 100644 index 0000000..b661cd3 --- /dev/null +++ b/utils/include/version_range.h @@ -0,0 +1,160 @@ +/** + *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:[email protected]">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/private/include/array_list_private.h ---------------------------------------------------------------------- diff --git a/utils/private/include/array_list_private.h b/utils/private/include/array_list_private.h deleted file mode 100644 index bea2712..0000000 --- a/utils/private/include/array_list_private.h +++ /dev/null @@ -1,52 +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. - */ -/* - * array_list_private.h - * - * \date Aug 4, 2010 - * \author <a href="mailto:[email protected]">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/private/include/hash_map_private.h ---------------------------------------------------------------------- diff --git a/utils/private/include/hash_map_private.h b/utils/private/include/hash_map_private.h deleted file mode 100644 index cddf7a1..0000000 --- a/utils/private/include/hash_map_private.h +++ /dev/null @@ -1,74 +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_private.h - * - * \date Jul 21, 2010 - * \author <a href="mailto:[email protected]">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/private/include/linked_list_private.h ---------------------------------------------------------------------- diff --git a/utils/private/include/linked_list_private.h b/utils/private/include/linked_list_private.h deleted file mode 100644 index dcb0a46..0000000 --- a/utils/private/include/linked_list_private.h +++ /dev/null @@ -1,44 +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_private.h - * - * \date Jul 16, 2010 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#ifndef LINKED_LIST_PRIVATE_H_ -#define LINKED_LIST_PRIVATE_H_ - -#include "linked_list.h" - -struct linked_list_entry { - void * element; - struct linked_list_entry * next; - struct linked_list_entry * previous; -}; - -struct linked_list { - linked_list_entry_pt header; - size_t size; - int modificationCount; -}; - -#endif /* LINKED_LIST_PRIVATE_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/private/include/version_private.h ---------------------------------------------------------------------- diff --git a/utils/private/include/version_private.h b/utils/private/include/version_private.h deleted file mode 100644 index 15e5c89..0000000 --- a/utils/private/include/version_private.h +++ /dev/null @@ -1,41 +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_private.h - * - * \date Dec 18, 2012 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - - -#ifndef VERSION_PRIVATE_H_ -#define VERSION_PRIVATE_H_ - -#include "version.h" - -struct version { - int major; - int minor; - int micro; - char *qualifier; -}; - - -#endif /* VERSION_PRIVATE_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/private/include/version_range_private.h ---------------------------------------------------------------------- diff --git a/utils/private/include/version_range_private.h b/utils/private/include/version_range_private.h deleted file mode 100644 index dfccd59..0000000 --- a/utils/private/include/version_range_private.h +++ /dev/null @@ -1,41 +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_private.h - * - * \date Dec 18, 2012 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - - -#ifndef VERSION_RANGE_PRIVATE_H_ -#define VERSION_RANGE_PRIVATE_H_ - -#include "version_range.h" - -struct versionRange { - version_pt low; - bool isLowInclusive; - version_pt high; - bool isHighInclusive; - -}; - -#endif /* VERSION_RANGE_PRIVATE_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/utils/private/src/array_list.c ---------------------------------------------------------------------- diff --git a/utils/private/src/array_list.c b/utils/private/src/array_list.c deleted file mode 100644 index e7a2e30..0000000 --- a/utils/private/src/array_list.c +++ /dev/null @@ -1,337 +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. - */ -/* - * array_list.c - * - * \date Aug 4, 2010 - * \author <a href="mailto:[email protected]">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/private/src/celix_threads.c ---------------------------------------------------------------------- diff --git a/utils/private/src/celix_threads.c b/utils/private/src/celix_threads.c deleted file mode 100644 index 64bdf5b..0000000 --- a/utils/private/src/celix_threads.c +++ /dev/null @@ -1,184 +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. - */ -/* - * celix_threads.c - * - * \date 4 Jun 2014 - * \author <a href="mailto:[email protected]">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
