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 2018/01/30 19:29:45 UTC
[01/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Repository: celix
Updated Branches:
refs/heads/develop e78ecc565 -> 398da49c7
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/utils/private/src/md5.inl
----------------------------------------------------------------------
diff --git a/remote_services/utils/private/src/md5.inl b/remote_services/utils/private/src/md5.inl
deleted file mode 100644
index 4da933d..0000000
--- a/remote_services/utils/private/src/md5.inl
+++ /dev/null
@@ -1,461 +0,0 @@
-/*
- * This an amalgamation of md5.c and md5.h into a single file
- * with all static declaration to reduce linker conflicts
- * in Civetweb.
- *
- * The MD5_STATIC declaration was added to facilitate static
- * inclusion.
- * No Face Press, LLC
- */
-
-/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
-/*
- Independent implementation of MD5 (RFC 1321).
-
- This code implements the MD5 Algorithm defined in RFC 1321, whose
- text is available at
- http://www.ietf.org/rfc/rfc1321.txt
- The code is derived from the text of the RFC, including the test suite
- (section A.5) but excluding the rest of Appendix A. It does not include
- any code or documentation that is identified in the RFC as being
- copyrighted.
-
- The original and principal author of md5.h is L. Peter Deutsch
- <gh...@aladdin.com>. Other authors are noted in the change history
- that follows (in reverse chronological order):
-
- 2002-04-13 lpd Removed support for non-ANSI compilers; removed
- references to Ghostscript; clarified derivation from RFC 1321;
- now handles byte order either statically or dynamically.
- 1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
- 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
- added conditionalization for C++ compilation from Martin
- Purschke <pu...@bnl.gov>.
- 1999-05-03 lpd Original version.
- */
-
-#ifndef md5_INCLUDED
-# define md5_INCLUDED
-
-/*
- * This package supports both compile-time and run-time determination of CPU
- * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
- * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
- * defined as non-zero, the code will be compiled to run only on big-endian
- * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
- * run on either big- or little-endian CPUs, but will run slightly less
- * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
- */
-
-typedef unsigned char md5_byte_t; /* 8-bit byte */
-typedef unsigned int md5_word_t; /* 32-bit word */
-
-/* Define the state of the MD5 Algorithm. */
-typedef struct md5_state_s {
- md5_word_t count[2]; /* message length in bits, lsw first */
- md5_word_t abcd[4]; /* digest buffer */
- md5_byte_t buf[64]; /* accumulate block */
-} md5_state_t;
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/* Initialize the algorithm. */
-MD5_STATIC void md5_init(md5_state_t *pms);
-
-/* Append a string to the message. */
-MD5_STATIC void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);
-
-/* Finish the message and return the digest. */
-MD5_STATIC void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
-
-#ifdef __cplusplus
-} /* end extern "C" */
-#endif
-
-#endif /* md5_INCLUDED */
-
-/*
- Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved.
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- L. Peter Deutsch
- ghost@aladdin.com
-
- */
-/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */
-/*
- Independent implementation of MD5 (RFC 1321).
-
- This code implements the MD5 Algorithm defined in RFC 1321, whose
- text is available at
- http://www.ietf.org/rfc/rfc1321.txt
- The code is derived from the text of the RFC, including the test suite
- (section A.5) but excluding the rest of Appendix A. It does not include
- any code or documentation that is identified in the RFC as being
- copyrighted.
-
- The original and principal author of md5.c is L. Peter Deutsch
- <gh...@aladdin.com>. Other authors are noted in the change history
- that follows (in reverse chronological order):
-
- 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order
- either statically or dynamically; added missing #include <string.h>
- in library.
- 2002-03-11 lpd Corrected argument list for main(), and added int return
- type, in test program and T value program.
- 2002-02-21 lpd Added missing #include <stdio.h> in test program.
- 2000-07-03 lpd Patched to eliminate warnings about "constant is
- unsigned in ANSI C, signed in traditional"; made test program
- self-checking.
- 1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
- 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
- 1999-05-03 lpd Original version.
- */
-
-#ifndef MD5_STATIC
-#include <string.h>
-#endif
-
-#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
-#ifdef ARCH_IS_BIG_ENDIAN
-# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
-#else
-# define BYTE_ORDER 0
-#endif
-
-#define T_MASK ((md5_word_t)~0)
-#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87)
-#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9)
-#define T3 0x242070db
-#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111)
-#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050)
-#define T6 0x4787c62a
-#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec)
-#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe)
-#define T9 0x698098d8
-#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850)
-#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e)
-#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841)
-#define T13 0x6b901122
-#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c)
-#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71)
-#define T16 0x49b40821
-#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d)
-#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf)
-#define T19 0x265e5a51
-#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855)
-#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2)
-#define T22 0x02441453
-#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e)
-#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437)
-#define T25 0x21e1cde6
-#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829)
-#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278)
-#define T28 0x455a14ed
-#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa)
-#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07)
-#define T31 0x676f02d9
-#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375)
-#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd)
-#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e)
-#define T35 0x6d9d6122
-#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3)
-#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb)
-#define T38 0x4bdecfa9
-#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f)
-#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f)
-#define T41 0x289b7ec6
-#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805)
-#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a)
-#define T44 0x04881d05
-#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6)
-#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a)
-#define T47 0x1fa27cf8
-#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a)
-#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb)
-#define T50 0x432aff97
-#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58)
-#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6)
-#define T53 0x655b59c3
-#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d)
-#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82)
-#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e)
-#define T57 0x6fa87e4f
-#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f)
-#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb)
-#define T60 0x4e0811a1
-#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d)
-#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca)
-#define T63 0x2ad7d2bb
-#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e)
-
-
-static void
-md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
-{
- md5_word_t
- a = pms->abcd[0], b = pms->abcd[1],
- c = pms->abcd[2], d = pms->abcd[3];
- md5_word_t t;
-#if BYTE_ORDER > 0
- /* Define storage only for big-endian CPUs. */
- md5_word_t X[16];
-#else
- /* Define storage for little-endian or both types of CPUs. */
- md5_word_t xbuf[16];
- const md5_word_t *X;
-#endif
-
- {
-#if BYTE_ORDER == 0
- /*
- * Determine dynamically whether this is a big-endian or
- * little-endian machine, since we can use a more efficient
- * algorithm on the latter.
- */
- static const int w = 1;
-
- if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
-#endif
-#if BYTE_ORDER <= 0 /* little-endian */
- {
- /*
- * On little-endian machines, we can process properly aligned
- * data without copying it.
- */
- if (!((data - (const md5_byte_t *)0) & 3)) {
- /* data are properly aligned */
- X = (const md5_word_t *)data;
- } else {
- /* not aligned */
- memcpy(xbuf, data, 64);
- X = xbuf;
- }
- }
-#endif
-#if BYTE_ORDER == 0
- else /* dynamic big-endian */
-#endif
-#if BYTE_ORDER >= 0 /* big-endian */
- {
- /*
- * On big-endian machines, we must arrange the bytes in the
- * right order.
- */
- const md5_byte_t *xp = data;
- int i;
-
-# if BYTE_ORDER == 0
- X = xbuf; /* (dynamic only) */
-# else
-# define xbuf X /* (static only) */
-# endif
- for (i = 0; i < 16; ++i, xp += 4)
- xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
- }
-#endif
- }
-
-#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
-
- /* Round 1. */
- /* Let [abcd k s i] denote the operation
- a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
-#define F(x, y, z) (((x) & (y)) | (~(x) & (z)))
-#define SET(a, b, c, d, k, s, Ti)\
- t = a + F(b,c,d) + X[k] + Ti;\
- a = ROTATE_LEFT(t, s) + b
- /* Do the following 16 operations. */
- SET(a, b, c, d, 0, 7, T1);
- SET(d, a, b, c, 1, 12, T2);
- SET(c, d, a, b, 2, 17, T3);
- SET(b, c, d, a, 3, 22, T4);
- SET(a, b, c, d, 4, 7, T5);
- SET(d, a, b, c, 5, 12, T6);
- SET(c, d, a, b, 6, 17, T7);
- SET(b, c, d, a, 7, 22, T8);
- SET(a, b, c, d, 8, 7, T9);
- SET(d, a, b, c, 9, 12, T10);
- SET(c, d, a, b, 10, 17, T11);
- SET(b, c, d, a, 11, 22, T12);
- SET(a, b, c, d, 12, 7, T13);
- SET(d, a, b, c, 13, 12, T14);
- SET(c, d, a, b, 14, 17, T15);
- SET(b, c, d, a, 15, 22, T16);
-#undef SET
-
- /* Round 2. */
- /* Let [abcd k s i] denote the operation
- a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
-#define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
-#define SET(a, b, c, d, k, s, Ti)\
- t = a + G(b,c,d) + X[k] + Ti;\
- a = ROTATE_LEFT(t, s) + b
- /* Do the following 16 operations. */
- SET(a, b, c, d, 1, 5, T17);
- SET(d, a, b, c, 6, 9, T18);
- SET(c, d, a, b, 11, 14, T19);
- SET(b, c, d, a, 0, 20, T20);
- SET(a, b, c, d, 5, 5, T21);
- SET(d, a, b, c, 10, 9, T22);
- SET(c, d, a, b, 15, 14, T23);
- SET(b, c, d, a, 4, 20, T24);
- SET(a, b, c, d, 9, 5, T25);
- SET(d, a, b, c, 14, 9, T26);
- SET(c, d, a, b, 3, 14, T27);
- SET(b, c, d, a, 8, 20, T28);
- SET(a, b, c, d, 13, 5, T29);
- SET(d, a, b, c, 2, 9, T30);
- SET(c, d, a, b, 7, 14, T31);
- SET(b, c, d, a, 12, 20, T32);
-#undef SET
-
- /* Round 3. */
- /* Let [abcd k s t] denote the operation
- a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
-#define H(x, y, z) ((x) ^ (y) ^ (z))
-#define SET(a, b, c, d, k, s, Ti)\
- t = a + H(b,c,d) + X[k] + Ti;\
- a = ROTATE_LEFT(t, s) + b
- /* Do the following 16 operations. */
- SET(a, b, c, d, 5, 4, T33);
- SET(d, a, b, c, 8, 11, T34);
- SET(c, d, a, b, 11, 16, T35);
- SET(b, c, d, a, 14, 23, T36);
- SET(a, b, c, d, 1, 4, T37);
- SET(d, a, b, c, 4, 11, T38);
- SET(c, d, a, b, 7, 16, T39);
- SET(b, c, d, a, 10, 23, T40);
- SET(a, b, c, d, 13, 4, T41);
- SET(d, a, b, c, 0, 11, T42);
- SET(c, d, a, b, 3, 16, T43);
- SET(b, c, d, a, 6, 23, T44);
- SET(a, b, c, d, 9, 4, T45);
- SET(d, a, b, c, 12, 11, T46);
- SET(c, d, a, b, 15, 16, T47);
- SET(b, c, d, a, 2, 23, T48);
-#undef SET
-
- /* Round 4. */
- /* Let [abcd k s t] denote the operation
- a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
-#define I(x, y, z) ((y) ^ ((x) | ~(z)))
-#define SET(a, b, c, d, k, s, Ti)\
- t = a + I(b,c,d) + X[k] + Ti;\
- a = ROTATE_LEFT(t, s) + b
- /* Do the following 16 operations. */
- SET(a, b, c, d, 0, 6, T49);
- SET(d, a, b, c, 7, 10, T50);
- SET(c, d, a, b, 14, 15, T51);
- SET(b, c, d, a, 5, 21, T52);
- SET(a, b, c, d, 12, 6, T53);
- SET(d, a, b, c, 3, 10, T54);
- SET(c, d, a, b, 10, 15, T55);
- SET(b, c, d, a, 1, 21, T56);
- SET(a, b, c, d, 8, 6, T57);
- SET(d, a, b, c, 15, 10, T58);
- SET(c, d, a, b, 6, 15, T59);
- SET(b, c, d, a, 13, 21, T60);
- SET(a, b, c, d, 4, 6, T61);
- SET(d, a, b, c, 11, 10, T62);
- SET(c, d, a, b, 2, 15, T63);
- SET(b, c, d, a, 9, 21, T64);
-#undef SET
-
- /* Then perform the following additions. (That is increment each
- of the four registers by the value it had before this block
- was started.) */
- pms->abcd[0] += a;
- pms->abcd[1] += b;
- pms->abcd[2] += c;
- pms->abcd[3] += d;
-}
-
-MD5_STATIC void
-md5_init(md5_state_t *pms)
-{
- pms->count[0] = pms->count[1] = 0;
- pms->abcd[0] = 0x67452301;
- pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476;
- pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301;
- pms->abcd[3] = 0x10325476;
-}
-
-MD5_STATIC void
-md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
-{
- const md5_byte_t *p = data;
- int left = nbytes;
- int offset = (pms->count[0] >> 3) & 63;
- md5_word_t nbits = (md5_word_t)(nbytes << 3);
-
- if (nbytes <= 0)
- return;
-
- /* Update the message length. */
- pms->count[1] += nbytes >> 29;
- pms->count[0] += nbits;
- if (pms->count[0] < nbits)
- pms->count[1]++;
-
- /* Process an initial partial block. */
- if (offset) {
- int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
-
- memcpy(pms->buf + offset, p, copy);
- if (offset + copy < 64)
- return;
- p += copy;
- left -= copy;
- md5_process(pms, pms->buf);
- }
-
- /* Process full blocks. */
- for (; left >= 64; p += 64, left -= 64)
- md5_process(pms, p);
-
- /* Process a final partial block. */
- if (left)
- memcpy(pms->buf, p, left);
-}
-
-MD5_STATIC void
-md5_finish(md5_state_t *pms, md5_byte_t digest[16])
-{
- static const md5_byte_t pad[64] = {
- 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- };
- md5_byte_t data[8];
- int i;
-
- /* Save the length before padding. */
- for (i = 0; i < 8; ++i)
- data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
- /* Pad to 56 bytes mod 64. */
- md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
- /* Append the length. */
- md5_append(pms, data, 8);
- for (i = 0; i < 16; ++i)
- digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/shell/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt
index 31822c4..ae8cf3f 100644
--- a/shell/CMakeLists.txt
+++ b/shell/CMakeLists.txt
@@ -39,7 +39,7 @@ if (SHELL)
src/help_command
)
target_include_directories(shell PRIVATE src ${CURL_INCLUDE_DIRS})
- target_link_libraries(shell PRIVATE Celix::shell_api ${CURL_LIBRARIES} Celix::log_service_api log_helper)
+ target_link_libraries(shell PRIVATE Celix::shell_api ${CURL_LIBRARIES} Celix::log_service_api Celix::log_helper)
install_bundle(shell
HEADERS
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/shell/README.md
----------------------------------------------------------------------
diff --git a/shell/README.md b/shell/README.md
index 76f1cc7..a20450c 100644
--- a/shell/README.md
+++ b/shell/README.md
@@ -30,4 +30,5 @@ ANSI colors when printing info. default is true.
## Using info
If the Celix Shell is installed The `FindCelix.cmake` will set:
- - The `Celix::dependency_manager_cxx_static` library target
+ - The `Celix::shell_api` interface (i.e. header only) library target
+ - The `Celix::shell` bundle target
[40/54] [abbrv] celix git commit: CELIX-417: Refactors cmake usage of
pubsub and rsa. Started with installing exported targets
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/private/src/psa_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/private/src/psa_activator.c b/pubsub/pubsub_admin_zmq/private/src/psa_activator.c
deleted file mode 100644
index fd07310..0000000
--- a/pubsub/pubsub_admin_zmq/private/src/psa_activator.c
+++ /dev/null
@@ -1,142 +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.
- */
-/*
- * psa_activator.c
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-
-#include "bundle_activator.h"
-#include "service_registration.h"
-#include "service_tracker.h"
-
-#include "pubsub_admin_impl.h"
-
-
-struct activator {
- pubsub_admin_pt admin;
- pubsub_admin_service_pt adminService;
- service_registration_pt registration;
- service_tracker_pt serializerTracker;
-};
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator;
-
- activator = calloc(1, sizeof(*activator));
- if (!activator) {
- status = CELIX_ENOMEM;
- }
- else{
- *userData = activator;
-
- status = pubsubAdmin_create(context, &(activator->admin));
-
- if(status == CELIX_SUCCESS){
- service_tracker_customizer_pt customizer = NULL;
- status = serviceTrackerCustomizer_create(activator->admin,
- NULL,
- pubsubAdmin_serializerAdded,
- NULL,
- pubsubAdmin_serializerRemoved,
- &customizer);
- if(status == CELIX_SUCCESS){
- status = serviceTracker_create(context, PUBSUB_SERIALIZER_SERVICE, customizer, &(activator->serializerTracker));
- if(status != CELIX_SUCCESS){
- serviceTrackerCustomizer_destroy(customizer);
- pubsubAdmin_destroy(activator->admin);
- }
- }
- else{
- pubsubAdmin_destroy(activator->admin);
- }
- }
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
- pubsub_admin_service_pt pubsubAdminSvc = calloc(1, sizeof(*pubsubAdminSvc));
-
- if (!pubsubAdminSvc) {
- status = CELIX_ENOMEM;
- }
- else{
- pubsubAdminSvc->admin = activator->admin;
-
- pubsubAdminSvc->addPublication = pubsubAdmin_addPublication;
- pubsubAdminSvc->removePublication = pubsubAdmin_removePublication;
-
- pubsubAdminSvc->addSubscription = pubsubAdmin_addSubscription;
- pubsubAdminSvc->removeSubscription = pubsubAdmin_removeSubscription;
-
- pubsubAdminSvc->closeAllPublications = pubsubAdmin_closeAllPublications;
- pubsubAdminSvc->closeAllSubscriptions = pubsubAdmin_closeAllSubscriptions;
-
- pubsubAdminSvc->matchEndpoint = pubsubAdmin_matchEndpoint;
-
- activator->adminService = pubsubAdminSvc;
-
- status = bundleContext_registerService(context, PUBSUB_ADMIN_SERVICE, pubsubAdminSvc, NULL, &activator->registration);
-
- status += serviceTracker_open(activator->serializerTracker);
-
- }
-
-
- return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- status += serviceTracker_close(activator->serializerTracker);
- status += serviceRegistration_unregister(activator->registration);
-
- activator->registration = NULL;
-
- free(activator->adminService);
- activator->adminService = NULL;
-
- return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- serviceTracker_destroy(activator->serializerTracker);
- pubsubAdmin_destroy(activator->admin);
- activator->admin = NULL;
-
- free(activator);
-
- return status;
-}
-
-
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/private/src/pubsub_admin_impl.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/private/src/pubsub_admin_impl.c b/pubsub/pubsub_admin_zmq/private/src/pubsub_admin_impl.c
deleted file mode 100644
index 29ead0c..0000000
--- a/pubsub/pubsub_admin_zmq/private/src/pubsub_admin_impl.c
+++ /dev/null
@@ -1,1040 +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.
- */
-/*
- * pubsub_admin_impl.c
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include "pubsub_admin_impl.h"
-#include <zmq.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <netdb.h>
-
-#ifndef ANDROID
-#include <ifaddrs.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "constants.h"
-#include "utils.h"
-#include "hash_map.h"
-#include "array_list.h"
-#include "bundle_context.h"
-#include "bundle.h"
-#include "service_reference.h"
-#include "service_registration.h"
-#include "log_helper.h"
-#include "log_service.h"
-#include "celix_threads.h"
-#include "service_factory.h"
-
-#include "topic_subscription.h"
-#include "topic_publication.h"
-#include "pubsub_endpoint.h"
-#include "pubsub_utils.h"
-#include "subscriber.h"
-
-#define MAX_KEY_FOLDER_PATH_LENGTH 512
-
-static const char *DEFAULT_IP = "127.0.0.1";
-
-static celix_status_t pubsubAdmin_getIpAdress(const char* interface, char** ip);
-static celix_status_t pubsubAdmin_addSubscriptionToPendingList(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
-static celix_status_t pubsubAdmin_addAnySubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
-
-static celix_status_t pubsubAdmin_getBestSerializer(pubsub_admin_pt admin,pubsub_endpoint_pt ep, pubsub_serializer_service_t **serSvc);
-static void connectTopicPubSubToSerializer(pubsub_admin_pt admin,pubsub_serializer_service_t *serializer,void *topicPubSub,bool isPublication);
-static void disconnectTopicPubSubFromSerializer(pubsub_admin_pt admin,void *topicPubSub,bool isPublication);
-
-celix_status_t pubsubAdmin_create(bundle_context_pt context, pubsub_admin_pt *admin) {
- celix_status_t status = CELIX_SUCCESS;
-
-#ifdef BUILD_WITH_ZMQ_SECURITY
- if (!zsys_has_curve()){
- printf("PSA_ZMQ: zeromq curve unsupported\n");
- return CELIX_SERVICE_EXCEPTION;
- }
-#endif
-
- *admin = calloc(1, sizeof(**admin));
-
- if (!*admin) {
- status = CELIX_ENOMEM;
- }
- else{
-
- const char *ip = NULL;
- char *detectedIp = NULL;
- (*admin)->bundle_context= context;
- (*admin)->localPublications = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- (*admin)->subscriptions = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- (*admin)->pendingSubscriptions = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- (*admin)->externalPublications = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- (*admin)->topicSubscriptionsPerSerializer = hashMap_create(NULL, NULL, NULL, NULL);
- (*admin)->topicPublicationsPerSerializer = hashMap_create(NULL, NULL, NULL, NULL);
- arrayList_create(&((*admin)->noSerializerSubscriptions));
- arrayList_create(&((*admin)->noSerializerPublications));
- arrayList_create(&((*admin)->serializerList));
-
- celixThreadMutex_create(&(*admin)->localPublicationsLock, NULL);
- celixThreadMutex_create(&(*admin)->subscriptionsLock, NULL);
- celixThreadMutex_create(&(*admin)->externalPublicationsLock, NULL);
- celixThreadMutex_create(&(*admin)->serializerListLock, NULL);
- celixThreadMutex_create(&(*admin)->usedSerializersLock, NULL);
-
- celixThreadMutexAttr_create(&(*admin)->noSerializerPendingsAttr);
- celixThreadMutexAttr_settype(&(*admin)->noSerializerPendingsAttr, CELIX_THREAD_MUTEX_RECURSIVE);
- celixThreadMutex_create(&(*admin)->noSerializerPendingsLock, &(*admin)->noSerializerPendingsAttr);
-
- celixThreadMutexAttr_create(&(*admin)->pendingSubscriptionsAttr);
- celixThreadMutexAttr_settype(&(*admin)->pendingSubscriptionsAttr, CELIX_THREAD_MUTEX_RECURSIVE);
- celixThreadMutex_create(&(*admin)->pendingSubscriptionsLock, &(*admin)->pendingSubscriptionsAttr);
-
- if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
- logHelper_start((*admin)->loghelper);
- }
-
- bundleContext_getProperty(context,PSA_IP , &ip);
-
-#ifndef ANDROID
- if (ip == NULL) {
- const char *interface = NULL;
-
- bundleContext_getProperty(context, PSA_ITF, &interface);
- if (pubsubAdmin_getIpAdress(interface, &detectedIp) != CELIX_SUCCESS) {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "PSA_ZMQ: Could not retrieve IP adress for interface %s", interface);
- }
-
- ip = detectedIp;
- }
-#endif
-
- if (ip != NULL) {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "PSA_ZMQ: Using %s for service annunciation", ip);
- (*admin)->ipAddress = strdup(ip);
- }
- else {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "PSA_ZMQ: No IP address for service annunciation set. Using %s", DEFAULT_IP);
- (*admin)->ipAddress = strdup(DEFAULT_IP);
- }
-
- if (detectedIp != NULL) {
- free(detectedIp);
- }
-
- const char* basePortStr = NULL;
- const char* maxPortStr = NULL;
- char* endptrBase = NULL;
- char* endptrMax = NULL;
- bundleContext_getPropertyWithDefault(context, PSA_ZMQ_BASE_PORT, "PSA_ZMQ_DEFAULT_BASE_PORT", &basePortStr);
- bundleContext_getPropertyWithDefault(context, PSA_ZMQ_MAX_PORT, "PSA_ZMQ_DEFAULT_MAX_PORT", &maxPortStr);
- (*admin)->basePort = strtol(basePortStr, &endptrBase, 10);
- (*admin)->maxPort = strtol(maxPortStr, &endptrMax, 10);
- if (*endptrBase != '\0') {
- (*admin)->basePort = PSA_ZMQ_DEFAULT_BASE_PORT;
- }
- if (*endptrMax != '\0') {
- (*admin)->maxPort = PSA_ZMQ_DEFAULT_MAX_PORT;
- }
-
- printf("PSA Using base port %u to max port %u\n", (*admin)->basePort, (*admin)->maxPort);
-
- // Disable Signal Handling by CZMQ
- setenv("ZSYS_SIGHANDLER", "false", true);
-
- const char *nrZmqThreads = NULL;
- bundleContext_getProperty(context, "PSA_NR_ZMQ_THREADS", &nrZmqThreads);
-
- if(nrZmqThreads != NULL) {
- char *endPtr = NULL;
- unsigned int nrThreads = strtoul(nrZmqThreads, &endPtr, 10);
- if(endPtr != nrZmqThreads && nrThreads > 0 && nrThreads < 50) {
- zsys_set_io_threads(nrThreads);
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "PSA_ZMQ: Using %d threads for ZMQ", nrThreads);
- printf("PSA_ZMQ: Using %d threads for ZMQ\n", nrThreads);
- }
- }
-
-#ifdef BUILD_WITH_ZMQ_SECURITY
- // Setup authenticator
- zactor_t* auth = zactor_new (zauth, NULL);
- zstr_sendx(auth, "VERBOSE", NULL);
-
- // Load all public keys of subscribers into the application
- // This step is done for authenticating subscribers
- char curve_folder_path[MAX_KEY_FOLDER_PATH_LENGTH];
- char* keys_bundle_dir = pubsub_getKeysBundleDir(context);
- snprintf(curve_folder_path, MAX_KEY_FOLDER_PATH_LENGTH, "%s/META-INF/keys/subscriber/public", keys_bundle_dir);
- zstr_sendx (auth, "CURVE", curve_folder_path, NULL);
- free(keys_bundle_dir);
-
- (*admin)->zmq_auth = auth;
-#endif
-
- }
-
- return status;
-}
-
-
-celix_status_t pubsubAdmin_destroy(pubsub_admin_pt admin)
-{
- celix_status_t status = CELIX_SUCCESS;
-
- free(admin->ipAddress);
-
- celixThreadMutex_lock(&admin->pendingSubscriptionsLock);
- hash_map_iterator_pt iter = hashMapIterator_create(admin->pendingSubscriptions);
- while(hashMapIterator_hasNext(iter)){
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- free((char*)hashMapEntry_getKey(entry));
- arrayList_destroy((array_list_pt)hashMapEntry_getValue(entry));
- }
- hashMapIterator_destroy(iter);
- hashMap_destroy(admin->pendingSubscriptions,false,false);
- celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);
-
- celixThreadMutex_lock(&admin->subscriptionsLock);
- hashMap_destroy(admin->subscriptions,false,false);
- celixThreadMutex_unlock(&admin->subscriptionsLock);
-
- celixThreadMutex_lock(&admin->localPublicationsLock);
- hashMap_destroy(admin->localPublications,true,false);
- celixThreadMutex_unlock(&admin->localPublicationsLock);
-
- celixThreadMutex_lock(&admin->externalPublicationsLock);
- iter = hashMapIterator_create(admin->externalPublications);
- while(hashMapIterator_hasNext(iter)){
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- free((char*)hashMapEntry_getKey(entry));
- arrayList_destroy((array_list_pt)hashMapEntry_getValue(entry));
- }
- hashMapIterator_destroy(iter);
- hashMap_destroy(admin->externalPublications,false,false);
- celixThreadMutex_unlock(&admin->externalPublicationsLock);
-
- celixThreadMutex_lock(&admin->serializerListLock);
- arrayList_destroy(admin->serializerList);
- celixThreadMutex_unlock(&admin->serializerListLock);
-
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
- arrayList_destroy(admin->noSerializerSubscriptions);
- arrayList_destroy(admin->noSerializerPublications);
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
-
-
- celixThreadMutex_lock(&admin->usedSerializersLock);
-
- iter = hashMapIterator_create(admin->topicSubscriptionsPerSerializer);
- while(hashMapIterator_hasNext(iter)){
- arrayList_destroy((array_list_pt)hashMapIterator_nextValue(iter));
- }
- hashMapIterator_destroy(iter);
- hashMap_destroy(admin->topicSubscriptionsPerSerializer,false,false);
-
- iter = hashMapIterator_create(admin->topicPublicationsPerSerializer);
- while(hashMapIterator_hasNext(iter)){
- arrayList_destroy((array_list_pt)hashMapIterator_nextValue(iter));
- }
- hashMapIterator_destroy(iter);
- hashMap_destroy(admin->topicPublicationsPerSerializer,false,false);
-
- celixThreadMutex_unlock(&admin->usedSerializersLock);
-
- celixThreadMutex_destroy(&admin->usedSerializersLock);
- celixThreadMutex_destroy(&admin->serializerListLock);
- celixThreadMutex_destroy(&admin->pendingSubscriptionsLock);
-
- celixThreadMutexAttr_destroy(&admin->noSerializerPendingsAttr);
- celixThreadMutex_destroy(&admin->noSerializerPendingsLock);
-
- celixThreadMutexAttr_destroy(&admin->pendingSubscriptionsAttr);
- celixThreadMutex_destroy(&admin->subscriptionsLock);
-
- celixThreadMutex_destroy(&admin->localPublicationsLock);
- celixThreadMutex_destroy(&admin->externalPublicationsLock);
-
- logHelper_stop(admin->loghelper);
-
- logHelper_destroy(&admin->loghelper);
-
-#ifdef BUILD_WITH_ZMQ_SECURITY
- if (admin->zmq_auth != NULL){
- zactor_destroy(&(admin->zmq_auth));
- }
-#endif
-
- free(admin);
-
- return status;
-}
-
-static celix_status_t pubsubAdmin_addAnySubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&admin->subscriptionsLock);
-
- topic_subscription_pt any_sub = hashMap_get(admin->subscriptions,PUBSUB_ANY_SUB_TOPIC);
-
- if(any_sub==NULL){
-
- int i;
- pubsub_serializer_service_t *best_serializer = NULL;
- if( (status=pubsubAdmin_getBestSerializer(admin, subEP, &best_serializer)) == CELIX_SUCCESS){
- status = pubsub_topicSubscriptionCreate(admin->bundle_context, PUBSUB_SUBSCRIBER_SCOPE_DEFAULT, PUBSUB_ANY_SUB_TOPIC, best_serializer, &any_sub);
- }
- else{
- printf("PSA_ZMQ: Cannot find a serializer for subscribing topic %s. Adding it to pending list.\n",subEP->topic);
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
- arrayList_add(admin->noSerializerSubscriptions,subEP);
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
- }
-
- if (status == CELIX_SUCCESS){
-
- /* Connect all internal publishers */
- celixThreadMutex_lock(&admin->localPublicationsLock);
- hash_map_iterator_pt lp_iter =hashMapIterator_create(admin->localPublications);
- while(hashMapIterator_hasNext(lp_iter)){
- service_factory_pt factory = (service_factory_pt)hashMapIterator_nextValue(lp_iter);
- topic_publication_pt topic_pubs = (topic_publication_pt)factory->handle;
- array_list_pt topic_publishers = pubsub_topicPublicationGetPublisherList(topic_pubs);
-
- if(topic_publishers!=NULL){
- for(i=0;i<arrayList_size(topic_publishers);i++){
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(topic_publishers,i);
- if(pubEP->endpoint !=NULL){
- status += pubsub_topicSubscriptionConnectPublisher(any_sub,pubEP->endpoint);
- }
- }
- arrayList_destroy(topic_publishers);
- }
- }
- hashMapIterator_destroy(lp_iter);
- celixThreadMutex_unlock(&admin->localPublicationsLock);
-
- /* Connect also all external publishers */
- celixThreadMutex_lock(&admin->externalPublicationsLock);
- hash_map_iterator_pt extp_iter =hashMapIterator_create(admin->externalPublications);
- while(hashMapIterator_hasNext(extp_iter)){
- array_list_pt ext_pub_list = (array_list_pt)hashMapIterator_nextValue(extp_iter);
- if(ext_pub_list!=NULL){
- for(i=0;i<arrayList_size(ext_pub_list);i++){
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
- if(pubEP->endpoint !=NULL){
- status += pubsub_topicSubscriptionConnectPublisher(any_sub,pubEP->endpoint);
- }
- }
- }
- }
- hashMapIterator_destroy(extp_iter);
- celixThreadMutex_unlock(&admin->externalPublicationsLock);
-
-
- pubsub_topicSubscriptionAddSubscriber(any_sub,subEP);
-
- status += pubsub_topicSubscriptionStart(any_sub);
-
- }
-
- if (status == CELIX_SUCCESS){
- hashMap_put(admin->subscriptions,strdup(PUBSUB_ANY_SUB_TOPIC),any_sub);
- connectTopicPubSubToSerializer(admin, best_serializer, any_sub, false);
- }
-
- }
-
- celixThreadMutex_unlock(&admin->subscriptionsLock);
-
- return status;
-}
-
-celix_status_t pubsubAdmin_addSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
- celix_status_t status = CELIX_SUCCESS;
-
- printf("PSA_ZMQ: Received subscription [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n",subEP->frameworkUUID,subEP->serviceID,subEP->scope, subEP->topic);
-
- if(strcmp(subEP->topic,PUBSUB_ANY_SUB_TOPIC)==0){
- return pubsubAdmin_addAnySubscription(admin,subEP);
- }
-
- /* Check if we already know some publisher about this topic, otherwise let's put the subscription in the pending hashmap */
- celixThreadMutex_lock(&admin->pendingSubscriptionsLock);
- celixThreadMutex_lock(&admin->subscriptionsLock);
- celixThreadMutex_lock(&admin->localPublicationsLock);
- celixThreadMutex_lock(&admin->externalPublicationsLock);
-
- char* scope_topic = createScopeTopicKey(subEP->scope, subEP->topic);
-
- service_factory_pt factory = (service_factory_pt)hashMap_get(admin->localPublications,scope_topic);
- array_list_pt ext_pub_list = (array_list_pt)hashMap_get(admin->externalPublications,scope_topic);
-
- if(factory==NULL && ext_pub_list==NULL){ //No (local or external) publishers yet for this topic
- pubsubAdmin_addSubscriptionToPendingList(admin,subEP);
- }
- else{
- int i;
- topic_subscription_pt subscription = hashMap_get(admin->subscriptions, scope_topic);
-
- if(subscription == NULL) {
- pubsub_serializer_service_t *best_serializer = NULL;
- if( (status=pubsubAdmin_getBestSerializer(admin, subEP, &best_serializer)) == CELIX_SUCCESS){
- status += pubsub_topicSubscriptionCreate(admin->bundle_context,subEP->scope, subEP->topic, best_serializer, &subscription);
- }
- else{
- printf("PSA_ZMQ: Cannot find a serializer for subscribing topic %s. Adding it to pending list.\n",subEP->topic);
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
- arrayList_add(admin->noSerializerSubscriptions,subEP);
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
- }
-
- if (status==CELIX_SUCCESS){
-
- /* Try to connect internal publishers */
- if(factory!=NULL){
- topic_publication_pt topic_pubs = (topic_publication_pt)factory->handle;
- array_list_pt topic_publishers = pubsub_topicPublicationGetPublisherList(topic_pubs);
-
- if(topic_publishers!=NULL){
- for(i=0;i<arrayList_size(topic_publishers);i++){
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(topic_publishers,i);
- if(pubEP->endpoint !=NULL){
- status += pubsub_topicSubscriptionConnectPublisher(subscription,pubEP->endpoint);
- }
- }
- arrayList_destroy(topic_publishers);
- }
-
- }
-
- /* Look also for external publishers */
- if(ext_pub_list!=NULL){
- for(i=0;i<arrayList_size(ext_pub_list);i++){
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
- if(pubEP->endpoint !=NULL){
- status += pubsub_topicSubscriptionConnectPublisher(subscription,pubEP->endpoint);
- }
- }
- }
-
- pubsub_topicSubscriptionAddSubscriber(subscription,subEP);
-
- status += pubsub_topicSubscriptionStart(subscription);
-
- }
-
- if(status==CELIX_SUCCESS){
-
- hashMap_put(admin->subscriptions,strdup(scope_topic),subscription);
-
- connectTopicPubSubToSerializer(admin, best_serializer, subscription, false);
- }
- }
-
- if (status == CELIX_SUCCESS){
- pubsub_topicIncreaseNrSubscribers(subscription);
- }
- }
-
- free(scope_topic);
- celixThreadMutex_unlock(&admin->externalPublicationsLock);
- celixThreadMutex_unlock(&admin->localPublicationsLock);
- celixThreadMutex_unlock(&admin->subscriptionsLock);
- celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);
-
- return status;
-
-}
-
-celix_status_t pubsubAdmin_removeSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
- celix_status_t status = CELIX_SUCCESS;
-
- printf("PSA_ZMQ: Removing subscription [FWUUID=%s bundleID=%ld topic=%s]\n",subEP->frameworkUUID,subEP->serviceID,subEP->topic);
-
- char* scope_topic = createScopeTopicKey(subEP->scope, subEP->topic);
-
- celixThreadMutex_lock(&admin->subscriptionsLock);
- topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic);
- if(sub!=NULL){
- pubsub_topicDecreaseNrSubscribers(sub);
- if(pubsub_topicGetNrSubscribers(sub) == 0) {
- status = pubsub_topicSubscriptionRemoveSubscriber(sub,subEP);
- }
- }
- celixThreadMutex_unlock(&admin->subscriptionsLock);
-
- if(sub==NULL){
- /* Maybe the endpoint was pending */
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
- if(!arrayList_removeElement(admin->noSerializerSubscriptions, subEP)){
- status = CELIX_ILLEGAL_STATE;
- }
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
- }
-
- free(scope_topic);
-
-
-
- return status;
-
-}
-
-celix_status_t pubsubAdmin_addPublication(pubsub_admin_pt admin, pubsub_endpoint_pt pubEP) {
- celix_status_t status = CELIX_SUCCESS;
-
- printf("PSA_ZMQ: Received publication [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n", pubEP->frameworkUUID, pubEP->serviceID, pubEP->scope, pubEP->topic);
-
- const char* fwUUID = NULL;
-
- bundleContext_getProperty(admin->bundle_context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &fwUUID);
- if (fwUUID == NULL) {
- printf("PSA_ZMQ: Cannot retrieve fwUUID.\n");
- return CELIX_INVALID_BUNDLE_CONTEXT;
- }
-
- char *scope_topic = createScopeTopicKey(pubEP->scope, pubEP->topic);
-
- if ((strcmp(pubEP->frameworkUUID, fwUUID) == 0) && (pubEP->endpoint == NULL)) {
-
- celixThreadMutex_lock(&admin->localPublicationsLock);
-
- service_factory_pt factory = (service_factory_pt) hashMap_get(admin->localPublications, scope_topic);
-
- if (factory == NULL) {
- topic_publication_pt pub = NULL;
- pubsub_serializer_service_t *best_serializer = NULL;
- if( (status=pubsubAdmin_getBestSerializer(admin, pubEP, &best_serializer)) == CELIX_SUCCESS){
- status = pubsub_topicPublicationCreate(admin->bundle_context, pubEP, best_serializer, admin->ipAddress, admin->basePort, admin->maxPort, &pub);
- }
- else{
- printf("PSA_ZMQ: Cannot find a serializer for publishing topic %s. Adding it to pending list.\n", pubEP->topic);
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
- arrayList_add(admin->noSerializerPublications,pubEP);
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
- }
-
- if (status == CELIX_SUCCESS) {
- status = pubsub_topicPublicationStart(admin->bundle_context, pub, &factory);
- if (status == CELIX_SUCCESS && factory != NULL) {
- hashMap_put(admin->localPublications, strdup(scope_topic), factory);
- connectTopicPubSubToSerializer(admin, best_serializer, pub, true);
- }
- } else {
- printf("PSA_ZMQ: Cannot create a topicPublication for scope=%s, topic=%s (bundle %ld).\n", pubEP->scope, pubEP->topic, pubEP->serviceID);
- }
- } else {
- //just add the new EP to the list
- topic_publication_pt pub = (topic_publication_pt) factory->handle;
- pubsub_topicPublicationAddPublisherEP(pub, pubEP);
- }
-
- celixThreadMutex_unlock(&admin->localPublicationsLock);
- }
- else{
-
- celixThreadMutex_lock(&admin->externalPublicationsLock);
- array_list_pt ext_pub_list = (array_list_pt) hashMap_get(admin->externalPublications, scope_topic);
- if (ext_pub_list == NULL) {
- arrayList_create(&ext_pub_list);
- hashMap_put(admin->externalPublications, strdup(scope_topic), ext_pub_list);
- }
-
- arrayList_add(ext_pub_list, pubEP);
-
- celixThreadMutex_unlock(&admin->externalPublicationsLock);
- }
-
- /* Re-evaluate the pending subscriptions */
- celixThreadMutex_lock(&admin->pendingSubscriptionsLock);
-
- hash_map_entry_pt pendingSub = hashMap_getEntry(admin->pendingSubscriptions, scope_topic);
- if (pendingSub != NULL) { //There were pending subscription for the just published topic. Let's connect them.
- char* topic = (char*) hashMapEntry_getKey(pendingSub);
- array_list_pt pendingSubList = (array_list_pt) hashMapEntry_getValue(pendingSub);
- int i;
- for (i = 0; i < arrayList_size(pendingSubList); i++) {
- pubsub_endpoint_pt subEP = (pubsub_endpoint_pt) arrayList_get(pendingSubList, i);
- pubsubAdmin_addSubscription(admin, subEP);
- }
- hashMap_remove(admin->pendingSubscriptions, scope_topic);
- arrayList_clear(pendingSubList);
- arrayList_destroy(pendingSubList);
- free(topic);
- }
-
- celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);
-
- /* Connect the new publisher to the subscription for his topic, if there is any */
- celixThreadMutex_lock(&admin->subscriptionsLock);
-
- topic_subscription_pt sub = (topic_subscription_pt) hashMap_get(admin->subscriptions, scope_topic);
- if (sub != NULL && pubEP->endpoint != NULL) {
- pubsub_topicSubscriptionAddConnectPublisherToPendingList(sub, pubEP->endpoint);
- }
-
- /* And check also for ANY subscription */
- topic_subscription_pt any_sub = (topic_subscription_pt) hashMap_get(admin->subscriptions, PUBSUB_ANY_SUB_TOPIC);
- if (any_sub != NULL && pubEP->endpoint != NULL) {
- pubsub_topicSubscriptionAddConnectPublisherToPendingList(any_sub, pubEP->endpoint);
- }
-
- free(scope_topic);
-
- celixThreadMutex_unlock(&admin->subscriptionsLock);
-
- return status;
-
-}
-
-celix_status_t pubsubAdmin_removePublication(pubsub_admin_pt admin,pubsub_endpoint_pt pubEP){
- celix_status_t status = CELIX_SUCCESS;
- int count = 0;
-
- printf("PSA_ZMQ: Removing publication [FWUUID=%s bundleID=%ld topic=%s]\n",pubEP->frameworkUUID,pubEP->serviceID,pubEP->topic);
-
- const char* fwUUID = NULL;
-
- bundleContext_getProperty(admin->bundle_context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
- if(fwUUID==NULL){
- printf("PSA_ZMQ: Cannot retrieve fwUUID.\n");
- return CELIX_INVALID_BUNDLE_CONTEXT;
- }
- char *scope_topic = createScopeTopicKey(pubEP->scope, pubEP->topic);
-
- if(strcmp(pubEP->frameworkUUID,fwUUID)==0){
-
- celixThreadMutex_lock(&admin->localPublicationsLock);
- service_factory_pt factory = (service_factory_pt)hashMap_get(admin->localPublications,scope_topic);
- if(factory!=NULL){
- topic_publication_pt pub = (topic_publication_pt)factory->handle;
- pubsub_topicPublicationRemovePublisherEP(pub,pubEP);
- }
- celixThreadMutex_unlock(&admin->localPublicationsLock);
-
- if(factory==NULL){
- /* Maybe the endpoint was pending */
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
- if(!arrayList_removeElement(admin->noSerializerPublications, pubEP)){
- status = CELIX_ILLEGAL_STATE;
- }
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
- }
- }
- else{
-
- celixThreadMutex_lock(&admin->externalPublicationsLock);
- array_list_pt ext_pub_list = (array_list_pt)hashMap_get(admin->externalPublications,scope_topic);
- if(ext_pub_list!=NULL){
- int i;
- bool found = false;
- for(i=0;!found && i<arrayList_size(ext_pub_list);i++){
- pubsub_endpoint_pt p = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
- found = pubsubEndpoint_equals(pubEP,p);
- if (found){
- arrayList_remove(ext_pub_list,i);
- }
- }
- // Check if there are more publishers on the same endpoint (happens when 1 celix-instance with multiple bundles publish in same topic)
- for(i=0; i<arrayList_size(ext_pub_list);i++) {
- pubsub_endpoint_pt p = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
- if (strcmp(pubEP->endpoint,p->endpoint) == 0) {
- count++;
- }
- }
-
- if(arrayList_size(ext_pub_list)==0){
- hash_map_entry_pt entry = hashMap_getEntry(admin->externalPublications,scope_topic);
- char* topic = (char*)hashMapEntry_getKey(entry);
- array_list_pt list = (array_list_pt)hashMapEntry_getValue(entry);
- hashMap_remove(admin->externalPublications,topic);
- arrayList_destroy(list);
- free(topic);
- }
- }
-
- celixThreadMutex_unlock(&admin->externalPublicationsLock);
- }
-
- /* Check if this publisher was connected to one of our subscribers*/
- celixThreadMutex_lock(&admin->subscriptionsLock);
-
- topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic);
- if(sub!=NULL && pubEP->endpoint!=NULL && count == 0){
- pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(sub,pubEP->endpoint);
- }
-
- /* And check also for ANY subscription */
- topic_subscription_pt any_sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,PUBSUB_ANY_SUB_TOPIC);
- if(any_sub!=NULL && pubEP->endpoint!=NULL && count == 0){
- pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(any_sub,pubEP->endpoint);
- }
-
- free(scope_topic);
- celixThreadMutex_unlock(&admin->subscriptionsLock);
-
- return status;
-
-}
-
-celix_status_t pubsubAdmin_closeAllPublications(pubsub_admin_pt admin, char *scope, char* topic){
- celix_status_t status = CELIX_SUCCESS;
-
- printf("PSA_ZMQ: Closing all publications\n");
-
- celixThreadMutex_lock(&admin->localPublicationsLock);
- char *scope_topic = createScopeTopicKey(scope, topic);
- hash_map_entry_pt pubsvc_entry = (hash_map_entry_pt)hashMap_getEntry(admin->localPublications,scope_topic);
- if(pubsvc_entry!=NULL){
- char* key = (char*)hashMapEntry_getKey(pubsvc_entry);
- service_factory_pt factory= (service_factory_pt)hashMapEntry_getValue(pubsvc_entry);
- topic_publication_pt pub = (topic_publication_pt)factory->handle;
- status += pubsub_topicPublicationStop(pub);
- disconnectTopicPubSubFromSerializer(admin, pub, true);
- status += pubsub_topicPublicationDestroy(pub);
- hashMap_remove(admin->localPublications,scope_topic);
- free(key);
- free(factory);
- }
- free(scope_topic);
- celixThreadMutex_unlock(&admin->localPublicationsLock);
-
- return status;
-
-}
-
-celix_status_t pubsubAdmin_closeAllSubscriptions(pubsub_admin_pt admin,char* scope,char* topic){
- celix_status_t status = CELIX_SUCCESS;
-
- printf("PSA_ZMQ: Closing all subscriptions\n");
-
- celixThreadMutex_lock(&admin->subscriptionsLock);
- char *scope_topic = createScopeTopicKey(scope, topic);
- hash_map_entry_pt sub_entry = (hash_map_entry_pt)hashMap_getEntry(admin->subscriptions,scope_topic);
- if(sub_entry!=NULL){
- char* topic = (char*)hashMapEntry_getKey(sub_entry);
-
- topic_subscription_pt ts = (topic_subscription_pt)hashMapEntry_getValue(sub_entry);
- status += pubsub_topicSubscriptionStop(ts);
- disconnectTopicPubSubFromSerializer(admin, ts, false);
- status += pubsub_topicSubscriptionDestroy(ts);
- hashMap_remove(admin->subscriptions,scope_topic);
- free(topic);
-
- }
- free(scope_topic);
- celixThreadMutex_unlock(&admin->subscriptionsLock);
-
- return status;
-
-}
-
-
-#ifndef ANDROID
-static celix_status_t pubsubAdmin_getIpAdress(const char* interface, char** ip) {
- celix_status_t status = CELIX_BUNDLE_EXCEPTION;
-
- struct ifaddrs *ifaddr, *ifa;
- char host[NI_MAXHOST];
-
- if (getifaddrs(&ifaddr) != -1)
- {
- for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
- {
- if (ifa->ifa_addr == NULL)
- continue;
-
- if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
- if (interface == NULL) {
- *ip = strdup(host);
- status = CELIX_SUCCESS;
- }
- else if (strcmp(ifa->ifa_name, interface) == 0) {
- *ip = strdup(host);
- status = CELIX_SUCCESS;
- }
- }
- }
-
- freeifaddrs(ifaddr);
- }
-
- return status;
-}
-#endif
-
-static celix_status_t pubsubAdmin_addSubscriptionToPendingList(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
- celix_status_t status = CELIX_SUCCESS;
- char* scope_topic = createScopeTopicKey(subEP->scope, subEP->topic);
- array_list_pt pendingListPerTopic = hashMap_get(admin->pendingSubscriptions,scope_topic);
- if(pendingListPerTopic==NULL){
- arrayList_create(&pendingListPerTopic);
- hashMap_put(admin->pendingSubscriptions,strdup(scope_topic),pendingListPerTopic);
- }
- arrayList_add(pendingListPerTopic,subEP);
- free(scope_topic);
- return status;
-}
-
-celix_status_t pubsubAdmin_serializerAdded(void * handle, service_reference_pt reference, void * service){
- /* Assumption: serializers are all available at startup.
- * If a new (possibly better) serializer is installed and started, already created topic_publications/subscriptions will not be destroyed and recreated */
-
- celix_status_t status = CELIX_SUCCESS;
- int i=0;
-
- const char *serType = NULL;
- serviceReference_getProperty(reference, PUBSUB_SERIALIZER_TYPE_KEY,&serType);
- if(serType == NULL){
- printf("Serializer serviceReference %p has no pubsub_serializer.type property specified\n",reference);
- return CELIX_SERVICE_EXCEPTION;
- }
-
- pubsub_admin_pt admin = (pubsub_admin_pt)handle;
- celixThreadMutex_lock(&admin->serializerListLock);
- arrayList_add(admin->serializerList, reference);
- celixThreadMutex_unlock(&admin->serializerListLock);
-
- /* Now let's re-evaluate the pending */
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
-
- for(i=0;i<arrayList_size(admin->noSerializerSubscriptions);i++){
- pubsub_endpoint_pt ep = (pubsub_endpoint_pt)arrayList_get(admin->noSerializerSubscriptions,i);
- pubsub_serializer_service_t *best_serializer = NULL;
- pubsubAdmin_getBestSerializer(admin, ep, &best_serializer);
- if(best_serializer != NULL){ /* Finally we have a valid serializer! */
- pubsubAdmin_addSubscription(admin, ep);
- }
- }
-
- for(i=0;i<arrayList_size(admin->noSerializerPublications);i++){
- pubsub_endpoint_pt ep = (pubsub_endpoint_pt)arrayList_get(admin->noSerializerPublications,i);
- pubsub_serializer_service_t *best_serializer = NULL;
- pubsubAdmin_getBestSerializer(admin, ep, &best_serializer);
- if(best_serializer != NULL){ /* Finally we have a valid serializer! */
- pubsubAdmin_addPublication(admin, ep);
- }
- }
-
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
-
- printf("PSA_ZMQ: %s serializer added\n",serType);
-
- return status;
-}
-
-celix_status_t pubsubAdmin_serializerRemoved(void * handle, service_reference_pt reference, void * service){
-
- pubsub_admin_pt admin = (pubsub_admin_pt)handle;
- int i=0, j=0;
- const char *serType = NULL;
-
- serviceReference_getProperty(reference, PUBSUB_SERIALIZER_TYPE_KEY,&serType);
- if(serType == NULL){
- printf("Serializer serviceReference %p has no pubsub_serializer.type property specified\n",reference);
- return CELIX_SERVICE_EXCEPTION;
- }
-
- celixThreadMutex_lock(&admin->serializerListLock);
- /* Remove the serializer from the list */
- arrayList_removeElement(admin->serializerList, reference);
- celixThreadMutex_unlock(&admin->serializerListLock);
-
-
- celixThreadMutex_lock(&admin->usedSerializersLock);
- array_list_pt topicPubList = (array_list_pt)hashMap_remove(admin->topicPublicationsPerSerializer, service);
- array_list_pt topicSubList = (array_list_pt)hashMap_remove(admin->topicSubscriptionsPerSerializer, service);
- celixThreadMutex_unlock(&admin->usedSerializersLock);
-
- /* Now destroy the topicPublications, but first put back the pubsub_endpoints back to the noSerializer pending list */
- if(topicPubList!=NULL){
- for(i=0;i<arrayList_size(topicPubList);i++){
- topic_publication_pt topicPub = (topic_publication_pt)arrayList_get(topicPubList,i);
- /* Stop the topic publication */
- pubsub_topicPublicationStop(topicPub);
- /* Get the endpoints that are going to be orphan */
- array_list_pt pubList = pubsub_topicPublicationGetPublisherList(topicPub);
- for(j=0;j<arrayList_size(pubList);j++){
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pubList,j);
- /* Remove the publication */
- pubsubAdmin_removePublication(admin, pubEP);
- /* Reset the endpoint field, so that will be recreated from scratch when a new serializer will be found */
- if(pubEP->endpoint!=NULL){
- free(pubEP->endpoint);
- pubEP->endpoint = NULL;
- }
- /* Add the orphan endpoint to the noSerializer pending list */
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
- arrayList_add(admin->noSerializerPublications,pubEP);
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
- }
- arrayList_destroy(pubList);
-
- /* Cleanup also the localPublications hashmap*/
- celixThreadMutex_lock(&admin->localPublicationsLock);
- hash_map_iterator_pt iter = hashMapIterator_create(admin->localPublications);
- char *key = NULL;
- service_factory_pt factory = NULL;
- while(hashMapIterator_hasNext(iter)){
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- factory = (service_factory_pt)hashMapEntry_getValue(entry);
- topic_publication_pt pub = (topic_publication_pt)factory->handle;
- if(pub==topicPub){
- key = (char*)hashMapEntry_getKey(entry);
- break;
- }
- }
- hashMapIterator_destroy(iter);
- if(key!=NULL){
- hashMap_remove(admin->localPublications, key);
- free(factory);
- free(key);
- }
- celixThreadMutex_unlock(&admin->localPublicationsLock);
-
- /* Finally destroy the topicPublication */
- pubsub_topicPublicationDestroy(topicPub);
- }
- arrayList_destroy(topicPubList);
- }
-
- /* Now destroy the topicSubscriptions, but first put back the pubsub_endpoints back to the noSerializer pending list */
- if(topicSubList!=NULL){
- for(i=0;i<arrayList_size(topicSubList);i++){
- topic_subscription_pt topicSub = (topic_subscription_pt)arrayList_get(topicSubList,i);
- /* Stop the topic subscription */
- pubsub_topicSubscriptionStop(topicSub);
- /* Get the endpoints that are going to be orphan */
- array_list_pt subList = pubsub_topicSubscriptionGetSubscribersList(topicSub);
- for(j=0;j<arrayList_size(subList);j++){
- pubsub_endpoint_pt subEP = (pubsub_endpoint_pt)arrayList_get(subList,j);
- /* Remove the subscription */
- pubsubAdmin_removeSubscription(admin, subEP);
- /* Reset the endpoint field, so that will be recreated from scratch when a new serializer will be found */
- if(subEP->endpoint!=NULL){
- free(subEP->endpoint);
- subEP->endpoint = NULL;
- }
- /* Add the orphan endpoint to the noSerializer pending list */
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
- arrayList_add(admin->noSerializerSubscriptions,subEP);
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
- }
-
- /* Cleanup also the subscriptions hashmap*/
- celixThreadMutex_lock(&admin->subscriptionsLock);
- hash_map_iterator_pt iter = hashMapIterator_create(admin->subscriptions);
- char *key = NULL;
- while(hashMapIterator_hasNext(iter)){
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- topic_subscription_pt sub = (topic_subscription_pt)hashMapEntry_getValue(entry);
- if(sub==topicSub){
- key = (char*)hashMapEntry_getKey(entry);
- break;
- }
- }
- hashMapIterator_destroy(iter);
- if(key!=NULL){
- hashMap_remove(admin->subscriptions, key);
- free(key);
- }
- celixThreadMutex_unlock(&admin->subscriptionsLock);
-
- /* Finally destroy the topicSubscription */
- pubsub_topicSubscriptionDestroy(topicSub);
- }
- arrayList_destroy(topicSubList);
- }
-
-
-
- printf("PSA_ZMQ: %s serializer removed\n",serType);
-
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t pubsubAdmin_matchEndpoint(pubsub_admin_pt admin, pubsub_endpoint_pt endpoint, double* score){
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&admin->serializerListLock);
- status = pubsub_admin_match(endpoint->topic_props,PUBSUB_ADMIN_TYPE,admin->serializerList,score);
- celixThreadMutex_unlock(&admin->serializerListLock);
-
- return status;
-}
-
-/* This one recall the same logic as in the match function */
-static celix_status_t pubsubAdmin_getBestSerializer(pubsub_admin_pt admin,pubsub_endpoint_pt ep, pubsub_serializer_service_t **serSvc){
-
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&admin->serializerListLock);
- status = pubsub_admin_get_best_serializer(ep->topic_props, admin->serializerList, serSvc);
- celixThreadMutex_unlock(&admin->serializerListLock);
-
- return status;
-
-}
-
-static void connectTopicPubSubToSerializer(pubsub_admin_pt admin,pubsub_serializer_service_t *serializer,void *topicPubSub,bool isPublication){
-
- celixThreadMutex_lock(&admin->usedSerializersLock);
-
- hash_map_pt map = isPublication?admin->topicPublicationsPerSerializer:admin->topicSubscriptionsPerSerializer;
- array_list_pt list = (array_list_pt)hashMap_get(map,serializer);
- if(list==NULL){
- arrayList_create(&list);
- hashMap_put(map,serializer,list);
- }
- arrayList_add(list,topicPubSub);
-
- celixThreadMutex_unlock(&admin->usedSerializersLock);
-
-}
-
-static void disconnectTopicPubSubFromSerializer(pubsub_admin_pt admin,void *topicPubSub,bool isPublication){
-
- celixThreadMutex_lock(&admin->usedSerializersLock);
-
- hash_map_pt map = isPublication?admin->topicPublicationsPerSerializer:admin->topicSubscriptionsPerSerializer;
- hash_map_iterator_pt iter = hashMapIterator_create(map);
- while(hashMapIterator_hasNext(iter)){
- array_list_pt list = (array_list_pt)hashMapIterator_nextValue(iter);
- if(arrayList_removeElement(list, topicPubSub)){ //Found it!
- break;
- }
- }
- hashMapIterator_destroy(iter);
-
- celixThreadMutex_unlock(&admin->usedSerializersLock);
-
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/private/src/topic_publication.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/private/src/topic_publication.c b/pubsub/pubsub_admin_zmq/private/src/topic_publication.c
deleted file mode 100644
index e405866..0000000
--- a/pubsub/pubsub_admin_zmq/private/src/topic_publication.c
+++ /dev/null
@@ -1,630 +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.
- */
-
-#include <czmq.h>
-/* The following undefs prevent the collision between:
- * - sys/syslog.h (which is included within czmq)
- * - celix/dfi/dfi_log_util.h
- */
-#undef LOG_DEBUG
-#undef LOG_WARNING
-#undef LOG_INFO
-#undef LOG_WARNING
-
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "array_list.h"
-#include "celixbool.h"
-#include "service_registration.h"
-#include "utils.h"
-#include "service_factory.h"
-#include "version.h"
-
-#include "pubsub_common.h"
-#include "pubsub_utils.h"
-#include "publisher.h"
-
-#include "topic_publication.h"
-
-#include "pubsub_serializer.h"
-
-#ifdef BUILD_WITH_ZMQ_SECURITY
- #include "zmq_crypto.h"
-
- #define MAX_CERT_PATH_LENGTH 512
-#endif
-
-#define EP_ADDRESS_LEN 32
-#define ZMQ_BIND_MAX_RETRY 5
-
-#define FIRST_SEND_DELAY 2
-
-struct topic_publication {
- zsock_t* zmq_socket;
- celix_thread_mutex_t socket_lock; //Protects zmq_socket access
- zcert_t * zmq_cert;
- char* endpoint;
- service_registration_pt svcFactoryReg;
- array_list_pt pub_ep_list; //List<pubsub_endpoint>
- hash_map_pt boundServices; //<bundle_pt,bound_service>
- pubsub_serializer_service_t *serializer;
- celix_thread_mutex_t tp_lock;
-};
-
-typedef struct publish_bundle_bound_service {
- topic_publication_pt parent;
- pubsub_publisher_t service;
- bundle_pt bundle;
- char *topic;
- hash_map_pt msgTypes;
- unsigned short getCount;
- celix_thread_mutex_t mp_lock; //Protects publish_bundle_bound_service data structure
- bool mp_send_in_progress;
- array_list_pt mp_parts;
-}* publish_bundle_bound_service_pt;
-
-/* Note: correct locking order is
- * 1. tp_lock
- * 2. mp_lock
- * 3. socket_lock
- *
- * tp_lock and socket_lock are independent.
- */
-
-typedef struct pubsub_msg{
- pubsub_msg_header_pt header;
- char* payload;
- int payloadSize;
-}* pubsub_msg_pt;
-
-static unsigned int rand_range(unsigned int min, unsigned int max);
-
-static celix_status_t pubsub_topicPublicationGetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service);
-static celix_status_t pubsub_topicPublicationUngetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service);
-
-static publish_bundle_bound_service_pt pubsub_createPublishBundleBoundService(topic_publication_pt tp,bundle_pt bundle);
-static void pubsub_destroyPublishBundleBoundService(publish_bundle_bound_service_pt boundSvc);
-
-static int pubsub_topicPublicationSend(void* handle,unsigned int msgTypeId, const void *msg);
-static int pubsub_topicPublicationSendMultipart(void *handle, unsigned int msgTypeId, const void *inMsg, int flags);
-static int pubsub_localMsgTypeIdForUUID(void* handle, const char* msgType, unsigned int* msgTypeId);
-
-static void delay_first_send_for_late_joiners(void);
-
-celix_status_t pubsub_topicPublicationCreate(bundle_context_pt bundle_context, pubsub_endpoint_pt pubEP, pubsub_serializer_service_t *best_serializer, char* bindIP, unsigned int basePort, unsigned int maxPort, topic_publication_pt *out){
- celix_status_t status = CELIX_SUCCESS;
-
-#ifdef BUILD_WITH_ZMQ_SECURITY
- char* secure_topics = NULL;
- bundleContext_getProperty(bundle_context, "SECURE_TOPICS", (const char **) &secure_topics);
-
- if (secure_topics){
- array_list_pt secure_topics_list = pubsub_getTopicsFromString(secure_topics);
-
- int i;
- int secure_topics_size = arrayList_size(secure_topics_list);
- for (i = 0; i < secure_topics_size; i++){
- char* top = arrayList_get(secure_topics_list, i);
- if (strcmp(pubEP->topic, top) == 0){
- printf("PSA_ZMQ_TP: Secure topic: '%s'\n", top);
- pubEP->is_secure = true;
- }
- free(top);
- top = NULL;
- }
-
- arrayList_destroy(secure_topics_list);
- }
-
- zcert_t* pub_cert = NULL;
- if (pubEP->is_secure){
- char* keys_bundle_dir = pubsub_getKeysBundleDir(bundle_context);
- if (keys_bundle_dir == NULL){
- return CELIX_SERVICE_EXCEPTION;
- }
-
- const char* keys_file_path = NULL;
- const char* keys_file_name = NULL;
- bundleContext_getProperty(bundle_context, PROPERTY_KEYS_FILE_PATH, &keys_file_path);
- bundleContext_getProperty(bundle_context, PROPERTY_KEYS_FILE_NAME, &keys_file_name);
-
- char cert_path[MAX_CERT_PATH_LENGTH];
-
- //certificate path ".cache/bundle{id}/version0.0/./META-INF/keys/publisher/private/pub_{topic}.key"
- snprintf(cert_path, MAX_CERT_PATH_LENGTH, "%s/META-INF/keys/publisher/private/pub_%s.key.enc", keys_bundle_dir, pubEP->topic);
- free(keys_bundle_dir);
- printf("PSA_ZMQ_TP: Loading key '%s'\n", cert_path);
-
- pub_cert = get_zcert_from_encoded_file((char *) keys_file_path, (char *) keys_file_name, cert_path);
- if (pub_cert == NULL){
- printf("PSA_ZMQ_TP: Cannot load key '%s'\n", cert_path);
- printf("PSA_ZMQ_TP: Topic '%s' NOT SECURED !\n", pubEP->topic);
- pubEP->is_secure = false;
- }
- }
-#endif
-
- zsock_t* socket = zsock_new (ZMQ_PUB);
- if(socket==NULL){
- #ifdef BUILD_WITH_ZMQ_SECURITY
- if (pubEP->is_secure){
- zcert_destroy(&pub_cert);
- }
- #endif
-
- perror("Error for zmq_socket");
- return CELIX_SERVICE_EXCEPTION;
- }
-#ifdef BUILD_WITH_ZMQ_SECURITY
- if (pubEP->is_secure){
- zcert_apply (pub_cert, socket); // apply certificate to socket
- zsock_set_curve_server (socket, true); // setup the publisher's socket to use the curve functions
- }
-#endif
-
- int rv = -1, retry=0;
- char* ep = malloc(EP_ADDRESS_LEN);
- char bindAddress[EP_ADDRESS_LEN];
-
- while(rv==-1 && retry<ZMQ_BIND_MAX_RETRY){
- /* Randomized part due to same bundle publishing on different topics */
- unsigned int port = rand_range(basePort,maxPort);
- memset(ep,0,EP_ADDRESS_LEN);
- memset(bindAddress, 0, EP_ADDRESS_LEN);
-
- snprintf(ep,EP_ADDRESS_LEN,"tcp://%s:%u",bindIP,port);
- snprintf(bindAddress, EP_ADDRESS_LEN, "tcp://0.0.0.0:%u", port); //NOTE using a different bind addres than endpoint address
- rv = zsock_bind (socket, "%s", bindAddress);
- if (rv == -1) {
- perror("Error for zmq_bind");
- }
- retry++;
- }
-
- if(rv == -1){
- free(ep);
- return CELIX_SERVICE_EXCEPTION;
- }
-
- /* ZMQ stuffs are all fine at this point. Let's create and initialize the structure */
-
- topic_publication_pt pub = calloc(1,sizeof(*pub));
-
- arrayList_create(&(pub->pub_ep_list));
- pub->boundServices = hashMap_create(NULL,NULL,NULL,NULL);
- celixThreadMutex_create(&(pub->tp_lock),NULL);
-
- pub->endpoint = ep;
- pub->zmq_socket = socket;
- pub->serializer = best_serializer;
-
- celixThreadMutex_create(&(pub->socket_lock),NULL);
-
-#ifdef BUILD_WITH_ZMQ_SECURITY
- if (pubEP->is_secure){
- pub->zmq_cert = pub_cert;
- }
-#endif
-
- pubsub_topicPublicationAddPublisherEP(pub,pubEP);
-
- *out = pub;
-
- return status;
-}
-
-celix_status_t pubsub_topicPublicationDestroy(topic_publication_pt pub){
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&(pub->tp_lock));
-
- free(pub->endpoint);
- arrayList_destroy(pub->pub_ep_list);
-
- hash_map_iterator_pt iter = hashMapIterator_create(pub->boundServices);
- while(hashMapIterator_hasNext(iter)){
- publish_bundle_bound_service_pt bound = hashMapIterator_nextValue(iter);
- pubsub_destroyPublishBundleBoundService(bound);
- }
- hashMapIterator_destroy(iter);
- hashMap_destroy(pub->boundServices,false,false);
-
- pub->svcFactoryReg = NULL;
- pub->serializer = NULL;
-#ifdef BUILD_WITH_ZMQ_SECURITY
- zcert_destroy(&(pub->zmq_cert));
-#endif
-
- celixThreadMutex_unlock(&(pub->tp_lock));
-
- celixThreadMutex_destroy(&(pub->tp_lock));
-
- celixThreadMutex_lock(&(pub->socket_lock));
- zsock_destroy(&(pub->zmq_socket));
- celixThreadMutex_unlock(&(pub->socket_lock));
-
- celixThreadMutex_destroy(&(pub->socket_lock));
-
- free(pub);
-
- return status;
-}
-
-celix_status_t pubsub_topicPublicationStart(bundle_context_pt bundle_context,topic_publication_pt pub,service_factory_pt* svcFactory){
- celix_status_t status = CELIX_SUCCESS;
-
- /* Let's register the new service */
-
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pub->pub_ep_list,0);
-
- if(pubEP!=NULL){
- service_factory_pt factory = calloc(1, sizeof(*factory));
- factory->handle = pub;
- factory->getService = pubsub_topicPublicationGetService;
- factory->ungetService = pubsub_topicPublicationUngetService;
-
- properties_pt props = properties_create();
- properties_set(props,PUBSUB_PUBLISHER_TOPIC,pubEP->topic);
- properties_set(props,PUBSUB_PUBLISHER_SCOPE,pubEP->scope);
- properties_set(props,"service.version", PUBSUB_PUBLISHER_SERVICE_VERSION);
-
- status = bundleContext_registerServiceFactory(bundle_context,PUBSUB_PUBLISHER_SERVICE_NAME,factory,props,&(pub->svcFactoryReg));
-
- if(status != CELIX_SUCCESS){
- properties_destroy(props);
- printf("PSA_ZMQ_PSA_ZMQ_TP: Cannot register ServiceFactory for topic %s (bundle %ld).\n",pubEP->topic,pubEP->serviceID);
- }
- else{
- *svcFactory = factory;
- }
- }
- else{
- printf("PSA_ZMQ_PSA_ZMQ_TP: Cannot find pubsub_endpoint after adding it...Should never happen!\n");
- status = CELIX_SERVICE_EXCEPTION;
- }
-
- return status;
-}
-
-celix_status_t pubsub_topicPublicationStop(topic_publication_pt pub){
- return serviceRegistration_unregister(pub->svcFactoryReg);
-}
-
-celix_status_t pubsub_topicPublicationAddPublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep){
-
- celixThreadMutex_lock(&(pub->tp_lock));
- ep->endpoint = strdup(pub->endpoint);
- arrayList_add(pub->pub_ep_list,ep);
- celixThreadMutex_unlock(&(pub->tp_lock));
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t pubsub_topicPublicationRemovePublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep){
-
- celixThreadMutex_lock(&(pub->tp_lock));
- for (int i = 0; i < arrayList_size(pub->pub_ep_list); i++) {
- pubsub_endpoint_pt e = arrayList_get(pub->pub_ep_list, i);
- if(pubsubEndpoint_equals(ep, e)) {
- arrayList_removeElement(pub->pub_ep_list,ep);
- break;
- }
- }
- celixThreadMutex_unlock(&(pub->tp_lock));
-
- return CELIX_SUCCESS;
-}
-
-array_list_pt pubsub_topicPublicationGetPublisherList(topic_publication_pt pub){
- array_list_pt list = NULL;
- celixThreadMutex_lock(&(pub->tp_lock));
- list = arrayList_clone(pub->pub_ep_list);
- celixThreadMutex_unlock(&(pub->tp_lock));
- return list;
-}
-
-
-static celix_status_t pubsub_topicPublicationGetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service) {
- celix_status_t status = CELIX_SUCCESS;
-
- topic_publication_pt publish = (topic_publication_pt)handle;
-
- celixThreadMutex_lock(&(publish->tp_lock));
-
- publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt)hashMap_get(publish->boundServices,bundle);
- if(bound==NULL){
- bound = pubsub_createPublishBundleBoundService(publish,bundle);
- if(bound!=NULL){
- hashMap_put(publish->boundServices,bundle,bound);
- }
- }
- else{
- bound->getCount++;
- }
-
- *service = &bound->service;
-
- celixThreadMutex_unlock(&(publish->tp_lock));
-
- return status;
-}
-
-static celix_status_t pubsub_topicPublicationUngetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service) {
-
- topic_publication_pt publish = (topic_publication_pt)handle;
-
- celixThreadMutex_lock(&(publish->tp_lock));
-
- publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt)hashMap_get(publish->boundServices,bundle);
- if(bound!=NULL){
-
- bound->getCount--;
- if(bound->getCount==0){
- pubsub_destroyPublishBundleBoundService(bound);
- hashMap_remove(publish->boundServices,bundle);
- }
-
- }
- else{
- long bundleId = -1;
- bundle_getBundleId(bundle,&bundleId);
- printf("PSA_ZMQ_TP: Unexpected ungetService call for bundle %ld.\n", bundleId);
- }
-
- /* service should be never used for unget, so let's set the pointer to NULL */
- *service = NULL;
-
- celixThreadMutex_unlock(&(publish->tp_lock));
-
- return CELIX_SUCCESS;
-}
-
-static bool send_pubsub_msg(zsock_t* zmq_socket, pubsub_msg_pt msg, bool last){
-
- bool ret = true;
-
- zframe_t* headerMsg = zframe_new(msg->header, sizeof(struct pubsub_msg_header));
- if (headerMsg == NULL) ret=false;
- zframe_t* payloadMsg = zframe_new(msg->payload, msg->payloadSize);
- if (payloadMsg == NULL) ret=false;
-
- delay_first_send_for_late_joiners();
-
- if( zframe_send(&headerMsg,zmq_socket, ZFRAME_MORE) == -1) ret=false;
-
- if(!last){
- if( zframe_send(&payloadMsg,zmq_socket, ZFRAME_MORE) == -1) ret=false;
- }
- else{
- if( zframe_send(&payloadMsg,zmq_socket, 0) == -1) ret=false;
- }
-
- if (!ret){
- zframe_destroy(&headerMsg);
- zframe_destroy(&payloadMsg);
- }
-
- free(msg->header);
- free(msg->payload);
- free(msg);
-
- return ret;
-
-}
-
-static bool send_pubsub_mp_msg(zsock_t* zmq_socket, array_list_pt mp_msg_parts){
-
- bool ret = true;
-
- unsigned int i = 0;
- unsigned int mp_num = arrayList_size(mp_msg_parts);
- for(;i<mp_num;i++){
- ret = ret && send_pubsub_msg(zmq_socket, (pubsub_msg_pt)arrayList_get(mp_msg_parts,i), (i==mp_num-1));
- }
- arrayList_clear(mp_msg_parts);
-
- return ret;
-
-}
-
-static int pubsub_topicPublicationSend(void* handle, unsigned int msgTypeId, const void *msg) {
-
- return pubsub_topicPublicationSendMultipart(handle,msgTypeId,msg, PUBSUB_PUBLISHER_FIRST_MSG | PUBSUB_PUBLISHER_LAST_MSG);
-
-}
-
-static int pubsub_topicPublicationSendMultipart(void *handle, unsigned int msgTypeId, const void *inMsg, int flags){
-
- int status = 0;
-
- publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt) handle;
-
- celixThreadMutex_lock(&(bound->parent->tp_lock));
- celixThreadMutex_lock(&(bound->mp_lock));
- if( (flags & PUBSUB_PUBLISHER_FIRST_MSG) && !(flags & PUBSUB_PUBLISHER_LAST_MSG) && bound->mp_send_in_progress){ //means a real mp_msg
- printf("PSA_ZMQ_TP: Multipart send already in progress. Cannot process a new one.\n");
- celixThreadMutex_unlock(&(bound->mp_lock));
- celixThreadMutex_unlock(&(bound->parent->tp_lock));
- return -3;
- }
-
- pubsub_msg_serializer_t* msgSer = (pubsub_msg_serializer_t*)hashMap_get(bound->msgTypes, (void*)(uintptr_t)msgTypeId);
-
- if (msgSer!= NULL) {
- int major=0, minor=0;
-
- pubsub_msg_header_pt msg_hdr = calloc(1,sizeof(struct pubsub_msg_header));
- strncpy(msg_hdr->topic,bound->topic,MAX_TOPIC_LEN-1);
- msg_hdr->type = msgTypeId;
-
- if (msgSer->msgVersion != NULL){
- version_getMajor(msgSer->msgVersion, &major);
- version_getMinor(msgSer->msgVersion, &minor);
- msg_hdr->major = major;
- msg_hdr->minor = minor;
- }
-
- void *serializedOutput = NULL;
- size_t serializedOutputLen = 0;
- msgSer->serialize(msgSer,inMsg,&serializedOutput, &serializedOutputLen);
-
- pubsub_msg_pt msg = calloc(1,sizeof(struct pubsub_msg));
- msg->header = msg_hdr;
- msg->payload = (char*)serializedOutput;
- msg->payloadSize = serializedOutputLen;
- bool snd = true;
-
- switch(flags){
- case PUBSUB_PUBLISHER_FIRST_MSG:
- bound->mp_send_in_progress = true;
- arrayList_add(bound->mp_parts,msg);
- break;
- case PUBSUB_PUBLISHER_PART_MSG:
- if(!bound->mp_send_in_progress){
- printf("PSA_ZMQ_TP: ERROR: received msg part without the first part.\n");
- status = -4;
- }
- else{
- arrayList_add(bound->mp_parts,msg);
- }
- break;
- case PUBSUB_PUBLISHER_LAST_MSG:
- if(!bound->mp_send_in_progress){
- printf("PSA_ZMQ_TP: ERROR: received end msg without the first part.\n");
- status = -4;
- }
- else{
- arrayList_add(bound->mp_parts,msg);
- snd = send_pubsub_mp_msg(bound->parent->zmq_socket,bound->mp_parts);
- bound->mp_send_in_progress = false;
- }
- break;
- case PUBSUB_PUBLISHER_FIRST_MSG | PUBSUB_PUBLISHER_LAST_MSG: //Normal send case
- snd = send_pubsub_msg(bound->parent->zmq_socket,msg,true);
- break;
- default:
- printf("PSA_ZMQ_TP: ERROR: Invalid MP flags combination\n");
- status = -4;
- break;
- }
-
- if(status==-4){
- free(msg);
- }
-
- if(!snd){
- printf("PSA_ZMQ_TP: Failed to send %s message %u.\n",flags == (PUBSUB_PUBLISHER_FIRST_MSG | PUBSUB_PUBLISHER_LAST_MSG) ? "single" : "multipart", msgTypeId);
- }
-
- } else {
- printf("PSA_ZMQ_TP: No msg serializer available for msg type id %d\n", msgTypeId);
- status=-1;
- }
-
- celixThreadMutex_unlock(&(bound->mp_lock));
- celixThreadMutex_unlock(&(bound->parent->tp_lock));
-
- return status;
-
-}
-
-static int pubsub_localMsgTypeIdForUUID(void* handle, const char* msgType, unsigned int* msgTypeId){
- *msgTypeId = utils_stringHash(msgType);
- return 0;
-}
-
-
-static unsigned int rand_range(unsigned int min, unsigned int max){
-
- double scaled = (double)(((double)random())/((double)RAND_MAX));
- return (max-min+1)*scaled + min;
-
-}
-
-static publish_bundle_bound_service_pt pubsub_createPublishBundleBoundService(topic_publication_pt tp,bundle_pt bundle){
-
- //PRECOND lock on tp->lock
-
- publish_bundle_bound_service_pt bound = calloc(1, sizeof(*bound));
-
- if (bound != NULL) {
-
- bound->parent = tp;
- bound->bundle = bundle;
- bound->getCount = 1;
- bound->mp_send_in_progress = false;
- celixThreadMutex_create(&bound->mp_lock,NULL);
-
- if(tp->serializer != NULL){
- tp->serializer->createSerializerMap(tp->serializer->handle,bundle,&bound->msgTypes);
- }
-
- arrayList_create(&bound->mp_parts);
-
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(bound->parent->pub_ep_list,0);
- bound->topic=strdup(pubEP->topic);
-
- bound->service.handle = bound;
- bound->service.localMsgTypeIdForMsgType = pubsub_localMsgTypeIdForUUID;
- bound->service.send = pubsub_topicPublicationSend;
- bound->service.sendMultipart = pubsub_topicPublicationSendMultipart;
-
- }
-
- return bound;
-}
-
-static void pubsub_destroyPublishBundleBoundService(publish_bundle_bound_service_pt boundSvc){
-
- //PRECOND lock on tp->lock
-
- celixThreadMutex_lock(&boundSvc->mp_lock);
-
-
- if(boundSvc->parent->serializer != NULL && boundSvc->msgTypes != NULL){
- boundSvc->parent->serializer->destroySerializerMap(boundSvc->parent->serializer->handle, boundSvc->msgTypes);
- }
-
- if(boundSvc->mp_parts!=NULL){
- arrayList_destroy(boundSvc->mp_parts);
- }
-
- if(boundSvc->topic!=NULL){
- free(boundSvc->topic);
- }
-
- celixThreadMutex_unlock(&boundSvc->mp_lock);
- celixThreadMutex_destroy(&boundSvc->mp_lock);
-
- free(boundSvc);
-
-}
-
-static void delay_first_send_for_late_joiners(){
-
- static bool firstSend = true;
-
- if(firstSend){
- printf("PSA_ZMQ_TP: Delaying first send for late joiners...\n");
- sleep(FIRST_SEND_DELAY);
- firstSend = false;
- }
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/private/src/topic_subscription.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/private/src/topic_subscription.c b/pubsub/pubsub_admin_zmq/private/src/topic_subscription.c
deleted file mode 100644
index 0e7a794..0000000
--- a/pubsub/pubsub_admin_zmq/private/src/topic_subscription.c
+++ /dev/null
@@ -1,732 +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.
- */
-/*
- * topic_subscription.c
- *
- * \date Oct 2, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include "topic_subscription.h"
-#include <czmq.h>
-/* The following undefs prevent the collision between:
- * - sys/syslog.h (which is included within czmq)
- * - celix/dfi/dfi_log_util.h
- */
-#undef LOG_DEBUG
-#undef LOG_WARNING
-#undef LOG_INFO
-#undef LOG_WARNING
-
-#include <string.h>
-#include <stdlib.h>
-#include <signal.h>
-
-#include "utils.h"
-#include "celix_errno.h"
-#include "constants.h"
-#include "version.h"
-
-#include "subscriber.h"
-#include "publisher.h"
-#include "pubsub_utils.h"
-
-#ifdef BUILD_WITH_ZMQ_SECURITY
-#include "zmq_crypto.h"
-
-#define MAX_CERT_PATH_LENGTH 512
-#endif
-
-#define POLL_TIMEOUT 250
-#define ZMQ_POLL_TIMEOUT_MS_ENV "ZMQ_POLL_TIMEOUT_MS"
-
-struct topic_subscription{
-
- zsock_t* zmq_socket;
- zcert_t * zmq_cert;
- zcert_t * zmq_pub_cert;
- pthread_mutex_t socket_lock;
- service_tracker_pt tracker;
- array_list_pt sub_ep_list;
- celix_thread_t recv_thread;
- bool running;
- celix_thread_mutex_t ts_lock;
- bundle_context_pt context;
-
- pubsub_serializer_service_t *serializer;
-
- hash_map_pt servicesMap; // key = service, value = msg types map
-
- celix_thread_mutex_t pendingConnections_lock;
- array_list_pt pendingConnections;
-
- array_list_pt pendingDisconnections;
- celix_thread_mutex_t pendingDisconnections_lock;
-
- unsigned int nrSubscribers;
-};
-
-typedef struct complete_zmq_msg{
- zframe_t* header;
- zframe_t* payload;
-}* complete_zmq_msg_pt;
-
-typedef struct mp_handle{
- hash_map_pt svc_msg_db;
- hash_map_pt rcv_msg_map;
-}* mp_handle_pt;
-
-typedef struct msg_map_entry{
- bool retain;
- void* msgInst;
-}* msg_map_entry_pt;
-
-static celix_status_t topicsub_subscriberTracked(void * handle, service_reference_pt reference, void * service);
-static celix_status_t topicsub_subscriberUntracked(void * handle, service_reference_pt reference, void * service);
-static void* zmq_recv_thread_func(void* arg);
-static bool checkVersion(version_pt msgVersion,pubsub_msg_header_pt hdr);
-static void sigusr1_sighandler(int signo);
-static int pubsub_localMsgTypeIdForMsgType(void* handle, const char* msgType, unsigned int* msgTypeId);
-static int pubsub_getMultipart(void *handle, unsigned int msgTypeId, bool retain, void **part);
-static mp_handle_pt create_mp_handle(hash_map_pt svc_msg_db,array_list_pt rcv_msg_list);
-static void destroy_mp_handle(mp_handle_pt mp_handle);
-static void connectPendingPublishers(topic_subscription_pt sub);
-static void disconnectPendingPublishers(topic_subscription_pt sub);
-
-celix_status_t pubsub_topicSubscriptionCreate(bundle_context_pt bundle_context, char* scope, char* topic, pubsub_serializer_service_t *best_serializer, topic_subscription_pt* out){
- celix_status_t status = CELIX_SUCCESS;
-
-#ifdef BUILD_WITH_ZMQ_SECURITY
- char* keys_bundle_dir = pubsub_getKeysBundleDir(bundle_context);
- if (keys_bundle_dir == NULL){
- return CELIX_SERVICE_EXCEPTION;
- }
-
- const char* keys_file_path = NULL;
- const char* keys_file_name = NULL;
- bundleContext_getProperty(bundle_context, PROPERTY_KEYS_FILE_PATH, &keys_file_path);
- bundleContext_getProperty(bundle_context, PROPERTY_KEYS_FILE_NAME, &keys_file_name);
-
- char sub_cert_path[MAX_CERT_PATH_LENGTH];
- char pub_cert_path[MAX_CERT_PATH_LENGTH];
-
- //certificate path ".cache/bundle{id}/version0.0/./META-INF/keys/subscriber/private/sub_{topic}.key.enc"
- snprintf(sub_cert_path, MAX_CERT_PATH_LENGTH, "%s/META-INF/keys/subscriber/private/sub_%s.key.enc", keys_bundle_dir, topic);
- snprintf(pub_cert_path, MAX_CERT_PATH_LENGTH, "%s/META-INF/keys/publisher/public/pub_%s.pub", keys_bundle_dir, topic);
- free(keys_bundle_dir);
-
- printf("PSA_ZMQ_PSA_ZMQ_TS: Loading subscriber key '%s'\n", sub_cert_path);
- printf("PSA_ZMQ_PSA_ZMQ_TS: Loading publisher key '%s'\n", pub_cert_path);
-
- zcert_t* sub_cert = get_zcert_from_encoded_file((char *) keys_file_path, (char *) keys_file_name, sub_cert_path);
- if (sub_cert == NULL){
- printf("PSA_ZMQ_PSA_ZMQ_TS: Cannot load key '%s'\n", sub_cert_path);
- return CELIX_SERVICE_EXCEPTION;
- }
-
- zcert_t* pub_cert = zcert_load(pub_cert_path);
- if (pub_cert == NULL){
- zcert_destroy(&sub_cert);
- printf("PSA_ZMQ_PSA_ZMQ_TS: Cannot load key '%s'\n", pub_cert_path);
- return CELIX_SERVICE_EXCEPTION;
- }
-
- const char* pub_key = zcert_public_txt(pub_cert);
-#endif
-
- zsock_t* zmq_s = zsock_new (ZMQ_SUB);
- if(zmq_s==NULL){
-#ifdef BUILD_WITH_ZMQ_SECURITY
- zcert_destroy(&sub_cert);
- zcert_destroy(&pub_cert);
-#endif
-
- return CELIX_SERVICE_EXCEPTION;
- }
-
-#ifdef BUILD_WITH_ZMQ_SECURITY
- zcert_apply (sub_cert, zmq_s);
- zsock_set_curve_serverkey (zmq_s, pub_key); //apply key of publisher to socket of subscriber
-#endif
-
- if(strcmp(topic,PUBSUB_ANY_SUB_TOPIC)==0){
- zsock_set_subscribe (zmq_s, "");
- }
- else{
- zsock_set_subscribe (zmq_s, topic);
- }
-
- topic_subscription_pt ts = (topic_subscription_pt) calloc(1,sizeof(*ts));
- ts->context = bundle_context;
- ts->zmq_socket = zmq_s;
- ts->running = false;
- ts->nrSubscribers = 0;
- ts->serializer = best_serializer;
-
-#ifdef BUILD_WITH_ZMQ_SECURITY
- ts->zmq_cert = sub_cert;
- ts->zmq_pub_cert = pub_cert;
-#endif
-
- celixThreadMutex_create(&ts->socket_lock, NULL);
- celixThreadMutex_create(&ts->ts_lock,NULL);
- arrayList_create(&ts->sub_ep_list);
- ts->servicesMap = hashMap_create(NULL, NULL, NULL, NULL);
-
- arrayList_create(&ts->pendingConnections);
- arrayList_create(&ts->pendingDisconnections);
- celixThreadMutex_create(&ts->pendingConnections_lock, NULL);
- celixThreadMutex_create(&ts->pendingDisconnections_lock, NULL);
-
- char filter[128];
- memset(filter,0,128);
- if(strncmp(PUBSUB_SUBSCRIBER_SCOPE_DEFAULT,scope,strlen(PUBSUB_SUBSCRIBER_SCOPE_DEFAULT)) == 0) {
- // default scope, means that subscriber has not defined a scope property
- snprintf(filter, 128, "(&(%s=%s)(%s=%s))",
- (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_SUBSCRIBER_SERVICE_NAME,
- PUBSUB_SUBSCRIBER_TOPIC,topic);
-
- } else {
- snprintf(filter, 128, "(&(%s=%s)(%s=%s)(%s=%s))",
- (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_SUBSCRIBER_SERVICE_NAME,
- PUBSUB_SUBSCRIBER_TOPIC,topic,
- PUBSUB_SUBSCRIBER_SCOPE,scope);
- }
- service_tracker_customizer_pt customizer = NULL;
- status += serviceTrackerCustomizer_create(ts,NULL,topicsub_subscriberTracked,NULL,topicsub_subscriberUntracked,&customizer);
- status += serviceTracker_createWithFilter(bundle_context, filter, customizer, &ts->tracker);
-
- struct sigaction actions;
- memset(&actions, 0, sizeof(actions));
- sigemptyset(&actions.sa_mask);
- actions.sa_flags = 0;
- actions.sa_handler = sigusr1_sighandler;
-
- sigaction(SIGUSR1,&actions,NULL);
-
- *out=ts;
-
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionDestroy(topic_subscription_pt ts){
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&ts->ts_lock);
-
- ts->running = false;
- serviceTracker_destroy(ts->tracker);
- arrayList_clear(ts->sub_ep_list);
- arrayList_destroy(ts->sub_ep_list);
- /* TODO: Destroy all the serializer maps? */
- hashMap_destroy(ts->servicesMap,false,false);
-
- celixThreadMutex_lock(&ts->pendingConnections_lock);
- arrayList_destroy(ts->pendingConnections);
- celixThreadMutex_unlock(&ts->pendingConnections_lock);
- celixThreadMutex_destroy(&ts->pendingConnections_lock);
-
- celixThreadMutex_lock(&ts->pendingDisconnections_lock);
- arrayList_destroy(ts->pendingDisconnections);
- celixThreadMutex_unlock(&ts->pendingDisconnections_lock);
- celixThreadMutex_destroy(&ts->pendingDisconnections_lock);
-
- celixThreadMutex_unlock(&ts->ts_lock);
-
- celixThreadMutex_lock(&ts->socket_lock);
- zsock_destroy(&(ts->zmq_socket));
-#ifdef BUILD_WITH_ZMQ_SECURITY
- zcert_destroy(&(ts->zmq_cert));
- zcert_destroy(&(ts->zmq_pub_cert));
-#endif
- celixThreadMutex_unlock(&ts->socket_lock);
- celixThreadMutex_destroy(&ts->socket_lock);
-
- celixThreadMutex_destroy(&ts->ts_lock);
-
- free(ts);
-
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionStart(topic_subscription_pt ts){
- celix_status_t status = CELIX_SUCCESS;
-
- status = serviceTracker_open(ts->tracker);
-
- ts->running = true;
-
- if(status==CELIX_SUCCESS){
- status=celixThread_create(&ts->recv_thread,NULL,zmq_recv_thread_func,ts);
- }
-
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionStop(topic_subscription_pt ts){
- celix_status_t status = CELIX_SUCCESS;
-
- ts->running = false;
-
- pthread_kill(ts->recv_thread.thread,SIGUSR1);
-
- celixThread_join(ts->recv_thread,NULL);
-
- status = serviceTracker_close(ts->tracker);
-
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionConnectPublisher(topic_subscription_pt ts, char* pubURL){
- celix_status_t status = CELIX_SUCCESS;
- celixThreadMutex_lock(&ts->socket_lock);
- if(!zsock_is(ts->zmq_socket) || zsock_connect(ts->zmq_socket,"%s",pubURL) != 0){
- status = CELIX_SERVICE_EXCEPTION;
- }
- celixThreadMutex_unlock(&ts->socket_lock);
-
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionAddConnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL) {
- celix_status_t status = CELIX_SUCCESS;
- char *url = strdup(pubURL);
- celixThreadMutex_lock(&ts->pendingConnections_lock);
- arrayList_add(ts->pendingConnections, url);
- celixThreadMutex_unlock(&ts->pendingConnections_lock);
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL) {
- celix_status_t status = CELIX_SUCCESS;
- char *url = strdup(pubURL);
- celixThreadMutex_lock(&ts->pendingDisconnections_lock);
- arrayList_add(ts->pendingDisconnections, url);
- celixThreadMutex_unlock(&ts->pendingDisconnections_lock);
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionDisconnectPublisher(topic_subscription_pt ts, char* pubURL){
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&ts->socket_lock);
- if(!zsock_is(ts->zmq_socket) || zsock_disconnect(ts->zmq_socket,"%s",pubURL) != 0){
- status = CELIX_SERVICE_EXCEPTION;
- }
- celixThreadMutex_unlock(&ts->socket_lock);
-
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionAddSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP){
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&ts->ts_lock);
- arrayList_add(ts->sub_ep_list,subEP);
- celixThreadMutex_unlock(&ts->ts_lock);
-
- return status;
-
-}
-
-celix_status_t pubsub_topicIncreaseNrSubscribers(topic_subscription_pt ts) {
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&ts->ts_lock);
- ts->nrSubscribers++;
- celixThreadMutex_unlock(&ts->ts_lock);
-
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionRemoveSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP){
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&ts->ts_lock);
- arrayList_removeElement(ts->sub_ep_list,subEP);
- celixThreadMutex_unlock(&ts->ts_lock);
-
- return status;
-}
-
-celix_status_t pubsub_topicDecreaseNrSubscribers(topic_subscription_pt ts) {
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&ts->ts_lock);
- ts->nrSubscribers--;
- celixThreadMutex_unlock(&ts->ts_lock);
-
- return status;
-}
-
-unsigned int pubsub_topicGetNrSubscribers(topic_subscription_pt ts) {
- return ts->nrSubscribers;
-}
-
-array_list_pt pubsub_topicSubscriptionGetSubscribersList(topic_subscription_pt sub){
- return sub->sub_ep_list;
-}
-
-static celix_status_t topicsub_subscriberTracked(void * handle, service_reference_pt reference, void * service){
- celix_status_t status = CELIX_SUCCESS;
- topic_subscription_pt ts = handle;
-
- celixThreadMutex_lock(&ts->ts_lock);
- if (!hashMap_containsKey(ts->servicesMap, service)) {
- bundle_pt bundle = NULL;
- hash_map_pt msgTypes = NULL;
-
- serviceReference_getBundle(reference, &bundle);
-
- if(ts->serializer != NULL && bundle!=NULL){
- ts->serializer->createSerializerMap(ts->serializer->handle,bundle,&msgTypes);
- if(msgTypes != NULL){
- hashMap_put(ts->servicesMap, service, msgTypes);
- printf("PSA_ZMQ_TS: New subscriber registered.\n");
- }
- }
- else{
- printf("PSA_ZMQ_TS: Cannot register new subscriber.\n");
- status = CELIX_SERVICE_EXCEPTION;
- }
- }
- celixThreadMutex_unlock(&ts->ts_lock);
-
- return status;
-}
-
-static celix_status_t topicsub_subscriberUntracked(void * handle, service_reference_pt reference, void * service){
- celix_status_t status = CELIX_SUCCESS;
- topic_subscription_pt ts = handle;
-
- celixThreadMutex_lock(&ts->ts_lock);
- if (hashMap_containsKey(ts->servicesMap, service)) {
- hash_map_pt msgTypes = hashMap_remove(ts->servicesMap, service);
- if(msgTypes!=NULL && ts->serializer!=NULL){
- ts->serializer->destroySerializerMap(ts->serializer->handle,msgTypes);
- printf("PSA_ZMQ_TS: Subscriber unregistered.\n");
- }
- else{
- printf("PSA_ZMQ_TS: Cannot unregister subscriber.\n");
- status = CELIX_SERVICE_EXCEPTION;
- }
- }
- celixThreadMutex_unlock(&ts->ts_lock);
-
- return status;
-}
-
-
-static void process_msg(topic_subscription_pt sub,array_list_pt msg_list){
-
- pubsub_msg_header_pt first_msg_hdr = (pubsub_msg_header_pt)zframe_data(((complete_zmq_msg_pt)arrayList_get(msg_list,0))->header);
-
- hash_map_iterator_pt iter = hashMapIterator_create(sub->servicesMap);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- pubsub_subscriber_pt subsvc = hashMapEntry_getKey(entry);
- hash_map_pt msgTypes = hashMapEntry_getValue(entry);
-
- pubsub_msg_serializer_t *msgSer = hashMap_get(msgTypes,(void*)(uintptr_t )first_msg_hdr->type);
- if (msgSer == NULL) {
- printf("PSA_ZMQ_TS: Primary message %d not supported. NOT sending any part of the whole message.\n",first_msg_hdr->type);
- }
- else{
- void *msgInst = NULL;
- bool validVersion = checkVersion(msgSer->msgVersion,first_msg_hdr);
-
- if(validVersion){
-
- celix_status_t status = msgSer->deserialize(msgSer, (const void *) zframe_data(((complete_zmq_msg_pt)arrayList_get(msg_list,0))->payload), 0, &msgInst);
-
- if (status == CELIX_SUCCESS) {
- bool release = true;
- mp_handle_pt mp_handle = create_mp_handle(msgTypes,msg_list);
- pubsub_multipart_callbacks_t mp_callbacks;
- mp_callbacks.handle = mp_handle;
- mp_callbacks.localMsgTypeIdForMsgType = pubsub_localMsgTypeIdForMsgType;
- mp_callbacks.getMultipart = pubsub_getMultipart;
- subsvc->receive(subsvc->handle, msgSer->msgName, first_msg_hdr->type, msgInst, &mp_callbacks, &release);
-
- if(release){
- msgSer->freeMsg(msgSer,msgInst); // pubsubSerializer_freeMsg(msgType, msgInst);
- }
- if(mp_handle!=NULL){
- destroy_mp_handle(mp_handle);
- }
- }
- else{
- printf("PSA_ZMQ_TS: Cannot deserialize msgType %s.\n",msgSer->msgName);
- }
-
- }
- else{
- int major=0,minor=0;
- version_getMajor(msgSer->msgVersion,&major);
- version_getMinor(msgSer->msgVersion,&minor);
- printf("PSA_ZMQ_TS: Version mismatch for primary message '%s' (have %d.%d, received %u.%u). NOT sending any part of the whole message.\n",
- msgSer->msgName,major,minor,first_msg_hdr->major,first_msg_hdr->minor);
- }
-
- }
- }
- hashMapIterator_destroy(iter);
-
- int i = 0;
- for(;i<arrayList_size(msg_list);i++){
- complete_zmq_msg_pt c_msg = arrayList_get(msg_list,i);
- zframe_destroy(&(c_msg->header));
- zframe_destroy(&(c_msg->payload));
- free(c_msg);
- }
-
- arrayList_destroy(msg_list);
-
-}
-
-static void* zmq_recv_thread_func(void * arg) {
- topic_subscription_pt sub = (topic_subscription_pt) arg;
-
- while (sub->running) {
-
- celixThreadMutex_lock(&sub->socket_lock);
-
- zframe_t* headerMsg = zframe_recv(sub->zmq_socket);
- if (headerMsg == NULL) {
- if (errno == EINTR) {
- //It means we got a signal and we have to exit...
- printf("PSA_ZMQ_TS: header_recv thread for topic got a signal and will exit.\n");
- } else {
- perror("PSA_ZMQ_TS: header_recv thread");
- }
- }
- else {
-
- pubsub_msg_header_pt hdr = (pubsub_msg_header_pt) zframe_data(headerMsg);
-
- if (zframe_more(headerMsg)) {
-
- zframe_t* payloadMsg = zframe_recv(sub->zmq_socket);
- if (payloadMsg == NULL) {
- if (errno == EINTR) {
- //It means we got a signal and we have to exit...
- printf("PSA_ZMQ_TS: payload_recv thread for topic got a signal and will exit.\n");
- } else {
- perror("PSA_ZMQ_TS: payload_recv");
- }
- zframe_destroy(&headerMsg);
- } else {
-
- //Let's fetch all the messages from the socket
- array_list_pt msg_list = NULL;
- arrayList_create(&msg_list);
- complete_zmq_msg_pt firstMsg = calloc(1, sizeof(struct complete_zmq_msg));
- firstMsg->header = headerMsg;
- firstMsg->payload = payloadMsg;
- arrayList_add(msg_list, firstMsg);
-
- bool more = zframe_more(payloadMsg);
- while (more) {
-
- zframe_t* h_msg = zframe_recv(sub->zmq_socket);
- if (h_msg == NULL) {
- if (errno == EINTR) {
- //It means we got a signal and we have to exit...
- printf("PSA_ZMQ_TS: h_recv thread for topic got a signal and will exit.\n");
- } else {
- perror("PSA_ZMQ_TS: h_recv");
- }
- break;
- }
-
- zframe_t* p_msg = zframe_recv(sub->zmq_socket);
- if (p_msg == NULL) {
- if (errno == EINTR) {
- //It means we got a signal and we have to exit...
- printf("PSA_ZMQ_TS: p_recv thread for topic got a signal and will exit.\n");
- } else {
- perror("PSA_ZMQ_TS: p_recv");
- }
- zframe_destroy(&h_msg);
- break;
- }
-
- complete_zmq_msg_pt c_msg = calloc(1, sizeof(struct complete_zmq_msg));
- c_msg->header = h_msg;
- c_msg->payload = p_msg;
- arrayList_add(msg_list, c_msg);
-
- if (!zframe_more(p_msg)) {
- more = false;
- }
- }
-
- celixThreadMutex_lock(&sub->ts_lock);
- process_msg(sub, msg_list);
- celixThreadMutex_unlock(&sub->ts_lock);
-
- }
-
- } //zframe_more(headerMsg)
- else {
- free(headerMsg);
- printf("PSA_ZMQ_TS: received message %u for topic %s without payload!\n", hdr->type, hdr->topic);
- }
-
- } // headerMsg != NULL
- celixThreadMutex_unlock(&sub->socket_lock);
- connectPendingPublishers(sub);
- disconnectPendingPublishers(sub);
- } // while
-
- return NULL;
-}
-
-static void connectPendingPublishers(topic_subscription_pt sub) {
- celixThreadMutex_lock(&sub->pendingConnections_lock);
- while(!arrayList_isEmpty(sub->pendingConnections)) {
- char * pubEP = arrayList_remove(sub->pendingConnections, 0);
- pubsub_topicSubscriptionConnectPublisher(sub, pubEP);
- free(pubEP);
- }
- celixThreadMutex_unlock(&sub->pendingConnections_lock);
-}
-
-static void disconnectPendingPublishers(topic_subscription_pt sub) {
- celixThreadMutex_lock(&sub->pendingDisconnections_lock);
- while(!arrayList_isEmpty(sub->pendingDisconnections)) {
- char * pubEP = arrayList_remove(sub->pendingDisconnections, 0);
- pubsub_topicSubscriptionDisconnectPublisher(sub, pubEP);
- free(pubEP);
- }
- celixThreadMutex_unlock(&sub->pendingDisconnections_lock);
-}
-
-static void sigusr1_sighandler(int signo){
- printf("PSA_ZMQ_TS: Topic subscription being shut down...\n");
- return;
-}
-
-static bool checkVersion(version_pt msgVersion,pubsub_msg_header_pt hdr){
- bool check=false;
- int major=0,minor=0;
-
- if(msgVersion!=NULL){
- version_getMajor(msgVersion,&major);
- version_getMinor(msgVersion,&minor);
- if(hdr->major==((unsigned char)major)){ /* Different major means incompatible */
- check = (hdr->minor>=((unsigned char)minor)); /* Compatible only if the provider has a minor equals or greater (means compatible update) */
- }
- }
-
- return check;
-}
-
-static int pubsub_localMsgTypeIdForMsgType(void* handle, const char* msgType, unsigned int* msgTypeId){
- *msgTypeId = utils_stringHash(msgType);
- return 0;
-}
-
-static int pubsub_getMultipart(void *handle, unsigned int msgTypeId, bool retain, void **part){
-
- if(handle==NULL){
- *part = NULL;
- return -1;
- }
-
- mp_handle_pt mp_handle = (mp_handle_pt)handle;
- msg_map_entry_pt entry = hashMap_get(mp_handle->rcv_msg_map, (void*)(uintptr_t) msgTypeId);
- if(entry!=NULL){
- entry->retain = retain;
- *part = entry->msgInst;
- }
- else{
- printf("TP: getMultipart cannot find msg '%u'\n",msgTypeId);
- *part=NULL;
- return -2;
- }
-
- return 0;
-
-}
-
-static mp_handle_pt create_mp_handle(hash_map_pt svc_msg_db,array_list_pt rcv_msg_list){
-
- if(arrayList_size(rcv_msg_list)==1){ //Means it's not a multipart message
- return NULL;
- }
-
- mp_handle_pt mp_handle = calloc(1,sizeof(struct mp_handle));
- mp_handle->svc_msg_db = svc_msg_db;
- mp_handle->rcv_msg_map = hashMap_create(NULL, NULL, NULL, NULL);
-
- int i=1; //We skip the first message, it will be handle differently
- for(;i<arrayList_size(rcv_msg_list);i++){
- complete_zmq_msg_pt c_msg = (complete_zmq_msg_pt)arrayList_get(rcv_msg_list,i);
- pubsub_msg_header_pt header = (pubsub_msg_header_pt)zframe_data(c_msg->header);
-
- pubsub_msg_serializer_t* msgSer = hashMap_get(svc_msg_db, (void*)(uintptr_t)(header->type));
-
- if (msgSer!= NULL) {
- void *msgInst = NULL;
-
- bool validVersion = checkVersion(msgSer->msgVersion,header);
-
- if(validVersion){
- celix_status_t status = msgSer->deserialize(msgSer, (const void*)zframe_data(c_msg->payload), 0, &msgInst);
-
- if(status == CELIX_SUCCESS){
- msg_map_entry_pt entry = calloc(1,sizeof(struct msg_map_entry));
- entry->msgInst = msgInst;
- hashMap_put(mp_handle->rcv_msg_map, (void*)(uintptr_t)header->type,entry);
- }
- }
- }
- }
-
- return mp_handle;
-
-}
-
-static void destroy_mp_handle(mp_handle_pt mp_handle){
-
- hash_map_iterator_pt iter = hashMapIterator_create(mp_handle->rcv_msg_map);
- while(hashMapIterator_hasNext(iter)){
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- unsigned int msgId = (unsigned int)(uintptr_t)hashMapEntry_getKey(entry);
- msg_map_entry_pt msgEntry = hashMapEntry_getValue(entry);
- pubsub_msg_serializer_t* msgSer = hashMap_get(mp_handle->svc_msg_db, (void*)(uintptr_t)msgId);
-
- if(msgSer!=NULL){
- if(!msgEntry->retain){
- msgSer->freeMsg(msgSer->handle,msgEntry->msgInst);
- }
- }
- else{
- printf("PSA_ZMQ_TS: ERROR: Cannot find messageSerializer for msg %u, so cannot destroy it!\n",msgId);
- }
-
- free(msgEntry);
- }
- hashMapIterator_destroy(iter);
-
- hashMap_destroy(mp_handle->rcv_msg_map,false,false);
- free(mp_handle);
-}
[06/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
deleted file mode 100644
index 9feab9f..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
+++ /dev/null
@@ -1,775 +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.
- */
-/*
- * remote_service_admin_impl.c
- *
- * \date May 21, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <ifaddrs.h>
-#include <string.h>
-#include <uuid/uuid.h>
-#include <curl/curl.h>
-
-#include <jansson.h>
-#include "json_serializer.h"
-#include "remote_service_admin.h"
-#include "celix_threads.h"
-#include "hash_map.h"
-#include "array_list.h"
-
-#include "import_registration_dfi.h"
-#include "export_registration_dfi.h"
-#include "remote_service_admin_dfi.h"
-#include "dyn_interface.h"
-#include "json_rpc.h"
-
-#include "remote_constants.h"
-#include "constants.h"
-#include "civetweb.h"
-
-// defines how often the webserver is restarted (with an increased port number)
-#define MAX_NUMBER_OF_RESTARTS 5
-
-
-#define RSA_LOG_ERROR(admin, msg, ...) \
- logHelper_log((admin)->loghelper, OSGI_LOGSERVICE_ERROR, (msg), ##__VA_ARGS__)
-
-#define RSA_LOG_WARNING(admin, msg, ...) \
- logHelper_log((admin)->loghelper, OSGI_LOGSERVICE_ERROR, (msg), ##__VA_ARGS__)
-
-#define RSA_LOG_DEBUG(admin, msg, ...) \
- logHelper_log((admin)->loghelper, OSGI_LOGSERVICE_ERROR, (msg), ##__VA_ARGS__)
-
-struct remote_service_admin {
- bundle_context_pt context;
- log_helper_pt loghelper;
-
- celix_thread_mutex_t exportedServicesLock;
- hash_map_pt exportedServices;
-
- celix_thread_mutex_t importedServicesLock;
- array_list_pt importedServices;
-
- char *port;
- char *ip;
-
- struct mg_context *ctx;
-};
-
-struct post {
- const char *readptr;
- int size;
-};
-
-struct get {
- char *writeptr;
- int size;
-};
-
-#define OSGI_RSA_REMOTE_PROXY_FACTORY "remote_proxy_factory"
-#define OSGI_RSA_REMOTE_PROXY_TIMEOUT "remote_proxy_timeout"
-
-static const char *data_response_headers =
- "HTTP/1.1 200 OK\r\n"
- "Cache: no-cache\r\n"
- "Content-Type: application/json\r\n"
- "\r\n";
-
-static const char *no_content_response_headers =
- "HTTP/1.1 204 OK\r\n";
-
-// TODO do we need to specify a non-Amdatu specific configuration type?!
-static const char * const CONFIGURATION_TYPE = "org.amdatu.remote.admin.http";
-static const char * const ENDPOINT_URL = "org.amdatu.remote.admin.http.url";
-
-static const char *DEFAULT_PORT = "8888";
-static const char *DEFAULT_IP = "127.0.0.1";
-
-static const unsigned int DEFAULT_TIMEOUT = 0;
-
-static int remoteServiceAdmin_callback(struct mg_connection *conn);
-static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, properties_pt props, char *interface, endpoint_description_pt *description);
-static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
-static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip);
-static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp);
-static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp);
-static void remoteServiceAdmin_log(remote_service_admin_pt admin, int level, const char *file, int line, const char *msg, ...);
-
-celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin) {
- celix_status_t status = CELIX_SUCCESS;
-
- *admin = calloc(1, sizeof(**admin));
-
- if (!*admin) {
- status = CELIX_ENOMEM;
- } else {
- unsigned int port_counter = 0;
- const char *port = NULL;
- const char *ip = NULL;
- char *detectedIp = NULL;
- (*admin)->context = context;
- (*admin)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL);
- arrayList_create(&(*admin)->importedServices);
-
- celixThreadMutex_create(&(*admin)->exportedServicesLock, NULL);
- celixThreadMutex_create(&(*admin)->importedServicesLock, NULL);
-
- if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
- logHelper_start((*admin)->loghelper);
- dynCommon_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
- dynType_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
- dynFunction_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
- dynInterface_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
- jsonSerializer_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
- jsonRpc_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
- }
-
- bundleContext_getProperty(context, "RSA_PORT", &port);
- if (port == NULL) {
- port = (char *)DEFAULT_PORT;
- }
-
- bundleContext_getProperty(context, "RSA_IP", &ip);
- if (ip == NULL) {
- const char *interface = NULL;
-
- bundleContext_getProperty(context, "RSA_INTERFACE", &interface);
- if ((interface != NULL) && (remoteServiceAdmin_getIpAdress((char*)interface, &detectedIp) != CELIX_SUCCESS)) {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: Could not retrieve IP adress for interface %s", interface);
- }
-
- if (ip == NULL) {
- remoteServiceAdmin_getIpAdress(NULL, &detectedIp);
- }
-
- ip = detectedIp;
- }
-
- if (ip != NULL) {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Using %s for service annunciation", ip);
- (*admin)->ip = strdup(ip);
- }
- else {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No IP address for service annunciation set. Using %s", DEFAULT_IP);
- (*admin)->ip = strdup((char*) DEFAULT_IP);
- }
-
- if (detectedIp != NULL) {
- free(detectedIp);
- }
-
- // Prepare callbacks structure. We have only one callback, the rest are NULL.
- struct mg_callbacks callbacks;
- memset(&callbacks, 0, sizeof(callbacks));
- callbacks.begin_request = remoteServiceAdmin_callback;
-
- char newPort[10];
-
- do {
-
- const char *options[] = { "listening_ports", port, "num_threads", "5", NULL};
-
- (*admin)->ctx = mg_start(&callbacks, (*admin), options);
-
- if ((*admin)->ctx != NULL) {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Start webserver: %s", port);
- (*admin)->port = strdup(port);
-
- }
- else {
- errno = 0;
- char* endptr = (char*)port;
- int currentPort = strtol(port, &endptr, 10);
-
- if (*endptr || errno != 0) {
- currentPort = strtol(DEFAULT_PORT, NULL, 10);
- }
-
- port_counter++;
- snprintf(&newPort[0], 6, "%d", (currentPort+1));
-
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_ERROR, "Error while starting rsa server on port %s - retrying on port %s...", port, newPort);
- port = newPort;
- }
- } while(((*admin)->ctx == NULL) && (port_counter < MAX_NUMBER_OF_RESTARTS));
-
- }
-
- return status;
-}
-
-
-celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin)
-{
- celix_status_t status = CELIX_SUCCESS;
-
- free((*admin)->ip);
- free((*admin)->port);
- free(*admin);
-
- //TODO destroy exports/imports
-
- *admin = NULL;
-
- return status;
-}
-
-
-celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin) {
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&admin->exportedServicesLock);
-
- hash_map_iterator_pt iter = hashMapIterator_create(admin->exportedServices);
- while (hashMapIterator_hasNext(iter)) {
- array_list_pt exports = hashMapIterator_nextValue(iter);
- int i;
- for (i = 0; i < arrayList_size(exports); i++) {
- export_registration_pt export = arrayList_get(exports, i);
- if (export != NULL) {
- exportRegistration_stop(export);
- exportRegistration_destroy(export);
- }
- }
- arrayList_destroy(exports);
- }
- hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&admin->exportedServicesLock);
-
- celixThreadMutex_lock(&admin->importedServicesLock);
- int i;
- int size = arrayList_size(admin->importedServices);
- for (i = 0; i < size ; i += 1) {
- import_registration_pt import = arrayList_get(admin->importedServices, i);
- if (import != NULL) {
- importRegistration_stop(import);
- importRegistration_destroy(import);
- }
- }
- celixThreadMutex_unlock(&admin->importedServicesLock);
-
- if (admin->ctx != NULL) {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Stopping webserver...");
- mg_stop(admin->ctx);
- admin->ctx = NULL;
- }
-
- hashMap_destroy(admin->exportedServices, false, false);
- arrayList_destroy(admin->importedServices);
-
- logHelper_stop(admin->loghelper);
- logHelper_destroy(&admin->loghelper);
-
- return status;
-}
-
-/**
- * Request: http://host:port/services/{service}/{request}
- */
-//void *remoteServiceAdmin_callback(enum mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info) {
-
-celix_status_t importRegistration_getFactory(import_registration_pt import, service_factory_pt *factory);
-
-static int remoteServiceAdmin_callback(struct mg_connection *conn) {
- int result = 1; // zero means: let civetweb handle it further, any non-zero value means it is handled by us...
-
- const struct mg_request_info *request_info = mg_get_request_info(conn);
- if (request_info->uri != NULL) {
- remote_service_admin_pt rsa = request_info->user_data;
-
-
- if (strncmp(request_info->uri, "/service/", 9) == 0 && strcmp("POST", request_info->request_method) == 0) {
-
- // uri = /services/myservice/call
- const char *uri = request_info->uri;
- // rest = myservice/call
-
- const char *rest = uri+9;
- char *interfaceStart = strchr(rest, '/');
- int pos = interfaceStart - rest;
- char service[pos+1];
- strncpy(service, rest, pos);
- service[pos] = '\0';
- unsigned long serviceId = strtoul(service,NULL,10);
-
- celixThreadMutex_lock(&rsa->exportedServicesLock);
-
- //find endpoint
- export_registration_pt export = NULL;
- hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- array_list_pt exports = hashMapEntry_getValue(entry);
- int expIt = 0;
- for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
- export_registration_pt check = arrayList_get(exports, expIt);
- export_reference_pt ref = NULL;
- exportRegistration_getExportReference(check, &ref);
- endpoint_description_pt checkEndpoint = NULL;
- exportReference_getExportedEndpoint(ref, &checkEndpoint);
- if (serviceId == checkEndpoint->serviceId) {
- export = check;
- free(ref);
- break;
- }
- free(ref);
- }
- }
- hashMapIterator_destroy(iter);
-
- if (export != NULL) {
-
- uint64_t datalength = request_info->content_length;
- char* data = malloc(datalength + 1);
- mg_read(conn, data, datalength);
- data[datalength] = '\0';
-
- char *response = NULL;
- int responceLength = 0;
- int rc = exportRegistration_call(export, data, -1, &response, &responceLength);
- if (rc != CELIX_SUCCESS) {
- RSA_LOG_ERROR(rsa, "Error trying to invoke remove service, got error %i\n", rc);
- }
-
- if (rc == CELIX_SUCCESS && response != NULL) {
- mg_write(conn, data_response_headers, strlen(data_response_headers));
- mg_write(conn, response, strlen(response));
- free(response);
- } else {
- mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
- }
- result = 1;
-
- free(data);
- } else {
- result = 0;
- RSA_LOG_WARNING(rsa, "NO export registration found for service id %lu", serviceId);
- }
-
- celixThreadMutex_unlock(&rsa->exportedServicesLock);
-
- }
- }
-
- return result;
-}
-
-celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations) {
- celix_status_t status;
-
- arrayList_create(registrations);
- array_list_pt references = NULL;
- service_reference_pt reference = NULL;
- char filter [256];
-
- snprintf(filter, 256, "(%s=%s)", (char *)OSGI_FRAMEWORK_SERVICE_ID, serviceId);
-
- status = bundleContext_getServiceReferences(admin->context, NULL, filter, &references);
-
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: exportService called for serviceId %s", serviceId);
-
- int i;
- int size = arrayList_size(references);
- for (i = 0; i < size; i += 1) {
- if (i == 0) {
- reference = arrayList_get(references, i);
- } else {
- bundleContext_ungetServiceReference(admin->context, arrayList_get(references, i));
- }
- }
- arrayList_destroy(references);
-
- if (reference == NULL) {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "ERROR: expected a reference for service id %s.", serviceId);
- status = CELIX_ILLEGAL_STATE;
- }
-
- const char *exports = NULL;
- const char *provided = NULL;
- if (status == CELIX_SUCCESS) {
- serviceReference_getProperty(reference, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exports);
- serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_OBJECTCLASS, &provided);
-
- if (exports == NULL || provided == NULL || strcmp(exports, provided) != 0) {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No Services to export.");
- status = CELIX_ILLEGAL_STATE;
- } else {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Export service (%s)", provided);
- }
- }
-
- if (status == CELIX_SUCCESS) {
- const char *interface = provided;
- endpoint_description_pt endpoint = NULL;
- export_registration_pt registration = NULL;
-
- remoteServiceAdmin_createEndpointDescription(admin, reference, properties, (char*)interface, &endpoint);
- //TODO precheck if descriptor exists
- status = exportRegistration_create(admin->loghelper, reference, endpoint, admin->context, ®istration);
- if (status == CELIX_SUCCESS) {
- status = exportRegistration_start(registration);
- if (status == CELIX_SUCCESS) {
- arrayList_add(*registrations, registration);
- }
- }
- }
-
-
- if (status == CELIX_SUCCESS) {
- celixThreadMutex_lock(&admin->exportedServicesLock);
- hashMap_put(admin->exportedServices, reference, *registrations);
- celixThreadMutex_unlock(&admin->exportedServicesLock);
- }
- else{
- arrayList_destroy(*registrations);
- *registrations = NULL;
- }
-
- return status;
-}
-
-celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration) {
- celix_status_t status;
-
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_DFI: Removing exported service");
-
- export_reference_pt ref = NULL;
- status = exportRegistration_getExportReference(registration, &ref);
-
- if (status == CELIX_SUCCESS && ref != NULL) {
- service_reference_pt servRef;
- celixThreadMutex_lock(&admin->exportedServicesLock);
- exportReference_getExportedService(ref, &servRef);
-
- array_list_pt exports = (array_list_pt)hashMap_remove(admin->exportedServices, servRef);
- if(exports!=NULL){
- arrayList_destroy(exports);
- }
-
- exportRegistration_close(registration);
- exportRegistration_destroy(registration);
-
- celixThreadMutex_unlock(&admin->exportedServicesLock);
-
- free(ref);
-
- } else {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "Cannot find reference for registration");
- }
-
- return status;
-}
-
-static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, properties_pt props, char *interface, endpoint_description_pt *endpoint) {
-
- celix_status_t status = CELIX_SUCCESS;
- properties_pt endpointProperties = properties_create();
-
-
- unsigned int size = 0;
- char **keys;
-
- serviceReference_getPropertyKeys(reference, &keys, &size);
- for (int i = 0; i < size; i++) {
- char *key = keys[i];
- const char *value = NULL;
-
- if (serviceReference_getProperty(reference, key, &value) == CELIX_SUCCESS
- && strcmp(key, (char*) OSGI_RSA_SERVICE_EXPORTED_INTERFACES) != 0
- && strcmp(key, (char*) OSGI_FRAMEWORK_OBJECTCLASS) != 0) {
- properties_set(endpointProperties, key, value);
- }
- }
-
- hash_map_entry_pt entry = hashMap_getEntry(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
-
- char* key = hashMapEntry_getKey(entry);
- char *serviceId = (char *) hashMap_remove(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
- const char *uuid = NULL;
-
- char buf[512];
- snprintf(buf, 512, "/service/%s/%s", serviceId, interface);
-
- char url[1024];
- snprintf(url, 1024, "http://%s:%s%s", admin->ip, admin->port, buf);
-
- uuid_t endpoint_uid;
- uuid_generate(endpoint_uid);
- char endpoint_uuid[37];
- uuid_unparse_lower(endpoint_uid, endpoint_uuid);
-
- bundleContext_getProperty(admin->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
- properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
- properties_set(endpointProperties, (char*) OSGI_FRAMEWORK_OBJECTCLASS, interface);
- properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_SERVICE_ID, serviceId);
- properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID, endpoint_uuid);
- properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED, "true");
- properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED_CONFIGS, (char*) CONFIGURATION_TYPE);
- properties_set(endpointProperties, (char*) ENDPOINT_URL, url);
-
- if (props != NULL) {
- hash_map_iterator_pt propIter = hashMapIterator_create(props);
- while (hashMapIterator_hasNext(propIter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(propIter);
- properties_set(endpointProperties, (char*)hashMapEntry_getKey(entry), (char*)hashMapEntry_getValue(entry));
- }
- hashMapIterator_destroy(propIter);
- }
-
- *endpoint = calloc(1, sizeof(**endpoint));
- if (!*endpoint) {
- status = CELIX_ENOMEM;
- } else {
- (*endpoint)->id = (char*)properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID);
- const char *serviceId = NULL;
- serviceReference_getProperty(reference, (char*) OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
- (*endpoint)->serviceId = strtoull(serviceId, NULL, 0);
- (*endpoint)->frameworkUUID = (char*) properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
- (*endpoint)->service = strndup(interface, 1024*10);
- (*endpoint)->properties = endpointProperties;
- }
-
- free(key);
- free(serviceId);
- free(keys);
-
- return status;
-}
-
-static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip) {
- celix_status_t status = CELIX_BUNDLE_EXCEPTION;
-
- struct ifaddrs *ifaddr, *ifa;
- char host[NI_MAXHOST];
-
- if (getifaddrs(&ifaddr) != -1)
- {
- for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
- {
- if (ifa->ifa_addr == NULL)
- continue;
-
- if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
- if (interface == NULL) {
- *ip = strdup(host);
- status = CELIX_SUCCESS;
- }
- else if (strcmp(ifa->ifa_name, interface) == 0) {
- *ip = strdup(host);
- status = CELIX_SUCCESS;
- }
- }
- }
-
- freeifaddrs(ifaddr);
- }
-
- return status;
-}
-
-
-celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description)
-{
- celix_status_t status = CELIX_SUCCESS;
-
- properties_destroy((*description)->properties);
- free((*description)->service);
- free(*description);
-
- return status;
-}
-
-
-celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpointDescription, import_registration_pt *out) {
- celix_status_t status = CELIX_SUCCESS;
- import_registration_pt import = NULL;
-
- const char *objectClass = properties_get(endpointDescription->properties, "objectClass");
- const char *serviceVersion = properties_get(endpointDescription->properties, (char*) CELIX_FRAMEWORK_SERVICE_VERSION);
-
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Import service %s", endpointDescription->service);
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "Registering service factory (proxy) for service '%s'\n", objectClass);
-
- if (objectClass != NULL) {
- status = importRegistration_create(admin->context, endpointDescription, objectClass, serviceVersion, &import);
- }
- if (status == CELIX_SUCCESS && import != NULL) {
- importRegistration_setSendFn(import, (send_func_type) remoteServiceAdmin_send, admin);
- }
-
- if (status == CELIX_SUCCESS && import != NULL) {
- status = importRegistration_start(import);
- }
-
- celixThreadMutex_lock(&admin->importedServicesLock);
- arrayList_add(admin->importedServices, import);
- celixThreadMutex_unlock(&admin->importedServicesLock);
-
- if (status == CELIX_SUCCESS) {
- *out = import;
- }
-
- return status;
-}
-
-
-celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_DFI: Removing imported service");
-
- celixThreadMutex_lock(&admin->importedServicesLock);
- int i;
- int size = arrayList_size(admin->importedServices);
- import_registration_pt current = NULL;
- for (i = 0; i < size; i += 1) {
- current = arrayList_get(admin->importedServices, i);
- if (current == registration) {
- arrayList_remove(admin->importedServices, i);
- importRegistration_close(current);
- importRegistration_destroy(current);
- break;
- }
- }
- celixThreadMutex_unlock(&admin->importedServicesLock);
-
- return status;
-}
-
-
-static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus) {
- remote_service_admin_pt rsa = handle;
- struct post post;
- post.readptr = request;
- post.size = strlen(request);
-
- struct get get;
- get.size = 0;
- get.writeptr = malloc(1);
-
- char *serviceUrl = (char*)properties_get(endpointDescription->properties, (char*) ENDPOINT_URL);
- char url[256];
- snprintf(url, 256, "%s", serviceUrl);
-
- // assume the default timeout
- int timeout = DEFAULT_TIMEOUT;
-
- const char *timeoutStr = NULL;
- // Check if the endpoint has a timeout, if so, use it.
- timeoutStr = (char*) properties_get(endpointDescription->properties, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT);
- if (timeoutStr == NULL) {
- // If not, get the global variable and use that one.
- bundleContext_getProperty(rsa->context, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT, &timeoutStr);
- }
-
- // Update timeout if a property is used to set it.
- if (timeoutStr != NULL) {
- timeout = atoi(timeoutStr);
- }
-
- celix_status_t status = CELIX_SUCCESS;
- CURL *curl;
- CURLcode res;
-
- curl = curl_easy_init();
- if(!curl) {
- status = CELIX_ILLEGAL_STATE;
- } else {
- curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
- curl_easy_setopt(curl, CURLOPT_URL, url);
- curl_easy_setopt(curl, CURLOPT_POST, 1L);
- curl_easy_setopt(curl, CURLOPT_READFUNCTION, remoteServiceAdmin_readCallback);
- curl_easy_setopt(curl, CURLOPT_READDATA, &post);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, remoteServiceAdmin_write);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&get);
- curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)post.size);
- logHelper_log(rsa->loghelper, OSGI_LOGSERVICE_DEBUG, "RSA: Performing curl post\n");
- res = curl_easy_perform(curl);
-
- *reply = get.writeptr;
- *replyStatus = res;
-
- curl_easy_cleanup(curl);
- }
-
- return status;
-}
-
-static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp) {
- struct post *post = userp;
-
- if (post->size) {
- *(char *) ptr = post->readptr[0];
- post->readptr++;
- post->size--;
- return 1;
- }
-
- return 0;
-}
-
-static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp) {
- size_t realsize = size * nmemb;
- struct get *mem = (struct get *)userp;
-
- mem->writeptr = realloc(mem->writeptr, mem->size + realsize + 1);
- if (mem->writeptr == NULL) {
- /* out of memory! */
- printf("not enough memory (realloc returned NULL)");
- exit(EXIT_FAILURE);
- }
-
- memcpy(&(mem->writeptr[mem->size]), contents, realsize);
- mem->size += realsize;
- mem->writeptr[mem->size] = 0;
-
- return realsize;
-}
-
-
-static void remoteServiceAdmin_log(remote_service_admin_pt admin, int level, const char *file, int line, const char *msg, ...) {
- va_list ap;
- va_start(ap, msg);
- int levels[5] = {0, OSGI_LOGSERVICE_ERROR, OSGI_LOGSERVICE_WARNING, OSGI_LOGSERVICE_INFO, OSGI_LOGSERVICE_DEBUG};
-
- char buf1[256];
- snprintf(buf1, 256, "FILE:%s, LINE:%i, MSG:", file, line);
-
- char buf2[256];
- vsnprintf(buf2, 256, msg, ap);
- logHelper_log(admin->loghelper, levels[level], "%s%s", buf1, buf2);
- va_end(ap);
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/src/dfi_utils.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/dfi_utils.c b/remote_services/remote_service_admin_dfi/rsa/src/dfi_utils.c
new file mode 100644
index 0000000..1b1eb36
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/src/dfi_utils.c
@@ -0,0 +1,98 @@
+/**
+ *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.
+ */
+
+#include "dfi_utils.h"
+#include <stdlib.h>
+#include <unistd.h>
+
+static celix_status_t dfi_findFileForFramework(bundle_context_pt context, const char *fileName, FILE **out) {
+ celix_status_t status;
+
+ char pwd[1024];
+ char path[1024];
+ const char *extPath = NULL;
+
+ status = bundleContext_getProperty(context, "CELIX_FRAMEWORK_EXTENDER_PATH", &extPath);
+ if (status != CELIX_SUCCESS || extPath == NULL) {
+ getcwd(pwd, sizeof(pwd));
+ extPath = pwd;
+ }
+
+ snprintf(path, sizeof(path), "%s/%s", extPath, fileName);
+
+ if (status == CELIX_SUCCESS) {
+ FILE *df = fopen(path, "r");
+ if (df == NULL) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ } else {
+ *out = df;
+ }
+ }
+
+ return status;
+}
+
+static celix_status_t dfi_findFileForBundle(bundle_pt bundle, const char *fileName, FILE **out) {
+ celix_status_t status;
+
+ char *path = NULL;
+ char metaInfFileName[512];
+ snprintf(metaInfFileName, sizeof(metaInfFileName), "META-INF/descriptors/%s", fileName);
+
+ status = bundle_getEntry(bundle, fileName, &path);
+
+ if (status != CELIX_SUCCESS || path == NULL) {
+ status = bundle_getEntry(bundle, metaInfFileName, &path);
+ }
+
+ if (status == CELIX_SUCCESS && path != NULL) {
+ FILE *df = fopen(path, "r");
+ if (df == NULL) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ } else {
+ *out = df;
+ }
+
+ }
+
+ free(path);
+ return status;
+}
+
+celix_status_t dfi_findDescriptor(bundle_context_pt context, bundle_pt bundle, const char *name, FILE **out) {
+ celix_status_t status;
+ char fileName[128];
+
+ snprintf(fileName, 128, "%s.descriptor", name);
+
+ long id;
+ status = bundle_getBundleId(bundle, &id);
+
+ if (status == CELIX_SUCCESS) {
+ if (id == 0) {
+ //framework bundle
+ status = dfi_findFileForFramework(context, fileName, out);
+ } else {
+ //normal bundle
+ status = dfi_findFileForBundle(bundle, fileName, out);
+ }
+ }
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/src/dfi_utils.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/dfi_utils.h b/remote_services/remote_service_admin_dfi/rsa/src/dfi_utils.h
new file mode 100644
index 0000000..cec8aa1
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/src/dfi_utils.h
@@ -0,0 +1,30 @@
+/**
+ *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.
+ */
+#ifndef DFI_UTILS_H_
+#define DFI_UTILS_H_
+
+#include "bundle.h"
+#include "bundle_context.h"
+#include <stdio.h>
+#include "celix_errno.h"
+
+
+celix_status_t dfi_findDescriptor(bundle_context_pt context, bundle_pt bundle, const char *name, FILE **out);
+
+#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/src/export_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/export_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/src/export_registration_dfi.c
new file mode 100644
index 0000000..b83b5a8
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/src/export_registration_dfi.c
@@ -0,0 +1,251 @@
+/**
+ *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.
+ */
+
+#include <jansson.h>
+#include <dyn_interface.h>
+#include <json_serializer.h>
+#include <remote_constants.h>
+#include <remote_service_admin.h>
+#include <service_tracker_customizer.h>
+#include <service_tracker.h>
+#include <json_rpc.h>
+#include "constants.h"
+#include "export_registration_dfi.h"
+#include "dfi_utils.h"
+
+struct export_reference {
+ endpoint_description_pt endpoint; //owner
+ service_reference_pt reference;
+};
+
+struct export_registration {
+ bundle_context_pt context;
+ struct export_reference exportReference;
+ char *servId;
+ dyn_interface_type *intf; //owner
+ service_tracker_pt tracker;
+
+ celix_thread_mutex_t mutex;
+ void *service; //protected by mutex
+
+ //TODO add tracker and lock
+ bool closed;
+};
+
+static void exportRegistration_addServ(export_registration_pt reg, service_reference_pt ref, void *service);
+static void exportRegistration_removeServ(export_registration_pt reg, service_reference_pt ref, void *service);
+
+celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, bundle_context_pt context, export_registration_pt *out) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ const char *servId = NULL;
+ status = serviceReference_getProperty(reference, "service.id", &servId);
+ if (status != CELIX_SUCCESS) {
+ logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "Cannot find service.id for ref");
+ }
+
+ export_registration_pt reg = NULL;
+ if (status == CELIX_SUCCESS) {
+ reg = calloc(1, sizeof(*reg));
+ if (reg == NULL) {
+ status = CELIX_ENOMEM;
+ }
+ }
+
+
+ if (status == CELIX_SUCCESS) {
+ reg->context = context;
+ reg->exportReference.endpoint = endpoint;
+ reg->exportReference.reference = reference;
+ reg->closed = false;
+
+ celixThreadMutex_create(®->mutex, NULL);
+ }
+
+ const char *exports = NULL;
+ CELIX_DO_IF(status, serviceReference_getProperty(reference, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exports));
+
+ bundle_pt bundle = NULL;
+ CELIX_DO_IF(status, serviceReference_getBundle(reference, &bundle));
+
+ FILE *descriptor = NULL;
+ if (status == CELIX_SUCCESS) {
+ status = dfi_findDescriptor(context, bundle, exports, &descriptor);
+ }
+
+ if (status != CELIX_SUCCESS || descriptor == NULL) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Cannot find/open descriptor for '%s'", exports);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ int rc = dynInterface_parse(descriptor, ®->intf);
+ fclose(descriptor);
+ if (rc != 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "RSA: Error parsing service descriptor.");
+ }
+ else{
+ /* Add the interface version as a property in the properties_map */
+ char* intfVersion = NULL;
+ dynInterface_getVersionString(reg->intf, &intfVersion);
+ const char *serviceVersion = properties_get(endpoint->properties,(char*) CELIX_FRAMEWORK_SERVICE_VERSION);
+ if(serviceVersion!=NULL){
+ if(strcmp(serviceVersion,intfVersion)!=0){
+ logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "Service version (%s) and interface version from the descriptor (%s) are not the same!",serviceVersion,intfVersion);
+ }
+ }
+ else{
+ properties_set(endpoint->properties, (char*) CELIX_FRAMEWORK_SERVICE_VERSION, intfVersion);
+ }
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ service_tracker_customizer_pt cust = NULL;
+ status = serviceTrackerCustomizer_create(reg, NULL, (void *) exportRegistration_addServ, NULL,
+ (void *) exportRegistration_removeServ, &cust);
+ if (status == CELIX_SUCCESS) {
+ char filter[32];
+ snprintf(filter, 32, "(service.id=%s)", servId);
+ status = serviceTracker_createWithFilter(reg->context, filter, cust, ®->tracker);
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *out = reg;
+ } else {
+ logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Error creating export registration");
+ exportRegistration_destroy(reg);
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_call(export_registration_pt export, char *data, int datalength, char **responseOut, int *responseLength) {
+ int status = CELIX_SUCCESS;
+
+ //printf("calling for '%s'\n");
+
+ *responseLength = -1;
+ celixThreadMutex_lock(&export->mutex);
+ status = jsonRpc_call(export->intf, export->service, data, responseOut);
+ celixThreadMutex_unlock(&export->mutex);
+
+ return status;
+}
+
+void exportRegistration_destroy(export_registration_pt reg) {
+ if (reg != NULL) {
+ if (reg->intf != NULL) {
+ dyn_interface_type *intf = reg->intf;
+ reg->intf = NULL;
+ dynInterface_destroy(intf);
+ }
+
+ if (reg->exportReference.endpoint != NULL) {
+ endpoint_description_pt ep = reg->exportReference.endpoint;
+ reg->exportReference.endpoint = NULL;
+ endpointDescription_destroy(ep);
+ }
+ if (reg->tracker != NULL) {
+ serviceTracker_destroy(reg->tracker);
+ }
+ celixThreadMutex_destroy(®->mutex);
+
+ free(reg);
+ }
+}
+
+celix_status_t exportRegistration_start(export_registration_pt reg) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ serviceTracker_open(reg->tracker);
+ return status;
+}
+
+
+celix_status_t exportRegistration_stop(export_registration_pt reg) {
+ celix_status_t status = CELIX_SUCCESS;
+ if (status == CELIX_SUCCESS) {
+ status = bundleContext_ungetServiceReference(reg->context, reg->exportReference.reference);
+ serviceTracker_close(reg->tracker);
+ }
+ return status;
+}
+
+static void exportRegistration_addServ(export_registration_pt reg, service_reference_pt ref, void *service) {
+ celixThreadMutex_lock(®->mutex);
+ reg->service = service;
+ celixThreadMutex_unlock(®->mutex);
+}
+
+static void exportRegistration_removeServ(export_registration_pt reg, service_reference_pt ref, void *service) {
+ celixThreadMutex_lock(®->mutex);
+ if (reg->service == service) {
+ reg->service = NULL;
+ }
+ celixThreadMutex_unlock(®->mutex);
+}
+
+
+celix_status_t exportRegistration_close(export_registration_pt reg) {
+ celix_status_t status = CELIX_SUCCESS;
+ exportRegistration_stop(reg);
+ return status;
+}
+
+
+celix_status_t exportRegistration_getException(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ //TODO
+ return status;
+}
+
+celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *out) {
+ celix_status_t status = CELIX_SUCCESS;
+ export_reference_pt ref = calloc(1, sizeof(*ref));
+ if (ref != NULL) {
+ ref->endpoint = registration->exportReference.endpoint;
+ ref->reference = registration->exportReference.reference;
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *out = ref;
+ }
+
+ return status;
+}
+
+celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint) {
+ celix_status_t status = CELIX_SUCCESS;
+ *endpoint = reference->endpoint;
+ return status;
+}
+
+celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *ref) {
+ celix_status_t status = CELIX_SUCCESS;
+ *ref = reference->reference;
+ return status;
+}
+
+
+
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/src/export_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/export_registration_dfi.h b/remote_services/remote_service_admin_dfi/rsa/src/export_registration_dfi.h
new file mode 100644
index 0000000..93f37ba
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/src/export_registration_dfi.h
@@ -0,0 +1,38 @@
+/**
+ *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.
+ */
+
+#ifndef CELIX_EXPORT_REGISTRATION_DFI_H
+#define CELIX_EXPORT_REGISTRATION_DFI_H
+
+
+#include "export_registration.h"
+#include "log_helper.h"
+#include "endpoint_description.h"
+
+celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, bundle_context_pt context, export_registration_pt *registration);
+celix_status_t exportRegistration_close(export_registration_pt registration);
+void exportRegistration_destroy(export_registration_pt registration);
+
+celix_status_t exportRegistration_start(export_registration_pt registration);
+celix_status_t exportRegistration_stop(export_registration_pt registration);
+
+celix_status_t exportRegistration_call(export_registration_pt export, char *data, int datalength, char **response, int *responseLength);
+
+
+#endif //CELIX_EXPORT_REGISTRATION_DFI_H
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/src/import_registration_dfi.c
new file mode 100644
index 0000000..0b8dcf7
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/src/import_registration_dfi.c
@@ -0,0 +1,402 @@
+/**
+ *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.
+ */
+
+#include <stdlib.h>
+#include <jansson.h>
+#include <json_rpc.h>
+#include <assert.h>
+#include "version.h"
+#include "json_serializer.h"
+#include "dyn_interface.h"
+#include "import_registration.h"
+#include "import_registration_dfi.h"
+
+struct import_registration {
+ bundle_context_pt context;
+ endpoint_description_pt endpoint; //TODO owner? -> free when destroyed
+ const char *classObject; //NOTE owned by endpoint
+ version_pt version;
+
+ celix_thread_mutex_t mutex; //protects send & sendhandle
+ send_func_type send;
+ void *sendHandle;
+
+ service_factory_pt factory;
+ service_registration_pt factoryReg;
+
+ hash_map_pt proxies; //key -> bundle, value -> service_proxy
+ celix_thread_mutex_t proxiesMutex; //protects proxies
+};
+
+struct service_proxy {
+ dyn_interface_type *intf;
+ void *service;
+ size_t count;
+};
+
+static celix_status_t importRegistration_createProxy(import_registration_pt import, bundle_pt bundle,
+ struct service_proxy **proxy);
+static void importRegistration_proxyFunc(void *userData, void *args[], void *returnVal);
+static void importRegistration_destroyProxy(struct service_proxy *proxy);
+static void importRegistration_clearProxies(import_registration_pt import);
+
+celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt endpoint, const char *classObject, const char* serviceVersion,
+ import_registration_pt *out) {
+ celix_status_t status = CELIX_SUCCESS;
+ import_registration_pt reg = calloc(1, sizeof(*reg));
+
+ if (reg != NULL) {
+ reg->factory = calloc(1, sizeof(*reg->factory));
+ }
+
+ if (reg != NULL && reg->factory != NULL) {
+ reg->context = context;
+ reg->endpoint = endpoint;
+ reg->classObject = classObject;
+ reg->proxies = hashMap_create(NULL, NULL, NULL, NULL);
+
+ celixThreadMutex_create(®->mutex, NULL);
+ celixThreadMutex_create(®->proxiesMutex, NULL);
+ status = version_createVersionFromString((char*)serviceVersion,&(reg->version));
+
+ reg->factory->handle = reg;
+ reg->factory->getService = (void *)importRegistration_getService;
+ reg->factory->ungetService = (void *)importRegistration_ungetService;
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ //printf("IMPORT REGISTRATION IS %p\n", reg);
+ *out = reg;
+ }
+ else{
+ importRegistration_destroy(reg);
+ }
+
+ return status;
+}
+
+
+celix_status_t importRegistration_setSendFn(import_registration_pt reg,
+ send_func_type send,
+ void *handle) {
+ celixThreadMutex_lock(®->mutex);
+ reg->send = send;
+ reg->sendHandle = handle;
+ celixThreadMutex_unlock(®->mutex);
+
+ return CELIX_SUCCESS;
+}
+
+static void importRegistration_clearProxies(import_registration_pt import) {
+ if (import != NULL) {
+ pthread_mutex_lock(&import->proxiesMutex);
+ if (import->proxies != NULL) {
+ hash_map_iterator_pt iter = hashMapIterator_create(import->proxies);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ struct service_proxy *proxy = hashMapEntry_getValue(entry);
+ importRegistration_destroyProxy(proxy);
+ }
+ hashMapIterator_destroy(iter);
+ }
+ pthread_mutex_unlock(&import->proxiesMutex);
+ }
+}
+
+void importRegistration_destroy(import_registration_pt import) {
+ if (import != NULL) {
+ if (import->proxies != NULL) {
+ hashMap_destroy(import->proxies, false, false);
+ import->proxies = NULL;
+ }
+
+ pthread_mutex_destroy(&import->mutex);
+ pthread_mutex_destroy(&import->proxiesMutex);
+
+ if (import->factory != NULL) {
+ free(import->factory);
+ }
+
+ if(import->version!=NULL){
+ version_destroy(import->version);
+ }
+ free(import);
+ }
+}
+
+celix_status_t importRegistration_start(import_registration_pt import) {
+ celix_status_t status = CELIX_SUCCESS;
+ if (import->factoryReg == NULL && import->factory != NULL) {
+ properties_pt props = NULL;
+ properties_copy(import->endpoint->properties, &props);
+ status = bundleContext_registerServiceFactory(import->context, (char *)import->classObject, import->factory, props, &import->factoryReg);
+ } else {
+ status = CELIX_ILLEGAL_STATE;
+ }
+ return status;
+}
+
+celix_status_t importRegistration_stop(import_registration_pt import) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (import->factoryReg != NULL) {
+ serviceRegistration_unregister(import->factoryReg);
+ import->factoryReg = NULL;
+ }
+
+ importRegistration_clearProxies(import);
+
+ return status;
+}
+
+
+celix_status_t importRegistration_getService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **out) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ /*
+ module_pt module = NULL;
+ char *name = NULL;
+ bundle_getCurrentModule(bundle, &module);
+ module_getSymbolicName(module, &name);
+ printf("getting service for bundle '%s'\n", name);
+ */
+
+
+ pthread_mutex_lock(&import->proxiesMutex);
+ struct service_proxy *proxy = hashMap_get(import->proxies, bundle);
+ if (proxy == NULL) {
+ status = importRegistration_createProxy(import, bundle, &proxy);
+ if (status == CELIX_SUCCESS) {
+ hashMap_put(import->proxies, bundle, proxy);
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ proxy->count += 1;
+ *out = proxy->service;
+ }
+ pthread_mutex_unlock(&import->proxiesMutex);
+
+ return status;
+}
+
+static celix_status_t importRegistration_createProxy(import_registration_pt import, bundle_pt bundle, struct service_proxy **out) {
+ celix_status_t status;
+ dyn_interface_type* intf = NULL;
+ FILE *descriptor = NULL;
+
+ status = dfi_findDescriptor(import->context, bundle, import->classObject, &descriptor);
+
+ if (status != CELIX_SUCCESS || descriptor == NULL) {
+ //TODO use log helper logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Cannot find/open descriptor for '%s'", import->classObject);
+ fprintf(stderr, "RSA_DFI: Cannot find/open descriptor for '%s'", import->classObject);
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ int rc = dynInterface_parse(descriptor, &intf);
+ fclose(descriptor);
+ if (rc != 0 || intf==NULL) {
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+ }
+
+ /* Check if the imported service version is compatible with the one in the consumer descriptor */
+ version_pt consumerVersion = NULL;
+ bool isCompatible = false;
+ dynInterface_getVersion(intf,&consumerVersion);
+ version_isCompatible(consumerVersion,import->version,&isCompatible);
+
+ if(!isCompatible){
+ char* cVerString = NULL;
+ char* pVerString = NULL;
+ version_toString(consumerVersion,&cVerString);
+ version_toString(import->version,&pVerString);
+ printf("Service version mismatch: consumer has %s, provider has %s. NOT creating proxy.\n",cVerString,pVerString);
+ dynInterface_destroy(intf);
+ free(cVerString);
+ free(pVerString);
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+
+ struct service_proxy *proxy = NULL;
+ if (status == CELIX_SUCCESS) {
+ proxy = calloc(1, sizeof(*proxy));
+ if (proxy == NULL) {
+ status = CELIX_ENOMEM;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ proxy->intf = intf;
+ size_t count = dynInterface_nrOfMethods(proxy->intf);
+ proxy->service = calloc(1 + count, sizeof(void *));
+ if (proxy->service == NULL) {
+ status = CELIX_ENOMEM;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ void **serv = proxy->service;
+ serv[0] = import;
+
+ struct methods_head *list = NULL;
+ dynInterface_methods(proxy->intf, &list);
+ struct method_entry *entry = NULL;
+ void (*fn)(void) = NULL;
+ int index = 0;
+ TAILQ_FOREACH(entry, list, entries) {
+ int rc = dynFunction_createClosure(entry->dynFunc, importRegistration_proxyFunc, entry, &fn);
+ serv[index + 1] = fn;
+ index += 1;
+
+ if (rc != 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ break;
+ }
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *out = proxy;
+ } else if (proxy != NULL) {
+ if (proxy->intf != NULL) {
+ dynInterface_destroy(proxy->intf);
+ proxy->intf = NULL;
+ }
+ free(proxy->service);
+ free(proxy);
+ }
+
+ return status;
+}
+
+static void importRegistration_proxyFunc(void *userData, void *args[], void *returnVal) {
+ int status = CELIX_SUCCESS;
+ struct method_entry *entry = userData;
+ import_registration_pt import = *((void **)args[0]);
+
+ if (import == NULL || import->send == NULL) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+
+ char *invokeRequest = NULL;
+ if (status == CELIX_SUCCESS) {
+ status = jsonRpc_prepareInvokeRequest(entry->dynFunc, entry->id, args, &invokeRequest);
+ //printf("Need to send following json '%s'\n", invokeRequest);
+ }
+
+
+ if (status == CELIX_SUCCESS) {
+ char *reply = NULL;
+ int rc = 0;
+ //printf("sending request\n");
+ celixThreadMutex_lock(&import->mutex);
+ if (import->send != NULL) {
+ import->send(import->sendHandle, import->endpoint, invokeRequest, &reply, &rc);
+ }
+ celixThreadMutex_unlock(&import->mutex);
+ //printf("request sended. got reply '%s' with status %i\n", reply, rc);
+
+ if (rc == 0) {
+ //fjprintf("Handling reply '%s'\n", reply);
+ status = jsonRpc_handleReply(entry->dynFunc, reply, args);
+ }
+
+ *(int *) returnVal = rc;
+
+ free(invokeRequest); //Allocated by json_dumps in jsonRpc_prepareInvokeRequest
+ free(reply); //Allocated by json_dumps in remoteServiceAdmin_send through curl call
+ }
+
+ if (status != CELIX_SUCCESS) {
+ //TODO log error
+ }
+}
+
+celix_status_t importRegistration_ungetService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **out) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ assert(import != NULL);
+ assert(import->proxies != NULL);
+
+ pthread_mutex_lock(&import->proxiesMutex);
+
+ struct service_proxy *proxy = hashMap_get(import->proxies, bundle);
+ if (proxy != NULL) {
+ if (*out == proxy->service) {
+ proxy->count -= 1;
+ } else {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (proxy->count == 0) {
+ hashMap_remove(import->proxies, bundle);
+ importRegistration_destroyProxy(proxy);
+ }
+ }
+
+ pthread_mutex_unlock(&import->proxiesMutex);
+
+ return status;
+}
+
+static void importRegistration_destroyProxy(struct service_proxy *proxy) {
+ if (proxy != NULL) {
+ if (proxy->intf != NULL) {
+ dynInterface_destroy(proxy->intf);
+ }
+ if (proxy->service != NULL) {
+ free(proxy->service);
+ }
+ free(proxy);
+ }
+}
+
+
+celix_status_t importRegistration_close(import_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ importRegistration_stop(registration);
+ return status;
+}
+
+celix_status_t importRegistration_getException(import_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ //TODO
+ return status;
+}
+
+celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ //TODO
+ return status;
+}
+
+celix_status_t importReference_getImportedEndpoint(import_reference_pt reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t importReference_getImportedService(import_reference_pt reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/src/import_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/import_registration_dfi.h b/remote_services/remote_service_admin_dfi/rsa/src/import_registration_dfi.h
new file mode 100644
index 0000000..aac4bc7
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/src/import_registration_dfi.h
@@ -0,0 +1,44 @@
+/**
+ *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.
+ */
+
+#ifndef CELIX_IMPORT_REGISTRATION_DFI_H
+#define CELIX_IMPORT_REGISTRATION_DFI_H
+
+#include "import_registration.h"
+#include "dfi_utils.h"
+
+#include <celix_errno.h>
+
+typedef void (*send_func_type)(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
+
+celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt description, const char *classObject, const char* serviceVersion,
+ import_registration_pt *import);
+celix_status_t importRegistration_close(import_registration_pt import);
+void importRegistration_destroy(import_registration_pt import);
+
+celix_status_t importRegistration_setSendFn(import_registration_pt reg,
+ send_func_type,
+ void *handle);
+celix_status_t importRegistration_start(import_registration_pt import);
+celix_status_t importRegistration_stop(import_registration_pt import);
+
+celix_status_t importRegistration_getService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **service);
+celix_status_t importRegistration_ungetService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **service);
+
+#endif //CELIX_IMPORT_REGISTRATION_DFI_H
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_activator.c b/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_activator.c
new file mode 100644
index 0000000..d4cc765
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_activator.c
@@ -0,0 +1,124 @@
+/**
+ *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.
+ */
+/*
+ * remote_service_admin_activator.c
+ *
+ * \date Sep 30, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <remote_service_admin.h>
+
+#include "remote_service_admin_dfi.h"
+
+#include "bundle_activator.h"
+#include "service_registration.h"
+
+#include "export_registration_dfi.h"
+#include "import_registration_dfi.h"
+
+struct activator {
+ remote_service_admin_pt admin;
+ remote_service_admin_service_pt adminService;
+ service_registration_pt registration;
+};
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator;
+
+ activator = calloc(1, sizeof(*activator));
+ if (!activator) {
+ status = CELIX_ENOMEM;
+ } else {
+ activator->admin = NULL;
+ activator->registration = NULL;
+
+ *userData = activator;
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+ remote_service_admin_service_pt remoteServiceAdmin = NULL;
+
+ status = remoteServiceAdmin_create(context, &activator->admin);
+ if (status == CELIX_SUCCESS) {
+ remoteServiceAdmin = calloc(1, sizeof(*remoteServiceAdmin));
+ if (!remoteServiceAdmin) {
+ status = CELIX_ENOMEM;
+ } else {
+ remoteServiceAdmin->admin = activator->admin;
+ remoteServiceAdmin->exportService = remoteServiceAdmin_exportService;
+
+ remoteServiceAdmin->getExportedServices = remoteServiceAdmin_getExportedServices;
+ remoteServiceAdmin->getImportedEndpoints = remoteServiceAdmin_getImportedEndpoints;
+ remoteServiceAdmin->importService = remoteServiceAdmin_importService;
+
+ remoteServiceAdmin->exportReference_getExportedEndpoint = exportReference_getExportedEndpoint;
+ remoteServiceAdmin->exportReference_getExportedService = exportReference_getExportedService;
+
+ remoteServiceAdmin->exportRegistration_close = remoteServiceAdmin_removeExportedService;
+ remoteServiceAdmin->exportRegistration_getException = exportRegistration_getException;
+ remoteServiceAdmin->exportRegistration_getExportReference = exportRegistration_getExportReference;
+
+ remoteServiceAdmin->importReference_getImportedEndpoint = importReference_getImportedEndpoint;
+ remoteServiceAdmin->importReference_getImportedService = importReference_getImportedService;
+
+ remoteServiceAdmin->importRegistration_close = remoteServiceAdmin_removeImportedService;
+ remoteServiceAdmin->importRegistration_getException = importRegistration_getException;
+ remoteServiceAdmin->importRegistration_getImportReference = importRegistration_getImportReference;
+
+ status = bundleContext_registerService(context, OSGI_RSA_REMOTE_SERVICE_ADMIN, remoteServiceAdmin, NULL, &activator->registration);
+ activator->adminService = remoteServiceAdmin;
+ }
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ serviceRegistration_unregister(activator->registration);
+ activator->registration = NULL;
+
+ remoteServiceAdmin_stop(activator->admin);
+ remoteServiceAdmin_destroy(&activator->admin);
+
+ free(activator->adminService);
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ free(activator);
+
+ return status;
+}
+
+
[44/54] [abbrv] celix git commit: Merge branch 'release/2.1.0' into
feature/CELIX-417-cmake-refactor
Posted by pn...@apache.org.
Merge branch 'release/2.1.0' into feature/CELIX-417-cmake-refactor
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/0ea8de64
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/0ea8de64
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/0ea8de64
Branch: refs/heads/develop
Commit: 0ea8de64a3aab5a1ee4e2a11edfad1c1ac3e0d84
Parents: 81804e0 353ac0d
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Jan 24 22:06:37 2018 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Jan 24 22:06:37 2018 +0100
----------------------------------------------------------------------
CHANGES | 215 ----------------
CHANGES.md | 252 +++++++++++++++++++
README.md | 17 ++
RELEASE_NOTES | 24 +-
cmake/cmake_celix/BundlePackaging.cmake | 26 +-
cmake/cmake_celix/DeployPackaging.cmake | 8 +-
config_admin/CMakeLists.txt | 2 +-
.../example_test/CMakeLists.txt | 2 +-
.../example_test2/CMakeLists.txt | 2 +-
config_admin/example/CMakeLists.txt | 2 +-
config_admin/readme.md | 17 ++
config_admin/service/CMakeLists.txt | 2 +-
dependency_manager/CMakeLists.txt | 34 ++-
dependency_manager/readme.md | 17 ++
dependency_manager_cxx/CMakeLists.txt | 17 +-
dependency_manager_cxx/readme.md | 17 ++
deployment_admin/CMakeLists.txt | 6 +-
deployment_admin/README.md | 17 ++
device_access/README.md | 17 ++
device_access/device_access/CMakeLists.txt | 4 +-
device_access/driver_locator/CMakeLists.txt | 4 +-
device_access/example/CMakeLists.txt | 4 +-
.../example/base_driver/CMakeLists.txt | 2 +-
.../example/consuming_driver/CMakeLists.txt | 2 +-
.../example/refining_driver/CMakeLists.txt | 2 +-
dfi/CMakeLists.txt | 45 ++--
documents/building/readme.md | 31 ++-
documents/cmake_commands/readme.md | 23 +-
.../getting_started/creating_a_simple_bundle.md | 128 ++++++----
.../getting_started/getting_started_img3.png | Bin 127686 -> 0 bytes
documents/getting_started/readme.md | 22 +-
.../getting_started/using_services_with_c.md | 125 +++++----
.../getting_started/using_services_with_cxx.md | 17 ++
documents/intro/readme.md | 17 ++
documents/roadmap/api_v3/readme.md | 19 +-
documents/roadmap/improvement_ideas.md | 19 +-
documents/roadmap/roadmap.md | 17 ++
documents/subprojects/readme.md | 17 ++
etcdlib/README.md | 17 ++
event_admin/CMakeLists.txt | 6 +-
event_admin/event_admin/CMakeLists.txt | 4 +-
event_admin/event_handler/CMakeLists.txt | 4 +-
event_admin/event_publisher/CMakeLists.txt | 4 +-
examples/dm_example/CMakeLists.txt | 2 +-
examples/dm_example/api/CMakeLists.txt | 2 +-
examples/dm_example/phase1/CMakeLists.txt | 2 +-
examples/dm_example/phase2a/CMakeLists.txt | 2 +-
examples/dm_example/phase2b/CMakeLists.txt | 2 +-
examples/dm_example/phase3/CMakeLists.txt | 2 +-
examples/dm_example_cxx/phase1/CMakeLists.txt | 2 +-
examples/dm_example_cxx/phase2/CMakeLists.txt | 4 +-
examples/dm_example_cxx/phase3/CMakeLists.txt | 2 +-
.../phase3_locking/CMakeLists.txt | 2 +-
examples/hello_world/CMakeLists.txt | 10 +-
examples/hello_world_test/CMakeLists.txt | 18 +-
examples/log_service_example/CMakeLists.txt | 4 +-
examples/mongoose/CMakeLists.txt | 6 +-
examples/service_hook_example/CMakeLists.txt | 6 +-
examples/services_example_c/CMakeLists.txt | 2 +-
examples/services_example_c/bar/CMakeLists.txt | 2 +-
examples/services_example_c/foo1/CMakeLists.txt | 2 +-
examples/services_example_c/foo2/CMakeLists.txt | 2 +-
examples/services_example_cxx/CMakeLists.txt | 2 +-
.../services_example_cxx/bar/CMakeLists.txt | 2 +-
.../services_example_cxx/baz/CMakeLists.txt | 2 +-
.../services_example_cxx/foo/CMakeLists.txt | 2 +-
.../test_bundle1/CMakeLists.txt | 2 +-
framework/src/celix_launcher.c | 12 +-
launcher/README.md | 17 ++
log_service/CMakeLists.txt | 5 +-
log_writer/log_writer/CMakeLists.txt | 2 +-
log_writer/log_writer_stdout/CMakeLists.txt | 6 +-
log_writer/log_writer_syslog/CMakeLists.txt | 4 +-
pubsub/CMakeLists.txt | 2 +-
pubsub/README.md | 17 ++
pubsub/examples/CMakeLists.txt | 26 +-
pubsub/examples/keys/README.md | 17 ++
.../examples/mp_pubsub/publisher/CMakeLists.txt | 8 +-
.../mp_pubsub/subscriber/CMakeLists.txt | 10 +-
pubsub/examples/pubsub/publisher/CMakeLists.txt | 10 +-
.../examples/pubsub/publisher2/CMakeLists.txt | 10 +-
.../examples/pubsub/subscriber/CMakeLists.txt | 12 +-
pubsub/mock/CMakeLists.txt | 8 +-
pubsub/pubsub_admin_udp_mc/CMakeLists.txt | 4 +-
pubsub/pubsub_admin_udp_mc/README.md | 17 ++
pubsub/pubsub_admin_zmq/CMakeLists.txt | 4 +-
pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.c | 2 +-
pubsub/pubsub_admin_zmq/src/topic_publication.c | 2 +-
pubsub/pubsub_admin_zmq/src/topic_publication.h | 2 +-
.../pubsub_admin_zmq/src/topic_subscription.c | 4 +-
pubsub/pubsub_discovery/CMakeLists.txt | 4 +-
pubsub/pubsub_serializer_json/CMakeLists.txt | 4 +-
pubsub/pubsub_spi/CMakeLists.txt | 13 +-
pubsub/pubsub_topology_manager/CMakeLists.txt | 6 +-
pubsub/test/CMakeLists.txt | 16 +-
rat-excludes.txt | 7 +-
remote_services/README.md | 17 ++
remote_services/civetweb/CMakeLists.txt | 2 +-
remote_services/discovery_common/CMakeLists.txt | 2 +-
.../discovery_configured/CMakeLists.txt | 4 +-
remote_services/discovery_etcd/CMakeLists.txt | 4 +-
remote_services/discovery_etcd/README.md | 17 ++
remote_services/discovery_shm/CMakeLists.txt | 4 +-
remote_services/examples/CMakeLists.txt | 12 +-
.../examples/calculator_service/CMakeLists.txt | 4 +-
.../examples/calculator_shell/CMakeLists.txt | 4 +-
.../remote_service_admin_dfi/CMakeLists.txt | 4 +-
.../test/CMakeLists.txt | 4 +-
.../remote_service_admin_shm/CMakeLists.txt | 4 +-
.../remote_services_api/CMakeLists.txt | 8 +-
remote_services/rsa_common/CMakeLists.txt | 11 +-
remote_services/topology_manager/CMakeLists.txt | 4 +-
remote_services/topology_manager/README.md | 17 ++
.../tms_tst/bundle/CMakeLists.txt | 4 +-
.../tms_tst/disc_mock/CMakeLists.txt | 2 +-
remote_shell/CMakeLists.txt | 6 +-
remote_shell/README.md | 17 ++
shell/CMakeLists.txt | 4 +-
shell/README.md | 17 ++
shell_bonjour/CMakeLists.txt | 4 +-
shell_tui/CMakeLists.txt | 4 +-
shell_tui/README.md | 17 ++
utils/README.md | 17 ++
123 files changed, 1162 insertions(+), 614 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/cmake/cmake_celix/BundlePackaging.cmake
----------------------------------------------------------------------
diff --cc cmake/cmake_celix/BundlePackaging.cmake
index 8e1755c,e336dbb..44e7382
--- a/cmake/cmake_celix/BundlePackaging.cmake
+++ b/cmake/cmake_celix/BundlePackaging.cmake
@@@ -88,9 -88,8 +88,9 @@@ function(check_bundle BUNDLE
endif()
endfunction()
+
function(add_bundle)
- #message(DEPRECATION"add_bundle is DEPRECATION, use add_celix_bundle instead.")
- message(DEPRECATION "add_bundle is DEPRECATION, use add_celix_bundle instead.")
++ message(DEPRECATION "add_bundle is deprecated, use add_celix_bundle instead.")
add_celix_bundle(${ARGN})
endfunction()
function(add_celix_bundle)
@@@ -278,7 -261,7 +278,7 @@@
endfunction()
function(bundle_export_libs)
- #message(DEPRECATION"bundle_export_libs is DEPRECATION, use celix_bundle_export_libs instead.")
- message(DEPRECATION "bundle_export_libs is DEPRECATION, use celix_bundle_export_libs instead.")
++ message(DEPRECATION "bundle_export_libs is deprecated, use celix_bundle_export_libs instead.")
celix_bundle_export_libs(${ARGN})
endfunction()
function(celix_bundle_export_libs)
@@@ -288,7 -271,7 +288,7 @@@
endfunction()
function(bundle_private_libs)
- #message(DEPRECATION"bundle_private_libs is DEPRECATION, use celix_bundle_private_libs instead.")
- message(DEPRECATION "bundle_private_libs is DEPRECATION, use celix_bundle_private_libs instead.")
++ message(DEPRECATION "bundle_private_libs is deprecated, use celix_bundle_private_libs instead.")
celix_bundle_private_libs(${ARGN})
endfunction()
function(celix_bundle_private_libs)
@@@ -298,7 -281,7 +298,7 @@@
endfunction()
function(bundle_libs)
- #message(DEPRECATION"bundle_libs is DEPRECATION, use celix_bundle_libs instead.")
- message(DEPRECATION "bundle_libs is DEPRECATION, use celix_bundle_libs instead.")
++ message(DEPRECATION "bundle_libs is deprecated, use celix_bundle_libs instead.")
celix_bundle_libs(${ARGN})
endfunction()
function(celix_bundle_libs)
@@@ -365,7 -348,7 +365,7 @@@
endfunction()
function(bundle_import_libs)
- #message(DEPRECATION"bundle_import_libs is DEPRECATION, use celix_bundle_import_libs instead.")
- message(DEPRECATION "bundle_import_libs is DEPRECATION, use celix_bundle_import_libs instead.")
++ message(DEPRECATION "bundle_import_libs is deprecated, use celix_bundle_import_libs instead.")
celix_bundle_import_libs(${ARGN})
endfunction()
function(celix_bundle_import_libs)
@@@ -395,7 -378,7 +395,7 @@@
endfunction()
function(bundle_files)
- #message(DEPRECATION"bundle_files is DEPRECATION, use celix_bundle_files instead.")
- message(DEPRECATION "bundle_files is DEPRECATION, use celix_bundle_files instead.")
++ message(DEPRECATION "bundle_files is deprecated, use celix_bundle_files instead.")
celix_bundle_files(${ARGN})
endfunction()
function(celix_bundle_files)
@@@ -422,7 -405,7 +422,7 @@@
endfunction()
function(bundle_headers)
- #message(DEPRECATION"bundle_headers is DEPRECATION, use celix_bundle_headers instead.")
- message(DEPRECATION "bundle_headers is DEPRECATION, use celix_bundle_headers instead.")
++ message(DEPRECATION "bundle_headers is deprecated, use celix_bundle_headers instead.")
celix_bundle_headers(${ARGN})
endfunction()
function(celix_bundle_headers)
@@@ -441,7 -424,7 +441,7 @@@
endfunction()
function(bundle_symbolic_name)
- #message(DEPRECATION"bundle_symbolic_name is DEPRECATION, use celix_bundle_symbolic_name instead.")
- message(DEPRECATION "bundle_symbolic_name is DEPRECATION, use celix_bundle_symbolic_name instead.")
++ message(DEPRECATION "bundle_symbolic_name is deprecated, use celix_bundle_symbolic_name instead.")
celix_bundle_symbolic_name(${ARGN})
endfunction()
function(celix_bundle_symbolic_name BUNDLE SYMBOLIC_NAME)
@@@ -449,7 -432,7 +449,7 @@@
endfunction()
function(bundle_name)
- #message(DEPRECATION"bundle_name is DEPRECATION, use celix_bundle_name instead.")
- message(DEPRECATION "bundle_name is DEPRECATION, use celix_bundle_name instead.")
++ message(DEPRECATION "bundle_name is deprecated, use celix_bundle_name instead.")
celix_bundle_symbolic_name(${ARGN})
endfunction()
function(celix_bundle_name BUNDLE NAME)
@@@ -457,7 -440,7 +457,7 @@@
endfunction()
function(bundle_version)
- #message(DEPRECATION"bundle_version is DEPRECATION, use celix_bundle_version instead.")
- message(DEPRECATION "bundle_version is DEPRECATION, use celix_bundle_version instead.")
++ message(DEPRECATION "bundle_version is deprecated, use celix_bundle_version instead.")
celix_bundle_symbolic_name(${ARGN})
endfunction()
function(celix_bundle_version BUNDLE VERSION)
@@@ -465,7 -448,7 +465,7 @@@
endfunction()
function(bundle_description)
- #message(DEPRECATION"bundle_description is DEPRECATION, use celix_bundle_description instead.")
- message(DEPRECATION "bundle_description is DEPRECATION, use celix_bundle_description instead.")
++ message(DEPRECATION "bundle_description is deprecated, use celix_bundle_description instead.")
celix_bundle_symbolic_name(${ARGN})
endfunction()
function(celix_bundle_description BUNDLE DESC)
@@@ -473,7 -456,7 +473,7 @@@
endfunction()
function(install_bundle)
- #message(DEPRECATION"install_bundle is DEPRECATION, use install_celix_bundle instead.")
- message(DEPRECATION "install_bundle is DEPRECATION, use install_celix_bundle instead.")
++ message(DEPRECATION "install_bundle is deprecated, use install_celix_bundle instead.")
install_celix_bundle(${ARGN})
endfunction()
function(install_celix_bundle)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/cmake/cmake_celix/DeployPackaging.cmake
----------------------------------------------------------------------
diff --cc cmake/cmake_celix/DeployPackaging.cmake
index 2065b47,707201f..b7880f4
--- a/cmake/cmake_celix/DeployPackaging.cmake
+++ b/cmake/cmake_celix/DeployPackaging.cmake
@@@ -28,9 -28,10 +28,9 @@@ set_directory_properties(PROPERTIES ADD
#####
function(add_deploy)
- #message(DEPRECATION "deploy_bundles_dir is depecrated, use celix_container_bundles_dir instead.")
- message(DEPRECATION "add_deploy is depecrated, use add_celix_container instead.")
++ message(DEPRECATION "deploy_bundles_dir is depecrated, use celix_container_bundles_dir instead.")
add_celix_container(${ARGN})
endfunction()
-
function(add_celix_container)
list(GET ARGN 0 CONTAINER_TARGET)
list(REMOVE_AT ARGN 0)
@@@ -212,8 -219,9 +212,8 @@@ endfunction(
#NOTE can be used for drivers/proxies/endpoints bundle dirs
-
function(deploy_bundles_dir)
- #message(DEPRECATION "deploy_bundles_dir is depecrated, use celix_container_bundles_dir instead.")
+ message(DEPRECATION "deploy_bundles_dir is depecrated, use celix_container_bundles_dir instead.")
celix_container_bundles_dir(${ARGN})
endfunction()
function(celix_container_bundles_dir)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/config_admin/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/config_admin/config_admin_tst/example_test/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/config_admin/config_admin_tst/example_test2/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/config_admin/example/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/config_admin/service/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/dependency_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --cc dependency_manager/CMakeLists.txt
index 477a163,952cfe7..f98701e
--- a/dependency_manager/CMakeLists.txt
+++ b/dependency_manager/CMakeLists.txt
@@@ -30,70 -30,63 +30,64 @@@ if (DEPENDENCY_MANAGER
endif(CMAKE_UNAME)
endif(UNIX AND NOT WIN32)
- add_celix_bundle(dm_shell
- SYMBOLIC_NAME "apache_celix_dm_shell"
- VERSION "1.0.0"
- NAME "Apache Celix DM Shell Commands"
- SOURCES
- private/src/dm_shell_activator
- private/src/dm_shell_list_command
- )
- target_link_libraries(dm_shell celix_framework celix_utils)
-
-
add_library(dependency_manager_static STATIC
- private/src/dm_component_impl
- private/src/dm_service_dependency
- private/src/dm_event
- private/src/dm_dependency_manager_impl
- private/src/dm_activator
+ src/dm_component_impl
+ src/dm_service_dependency
+ src/dm_event
+ src/dm_dependency_manager_impl
+ src/dm_activator
)
- set_target_properties(dependency_manager_static PROPERTIES SOVERSION 1)
- set_target_properties(dependency_manager_static PROPERTIES VERSION 1.1.0)
++ set_target_properties(dependency_manager_static PROPERTIES OUTPUT_NAME "celix_dependency_manager_static")
+ target_link_libraries(dependency_manager_static Celix::framework)
+ target_compile_options(dependency_manager_static PRIVATE ${DM_COMP_OPT})
add_library(dependency_manager_so SHARED
- private/src/dm_component_impl
- private/src/dm_service_dependency
- private/src/dm_event
- private/src/dm_dependency_manager_impl
- private/src/dm_activator
+ src/dm_component_impl
+ src/dm_service_dependency
+ src/dm_event
+ src/dm_dependency_manager_impl
+ src/dm_activator
)
++ set_target_properties(dependency_manager_so PROPERTIES OUTPUT_NAME "celix_dependency_manager_so")
set_target_properties(dependency_manager_so PROPERTIES SOVERSION 1)
if (APPLE)
- target_link_libraries(dependency_manager_so celix_framework "-undefined dynamic_lookup")
+ target_link_libraries(dependency_manager_so Celix::framework "-undefined dynamic_lookup")
else()
- target_link_libraries(dependency_manager_so celix_framework)
+ target_link_libraries(dependency_manager_so Celix::framework)
endif()
- target_include_directories(dependency_manager_static PUBLIC api)
- include_directories("public/include")
- include_directories("private/include")
- include_directories("${PROJECT_SOURCE_DIR}/shell/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- target_link_libraries(dependency_manager_static celix_framework)
-
- install(
- FILES
- public/include/dm_activator.h
- private/src/dm_activator.c
- public/include/dm_component.h
- public/include/dm_dependency_manager.h
- public/include/dm_service_dependency.h
- public/include/dm_info.h
- DESTINATION
- include/celix/dependency_manager
- COMPONENT
- dependency_manager
- )
++ target_include_directories(dependency_manager_static PUBLIC
++ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/api>
++ $<INSTALL_INTERFACE:include/celix/dependency_manager>
++ )
+ target_include_directories(dependency_manager_static PRIVATE src)
- target_include_directories(dependency_manager_so PUBLIC api)
++ target_include_directories(dependency_manager_so PUBLIC
++ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/api>
++ $<INSTALL_INTERFACE:include/celix/dependency_manager>
++ )
+ target_include_directories(dependency_manager_so PRIVATE src)
+
- add_bundle(dm_shell
++ add_celix_bundle(dm_shell
+ SYMBOLIC_NAME "apache_celix_dm_shell"
+ VERSION "1.0.0"
+ NAME "Apache Celix DM Shell Commands"
+ SOURCES
+ src/dm_shell_activator
+ src/dm_shell_list_command
+ )
+ target_include_directories(dm_shell PRIVATE api src)
+ target_link_libraries(dm_shell PRIVATE Celix::shell_api)
+
- #TODO check
- # install(
- # FILES
- # api/dm_activator.h
- # src/dm_activator.c
- # api/dm_component.h
- # api/dm_dependency_manager.h
- # apidm_service_dependency.h
- # apidm_info.h
- # DESTINATION
- # include/celix/dependency_manager
- # COMPONENT
- # dependency_manager
- # )
- install_bundle(dm_shell)
- install(TARGETS dependency_manager_static DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dependency_manager)
- install(TARGETS dependency_manager_so DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dependency_manager)
+ install_celix_bundle(dm_shell)
- install(TARGETS dependency_manager_static DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dependency_manager)
- install(TARGETS dependency_manager_so DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dependency_manager)
++ install(TARGETS dependency_manager_so dependency_manager_static DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dependency_manager)
++ install(DIRECTORY api/ DESTINATION include/celix/dependency_manager COMPONENT dependency_manager)
+
+ unset(DM_COMP_OPT)
+
+ #Setup target aliases to match external usage
+ add_library(Celix::dm_shell ALIAS dm_shell)
+ add_library(Celix::dependency_manager_static ALIAS dependency_manager_static)
+ add_library(Celix::dependency_manager_so ALIAS dependency_manager_so)
endif (DEPENDENCY_MANAGER)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/dependency_manager/readme.md
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/dependency_manager_cxx/CMakeLists.txt
----------------------------------------------------------------------
diff --cc dependency_manager_cxx/CMakeLists.txt
index 65c158d,55b02ca..5b7580a
--- a/dependency_manager_cxx/CMakeLists.txt
+++ b/dependency_manager_cxx/CMakeLists.txt
@@@ -29,36 -29,37 +29,35 @@@ if (DEPENDENCY_MANAGER_CXX
endif(CMAKE_UNAME)
endif(UNIX AND NOT WIN32)
- include_directories(
- include
- ${PROJECT_SOURCE_DIR}/dependency_manager/public/include
- ${PROJECT_SOURCE_DIR}/dependency_manager/private/include
- ${PROJECT_SOURCE_DIR}/utils/public/include
- )
-
add_library(dependency_manager_cxx_static STATIC
- ${CMAKE_SOURCE_DIR}/dependency_manager/private/src/dm_component_impl
- ${CMAKE_SOURCE_DIR}/dependency_manager/private/src/dm_service_dependency
- ${CMAKE_SOURCE_DIR}/dependency_manager/private/src/dm_event
- ${CMAKE_SOURCE_DIR}/dependency_manager/private/src/dm_dependency_manager_impl
+ ${CMAKE_SOURCE_DIR}/dependency_manager/src/dm_component_impl
+ ${CMAKE_SOURCE_DIR}/dependency_manager/src/dm_service_dependency
+ ${CMAKE_SOURCE_DIR}/dependency_manager/src/dm_event
+ ${CMAKE_SOURCE_DIR}/dependency_manager/src/dm_dependency_manager_impl
src/dm_activator.cc
)
- target_include_directories(dependency_manager_cxx_static PUBLIC include ${CMAKE_SOURCE_DIR}/dependency_manager/api)
- set_target_properties(dependency_manager_cxx_static PROPERTIES SOVERSION 1)
- set_target_properties(dependency_manager_cxx_static PROPERTIES VERSION 2.0.0)
++ set_target_properties(dependency_manager_cxx_static PROPERTIES OUTPUT_NAME "celix_dependency_manager_cxx_static")
++ target_include_directories(dependency_manager_cxx_static PUBLIC
++ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
++ $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/dependency_manager/api>
++ $<INSTALL_INTERFACE:include/celix/dependency_manager_cxx>
++ $<INSTALL_INTERFACE:include/celix/dependency_manager>
++ )
+ target_include_directories(dependency_manager_cxx_static PRIVATE src)
+ target_compile_options(dependency_manager_cxx_static PRIVATE ${DM_COMP_OPT})
if (APPLE)
- target_link_libraries(dependency_manager_cxx_static celix_framework "-undefined dynamic_lookup")
+ target_link_libraries(dependency_manager_cxx_static Celix::framework "-undefined dynamic_lookup")
else()
- target_link_libraries(dependency_manager_cxx_static celix_framework)
+ target_link_libraries(dependency_manager_cxx_static Celix::framework)
endif()
-- install(
-- DIRECTORY
-- include/celix
-- DESTINATION
-- include/celix/dependency_manager_cxx
-- COMPONENT
-- dependency_manager_cxx
-- )
install(TARGETS dependency_manager_cxx_static DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dependency_manager_cxx)
++ install(DIRECTORY include DESTINATION include/celix/dependency_manager_cxx COMPONENT dependency_manager_cxx)
+
+ unset(DM_COMP_OPT)
+
+ #Setup target aliases to match external usage
+ add_library(Celix::dependency_manager_cxx_static ALIAS dependency_manager_cxx_static)
endif (DEPENDENCY_MANAGER_CXX)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/dependency_manager_cxx/readme.md
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/deployment_admin/CMakeLists.txt
----------------------------------------------------------------------
diff --cc deployment_admin/CMakeLists.txt
index 3eb38ec,51fe2ba..8d74b1f
--- a/deployment_admin/CMakeLists.txt
+++ b/deployment_admin/CMakeLists.txt
@@@ -20,44 -20,52 +20,44 @@@ if (DEPLOYMENT_ADMIN
find_package(CURL REQUIRED)
find_package(UUID REQUIRED)
+ find_package(ZLIB REQUIRED)
- add_definitions(-DUSE_FILE32API)
+ add_library(deployment_admin_api INTERFACE)
+ target_include_directories(deployment_admin_api INTERFACE api)
- add_bundle(deployment_admin
- include_directories("${CURL_INCLUDE_DIR}")
- include_directories("${UUID_INCLUDE_DIR}")
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/deployment_admin/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/deployment_admin/public/include")
-
+ add_celix_bundle(deployment_admin
SYMBOLIC_NAME "apache_celix_deployment_admin"
VERSION "0.0.2"
NAME "Apache Celix Deployment Admin"
SOURCES
- private/src/deployment_package
- private/src/deployment_admin
- private/src/deployment_admin_activator
- private/src/ioapi
- private/src/miniunz
- private/src/unzip
- private/src/log
- private/src/log_store
- private/src/log_sync
+ src/deployment_package
+ src/deployment_admin
+ src/deployment_admin_activator
+ src/ioapi
+ src/miniunz
+ src/unzip
+ src/log
+ src/log_store
+ src/log_sync
+ )
- private/include/deployment_admin.h
- private/include/deployment_package.h
- private/include/ioapi.h
- private/include/log.h
- private/include/log_event.h
- private/include/log_store.h
- private/include/log_sync.h
- private/include/miniunz.h
- private/include/unzip.h
+ target_compile_definitions(deployment_admin PRIVATE -DUSE_FILE32API)
+ target_include_directories(deployment_admin PRIVATE
+ src
+ ${CURL_INCLUDE_DIRS}
+ ${UUID_INCLUDE_DIRS}
+ ${ZLIB_INCLUDE_DIRS}
)
+ target_link_libraries(deployment_admin PRIVATE ${CURL_LIBRARIES} ${UUID_LIBRARIES} ${ZLIB_LIBRARIES} deployment_admin_api)
- install_bundle(deployment_admin)
-
- install_celix_bundle(deployment_admin
- HEADERS
- public/include/resource_processor.h
- )
-
- target_link_libraries(deployment_admin celix_framework ${CURL_LIBRARIES})
++ install_celix_bundle(deployment_admin)
+ #Setup target aliases to match external usage
+ add_library(Celix::deployment_admin_api ALIAS deployment_admin_api)
+ add_library(Celix::deployment_admin ALIAS deployment_admin)
- add_deploy(deployment-admin
+ add_celix_container(deployment-admin
- BUNDLES deployment_admin shell shell_tui log_service log_writer
+ BUNDLES Celix::deployment_admin Celix::shell Celix::shell_tui Celix::log_service Celix::log_writer_stdout
PROPERTIES
"deployment_admin_url=http://localhost:8080"
"deployment_admin_identification=celix"
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/deployment_admin/README.md
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/device_access/README.md
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/device_access/device_access/CMakeLists.txt
----------------------------------------------------------------------
diff --cc device_access/device_access/CMakeLists.txt
index 5f19293,52b8694..c39eb9b
--- a/device_access/device_access/CMakeLists.txt
+++ b/device_access/device_access/CMakeLists.txt
@@@ -15,37 -15,39 +15,37 @@@
# specific language governing permissions and limitations
# under the License.
+
+add_library(device_access_api INTERFACE)
+target_include_directories(device_access_api INTERFACE include)
+
- add_bundle(device_manager
+ add_celix_bundle(device_manager
SYMBOLIC_NAME "apache_celix_device_manager"
VERSION "0.0.2"
NAME "Apache Celix Device Access Device Manager"
SOURCES
- private/src/activator
- private/src/driver_attributes
- private/src/device_manager
- private/src/driver_loader
- private/src/driver_matcher
-
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
-
- private/include/device_manager.h
- private/include/driver_attributes.h
- private/include/driver_loader.h
- private/include/driver_matcher.h
+ src/activator
+ src/driver_attributes
+ src/device_manager
+ src/driver_loader
+ src/driver_matcher
)
+target_link_libraries(device_manager PRIVATE Celix::log_helper)
- install_bundle(device_manager
+ install_celix_bundle(device_manager
HEADERS
- public/include/device.h
- public/include/driver_locator.h
- public/include/driver_selector.h
- public/include/driver.h
- public/include/match.h
+ include/device.h
+ include/driver_locator.h
+ include/driver_selector.h
+ include/driver.h
+ include/match.h
)
+target_include_directories(device_manager PRIVATE src)
+target_link_libraries(device_manager PRIVATE device_access_api)
-include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
-include_directories("public/include")
-include_directories("private/include")
+#Setup target aliases to match external usage
+add_library(Celix::device_access_api ALIAS device_access_api)
+add_library(Celix::device_manager ALIAS device_manager)
-target_link_libraries(device_manager celix_framework celix_utils)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/device_access/driver_locator/CMakeLists.txt
----------------------------------------------------------------------
diff --cc device_access/driver_locator/CMakeLists.txt
index 2e0dde2,88c1fed..f7c679a
--- a/device_access/driver_locator/CMakeLists.txt
+++ b/device_access/driver_locator/CMakeLists.txt
@@@ -20,13 -20,15 +20,13 @@@ add_celix_bundle(driver_locato
VERSION "0.0.2"
NAME "Apache Celix Device Access Driver Locator"
SOURCES
- private/src/activator
- private/src/driver_locator
+ src/activator
+ src/driver_locator
)
- install_bundle(driver_locator)
+ install_celix_bundle(driver_locator)
+target_include_directories(driver_locator PRIVATE src)
+target_link_libraries(driver_locator PRIVATE Celix::device_access_api)
-include_directories(${PROJECT_SOURCE_DIR}/device_access/device_access/public/include)
-include_directories(private/include)
-include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
-
-target_link_libraries(driver_locator celix_utils celix_framework)
+#Setup target aliases to match external usage
+add_library(Celix::driver_locator ALIAS driver_locator)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/device_access/example/CMakeLists.txt
----------------------------------------------------------------------
diff --cc device_access/example/CMakeLists.txt
index e21e5e0,f7062b4..5deaf85
--- a/device_access/example/CMakeLists.txt
+++ b/device_access/example/CMakeLists.txt
@@@ -21,11 -21,11 +21,11 @@@ if(DEVICE_ACCESS_EXAMPLE
add_subdirectory(consuming_driver)
add_subdirectory(refining_driver)
- add_deploy(device_access_example
+ add_celix_container(device_access_example
- BUNDLES device_manager driver_locator shell shell_tui log_service base_driver
+ BUNDLES Celix::device_manager Celix::driver_locator Celix::shell Celix::shell_tui log_service base_driver
)
- deploy_bundles_dir(device_access_example
+ celix_container_bundles_dir(device_access_example
DIR_NAME "drivers"
BUNDLES word_consumingdriver char_refiningdriver
)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/device_access/example/base_driver/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/device_access/example/consuming_driver/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/device_access/example/refining_driver/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/dfi/CMakeLists.txt
----------------------------------------------------------------------
diff --cc dfi/CMakeLists.txt
index 950aaa5,676277c..39ed784
--- a/dfi/CMakeLists.txt
+++ b/dfi/CMakeLists.txt
@@@ -18,40 -18,49 +18,45 @@@
find_package(FFI REQUIRED)
find_package(Jansson REQUIRED)
-include_directories(
- ${FFI_INCLUDE_DIRS}
- ${JANSSON_INCLUDE_DIRS}
- private/include
- public/include
- ${PROJECT_SOURCE_DIR}/utils/public/include
+set(SOURCES
+ src/dyn_common.c
+ src/dyn_type.c
+ src/dyn_function.c
+ src/dyn_interface.c
+ src/dyn_message.c
+ src/json_serializer.c
+ src/json_rpc.c
)
- add_library(celix_dfi SHARED ${SOURCES})
- set_target_properties(celix_dfi PROPERTIES OUTPUT_NAME "celix_dfi")
- target_include_directories(celix_dfi PUBLIC include ${JANSSON_INCLUDE_DIRS})
- target_include_directories(celix_dfi PRIVATE src ${FFI_INCLUDE_DIRS})
- target_link_libraries(celix_dfi PUBLIC ${JANSSON_LIBRARY})
- target_link_libraries(celix_dfi PRIVATE Celix::utils ${FFI_LIBRARIES})
- set_target_properties(celix_dfi PROPERTIES "SOVERSION" 1)
-set(MEMSTREAM_SOURCES )
-set(MEMSTREAM_INCLUDES )
-if (APPLE OR ANDROID)
- set(MEMSTREAM_SOURCES ${PROJECT_SOURCE_DIR}/utils/private/src/memstream/open_memstream.c ${PROJECT_SOURCE_DIR}/utils/private/src/memstream/fmemopen.c)
- set(MEMSTREAM_INCLUDES ${PROJECT_SOURCE_DIR}/utils/public/include/memstream/open_memstream.h ${PROJECT_SOURCE_DIR}/utils/public/include/memstream/fmemopen.h)
- include_directories(${PROJECT_SOURCE_DIR}/utils/public/include/memstream)
-endif()
--
- add_library(celix_dfi_static STATIC ${SOURCES})
- set_target_properties(celix_dfi_static PROPERTIES OUTPUT_NAME "celix_dfi_static")
- target_include_directories(celix_dfi_static PUBLIC include ${JANSSON_INCLUDE_DIRS})
- target_include_directories(celix_dfi_static PRIVATE src ${FFI_INCLUDE_DIRS})
- target_link_libraries(celix_dfi_static PUBLIC ${JANSSON_LIBRARY})
- target_link_libraries(celix_dfi_static PRIVATE Celix::utils ${FFI_LIBRARIES})
-add_library(celix_dfi SHARED
- private/src/dyn_common.c
- private/src/dyn_type.c
- private/src/dyn_function.c
- private/src/dyn_interface.c
- private/src/dyn_message.c
- private/src/json_serializer.c
- private/src/json_rpc.c
- ${MEMSTREAM_SOURCES}
++add_library(dfi SHARED ${SOURCES})
++set_target_properties(dfi PROPERTIES OUTPUT_NAME "celix_dfi")
++target_include_directories(dfi PUBLIC
++ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
++ $<INSTALL_INTERFACE:include/celix/dfi>
++ ${JANSSON_INCLUDE_DIRS}
++)
++target_include_directories(dfi PRIVATE src ${FFI_INCLUDE_DIRS})
++target_link_libraries(dfi PUBLIC ${JANSSON_LIBRARY})
++target_link_libraries(dfi PRIVATE Celix::utils ${FFI_LIBRARIES})
++set_target_properties(dfi PROPERTIES "SOVERSION" 1)
- install(TARGETS celix_dfi celix_dfi_static DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT framework)
- public/include/dyn_common.h
- public/include/dyn_type.h
- public/include/dyn_function.h
- public/include/dyn_interface.h
- public/include/dyn_message.h
- public/include/json_serializer.h
- public/include/json_rpc.h
- ${MEMSTREAM_INCLUDES}
++add_library(dfi_static STATIC ${SOURCES})
++set_target_properties(dfi_static PROPERTIES OUTPUT_NAME "celix_dfi_static")
++target_include_directories(dfi_static PUBLIC
++ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
++ $<INSTALL_INTERFACE:include/celix/dfi>
++ ${JANSSON_INCLUDE_DIRS}
+ )
-set_target_properties(celix_dfi PROPERTIES "SOVERSION" 1)
-set_target_properties(celix_dfi PROPERTIES "VERSION" 1.1.0)
-target_link_libraries(celix_dfi celix_utils ${FFI_LIBRARIES} ${JANSSON_LIBRARY})
++target_include_directories(dfi_static PRIVATE src ${FFI_INCLUDE_DIRS})
++target_link_libraries(dfi_static PUBLIC ${JANSSON_LIBRARY})
++target_link_libraries(dfi_static PRIVATE Celix::utils ${FFI_LIBRARIES})
--install(TARGETS celix_dfi DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT framework)
- FILE(GLOB files "include/*.h")
-FILE(GLOB files "public/include/*.h" ${MEMSTREAM_INCLUDES})
--INSTALL(FILES ${files} DESTINATION include/celix/dfi COMPONENT framework)
++install(TARGETS dfi dfi_static EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dfi)
++install(DIRECTORY include/ DESTINATION include/celix/dfi COMPONENT dfi)
+#Alias setup to match external usage
- add_library(Celix::dfi ALIAS celix_dfi)
- add_library(Celix::dfi_static ALIAS celix_dfi_static)
++add_library(Celix::dfi ALIAS dfi)
++add_library(Celix::dfi_static ALIAS dfi_static)
if (ENABLE_TESTING)
find_package(CppUTest REQUIRED)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/event_admin/event_admin/CMakeLists.txt
----------------------------------------------------------------------
diff --cc event_admin/event_admin/CMakeLists.txt
index 4a0f687,52b1120..87b6e62
--- a/event_admin/event_admin/CMakeLists.txt
+++ b/event_admin/event_admin/CMakeLists.txt
@@@ -34,6 -34,6 +34,6 @@@ add_celix_bundle(event_admi
${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
)
- install_bundle(event_admin)
+ install_celix_bundle(event_admin)
-target_link_libraries(event_admin celix_framework celix_utils)
+target_link_libraries(event_admin Celix::framework)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/event_admin/event_handler/CMakeLists.txt
----------------------------------------------------------------------
diff --cc event_admin/event_handler/CMakeLists.txt
index 2843122,fe2609c..92813a7
--- a/event_admin/event_handler/CMakeLists.txt
+++ b/event_admin/event_handler/CMakeLists.txt
@@@ -30,6 -30,6 +30,6 @@@ add_celix_bundle(event_handle
${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
)
- install_bundle(event_handler)
+ install_celix_bundle(event_handler)
-target_link_libraries(event_handler celix_framework celix_utils)
+target_link_libraries(event_handler Celix::framework)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/event_admin/event_publisher/CMakeLists.txt
----------------------------------------------------------------------
diff --cc event_admin/event_publisher/CMakeLists.txt
index dc9e516,01b7b10..4dd314a
--- a/event_admin/event_publisher/CMakeLists.txt
+++ b/event_admin/event_publisher/CMakeLists.txt
@@@ -29,6 -29,6 +29,6 @@@ add_celix_bundle(event_publishe
${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
)
- install_bundle(event_publisher)
+ install_celix_bundle(event_publisher)
-target_link_libraries(event_publisher celix_framework celix_utils)
+target_link_libraries(event_publisher Celix::framework)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/dm_example/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/dm_example/CMakeLists.txt
index a18a675,16a8ce1..a2a2143
--- a/examples/dm_example/CMakeLists.txt
+++ b/examples/dm_example/CMakeLists.txt
@@@ -24,16 -27,16 +24,16 @@@ if (BUILD_DEPENDENCY_MANAGER
add_subdirectory(phase3)
- add_deploy(dm_example
- add_celix_container("dm_example"
++ add_celix_container(dm_example
COPY
BUNDLES
- shell
- shell_tui
- dm_shell
- phase1
- phase2a
- phase2b
- phase3
+ Celix::shell
+ Celix::shell_tui
+ Celix::dm_shell
+ dm_example_phase1
+ dm_example_phase2a
+ dm_example_phase2b
+ dm_example_phase3
PROPERTIES
LOGHELPER_ENABLE_STDOUT_FALLBACK=true
)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/dm_example/api/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/dm_example/api/CMakeLists.txt
index 900c8fb,0000000..edbb643
mode 100644,000000..100644
--- a/examples/dm_example/api/CMakeLists.txt
+++ b/examples/dm_example/api/CMakeLists.txt
@@@ -1,19 -1,0 +1,19 @@@
+# 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.
+
+add_library(dm_example_api INTERFACE)
- target_include_directories(dm_example_api INTERFACE include)
++target_include_directories(dm_example_api INTERFACE include)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/dm_example/phase1/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/dm_example/phase1/CMakeLists.txt
index 5263bab,dabb88f..09402ea
--- a/examples/dm_example/phase1/CMakeLists.txt
+++ b/examples/dm_example/phase1/CMakeLists.txt
@@@ -15,8 -15,12 +15,8 @@@
# specific language governing permissions and limitations
# under the License.
-include_directories(
- private/include
- ../services
-)
- add_bundle(dm_example_phase1
-add_celix_bundle(phase1
++add_celix_bundle(dm_example_phase1
SYMBOLIC_NAME phase1
VERSION 0.0.1
SOURCES
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/dm_example/phase2a/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/dm_example/phase2a/CMakeLists.txt
index cda4971,0bd8e7e..82a6fb5
--- a/examples/dm_example/phase2a/CMakeLists.txt
+++ b/examples/dm_example/phase2a/CMakeLists.txt
@@@ -15,7 -15,12 +15,7 @@@
# specific language governing permissions and limitations
# under the License.
- add_bundle(dm_example_phase2a
-include_directories(
- private/include
- ../services
-)
-
-add_celix_bundle(phase2a
++add_celix_bundle(dm_example_phase2a
SYMBOLIC_NAME phase2a
VERSION 0.0.1
SOURCES
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/dm_example/phase2b/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/dm_example/phase2b/CMakeLists.txt
index 9afb6c7,775e786..9172ad8
--- a/examples/dm_example/phase2b/CMakeLists.txt
+++ b/examples/dm_example/phase2b/CMakeLists.txt
@@@ -15,7 -15,12 +15,7 @@@
# specific language governing permissions and limitations
# under the License.
- add_bundle(dm_example_phase2b
-include_directories(
- private/include
- ../services
-)
-
-add_celix_bundle(phase2b
++add_celix_bundle(dm_example_phase2b
SYMBOLIC_NAME phase2b
VERSION 0.0.1
SOURCES
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/dm_example/phase3/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/dm_example/phase3/CMakeLists.txt
index 1784057,163980f..7cad101
--- a/examples/dm_example/phase3/CMakeLists.txt
+++ b/examples/dm_example/phase3/CMakeLists.txt
@@@ -15,7 -15,12 +15,7 @@@
# specific language governing permissions and limitations
# under the License.
- add_bundle(dm_example_phase3
-include_directories(
- private/include
- ../services
-)
-
-add_celix_bundle(phase3
++add_celix_bundle(dm_example_phase3
SYMBOLIC_NAME phase3
VERSION 0.0.1
SOURCES
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/dm_example_cxx/phase1/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/dm_example_cxx/phase1/CMakeLists.txt
index 0832816,1a5d049..5007e77
--- a/examples/dm_example_cxx/phase1/CMakeLists.txt
+++ b/examples/dm_example_cxx/phase1/CMakeLists.txt
@@@ -15,7 -15,12 +15,7 @@@
# specific language governing permissions and limitations
# under the License.
- add_bundle(dm_example_cxx_phase1
-include_directories(
- include
- ../api
-)
-
-add_celix_bundle(phase1_cxx
++add_celix_bundle(dm_example_cxx_phase1
SYMBOLIC_NAME phase1_cxx
VERSION 0.0.1
SOURCES
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/dm_example_cxx/phase2/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/dm_example_cxx/phase2/CMakeLists.txt
index 66f4ddd,0000000..f2b3813
mode 100644,000000..100644
--- a/examples/dm_example_cxx/phase2/CMakeLists.txt
+++ b/examples/dm_example_cxx/phase2/CMakeLists.txt
@@@ -1,51 -1,0 +1,51 @@@
+# 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.
+
- add_bundle(dm_example_cxx_phase2a
++add_celix_bundle(dm_example_cxx_phase2a
+ SYMBOLIC_NAME phase2a_cxx
+ VERSION 0.0.1
+ SOURCES
+ src/Phase2aActivator.cc
+ src/Phase2aCmp.cc
+)
+target_include_directories(dm_example_cxx_phase2a PRIVATE src)
+target_link_libraries(dm_example_cxx_phase2a PRIVATE Celix::log_service_api dm_example_cxx_api)
+
- add_bundle(dm_example_cxx_phase2b
++add_celix_bundle(dm_example_cxx_phase2b
+ SYMBOLIC_NAME phase2b_cxx
+ VERSION 0.0.1
+ SOURCES
+ src/Phase2bActivator.cc
+ src/Phase2bCmp.cc
+ )
+target_include_directories(dm_example_cxx_phase2b PRIVATE src)
+target_link_libraries(dm_example_cxx_phase2b PRIVATE Celix::log_service_api dm_example_cxx_api)
+
+IF(APPLE)
+ target_link_libraries(dm_example_cxx_phase2a PRIVATE -Wl,-all_load Celix::dependency_manager_cxx_static)
+ target_link_libraries(dm_example_cxx_phase2b PRIVATE -Wl,-all_load Celix::dependency_manager_cxx_static)
+else()
+ if(ENABLE_ADDRESS_SANITIZER)
+ #With asan there can be undefined symbols
+ target_link_libraries(dm_example_cxx_phase2a PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
+ target_link_libraries(dm_example_cxx_phase2b PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
+ else()
+ target_link_libraries(dm_example_cxx_phase2a PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
+ target_link_libraries(dm_example_cxx_phase2b PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
+
+ endif()
+endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/dm_example_cxx/phase3/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/dm_example_cxx/phase3/CMakeLists.txt
index 2a62cbb,3c23582..3728abc
--- a/examples/dm_example_cxx/phase3/CMakeLists.txt
+++ b/examples/dm_example_cxx/phase3/CMakeLists.txt
@@@ -15,7 -15,12 +15,7 @@@
# specific language governing permissions and limitations
# under the License.
- add_bundle(dm_example_cxx_phase3
-include_directories(
- include
- ../api
-)
-
-add_celix_bundle(phase3_cxx
++add_celix_bundle(dm_example_cxx_phase3
SYMBOLIC_NAME phase3_cxx
VERSION 0.0.1
SOURCES
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/dm_example_cxx/phase3_locking/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/dm_example_cxx/phase3_locking/CMakeLists.txt
index 2ea1eb4,ef10a33..35ca3c9
--- a/examples/dm_example_cxx/phase3_locking/CMakeLists.txt
+++ b/examples/dm_example_cxx/phase3_locking/CMakeLists.txt
@@@ -15,8 -15,12 +15,8 @@@
# specific language governing permissions and limitations
# under the License.
-include_directories(
- include
- ../api
-)
- add_bundle(dm_example_cxx_phase3_locking
-add_celix_bundle(phase3_locking_cxx
++add_celix_bundle(dm_example_cxx_phase3_locking
SYMBOLIC_NAME phase3_locking_cxx
VERSION 0.0.1
SOURCES
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/hello_world/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/hello_world/CMakeLists.txt
index ca72eec,e90149e..130cef0
--- a/examples/hello_world/CMakeLists.txt
+++ b/examples/hello_world/CMakeLists.txt
@@@ -32,7 -32,7 +32,7 @@@ add_library(hello_test2lib SHARE
)
set_library_version(hello_test2lib "3.3.3")
- add_bundle(hello_bundle
-add_celix_bundle(hello
++add_celix_bundle(hello_bundle
VERSION "1.2"
SOURCES
private/src/activator.c
@@@ -45,19 -45,19 +45,19 @@@ add_celix_bundle(hello_expor
EXPORT_LIBRARIES hello_test2lib
)
- bundle_private_libs(hello_bundle
-celix_bundle_private_libs(hello
++celix_bundle_private_libs(hello_bundle
hello_testlib
)
- add_deploy(helloworld_byref
+ add_celix_container(helloworld_byref
GROUP hello
- BUNDLES hello_export hello shell shell_tui
+ BUNDLES hello_export hello_bundle ${CELIX_SHELL_BUNDLE} ${CELIX_SHELL_TUI_BUNDLE}
)
- add_deploy(helloworld_withcopy
+ add_celix_container(helloworld_withcopy
GROUP hello
COPY #Ensures that bundles are copied in the deploy location
- BUNDLES hello_export hello shell shell_tui
+ BUNDLES hello_export hello_bundle ${SHELL_BUNDLE} ${SHELL_TUI_BUNDLE}
)
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/hello_world_test/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/hello_world_test/CMakeLists.txt
index 08053e5,2d146fc..41045b2
--- a/examples/hello_world_test/CMakeLists.txt
+++ b/examples/hello_world_test/CMakeLists.txt
@@@ -16,22 -16,19 +16,22 @@@
# under the License.
#############################################################################
- ## NOTE Examples of using add_bundle and add_deploy and assorted commands ##
+ ## NOTE Examples of using add_celix_bundle and add_celix_container and assorted commands ##
#############################################################################
- add_bundle(hellotest1
-include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
-include_directories(public/include)
-
+ add_celix_bundle(hellotest1
VERSION "1.2"
SOURCES
private/src/activator
)
+target_include_directories(hellotest1 PRIVATE
+ ${PROJECT_SOURCE_DIR}/utils/public/include
+ public/include
+)
+
+
- bundle_headers(hellotest1
+ celix_bundle_headers(hellotest1
"X-WebContent: web"
"X-MediaType: application/json"
)
@@@ -41,7 -38,7 +41,7 @@@ add_library(tlib SHARE
)
set_library_version(tlib "4.3.2") # sets target propery VERSION to 4.3.2 and SOVERSION to 4
--#bundle_private_libs(hellotest1
++#celix_bundle_private_libs(hellotest1
# #/usr/local/lib/libjansson.4.dylib
# /usr/lib64/libjansson.so.4
#)
@@@ -75,8 -72,7 +75,8 @@@ add_library(hello2act SHARE
private/src/activator
)
set_library_version(hello2act "3.2.4") #sets VERSION prop to 3.2.4 and SOVERSION to 3
+target_link_libraries(hello2act PRIVATE Celix::framework )
- add_bundle(hellotest2
+ add_celix_bundle(hellotest2
VERSION "1.0.0" #can be the same as activator lib, but does not have to be
ACTIVATOR hello2act
)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/log_service_example/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/log_service_example/CMakeLists.txt
index 1326a0f,fffa68f..31f6fc8
--- a/examples/log_service_example/CMakeLists.txt
+++ b/examples/log_service_example/CMakeLists.txt
@@@ -17,15 -17,20 +17,15 @@@
#Importing and exporting libraries not (yet) work under OSX.
- add_bundle(log_service_example
-include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
-include_directories("public/include")
-include_directories("${CMAKE_SOURCE_DIR}/log_service/public/include")
-
+ add_celix_bundle(log_service_example
VERSION "1.0"
SOURCES
- private/src/activator.c
- ${CMAKE_SOURCE_DIR}/log_service/public/src/log_helper.c
+ src/activator.c
)
+target_include_directories(log_service_example PRIVATE src)
+target_link_libraries(log_service_example PRIVATE Celix::log_service_api Celix::log_helper)
- add_deploy(log_example
+ add_celix_container(log_example
GROUP log_service
- BUNDLES log_service_example log_service shell shell_tui
+ BUNDLES log_service_example Celix::log_service Celix::shell Celix::shell_tui
)
-
-target_link_libraries(log_service_example celix_framework celix_utils)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/mongoose/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/mongoose/CMakeLists.txt
index 118d923,2de051f..7119aa7
--- a/examples/mongoose/CMakeLists.txt
+++ b/examples/mongoose/CMakeLists.txt
@@@ -35,8 -35,8 +35,8 @@@ add_celix_bundle(mongoos
private/include/mongoose.h
)
- bundle_files(mongoose ${CMAKE_CURRENT_LIST_DIR}/root)
+ celix_bundle_files(mongoose ${CMAKE_CURRENT_LIST_DIR}/root)
-target_link_libraries(mongoose celix_framework mongooselib ${LIBS})
+target_link_libraries(mongoose PRIVATE mongooselib ${LIBS})
- add_deploy("mongoose_deploy" BUNDLES Celix::shell Celix::shell_tui log_service mongoose)
-add_celix_container("mongoose_deploy" BUNDLES shell shell_tui log_service mongoose)
++add_celix_container("mongoose_deploy" BUNDLES Celix::shell Celix::shell_tui log_service mongoose)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/service_hook_example/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/service_hook_example/CMakeLists.txt
index 99e9b2a,8348059..9dbe7c0
--- a/examples/service_hook_example/CMakeLists.txt
+++ b/examples/service_hook_example/CMakeLists.txt
@@@ -15,16 -15,23 +15,16 @@@
# specific language governing permissions and limitations
# under the License.
- add_bundle(hook_example
-if(NOT APPLE)
-#Importing and exporting libraries not (yet) work under OSX.
-
-include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
-include_directories("public/include")
-
+ add_celix_bundle(hook_example
- BUNDLE_SYMBOLICNAME "Hook_Example"
- VERSION "1.0.0"
- SOURCES
- private/src/activator
+ BUNDLE_SYMBOLICNAME "Hook_Example"
+ VERSION "1.0.0"
+ SOURCES
+ src/activator
)
- add_deploy(hook_service_example
-add_celix_container("hook_service_example"
- BUNDLES
- shell
- shell_tui
- hook_example
++add_celix_container(hook_service_example
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ hook_example
- )
+ )
-endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/services_example_c/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/services_example_c/bar/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/services_example_c/foo1/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/services_example_c/foo2/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/services_example_cxx/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/services_example_cxx/bar/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/services_example_cxx/baz/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/examples/services_example_cxx/foo/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/framework/src/celix_launcher.c
----------------------------------------------------------------------
diff --cc framework/src/celix_launcher.c
index fe5d0c0,0000000..8a14e9b
mode 100644,000000..100644
--- a/framework/src/celix_launcher.c
+++ b/framework/src/celix_launcher.c
@@@ -1,315 -1,0 +1,317 @@@
+/**
+ *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_launcher.c
+ *
+ * \date Mar 23, 2010
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include "celix_launcher.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <libgen.h>
+#include <signal.h>
+
+#ifndef CELIX_NO_CURLINIT
+#include <curl/curl.h>
+#endif
+
+#include <string.h>
+#include <curl/curl.h>
+#include <signal.h>
+#include <libgen.h>
+#include "celix_launcher.h"
+#include "framework.h"
+#include "linked_list_iterator.h"
+
+static void show_usage(char* prog_name);
+static void shutdown_framework(int signal);
+static void ignore(int signal);
+
+static int celixLauncher_launchWithConfigAndProps(const char *configFile, framework_pt *framework, properties_pt packedConfig);
+static int celixLauncher_launchWithStreamAndProps(FILE *stream, framework_pt *framework, properties_pt packedConfig);
+
+#define DEFAULT_CONFIG_FILE "config.properties"
+
+static framework_pt framework = NULL;
+
+/**
+ * Method kept because of usage in examples & unit tests
+ */
+int celixLauncher_launchWithArgs(int argc, char *argv[]) {
+ return celixLauncher_launchWithArgsAndProps(argc, argv, NULL);
+}
+
+int celixLauncher_launchWithArgsAndProps(int argc, char *argv[], properties_pt packedConfig) {
+ // Perform some minimal command-line option parsing...
+ char *opt = NULL;
+ if (argc > 1) {
+ opt = argv[1];
+ }
+
+ char *config_file = NULL;
+
+ if (opt) {
+ // Check whether the user wants some help...
+ if (strcmp("-h", opt) == 0 || strcmp("-help", opt) == 0) {
+ show_usage(argv[0]);
+ return 0;
+ } else {
+ config_file = opt;
+ }
+ } else {
+ config_file = DEFAULT_CONFIG_FILE;
+ }
+
+ struct sigaction sigact;
+ memset(&sigact, 0, sizeof(sigact));
+ sigact.sa_handler = shutdown_framework;
+ sigaction(SIGINT, &sigact, NULL);
+ sigaction(SIGTERM, &sigact, NULL);
+
+ memset(&sigact, 0, sizeof(sigact));
+ sigact.sa_handler = ignore;
+ sigaction(SIGUSR1, &sigact, NULL);
+ sigaction(SIGUSR2, &sigact, NULL);
+
+ int rc = celixLauncher_launchWithConfigAndProps(config_file, &framework, packedConfig);
+ if (rc == 0) {
+ celixLauncher_waitForShutdown(framework);
+ celixLauncher_destroy(framework);
+ }
+ return rc;
+}
+
+static void show_usage(char* prog_name) {
+ printf("Usage:\n %s [path/to/config.properties]\n\n", basename(prog_name));
+}
+
+static void shutdown_framework(int signal) {
+ if (framework != NULL) {
+ celixLauncher_stop(framework); //NOTE main thread will destroy
+ }
+}
+
+static void ignore(int signal) {
+ //ignoring for signal SIGUSR1, SIGUSR2. Can be used on threads
+}
+
+int celixLauncher_launch(const char *configFile, framework_pt *framework) {
+ return celixLauncher_launchWithConfigAndProps(configFile, framework, NULL);
+}
+
+static int celixLauncher_launchWithConfigAndProps(const char *configFile, framework_pt *framework, properties_pt packedConfig){
+ int status = 0;
+ FILE *config = fopen(configFile, "r");
+
+ if (config != NULL && packedConfig != NULL) {
+ status = celixLauncher_launchWithStreamAndProps(config, framework, packedConfig);
+ } else if (config != NULL) {
+ status = celixLauncher_launchWithStream(config, framework);
+ } else if (packedConfig != NULL) {
+ status = celixLauncher_launchWithProperties(packedConfig, framework);
+ } else {
+ fprintf(stderr, "Error: invalid or non-existing configuration file: '%s'.", configFile);
+ perror("");
+ status = 1;
+ }
+
+ return status;
+}
+
+int celixLauncher_launchWithStream(FILE *stream, framework_pt *framework) {
+ int status = 0;
+
+ properties_pt config = properties_loadWithStream(stream);
+ fclose(stream);
+ // Make sure we've read it and that nothing went wrong with the file access...
+ if (config == NULL) {
+ fprintf(stderr, "Error: invalid configuration file");
+ perror(NULL);
+ status = 1;
+ }
+ else {
+ status = celixLauncher_launchWithProperties(config, framework);
+ }
+
+ return status;
+}
+
+static int celixLauncher_launchWithStreamAndProps(FILE *stream, framework_pt *framework, properties_pt packedConfig){
+ int status = 0;
+
+ properties_pt runtimeConfig = properties_loadWithStream(stream);
+ fclose(stream);
+
+ // Make sure we've read it and that nothing went wrong with the file access...
+ // If there is no runtimeConfig, the packedConfig can be stored as global config
+ if (runtimeConfig == NULL){
+ runtimeConfig = packedConfig;
+ }
+
+ if (runtimeConfig == NULL) {
+ fprintf(stderr, "Error: invalid configuration file");
+ perror(NULL);
+ status = 1;
+ } else {
+ // Check if there's a pre-compiled config available
+ if (packedConfig != NULL){
+ // runtimeConfig and packedConfig must be merged
+ // when a duplicate of a key is available, the runtimeConfig must be prioritized
+
+ hash_map_iterator_t iter = hashMapIterator_construct(packedConfig);
+
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(&iter);
+
+ while (entry != NULL) {
+ const char * key = (const char *) hashMapEntry_getKey(entry);
+ const char * value = (const char *) hashMapEntry_getValue(entry);
+
+ // Check existence of key in runtimeConfig
+ if (!hashMap_containsKey(runtimeConfig, key)) {
+ properties_set(runtimeConfig, key, value);
+ }
+
+ entry = hashMapIterator_nextEntry(&iter);
+ if (entry != NULL) {
+ key = (const char *) hashMapEntry_getKey(entry);
+ value = (const char *) hashMapEntry_getValue(entry);
+ }
+ }
+
+ // normally, the framework_destroy will clean up the properties_pt
+ // since there are 2 properties_pt available (runtimeConfig and packedConfig)
+ // the packedConfig must be destroyed
+ properties_destroy(packedConfig);
+ }
+
+ status = celixLauncher_launchWithProperties(runtimeConfig, framework);
+ }
+
+ return status;
+}
+
+int celixLauncher_launchWithProperties(properties_pt config, framework_pt *framework) {
+ celix_status_t status;
+#ifndef CELIX_NO_CURLINIT
+ // Before doing anything else, let's setup Curl
+ curl_global_init(CURL_GLOBAL_NOTHING);
+#endif
+
+ const char* autoStartProp = properties_get(config, "cosgi.auto.start.1");
+ char* autoStart = NULL;
+ if (autoStartProp != NULL) {
+ autoStart = strndup(autoStartProp, 1024*10);
+ }
+
+ status = framework_create(framework, config);
+ bundle_pt fwBundle = NULL;
+ if (status == CELIX_SUCCESS) {
+ status = fw_init(*framework);
+ if (status == CELIX_SUCCESS) {
+ // Start the system bundle
+ status = framework_getFrameworkBundle(*framework, &fwBundle);
+
+ if(status == CELIX_SUCCESS){
+ bundle_start(fwBundle);
+
+ char delims[] = " ";
+ char *result = NULL;
+ char *save_ptr = NULL;
+ linked_list_pt bundles;
+ array_list_pt installed = NULL;
+ bundle_context_pt context = NULL;
+ linked_list_iterator_pt iter = NULL;
+ unsigned int i;
+
+ linkedList_create(&bundles);
- result = strtok_r(autoStart, delims, &save_ptr);
- while (result != NULL) {
- char *location = strdup(result);
- linkedList_addElement(bundles, location);
- result = strtok_r(NULL, delims, &save_ptr);
++ if (autoStart != NULL) {
++ result = strtok_r(autoStart, delims, &save_ptr);
++ while (result != NULL) {
++ char *location = strdup(result);
++ linkedList_addElement(bundles, location);
++ result = strtok_r(NULL, delims, &save_ptr);
++ }
+ }
+ // First install all bundles
+ // Afterwards start them
+ arrayList_create(&installed);
+ bundle_getContext(fwBundle, &context);
+ iter = linkedListIterator_create(bundles, 0);
+ while (linkedListIterator_hasNext(iter)) {
+ bundle_pt current = NULL;
+ char *location = (char *) linkedListIterator_next(iter);
+ if (bundleContext_installBundle(context, location, ¤t) == CELIX_SUCCESS) {
+ // Only add bundle if it is installed correctly
+ arrayList_add(installed, current);
+ } else {
+ printf("Could not install bundle from %s\n", location);
+ }
+ linkedListIterator_remove(iter);
+ free(location);
+ }
+ linkedListIterator_destroy(iter);
+ linkedList_destroy(bundles);
+
+ for (i = 0; i < arrayList_size(installed); i++) {
+ bundle_pt installedBundle = (bundle_pt) arrayList_get(installed, i);
+ bundle_startWithOptions(installedBundle, 0);
+ }
+
+ arrayList_destroy(installed);
+ }
+ }
+ }
+
+ if (status != CELIX_SUCCESS) {
+ printf("Problem creating framework\n");
+ }
+
+ printf("Launcher: Framework Started\n");
+
+ free(autoStart);
+
+ return status;
+}
+
+void celixLauncher_waitForShutdown(framework_pt framework) {
+ framework_waitForStop(framework);
+}
+
+void celixLauncher_destroy(framework_pt framework) {
+ framework_destroy(framework);
+
+#ifndef CELIX_NO_CURLINIT
+ // Cleanup Curl
+ curl_global_cleanup();
+#endif
+
+ printf("Launcher: Exit\n");
+}
+
+void celixLauncher_stop(framework_pt framework) {
+ bundle_pt fwBundle = NULL;
+ if( framework_getFrameworkBundle(framework, &fwBundle) == CELIX_SUCCESS){
+ bundle_stop(fwBundle);
+ }
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/log_service/CMakeLists.txt
----------------------------------------------------------------------
diff --cc log_service/CMakeLists.txt
index 70afb0e,856e21d..bd59961
--- a/log_service/CMakeLists.txt
+++ b/log_service/CMakeLists.txt
@@@ -18,49 -18,37 +18,50 @@@
celix_subproject(LOG_SERVICE "Option to enable building the Log Service bundles" ON DEPS framework)
if (LOG_SERVICE)
+ add_library(log_service_api INTERFACE)
+ target_include_directories(log_service_api INTERFACE
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
+ $<INSTALL_INTERFACE:include/celix/log_service>
+ )
+ install(TARGETS log_service_api EXPORT celix)
+ install(DIRECTORY include/ DESTINATION include/celix/log_service)
+
+ add_library(log_helper STATIC src/log_helper.c)
++ set_target_properties(log_helper PROPERTIES OUTPUT_NAME "celix_log_helper")
+ target_include_directories(log_helper PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/loghelper_include>
+ $<INSTALL_INTERFACE:include/celix/log_helper>
+ )
+ target_link_libraries(log_helper PUBLIC Celix::framework log_service_api)
+ install(TARGETS log_helper EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT log_service)
+ install(DIRECTORY loghelper_include/ DESTINATION include/celix/log_helper COMPONENT log_service)
+
- add_bundle(log_service
+ add_celix_bundle(log_service
SYMBOLIC_NAME "apache_celix_log_service"
NAME "Apache Celix Log Service"
VERSION "1.1.0"
SOURCES
- private/src/log
- private/src/log_entry
- private/src/log_factory
- private/src/log_service_impl
- private/src/log_service_activator
- private/src/log_reader_service_impl
-
- private/include/log.h
- private/include/log_factory.h
- private/include/log_reader_service_impl.h
- private/include/log_service_impl.h
+ src/log
+ src/log_entry
+ src/log_factory
+ src/log_service_impl
+ src/log_service_activator
+ src/log_reader_service_impl
)
- install_bundle(log_service
+ install_celix_bundle(log_service
HEADERS
- public/include/log_service.h
- public/include/log_reader_service.h
- public/include/log_listener.h
- public/include/log_entry.h
- public/include/log_helper.h
- RESOURCES
- public/src/log_helper.c
+ include/log_service.h
+ include/log_reader_service.h
+ include/log_listener.h
+ include/log_entry.h
)
-
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/log_service/private/include")
- target_link_libraries(log_service celix_framework)
+
+ target_include_directories(log_service PRIVATE src)
+ target_link_libraries(log_service PRIVATE log_service_api)
+
+ #Setup target aliases to match external usage
+ add_library(Celix::log_service_api ALIAS log_service_api)
+ add_library(Celix::log_service ALIAS log_service)
+ add_library(Celix::log_helper ALIAS log_helper)
endif (LOG_SERVICE)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/log_writer/log_writer/CMakeLists.txt
----------------------------------------------------------------------
diff --cc log_writer/log_writer/CMakeLists.txt
index 09aa9cf,0000000..cc6b8eb
mode 100644,000000..100644
--- a/log_writer/log_writer/CMakeLists.txt
+++ b/log_writer/log_writer/CMakeLists.txt
@@@ -1,24 -1,0 +1,24 @@@
+# 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.
+
+add_library(log_writer_common STATIC
+ src/log_writer.c
+ src/log_writer_activator.c
+)
+target_include_directories(log_writer_common PRIVATE src)
+target_include_directories(log_writer_common PUBLIC include)
- target_link_libraries(log_writer_common PUBLIC Celix::log_service_api Celix::framework)
++target_link_libraries(log_writer_common PUBLIC Celix::log_service_api Celix::framework)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/log_writer/log_writer_stdout/CMakeLists.txt
----------------------------------------------------------------------
diff --cc log_writer/log_writer_stdout/CMakeLists.txt
index 6070b2e,6502792..94effae
--- a/log_writer/log_writer_stdout/CMakeLists.txt
+++ b/log_writer/log_writer_stdout/CMakeLists.txt
@@@ -15,14 -15,22 +15,14 @@@
# specific language governing permissions and limitations
# under the License.
- add_bundle(log_writer_stdout
-add_celix_bundle(log_writer
++add_celix_bundle(log_writer_stdout
SYMBOLIC_NAME "apache_celix_log_writer"
VERSION "1.1.0"
NAME "Apache Celix Log Writer"
SOURCES
- ${PROJECT_SOURCE_DIR}/log_writer/log_writer/private/src/log_writer_activator
- ${PROJECT_SOURCE_DIR}/log_writer/log_writer/private/src/log_writer
- ${PROJECT_SOURCE_DIR}/log_writer/log_writer/private/include/log_writer.h
-
- private/src/log_writer_stdout
+ src/log_writer_stdout
)
- install_bundle(log_writer_stdout)
-install_celix_bundle(log_writer)
-
-target_link_libraries(log_writer celix_framework)
-
-include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/log_writer/log_writer/private/include")
++install_celix_bundle(log_writer_stdout)
+
- target_link_libraries(log_writer_stdout PRIVATE Celix::log_service_api log_writer_common)
++target_link_libraries(log_writer_stdout PRIVATE Celix::log_service_api log_writer_common)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/log_writer/log_writer_syslog/CMakeLists.txt
----------------------------------------------------------------------
diff --cc log_writer/log_writer_syslog/CMakeLists.txt
index b98b914,faa7905..e2003d5
--- a/log_writer/log_writer_syslog/CMakeLists.txt
+++ b/log_writer/log_writer_syslog/CMakeLists.txt
@@@ -23,10 -23,18 +23,10 @@@ if (LOG_WRITER_SYSLOG
SYMBOLIC_NAME "apache_celix_log_writer_syslog"
NAME "Apache Celix Log Writer Syslog"
SOURCES
- ${PROJECT_SOURCE_DIR}/log_writer/log_writer/private/src/log_writer_activator
- ${PROJECT_SOURCE_DIR}/log_writer/log_writer/private/src/log_writer
- ${PROJECT_SOURCE_DIR}/log_writer/log_writer/private/include/log_writer.h
-
- private/src/log_writer_syslog
+ private/src/log_writer_syslog
)
- install_bundle(log_writer_syslog)
+ install_celix_bundle(log_writer_syslog)
-
- target_link_libraries(log_writer_syslog celix_framework)
-
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/log_writer/log_writer/private/include")
+
+ target_link_libraries(log_writer_syslog PRIVATE log_writer_common)
endif (LOG_WRITER_SYSLOG)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/CMakeLists.txt
----------------------------------------------------------------------
diff --cc pubsub/CMakeLists.txt
index 79f8168,5afc296..e3db995
--- a/pubsub/CMakeLists.txt
+++ b/pubsub/CMakeLists.txt
@@@ -34,12 -35,13 +34,12 @@@ if (PUBSUB
add_subdirectory(keygen)
add_subdirectory(mock)
+ add_subdirectory(examples)
if (ENABLE_TESTING)
- option(BUILD_PUBSUB_TESTS "Enable Tests for PUBSUB" OFF)
+ option(BUILD_PUBSUB_TESTS "Enable Tests for PUBSUB" OFF)
endif()
- if (ENABLE_TESTING AND BUILD_PUBSUB_TESTS)
+ if (ENABLE_TESTING AND BUILD_PUBSUB_TESTS AND BUILD_PUBSUB_PSA_ZMQ)
add_subdirectory(test)
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/examples/CMakeLists.txt
----------------------------------------------------------------------
diff --cc pubsub/examples/CMakeLists.txt
index b79b101,22ca5ca..6703324
--- a/pubsub/examples/CMakeLists.txt
+++ b/pubsub/examples/CMakeLists.txt
@@@ -17,216 -17,3 +17,216 @@@
add_subdirectory(pubsub)
add_subdirectory(mp_pubsub)
+
+find_program(ETCD_CMD NAMES etcd)
+find_program(XTERM_CMD NAMES xterm)
+
+# UDP Multicast
- add_deploy(pubsub_publisher_udp_mc
++add_celix_container(pubsub_publisher_udp_mc
+ GROUP pubsub
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_udp_multicast
+ celix_pubsub_poi_publisher
+ celix_pubsub_poi_publisher2
+ )
+
- add_deploy("pubsub_subscriber_udp_mc"
++add_celix_container("pubsub_subscriber_udp_mc"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_udp_multicast
+ celix_pubsub_poi_subscriber
+ )
+
- add_deploy("pubsub_subscriber2_udp_mc"
++add_celix_container("pubsub_subscriber2_udp_mc"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_udp_multicast
+ celix_pubsub_poi_subscriber
+ )
+
+if (ETCD_CMD AND XTERM_CMD)
+ #Runtime starting a publish and subscriber for udp mc
+ add_runtime(pubsub_rt_upd_mc
+ NAME udp_mc
+ GROUP pubsub
+ DEPLOYMENTS
+ pubsub_publisher_udp_mc
+ pubsub_subscriber_udp_mc
+ pubsub_subscriber2_udp_mc
+ COMMANDS
+ etcd
+ USE_TERM
+ )
+endif ()
+
+if (BUILD_PUBSUB_PSA_ZMQ)
+
+ # Dynamic ZMQ / UDP admin
- add_deploy("pubsub_publisher"
++ add_celix_container("pubsub_publisher"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_zmq
+ Celix::pubsub_admin_udp_multicast
+ celix_pubsub_poi_publisher
+ celix_pubsub_poi_publisher2
+ PROPERTIES
+ poi1.psa=zmq
+ poi2.psa=udp
+ )
+
- add_deploy("pubsub_subscriber"
++ add_celix_container("pubsub_subscriber"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_zmq
+ Celix::pubsub_admin_udp_multicast
+ celix_pubsub_poi_subscriber
+ PROPERTIES
+ poi1.psa=zmq
+ poi2.psa=udp
+ )
+
+ # ZMQ
- add_deploy("pubsub_zmq"
++ add_celix_container("pubsub_zmq"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
- org.apache.celix.pubsub_admin.PubSubAdminZmq
++ Celix::pubsub_admin_zmq
+ celix_pubsub_poi_publisher
+ celix_pubsub_poi_subscriber
+ )
+
- add_deploy("pubsub_publisher_zmq"
++ add_celix_container("pubsub_publisher_zmq"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_zmq
+ celix_pubsub_poi_publisher
+ celix_pubsub_poi_publisher2
+ PROPERTIES
+ pubsub.scope=my_small_scope
+ )
+
- add_deploy("pubsub_subscriber_zmq"
++ add_celix_container("pubsub_subscriber_zmq"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
- org.apache.celix.pubsub_admin.PubSubAdminZmq
++ Celix::pubsub_admin_zmq
+ celix_pubsub_poi_subscriber
+ )
+
- add_deploy("pubsub_subscriber2_zmq"
++ add_celix_container("pubsub_subscriber2_zmq"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_zmq
+ celix_pubsub_poi_subscriber
+
+ )
+
+ # ZMQ Multipart
- add_deploy("pubsub_mp_subscriber_zmq"
++ add_celix_container("pubsub_mp_subscriber_zmq"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_zmq
+ org.apache.celix.pubsub_subscriber.MpSubscriber
+ )
+
- add_deploy("pubsub_mp_publisher_zmq"
++ add_celix_container("pubsub_mp_publisher_zmq"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_zmq
+ org.apache.celix.pubsub_publisher.MpPublisher
+ )
+
+ if (ETCD_CMD AND XTERM_CMD)
+ #Runtime starting two bundles using both zmq and upd mc pubsub
+ add_runtime(pubsub_rt_zmq_udpmc_combi
+ NAME combi
+ GROUP pubsub
+ DEPLOYMENTS
+ pubsub_publisher_zmq
+ pubsub_subscriber_zmq
+ pubsub_subscriber_zmq
+ COMMANDS
+ etcd
+ USE_TERM
+ )
+
+ #Runtime starting a publish and 2 subscribers for zmq
+ add_runtime(pubsub_rt_zmq
+ NAME zmq
+ GROUP pubsub
+ DEPLOYMENTS
+ pubsub_publisher
+ pubsub_subscriber_zmq
+ pubsub_subscriber2_zmq
+ COMMANDS
+ etcd
+ USE_TERM
+ )
+
+ #Runtime starting a multipart (multiple message in one send) publish and subscriber for zmq
+ add_runtime(pubsub_rt_multipart_zmq
+ NAME zmq_multipart
+ GROUP pubsub
+ DEPLOYMENTS
+ pubsub_mp_subscriber_zmq
+ pubsub_mp_publisher_zmq
+ COMMANDS
+ etcd
+ USE_TERM
+ )
+ endif ()
+
+endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/examples/mp_pubsub/publisher/CMakeLists.txt
----------------------------------------------------------------------
diff --cc pubsub/examples/mp_pubsub/publisher/CMakeLists.txt
index e837d7f,fef69e4..653387e
--- a/pubsub/examples/mp_pubsub/publisher/CMakeLists.txt
+++ b/pubsub/examples/mp_pubsub/publisher/CMakeLists.txt
@@@ -15,17 -15,22 +15,17 @@@
# specific language governing permissions and limitations
# under the License.
- add_bundle(org.apache.celix.pubsub_publisher.MpPublisher
-include_directories("private/include")
-include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/examples/mp_pubsub/common/include")
-
+ add_celix_bundle(org.apache.celix.pubsub_publisher.MpPublisher
SYMBOLIC_NAME "apache_celix_pubsub_mp_publisher"
VERSION "1.0.0"
SOURCES
private/src/mp_pub_activator.c
private/src/mp_publisher.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
)
+target_link_libraries(org.apache.celix.pubsub_publisher.MpPublisher PRIVATE Celix::framework Celix::pubsub_api)
+target_include_directories(org.apache.celix.pubsub_publisher.MpPublisher PRIVATE private/include)
- bundle_files(org.apache.celix.pubsub_publisher.MpPublisher
+ celix_bundle_files(org.apache.celix.pubsub_publisher.MpPublisher
${PROJECT_SOURCE_DIR}/pubsub/examples/mp_pubsub/msg_descriptors/msg_ew.descriptor
${PROJECT_SOURCE_DIR}/pubsub/examples/mp_pubsub/msg_descriptors/msg_ide.descriptor
${PROJECT_SOURCE_DIR}/pubsub/examples/mp_pubsub/msg_descriptors/msg_kinematics.descriptor
[12/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/src/civetweb.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/src/civetweb.c b/remote_services/discovery_common/src/civetweb.c
new file mode 100644
index 0000000..a6093b7
--- /dev/null
+++ b/remote_services/discovery_common/src/civetweb.c
@@ -0,0 +1,7907 @@
+ /* Copyright (c) 2013-2015 the Civetweb developers
+ * Copyright (c) 2004-2013 Sergey Lyubka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#if defined(_WIN32)
+#if !defined(_CRT_SECURE_NO_WARNINGS)
+#define _CRT_SECURE_NO_WARNINGS /* Disable deprecation warning in VS2005 */
+#endif
+#else
+#ifdef __linux__
+#define _XOPEN_SOURCE 600 /* For flockfile() on Linux */
+#endif
+#ifndef _LARGEFILE_SOURCE
+#define _LARGEFILE_SOURCE /* For fseeko(), ftello() */
+#endif
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64 /* Use 64-bit file offsets by default */
+#endif
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS /* <inttypes.h> wants this for C++ */
+#endif
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS /* C++ wants that for INT64_MAX */
+#endif
+#endif
+
+#if defined (_MSC_VER)
+/* 'type cast' : conversion from 'int' to 'HANDLE' of greater size */
+#pragma warning (disable : 4306 )
+/* conditional expression is constant: introduced by FD_SET(..) */
+#pragma warning (disable : 4127)
+/* non-constant aggregate initializer: issued due to missing C99 support */
+#pragma warning (disable : 4204)
+#endif
+
+/* Disable WIN32_LEAN_AND_MEAN.
+ This makes windows.h always include winsock2.h */
+#if defined(WIN32_LEAN_AND_MEAN)
+#undef WIN32_LEAN_AND_MEAN
+#endif
+
+#if defined USE_IPV6 && defined(_WIN32)
+#include <ws2tcpip.h>
+#endif
+
+#if defined(__SYMBIAN32__)
+#define NO_SSL /* SSL is not supported */
+#define NO_CGI /* CGI is not supported */
+#define PATH_MAX FILENAME_MAX
+#endif /* __SYMBIAN32__ */
+
+#ifndef IGNORE_UNUSED_RESULT
+#define IGNORE_UNUSED_RESULT(a) (void)((a) && 1)
+#endif
+
+#ifndef _WIN32_WCE /* Some ANSI #includes are not available on Windows CE */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <signal.h>
+#include <fcntl.h>
+#endif /* !_WIN32_WCE */
+
+#include <time.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <string.h>
+#include <ctype.h>
+#include <limits.h>
+#include <stddef.h>
+#include <stdio.h>
+
+#ifndef MAX_WORKER_THREADS
+#define MAX_WORKER_THREADS (1024*64)
+#endif
+
+#if defined(_WIN32) && !defined(__SYMBIAN32__) /* Windows specific */
+#if defined(_MSC_VER) && _MSC_VER <= 1400
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x0400 /* To make it link in VS2005 */
+#endif
+#include <windows.h>
+typedef const char * SOCK_OPT_TYPE;
+
+#ifndef PATH_MAX
+#define PATH_MAX MAX_PATH
+#endif
+
+#ifndef _IN_PORT_T
+#ifndef in_port_t
+#define in_port_t u_short
+#endif
+#endif
+
+#ifndef _WIN32_WCE
+#include <process.h>
+#include <direct.h>
+#include <io.h>
+#else /* _WIN32_WCE */
+#define NO_CGI /* WinCE has no pipes */
+
+typedef long off_t;
+
+#define errno GetLastError()
+#define strerror(x) _ultoa(x, (char *) _alloca(sizeof(x) *3 ), 10)
+#endif /* _WIN32_WCE */
+
+#define MAKEUQUAD(lo, hi) ((uint64_t)(((uint32_t)(lo)) | \
+ ((uint64_t)((uint32_t)(hi))) << 32))
+#define RATE_DIFF 10000000 /* 100 nsecs */
+#define EPOCH_DIFF MAKEUQUAD(0xd53e8000, 0x019db1de)
+#define SYS2UNIX_TIME(lo, hi) \
+ (time_t) ((MAKEUQUAD((lo), (hi)) - EPOCH_DIFF) / RATE_DIFF)
+
+/* Visual Studio 6 does not know __func__ or __FUNCTION__
+ The rest of MS compilers use __FUNCTION__, not C99 __func__
+ Also use _strtoui64 on modern M$ compilers */
+#if defined(_MSC_VER) && _MSC_VER < 1300
+#define STRX(x) #x
+#define STR(x) STRX(x)
+#define __func__ __FILE__ ":" STR(__LINE__)
+#define strtoull(x, y, z) (unsigned __int64) _atoi64(x)
+#define strtoll(x, y, z) _atoi64(x)
+#else
+#define __func__ __FUNCTION__
+#define strtoull(x, y, z) _strtoui64(x, y, z)
+#define strtoll(x, y, z) _strtoi64(x, y, z)
+#endif /* _MSC_VER */
+
+#define ERRNO GetLastError()
+#define NO_SOCKLEN_T
+#define SSL_LIB "ssleay32.dll"
+#define CRYPTO_LIB "libeay32.dll"
+#define O_NONBLOCK 0
+#define W_OK (2) /* http://msdn.microsoft.com/en-us/library/1w06ktdy.aspx */
+#if !defined(EWOULDBLOCK)
+#define EWOULDBLOCK WSAEWOULDBLOCK
+#endif /* !EWOULDBLOCK */
+#define _POSIX_
+#define INT64_FMT "I64d"
+
+#define WINCDECL __cdecl
+#define SHUT_WR 1
+#define snprintf _snprintf
+#define vsnprintf _vsnprintf
+#define access _access
+#define mg_sleep(x) Sleep(x)
+
+#define pipe(x) _pipe(x, MG_BUF_LEN, _O_BINARY)
+#ifndef popen
+#define popen(x, y) _popen(x, y)
+#endif
+#ifndef pclose
+#define pclose(x) _pclose(x)
+#endif
+#define close(x) _close(x)
+#define dlsym(x,y) GetProcAddress((HINSTANCE) (x), (y))
+#define RTLD_LAZY 0
+#define fseeko(x, y, z) _lseeki64(_fileno(x), (y), (z))
+#define fdopen(x, y) _fdopen((x), (y))
+#define write(x, y, z) _write((x), (y), (unsigned) z)
+#define read(x, y, z) _read((x), (y), (unsigned) z)
+#define flockfile(x) EnterCriticalSection(&global_log_file_lock)
+#define funlockfile(x) LeaveCriticalSection(&global_log_file_lock)
+#define sleep(x) Sleep((x) * 1000)
+#define rmdir(x) _rmdir(x)
+
+#if defined(USE_LUA) && defined(USE_WEBSOCKET)
+#define USE_TIMERS
+#endif
+
+#if !defined(va_copy)
+#define va_copy(x, y) x = y
+#endif /* !va_copy MINGW #defines va_copy */
+
+#if !defined(fileno)
+#define fileno(x) _fileno(x)
+#endif /* !fileno MINGW #defines fileno */
+
+typedef HANDLE pthread_mutex_t;
+typedef DWORD pthread_key_t;
+typedef HANDLE pthread_t;
+typedef struct {
+ CRITICAL_SECTION threadIdSec;
+ int waitingthreadcount; /* The number of threads queued. */
+ pthread_t *waitingthreadhdls; /* The thread handles. */
+} pthread_cond_t;
+
+#ifndef __clockid_t_defined
+typedef DWORD clockid_t;
+#endif
+#ifndef CLOCK_MONOTONIC
+#define CLOCK_MONOTONIC (1)
+#endif
+#ifndef CLOCK_REALTIME
+#define CLOCK_REALTIME (2)
+#endif
+
+#ifndef _TIMESPEC_DEFINED
+struct timespec {
+ time_t tv_sec; /* seconds */
+ long tv_nsec; /* nanoseconds */
+};
+#endif
+
+#define pid_t HANDLE /* MINGW typedefs pid_t to int. Using #define here. */
+
+static int pthread_mutex_lock(pthread_mutex_t *);
+static int pthread_mutex_unlock(pthread_mutex_t *);
+static void to_unicode(const char *path, wchar_t *wbuf, size_t wbuf_len);
+struct file;
+static char *mg_fgets(char *buf, size_t size, struct file *filep, char **p);
+
+#if defined(HAVE_STDINT)
+#include <stdint.h>
+#else
+typedef unsigned int uint32_t;
+typedef unsigned short uint16_t;
+typedef unsigned __int64 uint64_t;
+typedef __int64 int64_t;
+#define INT64_MAX 9223372036854775807
+#endif /* HAVE_STDINT */
+
+/* POSIX dirent interface */
+struct dirent {
+ char d_name[PATH_MAX];
+};
+
+typedef struct DIR {
+ HANDLE handle;
+ WIN32_FIND_DATAW info;
+ struct dirent result;
+} DIR;
+
+#if !defined(USE_IPV6) && defined(_WIN32)
+#ifndef HAVE_POLL
+struct pollfd {
+ SOCKET fd;
+ short events;
+ short revents;
+};
+#define POLLIN 1
+#endif
+#endif
+
+/* Mark required libraries */
+#ifdef _MSC_VER
+#pragma comment(lib, "Ws2_32.lib")
+#endif
+
+#else /* UNIX specific */
+#include <sys/wait.h>
+#include <sys/socket.h>
+#include <sys/poll.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/time.h>
+#include <sys/utsname.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <netdb.h>
+typedef const void * SOCK_OPT_TYPE;
+
+//#if defined(ANDROID)
+typedef unsigned short int in_port_t;
+//#endif
+
+#include <pwd.h>
+#include <unistd.h>
+#include <dirent.h>
+#if !defined(NO_SSL_DL) && !defined(NO_SSL)
+#include <dlfcn.h>
+#endif
+#include <pthread.h>
+#if defined(__MACH__)
+#define SSL_LIB "libssl.dylib"
+#define CRYPTO_LIB "libcrypto.dylib"
+#else
+#if !defined(SSL_LIB)
+#define SSL_LIB "libssl.so"
+#endif
+#if !defined(CRYPTO_LIB)
+#define CRYPTO_LIB "libcrypto.so"
+#endif
+#endif
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif /* O_BINARY */
+#define closesocket(a) close(a)
+#define mg_mkdir(x, y) mkdir(x, y)
+#define mg_remove(x) remove(x)
+#define mg_sleep(x) usleep((x) * 1000)
+#define ERRNO errno
+#define INVALID_SOCKET (-1)
+#define INT64_FMT PRId64
+typedef int SOCKET;
+#define WINCDECL
+
+#endif /* End of Windows and UNIX specific includes */
+
+#ifdef _WIN32
+static CRITICAL_SECTION global_log_file_lock;
+static DWORD pthread_self(void)
+{
+ return GetCurrentThreadId();
+}
+
+int pthread_key_create(pthread_key_t *key, void (*_must_be_zero)(void*) /* destructor function not supported for windows */)
+{
+ assert(_must_be_zero == NULL);
+ if ((key!=0) && (_must_be_zero == NULL)) {
+ *key = TlsAlloc();
+ return (*key != TLS_OUT_OF_INDEXES) ? 0 : -1;
+ }
+ return -2;
+}
+
+int pthread_key_delete(pthread_key_t key)
+{
+ return TlsFree(key) ? 0 : 1;
+}
+
+int pthread_setspecific(pthread_key_t key, void * value)
+{
+ return TlsSetValue(key, value) ? 0 : 1;
+}
+
+void *pthread_getspecific(pthread_key_t key)
+{
+ return TlsGetValue(key);
+}
+#endif /* _WIN32 */
+
+
+#include "civetweb.h"
+
+#define PASSWORDS_FILE_NAME ".htpasswd"
+#define CGI_ENVIRONMENT_SIZE 4096
+#define MAX_CGI_ENVIR_VARS 64
+#define MG_BUF_LEN 8192
+#ifndef MAX_REQUEST_SIZE
+#define MAX_REQUEST_SIZE 16384
+#endif
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
+
+#if !defined(DEBUG_TRACE)
+#if defined(CWDEBUG)
+
+static void DEBUG_TRACE_FUNC(const char *func, unsigned line, PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(3, 4);
+
+static void DEBUG_TRACE_FUNC(const char *func, unsigned line, const char *fmt, ...) {
+
+ va_list args;
+ flockfile(stdout);
+ printf("*** %lu.%p.%s.%u: ",
+ (unsigned long) time(NULL), (void *) pthread_self(),
+ func, line);
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+ putchar('\n');
+ fflush(stdout);
+ funlockfile(stdout);
+}
+
+#define DEBUG_TRACE(fmt, ...) DEBUG_TRACE_FUNC(__func__, __LINE__, fmt, __VA_ARGS__)
+
+#else
+#define DEBUG_TRACE(fmt, ...)
+#endif /* CWDEBUG */
+#endif /* DEBUG_TRACE */
+
+#if defined(MEMORY_DEBUGGING)
+static unsigned long blockCount = 0;
+static unsigned long totalMemUsed = 0;
+
+static void * mg_malloc_ex(size_t size, const char * file, unsigned line) {
+
+ void * data = malloc(size + sizeof(size_t));
+ void * memory = 0;
+ char mallocStr[256];
+
+ if (data) {
+ *(size_t*)data = size;
+ totalMemUsed += size;
+ blockCount++;
+ memory = (void *)(((char*)data)+sizeof(size_t));
+ }
+
+ sprintf(mallocStr, "MEM: %p %5lu alloc %7lu %4lu --- %s:%u\n", memory, (unsigned long)size, totalMemUsed, blockCount, file, line);
+#if defined(_WIN32)
+ OutputDebugStringA(mallocStr);
+#else
+ DEBUG_TRACE("%s", mallocStr);
+#endif
+
+ return memory;
+}
+
+static void * mg_calloc_ex(size_t count, size_t size, const char * file, unsigned line) {
+
+ void * data = mg_malloc_ex(size*count, file, line);
+ if (data) memset(data, 0, size);
+
+ return data;
+}
+
+static void mg_free_ex(void * memory, const char * file, unsigned line) {
+
+ char mallocStr[256];
+ void * data = (void *)(((char*)memory)-sizeof(size_t));
+ size_t size;
+
+ if (memory) {
+ size = *(size_t*)data;
+ totalMemUsed -= size;
+ blockCount--;
+ sprintf(mallocStr, "MEM: %p %5lu free %7lu %4lu --- %s:%u\n", memory, (unsigned long)size, totalMemUsed, blockCount, file, line);
+#if defined(_WIN32)
+ OutputDebugStringA(mallocStr);
+#else
+ DEBUG_TRACE("%s", mallocStr);
+#endif
+
+ free(data);
+ }
+}
+
+static void * mg_realloc_ex(void * memory, size_t newsize, const char * file, unsigned line) {
+
+ char mallocStr[256];
+ void * data;
+ void * _realloc;
+ size_t oldsize;
+
+ if (newsize) {
+ if (memory) {
+ data = (void *)(((char*)memory)-sizeof(size_t));
+ oldsize = *(size_t*)data;
+ _realloc = realloc(data, newsize+sizeof(size_t));
+ if (_realloc) {
+ data = _realloc;
+ totalMemUsed -= oldsize;
+ sprintf(mallocStr, "MEM: %p %5lu r-free %7lu %4lu --- %s:%u\n", memory, (unsigned long)oldsize, totalMemUsed, blockCount, file, line);
+#if defined(_WIN32)
+ OutputDebugStringA(mallocStr);
+#else
+ DEBUG_TRACE("%s", mallocStr);
+#endif
+ totalMemUsed += newsize;
+ sprintf(mallocStr, "MEM: %p %5lu r-alloc %7lu %4lu --- %s:%u\n", memory, (unsigned long)newsize, totalMemUsed, blockCount, file, line);
+#if defined(_WIN32)
+ OutputDebugStringA(mallocStr);
+#else
+ DEBUG_TRACE("%s", mallocStr);
+#endif
+ *(size_t*)data = newsize;
+ data = (void *)(((char*)data)+sizeof(size_t));
+ } else {
+#if defined(_WIN32)
+ OutputDebugStringA("MEM: realloc failed\n");
+#else
+ DEBUG_TRACE("%s", "MEM: realloc failed\n");
+#endif
+ return _realloc;
+ }
+ } else {
+ data = mg_malloc_ex(newsize, file, line);
+ }
+ } else {
+ data = 0;
+ mg_free_ex(memory, file, line);
+ }
+
+ return data;
+}
+
+#define mg_malloc(a) mg_malloc_ex(a, __FILE__, __LINE__)
+#define mg_calloc(a,b) mg_calloc_ex(a, b, __FILE__, __LINE__)
+#define mg_realloc(a, b) mg_realloc_ex(a, b, __FILE__, __LINE__)
+#define mg_free(a) mg_free_ex(a, __FILE__, __LINE__)
+
+#else
+static __inline void * mg_malloc(size_t a) {return malloc(a);}
+static __inline void * mg_calloc(size_t a, size_t b) {return calloc(a, b);}
+static __inline void * mg_realloc(void * a, size_t b) {return realloc(a, b);}
+static __inline void mg_free(void * a) {free(a);}
+#endif
+
+/* This following lines are just meant as a reminder to use the mg-functions for memory management */
+#ifdef malloc
+ #undef malloc
+#endif
+#ifdef calloc
+ #undef calloc
+#endif
+#ifdef realloc
+ #undef realloc
+#endif
+#ifdef free
+ #undef free
+#endif
+#define malloc DO_NOT_USE_THIS_FUNCTION__USE_mg_malloc
+#define calloc DO_NOT_USE_THIS_FUNCTION__USE_mg_calloc
+#define realloc DO_NOT_USE_THIS_FUNCTION__USE_mg_realloc
+#define free DO_NOT_USE_THIS_FUNCTION__USE_mg_free
+
+
+#define MD5_STATIC static
+#include "md5.inl"
+
+/* Darwin prior to 7.0 and Win32 do not have socklen_t */
+#ifdef NO_SOCKLEN_T
+typedef int socklen_t;
+#endif /* NO_SOCKLEN_T */
+#define _DARWIN_UNLIMITED_SELECT
+
+#define IP_ADDR_STR_LEN 50 /* IPv6 hex string is 46 chars */
+
+#if !defined(MSG_NOSIGNAL)
+#define MSG_NOSIGNAL 0
+#endif
+
+#if !defined(SOMAXCONN)
+#define SOMAXCONN 100
+#endif
+
+#if !defined(PATH_MAX)
+#define PATH_MAX 4096
+#endif
+
+/* Size of the accepted socket queue */
+#if !defined(MGSQLEN)
+#define MGSQLEN 20
+#endif
+
+#if defined(NO_SSL_DL)
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+#else
+/* SSL loaded dynamically from DLL.
+ I put the prototypes here to be independent from OpenSSL source
+ installation. */
+
+typedef struct ssl_st SSL;
+typedef struct ssl_method_st SSL_METHOD;
+typedef struct ssl_ctx_st SSL_CTX;
+
+struct ssl_func {
+ const char *name; /* SSL function name */
+ void (*ptr)(void); /* Function pointer */
+};
+
+#define SSL_free (* (void (*)(SSL *)) ssl_sw[0].ptr)
+#define SSL_accept (* (int (*)(SSL *)) ssl_sw[1].ptr)
+#define SSL_connect (* (int (*)(SSL *)) ssl_sw[2].ptr)
+#define SSL_read (* (int (*)(SSL *, void *, int)) ssl_sw[3].ptr)
+#define SSL_write (* (int (*)(SSL *, const void *,int)) ssl_sw[4].ptr)
+#define SSL_get_error (* (int (*)(SSL *, int)) ssl_sw[5].ptr)
+#define SSL_set_fd (* (int (*)(SSL *, SOCKET)) ssl_sw[6].ptr)
+#define SSL_new (* (SSL * (*)(SSL_CTX *)) ssl_sw[7].ptr)
+#define SSL_CTX_new (* (SSL_CTX * (*)(SSL_METHOD *)) ssl_sw[8].ptr)
+#define SSLv23_server_method (* (SSL_METHOD * (*)(void)) ssl_sw[9].ptr)
+#define SSL_library_init (* (int (*)(void)) ssl_sw[10].ptr)
+#define SSL_CTX_use_PrivateKey_file (* (int (*)(SSL_CTX *, \
+ const char *, int)) ssl_sw[11].ptr)
+#define SSL_CTX_use_certificate_file (* (int (*)(SSL_CTX *, \
+ const char *, int)) ssl_sw[12].ptr)
+#define SSL_CTX_set_default_passwd_cb \
+ (* (void (*)(SSL_CTX *, mg_callback_t)) ssl_sw[13].ptr)
+#define SSL_CTX_free (* (void (*)(SSL_CTX *)) ssl_sw[14].ptr)
+#define SSL_load_error_strings (* (void (*)(void)) ssl_sw[15].ptr)
+#define SSL_CTX_use_certificate_chain_file \
+ (* (int (*)(SSL_CTX *, const char *)) ssl_sw[16].ptr)
+#define SSLv23_client_method (* (SSL_METHOD * (*)(void)) ssl_sw[17].ptr)
+#define SSL_pending (* (int (*)(SSL *)) ssl_sw[18].ptr)
+#define SSL_CTX_set_verify (* (void (*)(SSL_CTX *, int, int)) ssl_sw[19].ptr)
+#define SSL_shutdown (* (int (*)(SSL *)) ssl_sw[20].ptr)
+
+#define CRYPTO_num_locks (* (int (*)(void)) crypto_sw[0].ptr)
+#define CRYPTO_set_locking_callback \
+ (* (void (*)(void (*)(int, int, const char *, int))) crypto_sw[1].ptr)
+#define CRYPTO_set_id_callback \
+ (* (void (*)(unsigned long (*)(void))) crypto_sw[2].ptr)
+#define ERR_get_error (* (unsigned long (*)(void)) crypto_sw[3].ptr)
+#define ERR_error_string (* (char * (*)(unsigned long,char *)) crypto_sw[4].ptr)
+
+/* set_ssl_option() function updates this array.
+ It loads SSL library dynamically and changes NULLs to the actual addresses
+ of respective functions. The macros above (like SSL_connect()) are really
+ just calling these functions indirectly via the pointer. */
+static struct ssl_func ssl_sw[] = {
+ {"SSL_free", NULL},
+ {"SSL_accept", NULL},
+ {"SSL_connect", NULL},
+ {"SSL_read", NULL},
+ {"SSL_write", NULL},
+ {"SSL_get_error", NULL},
+ {"SSL_set_fd", NULL},
+ {"SSL_new", NULL},
+ {"SSL_CTX_new", NULL},
+ {"SSLv23_server_method", NULL},
+ {"SSL_library_init", NULL},
+ {"SSL_CTX_use_PrivateKey_file", NULL},
+ {"SSL_CTX_use_certificate_file",NULL},
+ {"SSL_CTX_set_default_passwd_cb",NULL},
+ {"SSL_CTX_free", NULL},
+ {"SSL_load_error_strings", NULL},
+ {"SSL_CTX_use_certificate_chain_file", NULL},
+ {"SSLv23_client_method", NULL},
+ {"SSL_pending", NULL},
+ {"SSL_CTX_set_verify", NULL},
+ {"SSL_shutdown", NULL},
+ {NULL, NULL}
+};
+
+/* Similar array as ssl_sw. These functions could be located in different
+ lib. */
+#if !defined(NO_SSL)
+static struct ssl_func crypto_sw[] = {
+ {"CRYPTO_num_locks", NULL},
+ {"CRYPTO_set_locking_callback", NULL},
+ {"CRYPTO_set_id_callback", NULL},
+ {"ERR_get_error", NULL},
+ {"ERR_error_string", NULL},
+ {NULL, NULL}
+};
+#endif /* NO_SSL */
+#endif /* NO_SSL_DL */
+
+static const char *month_names[] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+
+/* Unified socket address. For IPv6 support, add IPv6 address structure
+ in the union u. */
+union usa {
+ struct sockaddr sa;
+ struct sockaddr_in sin;
+#if defined(USE_IPV6)
+ struct sockaddr_in6 sin6;
+#endif
+};
+
+/* Describes a string (chunk of memory). */
+struct vec {
+ const char *ptr;
+ size_t len;
+};
+
+struct file {
+ int is_directory;
+ time_t modification_time;
+ int64_t size;
+ FILE *fp;
+ const char *membuf; /* Non-NULL if file data is in memory */
+ /* set to 1 if the content is gzipped
+ in which case we need a content-encoding: gzip header */
+ int gzipped;
+};
+#define STRUCT_FILE_INITIALIZER {0, 0, 0, NULL, NULL, 0}
+
+/* Describes listening socket, or socket which was accept()-ed by the master
+ thread and queued for future handling by the worker thread. */
+struct socket {
+ SOCKET sock; /* Listening socket */
+ union usa lsa; /* Local socket address */
+ union usa rsa; /* Remote socket address */
+ unsigned is_ssl:1; /* Is port SSL-ed */
+ unsigned ssl_redir:1; /* Is port supposed to redirect everything to SSL
+ port */
+};
+
+/* NOTE(lsm): this enum shoulds be in sync with the config_options below. */
+enum {
+ CGI_EXTENSIONS, CGI_ENVIRONMENT, PUT_DELETE_PASSWORDS_FILE, CGI_INTERPRETER,
+ PROTECT_URI, AUTHENTICATION_DOMAIN, SSI_EXTENSIONS, THROTTLE,
+ ACCESS_LOG_FILE, ENABLE_DIRECTORY_LISTING, ERROR_LOG_FILE,
+ GLOBAL_PASSWORDS_FILE, INDEX_FILES, ENABLE_KEEP_ALIVE, ACCESS_CONTROL_LIST,
+ EXTRA_MIME_TYPES, LISTENING_PORTS, DOCUMENT_ROOT, SSL_CERTIFICATE,
+ NUM_THREADS, RUN_AS_USER, REWRITE, HIDE_FILES, REQUEST_TIMEOUT,
+ DECODE_URL,
+
+#if defined(USE_LUA)
+ LUA_PRELOAD_FILE, LUA_SCRIPT_EXTENSIONS, LUA_SERVER_PAGE_EXTENSIONS,
+#endif
+#if defined(USE_WEBSOCKET)
+ WEBSOCKET_ROOT,
+#endif
+#if defined(USE_LUA) && defined(USE_WEBSOCKET)
+ LUA_WEBSOCKET_EXTENSIONS,
+#endif
+ ACCESS_CONTROL_ALLOW_ORIGIN, ERROR_PAGES,
+
+ NUM_OPTIONS
+};
+
+/* Config option name, config types, default value */
+static struct mg_option config_options[] = {
+ {"cgi_pattern", CONFIG_TYPE_EXT_PATTERN, "**.cgi$|**.pl$|**.php$"},
+ {"cgi_environment", CONFIG_TYPE_STRING, NULL},
+ {"put_delete_auth_file", CONFIG_TYPE_FILE, NULL},
+ {"cgi_interpreter", CONFIG_TYPE_FILE, NULL},
+ {"protect_uri", CONFIG_TYPE_STRING, NULL},
+ {"authentication_domain", CONFIG_TYPE_STRING, "mydomain.com"},
+ {"ssi_pattern", CONFIG_TYPE_EXT_PATTERN, "**.shtml$|**.shtm$"},
+ {"throttle", CONFIG_TYPE_STRING, NULL},
+ {"access_log_file", CONFIG_TYPE_FILE, NULL},
+ {"enable_directory_listing", CONFIG_TYPE_BOOLEAN, "yes"},
+ {"error_log_file", CONFIG_TYPE_FILE, NULL},
+ {"global_auth_file", CONFIG_TYPE_FILE, NULL},
+ {"index_files", CONFIG_TYPE_STRING,
+#ifdef USE_LUA
+ "index.xhtml,index.html,index.htm,index.lp,index.lsp,index.lua,index.cgi,index.shtml,index.php"},
+#else
+ "index.xhtml,index.html,index.htm,index.cgi,index.shtml,index.php"},
+#endif
+ {"enable_keep_alive", CONFIG_TYPE_BOOLEAN, "no"},
+ {"access_control_list", CONFIG_TYPE_STRING, NULL},
+ {"extra_mime_types", CONFIG_TYPE_STRING, NULL},
+ {"listening_ports", CONFIG_TYPE_STRING, "8080"},
+ {"document_root", CONFIG_TYPE_DIRECTORY, NULL},
+ {"ssl_certificate", CONFIG_TYPE_FILE, NULL},
+ {"num_threads", CONFIG_TYPE_NUMBER, "50"},
+ {"run_as_user", CONFIG_TYPE_STRING, NULL},
+ {"url_rewrite_patterns", CONFIG_TYPE_STRING, NULL},
+ {"hide_files_patterns", CONFIG_TYPE_EXT_PATTERN, NULL},
+ {"request_timeout_ms", CONFIG_TYPE_NUMBER, "30000"},
+ {"decode_url", CONFIG_TYPE_BOOLEAN, "yes"},
+
+#if defined(USE_LUA)
+ {"lua_preload_file", CONFIG_TYPE_FILE, NULL},
+ {"lua_script_pattern", CONFIG_TYPE_EXT_PATTERN, "**.lua$"},
+ {"lua_server_page_pattern", CONFIG_TYPE_EXT_PATTERN, "**.lp$|**.lsp$"},
+#endif
+#if defined(USE_WEBSOCKET)
+ {"websocket_root", CONFIG_TYPE_DIRECTORY, NULL},
+#endif
+#if defined(USE_LUA) && defined(USE_WEBSOCKET)
+ {"lua_websocket_pattern", CONFIG_TYPE_EXT_PATTERN, "**.lua$"},
+#endif
+ {"access_control_allow_origin", CONFIG_TYPE_STRING, "*"},
+ {"error_pages", CONFIG_TYPE_DIRECTORY, NULL},
+
+ {NULL, CONFIG_TYPE_UNKNOWN, NULL}
+};
+
+struct mg_request_handler_info {
+ char *uri;
+ size_t uri_len;
+ mg_request_handler handler;
+
+ void *cbdata;
+ struct mg_request_handler_info *next;
+};
+
+struct mg_context {
+ volatile int stop_flag; /* Should we stop event loop */
+ SSL_CTX *ssl_ctx; /* SSL context */
+ char *config[NUM_OPTIONS]; /* Civetweb configuration parameters */
+ struct mg_callbacks callbacks; /* User-defined callback function */
+ void *user_data; /* User-defined data */
+ int context_type; /* 1 = server context, 2 = client context */
+
+ struct socket *listening_sockets;
+ in_port_t *listening_ports;
+ int num_listening_sockets;
+
+ volatile int num_threads; /* Number of threads */
+ pthread_mutex_t thread_mutex; /* Protects (max|num)_threads */
+ pthread_cond_t thread_cond; /* Condvar for tracking workers terminations */
+
+ struct socket queue[MGSQLEN]; /* Accepted sockets */
+ volatile int sq_head; /* Head of the socket queue */
+ volatile int sq_tail; /* Tail of the socket queue */
+ pthread_cond_t sq_full; /* Signaled when socket is produced */
+ pthread_cond_t sq_empty; /* Signaled when socket is consumed */
+ pthread_t masterthreadid; /* The master thread ID */
+ int workerthreadcount; /* The amount of worker threads. */
+ pthread_t *workerthreadids; /* The worker thread IDs */
+
+ unsigned long start_time; /* Server start time, used for authentication */
+ pthread_mutex_t nonce_mutex; /* Protects nonce_count */
+ unsigned long nonce_count; /* Used nonces, used for authentication */
+
+ char *systemName; /* What operating system is running */
+
+ /* linked list of uri handlers */
+ struct mg_request_handler_info *request_handlers;
+
+#if defined(USE_LUA) && defined(USE_WEBSOCKET)
+ /* linked list of shared lua websockets */
+ struct mg_shared_lua_websocket_list *shared_lua_websockets;
+#endif
+
+#ifdef USE_TIMERS
+ struct ttimers * timers;
+#endif
+};
+
+struct mg_connection {
+ struct mg_request_info request_info;
+ struct mg_context *ctx;
+ SSL *ssl; /* SSL descriptor */
+ SSL_CTX *client_ssl_ctx; /* SSL context for client connections */
+ struct socket client; /* Connected client */
+ time_t birth_time; /* Time when request was received */
+ int64_t num_bytes_sent; /* Total bytes sent to client */
+ int64_t content_len; /* Content-Length header value */
+ int64_t consumed_content; /* How many bytes of content have been read */
+ char *buf; /* Buffer for received data */
+ char *path_info; /* PATH_INFO part of the URL */
+ int must_close; /* 1 if connection must be closed */
+ int in_error_handler; /* 1 if in handler for user defined error pages */
+ int buf_size; /* Buffer size */
+ int request_len; /* Size of the request + headers in a buffer */
+ int data_len; /* Total size of data in a buffer */
+ int status_code; /* HTTP reply status code, e.g. 200 */
+ int throttle; /* Throttling, bytes/sec. <= 0 means no throttle */
+ time_t last_throttle_time; /* Last time throttled data was sent */
+ int64_t last_throttle_bytes; /* Bytes sent this second */
+ pthread_mutex_t mutex; /* Used by mg_lock_connection/mg_unlock_connection to ensure atomic transmissions for websockets */
+#if defined(USE_LUA) && defined(USE_WEBSOCKET)
+ void * lua_websocket_state; /* Lua_State for a websocket connection */
+#endif
+};
+
+static pthread_key_t sTlsKey; /* Thread local storage index */
+static int sTlsInit = 0;
+
+struct mg_workerTLS {
+ int is_master;
+#if defined(_WIN32) && !defined(__SYMBIAN32__)
+ HANDLE pthread_cond_helper_mutex;
+#endif
+};
+
+/* Directory entry */
+struct de {
+ struct mg_connection *conn;
+ char *file_name;
+ struct file file;
+};
+
+#if defined(USE_WEBSOCKET)
+static int is_websocket_protocol(const struct mg_connection *conn);
+#else
+#define is_websocket_protocol(conn) (0)
+#endif
+
+int mg_atomic_inc(volatile int * addr)
+{
+ int ret;
+#if defined(_WIN32) && !defined(__SYMBIAN32__)
+ ret = InterlockedIncrement((volatile unsigned int *) addr);
+#elif defined(__GNUC__)
+ ret = __sync_add_and_fetch(addr, 1);
+#else
+ ret = (++(*addr));
+#endif
+ return ret;
+}
+
+int mg_atomic_dec(volatile int * addr)
+{
+ int ret;
+#if defined(_WIN32) && !defined(__SYMBIAN32__)
+ ret = InterlockedDecrement((volatile unsigned int *) addr);
+#elif defined(__GNUC__)
+ ret = __sync_sub_and_fetch(addr, 1);
+#else
+ ret = (--(*addr));
+#endif
+ return ret;
+}
+
+#if !defined(NO_THREAD_NAME)
+#if defined(_WIN32) && defined(_MSC_VER)
+/* Set the thread name for debugging purposes in Visual Studio
+ http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
+*/
+#pragma pack(push,8)
+typedef struct tagTHREADNAME_INFO
+{
+ DWORD dwType; /* Must be 0x1000. */
+ LPCSTR szName; /* Pointer to name (in user addr space). */
+ DWORD dwThreadID; /* Thread ID (-1=caller thread). */
+ DWORD dwFlags; /* Reserved for future use, must be zero. */
+} THREADNAME_INFO;
+#pragma pack(pop)
+#elif defined(__linux__)
+#include <sys/prctl.h>
+#endif
+
+void mg_set_thread_name(const char* name)
+{
+ char threadName[16]; /* Max. thread length in Linux/OSX/.. */
+
+ if (snprintf(threadName, sizeof(threadName), "civetweb-%s", name)<0) return;
+ threadName[sizeof(threadName)-1] = 0;
+
+#if defined(_WIN32)
+#if defined(_MSC_VER)
+ /* Windows and Visual Studio Compiler */
+ __try
+ {
+ THREADNAME_INFO info;
+ info.dwType = 0x1000;
+ info.szName = threadName;
+ info.dwThreadID = -1;
+ info.dwFlags = 0;
+
+ RaiseException(0x406D1388, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info);
+ }
+ __except(EXCEPTION_EXECUTE_HANDLER)
+ {
+ }
+#elif defined(__MINGW32__)
+ /* No option known to set thread name for MinGW */
+#endif
+#elif defined(__linux__)
+ /* Linux */
+ (void)prctl(PR_SET_NAME,threadName,0,0,0);
+#elif defined(__APPLE__) || defined(__MACH__)
+ /* OS X (TODO: test) */
+ (void)pthread_setname_np(threadName);
+#elif defined(BSD) || defined(__FreeBSD__) || defined(__OpenBSD__)
+ /* BSD (TODO: test) */
+ pthread_set_name_np(pthread_self(), threadName);
+#else
+ /* POSIX */
+ (void)pthread_setname_np(pthread_self(), threadName);
+#endif
+}
+#else /* !defined(NO_THREAD_NAME) */
+void mg_set_thread_name(const char* threadName) {}
+#endif
+
+#if defined(MG_LEGACY_INTERFACE)
+const char **mg_get_valid_option_names(void)
+{
+ static const char * data[2 * sizeof(config_options) / sizeof(config_options[0])] = {0};
+ int i;
+
+ for (i=0; config_options[i].name != NULL; i++) {
+ data[i * 2] = config_options[i].name;
+ data[i * 2 + 1] = config_options[i].default_value;
+ }
+
+ return data;
+}
+#endif
+
+const struct mg_option *mg_get_valid_options(void)
+{
+ return config_options;
+}
+
+
+static int is_file_in_memory(struct mg_connection *conn, const char *path,
+ struct file *filep)
+{
+ size_t size = 0;
+ if ((filep->membuf = conn->ctx->callbacks.open_file == NULL ? NULL :
+ conn->ctx->callbacks.open_file(conn, path, &size)) != NULL) {
+ /* NOTE: override filep->size only on success. Otherwise, it might
+ break constructs like if (!mg_stat() || !mg_fopen()) ... */
+ filep->size = size;
+ }
+ return filep->membuf != NULL;
+}
+
+static int is_file_opened(const struct file *filep)
+{
+ return filep->membuf != NULL || filep->fp != NULL;
+}
+
+static int mg_fopen(struct mg_connection *conn, const char *path,
+ const char *mode, struct file *filep)
+{
+ if (!is_file_in_memory(conn, path, filep)) {
+#ifdef _WIN32
+ wchar_t wbuf[PATH_MAX], wmode[20];
+ to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
+ MultiByteToWideChar(CP_UTF8, 0, mode, -1, wmode, ARRAY_SIZE(wmode));
+ filep->fp = _wfopen(wbuf, wmode);
+#else
+ filep->fp = fopen(path, mode);
+#endif
+ }
+
+ return is_file_opened(filep);
+}
+
+static void mg_fclose(struct file *filep)
+{
+ if (filep != NULL && filep->fp != NULL) {
+ fclose(filep->fp);
+ }
+}
+
+static void mg_strlcpy(register char *dst, register const char *src, size_t n)
+{
+ for (; *src != '\0' && n > 1; n--) {
+ *dst++ = *src++;
+ }
+ *dst = '\0';
+}
+
+static int lowercase(const char *s)
+{
+ return tolower(* (const unsigned char *) s);
+}
+
+int mg_strncasecmp(const char *s1, const char *s2, size_t len)
+{
+ int diff = 0;
+
+ if (len > 0)
+ do {
+ diff = lowercase(s1++) - lowercase(s2++);
+ } while (diff == 0 && s1[-1] != '\0' && --len > 0);
+
+ return diff;
+}
+
+static int mg_strcasecmp(const char *s1, const char *s2)
+{
+ int diff;
+
+ do {
+ diff = lowercase(s1++) - lowercase(s2++);
+ } while (diff == 0 && s1[-1] != '\0');
+
+ return diff;
+}
+
+static char * mg_strndup(const char *ptr, size_t len)
+{
+ char *p;
+
+ if ((p = (char *) mg_malloc(len + 1)) != NULL) {
+ mg_strlcpy(p, ptr, len + 1);
+ }
+
+ return p;
+}
+
+static char * mg_strdup(const char *str)
+{
+ return mg_strndup(str, strlen(str));
+}
+
+static const char *mg_strcasestr(const char *big_str, const char *small_str)
+{
+ int i, big_len = (int)strlen(big_str), small_len = (int)strlen(small_str);
+
+ for (i = 0; i <= big_len - small_len; i++) {
+ if (mg_strncasecmp(big_str + i, small_str, small_len) == 0) {
+ return big_str + i;
+ }
+ }
+
+ return NULL;
+}
+
+/* Like snprintf(), but never returns negative value, or a value
+ that is larger than a supplied buffer.
+ Thanks to Adam Zeldis to pointing snprintf()-caused vulnerability
+ in his audit report. */
+static int mg_vsnprintf(struct mg_connection *conn, char *buf, size_t buflen,
+ const char *fmt, va_list ap)
+{
+ int n;
+
+ if (buflen == 0)
+ return 0;
+
+ n = vsnprintf(buf, buflen, fmt, ap);
+
+ if (n < 0) {
+ mg_cry(conn, "vsnprintf error");
+ n = 0;
+ } else if (n >= (int) buflen) {
+ mg_cry(conn, "truncating vsnprintf buffer: [%.*s]",
+ n > 200 ? 200 : n, buf);
+ n = (int) buflen - 1;
+ }
+ buf[n] = '\0';
+
+ return n;
+}
+
+static int mg_snprintf(struct mg_connection *conn, char *buf, size_t buflen,
+ PRINTF_FORMAT_STRING(const char *fmt), ...)
+PRINTF_ARGS(4, 5);
+
+static int mg_snprintf(struct mg_connection *conn, char *buf, size_t buflen,
+ const char *fmt, ...)
+{
+ va_list ap;
+ int n;
+
+ va_start(ap, fmt);
+ n = mg_vsnprintf(conn, buf, buflen, fmt, ap);
+ va_end(ap);
+
+ return n;
+}
+
+static int get_option_index(const char *name)
+{
+ int i;
+
+ for (i = 0; config_options[i].name != NULL; i++) {
+ if (strcmp(config_options[i].name, name) == 0) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+const char *mg_get_option(const struct mg_context *ctx, const char *name)
+{
+ int i;
+ if ((i = get_option_index(name)) == -1) {
+ return NULL;
+ } else if (ctx->config[i] == NULL) {
+ return "";
+ } else {
+ return ctx->config[i];
+ }
+}
+
+struct mg_context *mg_get_context(struct mg_connection * conn)
+{
+ return (conn == NULL) ? (struct mg_context *)NULL : (conn->ctx);
+}
+
+void *mg_get_user_data(struct mg_context *ctx)
+{
+ return (ctx == NULL) ? NULL : ctx->user_data;
+}
+
+size_t mg_get_ports(const struct mg_context *ctx, size_t size, int* ports, int* ssl)
+{
+ size_t i;
+ for (i = 0; i < size && i < (size_t)ctx->num_listening_sockets; i++)
+ {
+ ssl[i] = ctx->listening_sockets[i].is_ssl;
+ ports[i] = ctx->listening_ports[i];
+ }
+ return i;
+}
+
+static void sockaddr_to_string(char *buf, size_t len,
+ const union usa *usa)
+{
+ buf[0] = '\0';
+#if defined(USE_IPV6)
+ inet_ntop(usa->sa.sa_family, usa->sa.sa_family == AF_INET ?
+ (void *) &usa->sin.sin_addr :
+ (void *) &usa->sin6.sin6_addr, buf, len);
+#elif defined(_WIN32)
+ /* Only Windows Vista (and newer) have inet_ntop() */
+ mg_strlcpy(buf, inet_ntoa(usa->sin.sin_addr), len);
+#else
+ inet_ntop(usa->sa.sa_family, (void *) &usa->sin.sin_addr, buf, len);
+#endif
+}
+
+/* Convert time_t to a string. According to RFC2616, Sec 14.18, this must be included in all responses other than 100, 101, 5xx. */
+static void gmt_time_string(char *buf, size_t buf_len, time_t *t)
+{
+ struct tm *tm;
+
+ tm = gmtime(t);
+ if (tm != NULL) {
+ strftime(buf, buf_len, "%a, %d %b %Y %H:%M:%S GMT", tm);
+ } else {
+ mg_strlcpy(buf, "Thu, 01 Jan 1970 00:00:00 GMT", buf_len);
+ buf[buf_len - 1] = '\0';
+ }
+}
+
+/* Print error message to the opened error log stream. */
+void mg_cry(struct mg_connection *conn, const char *fmt, ...)
+{
+ char buf[MG_BUF_LEN], src_addr[IP_ADDR_STR_LEN];
+ va_list ap;
+ FILE *fp;
+ time_t timestamp;
+
+ va_start(ap, fmt);
+ IGNORE_UNUSED_RESULT(vsnprintf(buf, sizeof(buf), fmt, ap));
+ va_end(ap);
+
+ /* Do not lock when getting the callback value, here and below.
+ I suppose this is fine, since function cannot disappear in the
+ same way string option can. */
+ if (conn->ctx->callbacks.log_message == NULL ||
+ conn->ctx->callbacks.log_message(conn, buf) == 0) {
+ fp = conn->ctx->config[ERROR_LOG_FILE] == NULL ? NULL :
+ fopen(conn->ctx->config[ERROR_LOG_FILE], "a+");
+
+ if (fp != NULL) {
+ flockfile(fp);
+ timestamp = time(NULL);
+
+ sockaddr_to_string(src_addr, sizeof(src_addr), &conn->client.rsa);
+ fprintf(fp, "[%010lu] [error] [client %s] ", (unsigned long) timestamp,
+ src_addr);
+
+ if (conn->request_info.request_method != NULL) {
+ fprintf(fp, "%s %s: ", conn->request_info.request_method,
+ conn->request_info.uri);
+ }
+
+ fprintf(fp, "%s", buf);
+ fputc('\n', fp);
+ funlockfile(fp);
+ fclose(fp);
+ }
+ }
+}
+
+/* Return fake connection structure. Used for logging, if connection
+ is not applicable at the moment of logging. */
+static struct mg_connection *fc(struct mg_context *ctx)
+{
+ static struct mg_connection fake_connection;
+ fake_connection.ctx = ctx;
+ return &fake_connection;
+}
+
+const char *mg_version(void)
+{
+ return CIVETWEB_VERSION;
+}
+
+struct mg_request_info *mg_get_request_info(struct mg_connection *conn)
+{
+ return &conn->request_info;
+}
+
+/* Skip the characters until one of the delimiters characters found.
+ 0-terminate resulting word. Skip the delimiter and following whitespaces.
+ Advance pointer to buffer to the next word. Return found 0-terminated word.
+ Delimiters can be quoted with quotechar. */
+static char *skip_quoted(char **buf, const char *delimiters,
+ const char *whitespace, char quotechar)
+{
+ char *p, *begin_word, *end_word, *end_whitespace;
+
+ begin_word = *buf;
+ end_word = begin_word + strcspn(begin_word, delimiters);
+
+ /* Check for quotechar */
+ if (end_word > begin_word) {
+ p = end_word - 1;
+ while (*p == quotechar) {
+ /* TODO (bel): it seems this code is never reached, so quotechar is actually
+ not needed - check if this code may be droped */
+
+ /* If there is anything beyond end_word, copy it */
+ if (*end_word == '\0') {
+ *p = '\0';
+ break;
+ } else {
+ size_t end_off = strcspn(end_word + 1, delimiters);
+ memmove (p, end_word, end_off + 1);
+ p += end_off; /* p must correspond to end_word - 1 */
+ end_word += end_off + 1;
+ }
+ }
+ for (p++; p < end_word; p++) {
+ *p = '\0';
+ }
+ }
+
+ if (*end_word == '\0') {
+ *buf = end_word;
+ } else {
+ end_whitespace = end_word + 1 + strspn(end_word + 1, whitespace);
+
+ for (p = end_word; p < end_whitespace; p++) {
+ *p = '\0';
+ }
+
+ *buf = end_whitespace;
+ }
+
+ return begin_word;
+}
+
+/* Simplified version of skip_quoted without quote char
+ and whitespace == delimiters */
+static char *skip(char **buf, const char *delimiters)
+{
+ return skip_quoted(buf, delimiters, delimiters, 0);
+}
+
+
+/* Return HTTP header value, or NULL if not found. */
+static const char *get_header(const struct mg_request_info *ri,
+ const char *name)
+{
+ int i;
+
+ for (i = 0; i < ri->num_headers; i++)
+ if (!mg_strcasecmp(name, ri->http_headers[i].name))
+ return ri->http_headers[i].value;
+
+ return NULL;
+}
+
+const char *mg_get_header(const struct mg_connection *conn, const char *name)
+{
+ return get_header(&conn->request_info, name);
+}
+
+/* A helper function for traversing a comma separated list of values.
+ It returns a list pointer shifted to the next value, or NULL if the end
+ of the list found.
+ Value is stored in val vector. If value has form "x=y", then eq_val
+ vector is initialized to point to the "y" part, and val vector length
+ is adjusted to point only to "x". */
+static const char *next_option(const char *list, struct vec *val,
+ struct vec *eq_val)
+{
+ if (list == NULL || *list == '\0') {
+ /* End of the list */
+ list = NULL;
+ } else {
+ val->ptr = list;
+ if ((list = strchr(val->ptr, ',')) != NULL) {
+ /* Comma found. Store length and shift the list ptr */
+ val->len = list - val->ptr;
+ list++;
+ } else {
+ /* This value is the last one */
+ list = val->ptr + strlen(val->ptr);
+ val->len = list - val->ptr;
+ }
+
+ if (eq_val != NULL) {
+ /* Value has form "x=y", adjust pointers and lengths
+ so that val points to "x", and eq_val points to "y". */
+ eq_val->len = 0;
+ eq_val->ptr = (const char *) memchr(val->ptr, '=', val->len);
+ if (eq_val->ptr != NULL) {
+ eq_val->ptr++; /* Skip over '=' character */
+ eq_val->len = val->ptr + val->len - eq_val->ptr;
+ val->len = (eq_val->ptr - val->ptr) - 1;
+ }
+ }
+ }
+
+ return list;
+}
+
+/* Perform case-insensitive match of string against pattern */
+static int match_prefix(const char *pattern, int pattern_len, const char *str)
+{
+ const char *or_str;
+ int i, j, len, res;
+
+ if ((or_str = (const char *) memchr(pattern, '|', pattern_len)) != NULL) {
+ res = match_prefix(pattern, (int)(or_str - pattern), str);
+ return res > 0 ? res :
+ match_prefix(or_str + 1, (int)((pattern + pattern_len) - (or_str + 1)), str);
+ }
+
+ i = j = 0;
+ for (; i < pattern_len; i++, j++) {
+ if (pattern[i] == '?' && str[j] != '\0') {
+ continue;
+ } else if (pattern[i] == '$') {
+ return str[j] == '\0' ? j : -1;
+ } else if (pattern[i] == '*') {
+ i++;
+ if (pattern[i] == '*') {
+ i++;
+ len = (int) strlen(str + j);
+ } else {
+ len = (int) strcspn(str + j, "/");
+ }
+ if (i == pattern_len) {
+ return j + len;
+ }
+ do {
+ res = match_prefix(pattern + i, pattern_len - i, str + j + len);
+ } while (res == -1 && len-- > 0);
+ return res == -1 ? -1 : j + res + len;
+ } else if (lowercase(&pattern[i]) != lowercase(&str[j])) {
+ return -1;
+ }
+ }
+ return j;
+}
+
+/* HTTP 1.1 assumes keep alive if "Connection:" header is not set
+ This function must tolerate situations when connection info is not
+ set up, for example if request parsing failed. */
+static int should_keep_alive(const struct mg_connection *conn)
+{
+ const char *http_version = conn->request_info.http_version;
+ const char *header = mg_get_header(conn, "Connection");
+ if (conn->must_close ||
+ conn->status_code == 401 ||
+ mg_strcasecmp(conn->ctx->config[ENABLE_KEEP_ALIVE], "yes") != 0 ||
+ (header != NULL && mg_strcasecmp(header, "keep-alive") != 0) ||
+ (header == NULL && http_version && 0!=strcmp(http_version, "1.1"))) {
+ return 0;
+ }
+ return 1;
+}
+
+static int should_decode_url(const struct mg_connection *conn)
+{
+ return (mg_strcasecmp(conn->ctx->config[DECODE_URL], "yes") == 0);
+}
+
+static const char *suggest_connection_header(const struct mg_connection *conn)
+{
+ return should_keep_alive(conn) ? "keep-alive" : "close";
+}
+
+static void handle_file_based_request(struct mg_connection *conn, const char *path, struct file *filep);
+static int mg_stat(struct mg_connection *conn, const char *path, struct file *filep);
+
+static const char *mg_get_response_code_text(int response_code, struct mg_connection *conn)
+{
+ switch (response_code)
+ {
+ /* RFC2616 Section 10.1 - Informational 1xx */
+ case 100: return "Continue"; /* RFC2616 Section 10.1.1 */
+ case 101: return "Switching Protocols"; /* RFC2616 Section 10.1.2 */
+ case 102: return "Processing"; /* RFC2518 Section 10.1 */
+
+ /* RFC2616 Section 10.2 - Successful 2xx */
+ case 200: return "OK"; /* RFC2616 Section 10.2.1 */
+ case 201: return "Created"; /* RFC2616 Section 10.2.2 */
+ case 202: return "Accepted"; /* RFC2616 Section 10.2.3 */
+ case 203: return "Non-Authoritative Information"; /* RFC2616 Section 10.2.4 */
+ case 204: return "No Content"; /* RFC2616 Section 10.2.5 */
+ case 205: return "Reset Content"; /* RFC2616 Section 10.2.6 */
+ case 206: return "Partial Content"; /* RFC2616 Section 10.2.7 */
+ case 207: return "Multi-Status"; /* RFC2518 Section 10.2, RFC4918 Section 11.1 */
+
+ /* RFC2616 Section 10.3 - Redirection 3xx */
+ case 300: return "Multiple Choices"; /* RFC2616 Section 10.3.1 */
+ case 301: return "Moved Permanently"; /* RFC2616 Section 10.3.2 */
+ case 302: return "Found"; /* RFC2616 Section 10.3.3 */
+ case 303: return "See Other"; /* RFC2616 Section 10.3.4 */
+ case 304: return "Not Modified"; /* RFC2616 Section 10.3.5 */
+ case 305: return "Use Proxy"; /* RFC2616 Section 10.3.6 */
+ case 307: return "Temporary Redirect"; /* RFC2616 Section 10.3.8 */
+
+ /* RFC2616 Section 10.4 - Client Error 4xx */
+ case 400: return "Bad Request"; /* RFC2616 Section 10.4.1 */
+ case 401: return "Unauthorized"; /* RFC2616 Section 10.4.2 */
+ case 402: return "Payment Required"; /* RFC2616 Section 10.4.3 */
+ case 403: return "Forbidden"; /* RFC2616 Section 10.4.4 */
+ case 404: return "Not Found"; /* RFC2616 Section 10.4.5 */
+ case 405: return "Method Not Allowed"; /* RFC2616 Section 10.4.6 */
+ case 406: return "Not Acceptable"; /* RFC2616 Section 10.4.7 */
+ case 407: return "Proxy Authentication Required"; /* RFC2616 Section 10.4.8 */
+ case 408: return "Request Time-out"; /* RFC2616 Section 10.4.9 */
+ case 409: return "Conflict"; /* RFC2616 Section 10.4.10 */
+ case 410: return "Gone"; /* RFC2616 Section 10.4.11 */
+ case 411: return "Length Required"; /* RFC2616 Section 10.4.12 */
+ case 412: return "Precondition Failed"; /* RFC2616 Section 10.4.13 */
+ case 413: return "Request Entity Too Large"; /* RFC2616 Section 10.4.14 */
+ case 414: return "Request-URI Too Large"; /* RFC2616 Section 10.4.15 */
+ case 415: return "Unsupported Media Type"; /* RFC2616 Section 10.4.16 */
+ case 416: return "Requested range not satisfiable"; /* RFC2616 Section 10.4.17 */
+ case 417: return "Expectation Failed"; /* RFC2616 Section 10.4.18 */
+ case 422: return "Unproccessable entity"; /* RFC2518 Section 10.3, RFC4918 Section 11.2 */
+ case 423: return "Locked"; /* RFC2518 Section 10.4, RFC4918 Section 11.3 */
+ case 424: return "Failed Dependency"; /* RFC2518 Section 10.5, RFC4918 Section 11.4 */
+ case 428: return "Precondition Required"; /* RFC 6585, Section 3 */
+ case 429: return "Too Many Requests"; /* RFC 6585, Section 4 */
+ case 431: return "Request Header Fields Too Large"; /* RFC 6585, Section 5 */
+
+ /* RFC2616 Section 10.5 - Server Error 5xx */
+ case 500: return "Internal Server Error"; /* RFC2616 Section 10.5.1 */
+ case 501: return "Not Implemented"; /* RFC2616 Section 10.5.2 */
+ case 502: return "Bad Gateway"; /* RFC2616 Section 10.5.3 */
+ case 503: return "Service Unavailable"; /* RFC2616 Section 10.5.4 */
+ case 504: return "Gateway Time-out"; /* RFC2616 Section 10.5.5 */
+ case 505: return "HTTP Version not supported"; /* RFC2616 Section 10.5.6 */
+ case 507: return "Insufficient Storage"; /* RFC2518 Section 10.6, , RFC4918 Section 11.5 */
+ case 511: return "Network Authentication Required"; /* RFC 6585, Section 6 */
+
+ /* Other RFCs */
+ case 426: return "Upgrade Required"; /* RFC 2817 */
+
+ /* Return codes from non normative RFCs: */
+ /* Informative and experimental RFCs, "de facto" standards due to common use, ... */
+ case 208: return "Already Reported"; /* RFC5842 Section 7.1 */
+ case 226: return "IM used"; /* RFC3229 Section 10.4.1 */
+ case 308: return "Permanent Redirect"; /* RFC7238 Section 3 */
+ case 418: return "I am a teapot"; /* RFC2324 Section 2.3.2 */
+ case 419: return "Authentication Timeout"; /* common use */
+ case 451: return "Unavailable For Legal Reasons"; /* draft-tbray-http-legally-restricted-status-05, Section 3 */
+ case 506: return "Variant Also Negotiates"; /* RFC 2295, Section 8.1 */
+ case 508: return "Loop Detected"; /* RFC5842 Section 7.1 */
+ case 510: return "Not Extended"; /* RFC 2774, Section 7 */
+
+ default:
+ /* This error code is unknown. This should not happen. */
+ if (conn) {
+ mg_cry(conn, "Unknown HTTP response code: %u", response_code);
+ }
+
+ /* Return at least a category according to RFC 2616 Section 10. */
+ if (response_code>=100 && response_code<200) {
+ /* Unknown informational status code */
+ return "Information";
+ }
+ if (response_code>=200 && response_code<300) {
+ /* Unknown success code */
+ return "Success";
+ }
+ if (response_code>=300 && response_code<400) {
+ /* Unknown redirection code */
+ return "Redirection";
+ }
+ if (response_code>=400 && response_code<500) {
+ /* Unknown request error code */
+ return "Client Error";
+ }
+ if (response_code>=500 && response_code<600) {
+ /* Unknown server error code */
+ return "Server Error";
+ }
+
+ /* Response code not even within reasonable range */
+ return "";
+ }
+}
+
+
+static void send_http_error(struct mg_connection *, int, const char *,
+ PRINTF_FORMAT_STRING(const char *fmt), ...)
+PRINTF_ARGS(4, 5);
+
+
+static void send_http_error(struct mg_connection *conn, int status,
+ const char *reason, const char *fmt, ...)
+{
+ char buf[MG_BUF_LEN];
+ va_list ap;
+ int len = 0, i, page_handler_found, scope;
+ char date[64];
+ time_t curtime = time(NULL);
+ const char *error_handler = NULL;
+ struct file error_page_file = STRUCT_FILE_INITIALIZER;
+ const char *error_page_file_ext, *tstr;
+
+ if (!reason) {
+ reason = mg_get_response_code_text(status, conn);
+ }
+
+ conn->status_code = status;
+ if (conn->in_error_handler ||
+ conn->ctx->callbacks.http_error == NULL ||
+ conn->ctx->callbacks.http_error(conn, status)) {
+
+ if (!conn->in_error_handler) {
+ /* Send user defined error pages, if defined */
+ error_handler = conn->ctx->config[ERROR_PAGES];
+ error_page_file_ext = conn->ctx->config[INDEX_FILES];
+ page_handler_found = 0;
+ if (error_handler != NULL) {
+ for (scope=1; (scope<=3) && !page_handler_found; scope++) {
+ switch (scope) {
+ case 1:
+ len = mg_snprintf(conn, buf, sizeof(buf)-32, "%serror%03u.", error_handler, status);
+ break;
+ case 2:
+ len = mg_snprintf(conn, buf, sizeof(buf)-32, "%serror%01uxx.", error_handler, status/100);
+ break;
+ default:
+ len = mg_snprintf(conn, buf, sizeof(buf)-32, "%serror.", error_handler);
+ break;
+ }
+ tstr = strchr(error_page_file_ext, '.');
+ while (tstr) {
+ for (i=1; i<32 && tstr[i]!=0 && tstr[i]!=','; i++) buf[len+i-1]=tstr[i];
+ buf[len+i-1]=0;
+ if (mg_stat(conn, buf, &error_page_file)) {
+ page_handler_found = 1;
+ break;
+ }
+ tstr = strchr(tstr+i, '.');
+ }
+ }
+ }
+
+ if (page_handler_found) {
+ conn->in_error_handler = 1;
+ handle_file_based_request(conn, buf, &error_page_file);
+ conn->in_error_handler = 0;
+ return;
+ }
+ }
+
+ buf[0] = '\0';
+ gmt_time_string(date, sizeof(date), &curtime);
+
+ /* Errors 1xx, 204 and 304 MUST NOT send a body */
+ if (status > 199 && status != 204 && status != 304) {
+ len = mg_snprintf(conn, buf, sizeof(buf)-1, "Error %d: %s", status, reason);
+ buf[len] = '\n';
+ len++;
+ buf[len] = 0;
+
+ va_start(ap, fmt);
+ len += mg_vsnprintf(conn, buf + len, sizeof(buf) - len, fmt, ap);
+ va_end(ap);
+ }
+ DEBUG_TRACE("[%s]", buf);
+
+ mg_printf(conn, "HTTP/1.1 %d %s\r\n"
+ "Content-Length: %d\r\n"
+ "Date: %s\r\n"
+ "Connection: %s\r\n\r\n",
+ status, reason, len, date,
+ suggest_connection_header(conn));
+ conn->num_bytes_sent += mg_printf(conn, "%s", buf);
+ }
+}
+
+#if defined(_WIN32) && !defined(__SYMBIAN32__)
+static int pthread_mutex_init(pthread_mutex_t *mutex, void *unused)
+{
+ (void) unused;
+ *mutex = CreateMutex(NULL, FALSE, NULL);
+ return *mutex == NULL ? -1 : 0;
+}
+
+static int pthread_mutex_destroy(pthread_mutex_t *mutex)
+{
+ return CloseHandle(*mutex) == 0 ? -1 : 0;
+}
+
+static int pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+ return WaitForSingleObject(*mutex, INFINITE) == WAIT_OBJECT_0 ? 0 : -1;
+}
+
+static int pthread_mutex_trylock(pthread_mutex_t *mutex)
+{
+ switch (WaitForSingleObject(*mutex, 0)) {
+ case WAIT_OBJECT_0:
+ return 0;
+ case WAIT_TIMEOUT:
+ return -2; /* EBUSY */
+ }
+ return -1;
+}
+
+static int pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+ return ReleaseMutex(*mutex) == 0 ? -1 : 0;
+}
+
+#ifndef WIN_PTHREADS_TIME_H
+static int clock_gettime(clockid_t clk_id, struct timespec *tp)
+{
+ FILETIME ft;
+ ULARGE_INTEGER li;
+ BOOL ok = FALSE;
+ double d;
+ static double perfcnt_per_sec = 0.0;
+
+ if (tp) {
+ if (clk_id == CLOCK_REALTIME) {
+ GetSystemTimeAsFileTime(&ft);
+ li.LowPart = ft.dwLowDateTime;
+ li.HighPart = ft.dwHighDateTime;
+ li.QuadPart -= 116444736000000000; /* 1.1.1970 in filedate */
+ tp->tv_sec = (time_t)(li.QuadPart / 10000000);
+ tp->tv_nsec = (long)(li.QuadPart % 10000000) * 100;
+ ok = TRUE;
+ } else if (clk_id == CLOCK_MONOTONIC) {
+ if (perfcnt_per_sec == 0.0) {
+ QueryPerformanceFrequency((LARGE_INTEGER *) &li);
+ perfcnt_per_sec = 1.0 / li.QuadPart;
+ }
+ if (perfcnt_per_sec != 0.0) {
+ QueryPerformanceCounter((LARGE_INTEGER *) &li);
+ d = li.QuadPart * perfcnt_per_sec;
+ tp->tv_sec = (time_t)d;
+ d -= tp->tv_sec;
+ tp->tv_nsec = (long)(d*1.0E9);
+ ok = TRUE;
+ }
+ }
+ }
+
+ return ok ? 0 : -1;
+}
+#endif
+
+static int pthread_cond_init(pthread_cond_t *cv, const void *unused)
+{
+ (void) unused;
+ InitializeCriticalSection(&cv->threadIdSec);
+ cv->waitingthreadcount = 0;
+ cv->waitingthreadhdls = (pthread_t *) mg_calloc(MAX_WORKER_THREADS, sizeof(pthread_t));
+ return (cv->waitingthreadhdls!=NULL) ? 0 : -1;
+}
+
+static int pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t *mutex, const struct timespec * abstime)
+{
+ struct mg_workerTLS * tls = (struct mg_workerTLS *)TlsGetValue(sTlsKey);
+ int ok;
+ struct timespec tsnow;
+ int64_t nsnow, nswaitabs, nswaitrel;
+ DWORD mswaitrel;
+
+ EnterCriticalSection(&cv->threadIdSec);
+ assert(cv->waitingthreadcount < MAX_WORKER_THREADS);
+ cv->waitingthreadhdls[cv->waitingthreadcount] = tls->pthread_cond_helper_mutex;
+ cv->waitingthreadcount++;
+ LeaveCriticalSection(&cv->threadIdSec);
+
+ if (abstime) {
+ clock_gettime(CLOCK_REALTIME, &tsnow);
+ nsnow = (((uint64_t)tsnow.tv_sec)*1000000000) + tsnow.tv_nsec;
+ nswaitabs = (((uint64_t)abstime->tv_sec)*1000000000) + abstime->tv_nsec;
+ nswaitrel = nswaitabs - nsnow;
+ if (nswaitrel<0) nswaitrel=0;
+ mswaitrel = (DWORD)(nswaitrel / 1000000);
+ } else {
+ mswaitrel = INFINITE;
+ }
+
+ pthread_mutex_unlock(mutex);
+ ok = (WAIT_OBJECT_0 == WaitForSingleObject(tls->pthread_cond_helper_mutex, mswaitrel));
+ pthread_mutex_lock(mutex);
+
+ return ok ? 0 : -1;
+}
+
+static int pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex)
+{
+ return pthread_cond_timedwait(cv, mutex, NULL);
+}
+
+static int pthread_cond_signal(pthread_cond_t *cv)
+{
+ int i;
+ HANDLE wkup = NULL;
+ BOOL ok = FALSE;
+
+ EnterCriticalSection(&cv->threadIdSec);
+ if (cv->waitingthreadcount) {
+ wkup = cv->waitingthreadhdls[0];
+ ok = SetEvent(wkup);
+
+ for (i=1; i<cv->waitingthreadcount; i++) {
+ cv->waitingthreadhdls[i-1] = cv->waitingthreadhdls[i];
+ }
+ cv->waitingthreadcount--;
+
+ assert(ok);
+ }
+ LeaveCriticalSection(&cv->threadIdSec);
+
+ return ok ? 0 : 1;
+}
+
+static int pthread_cond_broadcast(pthread_cond_t *cv)
+{
+ EnterCriticalSection(&cv->threadIdSec);
+ while (cv->waitingthreadcount) {
+ pthread_cond_signal(cv);
+ }
+ LeaveCriticalSection(&cv->threadIdSec);
+
+ return 0;
+}
+
+static int pthread_cond_destroy(pthread_cond_t *cv)
+{
+ EnterCriticalSection(&cv->threadIdSec);
+ assert(cv->waitingthreadcount==0);
+ mg_free(cv->waitingthreadhdls);
+ cv->waitingthreadhdls = 0;
+ LeaveCriticalSection(&cv->threadIdSec);
+ DeleteCriticalSection(&cv->threadIdSec);
+
+ return 0;
+}
+
+/* For Windows, change all slashes to backslashes in path names. */
+static void change_slashes_to_backslashes(char *path)
+{
+ int i;
+
+ for (i = 0; path[i] != '\0'; i++) {
+ if (path[i] == '/')
+ path[i] = '\\';
+ /* i > 0 check is to preserve UNC paths, like \\server\file.txt */
+ if (path[i] == '\\' && i > 0)
+ while (path[i + 1] == '\\' || path[i + 1] == '/')
+ (void) memmove(path + i + 1,
+ path + i + 2, strlen(path + i + 1));
+ }
+}
+
+/* Encode 'path' which is assumed UTF-8 string, into UNICODE string.
+ wbuf and wbuf_len is a target buffer and its length. */
+static void to_unicode(const char *path, wchar_t *wbuf, size_t wbuf_len)
+{
+ char buf[PATH_MAX], buf2[PATH_MAX];
+
+ mg_strlcpy(buf, path, sizeof(buf));
+ change_slashes_to_backslashes(buf);
+
+ /* Convert to Unicode and back. If doubly-converted string does not
+ match the original, something is fishy, reject. */
+ memset(wbuf, 0, wbuf_len * sizeof(wchar_t));
+ MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, (int) wbuf_len);
+ WideCharToMultiByte(CP_UTF8, 0, wbuf, (int) wbuf_len, buf2, sizeof(buf2),
+ NULL, NULL);
+ if (strcmp(buf, buf2) != 0) {
+ wbuf[0] = L'\0';
+ }
+}
+
+#if defined(_WIN32_WCE)
+static time_t time(time_t *ptime)
+{
+ time_t t;
+ SYSTEMTIME st;
+ FILETIME ft;
+
+ GetSystemTime(&st);
+ SystemTimeToFileTime(&st, &ft);
+ t = SYS2UNIX_TIME(ft.dwLowDateTime, ft.dwHighDateTime);
+
+ if (ptime != NULL) {
+ *ptime = t;
+ }
+
+ return t;
+}
+
+static struct tm *localtime(const time_t *ptime, struct tm *ptm)
+{
+ int64_t t = ((int64_t) *ptime) * RATE_DIFF + EPOCH_DIFF;
+ FILETIME ft, lft;
+ SYSTEMTIME st;
+ TIME_ZONE_INFORMATION tzinfo;
+
+ if (ptm == NULL) {
+ return NULL;
+ }
+
+ * (int64_t *) &ft = t;
+ FileTimeToLocalFileTime(&ft, &lft);
+ FileTimeToSystemTime(&lft, &st);
+ ptm->tm_year = st.wYear - 1900;
+ ptm->tm_mon = st.wMonth - 1;
+ ptm->tm_wday = st.wDayOfWeek;
+ ptm->tm_mday = st.wDay;
+ ptm->tm_hour = st.wHour;
+ ptm->tm_min = st.wMinute;
+ ptm->tm_sec = st.wSecond;
+ ptm->tm_yday = 0; /* hope nobody uses this */
+ ptm->tm_isdst =
+ GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_DAYLIGHT ? 1 : 0;
+
+ return ptm;
+}
+
+static struct tm *gmtime(const time_t *ptime, struct tm *ptm)
+{
+ /* FIXME(lsm): fix this. */
+ return localtime(ptime, ptm);
+}
+
+static size_t strftime(char *dst, size_t dst_size, const char *fmt,
+ const struct tm *tm)
+{
+ (void) snprintf(dst, dst_size, "implement strftime() for WinCE");
+ return 0;
+}
+#endif
+
+/* Windows happily opens files with some garbage at the end of file name.
+ For example, fopen("a.cgi ", "r") on Windows successfully opens
+ "a.cgi", despite one would expect an error back.
+ This function returns non-0 if path ends with some garbage. */
+static int path_cannot_disclose_cgi(const char *path)
+{
+ static const char *allowed_last_characters = "_-";
+ int last = path[strlen(path) - 1];
+ return isalnum(last) || strchr(allowed_last_characters, last) != NULL;
+}
+
+static int mg_stat(struct mg_connection *conn, const char *path, struct file *filep)
+{
+ wchar_t wbuf[PATH_MAX];
+ WIN32_FILE_ATTRIBUTE_DATA info;
+
+ if (!is_file_in_memory(conn, path, filep)) {
+ to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
+ if (GetFileAttributesExW(wbuf, GetFileExInfoStandard, &info) != 0) {
+ filep->size = MAKEUQUAD(info.nFileSizeLow, info.nFileSizeHigh);
+ filep->modification_time = SYS2UNIX_TIME(
+ info.ftLastWriteTime.dwLowDateTime,
+ info.ftLastWriteTime.dwHighDateTime);
+ filep->is_directory = info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
+ /* If file name is fishy, reset the file structure and return
+ error.
+ Note it is important to reset, not just return the error, cause
+ functions like is_file_opened() check the struct. */
+ if (!filep->is_directory && !path_cannot_disclose_cgi(path)) {
+ memset(filep, 0, sizeof(*filep));
+ }
+ }
+ }
+
+ return filep->membuf != NULL || filep->modification_time != 0;
+}
+
+static int mg_remove(const char *path)
+{
+ wchar_t wbuf[PATH_MAX];
+ to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
+ return DeleteFileW(wbuf) ? 0 : -1;
+}
+
+static int mg_mkdir(const char *path, int mode)
+{
+ char buf[PATH_MAX];
+ wchar_t wbuf[PATH_MAX];
+
+ (void) mode;
+ mg_strlcpy(buf, path, sizeof(buf));
+ change_slashes_to_backslashes(buf);
+
+ (void) MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, ARRAY_SIZE(wbuf));
+
+ return CreateDirectoryW(wbuf, NULL) ? 0 : -1;
+}
+
+/* Implementation of POSIX opendir/closedir/readdir for Windows. */
+static DIR * opendir(const char *name)
+{
+ DIR *dir = NULL;
+ wchar_t wpath[PATH_MAX];
+ DWORD attrs;
+
+ if (name == NULL) {
+ SetLastError(ERROR_BAD_ARGUMENTS);
+ } else if ((dir = (DIR *) mg_malloc(sizeof(*dir))) == NULL) {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ } else {
+ to_unicode(name, wpath, ARRAY_SIZE(wpath));
+ attrs = GetFileAttributesW(wpath);
+ if (attrs != 0xFFFFFFFF &&
+ ((attrs & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)) {
+ (void) wcscat(wpath, L"\\*");
+ dir->handle = FindFirstFileW(wpath, &dir->info);
+ dir->result.d_name[0] = '\0';
+ } else {
+ mg_free(dir);
+ dir = NULL;
+ }
+ }
+
+ return dir;
+}
+
+static int closedir(DIR *dir)
+{
+ int result = 0;
+
+ if (dir != NULL) {
+ if (dir->handle != INVALID_HANDLE_VALUE)
+ result = FindClose(dir->handle) ? 0 : -1;
+
+ mg_free(dir);
+ } else {
+ result = -1;
+ SetLastError(ERROR_BAD_ARGUMENTS);
+ }
+
+ return result;
+}
+
+static struct dirent *readdir(DIR *dir)
+{
+ struct dirent *result = 0;
+
+ if (dir) {
+ if (dir->handle != INVALID_HANDLE_VALUE) {
+ result = &dir->result;
+ (void) WideCharToMultiByte(CP_UTF8, 0,
+ dir->info.cFileName, -1, result->d_name,
+ sizeof(result->d_name), NULL, NULL);
+
+ if (!FindNextFileW(dir->handle, &dir->info)) {
+ (void) FindClose(dir->handle);
+ dir->handle = INVALID_HANDLE_VALUE;
+ }
+
+ } else {
+ SetLastError(ERROR_FILE_NOT_FOUND);
+ }
+ } else {
+ SetLastError(ERROR_BAD_ARGUMENTS);
+ }
+
+ return result;
+}
+
+#ifndef HAVE_POLL
+static int poll(struct pollfd *pfd, int n, int milliseconds)
+{
+ struct timeval tv;
+ fd_set set;
+ int i, result;
+ SOCKET maxfd = 0;
+
+ tv.tv_sec = milliseconds / 1000;
+ tv.tv_usec = (milliseconds % 1000) * 1000;
+ FD_ZERO(&set);
+
+ for (i = 0; i < n; i++) {
+ FD_SET((SOCKET) pfd[i].fd, &set);
+ pfd[i].revents = 0;
+
+ if (pfd[i].fd > maxfd) {
+ maxfd = pfd[i].fd;
+ }
+ }
+
+ if ((result = select((int)maxfd + 1, &set, NULL, NULL, &tv)) > 0) {
+ for (i = 0; i < n; i++) {
+ if (FD_ISSET(pfd[i].fd, &set)) {
+ pfd[i].revents = POLLIN;
+ }
+ }
+ }
+
+ return result;
+}
+#endif /* HAVE_POLL */
+
+static void set_close_on_exec(SOCKET sock, struct mg_connection *conn /* may be null */)
+{
+ (void) conn; /* Unused. */
+ (void) SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0);
+}
+
+int mg_start_thread(mg_thread_func_t f, void *p)
+{
+#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
+ /* Compile-time option to control stack size, e.g. -DUSE_STACK_SIZE=16384 */
+ return ((_beginthread((void (__cdecl *)(void *)) f, USE_STACK_SIZE, p) == ((uintptr_t)(-1L))) ? -1 : 0);
+#else
+ return ((_beginthread((void (__cdecl *)(void *)) f, 0, p) == ((uintptr_t)(-1L))) ? -1 : 0);
+#endif /* defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1) */
+}
+
+/* Start a thread storing the thread context. */
+
+static int mg_start_thread_with_id(unsigned (__stdcall *f)(void *), void *p,
+ pthread_t *threadidptr)
+{
+ uintptr_t uip;
+ HANDLE threadhandle;
+ int result = -1;
+
+ uip = _beginthreadex(NULL, 0, (unsigned (__stdcall *)(void *)) f, p, 0,
+ NULL);
+ threadhandle = (HANDLE) uip;
+ if ((uip != (uintptr_t)(-1L)) && (threadidptr != NULL)) {
+ *threadidptr = threadhandle;
+ result = 0;
+ }
+
+ return result;
+}
+
+/* Wait for a thread to finish. */
+
+static int mg_join_thread(pthread_t threadid)
+{
+ int result;
+ DWORD dwevent;
+
+ result = -1;
+ dwevent = WaitForSingleObject(threadid, INFINITE);
+ if (dwevent == WAIT_FAILED) {
+ int err;
+
+ err = GetLastError();
+ DEBUG_TRACE("WaitForSingleObject() failed, error %d", err);
+ } else {
+ if (dwevent == WAIT_OBJECT_0) {
+ CloseHandle(threadid);
+ result = 0;
+ }
+ }
+
+ return result;
+}
+
+static HANDLE dlopen(const char *dll_name, int flags)
+{
+ wchar_t wbuf[PATH_MAX];
+ (void) flags;
+ to_unicode(dll_name, wbuf, ARRAY_SIZE(wbuf));
+ return LoadLibraryW(wbuf);
+}
+
+static int dlclose(void *handle)
+{
+ int result;
+
+ if (FreeLibrary((HMODULE) handle) != 0) {
+ result = 0;
+ } else {
+ result = -1;
+ }
+
+ return result;
+}
+
+#if !defined(NO_CGI)
+#define SIGKILL 0
+static int kill(pid_t pid, int sig_num)
+{
+ (void) TerminateProcess(pid, sig_num);
+ (void) CloseHandle(pid);
+ return 0;
+}
+
+static void trim_trailing_whitespaces(char *s)
+{
+ char *e = s + strlen(s) - 1;
+ while (e > s && isspace(* (unsigned char *) e)) {
+ *e-- = '\0';
+ }
+}
+
+static pid_t spawn_process(struct mg_connection *conn, const char *prog,
+ char *envblk, char *envp[], int fdin,
+ int fdout, const char *dir)
+{
+ HANDLE me;
+ char *p, *interp, full_interp[PATH_MAX], full_dir[PATH_MAX],
+ cmdline[PATH_MAX], buf[PATH_MAX];
+ struct file file = STRUCT_FILE_INITIALIZER;
+ STARTUPINFOA si;
+ PROCESS_INFORMATION pi = { 0 };
+
+ (void) envp;
+
+ memset(&si, 0, sizeof(si));
+ si.cb = sizeof(si);
+
+ /* TODO(lsm): redirect CGI errors to the error log file */
+ si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
+ si.wShowWindow = SW_HIDE;
+
+ me = GetCurrentProcess();
+ DuplicateHandle(me, (HANDLE) _get_osfhandle(fdin), me,
+ &si.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS);
+ DuplicateHandle(me, (HANDLE) _get_osfhandle(fdout), me,
+ &si.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS);
+
+ /* If CGI file is a script, try to read the interpreter line */
+ interp = conn->ctx->config[CGI_INTERPRETER];
+ if (interp == NULL) {
+ buf[0] = buf[1] = '\0';
+
+ /* Read the first line of the script into the buffer */
+ snprintf(cmdline, sizeof(cmdline), "%s%c%s", dir, '/', prog);
+ if (mg_fopen(conn, cmdline, "r", &file)) {
+ p = (char *) file.membuf;
+ mg_fgets(buf, sizeof(buf), &file, &p);
+ mg_fclose(&file);
+ buf[sizeof(buf) - 1] = '\0';
+ }
+
+ if (buf[0] == '#' && buf[1] == '!') {
+ trim_trailing_whitespaces(buf + 2);
+ } else {
+ buf[2] = '\0';
+ }
+ interp = buf + 2;
+ }
+
+ if (interp[0] != '\0') {
+ GetFullPathNameA(interp, sizeof(full_interp), full_interp, NULL);
+ interp = full_interp;
+ }
+ GetFullPathNameA(dir, sizeof(full_dir), full_dir, NULL);
+
+ mg_snprintf(conn, cmdline, sizeof(cmdline), "%s%s\"%s\\%s\"",
+ interp, interp[0] == '\0' ? "" : " ", full_dir, prog);
+
+ DEBUG_TRACE("Running [%s]", cmdline);
+ if (CreateProcessA(NULL, cmdline, NULL, NULL, TRUE,
+ CREATE_NEW_PROCESS_GROUP, envblk, NULL, &si, &pi) == 0) {
+ mg_cry(conn, "%s: CreateProcess(%s): %ld",
+ __func__, cmdline, ERRNO);
+ pi.hProcess = (pid_t) -1;
+ }
+
+ (void) CloseHandle(si.hStdOutput);
+ (void) CloseHandle(si.hStdInput);
+ if (pi.hThread != NULL)
+ (void) CloseHandle(pi.hThread);
+
+ return (pid_t) pi.hProcess;
+}
+#endif /* !NO_CGI */
+
+static int set_non_blocking_mode(SOCKET sock)
+{
+ unsigned long on = 1;
+ return ioctlsocket(sock, FIONBIO, &on);
+}
+
+#else
+static int mg_stat(struct mg_connection *conn, const char *path,
+ struct file *filep)
+{
+ struct stat st;
+
+ if (!is_file_in_memory(conn, path, filep) && !stat(path, &st)) {
+ filep->size = st.st_size;
+ filep->modification_time = st.st_mtime;
+ filep->is_directory = S_ISDIR(st.st_mode);
+ } else {
+ filep->modification_time = (time_t) 0;
+ }
+
+ return filep->membuf != NULL || filep->modification_time != (time_t) 0;
+}
+
+static void set_close_on_exec(int fd, struct mg_connection *conn /* may be null */)
+{
+ if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) {
+ if (conn) {
+ mg_cry(conn, "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s", __func__, strerror(ERRNO));
+ }
+ }
+}
+
+int mg_start_thread(mg_thread_func_t func, void *param)
+{
+ pthread_t thread_id;
+ pthread_attr_t attr;
+ int result;
+
+ (void) pthread_attr_init(&attr);
+ (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
+ /* Compile-time option to control stack size,
+ e.g. -DUSE_STACK_SIZE=16384 */
+ (void) pthread_attr_setstacksize(&attr, USE_STACK_SIZE);
+#endif /* defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1) */
+
+ result = pthread_create(&thread_id, &attr, func, param);
+ pthread_attr_destroy(&attr);
+
+ return result;
+}
+
+/* Start a thread storing the thread context. */
+
+static int mg_start_thread_with_id(mg_thread_func_t func, void *param, pthread_t *threadidptr)
+{
+ pthread_t thread_id;
+ pthread_attr_t attr;
+ int result;
+
+ (void) pthread_attr_init(&attr);
+
+#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
+ /* Compile-time option to control stack size,
+ e.g. -DUSE_STACK_SIZE=16384 */
+ (void) pthread_attr_setstacksize(&attr, USE_STACK_SIZE);
+#endif /* defined(USE_STACK_SIZE) && USE_STACK_SIZE > 1 */
+
+ result = pthread_create(&thread_id, &attr, func, param);
+ pthread_attr_destroy(&attr);
+ if ((result == 0) && (threadidptr != NULL)) {
+ *threadidptr = thread_id;
+ }
+ return result;
+}
+
+/* Wait for a thread to finish. */
+
+static int mg_join_thread(pthread_t threadid)
+{
+ int result;
+
+ result = pthread_join(threadid, NULL);
+ return result;
+}
+
+#ifndef NO_CGI
+static pid_t spawn_process(struct mg_connection *conn, const char *prog,
+ char *envblk, char *envp[], int fdin,
+ int fdout, const char *dir)
+{
+ pid_t pid;
+ const char *interp;
+
+ (void) envblk;
+
+ if ((pid = fork()) == -1) {
+ /* Parent */
+ send_http_error(conn, 500, NULL,
+ "Error: Creating CGI process\nfork(): %s", strerror(ERRNO));
+ } else if (pid == 0) {
+ /* Child */
+ if (chdir(dir) != 0) {
+ mg_cry(conn, "%s: chdir(%s): %s", __func__, dir, strerror(ERRNO));
+ } else if (dup2(fdin, 0) == -1) {
+ mg_cry(conn, "%s: dup2(%d, 0): %s", __func__, fdin, strerror(ERRNO));
+ } else if (dup2(fdout, 1) == -1) {
+ mg_cry(conn, "%s: dup2(%d, 1): %s", __func__, fdout, strerror(ERRNO));
+ } else {
+ /* Not redirecting stderr to stdout, to avoid output being littered
+ with the error messages. */
+ (void) close(fdin);
+ (void) close(fdout);
+
+ /* After exec, all signal handlers are restored to their default
+ values, with one exception of SIGCHLD. According to
+ POSIX.1-2001 and Linux's implementation, SIGCHLD's handler will
+ leave unchanged after exec if it was set to be ignored. Restore
+ it to default action. */
+ signal(SIGCHLD, SIG_DFL);
+
+ interp = conn->ctx->config[CGI_INTERPRETER];
+ if (interp == NULL) {
+ (void) execle(prog, prog, NULL, envp);
+ mg_cry(conn, "%s: execle(%s): %s", __func__, prog, strerror(ERRNO));
+ } else {
+ (void) execle(interp, interp, prog, NULL, envp);
+ mg_cry(conn, "%s: execle(%s %s): %s", __func__, interp, prog,
+ strerror(ERRNO));
+ }
+ }
+ exit(EXIT_FAILURE);
+ }
+
+ return pid;
+}
+#endif /* !NO_CGI */
+
+static int set_non_blocking_mode(SOCKET sock)
+{
+ int flags;
+
+ flags = fcntl(sock, F_GETFL, 0);
+ (void) fcntl(sock, F_SETFL, flags | O_NONBLOCK);
+
+ return 0;
+}
+#endif /* _WIN32 */
+
+/* Write data to the IO channel - opened file descriptor, socket or SSL
+ descriptor. Return number of bytes written. */
+static int64_t push(FILE *fp, SOCKET sock, SSL *ssl, const char *buf, int64_t len)
+{
+ int64_t sent;
+ int n, k;
+
+ (void) ssl; /* Get rid of warning */
+ sent = 0;
+ while (sent < len) {
+
+ /* How many bytes we send in this iteration */
+ k = len - sent > INT_MAX ? INT_MAX : (int) (len - sent);
+
+#ifndef NO_SSL
+ if (ssl != NULL) {
+ n = SSL_write(ssl, buf + sent, k);
+ } else
+#endif
+ if (fp != NULL) {
+ n = (int) fwrite(buf + sent, 1, (size_t) k, fp);
+ if (ferror(fp))
+ n = -1;
+ } else {
+ n = send(sock, buf + sent, (size_t) k, MSG_NOSIGNAL);
+ }
+
+ if (n <= 0)
+ break;
+
+ sent += n;
+ }
+
+ return sent;
+}
+
+/* Read from IO channel - opened file descriptor, socket, or SSL descriptor.
+ Return negative value on error, or number of bytes read on success. */
+static int pull(FILE *fp, struct mg_connection *conn, char *buf, int len)
+{
+ int nread;
+
+ if (fp != NULL) {
+ /* Use read() instead of fread(), because if we're reading from the
+ CGI pipe, fread() may block until IO buffer is filled up. We cannot
+ afford to block and must pass all read bytes immediately to the
+ client. */
+ nread = read(fileno(fp), buf, (size_t) len);
+#ifndef NO_SSL
+ } else if (conn->ssl != NULL) {
+ nread = SSL_read(conn->ssl, buf, len);
+#endif
+ } else {
+ nread = recv(conn->client.sock, buf, (size_t) len, 0);
+ }
+
+ return conn->ctx->stop_flag ? -1 : nread;
+}
+
+static int pull_all(FILE *fp, struct mg_connection *conn, char *buf, int len)
+{
+ int n, nread = 0;
+
+ while (len > 0 && conn->ctx->stop_flag == 0) {
+ n = pull(fp, conn, buf + nread, len);
+ if (n < 0) {
+ nread = n; /* Propagate the error */
+ break;
+ } else if (n == 0) {
+ break; /* No more data to read */
+ } else {
+ conn->consumed_content += n;
+ nread += n;
+ len -= n;
+ }
+ }
+
+ return nread;
+}
+
+int mg_read(struct mg_connection *conn, void *buf, size_t len)
+{
+ int64_t n, buffered_len, nread;
+ int64_t len64 = (int64_t)(len > INT_MAX ? INT_MAX : len); /* since the return value is int, we may not read more bytes */
+ const char *body;
+
+ /* If Content-Length is not set for a PUT or POST request, read until socket is closed */
+ if (conn->consumed_content == 0 && conn->content_len == -1) {
+ conn->content_len = INT64_MAX;
+ conn->must_close = 1;
+ }
+
+ nread = 0;
+ if (conn->consumed_content < conn->content_len) {
+ /* Adjust number of bytes to read. */
+ int64_t left_to_read = conn->content_len - conn->consumed_content;
+ if (left_to_read < len64) {
+ /* Do not reade more than the total content length of the request. */
+ len64 = left_to_read;
+ }
+
+ /* Return buffered data */
+ buffered_len = (int64_t)(conn->data_len) - (int64_t)conn->request_len - conn->consumed_content;
+ if (buffered_len > 0) {
+ if (len64 < buffered_len) {
+ buffered_len = len64;
+ }
+ body = conn->buf + conn->request_len + conn->consumed_content;
+ memcpy(buf, body, (size_t) buffered_len);
+ len64 -= buffered_len;
+ conn->consumed_content += buffered_len;
+ nread += buffered_len;
+ buf = (char *) buf + buffered_len;
+ }
+
+ /* We have returned all buffered data. Read new data from the remote
+ socket. */
+ if ((n = pull_all(NULL, conn, (char *) buf, (int)len64)) >= 0) {
+ nread += n;
+ } else {
+ nread = (nread > 0 ? nread : n);
+ }
+ }
+ return (int)nread;
+}
+
+int mg_write(struct mg_connection *conn, const void *buf, size_t len)
+{
+ time_t now;
+ int64_t n, total, allowed;
+
+ if (conn->throttle > 0) {
+ if ((now = time(NULL)) != conn->last_throttle_time) {
+ conn->last_throttle_time = now;
+ conn->last_throttle_bytes = 0;
+ }
+ allowed = conn->throttle - conn->last_throttle_bytes;
+ if (allowed > (int64_t) len) {
+ allowed = len;
+ }
+ if ((total = push(NULL, conn->client.sock, conn->ssl, (const char *) buf,
+ (int64_t) allowed)) == allowed) {
+ buf = (char *) buf + total;
+ conn->last_throttle_bytes += total;
+ while (total < (int64_t) len && conn->ctx->stop_flag == 0) {
+ allowed = conn->throttle > (int64_t) len - total ?
+ (int64_t) len - total : conn->throttle;
+ if ((n = push(NULL, conn->client.sock, conn->ssl, (const char *) buf,
+ (int64_t) allowed)) != allowed) {
+ break;
+ }
+ sleep(1);
+ conn->last_throttle_bytes = allowed;
+ conn->last_throttle_time = time(NULL);
+ buf = (char *) buf + n;
+ total += n;
+ }
+ }
+ } else {
+ total = push(NULL, conn->client.sock, conn->ssl, (const char *) buf,
+ (int64_t) len);
+ }
+ return (int) total;
+}
+
+/* Alternative alloc_vprintf() for non-compliant C runtimes */
+static int alloc_vprintf2(char **buf, const char *fmt, va_list ap)
+{
+ va_list ap_copy;
+ int size = MG_BUF_LEN;
+ int len = -1;
+
+ *buf = NULL;
+ while (len == -1) {
+ if (*buf) mg_free(*buf);
+ *buf = (char *)mg_malloc(size *= 4);
+ if (!*buf) break;
+ va_copy(ap_copy, ap);
+ len = vsnprintf(*buf, size, fmt, ap_copy);
+ va_end(ap_copy);
+ }
+
+ return len;
+}
+
+/* Print message to buffer. If buffer is large enough to hold the message,
+ return buffer. If buffer is to small, allocate large enough buffer on heap,
+ and return allocated buffer. */
+static int alloc_vprintf(char **buf, size_t size, const char *fmt, va_list ap)
+{
+ va_list ap_copy;
+ int len;
+
+ /* Windows is not standard-compliant, and vsnprintf() returns -1 if
+ buffer is too small. Also, older versions of msvcrt.dll do not have
+ _vscprintf(). However, if size is 0, vsnprintf() behaves correctly.
+ Therefore, we make two passes: on first pass, get required message
+ length.
+ On second pass, actually print the message. */
+ va_copy(ap_copy, ap);
+ len = vsnprintf(NULL, 0, fmt, ap_copy);
+ va_end(ap_copy);
+
+ if (len < 0) {
+ /* C runtime is not standard compliant, vsnprintf() returned -1.
+ Switch to alternative code path that uses incremental allocations.
+ */
+ va_copy(ap_copy, ap);
+ len = alloc_vprintf2(buf, fmt, ap);
+ va_end(ap_copy);
+ } else if (len > (int) size &&
+ (size = len + 1) > 0 &&
+ (*buf = (char *) mg_malloc(size)) == NULL) {
+ len = -1; /* Allocation failed, mark failure */
+ } else {
+ va_copy(ap_copy, ap);
+ IGNORE_UNUSED_RESULT(vsnprintf(*buf, size, fmt, ap_copy));
+ va_end(ap_copy);
+ }
+
+ return len;
+}
+
+int mg_vprintf(struct mg_connection *conn, const char *fmt, va_list ap)
+{
+ char mem[MG_BUF_LEN], *buf = mem;
+ int len;
+
+ if ((len = alloc_vprintf(&buf, sizeof(mem), fmt, ap)) > 0) {
+ len = mg_write(conn, buf, (size_t) len);
+ }
+ if (buf != mem && buf != NULL) {
+ mg_free(buf);
+ }
+
+ return len;
+}
+
+int mg_printf(struct mg_connection *conn, const char *fmt, ...)
+{
+ va_list ap;
+ int result;
+
+ va_start(ap, fmt);
+ result = mg_vprintf(conn, fmt, ap);
+ va_end(ap);
+
+ return result;
+}
+
+int mg_url_decode(const char *src, int src_len, char *dst,
+ int dst_len, int is_form_url_encoded)
+{
+ int i, j, a, b;
+#define HEXTOI(x) (isdigit(x) ? x - '0' : x - 'W')
+
+ for (i = j = 0; i < src_len && j < dst_len - 1; i++, j++) {
+ if (i < src_len - 2 && src[i] == '%' &&
+ isxdigit(* (const unsigned char *) (src + i + 1)) &&
+ isxdigit(* (const unsigned char *) (src + i + 2))) {
+ a = tolower(* (const unsigned char *) (src + i + 1));
+ b = tolower(* (const unsigned char *) (src + i + 2));
+ dst[j] = (char) ((HEXTOI(a) << 4) | HEXTOI(b));
+ i += 2;
+ } else if (is_form_url_encoded && src[i] == '+') {
+ dst[j] = ' ';
+ } else {
+ dst[j] = src[i];
+ }
+ }
+
+ dst[j] = '\0'; /* Null-terminate the destination */
+
+ return i >= src_len ? j : -1;
+}
+
+int mg_get_var(const char *data, size_t data_len, const char *name,
+ char *dst, size_t dst_len)
+{
+ return mg_get_var2(data,data_len,name,dst,dst_len,0);
+}
+
+int mg_get_var2(const char *data, size_t data_len, const char *name,
+ char *dst, size_t dst_len, size_t occurrence)
+{
+ const char *p, *e, *s;
+ size_t name_len;
+ int len;
+
+ if (dst == NULL || dst_len == 0) {
+ len = -2;
+ } else if (data == NULL || name == NULL || data_len == 0) {
+ len = -1;
+ dst[0] = '\0';
+ } else {
+ name_len = strlen(name);
+ e = data + data_len;
+ len = -1;
+ dst[0] = '\0';
+
+ /* data is "var1=val1&var2=val2...". Find variable first */
+ for (p = data; p + name_len < e; p++) {
+ if ((p == data || p[-1] == '&') && p[name_len] == '=' &&
+ !mg_strncasecmp(name, p, name_len) && 0 == occurrence--) {
+
+ /* Point p to variable value */
+ p += name_len + 1;
+
+ /* Point s to the end of the value */
+ s = (const char *) memchr(p, '&', (size_t)(e - p));
+ if (s == NULL) {
+ s = e;
+ }
+ assert(s >= p);
+
+ /* Decode variable into destination buffer */
+ len = mg_url_decode(p, (int)(s - p), dst, (int)dst_len, 1);
+
+ /* Redirect error code from -1 to -2 (destination buffer too
+ small). */
+ if (len == -1) {
+ len = -2;
+ }
+ break;
+ }
+ }
+ }
+
+ return len;
+}
+
+int mg_get_cookie(const char *cookie_header, const char *var_name,
+ char *dst, size_t dst_size)
+{
+ const char *s, *p, *end;
+ int name_len, len = -1;
+
+ if (dst == NULL || dst_size == 0) {
+ len = -2;
+ } else if (var_name == NULL || (s = cookie_header) == NULL) {
+ len = -1;
+ dst[0] = '\0';
+ } else {
+ name_len = (int) strlen(var_name);
+ end = s + strlen(s);
+ dst[0] = '\0';
+
+ for (; (s = mg_strcasestr(s, var_name)) != NULL; s += name_len) {
+
<TRUNCATED>
[13/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/include/endpoint_descriptor_common.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/include/endpoint_descriptor_common.h b/remote_services/discovery_common/include/endpoint_descriptor_common.h
new file mode 100644
index 0000000..a186a18
--- /dev/null
+++ b/remote_services/discovery_common/include/endpoint_descriptor_common.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.
+ */
+/*
+ * endpoint_descriptor_common.h
+ *
+ * \date Aug 8, 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef ENDPOINT_DESCRIPTOR_COMMON_H_
+#define ENDPOINT_DESCRIPTOR_COMMON_H_
+
+/*
+ * Private constant & enum definitions for endpoint descriptor reader and writer, not needed for normal usage of the reader and writer.
+ */
+
+typedef enum {
+ VALUE_TYPE_STRING,
+ VALUE_TYPE_LONG,
+ VALUE_TYPE_DOUBLE,
+ VALUE_TYPE_FLOAT,
+ VALUE_TYPE_INTEGER,
+ VALUE_TYPE_BYTE,
+ VALUE_TYPE_CHAR,
+ VALUE_TYPE_BOOLEAN,
+ VALUE_TYPE_SHORT,
+} valueType;
+
+static const __attribute__((unused)) xmlChar* XML = (const xmlChar*) "xml";
+static const __attribute__((unused)) xmlChar* XMLNS = (const xmlChar*) "http://www.osgi.org/xmlns/rsa/v1.0.0";
+
+static const __attribute__((unused)) xmlChar* ENDPOINT_DESCRIPTIONS = (const xmlChar*) "endpoint-descriptions";
+static const xmlChar* ENDPOINT_DESCRIPTION = (const xmlChar*) "endpoint-description";
+
+static const xmlChar* ARRAY = (const xmlChar*) "array";
+static const __attribute__((unused)) xmlChar* LIST = (const xmlChar*) "list";
+static const __attribute__((unused)) xmlChar* SET = (const xmlChar*) "set";
+
+static const xmlChar* PROPERTY = (const xmlChar*) "property";
+static const xmlChar* NAME = (const xmlChar*) "name";
+static const xmlChar* VALUE = (const xmlChar*) "value";
+static const xmlChar* VALUE_TYPE = (const xmlChar*) "value-type";
+
+#endif /* ENDPOINT_DESCRIPTOR_COMMON_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/include/endpoint_descriptor_reader.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/include/endpoint_descriptor_reader.h b/remote_services/discovery_common/include/endpoint_descriptor_reader.h
new file mode 100644
index 0000000..7a05d9e
--- /dev/null
+++ b/remote_services/discovery_common/include/endpoint_descriptor_reader.h
@@ -0,0 +1,42 @@
+/**
+ *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.
+ */
+/*
+ * endpoint_descriptor_reader.h
+ *
+ * \date 26 Jul 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef ENDPOINT_DESCRIPTOR_READER_H_
+#define ENDPOINT_DESCRIPTOR_READER_H_
+
+#include "endpoint_discovery_poller.h"
+#include "celix_errno.h"
+#include "array_list.h"
+
+typedef struct endpoint_descriptor_reader *endpoint_descriptor_reader_pt;
+
+celix_status_t endpointDescriptorReader_create(endpoint_discovery_poller_pt poller, endpoint_descriptor_reader_pt *reader);
+celix_status_t endpointDescriptorReader_destroy(endpoint_descriptor_reader_pt reader);
+
+celix_status_t endpointDescriptorReader_parseDocument(endpoint_descriptor_reader_pt reader, char *document, array_list_pt *endpoints);
+
+
+#endif /* ENDPOINT_DESCRIPTOR_READER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/include/endpoint_descriptor_writer.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/include/endpoint_descriptor_writer.h b/remote_services/discovery_common/include/endpoint_descriptor_writer.h
new file mode 100644
index 0000000..3c5a9be
--- /dev/null
+++ b/remote_services/discovery_common/include/endpoint_descriptor_writer.h
@@ -0,0 +1,39 @@
+/**
+ *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.
+ */
+/*
+ * endpoint_descriptor_writer.h
+ *
+ * \date 26 Jul 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef ENDPOINT_DESCRIPTOR_WRITER_H_
+#define ENDPOINT_DESCRIPTOR_WRITER_H_
+
+#include "celix_errno.h"
+#include "array_list.h"
+
+typedef struct endpoint_descriptor_writer *endpoint_descriptor_writer_pt;
+
+celix_status_t endpointDescriptorWriter_create(endpoint_descriptor_writer_pt *writer);
+celix_status_t endpointDescriptorWriter_destroy(endpoint_descriptor_writer_pt writer);
+celix_status_t endpointDescriptorWriter_writeDocument(endpoint_descriptor_writer_pt writer, array_list_pt endpoints, char **document);
+
+#endif /* ENDPOINT_DESCRIPTOR_WRITER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/include/endpoint_discovery_poller.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/include/endpoint_discovery_poller.h b/remote_services/discovery_common/include/endpoint_discovery_poller.h
new file mode 100644
index 0000000..d344e55
--- /dev/null
+++ b/remote_services/discovery_common/include/endpoint_discovery_poller.h
@@ -0,0 +1,56 @@
+/**
+ * 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.
+ */
+/*
+ * endpoint_discovery_poller.h
+ *
+ * \date 3 Jul 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef ENDPOINT_DISCOVERY_POLLER_H_
+#define ENDPOINT_DISCOVERY_POLLER_H_
+
+#include "celix_errno.h"
+#include "discovery.h"
+#include "log_helper.h"
+
+struct endpoint_discovery_poller {
+ discovery_pt discovery;
+ hash_map_pt entries;
+ log_helper_pt* loghelper;
+
+ celix_thread_mutex_t pollerLock;
+ celix_thread_t pollerThread;
+
+ unsigned int poll_interval;
+ volatile bool running;
+};
+
+typedef struct endpoint_discovery_poller *endpoint_discovery_poller_pt;
+
+celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_poller_pt *poller);
+celix_status_t endpointDiscoveryPoller_destroy(endpoint_discovery_poller_pt poller);
+
+celix_status_t endpointDiscoveryPoller_addDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url);
+celix_status_t endpointDiscoveryPoller_removeDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url);
+
+celix_status_t endpointDiscoveryPoller_getDiscoveryEndpoints(endpoint_discovery_poller_pt poller, array_list_pt urls);
+
+#endif /* ENDPOINT_DISCOVERY_POLLER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/include/endpoint_discovery_server.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/include/endpoint_discovery_server.h b/remote_services/discovery_common/include/endpoint_discovery_server.h
new file mode 100644
index 0000000..51082b5
--- /dev/null
+++ b/remote_services/discovery_common/include/endpoint_discovery_server.h
@@ -0,0 +1,81 @@
+/**
+ * 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.
+ */
+/*
+ * endpoint_discovery_server.h
+ *
+ * \date Aug 12, 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef ENDPOINT_DISCOVERY_SERVER_H_
+#define ENDPOINT_DISCOVERY_SERVER_H_
+
+#include "celix_errno.h"
+#include "discovery.h"
+
+typedef struct endpoint_discovery_server *endpoint_discovery_server_pt;
+
+/**
+ * Creates and starts a new instance of an endpoint discovery server.
+ *
+ * @param discovery [in] the discovery service itself;
+ * @param context [in] the bundle context;
+ * @param server [out] the pointer to the created instance.
+ * @return CELIX_SUCCESS when successful.
+ */
+celix_status_t endpointDiscoveryServer_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_server_pt *server);
+
+/**
+ * Stops and destroys a given instance of an endpoint discovery server.
+ *
+ * @param server [in] the pointer to the instance to destroy.
+ * @return CELIX_SUCCESS when successful.
+ */
+celix_status_t endpointDiscoveryServer_destroy(endpoint_discovery_server_pt server);
+
+/**
+ * Adds a given endpoint description to expose through the given discovery server.
+ *
+ * @param server [in] the endpoint discovery server to expose the endpoint through;
+ * @param endpoint [in] the endpoint description to expose.
+ * @return CELIX_SUCCESS when successful.
+ */
+celix_status_t endpointDiscoveryServer_addEndpoint(endpoint_discovery_server_pt server, endpoint_description_pt endpoint);
+
+/**
+ * Removes a given endpoint description from exposure through the given discovery server.
+ *
+ * @param server [in] the endpoint discovery server to remove the endpoint from;
+ * @param endpoint [in] the endpoint description to remove.
+ * @return CELIX_SUCCESS when successful.
+ */
+celix_status_t endpointDiscoveryServer_removeEndpoint( endpoint_discovery_server_pt server, endpoint_description_pt endpoint);
+
+/**
+ * Returns the url, which is used by the discovery server to announce the endpoints
+ *
+ * @param server [in] the endpoint discovery server to retrieve the url from
+ * @param url [out] url which is used to announce the endpoints.
+ * @return CELIX_SUCCESS when successful.
+ */
+celix_status_t endpointDiscoveryServer_getUrl(endpoint_discovery_server_pt server, char* url);
+
+
+#endif /* ENDPOINT_DISCOVERY_SERVER_H_ */
[43/54] [abbrv] celix git commit: Merge branch 'release/2.1.0' into
feature/CELIX-417-cmake-refactor
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/examples/mp_pubsub/subscriber/CMakeLists.txt
----------------------------------------------------------------------
diff --cc pubsub/examples/mp_pubsub/subscriber/CMakeLists.txt
index 858efb5,f2d2aaa..1185ec5
--- a/pubsub/examples/mp_pubsub/subscriber/CMakeLists.txt
+++ b/pubsub/examples/mp_pubsub/subscriber/CMakeLists.txt
@@@ -15,17 -15,22 +15,17 @@@
# specific language governing permissions and limitations
# under the License.
- add_bundle(org.apache.celix.pubsub_subscriber.MpSubscriber
-include_directories("private/include")
-include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/examples/mp_pubsub/common/include")
-
-add_celix_bundle( org.apache.celix.pubsub_subscriber.MpSubscriber
++add_celix_bundle(org.apache.celix.pubsub_subscriber.MpSubscriber
SYMBOLIC_NAME "apache_celix_pubsub_mp_subscriber"
VERSION "1.0.0"
SOURCES
private/src/mp_sub_activator.c
private/src/mp_subscriber.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
)
+target_link_libraries(org.apache.celix.pubsub_subscriber.MpSubscriber PRIVATE Celix::framework Celix::pubsub_api)
+target_include_directories(org.apache.celix.pubsub_subscriber.MpSubscriber PRIVATE private/include)
- bundle_files( org.apache.celix.pubsub_subscriber.MpSubscriber
+ celix_bundle_files( org.apache.celix.pubsub_subscriber.MpSubscriber
${PROJECT_SOURCE_DIR}/pubsub/examples/mp_pubsub/msg_descriptors/msg_ew.descriptor
${PROJECT_SOURCE_DIR}/pubsub/examples/mp_pubsub/msg_descriptors/msg_ide.descriptor
${PROJECT_SOURCE_DIR}/pubsub/examples/mp_pubsub/msg_descriptors/msg_kinematics.descriptor
@@@ -37,7 -42,9 +37,7 @@@ celix_bundle_files(org.apache.celix.pub
DESTINATION "META-INF/keys"
)
- bundle_files(org.apache.celix.pubsub_subscriber.MpSubscriber
+ celix_bundle_files(org.apache.celix.pubsub_subscriber.MpSubscriber
- ${PROJECT_SOURCE_DIR}/pubsub/examples/keys/publisher/public
+ ${PROJECT_SOURCE_DIR}/pubsub/examples/keys/publisher/public
DESTINATION "META-INF/keys/publisher"
- )
+ )
-
-target_link_libraries(org.apache.celix.pubsub_subscriber.MpSubscriber celix_framework celix_utils)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/examples/pubsub/publisher/CMakeLists.txt
----------------------------------------------------------------------
diff --cc pubsub/examples/pubsub/publisher/CMakeLists.txt
index 43eabd8,dec002d..176a57e
--- a/pubsub/examples/pubsub/publisher/CMakeLists.txt
+++ b/pubsub/examples/pubsub/publisher/CMakeLists.txt
@@@ -15,35 -15,38 +15,35 @@@
# specific language governing permissions and limitations
# under the License.
- add_bundle(celix_pubsub_poi_publisher
-include_directories("private/include")
-include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-
-add_celix_bundle(org.apache.celix.pubsub_publisher.PoiPublisher
++add_celix_bundle(celix_pubsub_poi_publisher
SYMBOLIC_NAME "apache_celix_pubsub_poi_publisher"
VERSION "1.0.0"
SOURCES
private/src/ps_pub_activator.c
private/src/pubsub_publisher.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
)
-celix_bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher
+target_link_libraries(celix_pubsub_poi_publisher PRIVATE Celix::framework Celix::pubsub_api)
+target_include_directories(celix_pubsub_poi_publisher PRIVATE private/include)
+
- bundle_files(celix_pubsub_poi_publisher
++celix_bundle_files(celix_pubsub_poi_publisher
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/msg_poi1.descriptor
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/msg_poi2.descriptor
DESTINATION "META-INF/descriptors"
)
- bundle_files(celix_pubsub_poi_publisher
-celix_bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher
++celix_bundle_files(celix_pubsub_poi_publisher
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/poi1.properties
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/poi2.properties
DESTINATION "META-INF/topics/pub"
)
- bundle_files(celix_pubsub_poi_publisher
-celix_bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher
++celix_bundle_files(celix_pubsub_poi_publisher
${PROJECT_SOURCE_DIR}/pubsub/examples/keys/publisher
DESTINATION "META-INF/keys"
)
- bundle_files(celix_pubsub_poi_publisher
-celix_bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher
++celix_bundle_files(celix_pubsub_poi_publisher
${PROJECT_SOURCE_DIR}/pubsub/examples/keys/subscriber/public
DESTINATION "META-INF/keys/subscriber"
)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/examples/pubsub/publisher2/CMakeLists.txt
----------------------------------------------------------------------
diff --cc pubsub/examples/pubsub/publisher2/CMakeLists.txt
index ba007c2,1defeb0..30d86ee
--- a/pubsub/examples/pubsub/publisher2/CMakeLists.txt
+++ b/pubsub/examples/pubsub/publisher2/CMakeLists.txt
@@@ -15,36 -15,39 +15,36 @@@
# specific language governing permissions and limitations
# under the License.
- add_bundle(celix_pubsub_poi_publisher2
-include_directories("../publisher/private/include")
-include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-
-add_celix_bundle(org.apache.celix.pubsub_publisher.PoiPublisher2
++add_celix_bundle(celix_pubsub_poi_publisher2
SYMBOLIC_NAME "apache_celix_pubsub_poi_publisher2"
VERSION "1.0.0"
SOURCES
../publisher/private/src/ps_pub_activator.c
../publisher/private/src/pubsub_publisher.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
)
+target_link_libraries(celix_pubsub_poi_publisher2 PRIVATE Celix::framework Celix::pubsub_api)
+target_include_directories(celix_pubsub_poi_publisher2 PRIVATE ../publisher/private/include)
+
- bundle_files(celix_pubsub_poi_publisher2
-celix_bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher2
++celix_bundle_files(celix_pubsub_poi_publisher2
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/msg_poi1.descriptor
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/msg_poi2.descriptor
DESTINATION "META-INF/descriptors"
)
- bundle_files(celix_pubsub_poi_publisher2
-celix_bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher2
++celix_bundle_files(celix_pubsub_poi_publisher2
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/poi1.properties
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/poi2.properties
DESTINATION "META-INF/topics/pub"
)
- bundle_files(celix_pubsub_poi_publisher2
-celix_bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher2
++celix_bundle_files(celix_pubsub_poi_publisher2
${PROJECT_SOURCE_DIR}/pubsub/examples/keys/publisher
DESTINATION "META-INF/keys"
)
- bundle_files(celix_pubsub_poi_publisher2
-celix_bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher2
- ${PROJECT_SOURCE_DIR}/pubsub/examples/keys/subscriber/public
++celix_bundle_files(celix_pubsub_poi_publisher2
+ ${PROJECT_SOURCE_DIR}/pubsub/examples/keys/subscriber/public
DESTINATION "META-INF/keys/subscriber"
)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/examples/pubsub/subscriber/CMakeLists.txt
----------------------------------------------------------------------
diff --cc pubsub/examples/pubsub/subscriber/CMakeLists.txt
index 1ffd39a,8bcec93..0eb13ff
--- a/pubsub/examples/pubsub/subscriber/CMakeLists.txt
+++ b/pubsub/examples/pubsub/subscriber/CMakeLists.txt
@@@ -15,36 -15,41 +15,36 @@@
# specific language governing permissions and limitations
# under the License.
- add_bundle(celix_pubsub_poi_subscriber
-include_directories("private/include")
-include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/common/include")
-
-add_celix_bundle(org.apache.celix.pubsub_subscriber.PoiSubscriber
++add_celix_bundle(celix_pubsub_poi_subscriber
SYMBOLIC_NAME "apache_celix_pubsub_poi_subscriber"
VERSION "1.0.0"
SOURCES
private/src/ps_sub_activator.c
- private/src/pubsub_subscriber.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
+ private/src/pubsub_subscriber.c
)
-celix_bundle_files(org.apache.celix.pubsub_subscriber.PoiSubscriber
+target_link_libraries(celix_pubsub_poi_subscriber PRIVATE Celix::framework Celix::pubsub_api)
+target_include_directories(celix_pubsub_poi_subscriber PRIVATE private/include)
+
+
- bundle_files(celix_pubsub_poi_subscriber
++celix_bundle_files(celix_pubsub_poi_subscriber
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/msg_poi1.descriptor
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/msg_poi2.descriptor
DESTINATION "META-INF/descriptors"
)
- bundle_files(celix_pubsub_poi_subscriber
-celix_bundle_files(org.apache.celix.pubsub_subscriber.PoiSubscriber
++celix_bundle_files(celix_pubsub_poi_subscriber
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/poi1.properties
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/poi2.properties
DESTINATION "META-INF/topics/sub"
)
- bundle_files(celix_pubsub_poi_subscriber
-celix_bundle_files(org.apache.celix.pubsub_subscriber.PoiSubscriber
++celix_bundle_files(celix_pubsub_poi_subscriber
${PROJECT_SOURCE_DIR}/pubsub/examples/keys/subscriber
DESTINATION "META-INF/keys"
)
- bundle_files(celix_pubsub_poi_subscriber
-celix_bundle_files(org.apache.celix.pubsub_subscriber.PoiSubscriber
++celix_bundle_files(celix_pubsub_poi_subscriber
${PROJECT_SOURCE_DIR}/pubsub/examples/keys/publisher/public
DESTINATION "META-INF/keys/publisher"
- )
+ )
-
-target_link_libraries(org.apache.celix.pubsub_subscriber.PoiSubscriber celix_framework celix_utils)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/mock/CMakeLists.txt
----------------------------------------------------------------------
diff --cc pubsub/mock/CMakeLists.txt
index ccc3d20,6313987..e68b1cb
--- a/pubsub/mock/CMakeLists.txt
+++ b/pubsub/mock/CMakeLists.txt
@@@ -18,13 -18,11 +18,13 @@@
#only install if CppuTest is available
find_package(CppUTest QUIET)
if (CPPUTEST_FOUND)
- include_directories(
- ../api
- api
+
- add_library(celix_pubsub_mock STATIC
++ add_library(pubsub_mock STATIC
+ src/publisher_mock.cc
)
- target_include_directories(celix_pubsub_mock PUBLIC api)
- target_link_libraries(celix_pubsub_mock PRIVATE Celix::pubsub_spi ${CPPUTEST_LIBRARY})
- target_include_directories(celix_pubsub_mock PRIVATE SYSTEM
- include_directories(SYSTEM
++ target_include_directories(pubsub_mock PUBLIC api)
++ target_link_libraries(pubsub_mock PRIVATE Celix::pubsub_spi ${CPPUTEST_LIBRARY})
++ target_include_directories(pubsub_mock PRIVATE SYSTEM
${CPPUTEST_INCLUDE_DIR}
)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/pubsub_admin_udp_mc/CMakeLists.txt
----------------------------------------------------------------------
diff --cc pubsub/pubsub_admin_udp_mc/CMakeLists.txt
index 87858e3,fdf43ac..6981c87
--- a/pubsub/pubsub_admin_udp_mc/CMakeLists.txt
+++ b/pubsub/pubsub_admin_udp_mc/CMakeLists.txt
@@@ -17,28 -17,33 +17,28 @@@
find_package(Jansson REQUIRED)
- add_bundle(celix_pubsub_admin_udp_multicast
-include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/dfi/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-include_directories("private/include")
-include_directories("public/include")
-include_directories("${JANSSON_INCLUDE_DIR}")
-
-add_celix_bundle(org.apache.celix.pubsub_admin.PubSubAdminUdpMc
++add_celix_bundle(celix_pubsub_admin_udp_multicast
BUNDLE_SYMBOLICNAME "apache_celix_pubsub_admin_udp_multicast"
VERSION "1.0.0"
SOURCES
- private/src/psa_activator.c
- private/src/pubsub_admin_impl.c
- private/src/topic_subscription.c
- private/src/topic_publication.c
- private/src/large_udp.c
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_endpoint.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_admin_match.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
+ src/psa_activator.c
+ src/pubsub_admin_impl.c
+ src/topic_subscription.c
+ src/topic_publication.c
+ src/large_udp.c
)
-set_target_properties(org.apache.celix.pubsub_admin.PubSubAdminUdpMc PROPERTIES INSTALL_RPATH "$ORIGIN")
-target_link_libraries(org.apache.celix.pubsub_admin.PubSubAdminUdpMc celix_framework celix_utils celix_dfi)
-install_celix_bundle(org.apache.celix.pubsub_admin.PubSubAdminUdpMc)
+target_include_directories(celix_pubsub_admin_udp_multicast PRIVATE
+ src
+ ${JANSSON_INCLUDE_DIR}
+)
+
+set_target_properties(celix_pubsub_admin_udp_multicast PROPERTIES INSTALL_RPATH "$ORIGIN")
+target_link_libraries(celix_pubsub_admin_udp_multicast PRIVATE Celix::pubsub_spi Celix::framework Celix::dfi Celix::log_helper)
+
- install_bundle(celix_pubsub_admin_udp_multicast)
++install_celix_bundle(celix_pubsub_admin_udp_multicast)
+
+add_library(Celix::pubsub_admin_udp_multicast ALIAS celix_pubsub_admin_udp_multicast)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/pubsub_admin_zmq/CMakeLists.txt
----------------------------------------------------------------------
diff --cc pubsub/pubsub_admin_zmq/CMakeLists.txt
index 9d57756,962310e..65d2107
--- a/pubsub/pubsub_admin_zmq/CMakeLists.txt
+++ b/pubsub/pubsub_admin_zmq/CMakeLists.txt
@@@ -30,31 -41,23 +30,31 @@@ if (BUILD_PUBSUB_PSA_ZMQ
set (ZMQ_CRYPTO_C "private/src/zmq_crypto.c")
endif()
- add_bundle(celix_pubsub_admin_zmq
- add_celix_bundle(org.apache.celix.pubsub_admin.PubSubAdminZmq
- BUNDLE_SYMBOLICNAME "apache_celix_pubsub_admin_zmq"
- VERSION "1.0.0"
- SOURCES
- private/src/psa_activator.c
- private/src/pubsub_admin_impl.c
- private/src/topic_subscription.c
- private/src/topic_publication.c
- ${ZMQ_CRYPTO_C}
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_endpoint.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_admin_match.c
++ add_celix_bundle(celix_pubsub_admin_zmq
+ BUNDLE_SYMBOLICNAME "apache_celix_pubsub_admin_zmq"
+ VERSION "1.0.0"
+ SOURCES
+ src/psa_activator.c
+ src/pubsub_admin_impl.c
+ src/topic_subscription.c
+ src/topic_publication.c
+ ${ZMQ_CRYPTO_C}
+ )
+
+ set_target_properties(celix_pubsub_admin_zmq PROPERTIES INSTALL_RPATH "$ORIGIN")
+ target_link_libraries(celix_pubsub_admin_zmq PRIVATE
+ Celix::pubsub_spi
+ Celix::framework Celix::dfi Celix::log_helper
+ ${ZMQ_LIBRARIES} ${CZMQ_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARY}
+ )
+ target_include_directories(celix_pubsub_admin_zmq PRIVATE
+ ${ZMQ_INCLUDE_DIR}
+ ${CZMQ_INCLUDE_DIR}
+ ${JANSSON_INCLUDE_DIR}
+ src
)
- install_bundle(org.apache.celix.pubsub_admin.PubSubAdminZmq)
- set_target_properties(org.apache.celix.pubsub_admin.PubSubAdminZmq PROPERTIES INSTALL_RPATH "$ORIGIN")
- target_link_libraries(org.apache.celix.pubsub_admin.PubSubAdminZmq celix_framework celix_utils celix_dfi ${ZMQ_LIBRARIES} ${CZMQ_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARY})
- install_celix_bundle(org.apache.celix.pubsub_admin.PubSubAdminZmq)
++ install_celix_bundle(celix_pubsub_admin_zmq)
+ add_library(Celix::pubsub_admin_zmq ALIAS celix_pubsub_admin_zmq)
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.c
----------------------------------------------------------------------
diff --cc pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.c
index 29ead0c,0000000..2dcec25
mode 100644,000000..100644
--- a/pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.c
+++ b/pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.c
@@@ -1,1040 -1,0 +1,1040 @@@
+/**
+ *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.
+ */
+/*
+ * pubsub_admin_impl.c
+ *
+ * \date Sep 30, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include "pubsub_admin_impl.h"
+#include <zmq.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+#ifndef ANDROID
+#include <ifaddrs.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "constants.h"
+#include "utils.h"
+#include "hash_map.h"
+#include "array_list.h"
+#include "bundle_context.h"
+#include "bundle.h"
+#include "service_reference.h"
+#include "service_registration.h"
+#include "log_helper.h"
+#include "log_service.h"
+#include "celix_threads.h"
+#include "service_factory.h"
+
+#include "topic_subscription.h"
+#include "topic_publication.h"
+#include "pubsub_endpoint.h"
+#include "pubsub_utils.h"
- #include "subscriber.h"
++#include "pubsub/subscriber.h"
+
+#define MAX_KEY_FOLDER_PATH_LENGTH 512
+
+static const char *DEFAULT_IP = "127.0.0.1";
+
+static celix_status_t pubsubAdmin_getIpAdress(const char* interface, char** ip);
+static celix_status_t pubsubAdmin_addSubscriptionToPendingList(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
+static celix_status_t pubsubAdmin_addAnySubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
+
+static celix_status_t pubsubAdmin_getBestSerializer(pubsub_admin_pt admin,pubsub_endpoint_pt ep, pubsub_serializer_service_t **serSvc);
+static void connectTopicPubSubToSerializer(pubsub_admin_pt admin,pubsub_serializer_service_t *serializer,void *topicPubSub,bool isPublication);
+static void disconnectTopicPubSubFromSerializer(pubsub_admin_pt admin,void *topicPubSub,bool isPublication);
+
+celix_status_t pubsubAdmin_create(bundle_context_pt context, pubsub_admin_pt *admin) {
+ celix_status_t status = CELIX_SUCCESS;
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ if (!zsys_has_curve()){
+ printf("PSA_ZMQ: zeromq curve unsupported\n");
+ return CELIX_SERVICE_EXCEPTION;
+ }
+#endif
+
+ *admin = calloc(1, sizeof(**admin));
+
+ if (!*admin) {
+ status = CELIX_ENOMEM;
+ }
+ else{
+
+ const char *ip = NULL;
+ char *detectedIp = NULL;
+ (*admin)->bundle_context= context;
+ (*admin)->localPublications = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ (*admin)->subscriptions = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ (*admin)->pendingSubscriptions = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ (*admin)->externalPublications = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ (*admin)->topicSubscriptionsPerSerializer = hashMap_create(NULL, NULL, NULL, NULL);
+ (*admin)->topicPublicationsPerSerializer = hashMap_create(NULL, NULL, NULL, NULL);
+ arrayList_create(&((*admin)->noSerializerSubscriptions));
+ arrayList_create(&((*admin)->noSerializerPublications));
+ arrayList_create(&((*admin)->serializerList));
+
+ celixThreadMutex_create(&(*admin)->localPublicationsLock, NULL);
+ celixThreadMutex_create(&(*admin)->subscriptionsLock, NULL);
+ celixThreadMutex_create(&(*admin)->externalPublicationsLock, NULL);
+ celixThreadMutex_create(&(*admin)->serializerListLock, NULL);
+ celixThreadMutex_create(&(*admin)->usedSerializersLock, NULL);
+
+ celixThreadMutexAttr_create(&(*admin)->noSerializerPendingsAttr);
+ celixThreadMutexAttr_settype(&(*admin)->noSerializerPendingsAttr, CELIX_THREAD_MUTEX_RECURSIVE);
+ celixThreadMutex_create(&(*admin)->noSerializerPendingsLock, &(*admin)->noSerializerPendingsAttr);
+
+ celixThreadMutexAttr_create(&(*admin)->pendingSubscriptionsAttr);
+ celixThreadMutexAttr_settype(&(*admin)->pendingSubscriptionsAttr, CELIX_THREAD_MUTEX_RECURSIVE);
+ celixThreadMutex_create(&(*admin)->pendingSubscriptionsLock, &(*admin)->pendingSubscriptionsAttr);
+
+ if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
+ logHelper_start((*admin)->loghelper);
+ }
+
+ bundleContext_getProperty(context,PSA_IP , &ip);
+
+#ifndef ANDROID
+ if (ip == NULL) {
+ const char *interface = NULL;
+
+ bundleContext_getProperty(context, PSA_ITF, &interface);
+ if (pubsubAdmin_getIpAdress(interface, &detectedIp) != CELIX_SUCCESS) {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "PSA_ZMQ: Could not retrieve IP adress for interface %s", interface);
+ }
+
+ ip = detectedIp;
+ }
+#endif
+
+ if (ip != NULL) {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "PSA_ZMQ: Using %s for service annunciation", ip);
+ (*admin)->ipAddress = strdup(ip);
+ }
+ else {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "PSA_ZMQ: No IP address for service annunciation set. Using %s", DEFAULT_IP);
+ (*admin)->ipAddress = strdup(DEFAULT_IP);
+ }
+
+ if (detectedIp != NULL) {
+ free(detectedIp);
+ }
+
+ const char* basePortStr = NULL;
+ const char* maxPortStr = NULL;
+ char* endptrBase = NULL;
+ char* endptrMax = NULL;
+ bundleContext_getPropertyWithDefault(context, PSA_ZMQ_BASE_PORT, "PSA_ZMQ_DEFAULT_BASE_PORT", &basePortStr);
+ bundleContext_getPropertyWithDefault(context, PSA_ZMQ_MAX_PORT, "PSA_ZMQ_DEFAULT_MAX_PORT", &maxPortStr);
+ (*admin)->basePort = strtol(basePortStr, &endptrBase, 10);
+ (*admin)->maxPort = strtol(maxPortStr, &endptrMax, 10);
+ if (*endptrBase != '\0') {
+ (*admin)->basePort = PSA_ZMQ_DEFAULT_BASE_PORT;
+ }
+ if (*endptrMax != '\0') {
+ (*admin)->maxPort = PSA_ZMQ_DEFAULT_MAX_PORT;
+ }
+
+ printf("PSA Using base port %u to max port %u\n", (*admin)->basePort, (*admin)->maxPort);
+
+ // Disable Signal Handling by CZMQ
+ setenv("ZSYS_SIGHANDLER", "false", true);
+
+ const char *nrZmqThreads = NULL;
+ bundleContext_getProperty(context, "PSA_NR_ZMQ_THREADS", &nrZmqThreads);
+
+ if(nrZmqThreads != NULL) {
+ char *endPtr = NULL;
+ unsigned int nrThreads = strtoul(nrZmqThreads, &endPtr, 10);
+ if(endPtr != nrZmqThreads && nrThreads > 0 && nrThreads < 50) {
+ zsys_set_io_threads(nrThreads);
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "PSA_ZMQ: Using %d threads for ZMQ", nrThreads);
+ printf("PSA_ZMQ: Using %d threads for ZMQ\n", nrThreads);
+ }
+ }
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ // Setup authenticator
+ zactor_t* auth = zactor_new (zauth, NULL);
+ zstr_sendx(auth, "VERBOSE", NULL);
+
+ // Load all public keys of subscribers into the application
+ // This step is done for authenticating subscribers
+ char curve_folder_path[MAX_KEY_FOLDER_PATH_LENGTH];
+ char* keys_bundle_dir = pubsub_getKeysBundleDir(context);
+ snprintf(curve_folder_path, MAX_KEY_FOLDER_PATH_LENGTH, "%s/META-INF/keys/subscriber/public", keys_bundle_dir);
+ zstr_sendx (auth, "CURVE", curve_folder_path, NULL);
+ free(keys_bundle_dir);
+
+ (*admin)->zmq_auth = auth;
+#endif
+
+ }
+
+ return status;
+}
+
+
+celix_status_t pubsubAdmin_destroy(pubsub_admin_pt admin)
+{
+ celix_status_t status = CELIX_SUCCESS;
+
+ free(admin->ipAddress);
+
+ celixThreadMutex_lock(&admin->pendingSubscriptionsLock);
+ hash_map_iterator_pt iter = hashMapIterator_create(admin->pendingSubscriptions);
+ while(hashMapIterator_hasNext(iter)){
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ free((char*)hashMapEntry_getKey(entry));
+ arrayList_destroy((array_list_pt)hashMapEntry_getValue(entry));
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(admin->pendingSubscriptions,false,false);
+ celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);
+
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+ hashMap_destroy(admin->subscriptions,false,false);
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ hashMap_destroy(admin->localPublications,true,false);
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+ celixThreadMutex_lock(&admin->externalPublicationsLock);
+ iter = hashMapIterator_create(admin->externalPublications);
+ while(hashMapIterator_hasNext(iter)){
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ free((char*)hashMapEntry_getKey(entry));
+ arrayList_destroy((array_list_pt)hashMapEntry_getValue(entry));
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(admin->externalPublications,false,false);
+ celixThreadMutex_unlock(&admin->externalPublicationsLock);
+
+ celixThreadMutex_lock(&admin->serializerListLock);
+ arrayList_destroy(admin->serializerList);
+ celixThreadMutex_unlock(&admin->serializerListLock);
+
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_destroy(admin->noSerializerSubscriptions);
+ arrayList_destroy(admin->noSerializerPublications);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+
+
+ celixThreadMutex_lock(&admin->usedSerializersLock);
+
+ iter = hashMapIterator_create(admin->topicSubscriptionsPerSerializer);
+ while(hashMapIterator_hasNext(iter)){
+ arrayList_destroy((array_list_pt)hashMapIterator_nextValue(iter));
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(admin->topicSubscriptionsPerSerializer,false,false);
+
+ iter = hashMapIterator_create(admin->topicPublicationsPerSerializer);
+ while(hashMapIterator_hasNext(iter)){
+ arrayList_destroy((array_list_pt)hashMapIterator_nextValue(iter));
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(admin->topicPublicationsPerSerializer,false,false);
+
+ celixThreadMutex_unlock(&admin->usedSerializersLock);
+
+ celixThreadMutex_destroy(&admin->usedSerializersLock);
+ celixThreadMutex_destroy(&admin->serializerListLock);
+ celixThreadMutex_destroy(&admin->pendingSubscriptionsLock);
+
+ celixThreadMutexAttr_destroy(&admin->noSerializerPendingsAttr);
+ celixThreadMutex_destroy(&admin->noSerializerPendingsLock);
+
+ celixThreadMutexAttr_destroy(&admin->pendingSubscriptionsAttr);
+ celixThreadMutex_destroy(&admin->subscriptionsLock);
+
+ celixThreadMutex_destroy(&admin->localPublicationsLock);
+ celixThreadMutex_destroy(&admin->externalPublicationsLock);
+
+ logHelper_stop(admin->loghelper);
+
+ logHelper_destroy(&admin->loghelper);
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ if (admin->zmq_auth != NULL){
+ zactor_destroy(&(admin->zmq_auth));
+ }
+#endif
+
+ free(admin);
+
+ return status;
+}
+
+static celix_status_t pubsubAdmin_addAnySubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+
+ topic_subscription_pt any_sub = hashMap_get(admin->subscriptions,PUBSUB_ANY_SUB_TOPIC);
+
+ if(any_sub==NULL){
+
+ int i;
+ pubsub_serializer_service_t *best_serializer = NULL;
+ if( (status=pubsubAdmin_getBestSerializer(admin, subEP, &best_serializer)) == CELIX_SUCCESS){
+ status = pubsub_topicSubscriptionCreate(admin->bundle_context, PUBSUB_SUBSCRIBER_SCOPE_DEFAULT, PUBSUB_ANY_SUB_TOPIC, best_serializer, &any_sub);
+ }
+ else{
+ printf("PSA_ZMQ: Cannot find a serializer for subscribing topic %s. Adding it to pending list.\n",subEP->topic);
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_add(admin->noSerializerSubscriptions,subEP);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+
+ if (status == CELIX_SUCCESS){
+
+ /* Connect all internal publishers */
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ hash_map_iterator_pt lp_iter =hashMapIterator_create(admin->localPublications);
+ while(hashMapIterator_hasNext(lp_iter)){
+ service_factory_pt factory = (service_factory_pt)hashMapIterator_nextValue(lp_iter);
+ topic_publication_pt topic_pubs = (topic_publication_pt)factory->handle;
+ array_list_pt topic_publishers = pubsub_topicPublicationGetPublisherList(topic_pubs);
+
+ if(topic_publishers!=NULL){
+ for(i=0;i<arrayList_size(topic_publishers);i++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(topic_publishers,i);
+ if(pubEP->endpoint !=NULL){
+ status += pubsub_topicSubscriptionConnectPublisher(any_sub,pubEP->endpoint);
+ }
+ }
+ arrayList_destroy(topic_publishers);
+ }
+ }
+ hashMapIterator_destroy(lp_iter);
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+ /* Connect also all external publishers */
+ celixThreadMutex_lock(&admin->externalPublicationsLock);
+ hash_map_iterator_pt extp_iter =hashMapIterator_create(admin->externalPublications);
+ while(hashMapIterator_hasNext(extp_iter)){
+ array_list_pt ext_pub_list = (array_list_pt)hashMapIterator_nextValue(extp_iter);
+ if(ext_pub_list!=NULL){
+ for(i=0;i<arrayList_size(ext_pub_list);i++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
+ if(pubEP->endpoint !=NULL){
+ status += pubsub_topicSubscriptionConnectPublisher(any_sub,pubEP->endpoint);
+ }
+ }
+ }
+ }
+ hashMapIterator_destroy(extp_iter);
+ celixThreadMutex_unlock(&admin->externalPublicationsLock);
+
+
+ pubsub_topicSubscriptionAddSubscriber(any_sub,subEP);
+
+ status += pubsub_topicSubscriptionStart(any_sub);
+
+ }
+
+ if (status == CELIX_SUCCESS){
+ hashMap_put(admin->subscriptions,strdup(PUBSUB_ANY_SUB_TOPIC),any_sub);
+ connectTopicPubSubToSerializer(admin, best_serializer, any_sub, false);
+ }
+
+ }
+
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ return status;
+}
+
+celix_status_t pubsubAdmin_addSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ printf("PSA_ZMQ: Received subscription [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n",subEP->frameworkUUID,subEP->serviceID,subEP->scope, subEP->topic);
+
+ if(strcmp(subEP->topic,PUBSUB_ANY_SUB_TOPIC)==0){
+ return pubsubAdmin_addAnySubscription(admin,subEP);
+ }
+
+ /* Check if we already know some publisher about this topic, otherwise let's put the subscription in the pending hashmap */
+ celixThreadMutex_lock(&admin->pendingSubscriptionsLock);
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ celixThreadMutex_lock(&admin->externalPublicationsLock);
+
+ char* scope_topic = createScopeTopicKey(subEP->scope, subEP->topic);
+
+ service_factory_pt factory = (service_factory_pt)hashMap_get(admin->localPublications,scope_topic);
+ array_list_pt ext_pub_list = (array_list_pt)hashMap_get(admin->externalPublications,scope_topic);
+
+ if(factory==NULL && ext_pub_list==NULL){ //No (local or external) publishers yet for this topic
+ pubsubAdmin_addSubscriptionToPendingList(admin,subEP);
+ }
+ else{
+ int i;
+ topic_subscription_pt subscription = hashMap_get(admin->subscriptions, scope_topic);
+
+ if(subscription == NULL) {
+ pubsub_serializer_service_t *best_serializer = NULL;
+ if( (status=pubsubAdmin_getBestSerializer(admin, subEP, &best_serializer)) == CELIX_SUCCESS){
+ status += pubsub_topicSubscriptionCreate(admin->bundle_context,subEP->scope, subEP->topic, best_serializer, &subscription);
+ }
+ else{
+ printf("PSA_ZMQ: Cannot find a serializer for subscribing topic %s. Adding it to pending list.\n",subEP->topic);
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_add(admin->noSerializerSubscriptions,subEP);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+
+ if (status==CELIX_SUCCESS){
+
+ /* Try to connect internal publishers */
+ if(factory!=NULL){
+ topic_publication_pt topic_pubs = (topic_publication_pt)factory->handle;
+ array_list_pt topic_publishers = pubsub_topicPublicationGetPublisherList(topic_pubs);
+
+ if(topic_publishers!=NULL){
+ for(i=0;i<arrayList_size(topic_publishers);i++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(topic_publishers,i);
+ if(pubEP->endpoint !=NULL){
+ status += pubsub_topicSubscriptionConnectPublisher(subscription,pubEP->endpoint);
+ }
+ }
+ arrayList_destroy(topic_publishers);
+ }
+
+ }
+
+ /* Look also for external publishers */
+ if(ext_pub_list!=NULL){
+ for(i=0;i<arrayList_size(ext_pub_list);i++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
+ if(pubEP->endpoint !=NULL){
+ status += pubsub_topicSubscriptionConnectPublisher(subscription,pubEP->endpoint);
+ }
+ }
+ }
+
+ pubsub_topicSubscriptionAddSubscriber(subscription,subEP);
+
+ status += pubsub_topicSubscriptionStart(subscription);
+
+ }
+
+ if(status==CELIX_SUCCESS){
+
+ hashMap_put(admin->subscriptions,strdup(scope_topic),subscription);
+
+ connectTopicPubSubToSerializer(admin, best_serializer, subscription, false);
+ }
+ }
+
+ if (status == CELIX_SUCCESS){
+ pubsub_topicIncreaseNrSubscribers(subscription);
+ }
+ }
+
+ free(scope_topic);
+ celixThreadMutex_unlock(&admin->externalPublicationsLock);
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+ celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);
+
+ return status;
+
+}
+
+celix_status_t pubsubAdmin_removeSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ printf("PSA_ZMQ: Removing subscription [FWUUID=%s bundleID=%ld topic=%s]\n",subEP->frameworkUUID,subEP->serviceID,subEP->topic);
+
+ char* scope_topic = createScopeTopicKey(subEP->scope, subEP->topic);
+
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+ topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic);
+ if(sub!=NULL){
+ pubsub_topicDecreaseNrSubscribers(sub);
+ if(pubsub_topicGetNrSubscribers(sub) == 0) {
+ status = pubsub_topicSubscriptionRemoveSubscriber(sub,subEP);
+ }
+ }
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ if(sub==NULL){
+ /* Maybe the endpoint was pending */
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ if(!arrayList_removeElement(admin->noSerializerSubscriptions, subEP)){
+ status = CELIX_ILLEGAL_STATE;
+ }
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+
+ free(scope_topic);
+
+
+
+ return status;
+
+}
+
+celix_status_t pubsubAdmin_addPublication(pubsub_admin_pt admin, pubsub_endpoint_pt pubEP) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ printf("PSA_ZMQ: Received publication [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n", pubEP->frameworkUUID, pubEP->serviceID, pubEP->scope, pubEP->topic);
+
+ const char* fwUUID = NULL;
+
+ bundleContext_getProperty(admin->bundle_context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &fwUUID);
+ if (fwUUID == NULL) {
+ printf("PSA_ZMQ: Cannot retrieve fwUUID.\n");
+ return CELIX_INVALID_BUNDLE_CONTEXT;
+ }
+
+ char *scope_topic = createScopeTopicKey(pubEP->scope, pubEP->topic);
+
+ if ((strcmp(pubEP->frameworkUUID, fwUUID) == 0) && (pubEP->endpoint == NULL)) {
+
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+
+ service_factory_pt factory = (service_factory_pt) hashMap_get(admin->localPublications, scope_topic);
+
+ if (factory == NULL) {
+ topic_publication_pt pub = NULL;
+ pubsub_serializer_service_t *best_serializer = NULL;
+ if( (status=pubsubAdmin_getBestSerializer(admin, pubEP, &best_serializer)) == CELIX_SUCCESS){
+ status = pubsub_topicPublicationCreate(admin->bundle_context, pubEP, best_serializer, admin->ipAddress, admin->basePort, admin->maxPort, &pub);
+ }
+ else{
+ printf("PSA_ZMQ: Cannot find a serializer for publishing topic %s. Adding it to pending list.\n", pubEP->topic);
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_add(admin->noSerializerPublications,pubEP);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = pubsub_topicPublicationStart(admin->bundle_context, pub, &factory);
+ if (status == CELIX_SUCCESS && factory != NULL) {
+ hashMap_put(admin->localPublications, strdup(scope_topic), factory);
+ connectTopicPubSubToSerializer(admin, best_serializer, pub, true);
+ }
+ } else {
+ printf("PSA_ZMQ: Cannot create a topicPublication for scope=%s, topic=%s (bundle %ld).\n", pubEP->scope, pubEP->topic, pubEP->serviceID);
+ }
+ } else {
+ //just add the new EP to the list
+ topic_publication_pt pub = (topic_publication_pt) factory->handle;
+ pubsub_topicPublicationAddPublisherEP(pub, pubEP);
+ }
+
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+ }
+ else{
+
+ celixThreadMutex_lock(&admin->externalPublicationsLock);
+ array_list_pt ext_pub_list = (array_list_pt) hashMap_get(admin->externalPublications, scope_topic);
+ if (ext_pub_list == NULL) {
+ arrayList_create(&ext_pub_list);
+ hashMap_put(admin->externalPublications, strdup(scope_topic), ext_pub_list);
+ }
+
+ arrayList_add(ext_pub_list, pubEP);
+
+ celixThreadMutex_unlock(&admin->externalPublicationsLock);
+ }
+
+ /* Re-evaluate the pending subscriptions */
+ celixThreadMutex_lock(&admin->pendingSubscriptionsLock);
+
+ hash_map_entry_pt pendingSub = hashMap_getEntry(admin->pendingSubscriptions, scope_topic);
+ if (pendingSub != NULL) { //There were pending subscription for the just published topic. Let's connect them.
+ char* topic = (char*) hashMapEntry_getKey(pendingSub);
+ array_list_pt pendingSubList = (array_list_pt) hashMapEntry_getValue(pendingSub);
+ int i;
+ for (i = 0; i < arrayList_size(pendingSubList); i++) {
+ pubsub_endpoint_pt subEP = (pubsub_endpoint_pt) arrayList_get(pendingSubList, i);
+ pubsubAdmin_addSubscription(admin, subEP);
+ }
+ hashMap_remove(admin->pendingSubscriptions, scope_topic);
+ arrayList_clear(pendingSubList);
+ arrayList_destroy(pendingSubList);
+ free(topic);
+ }
+
+ celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);
+
+ /* Connect the new publisher to the subscription for his topic, if there is any */
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+
+ topic_subscription_pt sub = (topic_subscription_pt) hashMap_get(admin->subscriptions, scope_topic);
+ if (sub != NULL && pubEP->endpoint != NULL) {
+ pubsub_topicSubscriptionAddConnectPublisherToPendingList(sub, pubEP->endpoint);
+ }
+
+ /* And check also for ANY subscription */
+ topic_subscription_pt any_sub = (topic_subscription_pt) hashMap_get(admin->subscriptions, PUBSUB_ANY_SUB_TOPIC);
+ if (any_sub != NULL && pubEP->endpoint != NULL) {
+ pubsub_topicSubscriptionAddConnectPublisherToPendingList(any_sub, pubEP->endpoint);
+ }
+
+ free(scope_topic);
+
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ return status;
+
+}
+
+celix_status_t pubsubAdmin_removePublication(pubsub_admin_pt admin,pubsub_endpoint_pt pubEP){
+ celix_status_t status = CELIX_SUCCESS;
+ int count = 0;
+
+ printf("PSA_ZMQ: Removing publication [FWUUID=%s bundleID=%ld topic=%s]\n",pubEP->frameworkUUID,pubEP->serviceID,pubEP->topic);
+
+ const char* fwUUID = NULL;
+
+ bundleContext_getProperty(admin->bundle_context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
+ if(fwUUID==NULL){
+ printf("PSA_ZMQ: Cannot retrieve fwUUID.\n");
+ return CELIX_INVALID_BUNDLE_CONTEXT;
+ }
+ char *scope_topic = createScopeTopicKey(pubEP->scope, pubEP->topic);
+
+ if(strcmp(pubEP->frameworkUUID,fwUUID)==0){
+
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ service_factory_pt factory = (service_factory_pt)hashMap_get(admin->localPublications,scope_topic);
+ if(factory!=NULL){
+ topic_publication_pt pub = (topic_publication_pt)factory->handle;
+ pubsub_topicPublicationRemovePublisherEP(pub,pubEP);
+ }
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+ if(factory==NULL){
+ /* Maybe the endpoint was pending */
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ if(!arrayList_removeElement(admin->noSerializerPublications, pubEP)){
+ status = CELIX_ILLEGAL_STATE;
+ }
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+ }
+ else{
+
+ celixThreadMutex_lock(&admin->externalPublicationsLock);
+ array_list_pt ext_pub_list = (array_list_pt)hashMap_get(admin->externalPublications,scope_topic);
+ if(ext_pub_list!=NULL){
+ int i;
+ bool found = false;
+ for(i=0;!found && i<arrayList_size(ext_pub_list);i++){
+ pubsub_endpoint_pt p = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
+ found = pubsubEndpoint_equals(pubEP,p);
+ if (found){
+ arrayList_remove(ext_pub_list,i);
+ }
+ }
+ // Check if there are more publishers on the same endpoint (happens when 1 celix-instance with multiple bundles publish in same topic)
+ for(i=0; i<arrayList_size(ext_pub_list);i++) {
+ pubsub_endpoint_pt p = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
+ if (strcmp(pubEP->endpoint,p->endpoint) == 0) {
+ count++;
+ }
+ }
+
+ if(arrayList_size(ext_pub_list)==0){
+ hash_map_entry_pt entry = hashMap_getEntry(admin->externalPublications,scope_topic);
+ char* topic = (char*)hashMapEntry_getKey(entry);
+ array_list_pt list = (array_list_pt)hashMapEntry_getValue(entry);
+ hashMap_remove(admin->externalPublications,topic);
+ arrayList_destroy(list);
+ free(topic);
+ }
+ }
+
+ celixThreadMutex_unlock(&admin->externalPublicationsLock);
+ }
+
+ /* Check if this publisher was connected to one of our subscribers*/
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+
+ topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic);
+ if(sub!=NULL && pubEP->endpoint!=NULL && count == 0){
+ pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(sub,pubEP->endpoint);
+ }
+
+ /* And check also for ANY subscription */
+ topic_subscription_pt any_sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,PUBSUB_ANY_SUB_TOPIC);
+ if(any_sub!=NULL && pubEP->endpoint!=NULL && count == 0){
+ pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(any_sub,pubEP->endpoint);
+ }
+
+ free(scope_topic);
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ return status;
+
+}
+
+celix_status_t pubsubAdmin_closeAllPublications(pubsub_admin_pt admin, char *scope, char* topic){
+ celix_status_t status = CELIX_SUCCESS;
+
+ printf("PSA_ZMQ: Closing all publications\n");
+
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ char *scope_topic = createScopeTopicKey(scope, topic);
+ hash_map_entry_pt pubsvc_entry = (hash_map_entry_pt)hashMap_getEntry(admin->localPublications,scope_topic);
+ if(pubsvc_entry!=NULL){
+ char* key = (char*)hashMapEntry_getKey(pubsvc_entry);
+ service_factory_pt factory= (service_factory_pt)hashMapEntry_getValue(pubsvc_entry);
+ topic_publication_pt pub = (topic_publication_pt)factory->handle;
+ status += pubsub_topicPublicationStop(pub);
+ disconnectTopicPubSubFromSerializer(admin, pub, true);
+ status += pubsub_topicPublicationDestroy(pub);
+ hashMap_remove(admin->localPublications,scope_topic);
+ free(key);
+ free(factory);
+ }
+ free(scope_topic);
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+ return status;
+
+}
+
+celix_status_t pubsubAdmin_closeAllSubscriptions(pubsub_admin_pt admin,char* scope,char* topic){
+ celix_status_t status = CELIX_SUCCESS;
+
+ printf("PSA_ZMQ: Closing all subscriptions\n");
+
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+ char *scope_topic = createScopeTopicKey(scope, topic);
+ hash_map_entry_pt sub_entry = (hash_map_entry_pt)hashMap_getEntry(admin->subscriptions,scope_topic);
+ if(sub_entry!=NULL){
+ char* topic = (char*)hashMapEntry_getKey(sub_entry);
+
+ topic_subscription_pt ts = (topic_subscription_pt)hashMapEntry_getValue(sub_entry);
+ status += pubsub_topicSubscriptionStop(ts);
+ disconnectTopicPubSubFromSerializer(admin, ts, false);
+ status += pubsub_topicSubscriptionDestroy(ts);
+ hashMap_remove(admin->subscriptions,scope_topic);
+ free(topic);
+
+ }
+ free(scope_topic);
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ return status;
+
+}
+
+
+#ifndef ANDROID
+static celix_status_t pubsubAdmin_getIpAdress(const char* interface, char** ip) {
+ celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+
+ struct ifaddrs *ifaddr, *ifa;
+ char host[NI_MAXHOST];
+
+ if (getifaddrs(&ifaddr) != -1)
+ {
+ for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
+ {
+ if (ifa->ifa_addr == NULL)
+ continue;
+
+ if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
+ if (interface == NULL) {
+ *ip = strdup(host);
+ status = CELIX_SUCCESS;
+ }
+ else if (strcmp(ifa->ifa_name, interface) == 0) {
+ *ip = strdup(host);
+ status = CELIX_SUCCESS;
+ }
+ }
+ }
+
+ freeifaddrs(ifaddr);
+ }
+
+ return status;
+}
+#endif
+
+static celix_status_t pubsubAdmin_addSubscriptionToPendingList(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+ char* scope_topic = createScopeTopicKey(subEP->scope, subEP->topic);
+ array_list_pt pendingListPerTopic = hashMap_get(admin->pendingSubscriptions,scope_topic);
+ if(pendingListPerTopic==NULL){
+ arrayList_create(&pendingListPerTopic);
+ hashMap_put(admin->pendingSubscriptions,strdup(scope_topic),pendingListPerTopic);
+ }
+ arrayList_add(pendingListPerTopic,subEP);
+ free(scope_topic);
+ return status;
+}
+
+celix_status_t pubsubAdmin_serializerAdded(void * handle, service_reference_pt reference, void * service){
+ /* Assumption: serializers are all available at startup.
+ * If a new (possibly better) serializer is installed and started, already created topic_publications/subscriptions will not be destroyed and recreated */
+
+ celix_status_t status = CELIX_SUCCESS;
+ int i=0;
+
+ const char *serType = NULL;
+ serviceReference_getProperty(reference, PUBSUB_SERIALIZER_TYPE_KEY,&serType);
+ if(serType == NULL){
+ printf("Serializer serviceReference %p has no pubsub_serializer.type property specified\n",reference);
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+ pubsub_admin_pt admin = (pubsub_admin_pt)handle;
+ celixThreadMutex_lock(&admin->serializerListLock);
+ arrayList_add(admin->serializerList, reference);
+ celixThreadMutex_unlock(&admin->serializerListLock);
+
+ /* Now let's re-evaluate the pending */
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+
+ for(i=0;i<arrayList_size(admin->noSerializerSubscriptions);i++){
+ pubsub_endpoint_pt ep = (pubsub_endpoint_pt)arrayList_get(admin->noSerializerSubscriptions,i);
+ pubsub_serializer_service_t *best_serializer = NULL;
+ pubsubAdmin_getBestSerializer(admin, ep, &best_serializer);
+ if(best_serializer != NULL){ /* Finally we have a valid serializer! */
+ pubsubAdmin_addSubscription(admin, ep);
+ }
+ }
+
+ for(i=0;i<arrayList_size(admin->noSerializerPublications);i++){
+ pubsub_endpoint_pt ep = (pubsub_endpoint_pt)arrayList_get(admin->noSerializerPublications,i);
+ pubsub_serializer_service_t *best_serializer = NULL;
+ pubsubAdmin_getBestSerializer(admin, ep, &best_serializer);
+ if(best_serializer != NULL){ /* Finally we have a valid serializer! */
+ pubsubAdmin_addPublication(admin, ep);
+ }
+ }
+
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+
+ printf("PSA_ZMQ: %s serializer added\n",serType);
+
+ return status;
+}
+
+celix_status_t pubsubAdmin_serializerRemoved(void * handle, service_reference_pt reference, void * service){
+
+ pubsub_admin_pt admin = (pubsub_admin_pt)handle;
+ int i=0, j=0;
+ const char *serType = NULL;
+
+ serviceReference_getProperty(reference, PUBSUB_SERIALIZER_TYPE_KEY,&serType);
+ if(serType == NULL){
+ printf("Serializer serviceReference %p has no pubsub_serializer.type property specified\n",reference);
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+ celixThreadMutex_lock(&admin->serializerListLock);
+ /* Remove the serializer from the list */
+ arrayList_removeElement(admin->serializerList, reference);
+ celixThreadMutex_unlock(&admin->serializerListLock);
+
+
+ celixThreadMutex_lock(&admin->usedSerializersLock);
+ array_list_pt topicPubList = (array_list_pt)hashMap_remove(admin->topicPublicationsPerSerializer, service);
+ array_list_pt topicSubList = (array_list_pt)hashMap_remove(admin->topicSubscriptionsPerSerializer, service);
+ celixThreadMutex_unlock(&admin->usedSerializersLock);
+
+ /* Now destroy the topicPublications, but first put back the pubsub_endpoints back to the noSerializer pending list */
+ if(topicPubList!=NULL){
+ for(i=0;i<arrayList_size(topicPubList);i++){
+ topic_publication_pt topicPub = (topic_publication_pt)arrayList_get(topicPubList,i);
+ /* Stop the topic publication */
+ pubsub_topicPublicationStop(topicPub);
+ /* Get the endpoints that are going to be orphan */
+ array_list_pt pubList = pubsub_topicPublicationGetPublisherList(topicPub);
+ for(j=0;j<arrayList_size(pubList);j++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pubList,j);
+ /* Remove the publication */
+ pubsubAdmin_removePublication(admin, pubEP);
+ /* Reset the endpoint field, so that will be recreated from scratch when a new serializer will be found */
+ if(pubEP->endpoint!=NULL){
+ free(pubEP->endpoint);
+ pubEP->endpoint = NULL;
+ }
+ /* Add the orphan endpoint to the noSerializer pending list */
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_add(admin->noSerializerPublications,pubEP);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+ arrayList_destroy(pubList);
+
+ /* Cleanup also the localPublications hashmap*/
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ hash_map_iterator_pt iter = hashMapIterator_create(admin->localPublications);
+ char *key = NULL;
+ service_factory_pt factory = NULL;
+ while(hashMapIterator_hasNext(iter)){
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ factory = (service_factory_pt)hashMapEntry_getValue(entry);
+ topic_publication_pt pub = (topic_publication_pt)factory->handle;
+ if(pub==topicPub){
+ key = (char*)hashMapEntry_getKey(entry);
+ break;
+ }
+ }
+ hashMapIterator_destroy(iter);
+ if(key!=NULL){
+ hashMap_remove(admin->localPublications, key);
+ free(factory);
+ free(key);
+ }
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+ /* Finally destroy the topicPublication */
+ pubsub_topicPublicationDestroy(topicPub);
+ }
+ arrayList_destroy(topicPubList);
+ }
+
+ /* Now destroy the topicSubscriptions, but first put back the pubsub_endpoints back to the noSerializer pending list */
+ if(topicSubList!=NULL){
+ for(i=0;i<arrayList_size(topicSubList);i++){
+ topic_subscription_pt topicSub = (topic_subscription_pt)arrayList_get(topicSubList,i);
+ /* Stop the topic subscription */
+ pubsub_topicSubscriptionStop(topicSub);
+ /* Get the endpoints that are going to be orphan */
+ array_list_pt subList = pubsub_topicSubscriptionGetSubscribersList(topicSub);
+ for(j=0;j<arrayList_size(subList);j++){
+ pubsub_endpoint_pt subEP = (pubsub_endpoint_pt)arrayList_get(subList,j);
+ /* Remove the subscription */
+ pubsubAdmin_removeSubscription(admin, subEP);
+ /* Reset the endpoint field, so that will be recreated from scratch when a new serializer will be found */
+ if(subEP->endpoint!=NULL){
+ free(subEP->endpoint);
+ subEP->endpoint = NULL;
+ }
+ /* Add the orphan endpoint to the noSerializer pending list */
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_add(admin->noSerializerSubscriptions,subEP);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+
+ /* Cleanup also the subscriptions hashmap*/
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+ hash_map_iterator_pt iter = hashMapIterator_create(admin->subscriptions);
+ char *key = NULL;
+ while(hashMapIterator_hasNext(iter)){
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ topic_subscription_pt sub = (topic_subscription_pt)hashMapEntry_getValue(entry);
+ if(sub==topicSub){
+ key = (char*)hashMapEntry_getKey(entry);
+ break;
+ }
+ }
+ hashMapIterator_destroy(iter);
+ if(key!=NULL){
+ hashMap_remove(admin->subscriptions, key);
+ free(key);
+ }
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ /* Finally destroy the topicSubscription */
+ pubsub_topicSubscriptionDestroy(topicSub);
+ }
+ arrayList_destroy(topicSubList);
+ }
+
+
+
+ printf("PSA_ZMQ: %s serializer removed\n",serType);
+
+
+ return CELIX_SUCCESS;
+}
+
+celix_status_t pubsubAdmin_matchEndpoint(pubsub_admin_pt admin, pubsub_endpoint_pt endpoint, double* score){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&admin->serializerListLock);
+ status = pubsub_admin_match(endpoint->topic_props,PUBSUB_ADMIN_TYPE,admin->serializerList,score);
+ celixThreadMutex_unlock(&admin->serializerListLock);
+
+ return status;
+}
+
+/* This one recall the same logic as in the match function */
+static celix_status_t pubsubAdmin_getBestSerializer(pubsub_admin_pt admin,pubsub_endpoint_pt ep, pubsub_serializer_service_t **serSvc){
+
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&admin->serializerListLock);
+ status = pubsub_admin_get_best_serializer(ep->topic_props, admin->serializerList, serSvc);
+ celixThreadMutex_unlock(&admin->serializerListLock);
+
+ return status;
+
+}
+
+static void connectTopicPubSubToSerializer(pubsub_admin_pt admin,pubsub_serializer_service_t *serializer,void *topicPubSub,bool isPublication){
+
+ celixThreadMutex_lock(&admin->usedSerializersLock);
+
+ hash_map_pt map = isPublication?admin->topicPublicationsPerSerializer:admin->topicSubscriptionsPerSerializer;
+ array_list_pt list = (array_list_pt)hashMap_get(map,serializer);
+ if(list==NULL){
+ arrayList_create(&list);
+ hashMap_put(map,serializer,list);
+ }
+ arrayList_add(list,topicPubSub);
+
+ celixThreadMutex_unlock(&admin->usedSerializersLock);
+
+}
+
+static void disconnectTopicPubSubFromSerializer(pubsub_admin_pt admin,void *topicPubSub,bool isPublication){
+
+ celixThreadMutex_lock(&admin->usedSerializersLock);
+
+ hash_map_pt map = isPublication?admin->topicPublicationsPerSerializer:admin->topicSubscriptionsPerSerializer;
+ hash_map_iterator_pt iter = hashMapIterator_create(map);
+ while(hashMapIterator_hasNext(iter)){
+ array_list_pt list = (array_list_pt)hashMapIterator_nextValue(iter);
+ if(arrayList_removeElement(list, topicPubSub)){ //Found it!
+ break;
+ }
+ }
+ hashMapIterator_destroy(iter);
+
+ celixThreadMutex_unlock(&admin->usedSerializersLock);
+
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/pubsub_admin_zmq/src/topic_publication.c
----------------------------------------------------------------------
diff --cc pubsub/pubsub_admin_zmq/src/topic_publication.c
index e405866,0000000..b612605
mode 100644,000000..100644
--- a/pubsub/pubsub_admin_zmq/src/topic_publication.c
+++ b/pubsub/pubsub_admin_zmq/src/topic_publication.c
@@@ -1,630 -1,0 +1,630 @@@
+/**
+ *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.
+ */
+
+#include <czmq.h>
+/* The following undefs prevent the collision between:
+ * - sys/syslog.h (which is included within czmq)
+ * - celix/dfi/dfi_log_util.h
+ */
+#undef LOG_DEBUG
+#undef LOG_WARNING
+#undef LOG_INFO
+#undef LOG_WARNING
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "array_list.h"
+#include "celixbool.h"
+#include "service_registration.h"
+#include "utils.h"
+#include "service_factory.h"
+#include "version.h"
+
+#include "pubsub_common.h"
+#include "pubsub_utils.h"
- #include "publisher.h"
++#include "pubsub/publisher.h"
+
+#include "topic_publication.h"
+
+#include "pubsub_serializer.h"
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ #include "zmq_crypto.h"
+
+ #define MAX_CERT_PATH_LENGTH 512
+#endif
+
+#define EP_ADDRESS_LEN 32
+#define ZMQ_BIND_MAX_RETRY 5
+
+#define FIRST_SEND_DELAY 2
+
+struct topic_publication {
+ zsock_t* zmq_socket;
+ celix_thread_mutex_t socket_lock; //Protects zmq_socket access
+ zcert_t * zmq_cert;
+ char* endpoint;
+ service_registration_pt svcFactoryReg;
+ array_list_pt pub_ep_list; //List<pubsub_endpoint>
+ hash_map_pt boundServices; //<bundle_pt,bound_service>
+ pubsub_serializer_service_t *serializer;
+ celix_thread_mutex_t tp_lock;
+};
+
+typedef struct publish_bundle_bound_service {
+ topic_publication_pt parent;
+ pubsub_publisher_t service;
+ bundle_pt bundle;
+ char *topic;
+ hash_map_pt msgTypes;
+ unsigned short getCount;
+ celix_thread_mutex_t mp_lock; //Protects publish_bundle_bound_service data structure
+ bool mp_send_in_progress;
+ array_list_pt mp_parts;
+}* publish_bundle_bound_service_pt;
+
+/* Note: correct locking order is
+ * 1. tp_lock
+ * 2. mp_lock
+ * 3. socket_lock
+ *
+ * tp_lock and socket_lock are independent.
+ */
+
+typedef struct pubsub_msg{
+ pubsub_msg_header_pt header;
+ char* payload;
+ int payloadSize;
+}* pubsub_msg_pt;
+
+static unsigned int rand_range(unsigned int min, unsigned int max);
+
+static celix_status_t pubsub_topicPublicationGetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service);
+static celix_status_t pubsub_topicPublicationUngetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service);
+
+static publish_bundle_bound_service_pt pubsub_createPublishBundleBoundService(topic_publication_pt tp,bundle_pt bundle);
+static void pubsub_destroyPublishBundleBoundService(publish_bundle_bound_service_pt boundSvc);
+
+static int pubsub_topicPublicationSend(void* handle,unsigned int msgTypeId, const void *msg);
+static int pubsub_topicPublicationSendMultipart(void *handle, unsigned int msgTypeId, const void *inMsg, int flags);
+static int pubsub_localMsgTypeIdForUUID(void* handle, const char* msgType, unsigned int* msgTypeId);
+
+static void delay_first_send_for_late_joiners(void);
+
+celix_status_t pubsub_topicPublicationCreate(bundle_context_pt bundle_context, pubsub_endpoint_pt pubEP, pubsub_serializer_service_t *best_serializer, char* bindIP, unsigned int basePort, unsigned int maxPort, topic_publication_pt *out){
+ celix_status_t status = CELIX_SUCCESS;
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ char* secure_topics = NULL;
+ bundleContext_getProperty(bundle_context, "SECURE_TOPICS", (const char **) &secure_topics);
+
+ if (secure_topics){
+ array_list_pt secure_topics_list = pubsub_getTopicsFromString(secure_topics);
+
+ int i;
+ int secure_topics_size = arrayList_size(secure_topics_list);
+ for (i = 0; i < secure_topics_size; i++){
+ char* top = arrayList_get(secure_topics_list, i);
+ if (strcmp(pubEP->topic, top) == 0){
+ printf("PSA_ZMQ_TP: Secure topic: '%s'\n", top);
+ pubEP->is_secure = true;
+ }
+ free(top);
+ top = NULL;
+ }
+
+ arrayList_destroy(secure_topics_list);
+ }
+
+ zcert_t* pub_cert = NULL;
+ if (pubEP->is_secure){
+ char* keys_bundle_dir = pubsub_getKeysBundleDir(bundle_context);
+ if (keys_bundle_dir == NULL){
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+ const char* keys_file_path = NULL;
+ const char* keys_file_name = NULL;
+ bundleContext_getProperty(bundle_context, PROPERTY_KEYS_FILE_PATH, &keys_file_path);
+ bundleContext_getProperty(bundle_context, PROPERTY_KEYS_FILE_NAME, &keys_file_name);
+
+ char cert_path[MAX_CERT_PATH_LENGTH];
+
+ //certificate path ".cache/bundle{id}/version0.0/./META-INF/keys/publisher/private/pub_{topic}.key"
+ snprintf(cert_path, MAX_CERT_PATH_LENGTH, "%s/META-INF/keys/publisher/private/pub_%s.key.enc", keys_bundle_dir, pubEP->topic);
+ free(keys_bundle_dir);
+ printf("PSA_ZMQ_TP: Loading key '%s'\n", cert_path);
+
+ pub_cert = get_zcert_from_encoded_file((char *) keys_file_path, (char *) keys_file_name, cert_path);
+ if (pub_cert == NULL){
+ printf("PSA_ZMQ_TP: Cannot load key '%s'\n", cert_path);
+ printf("PSA_ZMQ_TP: Topic '%s' NOT SECURED !\n", pubEP->topic);
+ pubEP->is_secure = false;
+ }
+ }
+#endif
+
+ zsock_t* socket = zsock_new (ZMQ_PUB);
+ if(socket==NULL){
+ #ifdef BUILD_WITH_ZMQ_SECURITY
+ if (pubEP->is_secure){
+ zcert_destroy(&pub_cert);
+ }
+ #endif
+
+ perror("Error for zmq_socket");
+ return CELIX_SERVICE_EXCEPTION;
+ }
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ if (pubEP->is_secure){
+ zcert_apply (pub_cert, socket); // apply certificate to socket
+ zsock_set_curve_server (socket, true); // setup the publisher's socket to use the curve functions
+ }
+#endif
+
+ int rv = -1, retry=0;
+ char* ep = malloc(EP_ADDRESS_LEN);
+ char bindAddress[EP_ADDRESS_LEN];
+
+ while(rv==-1 && retry<ZMQ_BIND_MAX_RETRY){
+ /* Randomized part due to same bundle publishing on different topics */
+ unsigned int port = rand_range(basePort,maxPort);
+ memset(ep,0,EP_ADDRESS_LEN);
+ memset(bindAddress, 0, EP_ADDRESS_LEN);
+
+ snprintf(ep,EP_ADDRESS_LEN,"tcp://%s:%u",bindIP,port);
+ snprintf(bindAddress, EP_ADDRESS_LEN, "tcp://0.0.0.0:%u", port); //NOTE using a different bind addres than endpoint address
+ rv = zsock_bind (socket, "%s", bindAddress);
+ if (rv == -1) {
+ perror("Error for zmq_bind");
+ }
+ retry++;
+ }
+
+ if(rv == -1){
+ free(ep);
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+ /* ZMQ stuffs are all fine at this point. Let's create and initialize the structure */
+
+ topic_publication_pt pub = calloc(1,sizeof(*pub));
+
+ arrayList_create(&(pub->pub_ep_list));
+ pub->boundServices = hashMap_create(NULL,NULL,NULL,NULL);
+ celixThreadMutex_create(&(pub->tp_lock),NULL);
+
+ pub->endpoint = ep;
+ pub->zmq_socket = socket;
+ pub->serializer = best_serializer;
+
+ celixThreadMutex_create(&(pub->socket_lock),NULL);
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ if (pubEP->is_secure){
+ pub->zmq_cert = pub_cert;
+ }
+#endif
+
+ pubsub_topicPublicationAddPublisherEP(pub,pubEP);
+
+ *out = pub;
+
+ return status;
+}
+
+celix_status_t pubsub_topicPublicationDestroy(topic_publication_pt pub){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&(pub->tp_lock));
+
+ free(pub->endpoint);
+ arrayList_destroy(pub->pub_ep_list);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(pub->boundServices);
+ while(hashMapIterator_hasNext(iter)){
+ publish_bundle_bound_service_pt bound = hashMapIterator_nextValue(iter);
+ pubsub_destroyPublishBundleBoundService(bound);
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(pub->boundServices,false,false);
+
+ pub->svcFactoryReg = NULL;
+ pub->serializer = NULL;
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ zcert_destroy(&(pub->zmq_cert));
+#endif
+
+ celixThreadMutex_unlock(&(pub->tp_lock));
+
+ celixThreadMutex_destroy(&(pub->tp_lock));
+
+ celixThreadMutex_lock(&(pub->socket_lock));
+ zsock_destroy(&(pub->zmq_socket));
+ celixThreadMutex_unlock(&(pub->socket_lock));
+
+ celixThreadMutex_destroy(&(pub->socket_lock));
+
+ free(pub);
+
+ return status;
+}
+
+celix_status_t pubsub_topicPublicationStart(bundle_context_pt bundle_context,topic_publication_pt pub,service_factory_pt* svcFactory){
+ celix_status_t status = CELIX_SUCCESS;
+
+ /* Let's register the new service */
+
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pub->pub_ep_list,0);
+
+ if(pubEP!=NULL){
+ service_factory_pt factory = calloc(1, sizeof(*factory));
+ factory->handle = pub;
+ factory->getService = pubsub_topicPublicationGetService;
+ factory->ungetService = pubsub_topicPublicationUngetService;
+
+ properties_pt props = properties_create();
+ properties_set(props,PUBSUB_PUBLISHER_TOPIC,pubEP->topic);
+ properties_set(props,PUBSUB_PUBLISHER_SCOPE,pubEP->scope);
+ properties_set(props,"service.version", PUBSUB_PUBLISHER_SERVICE_VERSION);
+
+ status = bundleContext_registerServiceFactory(bundle_context,PUBSUB_PUBLISHER_SERVICE_NAME,factory,props,&(pub->svcFactoryReg));
+
+ if(status != CELIX_SUCCESS){
+ properties_destroy(props);
+ printf("PSA_ZMQ_PSA_ZMQ_TP: Cannot register ServiceFactory for topic %s (bundle %ld).\n",pubEP->topic,pubEP->serviceID);
+ }
+ else{
+ *svcFactory = factory;
+ }
+ }
+ else{
+ printf("PSA_ZMQ_PSA_ZMQ_TP: Cannot find pubsub_endpoint after adding it...Should never happen!\n");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+
+ return status;
+}
+
+celix_status_t pubsub_topicPublicationStop(topic_publication_pt pub){
+ return serviceRegistration_unregister(pub->svcFactoryReg);
+}
+
+celix_status_t pubsub_topicPublicationAddPublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep){
+
+ celixThreadMutex_lock(&(pub->tp_lock));
+ ep->endpoint = strdup(pub->endpoint);
+ arrayList_add(pub->pub_ep_list,ep);
+ celixThreadMutex_unlock(&(pub->tp_lock));
+
+ return CELIX_SUCCESS;
+}
+
+celix_status_t pubsub_topicPublicationRemovePublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep){
+
+ celixThreadMutex_lock(&(pub->tp_lock));
+ for (int i = 0; i < arrayList_size(pub->pub_ep_list); i++) {
+ pubsub_endpoint_pt e = arrayList_get(pub->pub_ep_list, i);
+ if(pubsubEndpoint_equals(ep, e)) {
+ arrayList_removeElement(pub->pub_ep_list,ep);
+ break;
+ }
+ }
+ celixThreadMutex_unlock(&(pub->tp_lock));
+
+ return CELIX_SUCCESS;
+}
+
+array_list_pt pubsub_topicPublicationGetPublisherList(topic_publication_pt pub){
+ array_list_pt list = NULL;
+ celixThreadMutex_lock(&(pub->tp_lock));
+ list = arrayList_clone(pub->pub_ep_list);
+ celixThreadMutex_unlock(&(pub->tp_lock));
+ return list;
+}
+
+
+static celix_status_t pubsub_topicPublicationGetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ topic_publication_pt publish = (topic_publication_pt)handle;
+
+ celixThreadMutex_lock(&(publish->tp_lock));
+
+ publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt)hashMap_get(publish->boundServices,bundle);
+ if(bound==NULL){
+ bound = pubsub_createPublishBundleBoundService(publish,bundle);
+ if(bound!=NULL){
+ hashMap_put(publish->boundServices,bundle,bound);
+ }
+ }
+ else{
+ bound->getCount++;
+ }
+
+ *service = &bound->service;
+
+ celixThreadMutex_unlock(&(publish->tp_lock));
+
+ return status;
+}
+
+static celix_status_t pubsub_topicPublicationUngetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service) {
+
+ topic_publication_pt publish = (topic_publication_pt)handle;
+
+ celixThreadMutex_lock(&(publish->tp_lock));
+
+ publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt)hashMap_get(publish->boundServices,bundle);
+ if(bound!=NULL){
+
+ bound->getCount--;
+ if(bound->getCount==0){
+ pubsub_destroyPublishBundleBoundService(bound);
+ hashMap_remove(publish->boundServices,bundle);
+ }
+
+ }
+ else{
+ long bundleId = -1;
+ bundle_getBundleId(bundle,&bundleId);
+ printf("PSA_ZMQ_TP: Unexpected ungetService call for bundle %ld.\n", bundleId);
+ }
+
+ /* service should be never used for unget, so let's set the pointer to NULL */
+ *service = NULL;
+
+ celixThreadMutex_unlock(&(publish->tp_lock));
+
+ return CELIX_SUCCESS;
+}
+
+static bool send_pubsub_msg(zsock_t* zmq_socket, pubsub_msg_pt msg, bool last){
+
+ bool ret = true;
+
+ zframe_t* headerMsg = zframe_new(msg->header, sizeof(struct pubsub_msg_header));
+ if (headerMsg == NULL) ret=false;
+ zframe_t* payloadMsg = zframe_new(msg->payload, msg->payloadSize);
+ if (payloadMsg == NULL) ret=false;
+
+ delay_first_send_for_late_joiners();
+
+ if( zframe_send(&headerMsg,zmq_socket, ZFRAME_MORE) == -1) ret=false;
+
+ if(!last){
+ if( zframe_send(&payloadMsg,zmq_socket, ZFRAME_MORE) == -1) ret=false;
+ }
+ else{
+ if( zframe_send(&payloadMsg,zmq_socket, 0) == -1) ret=false;
+ }
+
+ if (!ret){
+ zframe_destroy(&headerMsg);
+ zframe_destroy(&payloadMsg);
+ }
+
+ free(msg->header);
+ free(msg->payload);
+ free(msg);
+
+ return ret;
+
+}
+
+static bool send_pubsub_mp_msg(zsock_t* zmq_socket, array_list_pt mp_msg_parts){
+
+ bool ret = true;
+
+ unsigned int i = 0;
+ unsigned int mp_num = arrayList_size(mp_msg_parts);
+ for(;i<mp_num;i++){
+ ret = ret && send_pubsub_msg(zmq_socket, (pubsub_msg_pt)arrayList_get(mp_msg_parts,i), (i==mp_num-1));
+ }
+ arrayList_clear(mp_msg_parts);
+
+ return ret;
+
+}
+
+static int pubsub_topicPublicationSend(void* handle, unsigned int msgTypeId, const void *msg) {
+
+ return pubsub_topicPublicationSendMultipart(handle,msgTypeId,msg, PUBSUB_PUBLISHER_FIRST_MSG | PUBSUB_PUBLISHER_LAST_MSG);
+
+}
+
+static int pubsub_topicPublicationSendMultipart(void *handle, unsigned int msgTypeId, const void *inMsg, int flags){
+
+ int status = 0;
+
+ publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt) handle;
+
+ celixThreadMutex_lock(&(bound->parent->tp_lock));
+ celixThreadMutex_lock(&(bound->mp_lock));
+ if( (flags & PUBSUB_PUBLISHER_FIRST_MSG) && !(flags & PUBSUB_PUBLISHER_LAST_MSG) && bound->mp_send_in_progress){ //means a real mp_msg
+ printf("PSA_ZMQ_TP: Multipart send already in progress. Cannot process a new one.\n");
+ celixThreadMutex_unlock(&(bound->mp_lock));
+ celixThreadMutex_unlock(&(bound->parent->tp_lock));
+ return -3;
+ }
+
+ pubsub_msg_serializer_t* msgSer = (pubsub_msg_serializer_t*)hashMap_get(bound->msgTypes, (void*)(uintptr_t)msgTypeId);
+
+ if (msgSer!= NULL) {
+ int major=0, minor=0;
+
+ pubsub_msg_header_pt msg_hdr = calloc(1,sizeof(struct pubsub_msg_header));
+ strncpy(msg_hdr->topic,bound->topic,MAX_TOPIC_LEN-1);
+ msg_hdr->type = msgTypeId;
+
+ if (msgSer->msgVersion != NULL){
+ version_getMajor(msgSer->msgVersion, &major);
+ version_getMinor(msgSer->msgVersion, &minor);
+ msg_hdr->major = major;
+ msg_hdr->minor = minor;
+ }
+
+ void *serializedOutput = NULL;
+ size_t serializedOutputLen = 0;
+ msgSer->serialize(msgSer,inMsg,&serializedOutput, &serializedOutputLen);
+
+ pubsub_msg_pt msg = calloc(1,sizeof(struct pubsub_msg));
+ msg->header = msg_hdr;
+ msg->payload = (char*)serializedOutput;
+ msg->payloadSize = serializedOutputLen;
+ bool snd = true;
+
+ switch(flags){
+ case PUBSUB_PUBLISHER_FIRST_MSG:
+ bound->mp_send_in_progress = true;
+ arrayList_add(bound->mp_parts,msg);
+ break;
+ case PUBSUB_PUBLISHER_PART_MSG:
+ if(!bound->mp_send_in_progress){
+ printf("PSA_ZMQ_TP: ERROR: received msg part without the first part.\n");
+ status = -4;
+ }
+ else{
+ arrayList_add(bound->mp_parts,msg);
+ }
+ break;
+ case PUBSUB_PUBLISHER_LAST_MSG:
+ if(!bound->mp_send_in_progress){
+ printf("PSA_ZMQ_TP: ERROR: received end msg without the first part.\n");
+ status = -4;
+ }
+ else{
+ arrayList_add(bound->mp_parts,msg);
+ snd = send_pubsub_mp_msg(bound->parent->zmq_socket,bound->mp_parts);
+ bound->mp_send_in_progress = false;
+ }
+ break;
+ case PUBSUB_PUBLISHER_FIRST_MSG | PUBSUB_PUBLISHER_LAST_MSG: //Normal send case
+ snd = send_pubsub_msg(bound->parent->zmq_socket,msg,true);
+ break;
+ default:
+ printf("PSA_ZMQ_TP: ERROR: Invalid MP flags combination\n");
+ status = -4;
+ break;
+ }
+
+ if(status==-4){
+ free(msg);
+ }
+
+ if(!snd){
+ printf("PSA_ZMQ_TP: Failed to send %s message %u.\n",flags == (PUBSUB_PUBLISHER_FIRST_MSG | PUBSUB_PUBLISHER_LAST_MSG) ? "single" : "multipart", msgTypeId);
+ }
+
+ } else {
+ printf("PSA_ZMQ_TP: No msg serializer available for msg type id %d\n", msgTypeId);
+ status=-1;
+ }
+
+ celixThreadMutex_unlock(&(bound->mp_lock));
+ celixThreadMutex_unlock(&(bound->parent->tp_lock));
+
+ return status;
+
+}
+
+static int pubsub_localMsgTypeIdForUUID(void* handle, const char* msgType, unsigned int* msgTypeId){
+ *msgTypeId = utils_stringHash(msgType);
+ return 0;
+}
+
+
+static unsigned int rand_range(unsigned int min, unsigned int max){
+
+ double scaled = (double)(((double)random())/((double)RAND_MAX));
+ return (max-min+1)*scaled + min;
+
+}
+
+static publish_bundle_bound_service_pt pubsub_createPublishBundleBoundService(topic_publication_pt tp,bundle_pt bundle){
+
+ //PRECOND lock on tp->lock
+
+ publish_bundle_bound_service_pt bound = calloc(1, sizeof(*bound));
+
+ if (bound != NULL) {
+
+ bound->parent = tp;
+ bound->bundle = bundle;
+ bound->getCount = 1;
+ bound->mp_send_in_progress = false;
+ celixThreadMutex_create(&bound->mp_lock,NULL);
+
+ if(tp->serializer != NULL){
+ tp->serializer->createSerializerMap(tp->serializer->handle,bundle,&bound->msgTypes);
+ }
+
+ arrayList_create(&bound->mp_parts);
+
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(bound->parent->pub_ep_list,0);
+ bound->topic=strdup(pubEP->topic);
+
+ bound->service.handle = bound;
+ bound->service.localMsgTypeIdForMsgType = pubsub_localMsgTypeIdForUUID;
+ bound->service.send = pubsub_topicPublicationSend;
+ bound->service.sendMultipart = pubsub_topicPublicationSendMultipart;
+
+ }
+
+ return bound;
+}
+
+static void pubsub_destroyPublishBundleBoundService(publish_bundle_bound_service_pt boundSvc){
+
+ //PRECOND lock on tp->lock
+
+ celixThreadMutex_lock(&boundSvc->mp_lock);
+
+
+ if(boundSvc->parent->serializer != NULL && boundSvc->msgTypes != NULL){
+ boundSvc->parent->serializer->destroySerializerMap(boundSvc->parent->serializer->handle, boundSvc->msgTypes);
+ }
+
+ if(boundSvc->mp_parts!=NULL){
+ arrayList_destroy(boundSvc->mp_parts);
+ }
+
+ if(boundSvc->topic!=NULL){
+ free(boundSvc->topic);
+ }
+
+ celixThreadMutex_unlock(&boundSvc->mp_lock);
+ celixThreadMutex_destroy(&boundSvc->mp_lock);
+
+ free(boundSvc);
+
+}
+
+static void delay_first_send_for_late_joiners(){
+
+ static bool firstSend = true;
+
+ if(firstSend){
+ printf("PSA_ZMQ_TP: Delaying first send for late joiners...\n");
+ sleep(FIRST_SEND_DELAY);
+ firstSend = false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/pubsub_admin_zmq/src/topic_publication.h
----------------------------------------------------------------------
diff --cc pubsub/pubsub_admin_zmq/src/topic_publication.h
index 3457263,0000000..65df0e3
mode 100644,000000..100644
--- a/pubsub/pubsub_admin_zmq/src/topic_publication.h
+++ b/pubsub/pubsub_admin_zmq/src/topic_publication.h
@@@ -1,49 -1,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.
+ */
+/*
+ * topic_publication.h
+ *
+ * \date Sep 24, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef TOPIC_PUBLICATION_H_
+#define TOPIC_PUBLICATION_H_
+
- #include "publisher.h"
++#include "pubsub/publisher.h"
+#include "pubsub_endpoint.h"
+#include "pubsub_common.h"
+
+#include "pubsub_serializer.h"
+
+typedef struct topic_publication *topic_publication_pt;
+
+celix_status_t pubsub_topicPublicationCreate(bundle_context_pt bundle_context,pubsub_endpoint_pt pubEP, pubsub_serializer_service_t *best_serializer, char* bindIP, unsigned int basePort, unsigned int maxPort, topic_publication_pt *out);
+celix_status_t pubsub_topicPublicationDestroy(topic_publication_pt pub);
+
+celix_status_t pubsub_topicPublicationAddPublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep);
+celix_status_t pubsub_topicPublicationRemovePublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep);
+
+celix_status_t pubsub_topicPublicationStart(bundle_context_pt bundle_context,topic_publication_pt pub,service_factory_pt* svcFactory);
+celix_status_t pubsub_topicPublicationStop(topic_publication_pt pub);
+
+array_list_pt pubsub_topicPublicationGetPublisherList(topic_publication_pt pub);
+
+#endif /* TOPIC_PUBLICATION_H_ */
[50/54] [abbrv] celix git commit: CELIX-417: Fixes pubsub mock test
build configuration
Posted by pn...@apache.org.
CELIX-417: Fixes pubsub mock test build configuration
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/49d0e356
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/49d0e356
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/49d0e356
Branch: refs/heads/develop
Commit: 49d0e3565af01b1528fd4424a10433c64eef3388
Parents: e08b428
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Jan 30 12:48:24 2018 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Jan 30 12:48:24 2018 +0100
----------------------------------------------------------------------
pubsub/mock/CMakeLists.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/49d0e356/pubsub/mock/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/mock/CMakeLists.txt b/pubsub/mock/CMakeLists.txt
index e68b1cb..c441e21 100644
--- a/pubsub/mock/CMakeLists.txt
+++ b/pubsub/mock/CMakeLists.txt
@@ -33,7 +33,8 @@ if (CPPUTEST_FOUND)
tst/pubsubmock_test.cc
tst/run_tests.cc
)
- target_link_libraries(pubsubmock_test celix_pubsub_mock ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} Celix::framework)
+ target_include_directories(pubsubmock_test PRIVATE ${CMAKE_CURRENT_LIST_DIR}/api)
+ target_link_libraries(pubsubmock_test pubsub_mock ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} Celix::framework)
add_test(NAME pubsubmock_test COMMAND pubsubmock_test)
endif()
endif()
[14/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery/private/src/discovery_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/src/discovery_activator.c b/remote_services/discovery/private/src/discovery_activator.c
deleted file mode 100644
index 3267d25..0000000
--- a/remote_services/discovery/private/src/discovery_activator.c
+++ /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.
- */
-/*
- * discovery_activator.c
- *
- * \date Aug 8, 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-#include "bundle_activator.h"
-#include "service_tracker.h"
-#include "constants.h"
-
-#include "log_helper.h"
-#include "discovery.h"
-#include "remote_constants.h"
-
-struct activator {
- bundle_context_pt context;
- discovery_pt discovery;
- log_helper_pt loghelper;
-
- service_tracker_pt endpointListenerTracker;
- endpoint_listener_pt endpointListener;
- service_registration_pt endpointListenerService;
-};
-
-celix_status_t bundleActivator_createEPLTracker(struct activator *activator, service_tracker_pt *tracker) {
- celix_status_t status;
-
- service_tracker_customizer_pt customizer = NULL;
-
- status = serviceTrackerCustomizer_create(activator->discovery, discovery_endpointListenerAdding, discovery_endpointListenerAdded, discovery_endpointListenerModified,
- discovery_endpointListenerRemoved, &customizer);
-
- if (status == CELIX_SUCCESS) {
- status = serviceTracker_create(activator->context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, customizer, tracker);
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status;
-
- struct activator* activator = calloc(1,sizeof(struct activator));
- if (!activator) {
- return CELIX_ENOMEM;
- }
-
- status = discovery_create(context, &activator->discovery);
- if (status == CELIX_SUCCESS) {
- activator->context = context;
-
- logHelper_create(context, &activator->loghelper);
-
- status = bundleActivator_createEPLTracker(activator, &activator->endpointListenerTracker);
- if(status==CELIX_SUCCESS){
- *userData = activator;
- }
- else{
- bundleActivator_destroy(activator,context);
- }
- }
- else{
- free(activator);
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status;
- struct activator *activator = userData;
- const char *uuid = NULL;
-
- logHelper_start(activator->loghelper);
-
- status = bundleContext_getProperty(context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
- if (!uuid) {
- logHelper_log(activator->loghelper, OSGI_LOGSERVICE_DEBUG, "no framework UUID defined?!");
- return CELIX_ILLEGAL_STATE;
- }
-
- size_t len = 11 + strlen(OSGI_FRAMEWORK_OBJECTCLASS) + strlen(OSGI_RSA_ENDPOINT_FRAMEWORK_UUID) + strlen(uuid);
- char *scope = malloc(len + 1);
- if (!scope) {
- return CELIX_ENOMEM;
- }
-
- sprintf(scope, "(&(%s=*)(%s=%s))", OSGI_FRAMEWORK_OBJECTCLASS, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
- scope[len] = 0;
-
- logHelper_log(activator->loghelper, OSGI_LOGSERVICE_DEBUG, "using scope %s.", scope);
-
- properties_pt props = properties_create();
- properties_set(props, "DISCOVERY", "true");
- properties_set(props, (char *) OSGI_ENDPOINT_LISTENER_SCOPE, scope);
-
- if (status == CELIX_SUCCESS) {
- status = serviceTracker_open(activator->endpointListenerTracker);
- }
-
- if (status == CELIX_SUCCESS) {
- status = discovery_start(activator->discovery);
- }
-
- if (status == CELIX_SUCCESS) {
- endpoint_listener_pt endpointListener = calloc(1, sizeof(struct endpoint_listener));
-
- if (endpointListener) {
- endpointListener->handle = activator->discovery;
- endpointListener->endpointAdded = discovery_endpointAdded;
- endpointListener->endpointRemoved = discovery_endpointRemoved;
-
- status = bundleContext_registerService(context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, endpointListener, props, &activator->endpointListenerService);
-
- if (status == CELIX_SUCCESS) {
- activator->endpointListener = endpointListener;
- }
- }
- }
- // We can release the scope, as properties_set makes a copy of the key & value...
- free(scope);
-
- return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status;
- struct activator *activator = userData;
-
- status = discovery_stop(activator->discovery);
-
- status = serviceTracker_close(activator->endpointListenerTracker);
-
- status = serviceRegistration_unregister(activator->endpointListenerService);
- free(activator->endpointListener);
-
- logHelper_stop(activator->loghelper);
-
- return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- celix_status_t status;
- struct activator *activator = userData;
-
- status = serviceTracker_destroy(activator->endpointListenerTracker);
-
- status = discovery_destroy(activator->discovery);
-
- logHelper_destroy(&activator->loghelper);
-
- activator->loghelper = NULL;
- activator->endpointListenerTracker = NULL;
- activator->endpointListenerService = NULL;
- activator->discovery = NULL;
- activator->context = NULL;
-
- free(activator);
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery/private/src/endpoint_descriptor_reader.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/src/endpoint_descriptor_reader.c b/remote_services/discovery/private/src/endpoint_descriptor_reader.c
deleted file mode 100644
index ea176bf..0000000
--- a/remote_services/discovery/private/src/endpoint_descriptor_reader.c
+++ /dev/null
@@ -1,387 +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.
- */
-/*
- * endpoint_descriptor_reader.c
- *
- * \date 24 Jul 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdbool.h>
-#include <string.h>
-#include <libxml/xmlreader.h>
-
-#include "log_helper.h"
-#include "remote_constants.h"
-
-#include "endpoint_description.h"
-#include "endpoint_descriptor_common.h"
-#include "endpoint_descriptor_reader.h"
-
-struct endpoint_descriptor_reader {
- xmlTextReaderPtr reader;
- log_helper_pt* loghelper;
-};
-
-static valueType valueTypeFromString(char *name);
-
-celix_status_t endpointDescriptorReader_create(endpoint_discovery_poller_pt poller, endpoint_descriptor_reader_pt *reader) {
- celix_status_t status = CELIX_SUCCESS;
-
- *reader = malloc(sizeof(**reader));
- if (!*reader) {
- status = CELIX_ENOMEM;
- } else {
- (*reader)->reader = NULL;
- (*reader)->loghelper = poller->loghelper;
- }
-
- return status;
-}
-
-celix_status_t endpointDescriptorReader_destroy(endpoint_descriptor_reader_pt reader) {
- celix_status_t status = CELIX_SUCCESS;
-
- reader->loghelper = NULL;
-
- free(reader);
-
- return status;
-}
-
-void endpointDescriptorReader_addSingleValuedProperty(properties_pt properties, const xmlChar* name, const xmlChar* value) {
- properties_set(properties, (char *) name, (char*) value);
-}
-
-void endpointDescriptorReader_addMultiValuedProperty(properties_pt properties, const xmlChar* name, array_list_pt values) {
- char *value = calloc(256, sizeof(*value));
- if (value) {
- unsigned int size = arrayList_size(values);
- unsigned int i;
- for (i = 0; i < size; i++) {
- char* item = (char*) arrayList_get(values, i);
- if (i > 0) {
- value = strcat(value, ",");
- }
- value = strcat(value, item);
- }
-
- properties_set(properties, (char *) name, value);
-
- free(value);
- }
-}
-
-celix_status_t endpointDescriptorReader_parseDocument(endpoint_descriptor_reader_pt reader, char *document, array_list_pt *endpoints) {
- celix_status_t status = CELIX_SUCCESS;
-
- reader->reader = xmlReaderForMemory(document, (int) strlen(document), NULL, "UTF-8", 0);
- if (reader->reader == NULL) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- bool inProperty = false;
- bool inXml = false;
- bool inArray = false;
- bool inList = false;
- bool inSet = false;
- bool inValue = false;
-
- const xmlChar *propertyName = NULL;
- const xmlChar *propertyValue = NULL;
- valueType propertyType = VALUE_TYPE_STRING;
- xmlChar *valueBuffer = xmlMalloc(256);
- valueBuffer[0] = '\0';
-
- array_list_pt propertyValues = NULL;
- arrayList_create(&propertyValues);
-
- array_list_pt endpointDescriptions = NULL;
- if (*endpoints) {
- // use the given arraylist...
- endpointDescriptions = *endpoints;
- } else {
- arrayList_create(&endpointDescriptions);
- // return the read endpoints...
- *endpoints = endpointDescriptions;
- }
-
- properties_pt endpointProperties = NULL;
-
- int read = xmlTextReaderRead(reader->reader);
- while (read == XML_TEXTREADER_MODE_INTERACTIVE) {
- int type = xmlTextReaderNodeType(reader->reader);
-
- if (type == XML_READER_TYPE_ELEMENT) {
- const xmlChar *localname = xmlTextReaderConstLocalName(reader->reader);
-
- if (inXml) {
- valueBuffer = xmlStrcat(valueBuffer, BAD_CAST "<");
- valueBuffer = xmlStrcat(valueBuffer, localname);
-
- int i = xmlTextReaderMoveToFirstAttribute(reader->reader);
- while (i == 1) {
- const xmlChar *name = xmlTextReaderConstName(reader->reader);
- const xmlChar *value = xmlTextReaderConstValue(reader->reader);
-
- valueBuffer = xmlStrcat(valueBuffer, BAD_CAST " ");
- valueBuffer = xmlStrcat(valueBuffer, name);
- valueBuffer = xmlStrcat(valueBuffer, BAD_CAST "=\"");
- valueBuffer = xmlStrcat(valueBuffer, BAD_CAST value);
- valueBuffer = xmlStrcat(valueBuffer, BAD_CAST "\"");
-
- i = xmlTextReaderMoveToNextAttribute(reader->reader);
- }
-
- valueBuffer = xmlStrcat(valueBuffer, BAD_CAST ">");
- } else if (xmlStrcmp(localname, ENDPOINT_DESCRIPTION) == 0) {
-
- if (endpointProperties != NULL)
- properties_destroy(endpointProperties);
-
- endpointProperties = properties_create();
- } else if (xmlStrcmp(localname, PROPERTY) == 0) {
- inProperty = true;
-
- propertyName = xmlTextReaderGetAttribute(reader->reader, NAME);
- propertyValue = xmlTextReaderGetAttribute(reader->reader, VALUE);
- xmlChar *vtype = xmlTextReaderGetAttribute(reader->reader, VALUE_TYPE);
- propertyType = valueTypeFromString((char*) vtype);
- arrayList_clear(propertyValues);
-
- if (xmlTextReaderIsEmptyElement(reader->reader)) {
- inProperty = false;
-
- if (propertyValue != NULL) {
- endpointDescriptorReader_addSingleValuedProperty(endpointProperties, propertyName, propertyValue);
- }
-
- xmlFree((void *) propertyName);
- xmlFree((void *) propertyValue);
- xmlFree((void *) vtype);
- }
- } else {
- valueBuffer[0] = 0;
- inArray |= inProperty && xmlStrcmp(localname, ARRAY) == 0;
- inList |= inProperty && xmlStrcmp(localname, LIST) == 0;
- inSet |= inProperty && xmlStrcmp(localname, SET) == 0;
- inXml |= inProperty && xmlStrcmp(localname, XML) == 0;
- inValue |= inProperty && xmlStrcmp(localname, VALUE) == 0;
- }
- } else if (type == XML_READER_TYPE_END_ELEMENT) {
- const xmlChar *localname = xmlTextReaderConstLocalName(reader->reader);
-
- if (inXml) {
- if (xmlStrcmp(localname, XML) != 0) {
- valueBuffer = xmlStrcat(valueBuffer, BAD_CAST "</");
- valueBuffer = xmlStrcat(valueBuffer, localname);
- valueBuffer = xmlStrcat(valueBuffer, BAD_CAST ">");
- }
- else {
- inXml = false;
- }
- } else if (xmlStrcmp(localname, ENDPOINT_DESCRIPTION) == 0) {
- endpoint_description_pt endpointDescription = NULL;
- // Completely parsed endpoint description, add it to our list of results...
- if(endpointDescription_create(endpointProperties, &endpointDescription) == CELIX_SUCCESS){
- arrayList_add(endpointDescriptions, endpointDescription);
- }
-
- endpointProperties = properties_create();
- } else if (xmlStrcmp(localname, PROPERTY) == 0) {
- inProperty = false;
-
- if (inArray || inList || inSet) {
- endpointDescriptorReader_addMultiValuedProperty(endpointProperties, propertyName, propertyValues);
- }
- else if (propertyValue != NULL) {
- if (propertyType != VALUE_TYPE_STRING) {
- logHelper_log(*reader->loghelper, OSGI_LOGSERVICE_WARNING, "ENDPOINT_DESCRIPTOR_READER: Only string support for %s\n", propertyName);
- }
- endpointDescriptorReader_addSingleValuedProperty(endpointProperties, propertyName, propertyValue);
-
- xmlFree((void *) propertyValue);
- }
- else {
- endpointDescriptorReader_addSingleValuedProperty(endpointProperties, propertyName, valueBuffer);
- }
-
- xmlFree((void *) propertyName);
- unsigned int k=0;
- for(;k<arrayList_size(propertyValues);k++){
- free(arrayList_get(propertyValues,k));
- }
- arrayList_clear(propertyValues);
-
- propertyType = VALUE_TYPE_STRING;
- inArray = false;
- inList = false;
- inSet = false;
- inXml = false;
- } else if (xmlStrcmp(localname, VALUE) == 0) {
- arrayList_add(propertyValues, strdup((char*) valueBuffer));
- valueBuffer[0] = 0;
- inValue = false;
- }
- } else if (type == XML_READER_TYPE_TEXT) {
- if (inValue || inXml) {
- const xmlChar *value = xmlTextReaderValue(reader->reader);
- valueBuffer = xmlStrcat(valueBuffer, value);
- xmlFree((void *)value);
- }
- }
-
- read = xmlTextReaderRead(reader->reader);
- }
-
- if(endpointProperties!=NULL){
- properties_destroy(endpointProperties);
- }
-
- unsigned int k=0;
- for(;k<arrayList_size(propertyValues);k++){
- free(arrayList_get(propertyValues,k));
- }
- arrayList_destroy(propertyValues);
- xmlFree(valueBuffer);
-
- xmlFreeTextReader(reader->reader);
- }
-
- return status;
-}
-
-static valueType valueTypeFromString(char *name) {
- if (name == NULL || strcmp(name, "") == 0 || strcmp(name, "String") == 0) {
- return VALUE_TYPE_STRING;
- } else if (strcmp(name, "long") == 0 || strcmp(name, "Long") == 0) {
- return VALUE_TYPE_LONG;
- } else if (strcmp(name, "double") == 0 || strcmp(name, "Double") == 0) {
- return VALUE_TYPE_DOUBLE;
- } else if (strcmp(name, "float") == 0 || strcmp(name, "Float") == 0) {
- return VALUE_TYPE_FLOAT;
- } else if (strcmp(name, "int") == 0 || strcmp(name, "integer") == 0 || strcmp(name, "Integer") == 0) {
- return VALUE_TYPE_INTEGER;
- } else if (strcmp(name, "short") == 0 || strcmp(name, "Short") == 0) {
- return VALUE_TYPE_SHORT;
- } else if (strcmp(name, "byte") == 0 || strcmp(name, "Byte") == 0) {
- return VALUE_TYPE_BYTE;
- } else if (strcmp(name, "char") == 0 || strcmp(name, "Character") == 0) {
- return VALUE_TYPE_CHAR;
- } else if (strcmp(name, "boolean") == 0 || strcmp(name, "Boolean") == 0) {
- return VALUE_TYPE_BOOLEAN;
- } else {
- return VALUE_TYPE_STRING;
- }
-}
-
-#ifdef RSA_ENDPOINT_TEST_READER
-int main() {
- array_list_pt list = NULL;
- endpoint_descriptor_reader_pt reader = NULL;
-
- char *doc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
-"<endpoint-descriptions xmlns=\"http://www.osgi.org/xmlns/rsa/v1.0.0\">"
- "<endpoint-description>"
- "<property name=\"endpoint.service.id\" value-type=\"long\" value=\"6\"/>"
- "<property name=\"endpoint.framework.uuid\" value=\"2983D849-93B1-4C2C-AC6D-5BCDA93ACB96\"/>"
- "<property name=\"service.intents\">"
- "<list>"
- "<value>SOAP</value>"
- "<value>HTTP</value>"
- "</list>"
- "</property>"
- "<property name=\"endpoint.id\" value=\"11111111-1111-1111-1111-111111111111\" />"
- "<property name=\"objectClass\"><array><value>com.acme.Foo</value></array></property>"
- "<property name=\"endpoint.package.version.com.acme\" value=\"4.2\" />"
- "<property name=\"service.imported.configs\" value=\"com.acme\" />"
- "<property name=\"service.imported\" value=\"true\"/>"
- "<property name=\"com.acme.ws.xml\">"
- "<xml>"
- "<config xmlns=\"http://acme.com/defs\">"
- "<port>1029</port>"
- "<host>www.acme.com</host>"
- "</config>"
- "</xml>"
- "</property>"
- "</endpoint-description>"
- "<endpoint-description>"
- "<property name=\"endpoint.service.id\" value-type=\"long\" value=\"5\"/>"
- "<property name=\"endpoint.framework.uuid\" value=\"2983D849-93B1-4C2C-AC6D-5BCDA93ACB96\"/>"
- "<property name=\"service.intents\">"
- "<list>"
- "<value>SOAP</value>"
- "<value>HTTP</value>"
- "</list>"
- "</property>"
- "<property name=\"endpoint.id\" value=\"22222222-2222-2222-2222-222222222222\" />"
- "<property name=\"objectClass\"><array><value>com.acme.Bar</value></array></property>"
- "<property name=\"endpoint.package.version.com.acme\" value=\"4.2\" />"
- "<property name=\"service.imported.configs\" value=\"com.acme\" />"
- "<property name=\"com.acme.ws.xml\">"
- "<xml>"
- "<config xmlns=\"http://acme.com/defs\">"
- "<port>1029</port>"
- "<host>www.acme.com</host>"
- "</config>"
- "</xml>"
- "</property>"
- "</endpoint-description>"
- "</endpoint-descriptions>";
-
- endpointDescriptorReader_create(&reader);
-
- endpointDescriptorReader_parseDocument(reader, doc, &list);
-
- int i;
- for (i = 0; i < arrayList_size(list); i++) {
- printf("\nEndpoint description #%d:\n", (i+1));
- endpoint_description_pt edp = arrayList_get(list, i);
- printf("Id: %s\n", edp->id);
- printf("Service Id: %lu\n", edp->serviceId);
- printf("Framework UUID: %s\n", edp->frameworkUUID);
- printf("Service: %s\n", edp->service);
-
- properties_pt props = edp->properties;
- if (props) {
- printf("Service properties:\n");
- hash_map_iterator_pt iter = hashMapIterator_create(props);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
-
- printf("- %s => '%s'\n", hashMapEntry_getKey(entry), hashMapEntry_getValue(entry));
- }
- hashMapIterator_destroy(iter);
- } else {
- printf("No service properties...\n");
- }
-
-
- endpointDescription_destroy(edp);
- }
-
- if (list != NULL) {
- arrayList_destroy(list);
- }
-
- endpointDescriptorReader_destroy(reader);
-
- return 0;
-}
-#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery/private/src/endpoint_descriptor_writer.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/src/endpoint_descriptor_writer.c b/remote_services/discovery/private/src/endpoint_descriptor_writer.c
deleted file mode 100644
index 71b07b4..0000000
--- a/remote_services/discovery/private/src/endpoint_descriptor_writer.c
+++ /dev/null
@@ -1,233 +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.
- */
-/*
- * endpoint_descriptor_writer.c
- *
- * \date 26 Jul 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <string.h>
-#include <libxml/xmlwriter.h>
-
-#include "constants.h"
-#include "remote_constants.h"
-
-#include "endpoint_description.h"
-#include "endpoint_descriptor_common.h"
-#include "endpoint_descriptor_writer.h"
-
-struct endpoint_descriptor_writer {
- xmlBufferPtr buffer;
- xmlTextWriterPtr writer;
-};
-
-static celix_status_t endpointDescriptorWriter_writeEndpoint(endpoint_descriptor_writer_pt writer, endpoint_description_pt endpoint);
-
-static char* valueTypeToString(valueType type);
-
-celix_status_t endpointDescriptorWriter_create(endpoint_descriptor_writer_pt *writer) {
- celix_status_t status = CELIX_SUCCESS;
-
- *writer = malloc(sizeof(**writer));
- if (!*writer) {
- status = CELIX_ENOMEM;
- } else {
- (*writer)->buffer = xmlBufferCreate();
- if ((*writer)->buffer == NULL) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- (*writer)->writer = xmlNewTextWriterMemory((*writer)->buffer, 0);
- if ((*writer)->writer == NULL) {
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
- }
-
- return status;
-}
-
-celix_status_t endpointDescriptorWriter_destroy(endpoint_descriptor_writer_pt writer) {
- xmlFreeTextWriter(writer->writer);
- xmlBufferFree(writer->buffer);
- free(writer);
- return CELIX_SUCCESS;
-}
-
-celix_status_t endpointDescriptorWriter_writeDocument(endpoint_descriptor_writer_pt writer, array_list_pt endpoints, char **document) {
- celix_status_t status = CELIX_SUCCESS;
- int rc;
-
- rc = xmlTextWriterStartDocument(writer->writer, NULL, "UTF-8", NULL);
- if (rc < 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- rc = xmlTextWriterStartElementNS(writer->writer, NULL, ENDPOINT_DESCRIPTIONS, XMLNS);
- if (rc < 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- unsigned int i;
- for (i = 0; i < arrayList_size(endpoints); i++) {
- endpoint_description_pt endpoint = arrayList_get(endpoints, i);
- status = endpointDescriptorWriter_writeEndpoint(writer, endpoint);
- }
- if (status == CELIX_SUCCESS) {
- rc = xmlTextWriterEndElement(writer->writer);
- if (rc < 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- rc = xmlTextWriterEndDocument(writer->writer);
- if (rc < 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- *document = (char *) writer->buffer->content;
- }
- }
- }
- }
- }
-
- return status;
-}
-
-static celix_status_t endpointDescriptorWriter_writeArrayValue(xmlTextWriterPtr writer, const xmlChar* value) {
- xmlTextWriterStartElement(writer, ARRAY);
- xmlTextWriterStartElement(writer, VALUE);
- xmlTextWriterWriteString(writer, value);
- xmlTextWriterEndElement(writer); // value
- xmlTextWriterEndElement(writer); // array
-
- return CELIX_SUCCESS;
-}
-
-static celix_status_t endpointDescriptorWriter_writeTypedValue(xmlTextWriterPtr writer, valueType type, const xmlChar* value) {
- xmlTextWriterWriteAttribute(writer, VALUE_TYPE, (const xmlChar*) valueTypeToString(type));
- xmlTextWriterWriteAttribute(writer, VALUE, value);
-
- return CELIX_SUCCESS;
-}
-
-static celix_status_t endpointDescriptorWriter_writeUntypedValue(xmlTextWriterPtr writer, const xmlChar* value) {
- xmlTextWriterWriteAttribute(writer, VALUE, value);
-
- return CELIX_SUCCESS;
-}
-
-static celix_status_t endpointDescriptorWriter_writeEndpoint(endpoint_descriptor_writer_pt writer, endpoint_description_pt endpoint) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (endpoint == NULL || writer == NULL) {
- status = CELIX_ILLEGAL_ARGUMENT;
- } else {
- xmlTextWriterStartElement(writer->writer, ENDPOINT_DESCRIPTION);
-
- hash_map_iterator_pt iter = hashMapIterator_create(endpoint->properties);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
-
- void* propertyName = hashMapEntry_getKey(entry);
- const xmlChar* propertyValue = (const xmlChar*) hashMapEntry_getValue(entry);
-
- xmlTextWriterStartElement(writer->writer, PROPERTY);
- xmlTextWriterWriteAttribute(writer->writer, NAME, propertyName);
-
- if (strcmp(OSGI_FRAMEWORK_OBJECTCLASS, (char*) propertyName) == 0) {
- // objectClass *must* be represented as array of string values...
- endpointDescriptorWriter_writeArrayValue(writer->writer, propertyValue);
- } else if (strcmp(OSGI_RSA_ENDPOINT_SERVICE_ID, (char*) propertyName) == 0) {
- // endpoint.service.id *must* be represented as long value...
- endpointDescriptorWriter_writeTypedValue(writer->writer, VALUE_TYPE_LONG, propertyValue);
- } else {
- // represent all other values as plain string values...
- endpointDescriptorWriter_writeUntypedValue(writer->writer, propertyValue);
- }
-
- xmlTextWriterEndElement(writer->writer);
- }
- hashMapIterator_destroy(iter);
-
- xmlTextWriterEndElement(writer->writer);
- }
-
- return status;
-}
-
-
-static char* valueTypeToString(valueType type) {
- switch (type) {
- case VALUE_TYPE_BOOLEAN:
- return "boolean";
- case VALUE_TYPE_BYTE:
- return "byte";
- case VALUE_TYPE_CHAR:
- return "char";
- case VALUE_TYPE_DOUBLE:
- return "double";
- case VALUE_TYPE_FLOAT:
- return "float";
- case VALUE_TYPE_INTEGER:
- return "int";
- case VALUE_TYPE_LONG:
- return "long";
- case VALUE_TYPE_SHORT:
- return "short";
- case VALUE_TYPE_STRING:
- // FALL-THROUGH!
- default:
- return "string";
- }
-}
-
-#ifdef RSA_ENDPOINT_TEST_WRITER
-int main() {
- endpoint_descriptor_writer_pt writer = NULL;
- endpointDescriptorWriter_create(&writer);
- array_list_pt list = NULL;
- arrayList_create(&list);
-
- properties_pt props = properties_create();
- properties_set(props, "objectClass", "com.acme.Foo");
- properties_set(props, "endpoint.service.id", "3");
- properties_set(props, "endpoint.id", "abcdefghijklmnopqrstuvwxyz");
- properties_set(props, "endpoint.framework.uuid", "2983D849-93B1-4C2C-AC6D-5BCDA93ACB96");
- endpoint_description_pt epd = NULL;
- endpointDescription_create(props, &epd);
- arrayList_add(list, epd);
-
- properties_pt props2 = properties_create();
- properties_set(props2, "objectClass", "com.acme.Bar");
- properties_set(props, "endpoint.service.id", "4");
- properties_set(props, "endpoint.id", "abcdefghijklmnopqrstuvwxyz");
- properties_set(props, "endpoint.framework.uuid", "2983D849-93B1-4C2C-AC6D-5BCDA93ACB96");
- endpoint_description_pt epd2 = NULL;
- endpointDescription_create(props2, &epd2);
- arrayList_add(list, epd2);
-
- char *buffer = NULL;
- endpointDescriptorWriter_writeDocument(writer, list, &buffer);
-
- arrayList_destroy(list);
- endpointDescription_destroy(epd);
- endpointDescription_destroy(epd2);
- endpointDescriptorWriter_destroy(writer);
-
- printf("%s\n", buffer);
-}
-#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery/private/src/endpoint_discovery_poller.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/src/endpoint_discovery_poller.c b/remote_services/discovery/private/src/endpoint_discovery_poller.c
deleted file mode 100644
index 73fb7ba..0000000
--- a/remote_services/discovery/private/src/endpoint_discovery_poller.c
+++ /dev/null
@@ -1,403 +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.
- */
-/*
- * endpoint_discovery_poller.c
- *
- * \date 3 Jul 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdbool.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <curl/curl.h>
-
-#include "bundle_context.h"
-#include "log_helper.h"
-#include "utils.h"
-
-#include "discovery_impl.h"
-
-#include "endpoint_descriptor_reader.h"
-
-
-#define DISCOVERY_POLL_INTERVAL "DISCOVERY_CFG_POLL_INTERVAL"
-#define DEFAULT_POLL_INTERVAL "10"
-
-
-static void *endpointDiscoveryPoller_performPeriodicPoll(void *data);
-celix_status_t endpointDiscoveryPoller_poll(endpoint_discovery_poller_pt poller, char *url, array_list_pt currentEndpoints);
-static celix_status_t endpointDiscoveryPoller_getEndpoints(endpoint_discovery_poller_pt poller, char *url, array_list_pt *updatedEndpoints);
-static celix_status_t endpointDiscoveryPoller_endpointDescriptionEquals(const void *endpointPtr, const void *comparePtr, bool *equals);
-
-/**
- * Allocates memory and initializes a new endpoint_discovery_poller instance.
- */
-celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_poller_pt *poller) {
- celix_status_t status;
-
- *poller = malloc(sizeof(struct endpoint_discovery_poller));
- if (!*poller) {
- return CELIX_ENOMEM;
- }
-
- (*poller)->loghelper = &discovery->loghelper;
-
- status = celixThreadMutex_create(&(*poller)->pollerLock, NULL);
- if (status != CELIX_SUCCESS) {
- return status;
- }
-
- const char* interval = NULL;
- status = bundleContext_getProperty(context, DISCOVERY_POLL_INTERVAL, &interval);
- if (!interval) {
- interval = DEFAULT_POLL_INTERVAL;
- }
-
- const char* endpointsProp = NULL;
- status = bundleContext_getProperty(context, DISCOVERY_POLL_ENDPOINTS, &endpointsProp);
- if (!endpointsProp) {
- endpointsProp = DEFAULT_POLL_ENDPOINTS;
- }
- // we're going to mutate the string with strtok, so create a copy...
- char* endpoints = strdup(endpointsProp);
-
- (*poller)->poll_interval = atoi(interval);
- (*poller)->discovery = discovery;
- (*poller)->running = false;
- (*poller)->entries = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
-
- const char* sep = ",";
- char *save_ptr = NULL;
- char* tok = strtok_r(endpoints, sep, &save_ptr);
- while (tok) {
- endpointDiscoveryPoller_addDiscoveryEndpoint(*poller, utils_stringTrim(tok));
- tok = strtok_r(NULL, sep, &save_ptr);
- }
- // Clean up after ourselves...
- free(endpoints);
-
- status = celixThreadMutex_lock(&(*poller)->pollerLock);
- if (status != CELIX_SUCCESS) {
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- (*poller)->running = true;
-
- status += celixThread_create(&(*poller)->pollerThread, NULL, endpointDiscoveryPoller_performPeriodicPoll, *poller);
- status += celixThreadMutex_unlock(&(*poller)->pollerLock);
-
- if(status != CELIX_SUCCESS){
- status = CELIX_BUNDLE_EXCEPTION;
- }
-
- return status;
-}
-
-/**
- * Destroys and frees up memory for a given endpoint_discovery_poller struct.
- */
-celix_status_t endpointDiscoveryPoller_destroy(endpoint_discovery_poller_pt poller) {
- celix_status_t status;
-
- poller->running = false;
-
- celixThread_join(poller->pollerThread, NULL);
-
- hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries);
- while (hashMapIterator_hasNext(iterator)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);
-
- if ( endpointDiscoveryPoller_removeDiscoveryEndpoint(poller, (char*) hashMapEntry_getKey(entry)) == CELIX_SUCCESS) {
- hashMapIterator_destroy(iterator);
- iterator = hashMapIterator_create(poller->entries);
- }
- }
- hashMapIterator_destroy(iterator);
-
- status = celixThreadMutex_lock(&poller->pollerLock);
-
- if (status != CELIX_SUCCESS) {
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- hashMap_destroy(poller->entries, true, false);
-
- status = celixThreadMutex_unlock(&poller->pollerLock);
-
- poller->loghelper = NULL;
-
- free(poller);
-
- return status;
-}
-
-
-celix_status_t endpointDiscoveryPoller_getDiscoveryEndpoints(endpoint_discovery_poller_pt poller, array_list_pt urls) {
- celixThreadMutex_lock(&(poller)->pollerLock);
-
- hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries);
-
- while(hashMapIterator_hasNext(iterator)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);
- char* toAdd = strdup((char*) hashMapEntry_getKey(entry));
- arrayList_add(urls, toAdd);
- }
-
- hashMapIterator_destroy(iterator);
-
- celixThreadMutex_unlock(&(poller)->pollerLock);
-
- return CELIX_SUCCESS;
-}
-
-/**
- * Adds a new endpoint URL to the list of polled endpoints.
- */
-celix_status_t endpointDiscoveryPoller_addDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url) {
- celix_status_t status;
-
- status = celixThreadMutex_lock(&(poller)->pollerLock);
- if (status != CELIX_SUCCESS) {
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- // Avoid memory leaks when adding an already existing URL...
- array_list_pt endpoints = hashMap_get(poller->entries, url);
- if (endpoints == NULL) {
- status = arrayList_createWithEquals(endpointDiscoveryPoller_endpointDescriptionEquals, &endpoints);
-
- if (status == CELIX_SUCCESS) {
- logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_DEBUG, "ENDPOINT_POLLER: add new discovery endpoint with url %s", url);
- hashMap_put(poller->entries, strdup(url), endpoints);
- endpointDiscoveryPoller_poll(poller, url, endpoints);
- }
- }
-
- status = celixThreadMutex_unlock(&poller->pollerLock);
-
- return status;
-}
-
-/**
- * Removes an endpoint URL from the list of polled endpoints.
- */
-celix_status_t endpointDiscoveryPoller_removeDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (celixThreadMutex_lock(&poller->pollerLock) != CELIX_SUCCESS) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- hash_map_entry_pt entry = hashMap_getEntry(poller->entries, url);
-
- if (entry == NULL) {
- logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_DEBUG, "ENDPOINT_POLLER: There was no entry found belonging to url %s - maybe already removed?", url);
- } else {
- char* origKey = hashMapEntry_getKey(entry);
-
- logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_DEBUG, "ENDPOINT_POLLER: remove discovery endpoint with url %s", url);
-
- array_list_pt entries = hashMap_remove(poller->entries, url);
-
- if (entries != NULL) {
- for (unsigned int i = arrayList_size(entries); i > 0; i--) {
- endpoint_description_pt endpoint = arrayList_get(entries, i - 1);
- discovery_removeDiscoveredEndpoint(poller->discovery, endpoint);
- arrayList_remove(entries, i - 1);
- endpointDescription_destroy(endpoint);
- }
- arrayList_destroy(entries);
- }
-
- free(origKey);
- }
- status = celixThreadMutex_unlock(&poller->pollerLock);
- }
-
- return status;
-}
-
-
-
-
-celix_status_t endpointDiscoveryPoller_poll(endpoint_discovery_poller_pt poller, char *url, array_list_pt currentEndpoints) {
- celix_status_t status;
- array_list_pt updatedEndpoints = NULL;
-
- // create an arraylist with a custom equality test to ensure we can find endpoints properly...
- arrayList_createWithEquals(endpointDiscoveryPoller_endpointDescriptionEquals, &updatedEndpoints);
- status = endpointDiscoveryPoller_getEndpoints(poller, url, &updatedEndpoints);
-
- if (status == CELIX_SUCCESS) {
- if (updatedEndpoints!=NULL) {
- for (unsigned int i = arrayList_size(currentEndpoints); i > 0; i--) {
- endpoint_description_pt endpoint = arrayList_get(currentEndpoints, i - 1);
-
- if (!arrayList_contains(updatedEndpoints, endpoint)) {
- status = discovery_removeDiscoveredEndpoint(poller->discovery, endpoint);
- arrayList_remove(currentEndpoints, i - 1);
- endpointDescription_destroy(endpoint);
- }
- }
-
- for (int i = arrayList_size(updatedEndpoints); i > 0; i--) {
- endpoint_description_pt endpoint = arrayList_remove(updatedEndpoints, 0);
-
- if (!arrayList_contains(currentEndpoints, endpoint)) {
- arrayList_add(currentEndpoints, endpoint);
- status = discovery_addDiscoveredEndpoint(poller->discovery, endpoint);
- } else {
- endpointDescription_destroy(endpoint);
-
- }
- }
- }
- }
-
- if(updatedEndpoints!=NULL){
- arrayList_destroy(updatedEndpoints);
- }
-
- return status;
-}
-
-static void *endpointDiscoveryPoller_performPeriodicPoll(void *data) {
- endpoint_discovery_poller_pt poller = (endpoint_discovery_poller_pt) data;
-
- useconds_t interval = (useconds_t) (poller->poll_interval * 1000000L);
-
- while (poller->running) {
- usleep(interval);
- celix_status_t status = celixThreadMutex_lock(&poller->pollerLock);
-
- if (status != CELIX_SUCCESS) {
- logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_WARNING, "ENDPOINT_POLLER: failed to obtain lock; retrying...");
- } else {
- hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries);
-
- while (hashMapIterator_hasNext(iterator)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);
-
- char *url = hashMapEntry_getKey(entry);
- array_list_pt currentEndpoints = hashMapEntry_getValue(entry);
-
- endpointDiscoveryPoller_poll(poller, url, currentEndpoints);
- }
-
- hashMapIterator_destroy(iterator);
- }
-
- status = celixThreadMutex_unlock(&poller->pollerLock);
- if (status != CELIX_SUCCESS) {
- logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_WARNING, "ENDPOINT_POLLER: failed to release lock; retrying...");
- }
- }
-
- return NULL;
-}
-
-
-
-struct MemoryStruct {
- char *memory;
- size_t size;
-};
-
-static size_t endpointDiscoveryPoller_writeMemory(void *contents, size_t size, size_t nmemb, void *memoryPtr) {
- size_t realsize = size * nmemb;
- struct MemoryStruct *mem = (struct MemoryStruct *)memoryPtr;
-
- mem->memory = realloc(mem->memory, mem->size + realsize + 1);
- if(mem->memory == NULL) {
- printf("ENDPOINT_POLLER: not enough memory (realloc returned NULL)!");
- return 0;
- }
-
- memcpy(&(mem->memory[mem->size]), contents, realsize);
- mem->size += realsize;
- mem->memory[mem->size] = 0;
-
- return realsize;
-}
-
-static celix_status_t endpointDiscoveryPoller_getEndpoints(endpoint_discovery_poller_pt poller, char *url, array_list_pt *updatedEndpoints) {
- celix_status_t status = CELIX_SUCCESS;
-
-
- CURL *curl = NULL;
- CURLcode res = CURLE_OK;
-
- struct MemoryStruct chunk;
- chunk.memory = malloc(1);
- chunk.size = 0;
-
- curl = curl_easy_init();
- if (!curl) {
- status = CELIX_ILLEGAL_STATE;
- } else {
- curl_easy_setopt(curl, CURLOPT_URL, url);
- curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, endpointDiscoveryPoller_writeMemory);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
- curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5L);
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
- res = curl_easy_perform(curl);
-
- curl_easy_cleanup(curl);
- }
-
- // process endpoints file
- if (res == CURLE_OK) {
- endpoint_descriptor_reader_pt reader = NULL;
-
- status = endpointDescriptorReader_create(poller, &reader);
- if (status == CELIX_SUCCESS) {
- status = endpointDescriptorReader_parseDocument(reader, chunk.memory, updatedEndpoints);
- }
-
- if (reader) {
- endpointDescriptorReader_destroy(reader);
- }
- } else {
- logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_ERROR, "ENDPOINT_POLLER: unable to read endpoints from %s, reason: %s", url, curl_easy_strerror(res));
- }
-
- // clean up endpoints file
- if (chunk.memory) {
- free(chunk.memory);
- }
-
- return status;
-}
-
-static celix_status_t endpointDiscoveryPoller_endpointDescriptionEquals(const void *endpointPtr, const void *comparePtr, bool *equals) {
- endpoint_description_pt endpoint = (endpoint_description_pt) endpointPtr;
- endpoint_description_pt compare = (endpoint_description_pt) comparePtr;
-
- if (strcmp(endpoint->id, compare->id) == 0) {
- *equals = true;
- } else {
- *equals = false;
- }
-
- return CELIX_SUCCESS;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery/private/src/endpoint_discovery_server.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/src/endpoint_discovery_server.c b/remote_services/discovery/private/src/endpoint_discovery_server.c
deleted file mode 100644
index f5f82af..0000000
--- a/remote_services/discovery/private/src/endpoint_discovery_server.c
+++ /dev/null
@@ -1,450 +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.
- */
-/*
- * endpoint_discovery_server.c
- *
- * \date Aug 12, 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <string.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#ifndef ANDROID
-#include <ifaddrs.h>
-#endif
-#include "civetweb.h"
-#include "celix_errno.h"
-#include "utils.h"
-#include "log_helper.h"
-#include "discovery.h"
-#include "discovery_impl.h"
-
-#include "endpoint_descriptor_writer.h"
-
-// defines how often the webserver is restarted (with an increased port number)
-#define MAX_NUMBER_OF_RESTARTS 15
-#define DEFAULT_SERVER_THREADS "1"
-
-#define CIVETWEB_REQUEST_NOT_HANDLED 0
-#define CIVETWEB_REQUEST_HANDLED 1
-
-static const char *response_headers =
- "HTTP/1.1 200 OK\r\n"
- "Cache: no-cache\r\n"
- "Content-Type: application/xml;charset=utf-8\r\n"
- "\r\n";
-
-struct endpoint_discovery_server {
- log_helper_pt* loghelper;
- hash_map_pt entries; // key = endpointId, value = endpoint_descriptor_pt
-
- celix_thread_mutex_t serverLock;
-
- const char* path;
- const char *port;
- const char* ip;
- struct mg_context* ctx;
-};
-
-// Forward declarations...
-static int endpointDiscoveryServer_callback(struct mg_connection *conn);
-static char* format_path(const char* path);
-
-#ifndef ANDROID
-static celix_status_t endpointDiscoveryServer_getIpAdress(char* interface, char** ip);
-#endif
-
-celix_status_t endpointDiscoveryServer_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_server_pt *server) {
- celix_status_t status;
-
- const char *port = NULL;
- const char *ip = NULL;
- char *detectedIp = NULL;
- const char *path = NULL;
- const char *retries = NULL;
-
- int max_ep_num = MAX_NUMBER_OF_RESTARTS;
-
- *server = malloc(sizeof(struct endpoint_discovery_server));
- if (!*server) {
- return CELIX_ENOMEM;
- }
-
- (*server)->loghelper = &discovery->loghelper;
- (*server)->entries = hashMap_create(&utils_stringHash, NULL, &utils_stringEquals, NULL);
- if (!(*server)->entries) {
- return CELIX_ENOMEM;
- }
-
- status = celixThreadMutex_create(&(*server)->serverLock, NULL);
- if (status != CELIX_SUCCESS) {
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- bundleContext_getProperty(context, DISCOVERY_SERVER_IP, &ip);
-#ifndef ANDROID
- if (ip == NULL) {
- const char *interface = NULL;
-
- bundleContext_getProperty(context, DISCOVERY_SERVER_INTERFACE, &interface);
- if ((interface != NULL) && (endpointDiscoveryServer_getIpAdress((char*)interface, &detectedIp) != CELIX_SUCCESS)) {
- logHelper_log(*(*server)->loghelper, OSGI_LOGSERVICE_WARNING, "Could not retrieve IP adress for interface %s", interface);
- }
-
- if (detectedIp == NULL) {
- endpointDiscoveryServer_getIpAdress(NULL, &detectedIp);
- }
-
- ip = detectedIp;
- }
-#endif
-
- if (ip != NULL) {
- logHelper_log(*(*server)->loghelper, OSGI_LOGSERVICE_INFO, "Using %s for service annunciation", ip);
- (*server)->ip = strdup(ip);
- }
- else {
- logHelper_log(*(*server)->loghelper, OSGI_LOGSERVICE_WARNING, "No IP address for service annunciation set. Using %s", DEFAULT_SERVER_IP);
- (*server)->ip = strdup((char*) DEFAULT_SERVER_IP);
- }
-
- if (detectedIp != NULL) {
- free(detectedIp);
- }
-
- bundleContext_getProperty(context, DISCOVERY_SERVER_PORT, &port);
- if (port == NULL) {
- port = DEFAULT_SERVER_PORT;
- }
-
- bundleContext_getProperty(context, DISCOVERY_SERVER_PATH, &path);
- if (path == NULL) {
- path = DEFAULT_SERVER_PATH;
- }
-
- bundleContext_getProperty(context, DISCOVERY_SERVER_MAX_EP, &retries);
- if (retries != NULL) {
- errno=0;
- max_ep_num = strtol(retries,NULL,10);
- if(errno!=0 || max_ep_num<=0){
- max_ep_num=MAX_NUMBER_OF_RESTARTS;
- }
- }
-
- (*server)->path = format_path(path);
-
- const struct mg_callbacks callbacks = {
- .begin_request = endpointDiscoveryServer_callback,
- };
-
- unsigned int port_counter = 0;
- char newPort[10];
-
- do {
- const char *options[] = {
- "listening_ports", port,
- "num_threads", DEFAULT_SERVER_THREADS,
- NULL
- };
-
- (*server)->ctx = mg_start(&callbacks, (*server), options);
-
- if ((*server)->ctx != NULL)
- {
- logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "Starting discovery server on port %s...", port);
- }
- else {
- errno = 0;
- char* endptr = (char*)port;
- long currentPort = strtol(port, &endptr, 10);
-
- if (*endptr || errno != 0) {
- currentPort = strtol(DEFAULT_SERVER_PORT, NULL, 10);
- }
-
- port_counter++;
- snprintf(&newPort[0], 10, "%ld", (currentPort+1));
-
- logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_ERROR, "Error while starting discovery server on port %s - retrying on port %s...", port, newPort);
- port = newPort;
-
- }
-
- } while(((*server)->ctx == NULL) && (port_counter < max_ep_num));
-
- (*server)->port = strdup(port);
-
- return status;
-}
-
-celix_status_t endpointDiscoveryServer_getUrl(endpoint_discovery_server_pt server, char* url)
-{
- celix_status_t status = CELIX_BUNDLE_EXCEPTION;
-
- if (server->ip && server->port && server->path) {
- sprintf(url, "http://%s:%s/%s", server->ip, server->port, server->path);
- status = CELIX_SUCCESS;
- }
-
- return status;
-}
-
-celix_status_t endpointDiscoveryServer_destroy(endpoint_discovery_server_pt server) {
- celix_status_t status;
-
- // stop & block until the actual server is shut down...
- if (server->ctx != NULL) {
- mg_stop(server->ctx);
- server->ctx = NULL;
- }
-
- status = celixThreadMutex_lock(&server->serverLock);
-
- hashMap_destroy(server->entries, true /* freeKeys */, false /* freeValues */);
-
- status = celixThreadMutex_unlock(&server->serverLock);
- status = celixThreadMutex_destroy(&server->serverLock);
-
- free((void*) server->path);
- free((void*) server->port);
- free((void*) server->ip);
-
- free(server);
-
- return status;
-}
-
-celix_status_t endpointDiscoveryServer_addEndpoint(endpoint_discovery_server_pt server, endpoint_description_pt endpoint) {
- celix_status_t status;
-
- status = celixThreadMutex_lock(&server->serverLock);
- if (status != CELIX_SUCCESS) {
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- // create a local copy of the endpointId which we can control...
- char* endpointId = strdup(endpoint->id);
- endpoint_description_pt cur_value = hashMap_get(server->entries, endpointId);
- if (!cur_value) {
- logHelper_log(*server->loghelper, OSGI_LOGSERVICE_INFO, "exposing new endpoint \"%s\"...", endpointId);
-
- hashMap_put(server->entries, endpointId, endpoint);
- }
-
- status = celixThreadMutex_unlock(&server->serverLock);
- if (status != CELIX_SUCCESS) {
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- return status;
-}
-
-celix_status_t endpointDiscoveryServer_removeEndpoint(endpoint_discovery_server_pt server, endpoint_description_pt endpoint) {
- celix_status_t status;
-
- status = celixThreadMutex_lock(&server->serverLock);
- if (status != CELIX_SUCCESS) {
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- hash_map_entry_pt entry = hashMap_getEntry(server->entries, endpoint->id);
- if (entry) {
- char* key = hashMapEntry_getKey(entry);
-
- logHelper_log(*server->loghelper, OSGI_LOGSERVICE_INFO, "removing endpoint \"%s\"...\n", key);
-
- hashMap_remove(server->entries, key);
-
- // we've made this key, see _addEnpoint above...
- free((void*) key);
- }
-
- status = celixThreadMutex_unlock(&server->serverLock);
- if (status != CELIX_SUCCESS) {
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- return status;
-}
-
-static char* format_path(const char* path) {
- char* result = strdup(path);
- result = utils_stringTrim(result);
- // check whether the path starts with a leading slash...
- if (result[0] != '/') {
- size_t len = strlen(result);
- result = realloc(result, len + 2);
- memmove(result + 1, result, len);
- result[0] = '/';
- result[len + 1] = 0;
- }
- return result;
-}
-
-static celix_status_t endpointDiscoveryServer_getEndpoints(endpoint_discovery_server_pt server, const char* the_endpoint_id, array_list_pt *endpoints) {
- celix_status_t status;
-
- status = arrayList_create(endpoints);
- if (status != CELIX_SUCCESS) {
- return CELIX_ENOMEM;
- }
-
-
- hash_map_iterator_pt iter = hashMapIterator_create(server->entries);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
-
- char* endpoint_id = hashMapEntry_getKey(entry);
- if (the_endpoint_id == NULL || strcmp(the_endpoint_id, endpoint_id) == 0) {
- endpoint_description_pt endpoint = hashMapEntry_getValue(entry);
-
- arrayList_add(*endpoints, endpoint);
- }
- }
- hashMapIterator_destroy(iter);
-
- return status;
-}
-
-static int endpointDiscoveryServer_writeEndpoints(struct mg_connection* conn, array_list_pt endpoints) {
- celix_status_t status;
- int rv = CIVETWEB_REQUEST_NOT_HANDLED;
-
- endpoint_descriptor_writer_pt writer = NULL;
- status = endpointDescriptorWriter_create(&writer);
- if (status == CELIX_SUCCESS) {
-
- char *buffer = NULL;
- status = endpointDescriptorWriter_writeDocument(writer, endpoints, &buffer);
- if (buffer) {
- mg_write(conn, response_headers, strlen(response_headers));
- mg_write(conn, buffer, strlen(buffer));
- }
-
- rv = CIVETWEB_REQUEST_HANDLED;
- }
-
- if(writer!=NULL){
- endpointDescriptorWriter_destroy(writer);
- }
-
- return rv;
-}
-
-// returns all endpoints as XML...
-static int endpointDiscoveryServer_returnAllEndpoints(endpoint_discovery_server_pt server, struct mg_connection* conn) {
- int status = CIVETWEB_REQUEST_NOT_HANDLED;
-
- array_list_pt endpoints = NULL;
-
- if (celixThreadMutex_lock(&server->serverLock) == CELIX_SUCCESS) {
- endpointDiscoveryServer_getEndpoints(server, NULL, &endpoints);
- if (endpoints) {
- status = endpointDiscoveryServer_writeEndpoints(conn, endpoints);
-
- arrayList_destroy(endpoints);
- }
-
-
- celixThreadMutex_unlock(&server->serverLock);
- }
-
- return status;
-}
-
-// returns a single endpoint as XML...
-static int endpointDiscoveryServer_returnEndpoint(endpoint_discovery_server_pt server, struct mg_connection* conn, const char* endpoint_id) {
- int status = CIVETWEB_REQUEST_NOT_HANDLED;
-
- array_list_pt endpoints = NULL;
-
- if (celixThreadMutex_lock(&server->serverLock) == CELIX_SUCCESS) {
- endpointDiscoveryServer_getEndpoints(server, endpoint_id, &endpoints);
- if (endpoints) {
- status = endpointDiscoveryServer_writeEndpoints(conn, endpoints);
-
- arrayList_destroy(endpoints);
- }
-
- celixThreadMutex_unlock(&server->serverLock);
- }
-
- return status;
-}
-
-static int endpointDiscoveryServer_callback(struct mg_connection* conn) {
- int status = CIVETWEB_REQUEST_NOT_HANDLED;
-
- const struct mg_request_info *request_info = mg_get_request_info(conn);
- if (request_info->uri != NULL && strcmp("GET", request_info->request_method) == 0) {
- endpoint_discovery_server_pt server = request_info->user_data;
-
- const char *uri = request_info->uri;
- const size_t path_len = strlen(server->path);
- const size_t uri_len = strlen(uri);
-
- if (strncmp(server->path, uri, strlen(server->path)) == 0) {
- // Be lenient when it comes to the trailing slash...
- if (path_len == uri_len || (uri_len == (path_len + 1) && uri[path_len] == '/')) {
- status = endpointDiscoveryServer_returnAllEndpoints(server, conn);
- } else {
- const char* endpoint_id = uri + path_len + 1; // right after the slash...
-
- status = endpointDiscoveryServer_returnEndpoint(server, conn, endpoint_id);
- }
- }
- }
-
- return status;
-}
-
-#ifndef ANDROID
-static celix_status_t endpointDiscoveryServer_getIpAdress(char* interface, char** ip) {
- celix_status_t status = CELIX_BUNDLE_EXCEPTION;
-
- struct ifaddrs *ifaddr, *ifa;
- char host[NI_MAXHOST];
-
- if (getifaddrs(&ifaddr) != -1)
- {
- for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
- {
- if (ifa->ifa_addr == NULL)
- continue;
-
- if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
- if (interface == NULL) {
- *ip = strdup(host);
- status = CELIX_SUCCESS;
- }
- else if (strcmp(ifa->ifa_name, interface) == 0) {
- *ip = strdup(host);
- status = CELIX_SUCCESS;
- }
- }
- }
-
- freeifaddrs(ifaddr);
- }
-
- return status;
-}
-#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/CMakeLists.txt b/remote_services/discovery_common/CMakeLists.txt
new file mode 100644
index 0000000..9388c90
--- /dev/null
+++ b/remote_services/discovery_common/CMakeLists.txt
@@ -0,0 +1,33 @@
+# 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.
+
+
+find_package(LibXml2 REQUIRED)
+
+add_library(discovery_common STATIC
+ src/discovery.c
+ src/discovery_activator.c
+ src/endpoint_descriptor_reader.c
+ src/endpoint_descriptor_writer.c
+ src/endpoint_discovery_poller.c
+ src/endpoint_discovery_server.c
+ src/civetweb.c
+)
+target_include_directories(discovery_common PUBLIC include)
+target_include_directories(discovery_common PRIVATE src ${LIBXML2_INCLUDE_DIR})
+target_link_libraries(discovery_common PRIVATE ${LIBXML2_LIBRARIES} Celix::framework)
+target_link_libraries(discovery_common PUBLIC Celix::log_helper Celix::remote_service_admin_api)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/include/civetweb.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/include/civetweb.h b/remote_services/discovery_common/include/civetweb.h
new file mode 100644
index 0000000..61a8e98
--- /dev/null
+++ b/remote_services/discovery_common/include/civetweb.h
@@ -0,0 +1,657 @@
+/* Copyright (c) 2013-2014 the Civetweb developers
+ * Copyright (c) 2004-2013 Sergey Lyubka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef CIVETWEB_HEADER_INCLUDED
+#define CIVETWEB_HEADER_INCLUDED
+
+#ifndef CIVETWEB_VERSION
+#define CIVETWEB_VERSION "1.7"
+#endif
+
+#ifndef CIVETWEB_API
+ #if defined(_WIN32)
+ #if defined(CIVETWEB_DLL_EXPORTS)
+ #define CIVETWEB_API __declspec(dllexport)
+ #elif defined(CIVETWEB_DLL_IMPORTS)
+ #define CIVETWEB_API __declspec(dllimport)
+ #else
+ #define CIVETWEB_API
+ #endif
+ #else
+ #define CIVETWEB_API
+ #endif
+#endif
+
+#include <stdio.h>
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+struct mg_context; /* Handle for the HTTP service itself */
+struct mg_connection; /* Handle for the individual connection */
+
+
+/* This structure contains information about the HTTP request. */
+struct mg_request_info {
+ const char *request_method; /* "GET", "POST", etc */
+ const char *uri; /* URL-decoded URI */
+ const char *http_version; /* E.g. "1.0", "1.1" */
+ const char *query_string; /* URL part after '?', not including '?', or
+ NULL */
+ const char *remote_user; /* Authenticated user, or NULL if no auth
+ used */
+ char remote_addr[48]; /* Client's IP address as a string. */
+ long remote_ip; /* Client's IP address. Deprecated: use remote_addr instead */
+
+ long long content_length; /* Length (in bytes) of the request body,
+ can be -1 if no length was given. */
+ int remote_port; /* Client's port */
+ int is_ssl; /* 1 if SSL-ed, 0 if not */
+ void *user_data; /* User data pointer passed to mg_start() */
+ void *conn_data; /* Connection-specific user data */
+
+ int num_headers; /* Number of HTTP headers */
+ struct mg_header {
+ const char *name; /* HTTP header name */
+ const char *value; /* HTTP header value */
+ } http_headers[64]; /* Maximum 64 headers */
+};
+
+
+/* This structure needs to be passed to mg_start(), to let civetweb know
+ which callbacks to invoke. For a detailed description, see
+ https://github.com/bel2125/civetweb/blob/master/docs/UserManual.md */
+struct mg_callbacks {
+ /* Called when civetweb has received new HTTP request.
+ If the callback returns one, it must process the request
+ by sending valid HTTP headers and a body. Civetweb will not do
+ any further processing. Otherwise it must return zero.
+ Note that since V1.7 the "begin_request" function is called
+ before an authorization check. If an authorization check is
+ required, use a request_handler instead.
+ Return value:
+ 0: civetweb will process the request itself. In this case,
+ the callback must not send any data to the client.
+ 1: callback already processed the request. Civetweb will
+ not send any data after the callback returned. */
+ int (*begin_request)(struct mg_connection *);
+
+ /* Called when civetweb has finished processing request. */
+ void (*end_request)(const struct mg_connection *, int reply_status_code);
+
+ /* Called when civetweb is about to log a message. If callback returns
+ non-zero, civetweb does not log anything. */
+ int (*log_message)(const struct mg_connection *, const char *message);
+
+ /* Called when civetweb initializes SSL library.
+ Parameters:
+ user_data: parameter user_data passed when starting the server.
+ Return value:
+ 0: civetweb will set up the SSL certificate.
+ 1: civetweb assumes the callback already set up the certificate.
+ -1: initializing ssl fails. */
+ int (*init_ssl)(void *ssl_context, void *user_data);
+
+ /* Called when websocket request is received, before websocket handshake.
+ Return value:
+ 0: civetweb proceeds with websocket handshake.
+ 1: connection is closed immediately. */
+ int (*websocket_connect)(const struct mg_connection *);
+
+ /* Called when websocket handshake is successfully completed, and
+ connection is ready for data exchange. */
+ void (*websocket_ready)(struct mg_connection *);
+
+ /* Called when data frame has been received from the client.
+ Parameters:
+ bits: first byte of the websocket frame, see websocket RFC at
+ http://tools.ietf.org/html/rfc6455, section 5.2
+ data, data_len: payload, with mask (if any) already applied.
+ Return value:
+ 1: keep this websocket connection open.
+ 0: close this websocket connection. */
+ int (*websocket_data)(struct mg_connection *, int bits,
+ char *data, size_t data_len);
+
+ /* Called when civetweb is closing a connection. The per-context mutex is
+ locked when this is invoked. This is primarily useful for noting when
+ a websocket is closing and removing it from any application-maintained
+ list of clients. */
+ void (*connection_close)(struct mg_connection *);
+
+ /* Called when civetweb tries to open a file. Used to intercept file open
+ calls, and serve file data from memory instead.
+ Parameters:
+ path: Full path to the file to open.
+ data_len: Placeholder for the file size, if file is served from
+ memory.
+ Return value:
+ NULL: do not serve file from memory, proceed with normal file open.
+ non-NULL: pointer to the file contents in memory. data_len must be
+ initilized with the size of the memory block. */
+ const char * (*open_file)(const struct mg_connection *,
+ const char *path, size_t *data_len);
+
+ /* Called when civetweb is about to serve Lua server page, if
+ Lua support is enabled.
+ Parameters:
+ lua_context: "lua_State *" pointer. */
+ void (*init_lua)(struct mg_connection *, void *lua_context);
+
+ /* Called when civetweb has uploaded a file to a temporary directory as a
+ result of mg_upload() call.
+ Parameters:
+ file_name: full path name to the uploaded file. */
+ void (*upload)(struct mg_connection *, const char *file_name);
+
+ /* Called when civetweb is about to send HTTP error to the client.
+ Implementing this callback allows to create custom error pages.
+ Parameters:
+ status: HTTP error status code.
+ Return value:
+ 1: run civetweb error handler.
+ 0: callback already handled the error. */
+ int (*http_error)(struct mg_connection *, int status);
+
+ /* Called after civetweb context has been created, before requests
+ are processed.
+ Parameters:
+ ctx: context handle */
+ void (*init_context)(struct mg_context * ctx);
+
+ /* Called when civetweb context is deleted.
+ Parameters:
+ ctx: context handle */
+ void (*exit_context)(struct mg_context * ctx);
+};
+
+
+/* Start web server.
+
+ Parameters:
+ callbacks: mg_callbacks structure with user-defined callbacks.
+ options: NULL terminated list of option_name, option_value pairs that
+ specify Civetweb configuration parameters.
+
+ Side-effects: on UNIX, ignores SIGCHLD and SIGPIPE signals. If custom
+ processing is required for these, signal handlers must be set up
+ after calling mg_start().
+
+
+ Example:
+ const char *options[] = {
+ "document_root", "/var/www",
+ "listening_ports", "80,443s",
+ NULL
+ };
+ struct mg_context *ctx = mg_start(&my_func, NULL, options);
+
+ Refer to https://github.com/bel2125/civetweb/blob/master/docs/UserManual.md
+ for the list of valid option and their possible values.
+
+ Return:
+ web server context, or NULL on error. */
+CIVETWEB_API struct mg_context *mg_start(const struct mg_callbacks *callbacks,
+ void *user_data,
+ const char **configuration_options);
+
+
+/* Stop the web server.
+
+ Must be called last, when an application wants to stop the web server and
+ release all associated resources. This function blocks until all Civetweb
+ threads are stopped. Context pointer becomes invalid. */
+CIVETWEB_API void mg_stop(struct mg_context *);
+
+
+/* mg_request_handler
+
+ Called when a new request comes in. This callback is URI based
+ and configured with mg_set_request_handler().
+
+ Parameters:
+ conn: current connection information.
+ cbdata: the callback data configured with mg_set_request_handler().
+ Returns:
+ 0: the handler could not handle the request, so fall through.
+ 1: the handler processed the request. */
+typedef int (* mg_request_handler)(struct mg_connection *conn, void *cbdata);
+
+
+/* mg_set_request_handler
+
+ Sets or removes a URI mapping for a request handler.
+
+ URI's are ordered and prefixed URI's are supported. For example,
+ consider two URIs: /a/b and /a
+ /a matches /a
+ /a/b matches /a/b
+ /a/c matches /a
+
+ Parameters:
+ ctx: server context
+ uri: the URI to configure
+ handler: the callback handler to use when the URI is requested.
+ If NULL, the URI will be removed.
+ cbdata: the callback data to give to the handler when it s requested. */
+CIVETWEB_API void mg_set_request_handler(struct mg_context *ctx, const char *uri, mg_request_handler handler, void *cbdata);
+
+
+/* Get the value of particular configuration parameter.
+ The value returned is read-only. Civetweb does not allow changing
+ configuration at run time.
+ If given parameter name is not valid, NULL is returned. For valid
+ names, return value is guaranteed to be non-NULL. If parameter is not
+ set, zero-length string is returned. */
+CIVETWEB_API const char *mg_get_option(const struct mg_context *ctx, const char *name);
+
+
+/* Get context from connection. */
+CIVETWEB_API struct mg_context *mg_get_context(struct mg_connection *conn);
+
+
+/* Get user data passed to mg_start from context. */
+CIVETWEB_API void *mg_get_user_data(struct mg_context *ctx);
+
+
+#if defined(MG_LEGACY_INTERFACE)
+/* Return array of strings that represent valid configuration options.
+ For each option, option name and default value is returned, i.e. the
+ number of entries in the array equals to number_of_options x 2.
+ Array is NULL terminated. */
+/* Deprecated: Use mg_get_valid_options instead. */
+CIVETWEB_API const char **mg_get_valid_option_names(void);
+#endif
+
+
+struct mg_option {
+ const char * name;
+ int type;
+ const char * default_value;
+};
+
+enum {
+ CONFIG_TYPE_UNKNOWN = 0x0,
+ CONFIG_TYPE_NUMBER = 0x1,
+ CONFIG_TYPE_STRING = 0x2,
+ CONFIG_TYPE_FILE = 0x3,
+ CONFIG_TYPE_DIRECTORY = 0x4,
+ CONFIG_TYPE_BOOLEAN = 0x5,
+ CONFIG_TYPE_EXT_PATTERN = 0x6
+};
+
+
+/* Return array of struct mg_option, representing all valid configuration
+ options of civetweb.c.
+ The array is terminated by a NULL name option. */
+CIVETWEB_API const struct mg_option *mg_get_valid_options(void);
+
+
+/* Get the list of ports that civetweb is listening on.
+ size is the size of the ports int array and ssl int array to fill.
+ It is the caller's responsibility to make sure ports and ssl each
+ contain at least size int elements worth of memory to write into.
+ Return value is the number of ports and ssl information filled in.
+ The value returned is read-only. Civetweb does not allow changing
+ configuration at run time. */
+CIVETWEB_API size_t mg_get_ports(const struct mg_context *ctx, size_t size, int* ports, int* ssl);
+
+
+/* Add, edit or delete the entry in the passwords file.
+
+ This function allows an application to manipulate .htpasswd files on the
+ fly by adding, deleting and changing user records. This is one of the
+ several ways of implementing authentication on the server side. For another,
+ cookie-based way please refer to the examples/chat in the source tree.
+
+ If password is not NULL, entry is added (or modified if already exists).
+ If password is NULL, entry is deleted.
+
+ Return:
+ 1 on success, 0 on error. */
+CIVETWEB_API int mg_modify_passwords_file(const char *passwords_file_name,
+ const char *domain,
+ const char *user,
+ const char *password);
+
+
+/* Return information associated with the request. */
+CIVETWEB_API struct mg_request_info *mg_get_request_info(struct mg_connection *);
+
+
+/* Send data to the client.
+ Return:
+ 0 when the connection has been closed
+ -1 on error
+ >0 number of bytes written on success */
+CIVETWEB_API int mg_write(struct mg_connection *, const void *buf, size_t len);
+
+
+/* Send data to a websocket client wrapped in a websocket frame. Uses mg_lock
+ to ensure that the transmission is not interrupted, i.e., when the
+ application is proactively communicating and responding to a request
+ simultaneously.
+
+ Send data to a websocket client wrapped in a websocket frame.
+ This function is available when civetweb is compiled with -DUSE_WEBSOCKET
+
+ Return:
+ 0 when the connection has been closed
+ -1 on error
+ >0 number of bytes written on success */
+CIVETWEB_API int mg_websocket_write(struct mg_connection* conn, int opcode,
+ const char *data, size_t data_len);
+
+
+/* Blocks until unique access is obtained to this connection. Intended for use
+ with websockets only.
+ Invoke this before mg_write or mg_printf when communicating with a
+ websocket if your code has server-initiated communication as well as
+ communication in direct response to a message. */
+CIVETWEB_API void mg_lock_connection(struct mg_connection* conn);
+CIVETWEB_API void mg_unlock_connection(struct mg_connection* conn);
+
+#if defined(MG_LEGACY_INTERFACE)
+#define mg_lock mg_lock_connection
+#define mg_unlock mg_unlock_connection
+#endif
+
+/* Lock server context. This lock may be used to protect ressources
+ that are shared between different connection/worker threads. */
+CIVETWEB_API void mg_lock_context(struct mg_context* ctx);
+CIVETWEB_API void mg_unlock_context(struct mg_context* ctx);
+
+
+/* Opcodes, from http://tools.ietf.org/html/rfc6455 */
+enum {
+ WEBSOCKET_OPCODE_CONTINUATION = 0x0,
+ WEBSOCKET_OPCODE_TEXT = 0x1,
+ WEBSOCKET_OPCODE_BINARY = 0x2,
+ WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
+ WEBSOCKET_OPCODE_PING = 0x9,
+ WEBSOCKET_OPCODE_PONG = 0xa
+};
+
+
+/* Macros for enabling compiler-specific checks forprintf-like arguments. */
+#undef PRINTF_FORMAT_STRING
+#if defined(_MSC_VER) && _MSC_VER >= 1400
+#include <sal.h>
+#if defined(_MSC_VER) && _MSC_VER > 1400
+#define PRINTF_FORMAT_STRING(s) _Printf_format_string_ s
+#else
+#define PRINTF_FORMAT_STRING(s) __format_string s
+#endif
+#else
+#define PRINTF_FORMAT_STRING(s) s
+#endif
+
+#ifdef __GNUC__
+#define PRINTF_ARGS(x, y) __attribute__((format(printf, x, y)))
+#else
+#define PRINTF_ARGS(x, y)
+#endif
+
+/* Send data to the client usingprintf() semantics.
+ Works exactly like mg_write(), but allows to do message formatting. */
+CIVETWEB_API int mg_printf(struct mg_connection *,
+ PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(2, 3);
+
+
+/* Send contents of the entire file together with HTTP headers. */
+CIVETWEB_API void mg_send_file(struct mg_connection *conn, const char *path);
+
+
+/* Read data from the remote end, return number of bytes read.
+ Return:
+ 0 connection has been closed by peer. No more data could be read.
+ < 0 read error. No more data could be read from the connection.
+ > 0 number of bytes read into the buffer. */
+CIVETWEB_API int mg_read(struct mg_connection *, void *buf, size_t len);
+
+
+/* Get the value of particular HTTP header.
+
+ This is a helper function. It traverses request_info->http_headers array,
+ and if the header is present in the array, returns its value. If it is
+ not present, NULL is returned. */
+CIVETWEB_API const char *mg_get_header(const struct mg_connection *, const char *name);
+
+
+/* Get a value of particular form variable.
+
+ Parameters:
+ data: pointer to form-uri-encoded buffer. This could be either POST data,
+ or request_info.query_string.
+ data_len: length of the encoded data.
+ var_name: variable name to decode from the buffer
+ dst: destination buffer for the decoded variable
+ dst_len: length of the destination buffer
+
+ Return:
+ On success, length of the decoded variable.
+ On error:
+ -1 (variable not found).
+ -2 (destination buffer is NULL, zero length or too small to hold the
+ decoded variable).
+
+ Destination buffer is guaranteed to be '\0' - terminated if it is not
+ NULL or zero length. */
+CIVETWEB_API int mg_get_var(const char *data, size_t data_len,
+ const char *var_name, char *dst, size_t dst_len);
+
+
+/* Get a value of particular form variable.
+
+ Parameters:
+ data: pointer to form-uri-encoded buffer. This could be either POST data,
+ or request_info.query_string.
+ data_len: length of the encoded data.
+ var_name: variable name to decode from the buffer
+ dst: destination buffer for the decoded variable
+ dst_len: length of the destination buffer
+ occurrence: which occurrence of the variable, 0 is the first, 1 the
+ second...
+ this makes it possible to parse a query like
+ b=x&a=y&a=z which will have occurrence values b:0, a:0 and a:1
+
+ Return:
+ On success, length of the decoded variable.
+ On error:
+ -1 (variable not found).
+ -2 (destination buffer is NULL, zero length or too small to hold the
+ decoded variable).
+
+ Destination buffer is guaranteed to be '\0' - terminated if it is not
+ NULL or zero length. */
+CIVETWEB_API int mg_get_var2(const char *data, size_t data_len,
+ const char *var_name, char *dst, size_t dst_len, size_t occurrence);
+
+
+/* Fetch value of certain cookie variable into the destination buffer.
+
+ Destination buffer is guaranteed to be '\0' - terminated. In case of
+ failure, dst[0] == '\0'. Note that RFC allows many occurrences of the same
+ parameter. This function returns only first occurrence.
+
+ Return:
+ On success, value length.
+ On error:
+ -1 (either "Cookie:" header is not present at all or the requested
+ parameter is not found).
+ -2 (destination buffer is NULL, zero length or too small to hold the
+ value). */
+CIVETWEB_API int mg_get_cookie(const char *cookie, const char *var_name,
+ char *buf, size_t buf_len);
+
+
+/* Download data from the remote web server.
+ host: host name to connect to, e.g. "foo.com", or "10.12.40.1".
+ port: port number, e.g. 80.
+ use_ssl: wether to use SSL connection.
+ error_buffer, error_buffer_size: error message placeholder.
+ request_fmt,...: HTTP request.
+ Return:
+ On success, valid pointer to the new connection, suitable for mg_read().
+ On error, NULL. error_buffer contains error message.
+ Example:
+ char ebuf[100];
+ struct mg_connection *conn;
+ conn = mg_download("google.com", 80, 0, ebuf, sizeof(ebuf),
+ "%s", "GET / HTTP/1.0\r\nHost: google.com\r\n\r\n");
+ */
+CIVETWEB_API struct mg_connection *mg_download(const char *host, int port, int use_ssl,
+ char *error_buffer, size_t error_buffer_size,
+ PRINTF_FORMAT_STRING(const char *request_fmt),
+ ...) PRINTF_ARGS(6, 7);
+
+
+/* Close the connection opened by mg_download(). */
+CIVETWEB_API void mg_close_connection(struct mg_connection *conn);
+
+
+/* File upload functionality. Each uploaded file gets saved into a temporary
+ file and MG_UPLOAD event is sent.
+ Return number of uploaded files. */
+CIVETWEB_API int mg_upload(struct mg_connection *conn, const char *destination_dir);
+
+
+/* Convenience function -- create detached thread.
+ Return: 0 on success, non-0 on error. */
+typedef void * (*mg_thread_func_t)(void *);
+CIVETWEB_API int mg_start_thread(mg_thread_func_t f, void *p);
+
+
+/* Return builtin mime type for the given file name.
+ For unrecognized extensions, "text/plain" is returned. */
+CIVETWEB_API const char *mg_get_builtin_mime_type(const char *file_name);
+
+
+/* Return Civetweb version. */
+CIVETWEB_API const char *mg_version(void);
+
+
+/* URL-decode input buffer into destination buffer.
+ 0-terminate the destination buffer.
+ form-url-encoded data differs from URI encoding in a way that it
+ uses '+' as character for space, see RFC 1866 section 8.2.1
+ http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
+ Return: length of the decoded data, or -1 if dst buffer is too small. */
+CIVETWEB_API int mg_url_decode(const char *src, int src_len, char *dst,
+ int dst_len, int is_form_url_encoded);
+
+
+/* URL-encode input buffer into destination buffer.
+ returns the length of the resulting buffer or -1
+ is the buffer is too small. */
+CIVETWEB_API int mg_url_encode(const char *src, char *dst, size_t dst_len);
+
+
+/* MD5 hash given strings.
+ Buffer 'buf' must be 33 bytes long. Varargs is a NULL terminated list of
+ ASCIIz strings. When function returns, buf will contain human-readable
+ MD5 hash. Example:
+ char buf[33];
+ mg_md5(buf, "aa", "bb", NULL); */
+CIVETWEB_API char *mg_md5(char buf[33], ...);
+
+
+/* Print error message to the opened error log stream.
+ This utilizes the provided logging configuration.
+ conn: connection
+ fmt: format string without the line return
+ ...: variable argument list
+ Example:
+ mg_cry(conn,"i like %s", "logging"); */
+CIVETWEB_API void mg_cry(struct mg_connection *conn,
+ PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(2, 3);
+
+
+/* utility method to compare two buffers, case incensitive. */
+CIVETWEB_API int mg_strncasecmp(const char *s1, const char *s2, size_t len);
+
+/* Connect to a websocket as a client
+ Parameters:
+ host: host to connect to, i.e. "echo.websocket.org" or "192.168.1.1" or "localhost"
+ port: server port
+ use_ssl: make a secure connection to server
+ error_buffer, error_buffer_size: buffer for an error message
+ path: server path you are trying to connect to, i.e. if connection to localhost/app, path should be "/app"
+ origin: value of the Origin HTTP header
+ data_func: callback that should be used when data is received from the server
+ user_data: user supplied argument
+
+ Return:
+ On success, valid mg_connection object.
+ On error, NULL. Se error_buffer for details.
+*/
+
+typedef int (*websocket_data_func)(struct mg_connection *, int bits,
+ char *data, size_t data_len);
+
+typedef void (*websocket_close_func)(struct mg_connection *);
+
+CIVETWEB_API struct mg_connection *mg_connect_websocket_client(const char *host, int port, int use_ssl,
+ char *error_buffer, size_t error_buffer_size,
+ const char *path, const char *origin,
+ websocket_data_func data_func, websocket_close_func close_func,
+ void * user_data);
+
+/* Connect to a TCP server as a client (can be used to connect to a HTTP server)
+ Parameters:
+ host: host to connect to, i.e. "www.wikipedia.org" or "192.168.1.1" or "localhost"
+ port: server port
+ use_ssl: make a secure connection to server
+ error_buffer, error_buffer_size: buffer for an error message
+
+ Return:
+ On success, valid mg_connection object.
+ On error, NULL. Se error_buffer for details.
+*/
+CIVETWEB_API struct mg_connection *mg_connect_client(const char *host, int port, int use_ssl,
+ char *error_buffer, size_t error_buffer_size);
+
+
+enum {
+ TIMEOUT_INFINITE = -1
+};
+
+/* Wait for a response from the server
+ Parameters:
+ conn: connection
+ ebuf, ebuf_len: error message placeholder.
+ timeout: time to wait for a response in milliseconds (if < 0 then wait forever)
+
+ Return:
+ On success, >= 0
+ On error/timeout, < 0
+*/
+CIVETWEB_API int mg_get_response(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int timeout);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* CIVETWEB_HEADER_INCLUDED */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/include/discovery.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/include/discovery.h b/remote_services/discovery_common/include/discovery.h
new file mode 100644
index 0000000..ee79caf
--- /dev/null
+++ b/remote_services/discovery_common/include/discovery.h
@@ -0,0 +1,67 @@
+/**
+ *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.
+ */
+/*
+ * discovery.h
+ *
+ * \date Sep 29, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef DISCOVERY_H_
+#define DISCOVERY_H_
+
+#include "bundle_context.h"
+#include "service_reference.h"
+
+#include "endpoint_description.h"
+#include "endpoint_listener.h"
+
+#define DISCOVERY_SERVER_INTERFACE "DISCOVERY_CFG_SERVER_INTERFACE"
+#define DISCOVERY_SERVER_IP "DISCOVERY_CFG_SERVER_IP"
+#define DISCOVERY_SERVER_PORT "DISCOVERY_CFG_SERVER_PORT"
+#define DISCOVERY_SERVER_PATH "DISCOVERY_CFG_SERVER_PATH"
+#define DISCOVERY_POLL_ENDPOINTS "DISCOVERY_CFG_POLL_ENDPOINTS"
+#define DISCOVERY_SERVER_MAX_EP "DISCOVERY_CFG_SERVER_MAX_EP"
+
+typedef struct discovery *discovery_pt;
+
+
+/* those one could be put into a general discovery.h - file */
+celix_status_t discovery_create(bundle_context_pt context, discovery_pt *discovery);
+celix_status_t discovery_destroy(discovery_pt discovery);
+
+celix_status_t discovery_start(discovery_pt discovery);
+celix_status_t discovery_stop(discovery_pt discovery);
+
+celix_status_t discovery_endpointAdded(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
+celix_status_t discovery_endpointRemoved(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
+
+celix_status_t discovery_endpointListenerAdding(void * handle, service_reference_pt reference, void **service);
+celix_status_t discovery_endpointListenerAdded(void * handle, service_reference_pt reference, void * service);
+celix_status_t discovery_endpointListenerModified(void * handle, service_reference_pt reference, void * service);
+celix_status_t discovery_endpointListenerRemoved(void * handle, service_reference_pt reference, void * service);
+
+celix_status_t discovery_informEndpointListeners(discovery_pt discovery, endpoint_description_pt endpoint, bool endpointAdded);
+celix_status_t discovery_updateEndpointListener(discovery_pt discovery, service_reference_pt reference, endpoint_listener_pt service);
+
+celix_status_t discovery_addDiscoveredEndpoint(discovery_pt discovery, endpoint_description_pt endpoint);
+celix_status_t discovery_removeDiscoveredEndpoint(discovery_pt discovery, endpoint_description_pt endpoint);
+
+#endif /* DISCOVERY_H_ */
[22/54] [abbrv] celix git commit: CELIX-417: Refactors CMake usage
for the RSA bundles
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_common/src/discovery.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/src/discovery.c b/remote_services/discovery_common/src/discovery.c
index d124c15..d016c09 100644
--- a/remote_services/discovery_common/src/discovery.c
+++ b/remote_services/discovery_common/src/discovery.c
@@ -33,7 +33,6 @@
#include "log_helper.h"
#include "discovery.h"
#include "endpoint_discovery_server.h"
-#include "discovery_impl.h" //TODO rename impl
celix_status_t discovery_endpointAdded(void *handle, endpoint_description_pt endpoint, char *matchedFilter) {
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_common/src/endpoint_discovery_poller.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/src/endpoint_discovery_poller.c b/remote_services/discovery_common/src/endpoint_discovery_poller.c
index 73fb7ba..e3f9cd4 100644
--- a/remote_services/discovery_common/src/endpoint_discovery_poller.c
+++ b/remote_services/discovery_common/src/endpoint_discovery_poller.c
@@ -35,9 +35,8 @@
#include "log_helper.h"
#include "utils.h"
-#include "discovery_impl.h"
-
#include "endpoint_descriptor_reader.h"
+#include "discovery.h"
#define DISCOVERY_POLL_INTERVAL "DISCOVERY_CFG_POLL_INTERVAL"
@@ -52,7 +51,7 @@ static celix_status_t endpointDiscoveryPoller_endpointDescriptionEquals(const vo
/**
* Allocates memory and initializes a new endpoint_discovery_poller instance.
*/
-celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_poller_pt *poller) {
+celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_context_pt context, const char* defaultPollEndpoints, endpoint_discovery_poller_pt *poller) {
celix_status_t status;
*poller = malloc(sizeof(struct endpoint_discovery_poller));
@@ -76,7 +75,7 @@ celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_con
const char* endpointsProp = NULL;
status = bundleContext_getProperty(context, DISCOVERY_POLL_ENDPOINTS, &endpointsProp);
if (!endpointsProp) {
- endpointsProp = DEFAULT_POLL_ENDPOINTS;
+ endpointsProp = defaultPollEndpoints;
}
// we're going to mutate the string with strtok, so create a copy...
char* endpoints = strdup(endpointsProp);
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_common/src/endpoint_discovery_server.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/src/endpoint_discovery_server.c b/remote_services/discovery_common/src/endpoint_discovery_server.c
index f5f82af..7620bbf 100644
--- a/remote_services/discovery_common/src/endpoint_discovery_server.c
+++ b/remote_services/discovery_common/src/endpoint_discovery_server.c
@@ -35,8 +35,6 @@
#include "utils.h"
#include "log_helper.h"
#include "discovery.h"
-#include "discovery_impl.h"
-
#include "endpoint_descriptor_writer.h"
// defines how often the webserver is restarted (with an increased port number)
@@ -72,7 +70,13 @@ static char* format_path(const char* path);
static celix_status_t endpointDiscoveryServer_getIpAdress(char* interface, char** ip);
#endif
-celix_status_t endpointDiscoveryServer_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_server_pt *server) {
+celix_status_t endpointDiscoveryServer_create(
+ discovery_pt discovery,
+ bundle_context_pt context,
+ const char* defaultServerPath,
+ const char* defaultServerPort,
+ const char* defaultServerIp,
+ endpoint_discovery_server_pt *server) {
celix_status_t status;
const char *port = NULL;
@@ -122,8 +126,8 @@ celix_status_t endpointDiscoveryServer_create(discovery_pt discovery, bundle_con
(*server)->ip = strdup(ip);
}
else {
- logHelper_log(*(*server)->loghelper, OSGI_LOGSERVICE_WARNING, "No IP address for service annunciation set. Using %s", DEFAULT_SERVER_IP);
- (*server)->ip = strdup((char*) DEFAULT_SERVER_IP);
+ logHelper_log(*(*server)->loghelper, OSGI_LOGSERVICE_WARNING, "No IP address for service annunciation set. Using %s", defaultServerIp);
+ (*server)->ip = strdup((char*) defaultServerIp);
}
if (detectedIp != NULL) {
@@ -132,12 +136,12 @@ celix_status_t endpointDiscoveryServer_create(discovery_pt discovery, bundle_con
bundleContext_getProperty(context, DISCOVERY_SERVER_PORT, &port);
if (port == NULL) {
- port = DEFAULT_SERVER_PORT;
+ port = defaultServerPort;
}
bundleContext_getProperty(context, DISCOVERY_SERVER_PATH, &path);
if (path == NULL) {
- path = DEFAULT_SERVER_PATH;
+ path = defaultServerPath;
}
bundleContext_getProperty(context, DISCOVERY_SERVER_MAX_EP, &retries);
@@ -177,7 +181,7 @@ celix_status_t endpointDiscoveryServer_create(discovery_pt discovery, bundle_con
long currentPort = strtol(port, &endptr, 10);
if (*endptr || errno != 0) {
- currentPort = strtol(DEFAULT_SERVER_PORT, NULL, 10);
+ currentPort = strtol(defaultServerPort, NULL, 10);
}
port_counter++;
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_common/src/md5.inl
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/src/md5.inl b/remote_services/discovery_common/src/md5.inl
deleted file mode 100644
index 4da933d..0000000
--- a/remote_services/discovery_common/src/md5.inl
+++ /dev/null
@@ -1,461 +0,0 @@
-/*
- * This an amalgamation of md5.c and md5.h into a single file
- * with all static declaration to reduce linker conflicts
- * in Civetweb.
- *
- * The MD5_STATIC declaration was added to facilitate static
- * inclusion.
- * No Face Press, LLC
- */
-
-/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
-/*
- Independent implementation of MD5 (RFC 1321).
-
- This code implements the MD5 Algorithm defined in RFC 1321, whose
- text is available at
- http://www.ietf.org/rfc/rfc1321.txt
- The code is derived from the text of the RFC, including the test suite
- (section A.5) but excluding the rest of Appendix A. It does not include
- any code or documentation that is identified in the RFC as being
- copyrighted.
-
- The original and principal author of md5.h is L. Peter Deutsch
- <gh...@aladdin.com>. Other authors are noted in the change history
- that follows (in reverse chronological order):
-
- 2002-04-13 lpd Removed support for non-ANSI compilers; removed
- references to Ghostscript; clarified derivation from RFC 1321;
- now handles byte order either statically or dynamically.
- 1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
- 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
- added conditionalization for C++ compilation from Martin
- Purschke <pu...@bnl.gov>.
- 1999-05-03 lpd Original version.
- */
-
-#ifndef md5_INCLUDED
-# define md5_INCLUDED
-
-/*
- * This package supports both compile-time and run-time determination of CPU
- * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
- * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
- * defined as non-zero, the code will be compiled to run only on big-endian
- * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
- * run on either big- or little-endian CPUs, but will run slightly less
- * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
- */
-
-typedef unsigned char md5_byte_t; /* 8-bit byte */
-typedef unsigned int md5_word_t; /* 32-bit word */
-
-/* Define the state of the MD5 Algorithm. */
-typedef struct md5_state_s {
- md5_word_t count[2]; /* message length in bits, lsw first */
- md5_word_t abcd[4]; /* digest buffer */
- md5_byte_t buf[64]; /* accumulate block */
-} md5_state_t;
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/* Initialize the algorithm. */
-MD5_STATIC void md5_init(md5_state_t *pms);
-
-/* Append a string to the message. */
-MD5_STATIC void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);
-
-/* Finish the message and return the digest. */
-MD5_STATIC void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
-
-#ifdef __cplusplus
-} /* end extern "C" */
-#endif
-
-#endif /* md5_INCLUDED */
-
-/*
- Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved.
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- L. Peter Deutsch
- ghost@aladdin.com
-
- */
-/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */
-/*
- Independent implementation of MD5 (RFC 1321).
-
- This code implements the MD5 Algorithm defined in RFC 1321, whose
- text is available at
- http://www.ietf.org/rfc/rfc1321.txt
- The code is derived from the text of the RFC, including the test suite
- (section A.5) but excluding the rest of Appendix A. It does not include
- any code or documentation that is identified in the RFC as being
- copyrighted.
-
- The original and principal author of md5.c is L. Peter Deutsch
- <gh...@aladdin.com>. Other authors are noted in the change history
- that follows (in reverse chronological order):
-
- 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order
- either statically or dynamically; added missing #include <string.h>
- in library.
- 2002-03-11 lpd Corrected argument list for main(), and added int return
- type, in test program and T value program.
- 2002-02-21 lpd Added missing #include <stdio.h> in test program.
- 2000-07-03 lpd Patched to eliminate warnings about "constant is
- unsigned in ANSI C, signed in traditional"; made test program
- self-checking.
- 1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
- 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
- 1999-05-03 lpd Original version.
- */
-
-#ifndef MD5_STATIC
-#include <string.h>
-#endif
-
-#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
-#ifdef ARCH_IS_BIG_ENDIAN
-# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
-#else
-# define BYTE_ORDER 0
-#endif
-
-#define T_MASK ((md5_word_t)~0)
-#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87)
-#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9)
-#define T3 0x242070db
-#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111)
-#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050)
-#define T6 0x4787c62a
-#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec)
-#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe)
-#define T9 0x698098d8
-#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850)
-#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e)
-#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841)
-#define T13 0x6b901122
-#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c)
-#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71)
-#define T16 0x49b40821
-#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d)
-#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf)
-#define T19 0x265e5a51
-#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855)
-#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2)
-#define T22 0x02441453
-#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e)
-#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437)
-#define T25 0x21e1cde6
-#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829)
-#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278)
-#define T28 0x455a14ed
-#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa)
-#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07)
-#define T31 0x676f02d9
-#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375)
-#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd)
-#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e)
-#define T35 0x6d9d6122
-#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3)
-#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb)
-#define T38 0x4bdecfa9
-#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f)
-#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f)
-#define T41 0x289b7ec6
-#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805)
-#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a)
-#define T44 0x04881d05
-#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6)
-#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a)
-#define T47 0x1fa27cf8
-#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a)
-#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb)
-#define T50 0x432aff97
-#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58)
-#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6)
-#define T53 0x655b59c3
-#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d)
-#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82)
-#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e)
-#define T57 0x6fa87e4f
-#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f)
-#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb)
-#define T60 0x4e0811a1
-#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d)
-#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca)
-#define T63 0x2ad7d2bb
-#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e)
-
-
-static void
-md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
-{
- md5_word_t
- a = pms->abcd[0], b = pms->abcd[1],
- c = pms->abcd[2], d = pms->abcd[3];
- md5_word_t t;
-#if BYTE_ORDER > 0
- /* Define storage only for big-endian CPUs. */
- md5_word_t X[16];
-#else
- /* Define storage for little-endian or both types of CPUs. */
- md5_word_t xbuf[16];
- const md5_word_t *X;
-#endif
-
- {
-#if BYTE_ORDER == 0
- /*
- * Determine dynamically whether this is a big-endian or
- * little-endian machine, since we can use a more efficient
- * algorithm on the latter.
- */
- static const int w = 1;
-
- if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
-#endif
-#if BYTE_ORDER <= 0 /* little-endian */
- {
- /*
- * On little-endian machines, we can process properly aligned
- * data without copying it.
- */
- if (!((data - (const md5_byte_t *)0) & 3)) {
- /* data are properly aligned */
- X = (const md5_word_t *)data;
- } else {
- /* not aligned */
- memcpy(xbuf, data, 64);
- X = xbuf;
- }
- }
-#endif
-#if BYTE_ORDER == 0
- else /* dynamic big-endian */
-#endif
-#if BYTE_ORDER >= 0 /* big-endian */
- {
- /*
- * On big-endian machines, we must arrange the bytes in the
- * right order.
- */
- const md5_byte_t *xp = data;
- int i;
-
-# if BYTE_ORDER == 0
- X = xbuf; /* (dynamic only) */
-# else
-# define xbuf X /* (static only) */
-# endif
- for (i = 0; i < 16; ++i, xp += 4)
- xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
- }
-#endif
- }
-
-#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
-
- /* Round 1. */
- /* Let [abcd k s i] denote the operation
- a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
-#define F(x, y, z) (((x) & (y)) | (~(x) & (z)))
-#define SET(a, b, c, d, k, s, Ti)\
- t = a + F(b,c,d) + X[k] + Ti;\
- a = ROTATE_LEFT(t, s) + b
- /* Do the following 16 operations. */
- SET(a, b, c, d, 0, 7, T1);
- SET(d, a, b, c, 1, 12, T2);
- SET(c, d, a, b, 2, 17, T3);
- SET(b, c, d, a, 3, 22, T4);
- SET(a, b, c, d, 4, 7, T5);
- SET(d, a, b, c, 5, 12, T6);
- SET(c, d, a, b, 6, 17, T7);
- SET(b, c, d, a, 7, 22, T8);
- SET(a, b, c, d, 8, 7, T9);
- SET(d, a, b, c, 9, 12, T10);
- SET(c, d, a, b, 10, 17, T11);
- SET(b, c, d, a, 11, 22, T12);
- SET(a, b, c, d, 12, 7, T13);
- SET(d, a, b, c, 13, 12, T14);
- SET(c, d, a, b, 14, 17, T15);
- SET(b, c, d, a, 15, 22, T16);
-#undef SET
-
- /* Round 2. */
- /* Let [abcd k s i] denote the operation
- a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
-#define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
-#define SET(a, b, c, d, k, s, Ti)\
- t = a + G(b,c,d) + X[k] + Ti;\
- a = ROTATE_LEFT(t, s) + b
- /* Do the following 16 operations. */
- SET(a, b, c, d, 1, 5, T17);
- SET(d, a, b, c, 6, 9, T18);
- SET(c, d, a, b, 11, 14, T19);
- SET(b, c, d, a, 0, 20, T20);
- SET(a, b, c, d, 5, 5, T21);
- SET(d, a, b, c, 10, 9, T22);
- SET(c, d, a, b, 15, 14, T23);
- SET(b, c, d, a, 4, 20, T24);
- SET(a, b, c, d, 9, 5, T25);
- SET(d, a, b, c, 14, 9, T26);
- SET(c, d, a, b, 3, 14, T27);
- SET(b, c, d, a, 8, 20, T28);
- SET(a, b, c, d, 13, 5, T29);
- SET(d, a, b, c, 2, 9, T30);
- SET(c, d, a, b, 7, 14, T31);
- SET(b, c, d, a, 12, 20, T32);
-#undef SET
-
- /* Round 3. */
- /* Let [abcd k s t] denote the operation
- a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
-#define H(x, y, z) ((x) ^ (y) ^ (z))
-#define SET(a, b, c, d, k, s, Ti)\
- t = a + H(b,c,d) + X[k] + Ti;\
- a = ROTATE_LEFT(t, s) + b
- /* Do the following 16 operations. */
- SET(a, b, c, d, 5, 4, T33);
- SET(d, a, b, c, 8, 11, T34);
- SET(c, d, a, b, 11, 16, T35);
- SET(b, c, d, a, 14, 23, T36);
- SET(a, b, c, d, 1, 4, T37);
- SET(d, a, b, c, 4, 11, T38);
- SET(c, d, a, b, 7, 16, T39);
- SET(b, c, d, a, 10, 23, T40);
- SET(a, b, c, d, 13, 4, T41);
- SET(d, a, b, c, 0, 11, T42);
- SET(c, d, a, b, 3, 16, T43);
- SET(b, c, d, a, 6, 23, T44);
- SET(a, b, c, d, 9, 4, T45);
- SET(d, a, b, c, 12, 11, T46);
- SET(c, d, a, b, 15, 16, T47);
- SET(b, c, d, a, 2, 23, T48);
-#undef SET
-
- /* Round 4. */
- /* Let [abcd k s t] denote the operation
- a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
-#define I(x, y, z) ((y) ^ ((x) | ~(z)))
-#define SET(a, b, c, d, k, s, Ti)\
- t = a + I(b,c,d) + X[k] + Ti;\
- a = ROTATE_LEFT(t, s) + b
- /* Do the following 16 operations. */
- SET(a, b, c, d, 0, 6, T49);
- SET(d, a, b, c, 7, 10, T50);
- SET(c, d, a, b, 14, 15, T51);
- SET(b, c, d, a, 5, 21, T52);
- SET(a, b, c, d, 12, 6, T53);
- SET(d, a, b, c, 3, 10, T54);
- SET(c, d, a, b, 10, 15, T55);
- SET(b, c, d, a, 1, 21, T56);
- SET(a, b, c, d, 8, 6, T57);
- SET(d, a, b, c, 15, 10, T58);
- SET(c, d, a, b, 6, 15, T59);
- SET(b, c, d, a, 13, 21, T60);
- SET(a, b, c, d, 4, 6, T61);
- SET(d, a, b, c, 11, 10, T62);
- SET(c, d, a, b, 2, 15, T63);
- SET(b, c, d, a, 9, 21, T64);
-#undef SET
-
- /* Then perform the following additions. (That is increment each
- of the four registers by the value it had before this block
- was started.) */
- pms->abcd[0] += a;
- pms->abcd[1] += b;
- pms->abcd[2] += c;
- pms->abcd[3] += d;
-}
-
-MD5_STATIC void
-md5_init(md5_state_t *pms)
-{
- pms->count[0] = pms->count[1] = 0;
- pms->abcd[0] = 0x67452301;
- pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476;
- pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301;
- pms->abcd[3] = 0x10325476;
-}
-
-MD5_STATIC void
-md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
-{
- const md5_byte_t *p = data;
- int left = nbytes;
- int offset = (pms->count[0] >> 3) & 63;
- md5_word_t nbits = (md5_word_t)(nbytes << 3);
-
- if (nbytes <= 0)
- return;
-
- /* Update the message length. */
- pms->count[1] += nbytes >> 29;
- pms->count[0] += nbits;
- if (pms->count[0] < nbits)
- pms->count[1]++;
-
- /* Process an initial partial block. */
- if (offset) {
- int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
-
- memcpy(pms->buf + offset, p, copy);
- if (offset + copy < 64)
- return;
- p += copy;
- left -= copy;
- md5_process(pms, pms->buf);
- }
-
- /* Process full blocks. */
- for (; left >= 64; p += 64, left -= 64)
- md5_process(pms, p);
-
- /* Process a final partial block. */
- if (left)
- memcpy(pms->buf, p, left);
-}
-
-MD5_STATIC void
-md5_finish(md5_state_t *pms, md5_byte_t digest[16])
-{
- static const md5_byte_t pad[64] = {
- 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- };
- md5_byte_t data[8];
- int i;
-
- /* Save the length before padding. */
- for (i = 0; i < 8; ++i)
- data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
- /* Pad to 56 bytes mod 64. */
- md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
- /* Append the length. */
- md5_append(pms, data, 8);
- for (i = 0; i < 16; ++i)
- digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_configured/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/discovery_configured/CMakeLists.txt b/remote_services/discovery_configured/CMakeLists.txt
index e0f3e9b..f7d104b 100644
--- a/remote_services/discovery_configured/CMakeLists.txt
+++ b/remote_services/discovery_configured/CMakeLists.txt
@@ -25,9 +25,15 @@ if (RSA_DISCOVERY_CONFIGURED)
NAME "Apache Celix RSA Configured Discovery"
SOURCES
src/discovery_impl.c
+ $<TARGET_OBJECTS:discovery_common>
+ $<TARGET_OBJECTS:civetweb>
)
- target_include_directories(discovery_configured PRIVATE src)
- target_link_libraries(discovery_configured PRIVATE ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} Celix::log_helper discovery_common)
+ target_include_directories(discovery_configured PRIVATE
+ src
+ $<TARGET_PROPERTY:discovery_common,INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:civetweb,INCLUDE_DIRECTORIES>
+ )
+ target_link_libraries(discovery_configured PRIVATE ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} Celix::log_helper)
install_bundle(discovery_configured)
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_configured/src/discovery_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_configured/src/discovery_impl.c b/remote_services/discovery_configured/src/discovery_impl.c
index 35a0c71..89c777e 100644
--- a/remote_services/discovery_configured/src/discovery_impl.c
+++ b/remote_services/discovery_configured/src/discovery_impl.c
@@ -66,12 +66,12 @@ celix_status_t discovery_start(discovery_pt discovery) {
logHelper_start(discovery->loghelper);
- status = endpointDiscoveryPoller_create(discovery, discovery->context, &discovery->poller);
+ status = endpointDiscoveryPoller_create(discovery, discovery->context, DEFAULT_POLL_ENDPOINTS, &discovery->poller);
if (status != CELIX_SUCCESS) {
return CELIX_BUNDLE_EXCEPTION;
}
- status = endpointDiscoveryServer_create(discovery, discovery->context, &discovery->server);
+ status = endpointDiscoveryServer_create(discovery, discovery->context, DEFAULT_SERVER_PATH, DEFAULT_SERVER_PORT, DEFAULT_SERVER_IP, &discovery->server);
if (status != CELIX_SUCCESS) {
return CELIX_BUNDLE_EXCEPTION;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_configured/src/discovery_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_configured/src/discovery_impl.h b/remote_services/discovery_configured/src/discovery_impl.h
index 0414eac..a9d56c1 100644
--- a/remote_services/discovery_configured/src/discovery_impl.h
+++ b/remote_services/discovery_configured/src/discovery_impl.h
@@ -44,19 +44,19 @@
#define DEFAULT_POLL_ENDPOINTS "http://localhost:9999/org.apache.celix.discovery.configured"
-struct discovery {
- bundle_context_pt context;
-
- celix_thread_mutex_t listenerReferencesMutex;
- celix_thread_mutex_t discoveredServicesMutex;
-
- hash_map_pt listenerReferences; //key=serviceReference, value=nop
- hash_map_pt discoveredServices; //key=endpointId (string), value=endpoint_description_pt
-
- endpoint_discovery_poller_pt poller;
- endpoint_discovery_server_pt server;
-
- log_helper_pt loghelper;
-};
+//struct discovery_impl {
+// bundle_context_pt context;
+//
+// celix_thread_mutex_t listenerReferencesMutex;
+// celix_thread_mutex_t discoveredServicesMutex;
+//
+// hash_map_pt listenerReferences; //key=serviceReference, value=nop
+// hash_map_pt discoveredServices; //key=endpointId (string), value=endpoint_description_pt
+//
+// endpoint_discovery_poller_pt poller;
+// endpoint_discovery_server_pt server;
+//
+// log_helper_pt loghelper;
+//};
#endif /* DISCOVERY_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_etcd/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/discovery_etcd/CMakeLists.txt b/remote_services/discovery_etcd/CMakeLists.txt
index 4168281..9c8edc8 100644
--- a/remote_services/discovery_etcd/CMakeLists.txt
+++ b/remote_services/discovery_etcd/CMakeLists.txt
@@ -28,11 +28,19 @@ if (RSA_DISCOVERY_ETCD)
SOURCES
src/discovery_impl.c
src/etcd_watcher.c
+ $<TARGET_OBJECTS:discovery_common>
+ $<TARGET_OBJECTS:civetweb>
)
- target_link_libraries(discovery_etcd PRIVATE Celix::log_helper)
- target_include_directories(discovery_etcd PRIVATE src )
- target_include_directories(discovery_etcd PRIVATE ${CURL_INCLUDE_DIR} ${JANSSON_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR})
- target_link_libraries(discovery_etcd PRIVATE ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} ${JANSSON_LIBRARIES} discovery_common)
+ target_link_libraries(discovery_etcd PRIVATE Celix::log_helper Celix::etcdlib_static)
+ target_include_directories(discovery_etcd PRIVATE src)
+ target_include_directories(discovery_etcd PRIVATE
+ $<TARGET_PROPERTY:discovery_common,INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:civetweb,INCLUDE_DIRECTORIES>
+ ${CURL_INCLUDE_DIR}
+ ${JANSSON_INCLUDE_DIR}
+ ${LIBXML2_INCLUDE_DIR}
+ )
+ target_link_libraries(discovery_etcd PRIVATE ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} ${JANSSON_LIBRARIES})
install_bundle(discovery_etcd)
endif (RSA_DISCOVERY_ETCD)
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_etcd/src/discovery_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_etcd/src/discovery_impl.c b/remote_services/discovery_etcd/src/discovery_impl.c
index 8087d95..500399e 100644
--- a/remote_services/discovery_etcd/src/discovery_impl.c
+++ b/remote_services/discovery_etcd/src/discovery_impl.c
@@ -50,25 +50,35 @@
-celix_status_t discovery_create(bundle_context_pt context, discovery_pt *discovery) {
+celix_status_t discovery_create(bundle_context_pt context, discovery_t** out) {
celix_status_t status = CELIX_SUCCESS;
- *discovery = malloc(sizeof(struct discovery));
- if (!*discovery) {
- return CELIX_ENOMEM;
- }
+ discovery_t* discovery = calloc(1, sizeof(*discovery));
+ discovery_impl_t* pImpl = calloc(1, sizeof(*pImpl));
+
+ if (discovery != NULL && pImpl != NULL) {
+ discovery->pImpl = pImpl;
+ discovery->context = context;
+ discovery->poller = NULL;
+ discovery->server = NULL;
- (*discovery)->context = context;
- (*discovery)->poller = NULL;
- (*discovery)->server = NULL;
+ discovery->listenerReferences = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2,
+ NULL);
+ discovery->discoveredServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- (*discovery)->listenerReferences = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
- (*discovery)->discoveredServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ status = celixThreadMutex_create(&discovery->listenerReferencesMutex, NULL);
+ status = celixThreadMutex_create(&discovery->discoveredServicesMutex, NULL);
- status = celixThreadMutex_create(&(*discovery)->listenerReferencesMutex, NULL);
- status = celixThreadMutex_create(&(*discovery)->discoveredServicesMutex, NULL);
+ logHelper_create(context, &discovery->loghelper);
+ } else {
+ status = CELIX_ENOMEM;
+ free(discovery);
+ free(pImpl);
+ }
- logHelper_create(context, &(*discovery)->loghelper);
+ if (status == CELIX_SUCCESS) {
+ *out = discovery;
+ }
return status;
}
@@ -124,17 +134,17 @@ celix_status_t discovery_start(discovery_pt discovery) {
path = DEFAULT_SERVER_PATH;
}
- status = endpointDiscoveryPoller_create(discovery, discovery->context, &discovery->poller);
+ status = endpointDiscoveryPoller_create(discovery, discovery->context, DEFAULT_POLL_ENDPOINTS, &discovery->poller);
if (status != CELIX_SUCCESS) {
return CELIX_BUNDLE_EXCEPTION;
}
- status = endpointDiscoveryServer_create(discovery, discovery->context, &discovery->server);
+ status = endpointDiscoveryServer_create(discovery, discovery->context, DEFAULT_SERVER_PATH, DEFAULT_SERVER_PORT, DEFAULT_SERVER_IP, &discovery->server);
if (status != CELIX_SUCCESS) {
return CELIX_BUNDLE_EXCEPTION;
}
- status = etcdWatcher_create(discovery, discovery->context, &discovery->watcher);
+ status = etcdWatcher_create(discovery, discovery->context, &discovery->pImpl->watcher);
if (status != CELIX_SUCCESS) {
return CELIX_BUNDLE_EXCEPTION;
}
@@ -144,7 +154,7 @@ celix_status_t discovery_start(discovery_pt discovery) {
celix_status_t discovery_stop(discovery_pt discovery) {
celix_status_t status;
- status = etcdWatcher_destroy(discovery->watcher);
+ status = etcdWatcher_destroy(discovery->pImpl->watcher);
if (status != CELIX_SUCCESS) {
return CELIX_BUNDLE_EXCEPTION;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_etcd/src/discovery_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_etcd/src/discovery_impl.h b/remote_services/discovery_etcd/src/discovery_impl.h
index a19b145..f28017b 100644
--- a/remote_services/discovery_etcd/src/discovery_impl.h
+++ b/remote_services/discovery_etcd/src/discovery_impl.h
@@ -47,20 +47,8 @@
#define FREE_MEM(ptr) if(ptr) {free(ptr); ptr = NULL;}
-struct discovery {
- bundle_context_pt context;
-
- celix_thread_mutex_t listenerReferencesMutex;
- celix_thread_mutex_t discoveredServicesMutex;
-
- hash_map_pt listenerReferences; //key=serviceReference, value=nop
- hash_map_pt discoveredServices; //key=endpointId (string), value=endpoint_description_pt
-
- etcd_watcher_pt watcher;
- endpoint_discovery_poller_pt poller;
- endpoint_discovery_server_pt server;
-
- log_helper_pt loghelper;
+struct discovery_impl {
+ etcd_watcher_t* watcher;
};
#endif /* DISCOVERY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_etcd/src/etcd_watcher.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_etcd/src/etcd_watcher.h b/remote_services/discovery_etcd/src/etcd_watcher.h
index b4dbf40..56bae92 100644
--- a/remote_services/discovery_etcd/src/etcd_watcher.h
+++ b/remote_services/discovery_etcd/src/etcd_watcher.h
@@ -31,6 +31,7 @@
#include "discovery.h"
#include "endpoint_discovery_poller.h"
+typedef struct etcd_watcher etcd_watcher_t;
typedef struct etcd_watcher *etcd_watcher_pt;
celix_status_t etcdWatcher_create(discovery_pt discovery, bundle_context_pt context, etcd_watcher_pt *watcher);
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_shm/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/CMakeLists.txt b/remote_services/discovery_shm/CMakeLists.txt
index dff403d..61e54f7 100644
--- a/remote_services/discovery_shm/CMakeLists.txt
+++ b/remote_services/discovery_shm/CMakeLists.txt
@@ -28,13 +28,17 @@ find_package(CURL REQUIRED)
src/discovery_shm.c
src/discovery_shmWatcher.c
src/discovery_impl.c
+ $<TARGET_OBJECTS:discovery_common>
+ $<TARGET_OBJECTS:civetweb>
)
target_include_directories(discovery_shm PRIVATE
src
${LIBXML2_INCLUDE_DIR}
${CURL_INCLUDE_DIR}
+ $<TARGET_PROPERTY:discovery_common,INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:civetweb,INCLUDE_DIRECTORIES>
)
- target_link_libraries(discovery_shm PRIVATE Celix::framework ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} discovery_common)
+ target_link_libraries(discovery_shm PRIVATE Celix::framework ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES})
install_bundle(discovery_shm)
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_shm/src/discovery_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/src/discovery_impl.c b/remote_services/discovery_shm/src/discovery_impl.c
index 2604595..fadff8c 100644
--- a/remote_services/discovery_shm/src/discovery_impl.c
+++ b/remote_services/discovery_shm/src/discovery_impl.c
@@ -48,28 +48,34 @@
#include "endpoint_discovery_poller.h"
#include "endpoint_discovery_server.h"
-
-
-celix_status_t discovery_create(bundle_context_pt context, discovery_pt *discovery) {
+celix_status_t discovery_create(bundle_context_pt context, discovery_t** out) {
celix_status_t status = CELIX_SUCCESS;
- *discovery = calloc(1, sizeof(struct discovery));
- if (!*discovery) {
- status = CELIX_ENOMEM;
- } else {
- (*discovery)->context = context;
- (*discovery)->poller = NULL;
- (*discovery)->server = NULL;
+ discovery_t* discovery = calloc(1, sizeof(*discovery));
+ discovery_impl_t* pImpl = calloc(1, sizeof(*pImpl));
+ if (discovery != NULL && pImpl != NULL) {
+ discovery->pImpl = pImpl;
+ discovery->context = context;
+ discovery->poller = NULL;
+ discovery->server = NULL;
- (*discovery)->listenerReferences = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
- (*discovery)->discoveredServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ discovery->listenerReferences = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
+ discovery->discoveredServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- celixThreadMutex_create(&(*discovery)->listenerReferencesMutex, NULL);
- celixThreadMutex_create(&(*discovery)->discoveredServicesMutex, NULL);
+ celixThreadMutex_create(&discovery->listenerReferencesMutex, NULL);
+ celixThreadMutex_create(&discovery->discoveredServicesMutex, NULL);
- if (logHelper_create(context, &(*discovery)->loghelper) == CELIX_SUCCESS) {
- logHelper_start((*discovery)->loghelper);
+ if (logHelper_create(context, &discovery->loghelper) == CELIX_SUCCESS) {
+ logHelper_start(discovery->loghelper);
}
+ } else {
+ status = CELIX_ENOMEM;
+ free(discovery);
+ free(pImpl);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *out = discovery;
}
return status;
@@ -113,9 +119,9 @@ celix_status_t discovery_destroy(discovery_pt discovery) {
celix_status_t discovery_start(discovery_pt discovery) {
celix_status_t status;
- status = endpointDiscoveryPoller_create(discovery, discovery->context, &discovery->poller);
+ status = endpointDiscoveryPoller_create(discovery, discovery->context, DEFAULT_POLL_ENDPOINTS, &discovery->poller);
if (status == CELIX_SUCCESS) {
- status = endpointDiscoveryServer_create(discovery, discovery->context, &discovery->server);
+ status = endpointDiscoveryServer_create(discovery, discovery->context, DEFAULT_SERVER_PATH, DEFAULT_SERVER_PORT, DEFAULT_SERVER_IP, &discovery->server);
}
if (status == CELIX_SUCCESS) {
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_shm/src/discovery_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/src/discovery_impl.h b/remote_services/discovery_shm/src/discovery_impl.h
index c7206bd..e994b1f 100644
--- a/remote_services/discovery_shm/src/discovery_impl.h
+++ b/remote_services/discovery_shm/src/discovery_impl.h
@@ -37,30 +37,17 @@
#include "endpoint_discovery_server.h"
#include "discovery_shmWatcher.h"
-
#define DEFAULT_SERVER_IP "127.0.0.1"
#define DEFAULT_SERVER_PORT "9999"
#define DEFAULT_SERVER_PATH "/org.apache.celix.discovery.shm"
#define DEFAULT_POLL_ENDPOINTS "http://localhost:9999/org.apache.celix.discovery.shm"
-#define MAX_ROOTNODE_LENGTH 64
-#define MAX_LOCALNODE_LENGTH 256
-
-
-struct discovery {
- bundle_context_pt context;
-
- celix_thread_mutex_t listenerReferencesMutex;
- celix_thread_mutex_t discoveredServicesMutex;
-
- hash_map_pt listenerReferences; //key=serviceReference, value=nop
- hash_map_pt discoveredServices; //key=endpointId (string), value=endpoint_description_pt
+#define MAX_ROOTNODE_LENGTH 64
+#define MAX_LOCALNODE_LENGTH 256
- shm_watcher_pt watcher;
- endpoint_discovery_poller_pt poller;
- endpoint_discovery_server_pt server;
- log_helper_pt loghelper;
+struct discovery_impl {
+ shm_watcher_t* watcher;
};
#endif /* DISCOVERY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_shm/src/discovery_shmWatcher.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/src/discovery_shmWatcher.c b/remote_services/discovery_shm/src/discovery_shmWatcher.c
index 6460de8..ef7df71 100644
--- a/remote_services/discovery_shm/src/discovery_shmWatcher.c
+++ b/remote_services/discovery_shm/src/discovery_shmWatcher.c
@@ -40,6 +40,15 @@
#include "endpoint_discovery_poller.h"
+#define DEFAULT_SERVER_IP "127.0.0.1"
+#define DEFAULT_SERVER_PORT "9999"
+#define DEFAULT_SERVER_PATH "/org.apache.celix.discovery.shm"
+#define DEFAULT_POLL_ENDPOINTS "http://localhost:9999/org.apache.celix.discovery.shm"
+
+#define MAX_ROOTNODE_LENGTH 64
+#define MAX_LOCALNODE_LENGTH 256
+
+
struct shm_watcher {
shmData_pt shmData;
celix_thread_t watcherThread;
@@ -82,7 +91,7 @@ static celix_status_t discoveryShmWatcher_getLocalNodePath(bundle_context_pt con
/* retrieves all endpoints from shm and syncs them with the ones already available */
static celix_status_t discoveryShmWatcher_syncEndpoints(discovery_pt discovery) {
celix_status_t status = CELIX_SUCCESS;
- shm_watcher_pt watcher = discovery->watcher;
+ shm_watcher_pt watcher = discovery->pImpl->watcher;
char** shmKeyArr = calloc(SHM_DATA_MAX_ENTRIES, sizeof(*shmKeyArr));
array_list_pt registeredKeyArr = NULL;
@@ -147,7 +156,7 @@ static celix_status_t discoveryShmWatcher_syncEndpoints(discovery_pt discovery)
static void* discoveryShmWatcher_run(void* data) {
discovery_pt discovery = (discovery_pt) data;
- shm_watcher_pt watcher = discovery->watcher;
+ shm_watcher_pt watcher = discovery->pImpl->watcher;
char localNodePath[MAX_LOCALNODE_LENGTH];
char url[MAX_LOCALNODE_LENGTH];
@@ -194,10 +203,10 @@ celix_status_t discoveryShmWatcher_create(discovery_pt discovery) {
}
if (status == CELIX_SUCCESS) {
- discovery->watcher = watcher;
+ discovery->pImpl->watcher = watcher;
}
else{
- discovery->watcher = NULL;
+ discovery->pImpl->watcher = NULL;
free(watcher);
}
@@ -216,7 +225,7 @@ celix_status_t discoveryShmWatcher_create(discovery_pt discovery) {
celix_status_t discoveryShmWatcher_destroy(discovery_pt discovery) {
celix_status_t status;
- shm_watcher_pt watcher = discovery->watcher;
+ shm_watcher_pt watcher = discovery->pImpl->watcher;
char localNodePath[MAX_LOCALNODE_LENGTH];
celixThreadMutex_lock(&watcher->watcherLock);
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_shm/src/discovery_shmWatcher.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/src/discovery_shmWatcher.h b/remote_services/discovery_shm/src/discovery_shmWatcher.h
index ff70f72..4e7e1d5 100644
--- a/remote_services/discovery_shm/src/discovery_shmWatcher.h
+++ b/remote_services/discovery_shm/src/discovery_shmWatcher.h
@@ -31,6 +31,7 @@
#include "discovery.h"
#include "endpoint_discovery_poller.h"
+typedef struct shm_watcher shm_watcher_t;
typedef struct shm_watcher *shm_watcher_pt;
celix_status_t discoveryShmWatcher_create(discovery_pt discovery);
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_common/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/CMakeLists.txt b/remote_services/remote_service_admin_common/CMakeLists.txt
index 1813211..a421cda 100644
--- a/remote_services/remote_service_admin_common/CMakeLists.txt
+++ b/remote_services/remote_service_admin_common/CMakeLists.txt
@@ -21,4 +21,6 @@ add_library(remote_service_admin_common STATIC
src/import_registration_impl.c
)
target_include_directories(remote_service_admin_common PRIVATE src)
-target_link_libraries(remote_service_admin_common PUBLIC Celix::framework Celix::remote_service_admin_api Celix::log_helper)
\ No newline at end of file
+target_link_libraries(remote_service_admin_common PUBLIC Celix::framework Celix::remote_service_admin_api Celix::log_helper)
+
+add_library(Celix::remote_service_admin_common ALIAS remote_service_admin_common)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/CMakeLists.txt b/remote_services/remote_service_admin_dfi/CMakeLists.txt
index 4b28231..206c6dc 100644
--- a/remote_services/remote_service_admin_dfi/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/CMakeLists.txt
@@ -23,21 +23,31 @@ if (RSA_REMOTE_SERVICE_ADMIN_DFI)
find_package(CURL REQUIRED)
find_package(Jansson REQUIRED)
- include_directories(
- ${CURL_INCLUDE_DIRS}
- ${JANSSON_INCLUDE_DIRS}
+ add_bundle(remote_service_admin_dfi
+ VERSION 0.9.0
+ SYMBOLIC_NAME "apache_celix_remote_service_admin_dfi"
+ NAME "Apache Celix Remote Service Admin Dynamic Function Interface (DFI)"
+ SOURCES
+ src/remote_service_admin_dfi.c
+ src/remote_service_admin_activator.c
+ src/export_registration_dfi.c
+ src/import_registration_dfi.c
+ src/dfi_utils.c
+ $<TARGET_OBJECTS:civetweb>
)
+ target_include_directories(remote_service_admin_dfi PRIVATE src $<TARGET_PROPERTY:civetweb,INCLUDE_DIRECTORIES>)
+ target_link_libraries(remote_service_admin_dfi PRIVATE
+ Celix::dfi_static
+ Celix::log_helper
+ Celix::remote_service_admin_common
+ ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
- if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
- include_directories(dynamic_function_interface/memstream)
- endif()
-
- add_subdirectory(rsa)
+ install_bundle(remote_service_admin_dfi)
if (ENABLE_TESTING)
- find_package(CppUTest REQUIRED)
- include_directories(${CPPUTEST_INCLUDE_DIR})
- add_subdirectory(rsa_tst)
+ add_subdirectory(test)
endif()
+ #Setup target aliases to match external usage
+ add_library(Celix::remote_service_admin_dfi ALIAS remote_service_admin_dfi)
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt b/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
deleted file mode 100644
index 3efabf8..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
+++ /dev/null
@@ -1,34 +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.
-
-add_bundle(remote_service_admin_dfi
- VERSION 0.9.0
- SYMBOLIC_NAME "apache_celix_remote_service_admin_dfi"
- NAME "Apache Celix Remote Service Admin Dynamic Function Interface (DFI)"
- SOURCES
- src/remote_service_admin_dfi.c
- src/remote_service_admin_activator.c
- src/export_registration_dfi.c
- src/import_registration_dfi.c
- src/dfi_utils.c
-)
-target_include_directories(remote_service_admin_dfi PRIVATE src)
-target_link_libraries(remote_service_admin_dfi PRIVATE
- Celix::dfi Celix::log_helper remote_service_admin_common
- ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
-
-install_bundle(remote_service_admin_dfi)
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa/src/dfi_utils.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/dfi_utils.c b/remote_services/remote_service_admin_dfi/rsa/src/dfi_utils.c
deleted file mode 100644
index 1b1eb36..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/src/dfi_utils.c
+++ /dev/null
@@ -1,98 +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.
- */
-
-#include "dfi_utils.h"
-#include <stdlib.h>
-#include <unistd.h>
-
-static celix_status_t dfi_findFileForFramework(bundle_context_pt context, const char *fileName, FILE **out) {
- celix_status_t status;
-
- char pwd[1024];
- char path[1024];
- const char *extPath = NULL;
-
- status = bundleContext_getProperty(context, "CELIX_FRAMEWORK_EXTENDER_PATH", &extPath);
- if (status != CELIX_SUCCESS || extPath == NULL) {
- getcwd(pwd, sizeof(pwd));
- extPath = pwd;
- }
-
- snprintf(path, sizeof(path), "%s/%s", extPath, fileName);
-
- if (status == CELIX_SUCCESS) {
- FILE *df = fopen(path, "r");
- if (df == NULL) {
- status = CELIX_FILE_IO_EXCEPTION;
- } else {
- *out = df;
- }
- }
-
- return status;
-}
-
-static celix_status_t dfi_findFileForBundle(bundle_pt bundle, const char *fileName, FILE **out) {
- celix_status_t status;
-
- char *path = NULL;
- char metaInfFileName[512];
- snprintf(metaInfFileName, sizeof(metaInfFileName), "META-INF/descriptors/%s", fileName);
-
- status = bundle_getEntry(bundle, fileName, &path);
-
- if (status != CELIX_SUCCESS || path == NULL) {
- status = bundle_getEntry(bundle, metaInfFileName, &path);
- }
-
- if (status == CELIX_SUCCESS && path != NULL) {
- FILE *df = fopen(path, "r");
- if (df == NULL) {
- status = CELIX_FILE_IO_EXCEPTION;
- } else {
- *out = df;
- }
-
- }
-
- free(path);
- return status;
-}
-
-celix_status_t dfi_findDescriptor(bundle_context_pt context, bundle_pt bundle, const char *name, FILE **out) {
- celix_status_t status;
- char fileName[128];
-
- snprintf(fileName, 128, "%s.descriptor", name);
-
- long id;
- status = bundle_getBundleId(bundle, &id);
-
- if (status == CELIX_SUCCESS) {
- if (id == 0) {
- //framework bundle
- status = dfi_findFileForFramework(context, fileName, out);
- } else {
- //normal bundle
- status = dfi_findFileForBundle(bundle, fileName, out);
- }
- }
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa/src/dfi_utils.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/dfi_utils.h b/remote_services/remote_service_admin_dfi/rsa/src/dfi_utils.h
deleted file mode 100644
index cec8aa1..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/src/dfi_utils.h
+++ /dev/null
@@ -1,30 +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.
- */
-#ifndef DFI_UTILS_H_
-#define DFI_UTILS_H_
-
-#include "bundle.h"
-#include "bundle_context.h"
-#include <stdio.h>
-#include "celix_errno.h"
-
-
-celix_status_t dfi_findDescriptor(bundle_context_pt context, bundle_pt bundle, const char *name, FILE **out);
-
-#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa/src/export_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/export_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/src/export_registration_dfi.c
deleted file mode 100644
index b83b5a8..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/src/export_registration_dfi.c
+++ /dev/null
@@ -1,251 +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.
- */
-
-#include <jansson.h>
-#include <dyn_interface.h>
-#include <json_serializer.h>
-#include <remote_constants.h>
-#include <remote_service_admin.h>
-#include <service_tracker_customizer.h>
-#include <service_tracker.h>
-#include <json_rpc.h>
-#include "constants.h"
-#include "export_registration_dfi.h"
-#include "dfi_utils.h"
-
-struct export_reference {
- endpoint_description_pt endpoint; //owner
- service_reference_pt reference;
-};
-
-struct export_registration {
- bundle_context_pt context;
- struct export_reference exportReference;
- char *servId;
- dyn_interface_type *intf; //owner
- service_tracker_pt tracker;
-
- celix_thread_mutex_t mutex;
- void *service; //protected by mutex
-
- //TODO add tracker and lock
- bool closed;
-};
-
-static void exportRegistration_addServ(export_registration_pt reg, service_reference_pt ref, void *service);
-static void exportRegistration_removeServ(export_registration_pt reg, service_reference_pt ref, void *service);
-
-celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, bundle_context_pt context, export_registration_pt *out) {
- celix_status_t status = CELIX_SUCCESS;
-
- const char *servId = NULL;
- status = serviceReference_getProperty(reference, "service.id", &servId);
- if (status != CELIX_SUCCESS) {
- logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "Cannot find service.id for ref");
- }
-
- export_registration_pt reg = NULL;
- if (status == CELIX_SUCCESS) {
- reg = calloc(1, sizeof(*reg));
- if (reg == NULL) {
- status = CELIX_ENOMEM;
- }
- }
-
-
- if (status == CELIX_SUCCESS) {
- reg->context = context;
- reg->exportReference.endpoint = endpoint;
- reg->exportReference.reference = reference;
- reg->closed = false;
-
- celixThreadMutex_create(®->mutex, NULL);
- }
-
- const char *exports = NULL;
- CELIX_DO_IF(status, serviceReference_getProperty(reference, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exports));
-
- bundle_pt bundle = NULL;
- CELIX_DO_IF(status, serviceReference_getBundle(reference, &bundle));
-
- FILE *descriptor = NULL;
- if (status == CELIX_SUCCESS) {
- status = dfi_findDescriptor(context, bundle, exports, &descriptor);
- }
-
- if (status != CELIX_SUCCESS || descriptor == NULL) {
- status = CELIX_BUNDLE_EXCEPTION;
- logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Cannot find/open descriptor for '%s'", exports);
- }
-
- if (status == CELIX_SUCCESS) {
- int rc = dynInterface_parse(descriptor, ®->intf);
- fclose(descriptor);
- if (rc != 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "RSA: Error parsing service descriptor.");
- }
- else{
- /* Add the interface version as a property in the properties_map */
- char* intfVersion = NULL;
- dynInterface_getVersionString(reg->intf, &intfVersion);
- const char *serviceVersion = properties_get(endpoint->properties,(char*) CELIX_FRAMEWORK_SERVICE_VERSION);
- if(serviceVersion!=NULL){
- if(strcmp(serviceVersion,intfVersion)!=0){
- logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "Service version (%s) and interface version from the descriptor (%s) are not the same!",serviceVersion,intfVersion);
- }
- }
- else{
- properties_set(endpoint->properties, (char*) CELIX_FRAMEWORK_SERVICE_VERSION, intfVersion);
- }
- }
- }
-
- if (status == CELIX_SUCCESS) {
- service_tracker_customizer_pt cust = NULL;
- status = serviceTrackerCustomizer_create(reg, NULL, (void *) exportRegistration_addServ, NULL,
- (void *) exportRegistration_removeServ, &cust);
- if (status == CELIX_SUCCESS) {
- char filter[32];
- snprintf(filter, 32, "(service.id=%s)", servId);
- status = serviceTracker_createWithFilter(reg->context, filter, cust, ®->tracker);
- }
- }
-
- if (status == CELIX_SUCCESS) {
- *out = reg;
- } else {
- logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Error creating export registration");
- exportRegistration_destroy(reg);
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_call(export_registration_pt export, char *data, int datalength, char **responseOut, int *responseLength) {
- int status = CELIX_SUCCESS;
-
- //printf("calling for '%s'\n");
-
- *responseLength = -1;
- celixThreadMutex_lock(&export->mutex);
- status = jsonRpc_call(export->intf, export->service, data, responseOut);
- celixThreadMutex_unlock(&export->mutex);
-
- return status;
-}
-
-void exportRegistration_destroy(export_registration_pt reg) {
- if (reg != NULL) {
- if (reg->intf != NULL) {
- dyn_interface_type *intf = reg->intf;
- reg->intf = NULL;
- dynInterface_destroy(intf);
- }
-
- if (reg->exportReference.endpoint != NULL) {
- endpoint_description_pt ep = reg->exportReference.endpoint;
- reg->exportReference.endpoint = NULL;
- endpointDescription_destroy(ep);
- }
- if (reg->tracker != NULL) {
- serviceTracker_destroy(reg->tracker);
- }
- celixThreadMutex_destroy(®->mutex);
-
- free(reg);
- }
-}
-
-celix_status_t exportRegistration_start(export_registration_pt reg) {
- celix_status_t status = CELIX_SUCCESS;
-
- serviceTracker_open(reg->tracker);
- return status;
-}
-
-
-celix_status_t exportRegistration_stop(export_registration_pt reg) {
- celix_status_t status = CELIX_SUCCESS;
- if (status == CELIX_SUCCESS) {
- status = bundleContext_ungetServiceReference(reg->context, reg->exportReference.reference);
- serviceTracker_close(reg->tracker);
- }
- return status;
-}
-
-static void exportRegistration_addServ(export_registration_pt reg, service_reference_pt ref, void *service) {
- celixThreadMutex_lock(®->mutex);
- reg->service = service;
- celixThreadMutex_unlock(®->mutex);
-}
-
-static void exportRegistration_removeServ(export_registration_pt reg, service_reference_pt ref, void *service) {
- celixThreadMutex_lock(®->mutex);
- if (reg->service == service) {
- reg->service = NULL;
- }
- celixThreadMutex_unlock(®->mutex);
-}
-
-
-celix_status_t exportRegistration_close(export_registration_pt reg) {
- celix_status_t status = CELIX_SUCCESS;
- exportRegistration_stop(reg);
- return status;
-}
-
-
-celix_status_t exportRegistration_getException(export_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- //TODO
- return status;
-}
-
-celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *out) {
- celix_status_t status = CELIX_SUCCESS;
- export_reference_pt ref = calloc(1, sizeof(*ref));
- if (ref != NULL) {
- ref->endpoint = registration->exportReference.endpoint;
- ref->reference = registration->exportReference.reference;
- } else {
- status = CELIX_ENOMEM;
- }
-
- if (status == CELIX_SUCCESS) {
- *out = ref;
- }
-
- return status;
-}
-
-celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint) {
- celix_status_t status = CELIX_SUCCESS;
- *endpoint = reference->endpoint;
- return status;
-}
-
-celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *ref) {
- celix_status_t status = CELIX_SUCCESS;
- *ref = reference->reference;
- return status;
-}
-
-
-
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa/src/export_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/export_registration_dfi.h b/remote_services/remote_service_admin_dfi/rsa/src/export_registration_dfi.h
deleted file mode 100644
index 93f37ba..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/src/export_registration_dfi.h
+++ /dev/null
@@ -1,38 +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.
- */
-
-#ifndef CELIX_EXPORT_REGISTRATION_DFI_H
-#define CELIX_EXPORT_REGISTRATION_DFI_H
-
-
-#include "export_registration.h"
-#include "log_helper.h"
-#include "endpoint_description.h"
-
-celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, bundle_context_pt context, export_registration_pt *registration);
-celix_status_t exportRegistration_close(export_registration_pt registration);
-void exportRegistration_destroy(export_registration_pt registration);
-
-celix_status_t exportRegistration_start(export_registration_pt registration);
-celix_status_t exportRegistration_stop(export_registration_pt registration);
-
-celix_status_t exportRegistration_call(export_registration_pt export, char *data, int datalength, char **response, int *responseLength);
-
-
-#endif //CELIX_EXPORT_REGISTRATION_DFI_H
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/src/import_registration_dfi.c
deleted file mode 100644
index 0b8dcf7..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/src/import_registration_dfi.c
+++ /dev/null
@@ -1,402 +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.
- */
-
-#include <stdlib.h>
-#include <jansson.h>
-#include <json_rpc.h>
-#include <assert.h>
-#include "version.h"
-#include "json_serializer.h"
-#include "dyn_interface.h"
-#include "import_registration.h"
-#include "import_registration_dfi.h"
-
-struct import_registration {
- bundle_context_pt context;
- endpoint_description_pt endpoint; //TODO owner? -> free when destroyed
- const char *classObject; //NOTE owned by endpoint
- version_pt version;
-
- celix_thread_mutex_t mutex; //protects send & sendhandle
- send_func_type send;
- void *sendHandle;
-
- service_factory_pt factory;
- service_registration_pt factoryReg;
-
- hash_map_pt proxies; //key -> bundle, value -> service_proxy
- celix_thread_mutex_t proxiesMutex; //protects proxies
-};
-
-struct service_proxy {
- dyn_interface_type *intf;
- void *service;
- size_t count;
-};
-
-static celix_status_t importRegistration_createProxy(import_registration_pt import, bundle_pt bundle,
- struct service_proxy **proxy);
-static void importRegistration_proxyFunc(void *userData, void *args[], void *returnVal);
-static void importRegistration_destroyProxy(struct service_proxy *proxy);
-static void importRegistration_clearProxies(import_registration_pt import);
-
-celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt endpoint, const char *classObject, const char* serviceVersion,
- import_registration_pt *out) {
- celix_status_t status = CELIX_SUCCESS;
- import_registration_pt reg = calloc(1, sizeof(*reg));
-
- if (reg != NULL) {
- reg->factory = calloc(1, sizeof(*reg->factory));
- }
-
- if (reg != NULL && reg->factory != NULL) {
- reg->context = context;
- reg->endpoint = endpoint;
- reg->classObject = classObject;
- reg->proxies = hashMap_create(NULL, NULL, NULL, NULL);
-
- celixThreadMutex_create(®->mutex, NULL);
- celixThreadMutex_create(®->proxiesMutex, NULL);
- status = version_createVersionFromString((char*)serviceVersion,&(reg->version));
-
- reg->factory->handle = reg;
- reg->factory->getService = (void *)importRegistration_getService;
- reg->factory->ungetService = (void *)importRegistration_ungetService;
- } else {
- status = CELIX_ENOMEM;
- }
-
- if (status == CELIX_SUCCESS) {
- //printf("IMPORT REGISTRATION IS %p\n", reg);
- *out = reg;
- }
- else{
- importRegistration_destroy(reg);
- }
-
- return status;
-}
-
-
-celix_status_t importRegistration_setSendFn(import_registration_pt reg,
- send_func_type send,
- void *handle) {
- celixThreadMutex_lock(®->mutex);
- reg->send = send;
- reg->sendHandle = handle;
- celixThreadMutex_unlock(®->mutex);
-
- return CELIX_SUCCESS;
-}
-
-static void importRegistration_clearProxies(import_registration_pt import) {
- if (import != NULL) {
- pthread_mutex_lock(&import->proxiesMutex);
- if (import->proxies != NULL) {
- hash_map_iterator_pt iter = hashMapIterator_create(import->proxies);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- struct service_proxy *proxy = hashMapEntry_getValue(entry);
- importRegistration_destroyProxy(proxy);
- }
- hashMapIterator_destroy(iter);
- }
- pthread_mutex_unlock(&import->proxiesMutex);
- }
-}
-
-void importRegistration_destroy(import_registration_pt import) {
- if (import != NULL) {
- if (import->proxies != NULL) {
- hashMap_destroy(import->proxies, false, false);
- import->proxies = NULL;
- }
-
- pthread_mutex_destroy(&import->mutex);
- pthread_mutex_destroy(&import->proxiesMutex);
-
- if (import->factory != NULL) {
- free(import->factory);
- }
-
- if(import->version!=NULL){
- version_destroy(import->version);
- }
- free(import);
- }
-}
-
-celix_status_t importRegistration_start(import_registration_pt import) {
- celix_status_t status = CELIX_SUCCESS;
- if (import->factoryReg == NULL && import->factory != NULL) {
- properties_pt props = NULL;
- properties_copy(import->endpoint->properties, &props);
- status = bundleContext_registerServiceFactory(import->context, (char *)import->classObject, import->factory, props, &import->factoryReg);
- } else {
- status = CELIX_ILLEGAL_STATE;
- }
- return status;
-}
-
-celix_status_t importRegistration_stop(import_registration_pt import) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (import->factoryReg != NULL) {
- serviceRegistration_unregister(import->factoryReg);
- import->factoryReg = NULL;
- }
-
- importRegistration_clearProxies(import);
-
- return status;
-}
-
-
-celix_status_t importRegistration_getService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **out) {
- celix_status_t status = CELIX_SUCCESS;
-
- /*
- module_pt module = NULL;
- char *name = NULL;
- bundle_getCurrentModule(bundle, &module);
- module_getSymbolicName(module, &name);
- printf("getting service for bundle '%s'\n", name);
- */
-
-
- pthread_mutex_lock(&import->proxiesMutex);
- struct service_proxy *proxy = hashMap_get(import->proxies, bundle);
- if (proxy == NULL) {
- status = importRegistration_createProxy(import, bundle, &proxy);
- if (status == CELIX_SUCCESS) {
- hashMap_put(import->proxies, bundle, proxy);
- }
- }
-
- if (status == CELIX_SUCCESS) {
- proxy->count += 1;
- *out = proxy->service;
- }
- pthread_mutex_unlock(&import->proxiesMutex);
-
- return status;
-}
-
-static celix_status_t importRegistration_createProxy(import_registration_pt import, bundle_pt bundle, struct service_proxy **out) {
- celix_status_t status;
- dyn_interface_type* intf = NULL;
- FILE *descriptor = NULL;
-
- status = dfi_findDescriptor(import->context, bundle, import->classObject, &descriptor);
-
- if (status != CELIX_SUCCESS || descriptor == NULL) {
- //TODO use log helper logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Cannot find/open descriptor for '%s'", import->classObject);
- fprintf(stderr, "RSA_DFI: Cannot find/open descriptor for '%s'", import->classObject);
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- if (status == CELIX_SUCCESS) {
- int rc = dynInterface_parse(descriptor, &intf);
- fclose(descriptor);
- if (rc != 0 || intf==NULL) {
- return CELIX_BUNDLE_EXCEPTION;
- }
- }
-
- /* Check if the imported service version is compatible with the one in the consumer descriptor */
- version_pt consumerVersion = NULL;
- bool isCompatible = false;
- dynInterface_getVersion(intf,&consumerVersion);
- version_isCompatible(consumerVersion,import->version,&isCompatible);
-
- if(!isCompatible){
- char* cVerString = NULL;
- char* pVerString = NULL;
- version_toString(consumerVersion,&cVerString);
- version_toString(import->version,&pVerString);
- printf("Service version mismatch: consumer has %s, provider has %s. NOT creating proxy.\n",cVerString,pVerString);
- dynInterface_destroy(intf);
- free(cVerString);
- free(pVerString);
- status = CELIX_SERVICE_EXCEPTION;
- }
-
- struct service_proxy *proxy = NULL;
- if (status == CELIX_SUCCESS) {
- proxy = calloc(1, sizeof(*proxy));
- if (proxy == NULL) {
- status = CELIX_ENOMEM;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- proxy->intf = intf;
- size_t count = dynInterface_nrOfMethods(proxy->intf);
- proxy->service = calloc(1 + count, sizeof(void *));
- if (proxy->service == NULL) {
- status = CELIX_ENOMEM;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- void **serv = proxy->service;
- serv[0] = import;
-
- struct methods_head *list = NULL;
- dynInterface_methods(proxy->intf, &list);
- struct method_entry *entry = NULL;
- void (*fn)(void) = NULL;
- int index = 0;
- TAILQ_FOREACH(entry, list, entries) {
- int rc = dynFunction_createClosure(entry->dynFunc, importRegistration_proxyFunc, entry, &fn);
- serv[index + 1] = fn;
- index += 1;
-
- if (rc != 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- break;
- }
- }
- }
-
- if (status == CELIX_SUCCESS) {
- *out = proxy;
- } else if (proxy != NULL) {
- if (proxy->intf != NULL) {
- dynInterface_destroy(proxy->intf);
- proxy->intf = NULL;
- }
- free(proxy->service);
- free(proxy);
- }
-
- return status;
-}
-
-static void importRegistration_proxyFunc(void *userData, void *args[], void *returnVal) {
- int status = CELIX_SUCCESS;
- struct method_entry *entry = userData;
- import_registration_pt import = *((void **)args[0]);
-
- if (import == NULL || import->send == NULL) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
-
- char *invokeRequest = NULL;
- if (status == CELIX_SUCCESS) {
- status = jsonRpc_prepareInvokeRequest(entry->dynFunc, entry->id, args, &invokeRequest);
- //printf("Need to send following json '%s'\n", invokeRequest);
- }
-
-
- if (status == CELIX_SUCCESS) {
- char *reply = NULL;
- int rc = 0;
- //printf("sending request\n");
- celixThreadMutex_lock(&import->mutex);
- if (import->send != NULL) {
- import->send(import->sendHandle, import->endpoint, invokeRequest, &reply, &rc);
- }
- celixThreadMutex_unlock(&import->mutex);
- //printf("request sended. got reply '%s' with status %i\n", reply, rc);
-
- if (rc == 0) {
- //fjprintf("Handling reply '%s'\n", reply);
- status = jsonRpc_handleReply(entry->dynFunc, reply, args);
- }
-
- *(int *) returnVal = rc;
-
- free(invokeRequest); //Allocated by json_dumps in jsonRpc_prepareInvokeRequest
- free(reply); //Allocated by json_dumps in remoteServiceAdmin_send through curl call
- }
-
- if (status != CELIX_SUCCESS) {
- //TODO log error
- }
-}
-
-celix_status_t importRegistration_ungetService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **out) {
- celix_status_t status = CELIX_SUCCESS;
-
- assert(import != NULL);
- assert(import->proxies != NULL);
-
- pthread_mutex_lock(&import->proxiesMutex);
-
- struct service_proxy *proxy = hashMap_get(import->proxies, bundle);
- if (proxy != NULL) {
- if (*out == proxy->service) {
- proxy->count -= 1;
- } else {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (proxy->count == 0) {
- hashMap_remove(import->proxies, bundle);
- importRegistration_destroyProxy(proxy);
- }
- }
-
- pthread_mutex_unlock(&import->proxiesMutex);
-
- return status;
-}
-
-static void importRegistration_destroyProxy(struct service_proxy *proxy) {
- if (proxy != NULL) {
- if (proxy->intf != NULL) {
- dynInterface_destroy(proxy->intf);
- }
- if (proxy->service != NULL) {
- free(proxy->service);
- }
- free(proxy);
- }
-}
-
-
-celix_status_t importRegistration_close(import_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- importRegistration_stop(registration);
- return status;
-}
-
-celix_status_t importRegistration_getException(import_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- //TODO
- return status;
-}
-
-celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference) {
- celix_status_t status = CELIX_SUCCESS;
- //TODO
- return status;
-}
-
-celix_status_t importReference_getImportedEndpoint(import_reference_pt reference) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-celix_status_t importReference_getImportedService(import_reference_pt reference) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa/src/import_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/import_registration_dfi.h b/remote_services/remote_service_admin_dfi/rsa/src/import_registration_dfi.h
deleted file mode 100644
index aac4bc7..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/src/import_registration_dfi.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.
- */
-
-#ifndef CELIX_IMPORT_REGISTRATION_DFI_H
-#define CELIX_IMPORT_REGISTRATION_DFI_H
-
-#include "import_registration.h"
-#include "dfi_utils.h"
-
-#include <celix_errno.h>
-
-typedef void (*send_func_type)(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
-
-celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt description, const char *classObject, const char* serviceVersion,
- import_registration_pt *import);
-celix_status_t importRegistration_close(import_registration_pt import);
-void importRegistration_destroy(import_registration_pt import);
-
-celix_status_t importRegistration_setSendFn(import_registration_pt reg,
- send_func_type,
- void *handle);
-celix_status_t importRegistration_start(import_registration_pt import);
-celix_status_t importRegistration_stop(import_registration_pt import);
-
-celix_status_t importRegistration_getService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **service);
-celix_status_t importRegistration_ungetService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **service);
-
-#endif //CELIX_IMPORT_REGISTRATION_DFI_H
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_activator.c b/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_activator.c
deleted file mode 100644
index d4cc765..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_activator.c
+++ /dev/null
@@ -1,124 +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.
- */
-/*
- * remote_service_admin_activator.c
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <remote_service_admin.h>
-
-#include "remote_service_admin_dfi.h"
-
-#include "bundle_activator.h"
-#include "service_registration.h"
-
-#include "export_registration_dfi.h"
-#include "import_registration_dfi.h"
-
-struct activator {
- remote_service_admin_pt admin;
- remote_service_admin_service_pt adminService;
- service_registration_pt registration;
-};
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator;
-
- activator = calloc(1, sizeof(*activator));
- if (!activator) {
- status = CELIX_ENOMEM;
- } else {
- activator->admin = NULL;
- activator->registration = NULL;
-
- *userData = activator;
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
- remote_service_admin_service_pt remoteServiceAdmin = NULL;
-
- status = remoteServiceAdmin_create(context, &activator->admin);
- if (status == CELIX_SUCCESS) {
- remoteServiceAdmin = calloc(1, sizeof(*remoteServiceAdmin));
- if (!remoteServiceAdmin) {
- status = CELIX_ENOMEM;
- } else {
- remoteServiceAdmin->admin = activator->admin;
- remoteServiceAdmin->exportService = remoteServiceAdmin_exportService;
-
- remoteServiceAdmin->getExportedServices = remoteServiceAdmin_getExportedServices;
- remoteServiceAdmin->getImportedEndpoints = remoteServiceAdmin_getImportedEndpoints;
- remoteServiceAdmin->importService = remoteServiceAdmin_importService;
-
- remoteServiceAdmin->exportReference_getExportedEndpoint = exportReference_getExportedEndpoint;
- remoteServiceAdmin->exportReference_getExportedService = exportReference_getExportedService;
-
- remoteServiceAdmin->exportRegistration_close = remoteServiceAdmin_removeExportedService;
- remoteServiceAdmin->exportRegistration_getException = exportRegistration_getException;
- remoteServiceAdmin->exportRegistration_getExportReference = exportRegistration_getExportReference;
-
- remoteServiceAdmin->importReference_getImportedEndpoint = importReference_getImportedEndpoint;
- remoteServiceAdmin->importReference_getImportedService = importReference_getImportedService;
-
- remoteServiceAdmin->importRegistration_close = remoteServiceAdmin_removeImportedService;
- remoteServiceAdmin->importRegistration_getException = importRegistration_getException;
- remoteServiceAdmin->importRegistration_getImportReference = importRegistration_getImportReference;
-
- status = bundleContext_registerService(context, OSGI_RSA_REMOTE_SERVICE_ADMIN, remoteServiceAdmin, NULL, &activator->registration);
- activator->adminService = remoteServiceAdmin;
- }
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- serviceRegistration_unregister(activator->registration);
- activator->registration = NULL;
-
- remoteServiceAdmin_stop(activator->admin);
- remoteServiceAdmin_destroy(&activator->admin);
-
- free(activator->adminService);
-
- return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- free(activator);
-
- return status;
-}
-
-
[29/54] [abbrv] celix git commit: CELIX-417: Refactors CMake usage
for example embedded, dm and dm_cxx
Posted by pn...@apache.org.
CELIX-417: Refactors CMake usage for example embedded, dm and dm_cxx
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/1836cf84
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/1836cf84
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/1836cf84
Branch: refs/heads/develop
Commit: 1836cf84110367ae052f0fb5cbb3eb859d540275
Parents: 486d4f0
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Nov 24 12:27:20 2017 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Fri Nov 24 12:27:20 2017 +0100
----------------------------------------------------------------------
examples/dm_example/CMakeLists.txt | 31 +++--
examples/dm_example/api/CMakeLists.txt | 19 +++
examples/dm_example/api/include/phase1.h | 44 +++++++
examples/dm_example/api/include/phase2.h | 41 +++++++
examples/dm_example/phase1/CMakeLists.txt | 18 ++-
.../phase1/private/include/phase1_cmp.h | 43 -------
.../phase1/private/src/phase1_activator.c | 85 --------------
.../dm_example/phase1/private/src/phase1_cmp.c | 99 ----------------
.../dm_example/phase1/src/phase1_activator.c | 85 ++++++++++++++
examples/dm_example/phase1/src/phase1_cmp.c | 99 ++++++++++++++++
examples/dm_example/phase1/src/phase1_cmp.h | 43 +++++++
examples/dm_example/phase2a/CMakeLists.txt | 19 ++-
.../phase2a/private/include/phase2a_cmp.h | 46 --------
.../phase2a/private/src/phase2a_activator.c | 95 ---------------
.../phase2a/private/src/phase2a_cmp.c | 116 -------------------
.../dm_example/phase2a/src/phase2a_activator.c | 95 +++++++++++++++
examples/dm_example/phase2a/src/phase2a_cmp.c | 116 +++++++++++++++++++
examples/dm_example/phase2a/src/phase2a_cmp.h | 46 ++++++++
examples/dm_example/phase2b/CMakeLists.txt | 21 ++--
.../phase2b/private/include/phase2b_cmp.h | 46 --------
.../phase2b/private/src/phase2b_activator.c | 95 ---------------
.../phase2b/private/src/phase2b_cmp.c | 115 ------------------
.../dm_example/phase2b/src/phase2b_activator.c | 95 +++++++++++++++
examples/dm_example/phase2b/src/phase2b_cmp.c | 115 ++++++++++++++++++
examples/dm_example/phase2b/src/phase2b_cmp.h | 46 ++++++++
examples/dm_example/phase3/CMakeLists.txt | 21 ++--
.../phase3/private/include/phase3_cmp.h | 45 -------
.../phase3/private/src/phase3_activator.c | 84 --------------
.../dm_example/phase3/private/src/phase3_cmp.c | 116 -------------------
.../dm_example/phase3/src/phase3_activator.c | 84 ++++++++++++++
examples/dm_example/phase3/src/phase3_cmp.c | 116 +++++++++++++++++++
examples/dm_example/phase3/src/phase3_cmp.h | 45 +++++++
examples/dm_example/services/phase1.h | 44 -------
examples/dm_example/services/phase2.h | 41 -------
examples/dm_example_cxx/CMakeLists.txt | 32 +++--
examples/dm_example_cxx/api/CMakeLists.txt | 19 +++
examples/dm_example_cxx/api/IName.h | 39 -------
examples/dm_example_cxx/api/IPhase1.h | 33 ------
examples/dm_example_cxx/api/IPhase2.h | 33 ------
examples/dm_example_cxx/api/include/IName.h | 39 +++++++
examples/dm_example_cxx/api/include/IPhase1.h | 33 ++++++
examples/dm_example_cxx/api/include/IPhase2.h | 33 ++++++
examples/dm_example_cxx/phase1/CMakeLists.txt | 17 +--
.../phase1/include/Phase1Activator.h | 36 ------
.../dm_example_cxx/phase1/include/Phase1Cmp.h | 44 -------
.../dm_example_cxx/phase1/src/Phase1Activator.h | 36 ++++++
examples/dm_example_cxx/phase1/src/Phase1Cmp.h | 44 +++++++
examples/dm_example_cxx/phase2/CMakeLists.txt | 51 ++++++++
.../phase2/include/Phase2Activator.h | 34 ------
.../dm_example_cxx/phase2/include/Phase2Cmp.h | 56 ---------
.../dm_example_cxx/phase2/src/Phase2Activator.h | 34 ++++++
examples/dm_example_cxx/phase2/src/Phase2Cmp.h | 56 +++++++++
.../phase2/src/Phase2aActivator.cc | 57 +++++++++
.../dm_example_cxx/phase2/src/Phase2aCmp.cc | 45 +++++++
.../phase2/src/Phase2bActivator.cc | 50 ++++++++
.../dm_example_cxx/phase2/src/Phase2bCmp.cc | 45 +++++++
examples/dm_example_cxx/phase2a/CMakeLists.txt | 41 -------
.../phase2a/src/Phase2aActivator.cc | 57 ---------
.../dm_example_cxx/phase2a/src/Phase2aCmp.cc | 45 -------
examples/dm_example_cxx/phase2b/CMakeLists.txt | 39 -------
.../phase2b/src/Phase2bActivator.cc | 50 --------
.../dm_example_cxx/phase2b/src/Phase2bCmp.cc | 45 -------
examples/dm_example_cxx/phase3/CMakeLists.txt | 17 +--
.../phase3/include/Phase3Activator.h | 33 ------
.../phase3/include/Phase3BaseActivator.h | 35 ------
.../dm_example_cxx/phase3/include/Phase3Cmp.h | 50 --------
.../dm_example_cxx/phase3/src/Phase3Activator.h | 33 ++++++
.../phase3/src/Phase3BaseActivator.h | 35 ++++++
examples/dm_example_cxx/phase3/src/Phase3Cmp.h | 50 ++++++++
.../phase3_locking/CMakeLists.txt | 16 +--
.../include/Phase3LockingActivator.h | 33 ------
.../phase3_locking/include/Phase3LockingCmp.h | 50 --------
.../phase3_locking/src/Phase3LockingActivator.h | 33 ++++++
.../phase3_locking/src/Phase3LockingCmp.h | 50 ++++++++
examples/embedding/CMakeLists.txt | 1 -
75 files changed, 1909 insertions(+), 1939 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example/CMakeLists.txt b/examples/dm_example/CMakeLists.txt
index 9a9e69b..2cef7ec 100644
--- a/examples/dm_example/CMakeLists.txt
+++ b/examples/dm_example/CMakeLists.txt
@@ -15,11 +15,8 @@
# specific language governing permissions and limitations
# under the License.
if (BUILD_DEPENDENCY_MANAGER)
- include_directories(
- ${PROJECT_SOURCE_DIR}/dependency_manager/public/include
- ${PROJECT_SOURCE_DIR}/utils/public/include
- services
- )
+
+ add_subdirectory(api)
add_subdirectory(phase1)
add_subdirectory(phase2a)
@@ -32,11 +29,11 @@ if (BUILD_DEPENDENCY_MANAGER)
BUNDLES
Celix::shell
Celix::shell_tui
- dm_shell
- phase1
- phase2a
- phase2b
- phase3
+ Celix::dm_shell
+ dm_example_phase1
+ dm_example_phase2a
+ dm_example_phase2b
+ dm_example_phase3
PROPERTIES
LOGHELPER_ENABLE_STDOUT_FALLBACK=true
)
@@ -53,13 +50,13 @@ if (BUILD_DEPENDENCY_MANAGER)
FROM dmbase
GROUP examples
BUNDLES
- ${CELIX_SHELL_BUNDLE}
- ${CELIX_SHELL_TUI_BUNDLE}
- dm_shell
- phase1
- phase2a
- phase2b
- phase3
+ Celix::shell
+ Celix::shell_tui
+ Celix::dm_shell
+ dm_example_phase1
+ dm_example_phase2a
+ dm_example_phase2b
+ dm_example_phase3
PROPERTIES
LOGHELPER_ENABLE_STDOUT_FALLBACK=true
)
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/api/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example/api/CMakeLists.txt b/examples/dm_example/api/CMakeLists.txt
new file mode 100644
index 0000000..900c8fb
--- /dev/null
+++ b/examples/dm_example/api/CMakeLists.txt
@@ -0,0 +1,19 @@
+# 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.
+
+add_library(dm_example_api INTERFACE)
+target_include_directories(dm_example_api INTERFACE include)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/api/include/phase1.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/api/include/phase1.h b/examples/dm_example/api/include/phase1.h
new file mode 100644
index 0000000..04e9da7
--- /dev/null
+++ b/examples/dm_example/api/include/phase1.h
@@ -0,0 +1,44 @@
+/**
+ *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.
+ */
+/*
+ * publisher.h
+ *
+ * \date Aug 23, 2010
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PHASE1_H_
+#define PHASE1_H_
+
+#define PHASE1_NAME "PHASE1"
+#define PHASE1_VERSION "1.2.2.0"
+#define PHASE1_RANGE_ALL "[1.2.2.0,4.5.6.x)"
+#define PHASE1_RANGE_EXACT "[1.2.2.0,1.2.2.0]"
+
+
+
+struct phase1_struct {
+ void *handle;
+ int (*getData)(void *handle, unsigned int *data);
+};
+
+typedef struct phase1_struct phase1_t;
+
+#endif /* PHASE1_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/api/include/phase2.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/api/include/phase2.h b/examples/dm_example/api/include/phase2.h
new file mode 100644
index 0000000..2f4df86
--- /dev/null
+++ b/examples/dm_example/api/include/phase2.h
@@ -0,0 +1,41 @@
+/**
+ *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.
+ */
+/*
+ * publisher.h
+ *
+ * \date Aug 23, 2010
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PHASE2_H
+#define PHASE2_H
+
+#define PHASE2_NAME "PHASE2"
+#define PHASE2_VERSION "1.0.0.0"
+
+struct phase2_struct {
+ void *handle;
+ void (*getData)(void *handle, double *data);
+};
+
+typedef struct phase2_struct phase2_t;
+
+
+#endif /* PHASE2_H */
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase1/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase1/CMakeLists.txt b/examples/dm_example/phase1/CMakeLists.txt
index 6299688..5263bab 100644
--- a/examples/dm_example/phase1/CMakeLists.txt
+++ b/examples/dm_example/phase1/CMakeLists.txt
@@ -15,26 +15,24 @@
# specific language governing permissions and limitations
# under the License.
-include_directories(
- private/include
- ../services
-)
-add_bundle(phase1
+add_bundle(dm_example_phase1
SYMBOLIC_NAME phase1
VERSION 0.0.1
SOURCES
- private/src/phase1_activator
- private/src/phase1_cmp.c
+ src/phase1_activator
+ src/phase1_cmp.c
)
+target_include_directories(dm_example_phase1 PRIVATE src)
+target_link_libraries(dm_example_phase1 PRIVATE dm_example_api)
IF(APPLE)
- target_link_libraries(phase1 PRIVATE -Wl,-all_load dependency_manager_static)
+ target_link_libraries(dm_example_phase1 PRIVATE -Wl,-all_load Celix::dependency_manager_static)
else()
if(ENABLE_ADDRESS_SANITIZER)
#With asan there can be undefined symbols
- target_link_libraries(phase1 PRIVATE -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive)
+ target_link_libraries(dm_example_phase1 PRIVATE -Wl,--whole-archive Celix::dependency_manager_static -Wl,--no-whole-archive)
else()
- target_link_libraries(phase1 PRIVATE -Wl,--no-undefined -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive)
+ target_link_libraries(dm_example_phase1 PRIVATE -Wl,--no-undefined -Wl,--whole-archive Celix::dependency_manager_static -Wl,--no-whole-archive)
endif()
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase1/private/include/phase1_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase1/private/include/phase1_cmp.h b/examples/dm_example/phase1/private/include/phase1_cmp.h
deleted file mode 100644
index 5715f6e..0000000
--- a/examples/dm_example/phase1/private/include/phase1_cmp.h
+++ /dev/null
@@ -1,43 +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.
- */
-/*
- * publisher.h
- *
- * \date Oct 29, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PHASE1_CMP_H
-#define PHASE1_CMP_H
-
-
-typedef struct phase1_cmp_struct phase1_cmp_t;
-
-phase1_cmp_t *phase1_create(void);
-int phase1_init(phase1_cmp_t *cmp);
-int phase1_start(phase1_cmp_t *cmp);
-int phase1_stop(phase1_cmp_t *cmp);
-int phase1_deinit(phase1_cmp_t *cmp);
-void phase1_destroy(phase1_cmp_t *cmp);
-
-int phase1_getData(phase1_cmp_t *cmp, unsigned int *data);
-
-
-#endif //PHASE1_CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase1/private/src/phase1_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase1/private/src/phase1_activator.c b/examples/dm_example/phase1/private/src/phase1_activator.c
deleted file mode 100644
index 783e642..0000000
--- a/examples/dm_example/phase1/private/src/phase1_activator.c
+++ /dev/null
@@ -1,85 +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.
- */
-/*
- * activator.c
- *
- * \date Oct 29, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <phase1_cmp.h>
-
-#include "bundle_activator.h"
-#include "dm_activator.h"
-
-#include "phase1.h"
-
-struct phase1_activator_struct {
- phase1_cmp_t *phase1Cmp;
- phase1_t phase1Serv;
-};
-
-celix_status_t dm_create(bundle_context_pt context, void **userData) {
- printf("PHASE1: dm_create\n");
- *userData = calloc(1, sizeof(struct phase1_activator_struct));
- return *userData != NULL ? CELIX_SUCCESS : CELIX_ENOMEM;
-}
-
-celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
- printf("PHASE1: dm_init\n");
- celix_status_t status = CELIX_SUCCESS;
-
-
- struct phase1_activator_struct *act = (struct phase1_activator_struct *)userData;
-
- act->phase1Cmp = phase1_create();
- if (act->phase1Cmp != NULL) {
-
- act->phase1Serv.handle = act->phase1Cmp;
- act->phase1Serv.getData = (void *)phase1_getData;
-
- properties_pt props = properties_create();
- properties_set(props, "id", "phase1");
-
- dm_component_pt cmp;
- component_create(context, "PHASE1_PROCESSING_COMPONENT", &cmp);
- component_setImplementation(cmp, act->phase1Cmp);
- component_setCallbacksSafe(cmp, phase1_cmp_t *, phase1_init, phase1_start, phase1_stop, phase1_deinit);
- component_addInterface(cmp, PHASE1_NAME, PHASE1_VERSION, &act->phase1Serv, props);
-
- dependencyManager_add(manager, cmp);
- } else {
- status = CELIX_ENOMEM;
- }
-
- return status;
-}
-
-celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
- printf("PHASE1: dm-destroy\n");
-
- struct phase1_activator_struct *act = (struct phase1_activator_struct *)userData;
- if (act->phase1Cmp != NULL) {
- phase1_destroy(act->phase1Cmp);
- }
- free(act);
-
- return CELIX_SUCCESS;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase1/private/src/phase1_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase1/private/src/phase1_cmp.c b/examples/dm_example/phase1/private/src/phase1_cmp.c
deleted file mode 100644
index 75de182..0000000
--- a/examples/dm_example/phase1/private/src/phase1_cmp.c
+++ /dev/null
@@ -1,99 +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.
- */
-/*
- * publisher.c
- *
- * \date Oct 29, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <signal.h>
-
-#include "celix_threads.h"
-#include "phase1_cmp.h"
-
-#define SLEEPTIME 1000
-
-struct phase1_cmp_struct {
- celix_thread_t thread;
- bool running;
- unsigned int counter;
-};
-
-static void *phase1_thread(void *data);
-
-phase1_cmp_t *phase1_create(void) {
- phase1_cmp_t *cmp = calloc(1, sizeof(*cmp));
- if (cmp != NULL) {
- cmp->counter = 0;
- cmp->running = false;
- }
- return cmp;
-}
-
-int phase1_init(phase1_cmp_t *cmp) {
- printf("init phase1\n");
- return 0;
-}
-
-int phase1_start(phase1_cmp_t *cmp) {
- printf("start phase1\n");
- cmp->running = true;
- celixThread_create(&cmp->thread, NULL, phase1_thread, cmp);
- return 0;
-}
-
-int phase1_stop(phase1_cmp_t *cmp) {
- printf("stop phase1\n");
- cmp->running = false;
- celixThread_kill(cmp->thread, SIGUSR1);
- celixThread_join(cmp->thread, NULL);
- return 0;
-}
-
-int phase1_deinit(phase1_cmp_t *cmp) {
- printf("deinit phase1\n");
- return 0;
-}
-
-void phase1_destroy(phase1_cmp_t *cmp) {
- free(cmp);
- printf("destroy phase1\n");
-}
-
-static void *phase1_thread(void *data) {
- phase1_cmp_t *cmp = data;
-
- while (cmp->running) {
- cmp->counter += 1;
- usleep(SLEEPTIME);
- }
-
- celixThread_exit(NULL);
- return NULL;
-}
-
-int phase1_getData(phase1_cmp_t *cmp, unsigned int *data) {
- *data = cmp->counter;
- return 0;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase1/src/phase1_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase1/src/phase1_activator.c b/examples/dm_example/phase1/src/phase1_activator.c
new file mode 100644
index 0000000..783e642
--- /dev/null
+++ b/examples/dm_example/phase1/src/phase1_activator.c
@@ -0,0 +1,85 @@
+/**
+ *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.
+ */
+/*
+ * activator.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <phase1_cmp.h>
+
+#include "bundle_activator.h"
+#include "dm_activator.h"
+
+#include "phase1.h"
+
+struct phase1_activator_struct {
+ phase1_cmp_t *phase1Cmp;
+ phase1_t phase1Serv;
+};
+
+celix_status_t dm_create(bundle_context_pt context, void **userData) {
+ printf("PHASE1: dm_create\n");
+ *userData = calloc(1, sizeof(struct phase1_activator_struct));
+ return *userData != NULL ? CELIX_SUCCESS : CELIX_ENOMEM;
+}
+
+celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("PHASE1: dm_init\n");
+ celix_status_t status = CELIX_SUCCESS;
+
+
+ struct phase1_activator_struct *act = (struct phase1_activator_struct *)userData;
+
+ act->phase1Cmp = phase1_create();
+ if (act->phase1Cmp != NULL) {
+
+ act->phase1Serv.handle = act->phase1Cmp;
+ act->phase1Serv.getData = (void *)phase1_getData;
+
+ properties_pt props = properties_create();
+ properties_set(props, "id", "phase1");
+
+ dm_component_pt cmp;
+ component_create(context, "PHASE1_PROCESSING_COMPONENT", &cmp);
+ component_setImplementation(cmp, act->phase1Cmp);
+ component_setCallbacksSafe(cmp, phase1_cmp_t *, phase1_init, phase1_start, phase1_stop, phase1_deinit);
+ component_addInterface(cmp, PHASE1_NAME, PHASE1_VERSION, &act->phase1Serv, props);
+
+ dependencyManager_add(manager, cmp);
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ return status;
+}
+
+celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("PHASE1: dm-destroy\n");
+
+ struct phase1_activator_struct *act = (struct phase1_activator_struct *)userData;
+ if (act->phase1Cmp != NULL) {
+ phase1_destroy(act->phase1Cmp);
+ }
+ free(act);
+
+ return CELIX_SUCCESS;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase1/src/phase1_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase1/src/phase1_cmp.c b/examples/dm_example/phase1/src/phase1_cmp.c
new file mode 100644
index 0000000..75de182
--- /dev/null
+++ b/examples/dm_example/phase1/src/phase1_cmp.c
@@ -0,0 +1,99 @@
+/**
+ *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.
+ */
+/*
+ * publisher.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+
+#include "celix_threads.h"
+#include "phase1_cmp.h"
+
+#define SLEEPTIME 1000
+
+struct phase1_cmp_struct {
+ celix_thread_t thread;
+ bool running;
+ unsigned int counter;
+};
+
+static void *phase1_thread(void *data);
+
+phase1_cmp_t *phase1_create(void) {
+ phase1_cmp_t *cmp = calloc(1, sizeof(*cmp));
+ if (cmp != NULL) {
+ cmp->counter = 0;
+ cmp->running = false;
+ }
+ return cmp;
+}
+
+int phase1_init(phase1_cmp_t *cmp) {
+ printf("init phase1\n");
+ return 0;
+}
+
+int phase1_start(phase1_cmp_t *cmp) {
+ printf("start phase1\n");
+ cmp->running = true;
+ celixThread_create(&cmp->thread, NULL, phase1_thread, cmp);
+ return 0;
+}
+
+int phase1_stop(phase1_cmp_t *cmp) {
+ printf("stop phase1\n");
+ cmp->running = false;
+ celixThread_kill(cmp->thread, SIGUSR1);
+ celixThread_join(cmp->thread, NULL);
+ return 0;
+}
+
+int phase1_deinit(phase1_cmp_t *cmp) {
+ printf("deinit phase1\n");
+ return 0;
+}
+
+void phase1_destroy(phase1_cmp_t *cmp) {
+ free(cmp);
+ printf("destroy phase1\n");
+}
+
+static void *phase1_thread(void *data) {
+ phase1_cmp_t *cmp = data;
+
+ while (cmp->running) {
+ cmp->counter += 1;
+ usleep(SLEEPTIME);
+ }
+
+ celixThread_exit(NULL);
+ return NULL;
+}
+
+int phase1_getData(phase1_cmp_t *cmp, unsigned int *data) {
+ *data = cmp->counter;
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase1/src/phase1_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase1/src/phase1_cmp.h b/examples/dm_example/phase1/src/phase1_cmp.h
new file mode 100644
index 0000000..5715f6e
--- /dev/null
+++ b/examples/dm_example/phase1/src/phase1_cmp.h
@@ -0,0 +1,43 @@
+/**
+ *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.
+ */
+/*
+ * publisher.h
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PHASE1_CMP_H
+#define PHASE1_CMP_H
+
+
+typedef struct phase1_cmp_struct phase1_cmp_t;
+
+phase1_cmp_t *phase1_create(void);
+int phase1_init(phase1_cmp_t *cmp);
+int phase1_start(phase1_cmp_t *cmp);
+int phase1_stop(phase1_cmp_t *cmp);
+int phase1_deinit(phase1_cmp_t *cmp);
+void phase1_destroy(phase1_cmp_t *cmp);
+
+int phase1_getData(phase1_cmp_t *cmp, unsigned int *data);
+
+
+#endif //PHASE1_CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2a/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2a/CMakeLists.txt b/examples/dm_example/phase2a/CMakeLists.txt
index d8f9165..cda4971 100644
--- a/examples/dm_example/phase2a/CMakeLists.txt
+++ b/examples/dm_example/phase2a/CMakeLists.txt
@@ -15,26 +15,23 @@
# specific language governing permissions and limitations
# under the License.
-include_directories(
- private/include
- ../services
-)
-
-add_bundle(phase2a
+add_bundle(dm_example_phase2a
SYMBOLIC_NAME phase2a
VERSION 0.0.1
SOURCES
- private/src/phase2a_activator
- private/src/phase2a_cmp
+ src/phase2a_activator
+ src/phase2a_cmp
)
+target_include_directories(dm_example_phase2a PRIVATE src)
+target_link_libraries(dm_example_phase2a PRIVATE dm_example_api)
IF(APPLE)
- target_link_libraries(phase2a PRIVATE -Wl,-all_load dependency_manager_static)
+ target_link_libraries(dm_example_phase2a PRIVATE -Wl,-all_load Celix::dependency_manager_static)
else()
if(ENABLE_ADDRESS_SANITIZER)
#With asan there can be undefined symbols
- target_link_libraries(phase2a PRIVATE -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive)
+ target_link_libraries(dm_example_phase2a PRIVATE -Wl,--whole-archive Celix::dependency_manager_static -Wl,--no-whole-archive)
else()
- target_link_libraries(phase2a PRIVATE -Wl,--no-undefined -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive)
+ target_link_libraries(dm_example_phase2a PRIVATE -Wl,--no-undefined -Wl,--whole-archive Celix::dependency_manager_static -Wl,--no-whole-archive)
endif()
ENDIF()
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2a/private/include/phase2a_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2a/private/include/phase2a_cmp.h b/examples/dm_example/phase2a/private/include/phase2a_cmp.h
deleted file mode 100644
index 060b23d..0000000
--- a/examples/dm_example/phase2a/private/include/phase2a_cmp.h
+++ /dev/null
@@ -1,46 +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.
- */
-/*
- * publisher.h
- *
- * \date Oct 29, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PHASE2A_CMP_H
-#define PHASE2A_CMP_H
-
-#include "phase1.h"
-
-typedef struct phase2a_cmp_struct phase2a_cmp_t;
-
-phase2a_cmp_t *phase2a_create(void);
-int phase2a_init(phase2a_cmp_t *cmp);
-int phase2a_start(phase2a_cmp_t *cmp);
-int phase2a_stop(phase2a_cmp_t *cmp);
-int phase2a_deinit(phase2a_cmp_t *cmp);
-void phase2a_destroy(phase2a_cmp_t *cmp);
-
-int phase2a_setPhase1(phase2a_cmp_t *cmp, const phase1_t* phase1);
-
-int phase2a_getData(phase2a_cmp_t *cmp, double *data);
-
-
-#endif //PHASE2A_CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2a/private/src/phase2a_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2a/private/src/phase2a_activator.c b/examples/dm_example/phase2a/private/src/phase2a_activator.c
deleted file mode 100644
index 6416c68..0000000
--- a/examples/dm_example/phase2a/private/src/phase2a_activator.c
+++ /dev/null
@@ -1,95 +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.
- */
-/*
- * activator.c
- *
- * \date Oct 29, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <phase2a_cmp.h>
-
-#include "bundle_activator.h"
-#include "dm_activator.h"
-
-#include "phase1.h"
-#include "phase2.h"
-#include "phase2a_cmp.h"
-
-struct phase2a_activator_struct {
- phase2a_cmp_t *phase2aCmp;
- phase2_t phase2Serv;
-};
-
-celix_status_t dm_create(bundle_context_pt context, void **userData) {
- printf("phase2a: dm_create\n");
- *userData = calloc(1, sizeof(struct phase2a_activator_struct));
- return *userData != NULL ? CELIX_SUCCESS : CELIX_ENOMEM;
-}
-
-celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
- printf("phase2a: dm_init\n");
- celix_status_t status = CELIX_SUCCESS;
-
- struct phase2a_activator_struct *act = (struct phase2a_activator_struct *)userData;
-
- act->phase2aCmp = phase2a_create();
- if (act->phase2aCmp != NULL) {
-
- act->phase2Serv.handle = act->phase2aCmp;
- act->phase2Serv.getData = (void *)phase2a_getData;
-
- properties_pt props = properties_create();
- properties_set(props, "id", "phase2a");
-
- dm_component_pt cmp;
- component_create(context, "PHASE2A_PROCESSING_COMPONENT", &cmp);
- component_setImplementation(cmp, act->phase2aCmp);
- component_setCallbacksSafe(cmp, phase2a_cmp_t *, phase2a_init, phase2a_start, phase2a_stop, phase2a_deinit);
- component_addInterface(cmp, PHASE2_NAME, PHASE2_VERSION, &act->phase2Serv, props);
-
-
- dm_service_dependency_pt dep;
- serviceDependency_create(&dep);
- serviceDependency_setService(dep, PHASE1_NAME, PHASE1_RANGE_ALL, NULL);
- serviceDependency_setCallbacksSafe(dep, phase2a_cmp_t*, const phase1_t*, phase2a_setPhase1, NULL, NULL, NULL, NULL);
- serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_LOCKING);
- serviceDependency_setRequired(dep, true);
- component_addServiceDependency(cmp, dep);
-
- dependencyManager_add(manager, cmp);
- } else {
- status = CELIX_ENOMEM;
- }
-
- return status;
-}
-
-celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
- printf("phase2a: dm-destroy\n");
-
- struct phase2a_activator_struct *act = (struct phase2a_activator_struct *)userData;
- if (act->phase2aCmp != NULL) {
- phase2a_destroy(act->phase2aCmp);
- }
- free(act);
-
- return CELIX_SUCCESS;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2a/private/src/phase2a_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2a/private/src/phase2a_cmp.c b/examples/dm_example/phase2a/private/src/phase2a_cmp.c
deleted file mode 100644
index d115b69..0000000
--- a/examples/dm_example/phase2a/private/src/phase2a_cmp.c
+++ /dev/null
@@ -1,116 +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.
- */
-/*
- * publisher.c
- *
- * \date Oct 29, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-
-#include "celix_threads.h"
-#include "phase2a_cmp.h"
-
-#define SLEEPTIME 2000000
-
-struct phase2a_cmp_struct {
- celix_thread_t thread;
- bool running;
- double currentValue;
- celix_thread_mutex_t mutex;
- const phase1_t* phase1Serv;
-};
-
-static void *phase2a_thread(void *data);
-
-phase2a_cmp_t *phase2a_create(void) {
- phase2a_cmp_t *cmp = calloc(1, sizeof(*cmp));
- if (cmp != NULL) {
- cmp->currentValue = 0.0;
- cmp->running = false;
- celixThreadMutex_create(&cmp->mutex, NULL);
- }
- return cmp;
-}
-
-int phase2a_init(phase2a_cmp_t *cmp) {
- printf("init phase2a\n");
- return 0;
-}
-
-int phase2a_start(phase2a_cmp_t *cmp) {
- printf("start phase2a\n");
- cmp->running = true;
- celixThread_create(&cmp->thread, NULL, phase2a_thread, cmp);
- return 0;
-}
-
-int phase2a_stop(phase2a_cmp_t *cmp) {
- printf("stop phase2a\n");
- cmp->running = false;
- celixThread_kill(cmp->thread, SIGUSR1);
- celixThread_join(cmp->thread, NULL);
- return 0;
-}
-
-int phase2a_deinit(phase2a_cmp_t *cmp) {
- printf("deinit phase2a\n");
- return 0;
-}
-
-void phase2a_destroy(phase2a_cmp_t *cmp) {
- celixThreadMutex_destroy(&cmp->mutex);
- free(cmp);
- printf("destroy phase2a\n");
-}
-
-int phase2a_setPhase1(phase2a_cmp_t *cmp, const phase1_t* phase1) {
- printf("phase2a_setPhase1 called!\n\n");
- celixThreadMutex_lock(&cmp->mutex);
- cmp->phase1Serv = phase1;
- celixThreadMutex_unlock(&cmp->mutex);
- return 0;
-}
-
-static void *phase2a_thread(void *data) {
- phase2a_cmp_t *cmp = data;
- unsigned int counter;
-
- while (cmp->running) {
- celixThreadMutex_lock(&cmp->mutex);
- if (cmp->phase1Serv != NULL) {
- cmp->phase1Serv->getData(cmp->phase1Serv->handle, &counter);
- cmp->currentValue = 1.0 / counter;
- }
- celixThreadMutex_unlock(&cmp->mutex);
- usleep(SLEEPTIME);
- }
-
- celixThread_exit(NULL);
- return NULL;
-}
-
-int phase2a_getData(phase2a_cmp_t *cmp, double *data) {
- *data = cmp->currentValue;
- return 0;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2a/src/phase2a_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2a/src/phase2a_activator.c b/examples/dm_example/phase2a/src/phase2a_activator.c
new file mode 100644
index 0000000..6416c68
--- /dev/null
+++ b/examples/dm_example/phase2a/src/phase2a_activator.c
@@ -0,0 +1,95 @@
+/**
+ *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.
+ */
+/*
+ * activator.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <phase2a_cmp.h>
+
+#include "bundle_activator.h"
+#include "dm_activator.h"
+
+#include "phase1.h"
+#include "phase2.h"
+#include "phase2a_cmp.h"
+
+struct phase2a_activator_struct {
+ phase2a_cmp_t *phase2aCmp;
+ phase2_t phase2Serv;
+};
+
+celix_status_t dm_create(bundle_context_pt context, void **userData) {
+ printf("phase2a: dm_create\n");
+ *userData = calloc(1, sizeof(struct phase2a_activator_struct));
+ return *userData != NULL ? CELIX_SUCCESS : CELIX_ENOMEM;
+}
+
+celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("phase2a: dm_init\n");
+ celix_status_t status = CELIX_SUCCESS;
+
+ struct phase2a_activator_struct *act = (struct phase2a_activator_struct *)userData;
+
+ act->phase2aCmp = phase2a_create();
+ if (act->phase2aCmp != NULL) {
+
+ act->phase2Serv.handle = act->phase2aCmp;
+ act->phase2Serv.getData = (void *)phase2a_getData;
+
+ properties_pt props = properties_create();
+ properties_set(props, "id", "phase2a");
+
+ dm_component_pt cmp;
+ component_create(context, "PHASE2A_PROCESSING_COMPONENT", &cmp);
+ component_setImplementation(cmp, act->phase2aCmp);
+ component_setCallbacksSafe(cmp, phase2a_cmp_t *, phase2a_init, phase2a_start, phase2a_stop, phase2a_deinit);
+ component_addInterface(cmp, PHASE2_NAME, PHASE2_VERSION, &act->phase2Serv, props);
+
+
+ dm_service_dependency_pt dep;
+ serviceDependency_create(&dep);
+ serviceDependency_setService(dep, PHASE1_NAME, PHASE1_RANGE_ALL, NULL);
+ serviceDependency_setCallbacksSafe(dep, phase2a_cmp_t*, const phase1_t*, phase2a_setPhase1, NULL, NULL, NULL, NULL);
+ serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_LOCKING);
+ serviceDependency_setRequired(dep, true);
+ component_addServiceDependency(cmp, dep);
+
+ dependencyManager_add(manager, cmp);
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ return status;
+}
+
+celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("phase2a: dm-destroy\n");
+
+ struct phase2a_activator_struct *act = (struct phase2a_activator_struct *)userData;
+ if (act->phase2aCmp != NULL) {
+ phase2a_destroy(act->phase2aCmp);
+ }
+ free(act);
+
+ return CELIX_SUCCESS;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2a/src/phase2a_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2a/src/phase2a_cmp.c b/examples/dm_example/phase2a/src/phase2a_cmp.c
new file mode 100644
index 0000000..d115b69
--- /dev/null
+++ b/examples/dm_example/phase2a/src/phase2a_cmp.c
@@ -0,0 +1,116 @@
+/**
+ *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.
+ */
+/*
+ * publisher.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include "celix_threads.h"
+#include "phase2a_cmp.h"
+
+#define SLEEPTIME 2000000
+
+struct phase2a_cmp_struct {
+ celix_thread_t thread;
+ bool running;
+ double currentValue;
+ celix_thread_mutex_t mutex;
+ const phase1_t* phase1Serv;
+};
+
+static void *phase2a_thread(void *data);
+
+phase2a_cmp_t *phase2a_create(void) {
+ phase2a_cmp_t *cmp = calloc(1, sizeof(*cmp));
+ if (cmp != NULL) {
+ cmp->currentValue = 0.0;
+ cmp->running = false;
+ celixThreadMutex_create(&cmp->mutex, NULL);
+ }
+ return cmp;
+}
+
+int phase2a_init(phase2a_cmp_t *cmp) {
+ printf("init phase2a\n");
+ return 0;
+}
+
+int phase2a_start(phase2a_cmp_t *cmp) {
+ printf("start phase2a\n");
+ cmp->running = true;
+ celixThread_create(&cmp->thread, NULL, phase2a_thread, cmp);
+ return 0;
+}
+
+int phase2a_stop(phase2a_cmp_t *cmp) {
+ printf("stop phase2a\n");
+ cmp->running = false;
+ celixThread_kill(cmp->thread, SIGUSR1);
+ celixThread_join(cmp->thread, NULL);
+ return 0;
+}
+
+int phase2a_deinit(phase2a_cmp_t *cmp) {
+ printf("deinit phase2a\n");
+ return 0;
+}
+
+void phase2a_destroy(phase2a_cmp_t *cmp) {
+ celixThreadMutex_destroy(&cmp->mutex);
+ free(cmp);
+ printf("destroy phase2a\n");
+}
+
+int phase2a_setPhase1(phase2a_cmp_t *cmp, const phase1_t* phase1) {
+ printf("phase2a_setPhase1 called!\n\n");
+ celixThreadMutex_lock(&cmp->mutex);
+ cmp->phase1Serv = phase1;
+ celixThreadMutex_unlock(&cmp->mutex);
+ return 0;
+}
+
+static void *phase2a_thread(void *data) {
+ phase2a_cmp_t *cmp = data;
+ unsigned int counter;
+
+ while (cmp->running) {
+ celixThreadMutex_lock(&cmp->mutex);
+ if (cmp->phase1Serv != NULL) {
+ cmp->phase1Serv->getData(cmp->phase1Serv->handle, &counter);
+ cmp->currentValue = 1.0 / counter;
+ }
+ celixThreadMutex_unlock(&cmp->mutex);
+ usleep(SLEEPTIME);
+ }
+
+ celixThread_exit(NULL);
+ return NULL;
+}
+
+int phase2a_getData(phase2a_cmp_t *cmp, double *data) {
+ *data = cmp->currentValue;
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2a/src/phase2a_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2a/src/phase2a_cmp.h b/examples/dm_example/phase2a/src/phase2a_cmp.h
new file mode 100644
index 0000000..060b23d
--- /dev/null
+++ b/examples/dm_example/phase2a/src/phase2a_cmp.h
@@ -0,0 +1,46 @@
+/**
+ *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.
+ */
+/*
+ * publisher.h
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PHASE2A_CMP_H
+#define PHASE2A_CMP_H
+
+#include "phase1.h"
+
+typedef struct phase2a_cmp_struct phase2a_cmp_t;
+
+phase2a_cmp_t *phase2a_create(void);
+int phase2a_init(phase2a_cmp_t *cmp);
+int phase2a_start(phase2a_cmp_t *cmp);
+int phase2a_stop(phase2a_cmp_t *cmp);
+int phase2a_deinit(phase2a_cmp_t *cmp);
+void phase2a_destroy(phase2a_cmp_t *cmp);
+
+int phase2a_setPhase1(phase2a_cmp_t *cmp, const phase1_t* phase1);
+
+int phase2a_getData(phase2a_cmp_t *cmp, double *data);
+
+
+#endif //PHASE2A_CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2b/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2b/CMakeLists.txt b/examples/dm_example/phase2b/CMakeLists.txt
index a65b422..9afb6c7 100644
--- a/examples/dm_example/phase2b/CMakeLists.txt
+++ b/examples/dm_example/phase2b/CMakeLists.txt
@@ -15,28 +15,23 @@
# specific language governing permissions and limitations
# under the License.
-include_directories(
- private/include
- ../services
-)
-
-add_bundle(phase2b
+add_bundle(dm_example_phase2b
SYMBOLIC_NAME phase2b
VERSION 0.0.1
SOURCES
- private/src/phase2b_activator
- private/src/phase2b_cmp
+ src/phase2b_activator
+ src/phase2b_cmp
)
-
-#bundle_private_libs(phase2b dependency_manager)
+target_include_directories(dm_example_phase2b PRIVATE src)
+target_link_libraries(dm_example_phase2b PRIVATE dm_example_api)
IF(APPLE)
- target_link_libraries(phase2b PRIVATE -Wl,-all_load dependency_manager_static)
+ target_link_libraries(dm_example_phase2b PRIVATE -Wl,-all_load Celix::dependency_manager_static)
else()
if(ENABLE_ADDRESS_SANITIZER)
#With asan there can be undefined symbols
- target_link_libraries(phase2b PRIVATE -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive)
+ target_link_libraries(dm_example_phase2b PRIVATE -Wl,--whole-archive Celix::dependency_manager_static -Wl,--no-whole-archive)
else()
- target_link_libraries(phase2b PRIVATE -Wl,--no-undefined -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive)
+ target_link_libraries(dm_example_phase2b PRIVATE -Wl,--no-undefined -Wl,--whole-archive Celix::dependency_manager_static -Wl,--no-whole-archive)
endif()
ENDIF()
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2b/private/include/phase2b_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2b/private/include/phase2b_cmp.h b/examples/dm_example/phase2b/private/include/phase2b_cmp.h
deleted file mode 100644
index 7ae0358..0000000
--- a/examples/dm_example/phase2b/private/include/phase2b_cmp.h
+++ /dev/null
@@ -1,46 +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.
- */
-/*
- * publisher.h
- *
- * \date Oct 29, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PHASE2B_CMP_H
-#define PHASE2B_CMP_H
-
-#include "phase1.h"
-
-typedef struct phase2b_cmp_struct phase2b_cmp_t;
-
-phase2b_cmp_t *phase2b_create(void);
-int phase2b_init(phase2b_cmp_t *cmp);
-int phase2b_start(phase2b_cmp_t *cmp);
-int phase2b_stop(phase2b_cmp_t *cmp);
-int phase2b_deinit(phase2b_cmp_t *cmp);
-void phase2b_destroy(phase2b_cmp_t *cmp);
-
-int phase2b_setPhase1(phase2b_cmp_t *cmp, const phase1_t* phase1);
-
-int phase2b_getData(phase2b_cmp_t *cmp, double *data);
-
-
-#endif //PHASE2B_CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2b/private/src/phase2b_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2b/private/src/phase2b_activator.c b/examples/dm_example/phase2b/private/src/phase2b_activator.c
deleted file mode 100644
index c7692d4..0000000
--- a/examples/dm_example/phase2b/private/src/phase2b_activator.c
+++ /dev/null
@@ -1,95 +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.
- */
-/*
- * activator.c
- *
- * \date Oct 29, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <phase2b_cmp.h>
-
-#include "bundle_activator.h"
-#include "dm_activator.h"
-
-#include "phase1.h"
-#include "phase2.h"
-#include "phase2b_cmp.h"
-
-struct phase2b_activator_struct {
- phase2b_cmp_t *phase2bCmp;
- phase2_t phase2Serv;
-};
-
-celix_status_t dm_create(bundle_context_pt context, void **userData) {
- printf("phase2b: dm_create\n");
- *userData = calloc(1, sizeof(struct phase2b_activator_struct));
- return *userData != NULL ? CELIX_SUCCESS : CELIX_ENOMEM;
-}
-
-celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
- printf("phase2b: dm_init\n");
- celix_status_t status = CELIX_SUCCESS;
-
- struct phase2b_activator_struct *act = (struct phase2b_activator_struct *)userData;
-
- act->phase2bCmp = phase2b_create();
- if (act->phase2bCmp != NULL) {
-
- act->phase2Serv.handle = act->phase2bCmp;
- act->phase2Serv.getData = (void *)phase2b_getData;
-
- properties_pt props = properties_create();
- properties_set(props, "id", "phase2b");
-
- dm_component_pt cmp;
- component_create(context, "PHASE2B_PROCESSING_COMPONENT", &cmp);
- component_setImplementation(cmp, act->phase2bCmp);
- component_setCallbacksSafe(cmp, phase2b_cmp_t *, phase2b_init, phase2b_start, phase2b_stop, phase2b_deinit);
- component_addInterface(cmp, PHASE2_NAME, PHASE2_VERSION, &act->phase2Serv, props);
-
-
- dm_service_dependency_pt dep;
- serviceDependency_create(&dep);
- serviceDependency_setService(dep, PHASE1_NAME, PHASE1_RANGE_EXACT, NULL);
- serviceDependency_setCallbacksSafe(dep, phase2b_cmp_t*, const phase1_t*, phase2b_setPhase1, NULL, NULL, NULL, NULL);
- serviceDependency_setRequired(dep, true);
- serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_LOCKING);
- component_addServiceDependency(cmp, dep);
-
- dependencyManager_add(manager, cmp);
- } else {
- status = CELIX_ENOMEM;
- }
-
- return status;
-}
-
-celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
- printf("phase2b: dm-destroy\n");
-
- struct phase2b_activator_struct *act = (struct phase2b_activator_struct *)userData;
- if (act->phase2bCmp != NULL) {
- phase2b_destroy(act->phase2bCmp);
- }
- free(act);
-
- return CELIX_SUCCESS;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2b/private/src/phase2b_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2b/private/src/phase2b_cmp.c b/examples/dm_example/phase2b/private/src/phase2b_cmp.c
deleted file mode 100644
index a74dcfa..0000000
--- a/examples/dm_example/phase2b/private/src/phase2b_cmp.c
+++ /dev/null
@@ -1,115 +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.
- */
-/*
- * publisher.c
- *
- * \date Oct 29, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-
-#include "celix_threads.h"
-#include "phase2b_cmp.h"
-
-#define SLEEPTIME 2000000
-
-struct phase2b_cmp_struct {
- celix_thread_t thread;
- bool running;
- double currentValue;
- celix_thread_mutex_t mutex;
- const phase1_t* phase1Serv;
-};
-
-static void *phase2b_thread(void *data);
-
-phase2b_cmp_t *phase2b_create(void) {
- phase2b_cmp_t *cmp = calloc(1, sizeof(*cmp));
- if (cmp != NULL) {
- cmp->currentValue = 0.0;
- cmp->running = false;
- celixThreadMutex_create(&cmp->mutex, NULL);
- }
- return cmp;
-}
-
-int phase2b_init(phase2b_cmp_t *cmp) {
- printf("init phase2b\n");
- return 0;
-}
-
-int phase2b_start(phase2b_cmp_t *cmp) {
- printf("start phase2b\n");
- cmp->running = true;
- celixThread_create(&cmp->thread, NULL, phase2b_thread, cmp);
- return 0;
-}
-
-int phase2b_stop(phase2b_cmp_t *cmp) {
- printf("stop phase2b\n");
- cmp->running = false;
- celixThread_kill(cmp->thread, SIGUSR1);
- celixThread_join(cmp->thread, NULL);
- return 0;
-}
-
-int phase2b_deinit(phase2b_cmp_t *cmp) {
- printf("deinit phase2b\n");
- return 0;
-}
-
-void phase2b_destroy(phase2b_cmp_t *cmp) {
- celixThreadMutex_destroy(&cmp->mutex);
- free(cmp);
- printf("destroy phase2b\n");
-}
-
-int phase2b_setPhase1(phase2b_cmp_t *cmp, const phase1_t* phase1) {
- celixThreadMutex_lock(&cmp->mutex);
- cmp->phase1Serv = phase1;
- celixThreadMutex_unlock(&cmp->mutex);
- return 0;
-}
-
-static void *phase2b_thread(void *data) {
- phase2b_cmp_t *cmp = data;
- unsigned int counter;
-
- while (cmp->running) {
- celixThreadMutex_lock(&cmp->mutex);
- if (cmp->phase1Serv != NULL) {
- cmp->phase1Serv->getData(cmp->phase1Serv->handle, &counter);
- cmp->currentValue = counter / 1000;
- }
- celixThreadMutex_unlock(&cmp->mutex);
- usleep(SLEEPTIME);
- }
-
- celixThread_exit(NULL);
- return NULL;
-}
-
-int phase2b_getData(phase2b_cmp_t *cmp, double *data) {
- *data = cmp->currentValue;
- return 0;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2b/src/phase2b_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2b/src/phase2b_activator.c b/examples/dm_example/phase2b/src/phase2b_activator.c
new file mode 100644
index 0000000..c7692d4
--- /dev/null
+++ b/examples/dm_example/phase2b/src/phase2b_activator.c
@@ -0,0 +1,95 @@
+/**
+ *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.
+ */
+/*
+ * activator.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <phase2b_cmp.h>
+
+#include "bundle_activator.h"
+#include "dm_activator.h"
+
+#include "phase1.h"
+#include "phase2.h"
+#include "phase2b_cmp.h"
+
+struct phase2b_activator_struct {
+ phase2b_cmp_t *phase2bCmp;
+ phase2_t phase2Serv;
+};
+
+celix_status_t dm_create(bundle_context_pt context, void **userData) {
+ printf("phase2b: dm_create\n");
+ *userData = calloc(1, sizeof(struct phase2b_activator_struct));
+ return *userData != NULL ? CELIX_SUCCESS : CELIX_ENOMEM;
+}
+
+celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("phase2b: dm_init\n");
+ celix_status_t status = CELIX_SUCCESS;
+
+ struct phase2b_activator_struct *act = (struct phase2b_activator_struct *)userData;
+
+ act->phase2bCmp = phase2b_create();
+ if (act->phase2bCmp != NULL) {
+
+ act->phase2Serv.handle = act->phase2bCmp;
+ act->phase2Serv.getData = (void *)phase2b_getData;
+
+ properties_pt props = properties_create();
+ properties_set(props, "id", "phase2b");
+
+ dm_component_pt cmp;
+ component_create(context, "PHASE2B_PROCESSING_COMPONENT", &cmp);
+ component_setImplementation(cmp, act->phase2bCmp);
+ component_setCallbacksSafe(cmp, phase2b_cmp_t *, phase2b_init, phase2b_start, phase2b_stop, phase2b_deinit);
+ component_addInterface(cmp, PHASE2_NAME, PHASE2_VERSION, &act->phase2Serv, props);
+
+
+ dm_service_dependency_pt dep;
+ serviceDependency_create(&dep);
+ serviceDependency_setService(dep, PHASE1_NAME, PHASE1_RANGE_EXACT, NULL);
+ serviceDependency_setCallbacksSafe(dep, phase2b_cmp_t*, const phase1_t*, phase2b_setPhase1, NULL, NULL, NULL, NULL);
+ serviceDependency_setRequired(dep, true);
+ serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_LOCKING);
+ component_addServiceDependency(cmp, dep);
+
+ dependencyManager_add(manager, cmp);
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ return status;
+}
+
+celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("phase2b: dm-destroy\n");
+
+ struct phase2b_activator_struct *act = (struct phase2b_activator_struct *)userData;
+ if (act->phase2bCmp != NULL) {
+ phase2b_destroy(act->phase2bCmp);
+ }
+ free(act);
+
+ return CELIX_SUCCESS;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2b/src/phase2b_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2b/src/phase2b_cmp.c b/examples/dm_example/phase2b/src/phase2b_cmp.c
new file mode 100644
index 0000000..a74dcfa
--- /dev/null
+++ b/examples/dm_example/phase2b/src/phase2b_cmp.c
@@ -0,0 +1,115 @@
+/**
+ *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.
+ */
+/*
+ * publisher.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include "celix_threads.h"
+#include "phase2b_cmp.h"
+
+#define SLEEPTIME 2000000
+
+struct phase2b_cmp_struct {
+ celix_thread_t thread;
+ bool running;
+ double currentValue;
+ celix_thread_mutex_t mutex;
+ const phase1_t* phase1Serv;
+};
+
+static void *phase2b_thread(void *data);
+
+phase2b_cmp_t *phase2b_create(void) {
+ phase2b_cmp_t *cmp = calloc(1, sizeof(*cmp));
+ if (cmp != NULL) {
+ cmp->currentValue = 0.0;
+ cmp->running = false;
+ celixThreadMutex_create(&cmp->mutex, NULL);
+ }
+ return cmp;
+}
+
+int phase2b_init(phase2b_cmp_t *cmp) {
+ printf("init phase2b\n");
+ return 0;
+}
+
+int phase2b_start(phase2b_cmp_t *cmp) {
+ printf("start phase2b\n");
+ cmp->running = true;
+ celixThread_create(&cmp->thread, NULL, phase2b_thread, cmp);
+ return 0;
+}
+
+int phase2b_stop(phase2b_cmp_t *cmp) {
+ printf("stop phase2b\n");
+ cmp->running = false;
+ celixThread_kill(cmp->thread, SIGUSR1);
+ celixThread_join(cmp->thread, NULL);
+ return 0;
+}
+
+int phase2b_deinit(phase2b_cmp_t *cmp) {
+ printf("deinit phase2b\n");
+ return 0;
+}
+
+void phase2b_destroy(phase2b_cmp_t *cmp) {
+ celixThreadMutex_destroy(&cmp->mutex);
+ free(cmp);
+ printf("destroy phase2b\n");
+}
+
+int phase2b_setPhase1(phase2b_cmp_t *cmp, const phase1_t* phase1) {
+ celixThreadMutex_lock(&cmp->mutex);
+ cmp->phase1Serv = phase1;
+ celixThreadMutex_unlock(&cmp->mutex);
+ return 0;
+}
+
+static void *phase2b_thread(void *data) {
+ phase2b_cmp_t *cmp = data;
+ unsigned int counter;
+
+ while (cmp->running) {
+ celixThreadMutex_lock(&cmp->mutex);
+ if (cmp->phase1Serv != NULL) {
+ cmp->phase1Serv->getData(cmp->phase1Serv->handle, &counter);
+ cmp->currentValue = counter / 1000;
+ }
+ celixThreadMutex_unlock(&cmp->mutex);
+ usleep(SLEEPTIME);
+ }
+
+ celixThread_exit(NULL);
+ return NULL;
+}
+
+int phase2b_getData(phase2b_cmp_t *cmp, double *data) {
+ *data = cmp->currentValue;
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2b/src/phase2b_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2b/src/phase2b_cmp.h b/examples/dm_example/phase2b/src/phase2b_cmp.h
new file mode 100644
index 0000000..7ae0358
--- /dev/null
+++ b/examples/dm_example/phase2b/src/phase2b_cmp.h
@@ -0,0 +1,46 @@
+/**
+ *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.
+ */
+/*
+ * publisher.h
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PHASE2B_CMP_H
+#define PHASE2B_CMP_H
+
+#include "phase1.h"
+
+typedef struct phase2b_cmp_struct phase2b_cmp_t;
+
+phase2b_cmp_t *phase2b_create(void);
+int phase2b_init(phase2b_cmp_t *cmp);
+int phase2b_start(phase2b_cmp_t *cmp);
+int phase2b_stop(phase2b_cmp_t *cmp);
+int phase2b_deinit(phase2b_cmp_t *cmp);
+void phase2b_destroy(phase2b_cmp_t *cmp);
+
+int phase2b_setPhase1(phase2b_cmp_t *cmp, const phase1_t* phase1);
+
+int phase2b_getData(phase2b_cmp_t *cmp, double *data);
+
+
+#endif //PHASE2B_CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase3/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/CMakeLists.txt b/examples/dm_example/phase3/CMakeLists.txt
index 9547e04..1784057 100644
--- a/examples/dm_example/phase3/CMakeLists.txt
+++ b/examples/dm_example/phase3/CMakeLists.txt
@@ -15,28 +15,23 @@
# specific language governing permissions and limitations
# under the License.
-include_directories(
- private/include
- ../services
-)
-
-add_bundle(phase3
+add_bundle(dm_example_phase3
SYMBOLIC_NAME phase3
VERSION 0.0.1
SOURCES
- private/src/phase3_activator
- private/src/phase3_cmp
+ src/phase3_activator
+ src/phase3_cmp
)
-
-#bundle_private_libs(phase3 dependency_manager)
+target_include_directories(dm_example_phase3 PRIVATE src)
+target_link_libraries(dm_example_phase3 PRIVATE dm_example_api)
IF(APPLE)
- target_link_libraries(phase3 PRIVATE -Wl,-all_load dependency_manager_static)
+ target_link_libraries(dm_example_phase3 PRIVATE -Wl,-all_load dependency_manager_static)
else()
if(ENABLE_ADDRESS_SANITIZER)
#With asan there can be undefined symbols
- target_link_libraries(phase3 PRIVATE -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive)
+ target_link_libraries(dm_example_phase3 PRIVATE -Wl,--whole-archive Celix::dependency_manager_static -Wl,--no-whole-archive)
else()
- target_link_libraries(phase3 PRIVATE -Wl,--no-undefined -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive)
+ target_link_libraries(dm_example_phase3 PRIVATE -Wl,--no-undefined -Wl,--whole-archive Celix::dependency_manager_static -Wl,--no-whole-archive)
endif()
ENDIF()
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase3/private/include/phase3_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/private/include/phase3_cmp.h b/examples/dm_example/phase3/private/include/phase3_cmp.h
deleted file mode 100644
index 9c63845..0000000
--- a/examples/dm_example/phase3/private/include/phase3_cmp.h
+++ /dev/null
@@ -1,45 +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.
- */
-/*
- * publisher.h
- *
- * \date Oct 29, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PHASE3_CMP_H
-#define PHASE3_CMP_H
-
-#include "phase2.h"
-
-typedef struct phase3_cmp_struct phase3_cmp_t;
-
-phase3_cmp_t *phase3_create();
-int phase3_init(phase3_cmp_t *cmp);
-int phase3_start(phase3_cmp_t *cmp);
-int phase3_stop(phase3_cmp_t *cmp);
-int phase3_deinit(phase3_cmp_t *cmp);
-void phase3_destroy(phase3_cmp_t *cmp);
-
-int phase3_addPhase2(phase3_cmp_t *cmp, const phase2_t* phase2);
-int phase3_removePhase2(phase3_cmp_t *cmp, const phase2_t* phase2);
-
-
-#endif //PHASE3_CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase3/private/src/phase3_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/private/src/phase3_activator.c b/examples/dm_example/phase3/private/src/phase3_activator.c
deleted file mode 100644
index 64b7a0b..0000000
--- a/examples/dm_example/phase3/private/src/phase3_activator.c
+++ /dev/null
@@ -1,84 +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.
- */
-/*
- * activator.c
- *
- * \date Oct 29, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-
-#include "bundle_activator.h"
-#include "dm_activator.h"
-
-#include "phase2.h"
-#include "phase3_cmp.h"
-
-struct phase3_activator_struct {
- phase3_cmp_t *phase3Cmp;
-};
-
-celix_status_t dm_create(bundle_context_pt context, void **userData) {
- printf("phase3: dm_create\n");
- *userData = calloc(1, sizeof(struct phase3_activator_struct));
- return *userData != NULL ? CELIX_SUCCESS : CELIX_ENOMEM;
-}
-
-celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
- printf("phase3: dm_init\n");
- celix_status_t status = CELIX_SUCCESS;
-
- struct phase3_activator_struct *act = (struct phase3_activator_struct *)userData;
-
- act->phase3Cmp = phase3_create();
- if (act->phase3Cmp != NULL) {
-
- dm_component_pt cmp;
- component_create(context, "PHASE3_PROCESSING_COMPONENT", &cmp);
- component_setImplementation(cmp, act->phase3Cmp);
- component_setCallbacksSafe(cmp, phase3_cmp_t *, phase3_init, phase3_start, phase3_stop, phase3_deinit);
-
- dm_service_dependency_pt dep;
- serviceDependency_create(&dep);
- serviceDependency_setService(dep, PHASE2_NAME, NULL, NULL);
- serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND); //SUSPEND Strategy is default
- serviceDependency_setCallbacksSafe(dep, phase3_cmp_t*, const phase2_t*, NULL, phase3_addPhase2, NULL, phase3_removePhase2, NULL);
- serviceDependency_setRequired(dep, true);
- component_addServiceDependency(cmp, dep);
-
- dependencyManager_add(manager, cmp);
- } else {
- status = CELIX_ENOMEM;
- }
-
- return status;
-}
-
-celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
- printf("phase3: dm-destroy\n");
-
- struct phase3_activator_struct *act = (struct phase3_activator_struct *)userData;
- if (act->phase3Cmp != NULL) {
- phase3_destroy(act->phase3Cmp);
- }
- free(act);
-
- return CELIX_SUCCESS;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase3/private/src/phase3_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/private/src/phase3_cmp.c b/examples/dm_example/phase3/private/src/phase3_cmp.c
deleted file mode 100644
index 47cb720..0000000
--- a/examples/dm_example/phase3/private/src/phase3_cmp.c
+++ /dev/null
@@ -1,116 +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.
- */
-/*
- * publisher.c
- *
- * \date Oct 29, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-
-#include "array_list.h"
-#include "celix_threads.h"
-#include "phase3_cmp.h"
-
-#define SLEEPTIME 2000000
-
-struct phase3_cmp_struct {
- celix_thread_t thread;
- bool running;
- double currentValue;
- array_list_pt phase2Services; //phase2_t *
-};
-
-static void *phase3_thread(void *data);
-
-phase3_cmp_t *phase3_create() {
- phase3_cmp_t *cmp = calloc(1, sizeof(*cmp));
- if (cmp != NULL) {
- cmp->currentValue = 0.0;
- cmp->running = false;
- arrayList_create(&cmp->phase2Services);
- }
- return cmp;
-}
-
-int phase3_init(phase3_cmp_t *cmp) {
- printf("init phase3\n");
- return 0;
-}
-
-int phase3_start(phase3_cmp_t *cmp) {
- printf("start phase3\n");
- cmp->running = true;
- celixThread_create(&cmp->thread, NULL, phase3_thread, cmp);
- return 0;
-}
-
-int phase3_stop(phase3_cmp_t *cmp) {
- printf("stop phase3\n");
- cmp->running = false;
- celixThread_kill(cmp->thread, SIGUSR1);
- celixThread_join(cmp->thread, NULL);
- return 0;
-}
-
-int phase3_deinit(phase3_cmp_t *cmp) {
- printf("deinit phase3\n");
- return 0;
-}
-
-void phase3_destroy(phase3_cmp_t *cmp) {
- arrayList_destroy(cmp->phase2Services);
- free(cmp);
- printf("destroy phase3\n");
-}
-
-int phase3_addPhase2(phase3_cmp_t *cmp, const phase2_t* phase2) {
- arrayList_add(cmp->phase2Services, (void*)phase2);
- return 0;
-}
-
-int phase3_removePhase2(phase3_cmp_t *cmp, const phase2_t *phase2) {
- arrayList_removeElement(cmp->phase2Services, (void*)phase2);
- return 0;
-}
-
-
-static void *phase3_thread(void *data) {
- phase3_cmp_t *cmp = data;
- int size;
- int i;
- double value;
-
- while (cmp->running) {
- size = arrayList_size(cmp->phase2Services);
- for (i = 0; i < size; i += 1) {
- const phase2_t* serv = arrayList_get(cmp->phase2Services, i);
- serv->getData(serv->handle, &value);
- printf("PHASE3: Data from %p is %f\n", serv, value);
- }
- usleep(SLEEPTIME);
- }
-
- celixThread_exit(NULL);
- return NULL;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase3/src/phase3_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/src/phase3_activator.c b/examples/dm_example/phase3/src/phase3_activator.c
new file mode 100644
index 0000000..64b7a0b
--- /dev/null
+++ b/examples/dm_example/phase3/src/phase3_activator.c
@@ -0,0 +1,84 @@
+/**
+ *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.
+ */
+/*
+ * activator.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+
+#include "bundle_activator.h"
+#include "dm_activator.h"
+
+#include "phase2.h"
+#include "phase3_cmp.h"
+
+struct phase3_activator_struct {
+ phase3_cmp_t *phase3Cmp;
+};
+
+celix_status_t dm_create(bundle_context_pt context, void **userData) {
+ printf("phase3: dm_create\n");
+ *userData = calloc(1, sizeof(struct phase3_activator_struct));
+ return *userData != NULL ? CELIX_SUCCESS : CELIX_ENOMEM;
+}
+
+celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("phase3: dm_init\n");
+ celix_status_t status = CELIX_SUCCESS;
+
+ struct phase3_activator_struct *act = (struct phase3_activator_struct *)userData;
+
+ act->phase3Cmp = phase3_create();
+ if (act->phase3Cmp != NULL) {
+
+ dm_component_pt cmp;
+ component_create(context, "PHASE3_PROCESSING_COMPONENT", &cmp);
+ component_setImplementation(cmp, act->phase3Cmp);
+ component_setCallbacksSafe(cmp, phase3_cmp_t *, phase3_init, phase3_start, phase3_stop, phase3_deinit);
+
+ dm_service_dependency_pt dep;
+ serviceDependency_create(&dep);
+ serviceDependency_setService(dep, PHASE2_NAME, NULL, NULL);
+ serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND); //SUSPEND Strategy is default
+ serviceDependency_setCallbacksSafe(dep, phase3_cmp_t*, const phase2_t*, NULL, phase3_addPhase2, NULL, phase3_removePhase2, NULL);
+ serviceDependency_setRequired(dep, true);
+ component_addServiceDependency(cmp, dep);
+
+ dependencyManager_add(manager, cmp);
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ return status;
+}
+
+celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("phase3: dm-destroy\n");
+
+ struct phase3_activator_struct *act = (struct phase3_activator_struct *)userData;
+ if (act->phase3Cmp != NULL) {
+ phase3_destroy(act->phase3Cmp);
+ }
+ free(act);
+
+ return CELIX_SUCCESS;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase3/src/phase3_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/src/phase3_cmp.c b/examples/dm_example/phase3/src/phase3_cmp.c
new file mode 100644
index 0000000..47cb720
--- /dev/null
+++ b/examples/dm_example/phase3/src/phase3_cmp.c
@@ -0,0 +1,116 @@
+/**
+ *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.
+ */
+/*
+ * publisher.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include "array_list.h"
+#include "celix_threads.h"
+#include "phase3_cmp.h"
+
+#define SLEEPTIME 2000000
+
+struct phase3_cmp_struct {
+ celix_thread_t thread;
+ bool running;
+ double currentValue;
+ array_list_pt phase2Services; //phase2_t *
+};
+
+static void *phase3_thread(void *data);
+
+phase3_cmp_t *phase3_create() {
+ phase3_cmp_t *cmp = calloc(1, sizeof(*cmp));
+ if (cmp != NULL) {
+ cmp->currentValue = 0.0;
+ cmp->running = false;
+ arrayList_create(&cmp->phase2Services);
+ }
+ return cmp;
+}
+
+int phase3_init(phase3_cmp_t *cmp) {
+ printf("init phase3\n");
+ return 0;
+}
+
+int phase3_start(phase3_cmp_t *cmp) {
+ printf("start phase3\n");
+ cmp->running = true;
+ celixThread_create(&cmp->thread, NULL, phase3_thread, cmp);
+ return 0;
+}
+
+int phase3_stop(phase3_cmp_t *cmp) {
+ printf("stop phase3\n");
+ cmp->running = false;
+ celixThread_kill(cmp->thread, SIGUSR1);
+ celixThread_join(cmp->thread, NULL);
+ return 0;
+}
+
+int phase3_deinit(phase3_cmp_t *cmp) {
+ printf("deinit phase3\n");
+ return 0;
+}
+
+void phase3_destroy(phase3_cmp_t *cmp) {
+ arrayList_destroy(cmp->phase2Services);
+ free(cmp);
+ printf("destroy phase3\n");
+}
+
+int phase3_addPhase2(phase3_cmp_t *cmp, const phase2_t* phase2) {
+ arrayList_add(cmp->phase2Services, (void*)phase2);
+ return 0;
+}
+
+int phase3_removePhase2(phase3_cmp_t *cmp, const phase2_t *phase2) {
+ arrayList_removeElement(cmp->phase2Services, (void*)phase2);
+ return 0;
+}
+
+
+static void *phase3_thread(void *data) {
+ phase3_cmp_t *cmp = data;
+ int size;
+ int i;
+ double value;
+
+ while (cmp->running) {
+ size = arrayList_size(cmp->phase2Services);
+ for (i = 0; i < size; i += 1) {
+ const phase2_t* serv = arrayList_get(cmp->phase2Services, i);
+ serv->getData(serv->handle, &value);
+ printf("PHASE3: Data from %p is %f\n", serv, value);
+ }
+ usleep(SLEEPTIME);
+ }
+
+ celixThread_exit(NULL);
+ return NULL;
+}
[08/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/private/src/export_registration_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/private/src/export_registration_impl.c b/remote_services/remote_service_admin/private/src/export_registration_impl.c
deleted file mode 100644
index 1c684e7..0000000
--- a/remote_services/remote_service_admin/private/src/export_registration_impl.c
+++ /dev/null
@@ -1,257 +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.
- */
-/*
- * export_registration_impl.c
- *
- * \date Oct 6, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-
-#include "constants.h"
-
-#include "celix_errno.h"
-
-#include "export_registration_impl.h"
-#include "remote_service_admin_impl.h"
-
-
-struct export_reference {
- endpoint_description_pt endpoint;
- service_reference_pt reference;
-};
-
-celix_status_t exportRegistration_endpointAdding(void * handle, service_reference_pt reference, void **service);
-celix_status_t exportRegistration_endpointAdded(void * handle, service_reference_pt reference, void *service);
-celix_status_t exportRegistration_endpointModified(void * handle, service_reference_pt reference, void *service);
-celix_status_t exportRegistration_endpointRemoved(void * handle, service_reference_pt reference, void *service);
-
-celix_status_t exportRegistration_createEndpointTracker(export_registration_pt registration, service_tracker_pt *tracker);
-
-celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, remote_service_admin_pt rsa, bundle_context_pt context, export_registration_pt *registration) {
- celix_status_t status = CELIX_SUCCESS;
-
- *registration = calloc(1, sizeof(**registration));
- if (!*registration) {
- status = CELIX_ENOMEM;
- } else {
- (*registration)->context = context;
- (*registration)->closed = false;
- (*registration)->endpointDescription = endpoint;
- (*registration)->reference = reference;
- (*registration)->rsa = rsa;
- (*registration)->tracker = NULL;
- (*registration)->endpoint = NULL;
- (*registration)->endpointTracker = NULL;
- (*registration)->exportReference = NULL;
- (*registration)->bundle = NULL;
- (*registration)->loghelper = helper;
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_destroy(export_registration_pt *registration) {
- celix_status_t status = CELIX_SUCCESS;
-
- remoteServiceAdmin_destroyEndpointDescription(&(*registration)->endpointDescription);
- free(*registration);
-
- return status;
-}
-
-celix_status_t exportRegistration_startTracking(export_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (registration->endpointTracker == NULL) {
- status = exportRegistration_createEndpointTracker(registration, ®istration->endpointTracker);
- if (status == CELIX_SUCCESS) {
- status = serviceTracker_open(registration->endpointTracker);
- }
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_stopTracking(export_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (registration->endpointTracker != NULL) {
- status = serviceTracker_close(registration->endpointTracker);
- if (status != CELIX_SUCCESS) {
- logHelper_log(registration->loghelper, OSGI_LOGSERVICE_ERROR, "EXPORT_REGISTRATION: Could not close endpoint tracker");
- }
- else {
- status = serviceTracker_destroy(registration->endpointTracker);
- }
- }
- if (registration->tracker != NULL) {
- status = serviceTracker_close(registration->tracker);
- if (status != CELIX_SUCCESS) {
- logHelper_log(registration->loghelper, OSGI_LOGSERVICE_ERROR, "EXPORT_REGISTRATION: Could not close service tracker");
- }
- else {
- status = serviceTracker_destroy(registration->tracker);
- }
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_createEndpointTracker(export_registration_pt registration, service_tracker_pt *tracker) {
- celix_status_t status;
-
- service_tracker_customizer_pt customizer = NULL;
-
- status = serviceTrackerCustomizer_create(registration, exportRegistration_endpointAdding,
- exportRegistration_endpointAdded, exportRegistration_endpointModified, exportRegistration_endpointRemoved, &customizer);
-
- if (status == CELIX_SUCCESS) {
- char filter[512];
-
- snprintf(filter, 512, "(&(%s=%s)(remote.interface=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, (char*) OSGI_RSA_REMOTE_ENDPOINT, registration->endpointDescription->service);
- status = serviceTracker_createWithFilter(registration->context, filter, customizer, tracker);
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_endpointAdding(void * handle, service_reference_pt reference, void **service) {
- celix_status_t status;
- export_registration_pt registration = handle;
-
- status = bundleContext_getService(registration->context, reference, service);
-
- return status;
-}
-
-celix_status_t exportRegistration_endpointAdded(void * handle, service_reference_pt reference, void *endpoint_service) {
- celix_status_t status = CELIX_SUCCESS;
- export_registration_pt registration = handle;
-
- remote_endpoint_service_pt endpoint = endpoint_service;
- if (registration->endpoint == NULL) {
- registration->endpoint = endpoint;
- void *service = NULL;
- status = bundleContext_getService(registration->context, registration->reference, &service);
- if (status == CELIX_SUCCESS) {
- endpoint->setService(endpoint->endpoint, service);
- }
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_endpointModified(void * handle, service_reference_pt reference, void *service) {
- celix_status_t status = CELIX_SUCCESS;
-
- return status;
-}
-
-celix_status_t exportRegistration_endpointRemoved(void * handle, service_reference_pt reference, void *service) {
- celix_status_t status = CELIX_SUCCESS;
- export_registration_pt registration = handle;
-
- remote_endpoint_service_pt endpoint = service;
- if (registration->endpoint != NULL) {
- endpoint->setService(endpoint->endpoint, NULL);
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_open(export_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- const char *bundleStore = NULL;
-
- bundleContext_getProperty(registration->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore);
-
- if (bundleStore == NULL) {
- bundleStore = DEFAULT_BUNDLE_STORE;
- }
- char name[256];
-
- snprintf(name, 256, "%s/%s_endpoint.zip", bundleStore, registration->endpointDescription->service);
-
- status = bundleContext_installBundle(registration->context, name, ®istration->bundle);
- if (status == CELIX_SUCCESS) {
- status = bundle_start(registration->bundle);
- if (status == CELIX_SUCCESS) {
- }
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_close(export_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
-
- exportRegistration_stopTracking(registration);
-
- bundle_uninstall(registration->bundle);
-
-
- return status;
-}
-
-celix_status_t exportRegistration_getException(export_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *reference) {
- celix_status_t status = CELIX_SUCCESS;
-
- registration->exportReference = calloc(1, sizeof(*registration->exportReference));
-
- if (registration->exportReference == NULL) {
- status = CELIX_ENOMEM;
- } else {
- registration->exportReference->endpoint = registration->endpointDescription;
- registration->exportReference->reference = registration->reference;
- }
-
- *reference = registration->exportReference;
-
- return status;
-}
-
-celix_status_t exportRegistration_setEndpointDescription(export_registration_pt registration, endpoint_description_pt endpointDescription) {
- celix_status_t status = CELIX_SUCCESS;
-
- registration->endpointDescription = endpointDescription;
-
- return status;
-}
-
-celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint) {
- celix_status_t status = CELIX_SUCCESS;
-
- *endpoint = reference->endpoint;
-
- return status;
-}
-
-celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service) {
- celix_status_t status = CELIX_SUCCESS;
- *service = reference->reference;
- return status;
-}
-
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/private/src/import_registration_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/private/src/import_registration_impl.c b/remote_services/remote_service_admin/private/src/import_registration_impl.c
deleted file mode 100644
index 9a84327..0000000
--- a/remote_services/remote_service_admin/private/src/import_registration_impl.c
+++ /dev/null
@@ -1,274 +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.
- */
-/*
- * import_registration_impl.c
- *
- * \date Oct 14, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include <constants.h>
-
-#include "celix_errno.h"
-
-#include "import_registration_impl.h"
-#include "remote_service_admin_impl.h"
-
-struct import_reference {
- endpoint_description_pt endpoint;
- service_reference_pt reference;
-};
-
-
-
-celix_status_t importRegistration_proxyFactoryAdding(void * handle, service_reference_pt reference, void **service);
-celix_status_t importRegistration_proxyFactoryAdded(void * handle, service_reference_pt reference, void *service);
-celix_status_t importRegistration_proxyFactoryModified(void * handle, service_reference_pt reference, void *service);
-celix_status_t importRegistration_proxyFactoryRemoved(void * handle, service_reference_pt reference, void *service);
-
-celix_status_t importRegistration_create(endpoint_description_pt endpoint, remote_service_admin_pt rsa, sendToHandle sendToCallback, bundle_context_pt context, import_registration_pt *registration) {
- celix_status_t status = CELIX_SUCCESS;
-
- *registration = calloc(1, sizeof(**registration));
- if (!*registration) {
- status = CELIX_ENOMEM;
- } else {
- (*registration)->context = context;
- (*registration)->closed = false;
- (*registration)->endpointDescription = endpoint;
- (*registration)->rsa = rsa;
- (*registration)->sendToCallback = sendToCallback;
- (*registration)->reference = NULL;
- (*registration)->importReference = NULL;
- }
-
- return status;
-}
-
-celix_status_t importRegistration_destroy(import_registration_pt registration)
-{
- free(registration);
-
- return CELIX_SUCCESS;
-}
-
-
-celix_status_t importRegistrationFactory_create(log_helper_pt helper, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory) {
- celix_status_t status = CELIX_SUCCESS;
-
- *registration_factory = calloc(1, sizeof(**registration_factory));
- if (!*registration_factory) {
- status = CELIX_ENOMEM;
- } else {
- (*registration_factory)->serviceName = strdup(serviceName);
- (*registration_factory)->context = context;
- (*registration_factory)->bundle = NULL;
- (*registration_factory)->loghelper = helper;
-
- arrayList_create(&(*registration_factory)->registrations);
- }
-
- return status;
-}
-
-
-
-celix_status_t importRegistrationFactory_destroy(import_registration_factory_pt* registration_factory) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (*registration_factory != NULL)
- {
- free((*registration_factory)->serviceName);
- arrayList_destroy((*registration_factory)->registrations);
-
- serviceTracker_destroy((*registration_factory)->proxyFactoryTracker);
- free(*registration_factory);
-
- *registration_factory = NULL;
- }
-
-
- return status;
-}
-
-
-celix_status_t importRegistrationFactory_open(import_registration_factory_pt registration_factory)
-{
- celix_status_t status;
-
- const char *bundleStore = NULL;
- bundleContext_getProperty(registration_factory->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore);
-
- if (bundleStore == NULL) {
- bundleStore = DEFAULT_BUNDLE_STORE;
- }
-
- char name[256];
- snprintf(name, 256, "%s/%s_proxy.zip", bundleStore, registration_factory->serviceName);
-
- status = bundleContext_installBundle(registration_factory->context, name, ®istration_factory->bundle);
-
- if (status == CELIX_SUCCESS) {
- status = bundle_start(registration_factory->bundle);
- if (status == CELIX_SUCCESS) {
- logHelper_log(registration_factory->loghelper, OSGI_LOGSERVICE_INFO, "%s successfully started.", name);
- }
- }
- else {
- logHelper_log(registration_factory->loghelper, OSGI_LOGSERVICE_ERROR, "%s could not be installed.", name);
- }
-
- return status;
-}
-
-celix_status_t importRegistrationFactory_close(import_registration_factory_pt registration_factory)
-{
- celix_status_t status = CELIX_SUCCESS;
-
-
- if (registration_factory->proxyFactoryTracker != NULL) {
- serviceTracker_close(registration_factory->proxyFactoryTracker);
- }
-
- if (registration_factory->bundle != NULL) {
- bundle_uninstall(registration_factory->bundle);
- }
-
- return status;
-}
-
-
-celix_status_t importRegistration_createProxyFactoryTracker(import_registration_factory_pt registration_factory, service_tracker_pt *tracker) {
- celix_status_t status;
- service_tracker_customizer_pt customizer = NULL;
-
- status = serviceTrackerCustomizer_create(registration_factory, importRegistration_proxyFactoryAdding, importRegistration_proxyFactoryAdded, importRegistration_proxyFactoryModified, importRegistration_proxyFactoryRemoved, &customizer);
-
- if (status == CELIX_SUCCESS) {
- char filter[512];
-
- snprintf(filter, 512, "(&(%s=%s)(proxy.interface=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, (char*) OSGI_RSA_REMOTE_PROXY_FACTORY, registration_factory->serviceName);
- status = serviceTracker_createWithFilter(registration_factory->context, filter, customizer, tracker);
-
- if (status == CELIX_SUCCESS)
- {
- serviceTracker_open(*tracker);
- }
- }
-
- return status;
-}
-
-celix_status_t importRegistration_proxyFactoryAdding(void * handle, service_reference_pt reference, void **service) {
- celix_status_t status = CELIX_SUCCESS;
- import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
-
- bundleContext_getService(registration_factory->context, reference, service);
-
- return status;
-}
-
-celix_status_t importRegistration_proxyFactoryAdded(void * handle, service_reference_pt reference, void *service) {
- celix_status_t status = CELIX_SUCCESS;
-
- import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
- registration_factory->trackedFactory = (remote_proxy_factory_service_pt) service;
-
- return status;
-}
-
-celix_status_t importRegistration_proxyFactoryModified(void * handle, service_reference_pt reference, void *service) {
- celix_status_t status = CELIX_SUCCESS;
-
- return status;
-}
-
-celix_status_t importRegistration_proxyFactoryRemoved(void * handle, service_reference_pt reference, void *service) {
- celix_status_t status = CELIX_SUCCESS;
-
- import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
- registration_factory->trackedFactory = NULL;
-
- return status;
-}
-
-
-
-celix_status_t importRegistrationFactory_install(log_helper_pt helper, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory)
-{
- celix_status_t status;
-
- if ( (status = importRegistrationFactory_create(helper, serviceName, context, registration_factory)) == CELIX_SUCCESS) {
- // starting the proxy tracker first allows us to pick up already available proxy factories
- importRegistration_createProxyFactoryTracker(*registration_factory, &((*registration_factory)->proxyFactoryTracker));
- logHelper_log((*registration_factory)->loghelper, OSGI_LOGSERVICE_INFO, "remoteServiceAdmin_importService: new registration_factory added for %s at %p", serviceName, (*registration_factory)->proxyFactoryTracker);
-
- // check whether factory is available
- if (((*registration_factory)->trackedFactory == NULL) && ((status = importRegistrationFactory_open(*registration_factory)) != CELIX_SUCCESS)) {
- logHelper_log((*registration_factory)->loghelper, OSGI_LOGSERVICE_ERROR, "remoteServiceAdmin_importService: cannot open registration_factory for %s.", serviceName);
-
- importRegistrationFactory_close(*registration_factory);
- importRegistrationFactory_destroy(registration_factory);
- }
- }
-
- return status;
-}
-
-
-
-
-celix_status_t importRegistration_getException(import_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-
-celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (registration->importReference == NULL) {
- registration->importReference = calloc(1, sizeof(*registration->importReference));
- if (registration->importReference == NULL) {
- status = CELIX_ENOMEM;
- } else {
- registration->importReference->endpoint = registration->endpointDescription;
- registration->importReference->reference = registration->reference;
- }
- }
-
- *reference = registration->importReference;
-
- return status;
-}
-
-
-celix_status_t importReference_getImportedEndpoint(import_reference_pt reference) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-celix_status_t importReference_getImportedService(import_reference_pt reference) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/private/src/remote_proxy_factory_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/private/src/remote_proxy_factory_impl.c b/remote_services/remote_service_admin/private/src/remote_proxy_factory_impl.c
deleted file mode 100644
index 9f996d6..0000000
--- a/remote_services/remote_service_admin/private/src/remote_proxy_factory_impl.c
+++ /dev/null
@@ -1,252 +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.
- */
-
-/*
- * remote_proxy_factory_impl.c
- *
- * \date 22 Dec 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "remote_proxy.h"
-
-typedef struct proxy_instance {
- service_registration_pt registration_ptr;
- void *service;
- properties_pt properties;
-} *proxy_instance_pt;
-
-static celix_status_t remoteProxyFactory_registerProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback);
-static celix_status_t remoteProxyFactory_unregisterProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription);
-
-celix_status_t remoteProxyFactory_create(bundle_context_pt context, char *service, void *handle,
- createProxyService create, destroyProxyService destroy,
- remote_proxy_factory_pt *remote_proxy_factory_ptr) {
- celix_status_t status = CELIX_SUCCESS;
-
- *remote_proxy_factory_ptr = calloc(1, sizeof(**remote_proxy_factory_ptr));
- if (!*remote_proxy_factory_ptr) {
- status = CELIX_ENOMEM;
- }
-
- if (status == CELIX_SUCCESS) {
- (*remote_proxy_factory_ptr)->context_ptr = context;
- (*remote_proxy_factory_ptr)->service = strdup(service);
-
- (*remote_proxy_factory_ptr)->remote_proxy_factory_service_ptr = NULL;
- (*remote_proxy_factory_ptr)->properties = NULL;
- (*remote_proxy_factory_ptr)->registration = NULL;
-
- (*remote_proxy_factory_ptr)->proxy_instances = hashMap_create(NULL, NULL, NULL, NULL);
-
- (*remote_proxy_factory_ptr)->handle = handle;
-
- (*remote_proxy_factory_ptr)->create_proxy_service_ptr = create;
- (*remote_proxy_factory_ptr)->destroy_proxy_service_ptr = destroy;
- }
-
- return status;
-}
-
-celix_status_t remoteProxyFactory_destroy(remote_proxy_factory_pt *remote_proxy_factory_ptr) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!*remote_proxy_factory_ptr) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- if ((*remote_proxy_factory_ptr)->proxy_instances) {
- hashMap_destroy((*remote_proxy_factory_ptr)->proxy_instances, false, false);
- (*remote_proxy_factory_ptr)->proxy_instances = NULL;
- }
- if ((*remote_proxy_factory_ptr)->service) {
- free((*remote_proxy_factory_ptr)->service);
- (*remote_proxy_factory_ptr)->service = NULL;
- }
- free(*remote_proxy_factory_ptr);
- *remote_proxy_factory_ptr = NULL;
- }
-
- return status;
-}
-
-celix_status_t remoteProxyFactory_register(remote_proxy_factory_pt remote_proxy_factory_ptr) {
- celix_status_t status = CELIX_SUCCESS;
-
- remote_proxy_factory_ptr->remote_proxy_factory_service_ptr = calloc(1, sizeof(*remote_proxy_factory_ptr->remote_proxy_factory_service_ptr));
- if (!remote_proxy_factory_ptr->remote_proxy_factory_service_ptr) {
- status = CELIX_ENOMEM;
- }
-
- if (status == CELIX_SUCCESS) {
- remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->factory = remote_proxy_factory_ptr;
- remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->registerProxyService = remoteProxyFactory_registerProxyService;
- remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->unregisterProxyService = remoteProxyFactory_unregisterProxyService;
-
- remote_proxy_factory_ptr->properties = properties_create();
- if (!remote_proxy_factory_ptr->properties) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- properties_set(remote_proxy_factory_ptr->properties, "proxy.interface", remote_proxy_factory_ptr->service);
- }
- }
-
- if (status == CELIX_SUCCESS) {
- status = bundleContext_registerService(remote_proxy_factory_ptr->context_ptr, OSGI_RSA_REMOTE_PROXY_FACTORY,
- remote_proxy_factory_ptr->remote_proxy_factory_service_ptr, remote_proxy_factory_ptr->properties, &remote_proxy_factory_ptr->registration);
- }
-
- return status;
-}
-
-celix_status_t remoteProxyFactory_unregister(remote_proxy_factory_pt remote_proxy_factory_ptr) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!remote_proxy_factory_ptr) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- // #TODO Remove proxy registrations
- if (status == CELIX_SUCCESS) {
-
- hash_map_iterator_pt iter = hashMapIterator_create(remote_proxy_factory_ptr->proxy_instances);
- while(hashMapIterator_hasNext(iter)){
- proxy_instance_pt proxy_instance_ptr = (proxy_instance_pt)hashMapIterator_nextValue(iter);
-
- if (proxy_instance_ptr->service) {
- remote_proxy_factory_ptr->destroy_proxy_service_ptr(remote_proxy_factory_ptr->handle, proxy_instance_ptr->service);
- }
- free(proxy_instance_ptr);
- }
- hashMapIterator_destroy(iter);
-
- if (remote_proxy_factory_ptr->registration) {
- status = serviceRegistration_unregister(remote_proxy_factory_ptr->registration);
- remote_proxy_factory_ptr->properties = NULL;
- }
- if (remote_proxy_factory_ptr->properties) {
- properties_destroy(remote_proxy_factory_ptr->properties);
- }
- if (remote_proxy_factory_ptr->remote_proxy_factory_service_ptr) {
- free(remote_proxy_factory_ptr->remote_proxy_factory_service_ptr);
- }
- }
-
- return status;
-}
-
-
-static celix_status_t remoteProxyFactory_registerProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback) {
- celix_status_t status = CELIX_SUCCESS;
- proxy_instance_pt proxy_instance_ptr = NULL;
-
- if (!remote_proxy_factory_ptr || !remote_proxy_factory_ptr->create_proxy_service_ptr) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- proxy_instance_ptr = calloc(1, sizeof(*proxy_instance_ptr));
- if (!proxy_instance_ptr) {
- status = CELIX_ENOMEM;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- proxy_instance_ptr->properties = properties_create();
- if (!proxy_instance_ptr->properties) {
- status = CELIX_ENOMEM;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- status = remote_proxy_factory_ptr->create_proxy_service_ptr(remote_proxy_factory_ptr->handle, endpointDescription, rsa, sendToCallback, proxy_instance_ptr->properties, &proxy_instance_ptr->service);
- }
-
- if (status == CELIX_SUCCESS) {
- properties_set(proxy_instance_ptr->properties, "proxy.interface", remote_proxy_factory_ptr->service);
-
- hash_map_iterator_pt iter = hashMapIterator_create(endpointDescription->properties);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- char *key = hashMapEntry_getKey(entry);
- char *value = hashMapEntry_getValue(entry);
-
- properties_set(proxy_instance_ptr->properties, key, value);
- }
- hashMapIterator_destroy(iter);
- }
-
- if (status == CELIX_SUCCESS) {
- status = bundleContext_registerService(remote_proxy_factory_ptr->context_ptr, remote_proxy_factory_ptr->service, proxy_instance_ptr->service, proxy_instance_ptr->properties, &proxy_instance_ptr->registration_ptr);
- }
-
- if (status == CELIX_SUCCESS) {
- hashMap_put(remote_proxy_factory_ptr->proxy_instances, endpointDescription, proxy_instance_ptr);
- }
-
- if(status!=CELIX_SUCCESS){
- if(proxy_instance_ptr != NULL){
- if(proxy_instance_ptr->properties != NULL){
- properties_destroy(proxy_instance_ptr->properties);
- }
- free(proxy_instance_ptr);
- }
- }
-
- return status;
-}
-
-static celix_status_t remoteProxyFactory_unregisterProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription) {
- celix_status_t status = CELIX_SUCCESS;
- proxy_instance_pt proxy_instance_ptr = NULL;
-
- if (!remote_proxy_factory_ptr || !endpointDescription || !remote_proxy_factory_ptr->proxy_instances || !remote_proxy_factory_ptr->handle) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- proxy_instance_ptr = hashMap_remove(remote_proxy_factory_ptr->proxy_instances, endpointDescription);
- if (proxy_instance_ptr == NULL) {
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- if (proxy_instance_ptr->registration_ptr) {
- status = serviceRegistration_unregister(proxy_instance_ptr->registration_ptr);
- proxy_instance_ptr->properties = NULL;
- }
- if (proxy_instance_ptr->service) {
- status = remote_proxy_factory_ptr->destroy_proxy_service_ptr(remote_proxy_factory_ptr->handle, proxy_instance_ptr->service);
- }
- if (proxy_instance_ptr->properties) {
- properties_destroy(proxy_instance_ptr->properties);
- }
- free(proxy_instance_ptr);
- }
-
- return status;
-}
-
-
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/public/include/endpoint_description.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/public/include/endpoint_description.h b/remote_services/remote_service_admin/public/include/endpoint_description.h
deleted file mode 100644
index de27d2e..0000000
--- a/remote_services/remote_service_admin/public/include/endpoint_description.h
+++ /dev/null
@@ -1,50 +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.
- */
-/*
- * endpoint_description.h
- *
- * \date 25 Jul 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef ENDPOINT_DESCRIPTION_H_
-#define ENDPOINT_DESCRIPTION_H_
-
-#include "properties.h"
-#include "array_list.h"
-
-struct endpoint_description {
- char *frameworkUUID;
- char *id;
- // array_list_pt intents;
- char *service;
- // HASH_MAP packageVersions;
- properties_pt properties;
- unsigned long serviceId;
-};
-
-typedef struct endpoint_description endpoint_description_t;
-typedef endpoint_description_t* endpoint_description_pt;
-
-celix_status_t endpointDescription_create(properties_pt properties, endpoint_description_pt *endpointDescription);
-celix_status_t endpointDescription_destroy(endpoint_description_pt description);
-
-
-#endif /* ENDPOINT_DESCRIPTION_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/public/include/endpoint_listener.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/public/include/endpoint_listener.h b/remote_services/remote_service_admin/public/include/endpoint_listener.h
deleted file mode 100644
index 2e6359f..0000000
--- a/remote_services/remote_service_admin/public/include/endpoint_listener.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.
- */
-/*
- * endpoint_listener.h
- *
- * \date Sep 29, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef ENDPOINT_LISTENER_H_
-#define ENDPOINT_LISTENER_H_
-
-#include "array_list.h"
-#include "properties.h"
-
-#include "endpoint_description.h"
-
-static const char * const OSGI_ENDPOINT_LISTENER_SERVICE = "endpoint_listener";
-
-static const char * const OSGI_ENDPOINT_LISTENER_SCOPE = "endpoint.listener.scope";
-
-struct endpoint_listener {
- void *handle;
- celix_status_t (*endpointAdded)(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
- celix_status_t (*endpointRemoved)(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
-};
-
-typedef struct endpoint_listener endpoint_listener_t;
-typedef endpoint_listener_t *endpoint_listener_pt;
-
-
-#endif /* ENDPOINT_LISTENER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/public/include/export_registration.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/public/include/export_registration.h b/remote_services/remote_service_admin/public/include/export_registration.h
deleted file mode 100644
index dc3882b..0000000
--- a/remote_services/remote_service_admin/public/include/export_registration.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed under Apache License v2. See LICENSE for more information.
- */
-#ifndef CELIX_EXPORT_REGISTRATION_H
-#define CELIX_EXPORT_REGISTRATION_H
-
-#include "celix_errno.h"
-#include "endpoint_description.h"
-#include "service_reference.h"
-
-typedef struct export_registration *export_registration_pt;
-
-typedef struct export_reference *export_reference_pt;
-
-celix_status_t exportRegistration_close(export_registration_pt registration);
-celix_status_t exportRegistration_getException(export_registration_pt registration);
-celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *reference);
-
-celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint);
-celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service);
-
-#endif //CELIX_EXPORT_REGISTRATION_H
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/public/include/import_registration.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/public/include/import_registration.h b/remote_services/remote_service_admin/public/include/import_registration.h
deleted file mode 100644
index ef8193f..0000000
--- a/remote_services/remote_service_admin/public/include/import_registration.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed under Apache License v2. See LICENSE for more information.
- */
-#ifndef CELIX_IMPORT_REGISTRATION_H
-#define CELIX_IMPORT_REGISTRATION_H
-
-#include "celix_errno.h"
-#include "endpoint_description.h"
-#include "service_reference.h"
-
-typedef struct import_registration *import_registration_pt;
-
-typedef struct import_reference *import_reference_pt;
-
-celix_status_t importRegistration_close(import_registration_pt registration);
-celix_status_t importRegistration_getException(import_registration_pt registration);
-celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference);
-
-celix_status_t importReference_getImportedEndpoint(import_reference_pt reference);
-celix_status_t importReference_getImportedService(import_reference_pt reference);
-
-#endif //CELIX_IMPORT_REGISTRATION_H
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/public/include/remote_constants.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/public/include/remote_constants.h b/remote_services/remote_service_admin/public/include/remote_constants.h
deleted file mode 100644
index 0736685..0000000
--- a/remote_services/remote_service_admin/public/include/remote_constants.h
+++ /dev/null
@@ -1,38 +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.
- */
-/*
- * remote_constants.h
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_CONSTANTS_H_
-#define REMOTE_CONSTANTS_H_
-
-static const char * const OSGI_RSA_SERVICE_EXPORTED_INTERFACES = "service.exported.interfaces";
-static const char * const OSGI_RSA_ENDPOINT_FRAMEWORK_UUID = "endpoint.framework.uuid";
-static const char * const OSGI_RSA_ENDPOINT_SERVICE_ID = "endpoint.service.id";
-static const char * const OSGI_RSA_ENDPOINT_ID = "endpoint.id";
-static const char * const OSGI_RSA_SERVICE_IMPORTED = "service.imported";
-static const char * const OSGI_RSA_SERVICE_IMPORTED_CONFIGS = "service.imported.configs";
-static const char * const OSGI_RSA_SERVICE_LOCATION = "service.location";
-
-#endif /* REMOTE_CONSTANTS_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/public/include/remote_endpoint.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/public/include/remote_endpoint.h b/remote_services/remote_service_admin/public/include/remote_endpoint.h
deleted file mode 100644
index ab80abb..0000000
--- a/remote_services/remote_service_admin/public/include/remote_endpoint.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.
- */
-/*
- * remote_endpoint.h
- *
- * \date Oct 7, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_ENDPOINT_H_
-#define REMOTE_ENDPOINT_H_
-
-#define OSGI_RSA_REMOTE_ENDPOINT "remote_endpoint"
-
-typedef struct remote_endpoint remote_endpoint_t;
-typedef remote_endpoint_t* remote_endpoint_pt;
-
-struct remote_endpoint_service {
- remote_endpoint_pt endpoint;
- celix_status_t (*setService)(remote_endpoint_pt endpoint, void *service);
- celix_status_t (*handleRequest)(remote_endpoint_pt endpoint, char *data, char **reply);
-};
-
-typedef struct remote_endpoint_service *remote_endpoint_service_pt;
-
-
-#endif /* REMOTE_ENDPOINT_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/public/include/remote_endpoint_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/public/include/remote_endpoint_impl.h b/remote_services/remote_service_admin/public/include/remote_endpoint_impl.h
deleted file mode 100644
index 3782d62..0000000
--- a/remote_services/remote_service_admin/public/include/remote_endpoint_impl.h
+++ /dev/null
@@ -1,38 +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.
- */
-/*
- * remote_endpoint_impl.h
- *
- * \date Oct 11, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_ENDPOINT_IMPL_H_
-#define REMOTE_ENDPOINT_IMPL_H_
-
-#include "remote_endpoint.h"
-#include "celix_threads.h"
-
-struct remote_endpoint {
- celix_thread_mutex_t serviceLock;
- void *service;
-};
-
-#endif /* REMOTE_ENDPOINT_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/public/include/remote_proxy.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/public/include/remote_proxy.h b/remote_services/remote_service_admin/public/include/remote_proxy.h
deleted file mode 100644
index 4c3f5c3..0000000
--- a/remote_services/remote_service_admin/public/include/remote_proxy.h
+++ /dev/null
@@ -1,76 +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.
- */
-/*
- * remote_proxy.h
- *
- * \date Oct 13, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_PROXY_H_
-#define REMOTE_PROXY_H_
-
-#include "endpoint_listener.h"
-#include "remote_service_admin.h"
-
-#define OSGI_RSA_REMOTE_PROXY_FACTORY "remote_proxy_factory"
-#define OSGI_RSA_REMOTE_PROXY_TIMEOUT "remote_proxy_timeout"
-
-typedef celix_status_t (*sendToHandle)(remote_service_admin_pt remote_service_admin_ptr, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
-typedef celix_status_t (*createProxyService)(void *handle, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback, properties_pt properties, void **service);
-typedef celix_status_t (*destroyProxyService)(void *handle, void *service);
-
-typedef struct remote_proxy_factory *remote_proxy_factory_pt;
-typedef struct remote_proxy_factory_service *remote_proxy_factory_service_pt;
-
-struct remote_proxy_factory {
- bundle_context_pt context_ptr;
- char *service;
-
- remote_proxy_factory_service_pt remote_proxy_factory_service_ptr;
- properties_pt properties;
- service_registration_pt registration;
-
- hash_map_pt proxy_instances;
-
- void *handle;
-
- createProxyService create_proxy_service_ptr;
- destroyProxyService destroy_proxy_service_ptr;
-};
-
-struct remote_proxy_factory_service {
- remote_proxy_factory_pt factory;
- celix_status_t (*registerProxyService)(remote_proxy_factory_pt proxyFactoryService, endpoint_description_pt endpoint, remote_service_admin_pt remote_service_admin_ptr, sendToHandle callback);
- celix_status_t (*unregisterProxyService)(remote_proxy_factory_pt proxyFactoryService, endpoint_description_pt endpoint);
-};
-
-celix_status_t remoteProxyFactory_create(bundle_context_pt context, char *service, void *handle,
- createProxyService create, destroyProxyService destroy,
- remote_proxy_factory_pt *remote_proxy_factory_ptr);
-celix_status_t remoteProxyFactory_destroy(remote_proxy_factory_pt *remote_proxy_factory_ptr);
-
-celix_status_t remoteProxyFactory_register(remote_proxy_factory_pt remote_proxy_factory_ptr);
-celix_status_t remoteProxyFactory_unregister(remote_proxy_factory_pt remote_proxy_factory_ptr);
-
-
-
-
-#endif /* REMOTE_PROXY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/public/include/remote_service_admin.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/public/include/remote_service_admin.h b/remote_services/remote_service_admin/public/include/remote_service_admin.h
deleted file mode 100644
index cc7fd98..0000000
--- a/remote_services/remote_service_admin/public/include/remote_service_admin.h
+++ /dev/null
@@ -1,73 +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.
- */
-/*
- * remote_service_admin.h
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_SERVICE_ADMIN_H_
-#define REMOTE_SERVICE_ADMIN_H_
-
-#include "endpoint_listener.h"
-#include "service_reference.h"
-#include "export_registration.h"
-#include "import_registration.h"
-
-#define OSGI_RSA_REMOTE_SERVICE_ADMIN "remote_service_admin"
-
-typedef struct import_registration_factory import_registration_factory_t;
-typedef import_registration_factory_t* import_registration_factory_pt;
-
-typedef struct remote_service_admin remote_service_admin_t;
-typedef remote_service_admin_t* remote_service_admin_pt;
-
-struct remote_service_admin_service {
- remote_service_admin_pt admin;
- celix_status_t (*exportService)(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
- celix_status_t (*removeExportedService)(remote_service_admin_pt admin, export_registration_pt registration);
- celix_status_t (*getExportedServices)(remote_service_admin_pt admin, array_list_pt *services);
- celix_status_t (*getImportedEndpoints)(remote_service_admin_pt admin, array_list_pt *services);
- celix_status_t (*importService)(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
-
- celix_status_t (*exportReference_getExportedEndpoint)(export_reference_pt reference, endpoint_description_pt *endpoint);
- celix_status_t (*exportReference_getExportedService)(export_reference_pt reference, service_reference_pt *service);
-
- celix_status_t (*exportRegistration_close)(remote_service_admin_pt admin, export_registration_pt registration);
- celix_status_t (*exportRegistration_getException)(export_registration_pt registration);
- celix_status_t (*exportRegistration_getExportReference)(export_registration_pt registration, export_reference_pt *reference);
- celix_status_t (*exportRegistration_freeExportReference)(export_reference_pt *reference);
- celix_status_t (*exportRegistration_getEndpointDescription)(export_registration_pt registration, endpoint_description_pt endpointDescription);
-
- celix_status_t (*importReference_getImportedEndpoint)(import_reference_pt reference);
- celix_status_t (*importReference_getImportedService)(import_reference_pt reference);
-
- celix_status_t (*importRegistration_close)(remote_service_admin_pt admin, import_registration_pt registration);
- celix_status_t (*importRegistration_getException)(import_registration_pt registration);
- celix_status_t (*importRegistration_getImportReference)(import_registration_pt registration, import_reference_pt *reference);
-
-};
-
-typedef struct remote_service_admin_service remote_service_admin_service_t;
-typedef remote_service_admin_service_t* remote_service_admin_service_pt;
-
-
-#endif /* REMOTE_SERVICE_ADMIN_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_api/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/CMakeLists.txt b/remote_services/remote_service_admin_api/CMakeLists.txt
new file mode 100644
index 0000000..a7d0640
--- /dev/null
+++ b/remote_services/remote_service_admin_api/CMakeLists.txt
@@ -0,0 +1,45 @@
+# 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.
+
+add_library(remote_service_admin_api INTERFACE)
+target_include_directories(remote_service_admin_api INTERFACE include)
+
+install (FILES
+ include/remote_endpoint_impl.h
+ include/remote_endpoint.h
+ include/remote_proxy.h
+ include/remote_service_admin.h
+ include/export_registration.h
+ include/import_registration.h
+ include/endpoint_description.h
+ include/endpoint_listener.h
+ include/remote_constants.h
+ DESTINATION
+ include/celix/remote_service_admin
+ COMPONENT
+ remote_service_admin
+)
+install (FILES
+ public/include/endpoint_listener.h
+ DESTINATION
+ include/celix/endpoint_listener
+ COMPONENT
+ remote_service_admin
+)
+
+#Setup target aliases to match external usage
+add_library(Celix::remote_service_admin_api ALIAS remote_service_admin_api)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_api/README.md
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/README.md b/remote_services/remote_service_admin_api/README.md
new file mode 100644
index 0000000..2e3d268
--- /dev/null
+++ b/remote_services/remote_service_admin_api/README.md
@@ -0,0 +1,11 @@
+# Remote Service Admin
+
+The Remote Service Admin (RSA) provides the mechanisms to import and export services when instructed to do so by the Topology Manager.
+
+To delegate method calls to the actual service implementation, the RSA_SHM and the RSA_HTTP are using "endpoint/proxy" bundles, which has all the knowledge about the marshalling and unmarshalling of data for the service. The RSA_DFI implementation combines a [foreign function interface](https://en.wikipedia.org/wiki/Foreign_function_interface) technique together with manualy created descriptors.
+
+Note that this folder contains code commonly used by the RSA implementations and therefore does not include any CMAKE configuration.
+
+## Properties
+ ENDPOINTS defines the relative directory where endpoints and proxys can be found (default: endpoints)
+ CELIX_FRAMEWORK_EXTENDER_PATH Used in RSA_DFI only. Can be used to define a path to use as an extender path point for the framework bundle. For normal bundles the bundle cache is used.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_api/include/endpoint_description.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/endpoint_description.h b/remote_services/remote_service_admin_api/include/endpoint_description.h
new file mode 100644
index 0000000..de27d2e
--- /dev/null
+++ b/remote_services/remote_service_admin_api/include/endpoint_description.h
@@ -0,0 +1,50 @@
+/**
+ *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.
+ */
+/*
+ * endpoint_description.h
+ *
+ * \date 25 Jul 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef ENDPOINT_DESCRIPTION_H_
+#define ENDPOINT_DESCRIPTION_H_
+
+#include "properties.h"
+#include "array_list.h"
+
+struct endpoint_description {
+ char *frameworkUUID;
+ char *id;
+ // array_list_pt intents;
+ char *service;
+ // HASH_MAP packageVersions;
+ properties_pt properties;
+ unsigned long serviceId;
+};
+
+typedef struct endpoint_description endpoint_description_t;
+typedef endpoint_description_t* endpoint_description_pt;
+
+celix_status_t endpointDescription_create(properties_pt properties, endpoint_description_pt *endpointDescription);
+celix_status_t endpointDescription_destroy(endpoint_description_pt description);
+
+
+#endif /* ENDPOINT_DESCRIPTION_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_api/include/endpoint_listener.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/endpoint_listener.h b/remote_services/remote_service_admin_api/include/endpoint_listener.h
new file mode 100644
index 0000000..2e6359f
--- /dev/null
+++ b/remote_services/remote_service_admin_api/include/endpoint_listener.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.
+ */
+/*
+ * endpoint_listener.h
+ *
+ * \date Sep 29, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef ENDPOINT_LISTENER_H_
+#define ENDPOINT_LISTENER_H_
+
+#include "array_list.h"
+#include "properties.h"
+
+#include "endpoint_description.h"
+
+static const char * const OSGI_ENDPOINT_LISTENER_SERVICE = "endpoint_listener";
+
+static const char * const OSGI_ENDPOINT_LISTENER_SCOPE = "endpoint.listener.scope";
+
+struct endpoint_listener {
+ void *handle;
+ celix_status_t (*endpointAdded)(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
+ celix_status_t (*endpointRemoved)(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
+};
+
+typedef struct endpoint_listener endpoint_listener_t;
+typedef endpoint_listener_t *endpoint_listener_pt;
+
+
+#endif /* ENDPOINT_LISTENER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_api/include/export_registration.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/export_registration.h b/remote_services/remote_service_admin_api/include/export_registration.h
new file mode 100644
index 0000000..dc3882b
--- /dev/null
+++ b/remote_services/remote_service_admin_api/include/export_registration.h
@@ -0,0 +1,22 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#ifndef CELIX_EXPORT_REGISTRATION_H
+#define CELIX_EXPORT_REGISTRATION_H
+
+#include "celix_errno.h"
+#include "endpoint_description.h"
+#include "service_reference.h"
+
+typedef struct export_registration *export_registration_pt;
+
+typedef struct export_reference *export_reference_pt;
+
+celix_status_t exportRegistration_close(export_registration_pt registration);
+celix_status_t exportRegistration_getException(export_registration_pt registration);
+celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *reference);
+
+celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint);
+celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service);
+
+#endif //CELIX_EXPORT_REGISTRATION_H
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_api/include/import_registration.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/import_registration.h b/remote_services/remote_service_admin_api/include/import_registration.h
new file mode 100644
index 0000000..ef8193f
--- /dev/null
+++ b/remote_services/remote_service_admin_api/include/import_registration.h
@@ -0,0 +1,22 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#ifndef CELIX_IMPORT_REGISTRATION_H
+#define CELIX_IMPORT_REGISTRATION_H
+
+#include "celix_errno.h"
+#include "endpoint_description.h"
+#include "service_reference.h"
+
+typedef struct import_registration *import_registration_pt;
+
+typedef struct import_reference *import_reference_pt;
+
+celix_status_t importRegistration_close(import_registration_pt registration);
+celix_status_t importRegistration_getException(import_registration_pt registration);
+celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference);
+
+celix_status_t importReference_getImportedEndpoint(import_reference_pt reference);
+celix_status_t importReference_getImportedService(import_reference_pt reference);
+
+#endif //CELIX_IMPORT_REGISTRATION_H
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_api/include/remote_constants.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/remote_constants.h b/remote_services/remote_service_admin_api/include/remote_constants.h
new file mode 100644
index 0000000..0736685
--- /dev/null
+++ b/remote_services/remote_service_admin_api/include/remote_constants.h
@@ -0,0 +1,38 @@
+/**
+ *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.
+ */
+/*
+ * remote_constants.h
+ *
+ * \date Sep 30, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef REMOTE_CONSTANTS_H_
+#define REMOTE_CONSTANTS_H_
+
+static const char * const OSGI_RSA_SERVICE_EXPORTED_INTERFACES = "service.exported.interfaces";
+static const char * const OSGI_RSA_ENDPOINT_FRAMEWORK_UUID = "endpoint.framework.uuid";
+static const char * const OSGI_RSA_ENDPOINT_SERVICE_ID = "endpoint.service.id";
+static const char * const OSGI_RSA_ENDPOINT_ID = "endpoint.id";
+static const char * const OSGI_RSA_SERVICE_IMPORTED = "service.imported";
+static const char * const OSGI_RSA_SERVICE_IMPORTED_CONFIGS = "service.imported.configs";
+static const char * const OSGI_RSA_SERVICE_LOCATION = "service.location";
+
+#endif /* REMOTE_CONSTANTS_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_api/include/remote_endpoint.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/remote_endpoint.h b/remote_services/remote_service_admin_api/include/remote_endpoint.h
new file mode 100644
index 0000000..ab80abb
--- /dev/null
+++ b/remote_services/remote_service_admin_api/include/remote_endpoint.h
@@ -0,0 +1,44 @@
+/**
+ *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.
+ */
+/*
+ * remote_endpoint.h
+ *
+ * \date Oct 7, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef REMOTE_ENDPOINT_H_
+#define REMOTE_ENDPOINT_H_
+
+#define OSGI_RSA_REMOTE_ENDPOINT "remote_endpoint"
+
+typedef struct remote_endpoint remote_endpoint_t;
+typedef remote_endpoint_t* remote_endpoint_pt;
+
+struct remote_endpoint_service {
+ remote_endpoint_pt endpoint;
+ celix_status_t (*setService)(remote_endpoint_pt endpoint, void *service);
+ celix_status_t (*handleRequest)(remote_endpoint_pt endpoint, char *data, char **reply);
+};
+
+typedef struct remote_endpoint_service *remote_endpoint_service_pt;
+
+
+#endif /* REMOTE_ENDPOINT_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_api/include/remote_endpoint_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/remote_endpoint_impl.h b/remote_services/remote_service_admin_api/include/remote_endpoint_impl.h
new file mode 100644
index 0000000..3782d62
--- /dev/null
+++ b/remote_services/remote_service_admin_api/include/remote_endpoint_impl.h
@@ -0,0 +1,38 @@
+/**
+ *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.
+ */
+/*
+ * remote_endpoint_impl.h
+ *
+ * \date Oct 11, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef REMOTE_ENDPOINT_IMPL_H_
+#define REMOTE_ENDPOINT_IMPL_H_
+
+#include "remote_endpoint.h"
+#include "celix_threads.h"
+
+struct remote_endpoint {
+ celix_thread_mutex_t serviceLock;
+ void *service;
+};
+
+#endif /* REMOTE_ENDPOINT_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_api/include/remote_proxy.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/remote_proxy.h b/remote_services/remote_service_admin_api/include/remote_proxy.h
new file mode 100644
index 0000000..4c3f5c3
--- /dev/null
+++ b/remote_services/remote_service_admin_api/include/remote_proxy.h
@@ -0,0 +1,76 @@
+/**
+ *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.
+ */
+/*
+ * remote_proxy.h
+ *
+ * \date Oct 13, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef REMOTE_PROXY_H_
+#define REMOTE_PROXY_H_
+
+#include "endpoint_listener.h"
+#include "remote_service_admin.h"
+
+#define OSGI_RSA_REMOTE_PROXY_FACTORY "remote_proxy_factory"
+#define OSGI_RSA_REMOTE_PROXY_TIMEOUT "remote_proxy_timeout"
+
+typedef celix_status_t (*sendToHandle)(remote_service_admin_pt remote_service_admin_ptr, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
+typedef celix_status_t (*createProxyService)(void *handle, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback, properties_pt properties, void **service);
+typedef celix_status_t (*destroyProxyService)(void *handle, void *service);
+
+typedef struct remote_proxy_factory *remote_proxy_factory_pt;
+typedef struct remote_proxy_factory_service *remote_proxy_factory_service_pt;
+
+struct remote_proxy_factory {
+ bundle_context_pt context_ptr;
+ char *service;
+
+ remote_proxy_factory_service_pt remote_proxy_factory_service_ptr;
+ properties_pt properties;
+ service_registration_pt registration;
+
+ hash_map_pt proxy_instances;
+
+ void *handle;
+
+ createProxyService create_proxy_service_ptr;
+ destroyProxyService destroy_proxy_service_ptr;
+};
+
+struct remote_proxy_factory_service {
+ remote_proxy_factory_pt factory;
+ celix_status_t (*registerProxyService)(remote_proxy_factory_pt proxyFactoryService, endpoint_description_pt endpoint, remote_service_admin_pt remote_service_admin_ptr, sendToHandle callback);
+ celix_status_t (*unregisterProxyService)(remote_proxy_factory_pt proxyFactoryService, endpoint_description_pt endpoint);
+};
+
+celix_status_t remoteProxyFactory_create(bundle_context_pt context, char *service, void *handle,
+ createProxyService create, destroyProxyService destroy,
+ remote_proxy_factory_pt *remote_proxy_factory_ptr);
+celix_status_t remoteProxyFactory_destroy(remote_proxy_factory_pt *remote_proxy_factory_ptr);
+
+celix_status_t remoteProxyFactory_register(remote_proxy_factory_pt remote_proxy_factory_ptr);
+celix_status_t remoteProxyFactory_unregister(remote_proxy_factory_pt remote_proxy_factory_ptr);
+
+
+
+
+#endif /* REMOTE_PROXY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_api/include/remote_service_admin.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/remote_service_admin.h b/remote_services/remote_service_admin_api/include/remote_service_admin.h
new file mode 100644
index 0000000..cc7fd98
--- /dev/null
+++ b/remote_services/remote_service_admin_api/include/remote_service_admin.h
@@ -0,0 +1,73 @@
+/**
+ *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.
+ */
+/*
+ * remote_service_admin.h
+ *
+ * \date Sep 30, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef REMOTE_SERVICE_ADMIN_H_
+#define REMOTE_SERVICE_ADMIN_H_
+
+#include "endpoint_listener.h"
+#include "service_reference.h"
+#include "export_registration.h"
+#include "import_registration.h"
+
+#define OSGI_RSA_REMOTE_SERVICE_ADMIN "remote_service_admin"
+
+typedef struct import_registration_factory import_registration_factory_t;
+typedef import_registration_factory_t* import_registration_factory_pt;
+
+typedef struct remote_service_admin remote_service_admin_t;
+typedef remote_service_admin_t* remote_service_admin_pt;
+
+struct remote_service_admin_service {
+ remote_service_admin_pt admin;
+ celix_status_t (*exportService)(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
+ celix_status_t (*removeExportedService)(remote_service_admin_pt admin, export_registration_pt registration);
+ celix_status_t (*getExportedServices)(remote_service_admin_pt admin, array_list_pt *services);
+ celix_status_t (*getImportedEndpoints)(remote_service_admin_pt admin, array_list_pt *services);
+ celix_status_t (*importService)(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
+
+ celix_status_t (*exportReference_getExportedEndpoint)(export_reference_pt reference, endpoint_description_pt *endpoint);
+ celix_status_t (*exportReference_getExportedService)(export_reference_pt reference, service_reference_pt *service);
+
+ celix_status_t (*exportRegistration_close)(remote_service_admin_pt admin, export_registration_pt registration);
+ celix_status_t (*exportRegistration_getException)(export_registration_pt registration);
+ celix_status_t (*exportRegistration_getExportReference)(export_registration_pt registration, export_reference_pt *reference);
+ celix_status_t (*exportRegistration_freeExportReference)(export_reference_pt *reference);
+ celix_status_t (*exportRegistration_getEndpointDescription)(export_registration_pt registration, endpoint_description_pt endpointDescription);
+
+ celix_status_t (*importReference_getImportedEndpoint)(import_reference_pt reference);
+ celix_status_t (*importReference_getImportedService)(import_reference_pt reference);
+
+ celix_status_t (*importRegistration_close)(remote_service_admin_pt admin, import_registration_pt registration);
+ celix_status_t (*importRegistration_getException)(import_registration_pt registration);
+ celix_status_t (*importRegistration_getImportReference)(import_registration_pt registration, import_reference_pt *reference);
+
+};
+
+typedef struct remote_service_admin_service remote_service_admin_service_t;
+typedef remote_service_admin_service_t* remote_service_admin_service_pt;
+
+
+#endif /* REMOTE_SERVICE_ADMIN_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_common/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/CMakeLists.txt b/remote_services/remote_service_admin_common/CMakeLists.txt
new file mode 100644
index 0000000..1813211
--- /dev/null
+++ b/remote_services/remote_service_admin_common/CMakeLists.txt
@@ -0,0 +1,24 @@
+# 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.
+
+add_library(remote_service_admin_common STATIC
+ src/endpoint_description.c
+ src/export_registration_impl.c
+ src/import_registration_impl.c
+)
+target_include_directories(remote_service_admin_common PRIVATE src)
+target_link_libraries(remote_service_admin_common PUBLIC Celix::framework Celix::remote_service_admin_api Celix::log_helper)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_common/src/endpoint_description.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/endpoint_description.c b/remote_services/remote_service_admin_common/src/endpoint_description.c
new file mode 100644
index 0000000..0d8b684
--- /dev/null
+++ b/remote_services/remote_service_admin_common/src/endpoint_description.c
@@ -0,0 +1,89 @@
+/**
+ *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.
+ */
+/*
+ * endpoint_description.c
+ *
+ * \date 25 Jul 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <string.h>
+
+#include "celix_errno.h"
+#include "celix_log.h"
+
+#include "endpoint_description.h"
+#include "remote_constants.h"
+#include "constants.h"
+
+static celix_status_t endpointDescription_verifyLongProperty(properties_pt properties, char *propertyName, unsigned long *longProperty);
+
+celix_status_t endpointDescription_create(properties_pt properties, endpoint_description_pt *endpointDescription) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ unsigned long serviceId = 0UL;
+ status = endpointDescription_verifyLongProperty(properties, (char *) OSGI_RSA_ENDPOINT_SERVICE_ID, &serviceId);
+ if (status != CELIX_SUCCESS) {
+ return status;
+ }
+
+ endpoint_description_pt ep = calloc(1,sizeof(*ep));
+
+ ep->properties = properties;
+ ep->frameworkUUID = (char*)properties_get(properties, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
+ ep->id = (char*)properties_get(properties, OSGI_RSA_ENDPOINT_ID);
+ ep->service = strndup(properties_get(properties, OSGI_FRAMEWORK_OBJECTCLASS), 1024*10);
+ ep->serviceId = serviceId;
+
+ if (!(ep->frameworkUUID) || !(ep->id) || !(ep->service) ) {
+ fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "ENDPOINT_DESCRIPTION: incomplete description!.");
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+
+ if(status == CELIX_SUCCESS){
+ *endpointDescription = ep;
+ }
+ else{
+ *endpointDescription = NULL;
+ free(ep);
+ }
+
+ return status;
+}
+
+celix_status_t endpointDescription_destroy(endpoint_description_pt description) {
+ properties_destroy(description->properties);
+ free(description->service);
+ free(description);
+ return CELIX_SUCCESS;
+}
+
+static celix_status_t endpointDescription_verifyLongProperty(properties_pt properties, char *propertyName, unsigned long *longProperty) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ const char *value = properties_get(properties, propertyName);
+ if (value == NULL) {
+ *longProperty = 0UL;
+ } else {
+ *longProperty = strtoul(value,NULL,10);
+ }
+
+ return status;
+}
[16/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/CMakeLists.txt b/pubsub/pubsub_discovery/CMakeLists.txt
index 948da3e..0e7d6c5 100644
--- a/pubsub/pubsub_discovery/CMakeLists.txt
+++ b/pubsub/pubsub_discovery/CMakeLists.txt
@@ -18,26 +18,25 @@
find_package(CURL REQUIRED)
find_package(Jansson REQUIRED)
-include_directories("${CURL_INCLUDE_DIR}")
-include_directories("${JANSSON_INCLUDE_DIR}")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-include_directories("${PROJECT_SOURCE_DIR}/etcdlib/public/include")
-include_directories("private/include")
-include_directories("public/include")
-
add_bundle(org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
BUNDLE_SYMBOLICNAME "apache_celix_pubsub_discovery_etcd"
VERSION "1.0.0"
SOURCES
- private/src/psd_activator.c
- private/src/pubsub_discovery_impl.c
- private/src/etcd_common.c
- private/src/etcd_watcher.c
- private/src/etcd_writer.c
+ src/psd_activator.c
+ src/pubsub_discovery_impl.c
+ src/etcd_common.c
+ src/etcd_watcher.c
+ src/etcd_writer.c
${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_endpoint.c
${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
)
-target_link_libraries(org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery celix_framework celix_utils etcdlib_static ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
+target_include_directories(org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery PRIVATE
+ src
+ include
+ ${CURL_INCLUDE_DIR}
+ ${JANSSON_INCLUDE_DIR}
+ )
+
+target_link_libraries(org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery PRIVATE Celix::framework Celix::etcdlib_static ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
install_bundle(org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/private/include/etcd_common.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/private/include/etcd_common.h b/pubsub/pubsub_discovery/private/include/etcd_common.h
deleted file mode 100644
index 7a3e7b6..0000000
--- a/pubsub/pubsub_discovery/private/include/etcd_common.h
+++ /dev/null
@@ -1,28 +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.
- */
-
-#ifndef ETCD_COMMON_H_
-#define ETCD_COMMON_H_
-
-#include "bundle_context.h"
-#include "celix_errno.h"
-
-celix_status_t etcdCommon_init(bundle_context_pt context);
-
-#endif /* ETCD_COMMON_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/private/include/etcd_watcher.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/private/include/etcd_watcher.h b/pubsub/pubsub_discovery/private/include/etcd_watcher.h
deleted file mode 100644
index c425e60..0000000
--- a/pubsub/pubsub_discovery/private/include/etcd_watcher.h
+++ /dev/null
@@ -1,38 +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.
- */
-
-#ifndef ETCD_WATCHER_H_
-#define ETCD_WATCHER_H_
-
-#include "bundle_context.h"
-#include "celix_errno.h"
-
-#include "pubsub_discovery.h"
-#include "pubsub_endpoint.h"
-
-typedef struct etcd_watcher *etcd_watcher_pt;
-
-celix_status_t etcdWatcher_create(pubsub_discovery_pt discovery, bundle_context_pt context, const char *scope, const char* topic, etcd_watcher_pt *watcher);
-celix_status_t etcdWatcher_destroy(etcd_watcher_pt watcher);
-celix_status_t etcdWatcher_stop(etcd_watcher_pt watcher);
-
-celix_status_t etcdWatcher_getPublisherEndpointFromKey(pubsub_discovery_pt discovery, const char* key, const char* value, pubsub_endpoint_pt* pubEP);
-
-
-#endif /* ETCD_WATCHER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/private/include/etcd_writer.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/private/include/etcd_writer.h b/pubsub/pubsub_discovery/private/include/etcd_writer.h
deleted file mode 100644
index 3ff98b9..0000000
--- a/pubsub/pubsub_discovery/private/include/etcd_writer.h
+++ /dev/null
@@ -1,39 +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.
- */
-
-#ifndef ETCD_WRITER_H_
-#define ETCD_WRITER_H_
-
-#include "bundle_context.h"
-#include "celix_errno.h"
-
-#include "pubsub_discovery.h"
-#include "pubsub_endpoint.h"
-
-typedef struct etcd_writer *etcd_writer_pt;
-
-
-etcd_writer_pt etcdWriter_create(pubsub_discovery_pt discovery);
-void etcdWriter_destroy(etcd_writer_pt writer);
-
-celix_status_t etcdWriter_addPublisherEndpoint(etcd_writer_pt writer, pubsub_endpoint_pt pubEP,bool storeEP);
-celix_status_t etcdWriter_deletePublisherEndpoint(etcd_writer_pt writer, pubsub_endpoint_pt pubEP);
-
-
-#endif /* ETCD_WRITER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/private/include/pubsub_discovery_impl.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/private/include/pubsub_discovery_impl.h b/pubsub/pubsub_discovery/private/include/pubsub_discovery_impl.h
deleted file mode 100644
index 676a6ab..0000000
--- a/pubsub/pubsub_discovery/private/include/pubsub_discovery_impl.h
+++ /dev/null
@@ -1,72 +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.
- */
-
-#ifndef PUBSUB_DISCOVERY_IMPL_H_
-#define PUBSUB_DISCOVERY_IMPL_H_
-
-#include "bundle_context.h"
-#include "service_reference.h"
-
-#include "etcd_watcher.h"
-#include "etcd_writer.h"
-#include "pubsub_endpoint.h"
-
-#define FREE_MEM(ptr) if(ptr) {free(ptr); ptr = NULL;}
-
-struct watcher_info {
- etcd_watcher_pt watcher;
- int nr_references;
-};
-
-struct pubsub_discovery {
- bundle_context_pt context;
-
- celix_thread_mutex_t discoveredPubsMutex;
- hash_map_pt discoveredPubs; //<topic,List<pubsub_endpoint_pt>>
-
- celix_thread_mutex_t listenerReferencesMutex;
- hash_map_pt listenerReferences; //key=serviceReference, value=nop
-
- celix_thread_mutex_t watchersMutex;
- hash_map_pt watchers; //key = topicname, value = struct watcher_info
-
- etcd_writer_pt writer;
-};
-
-
-celix_status_t pubsub_discovery_create(bundle_context_pt context, pubsub_discovery_pt* node_discovery);
-celix_status_t pubsub_discovery_destroy(pubsub_discovery_pt node_discovery);
-celix_status_t pubsub_discovery_start(pubsub_discovery_pt node_discovery);
-celix_status_t pubsub_discovery_stop(pubsub_discovery_pt node_discovery);
-
-celix_status_t pubsub_discovery_addNode(pubsub_discovery_pt node_discovery, pubsub_endpoint_pt pubEP);
-celix_status_t pubsub_discovery_removeNode(pubsub_discovery_pt node_discovery, pubsub_endpoint_pt pubEP);
-
-celix_status_t pubsub_discovery_tmPublisherAnnounceAdded(void * handle, service_reference_pt reference, void * service);
-celix_status_t pubsub_discovery_tmPublisherAnnounceModified(void * handle, service_reference_pt reference, void * service);
-celix_status_t pubsub_discovery_tmPublisherAnnounceRemoved(void * handle, service_reference_pt reference, void * service);
-
-celix_status_t pubsub_discovery_announcePublisher(void *handle, pubsub_endpoint_pt pubEP);
-celix_status_t pubsub_discovery_removePublisher(void *handle, pubsub_endpoint_pt pubEP);
-celix_status_t pubsub_discovery_interestedInTopic(void *handle, const char* scope, const char* topic);
-celix_status_t pubsub_discovery_uninterestedInTopic(void *handle, const char* scope, const char* topic);
-
-celix_status_t pubsub_discovery_informPublishersListeners(pubsub_discovery_pt discovery, pubsub_endpoint_pt endpoint, bool endpointAdded);
-
-#endif /* PUBSUB_DISCOVERY_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/private/src/etcd_common.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/private/src/etcd_common.c b/pubsub/pubsub_discovery/private/src/etcd_common.c
deleted file mode 100644
index c757801..0000000
--- a/pubsub/pubsub_discovery/private/src/etcd_common.c
+++ /dev/null
@@ -1,82 +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.
- */
-
-#include <stdbool.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "celix_log.h"
-#include "constants.h"
-
-#include <curl/curl.h>
-#include "etcd.h"
-#include "etcd_watcher.h"
-
-#include "pubsub_discovery.h"
-#include "pubsub_discovery_impl.h"
-
-
-#define MAX_ROOTNODE_LENGTH 128
-#define MAX_LOCALNODE_LENGTH 4096
-#define MAX_FIELD_LENGTH 128
-
-#define CFG_ETCD_SERVER_IP "PUBSUB_DISCOVERY_ETCD_SERVER_IP"
-#define DEFAULT_ETCD_SERVER_IP "127.0.0.1"
-
-#define CFG_ETCD_SERVER_PORT "PUBSUB_DISCOVERY_ETCD_SERVER_PORT"
-#define DEFAULT_ETCD_SERVER_PORT 2379
-
-// be careful - this should be higher than the curl timeout
-#define CFG_ETCD_TTL "DISCOVERY_ETCD_TTL"
-#define DEFAULT_ETCD_TTL 30
-
-
-celix_status_t etcdCommon_init(bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- const char* etcd_server = NULL;
- const char* etcd_port_string = NULL;
- int etcd_port = 0;
-
- if ((bundleContext_getProperty(context, CFG_ETCD_SERVER_IP, &etcd_server) != CELIX_SUCCESS) || !etcd_server) {
- etcd_server = DEFAULT_ETCD_SERVER_IP;
- }
-
- if ((bundleContext_getProperty(context, CFG_ETCD_SERVER_PORT, &etcd_port_string) != CELIX_SUCCESS) || !etcd_port_string) {
- etcd_port = DEFAULT_ETCD_SERVER_PORT;
- } else {
- char* endptr = NULL;
- errno = 0;
- etcd_port = strtol(etcd_port_string, &endptr, 10);
- if (*endptr || errno != 0) {
- etcd_port = DEFAULT_ETCD_SERVER_PORT;
- }
- }
-
- printf("PSD: Using discovery HOST:PORT: %s:%i\n", etcd_server, etcd_port);
-
- if (etcd_init(etcd_server, etcd_port, CURL_GLOBAL_DEFAULT) != 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- status = CELIX_SUCCESS;
- }
-
- return status;
-}
-
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/private/src/etcd_watcher.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/private/src/etcd_watcher.c b/pubsub/pubsub_discovery/private/src/etcd_watcher.c
deleted file mode 100644
index 3c3a5a8..0000000
--- a/pubsub/pubsub_discovery/private/src/etcd_watcher.c
+++ /dev/null
@@ -1,290 +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.
- */
-
-#include <stdbool.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "celix_log.h"
-#include "constants.h"
-
-#include "etcd.h"
-#include "etcd_watcher.h"
-
-#include "pubsub_discovery.h"
-#include "pubsub_discovery_impl.h"
-
-
-
-#define MAX_ROOTNODE_LENGTH 128
-#define MAX_LOCALNODE_LENGTH 4096
-#define MAX_FIELD_LENGTH 128
-
-#define CFG_ETCD_ROOT_PATH "PUBSUB_DISCOVERY_ETCD_ROOT_PATH"
-#define DEFAULT_ETCD_ROOTPATH "pubsub/discovery"
-
-#define CFG_ETCD_SERVER_IP "PUBSUB_DISCOVERY_ETCD_SERVER_IP"
-#define DEFAULT_ETCD_SERVER_IP "127.0.0.1"
-
-#define CFG_ETCD_SERVER_PORT "PUBSUB_DISCOVERY_ETCD_SERVER_PORT"
-#define DEFAULT_ETCD_SERVER_PORT 2379
-
-// be careful - this should be higher than the curl timeout
-#define CFG_ETCD_TTL "DISCOVERY_ETCD_TTL"
-#define DEFAULT_ETCD_TTL 30
-
-
-struct etcd_watcher {
- pubsub_discovery_pt pubsub_discovery;
-
- celix_thread_mutex_t watcherLock;
- celix_thread_t watcherThread;
-
- char *scope;
- char *topic;
- volatile bool running;
-};
-
-struct etcd_writer {
- pubsub_discovery_pt pubsub_discovery;
- celix_thread_mutex_t localPubsLock;
- array_list_pt localPubs;
- volatile bool running;
- celix_thread_t writerThread;
-};
-
-
-// note that the rootNode shouldn't have a leading slash
-static celix_status_t etcdWatcher_getTopicRootPath(bundle_context_pt context, const char *scope, const char *topic, char* rootNode, int rootNodeLen) {
- celix_status_t status = CELIX_SUCCESS;
- const char* rootPath = NULL;
-
- if (((bundleContext_getProperty(context, CFG_ETCD_ROOT_PATH, &rootPath)) != CELIX_SUCCESS) || (!rootPath)) {
- snprintf(rootNode, rootNodeLen, "%s/%s/%s", DEFAULT_ETCD_ROOTPATH, scope, topic);
- } else {
- snprintf(rootNode, rootNodeLen, "%s/%s/%s", rootPath, scope, topic);
- }
-
- return status;
-}
-
-static celix_status_t etcdWatcher_getRootPath(bundle_context_pt context, char* rootNode) {
- celix_status_t status = CELIX_SUCCESS;
- const char* rootPath = NULL;
-
- if (((bundleContext_getProperty(context, CFG_ETCD_ROOT_PATH, &rootPath)) != CELIX_SUCCESS) || (!rootPath)) {
- strncpy(rootNode, DEFAULT_ETCD_ROOTPATH, MAX_ROOTNODE_LENGTH);
- } else {
- strncpy(rootNode, rootPath, MAX_ROOTNODE_LENGTH);
- }
-
- return status;
-}
-
-
-static void add_node(const char *key, const char *value, void* arg) {
- pubsub_discovery_pt ps_discovery = (pubsub_discovery_pt) arg;
- pubsub_endpoint_pt pubEP = NULL;
- celix_status_t status = etcdWatcher_getPublisherEndpointFromKey(ps_discovery, key, value, &pubEP);
- if(!status && pubEP) {
- pubsub_discovery_addNode(ps_discovery, pubEP);
- }
-}
-
-static celix_status_t etcdWatcher_addAlreadyExistingPublishers(pubsub_discovery_pt ps_discovery, const char *rootPath, long long * highestModified) {
- celix_status_t status = CELIX_SUCCESS;
- if(etcd_get_directory(rootPath, add_node, ps_discovery, highestModified)) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
- return status;
-}
-
-// gets everything from provided key
-celix_status_t etcdWatcher_getPublisherEndpointFromKey(pubsub_discovery_pt pubsub_discovery, const char* etcdKey, const char* etcdValue, pubsub_endpoint_pt* pubEP) {
-
- celix_status_t status = CELIX_SUCCESS;
-
- char rootPath[MAX_ROOTNODE_LENGTH];
- char *expr = NULL;
- char scope[MAX_FIELD_LENGTH];
- char topic[MAX_FIELD_LENGTH];
- char fwUUID[MAX_FIELD_LENGTH];
- char serviceId[MAX_FIELD_LENGTH];
-
- memset(rootPath,0,MAX_ROOTNODE_LENGTH);
- memset(topic,0,MAX_FIELD_LENGTH);
- memset(fwUUID,0,MAX_FIELD_LENGTH);
- memset(serviceId,0,MAX_FIELD_LENGTH);
-
- etcdWatcher_getRootPath(pubsub_discovery->context, rootPath);
-
- asprintf(&expr, "/%s/%%[^/]/%%[^/]/%%[^/]/%%[^/].*", rootPath);
- if(expr) {
- int foundItems = sscanf(etcdKey, expr, scope, topic, fwUUID, serviceId);
- free(expr);
- if (foundItems != 4) { // Could happen when a directory is removed, just don't process this.
- status = CELIX_ILLEGAL_STATE;
- }
- else{
- status = pubsubEndpoint_create(fwUUID,scope,topic,strtol(serviceId,NULL,10),etcdValue,NULL,pubEP);
- }
- }
- return status;
-}
-
-/*
- * performs (blocking) etcd_watch calls to check for
- * changing discovery endpoint information within etcd.
- */
-static void* etcdWatcher_run(void* data) {
- etcd_watcher_pt watcher = (etcd_watcher_pt) data;
- time_t timeBeforeWatch = time(NULL);
- char rootPath[MAX_ROOTNODE_LENGTH];
- long long highestModified = 0;
-
- pubsub_discovery_pt ps_discovery = watcher->pubsub_discovery;
- bundle_context_pt context = ps_discovery->context;
-
- memset(rootPath, 0, MAX_ROOTNODE_LENGTH);
-
- //TODO: add topic to etcd key
- etcdWatcher_getTopicRootPath(context, watcher->scope, watcher->topic, rootPath, MAX_ROOTNODE_LENGTH);
- etcdWatcher_addAlreadyExistingPublishers(ps_discovery, rootPath, &highestModified);
-
- while ((celixThreadMutex_lock(&watcher->watcherLock) == CELIX_SUCCESS) && watcher->running) {
-
- char *rkey = NULL;
- char *value = NULL;
- char *preValue = NULL;
- char *action = NULL;
- long long modIndex;
-
- celixThreadMutex_unlock(&watcher->watcherLock);
-
- if (etcd_watch(rootPath, highestModified + 1, &action, &preValue, &value, &rkey, &modIndex) == 0 && action != NULL) {
- pubsub_endpoint_pt pubEP = NULL;
- if ((strcmp(action, "set") == 0) || (strcmp(action, "create") == 0)) {
- if (etcdWatcher_getPublisherEndpointFromKey(ps_discovery, rkey, value, &pubEP) == CELIX_SUCCESS) {
- pubsub_discovery_addNode(ps_discovery, pubEP);
- }
- } else if (strcmp(action, "delete") == 0) {
- if (etcdWatcher_getPublisherEndpointFromKey(ps_discovery, rkey, preValue, &pubEP) == CELIX_SUCCESS) {
- pubsub_discovery_removeNode(ps_discovery, pubEP);
- }
- } else if (strcmp(action, "expire") == 0) {
- if (etcdWatcher_getPublisherEndpointFromKey(ps_discovery, rkey, preValue, &pubEP) == CELIX_SUCCESS) {
- pubsub_discovery_removeNode(ps_discovery, pubEP);
- }
- } else if (strcmp(action, "update") == 0) {
- if (etcdWatcher_getPublisherEndpointFromKey(ps_discovery, rkey, value, &pubEP) == CELIX_SUCCESS) {
- pubsub_discovery_addNode(ps_discovery, pubEP);
- }
- } else {
- fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "Unexpected action: %s", action);
- }
- highestModified = modIndex;
- } else if (time(NULL) - timeBeforeWatch <= (DEFAULT_ETCD_TTL / 4)) {
- sleep(DEFAULT_ETCD_TTL / 4);
- }
-
- FREE_MEM(action);
- FREE_MEM(value);
- FREE_MEM(preValue);
- FREE_MEM(rkey);
-
- /* prevent busy waiting, in case etcd_watch returns false */
-
-
- if (time(NULL) - timeBeforeWatch > (DEFAULT_ETCD_TTL / 4)) {
- timeBeforeWatch = time(NULL);
- }
-
- }
-
- if (watcher->running == false) {
- celixThreadMutex_unlock(&watcher->watcherLock);
- }
-
- return NULL;
-}
-
-celix_status_t etcdWatcher_create(pubsub_discovery_pt pubsub_discovery, bundle_context_pt context, const char *scope, const char *topic, etcd_watcher_pt *watcher) {
- celix_status_t status = CELIX_SUCCESS;
-
-
- if (pubsub_discovery == NULL) {
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- (*watcher) = calloc(1, sizeof(struct etcd_watcher));
-
- if(*watcher == NULL){
- return CELIX_ENOMEM;
- }
-
- (*watcher)->pubsub_discovery = pubsub_discovery;
- (*watcher)->scope = strdup(scope);
- (*watcher)->topic = strdup(topic);
-
-
- celixThreadMutex_create(&(*watcher)->watcherLock, NULL);
-
- celixThreadMutex_lock(&(*watcher)->watcherLock);
-
- status = celixThread_create(&(*watcher)->watcherThread, NULL, etcdWatcher_run, *watcher);
- if (status == CELIX_SUCCESS) {
- (*watcher)->running = true;
- }
-
- celixThreadMutex_unlock(&(*watcher)->watcherLock);
-
-
- return status;
-}
-
-celix_status_t etcdWatcher_destroy(etcd_watcher_pt watcher) {
-
- celix_status_t status = CELIX_SUCCESS;
-
- char rootPath[MAX_ROOTNODE_LENGTH];
- etcdWatcher_getTopicRootPath(watcher->pubsub_discovery->context, watcher->scope, watcher->topic, rootPath, MAX_ROOTNODE_LENGTH);
- celixThreadMutex_destroy(&(watcher->watcherLock));
-
- free(watcher->scope);
- free(watcher->topic);
- free(watcher);
-
- return status;
-}
-
-celix_status_t etcdWatcher_stop(etcd_watcher_pt watcher){
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&(watcher->watcherLock));
- watcher->running = false;
- celixThreadMutex_unlock(&(watcher->watcherLock));
-
- celixThread_join(watcher->watcherThread, NULL);
-
- return status;
-
-}
-
-
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/private/src/etcd_writer.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/private/src/etcd_writer.c b/pubsub/pubsub_discovery/private/src/etcd_writer.c
deleted file mode 100644
index 1c423f3..0000000
--- a/pubsub/pubsub_discovery/private/src/etcd_writer.c
+++ /dev/null
@@ -1,189 +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.
- */
-
-#include <stdbool.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "celix_log.h"
-#include "constants.h"
-
-#include "etcd.h"
-#include "etcd_writer.h"
-
-#include "pubsub_discovery.h"
-#include "pubsub_discovery_impl.h"
-
-#define MAX_ROOTNODE_LENGTH 128
-
-#define CFG_ETCD_ROOT_PATH "PUBSUB_DISCOVERY_ETCD_ROOT_PATH"
-#define DEFAULT_ETCD_ROOTPATH "pubsub/discovery"
-
-#define CFG_ETCD_SERVER_IP "PUBSUB_DISCOVERY_ETCD_SERVER_IP"
-#define DEFAULT_ETCD_SERVER_IP "127.0.0.1"
-
-#define CFG_ETCD_SERVER_PORT "PUBSUB_DISCOVERY_ETCD_SERVER_PORT"
-#define DEFAULT_ETCD_SERVER_PORT 2379
-
-// be careful - this should be higher than the curl timeout
-#define CFG_ETCD_TTL "DISCOVERY_ETCD_TTL"
-#define DEFAULT_ETCD_TTL 30
-
-struct etcd_writer {
- pubsub_discovery_pt pubsub_discovery;
- celix_thread_mutex_t localPubsLock;
- array_list_pt localPubs;
- volatile bool running;
- celix_thread_t writerThread;
-};
-
-
-static const char* etcdWriter_getRootPath(bundle_context_pt context);
-static void* etcdWriter_run(void* data);
-
-
-etcd_writer_pt etcdWriter_create(pubsub_discovery_pt disc) {
- etcd_writer_pt writer = calloc(1, sizeof(*writer));
- if(writer) {
- celixThreadMutex_create(&writer->localPubsLock, NULL);
- arrayList_create(&writer->localPubs);
- writer->pubsub_discovery = disc;
- writer->running = true;
- celixThread_create(&writer->writerThread, NULL, etcdWriter_run, writer);
- }
- return writer;
-}
-
-void etcdWriter_destroy(etcd_writer_pt writer) {
- char dir[MAX_ROOTNODE_LENGTH];
- const char *rootPath = etcdWriter_getRootPath(writer->pubsub_discovery->context);
-
- writer->running = false;
- celixThread_join(writer->writerThread, NULL);
-
- celixThreadMutex_lock(&writer->localPubsLock);
- for(int i = 0; i < arrayList_size(writer->localPubs); i++) {
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(writer->localPubs,i);
- memset(dir,0,MAX_ROOTNODE_LENGTH);
- snprintf(dir,MAX_ROOTNODE_LENGTH,"%s/%s/%s/%s",rootPath,pubEP->scope,pubEP->topic,pubEP->frameworkUUID);
- etcd_del(dir);
- pubsubEndpoint_destroy(pubEP);
- }
- arrayList_destroy(writer->localPubs);
-
- celixThreadMutex_unlock(&writer->localPubsLock);
- celixThreadMutex_destroy(&(writer->localPubsLock));
-
- free(writer);
-}
-
-celix_status_t etcdWriter_addPublisherEndpoint(etcd_writer_pt writer, pubsub_endpoint_pt pubEP, bool storeEP){
- celix_status_t status = CELIX_BUNDLE_EXCEPTION;
-
- if(storeEP){
- const char *fwUUID = NULL;
- bundleContext_getProperty(writer->pubsub_discovery->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &fwUUID);
- if(fwUUID && strcmp(pubEP->frameworkUUID, fwUUID) == 0) {
- celixThreadMutex_lock(&writer->localPubsLock);
- pubsub_endpoint_pt p = NULL;
- pubsubEndpoint_clone(pubEP, &p);
- arrayList_add(writer->localPubs,p);
- celixThreadMutex_unlock(&writer->localPubsLock);
- }
- }
-
- char *key;
-
- const char* ttlStr = NULL;
- int ttl = 0;
-
- // determine ttl
- if ((bundleContext_getProperty(writer->pubsub_discovery->context, CFG_ETCD_TTL, &ttlStr) != CELIX_SUCCESS) || !ttlStr) {
- ttl = DEFAULT_ETCD_TTL;
- } else {
- char* endptr = NULL;
- errno = 0;
- ttl = strtol(ttlStr, &endptr, 10);
- if (*endptr || errno != 0) {
- ttl = DEFAULT_ETCD_TTL;
- }
- }
-
- const char *rootPath = etcdWriter_getRootPath(writer->pubsub_discovery->context);
-
- asprintf(&key,"%s/%s/%s/%s/%ld",rootPath,pubEP->scope,pubEP->topic,pubEP->frameworkUUID,pubEP->serviceID);
-
- if(!etcd_set(key,pubEP->endpoint,ttl,false)){
- status = CELIX_ILLEGAL_ARGUMENT;
- }
- FREE_MEM(key);
- return status;
-}
-
-celix_status_t etcdWriter_deletePublisherEndpoint(etcd_writer_pt writer, pubsub_endpoint_pt pubEP) {
- celix_status_t status = CELIX_SUCCESS;
- char *key = NULL;
-
- const char *rootPath = etcdWriter_getRootPath(writer->pubsub_discovery->context);
-
- asprintf(&key, "%s/%s/%s/%s/%ld", rootPath, pubEP->scope, pubEP->topic, pubEP->frameworkUUID, pubEP->serviceID);
-
- celixThreadMutex_lock(&writer->localPubsLock);
- for (unsigned int i = 0; i < arrayList_size(writer->localPubs); i++) {
- pubsub_endpoint_pt ep = arrayList_get(writer->localPubs, i);
- if (pubsubEndpoint_equals(ep, pubEP)) {
- arrayList_remove(writer->localPubs, i);
- pubsubEndpoint_destroy(ep);
- break;
- }
- }
- celixThreadMutex_unlock(&writer->localPubsLock);
-
- if (etcd_del(key)) {
- printf("Failed to remove key %s from ETCD\n",key);
- status = CELIX_ILLEGAL_ARGUMENT;
- }
- FREE_MEM(key);
- return status;
-}
-
-static void* etcdWriter_run(void* data) {
- etcd_writer_pt writer = (etcd_writer_pt)data;
- while(writer->running) {
- celixThreadMutex_lock(&writer->localPubsLock);
- for(int i=0; i < arrayList_size(writer->localPubs); i++) {
- etcdWriter_addPublisherEndpoint(writer,(pubsub_endpoint_pt)arrayList_get(writer->localPubs,i),false);
- }
- celixThreadMutex_unlock(&writer->localPubsLock);
- sleep(DEFAULT_ETCD_TTL / 2);
- }
-
- return NULL;
-}
-
-static const char* etcdWriter_getRootPath(bundle_context_pt context) {
- const char* rootPath = NULL;
- bundleContext_getProperty(context, CFG_ETCD_ROOT_PATH, &rootPath);
- if(rootPath == NULL) {
- rootPath = DEFAULT_ETCD_ROOTPATH;
- }
- return rootPath;
-}
-
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/private/src/psd_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/private/src/psd_activator.c b/pubsub/pubsub_discovery/private/src/psd_activator.c
deleted file mode 100644
index 89a517d..0000000
--- a/pubsub/pubsub_discovery/private/src/psd_activator.c
+++ /dev/null
@@ -1,171 +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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "bundle_activator.h"
-#include "service_tracker.h"
-#include "service_registration.h"
-#include "constants.h"
-#include "celix_log.h"
-
-#include "pubsub_common.h"
-#include "publisher_endpoint_announce.h"
-#include "pubsub_discovery.h"
-#include "pubsub_discovery_impl.h"
-
-struct activator {
- bundle_context_pt context;
- pubsub_discovery_pt pubsub_discovery;
-
- service_tracker_pt pstmPublishersTracker;
-
- publisher_endpoint_announce_pt publisherEPAnnounce;
- service_registration_pt publisherEPAnnounceService;
-};
-
-static celix_status_t createTMPublisherAnnounceTracker(struct activator *activator, service_tracker_pt *tracker) {
- celix_status_t status = CELIX_SUCCESS;
-
- service_tracker_customizer_pt customizer = NULL;
-
- status = serviceTrackerCustomizer_create(activator->pubsub_discovery,
- NULL,
- pubsub_discovery_tmPublisherAnnounceAdded,
- pubsub_discovery_tmPublisherAnnounceModified,
- pubsub_discovery_tmPublisherAnnounceRemoved,
- &customizer);
-
- if (status == CELIX_SUCCESS) {
- status = serviceTracker_create(activator->context, (char *) PUBSUB_TM_ANNOUNCE_PUBLISHER_SERVICE, customizer, tracker);
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status = CELIX_SUCCESS;
-
- struct activator* activator = calloc(1, sizeof(*activator));
-
- if (activator) {
- activator->context = context;
- activator->pstmPublishersTracker = NULL;
- activator->publisherEPAnnounce = NULL;
- activator->publisherEPAnnounceService = NULL;
-
- status = pubsub_discovery_create(context, &activator->pubsub_discovery);
-
- if (status == CELIX_SUCCESS) {
- status = createTMPublisherAnnounceTracker(activator, &(activator->pstmPublishersTracker));
- }
-
- if (status == CELIX_SUCCESS) {
- *userData = activator;
- } else {
- free(activator);
- }
- } else {
- status = CELIX_ENOMEM;
- }
-
- return status;
-
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
-
- struct activator *activator = userData;
-
- publisher_endpoint_announce_pt pubEPAnnouncer = calloc(1, sizeof(*pubEPAnnouncer));
-
- if (pubEPAnnouncer) {
-
- pubEPAnnouncer->handle = activator->pubsub_discovery;
- pubEPAnnouncer->announcePublisher = pubsub_discovery_announcePublisher;
- pubEPAnnouncer->removePublisher = pubsub_discovery_removePublisher;
- pubEPAnnouncer->interestedInTopic = pubsub_discovery_interestedInTopic;
- pubEPAnnouncer->uninterestedInTopic = pubsub_discovery_uninterestedInTopic;
- activator->publisherEPAnnounce = pubEPAnnouncer;
-
- properties_pt props = properties_create();
- properties_set(props, "PUBSUB_DISCOVERY", "true");
-
- // pubsub_discovery_start needs to be first to initalize the propert etcd_watcher values
- status = pubsub_discovery_start(activator->pubsub_discovery);
-
- if (status == CELIX_SUCCESS) {
- status = serviceTracker_open(activator->pstmPublishersTracker);
- }
-
- if (status == CELIX_SUCCESS) {
- status = bundleContext_registerService(context, (char *) PUBSUB_DISCOVERY_SERVICE, pubEPAnnouncer, props, &activator->publisherEPAnnounceService);
- }
-
-
- }
- else{
- status = CELIX_ENOMEM;
- }
-
- if(status!=CELIX_SUCCESS && pubEPAnnouncer!=NULL){
- free(pubEPAnnouncer);
- }
-
-
- return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- status += pubsub_discovery_stop(activator->pubsub_discovery);
-
- status += serviceTracker_close(activator->pstmPublishersTracker);
-
- status += serviceRegistration_unregister(activator->publisherEPAnnounceService);
-
- if (status == CELIX_SUCCESS) {
- free(activator->publisherEPAnnounce);
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- status += serviceTracker_destroy(activator->pstmPublishersTracker);
- status += pubsub_discovery_destroy(activator->pubsub_discovery);
-
- activator->publisherEPAnnounce = NULL;
- activator->publisherEPAnnounceService = NULL;
- activator->pstmPublishersTracker = NULL;
- activator->pubsub_discovery = NULL;
- activator->context = NULL;
-
- free(activator);
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/private/src/pubsub_discovery_impl.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/private/src/pubsub_discovery_impl.c b/pubsub/pubsub_discovery/private/src/pubsub_discovery_impl.c
deleted file mode 100644
index 94a8e11..0000000
--- a/pubsub/pubsub_discovery/private/src/pubsub_discovery_impl.c
+++ /dev/null
@@ -1,457 +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.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdbool.h>
-#include <netdb.h>
-#include <netinet/in.h>
-
-#include "constants.h"
-#include "celix_threads.h"
-#include "bundle_context.h"
-#include "array_list.h"
-#include "utils.h"
-#include "celix_errno.h"
-#include "filter.h"
-#include "service_reference.h"
-#include "service_registration.h"
-
-#include "publisher_endpoint_announce.h"
-#include "etcd_common.h"
-#include "etcd_watcher.h"
-#include "etcd_writer.h"
-#include "pubsub_endpoint.h"
-#include "pubsub_discovery_impl.h"
-
-/* Discovery activator functions */
-celix_status_t pubsub_discovery_create(bundle_context_pt context, pubsub_discovery_pt *ps_discovery) {
- celix_status_t status = CELIX_SUCCESS;
-
- *ps_discovery = calloc(1, sizeof(**ps_discovery));
-
- if (*ps_discovery == NULL) {
- status = CELIX_ENOMEM;
- }
- else{
- (*ps_discovery)->context = context;
- (*ps_discovery)->discoveredPubs = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- (*ps_discovery)->listenerReferences = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
- (*ps_discovery)->watchers = hashMap_create(utils_stringHash,NULL,utils_stringEquals, NULL);
- celixThreadMutex_create(&(*ps_discovery)->listenerReferencesMutex, NULL);
- celixThreadMutex_create(&(*ps_discovery)->discoveredPubsMutex, NULL);
- celixThreadMutex_create(&(*ps_discovery)->watchersMutex, NULL);
- }
-
- return status;
-}
-
-celix_status_t pubsub_discovery_destroy(pubsub_discovery_pt ps_discovery) {
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&ps_discovery->discoveredPubsMutex);
-
- hash_map_iterator_pt iter = hashMapIterator_create(ps_discovery->discoveredPubs);
-
- while (hashMapIterator_hasNext(iter)) {
- array_list_pt pubEP_list = (array_list_pt) hashMapIterator_nextValue(iter);
-
- for(int i=0; i < arrayList_size(pubEP_list); i++) {
- pubsubEndpoint_destroy(((pubsub_endpoint_pt)arrayList_get(pubEP_list,i)));
- }
- arrayList_destroy(pubEP_list);
- }
-
- hashMapIterator_destroy(iter);
-
- hashMap_destroy(ps_discovery->discoveredPubs, true, false);
- ps_discovery->discoveredPubs = NULL;
-
- celixThreadMutex_unlock(&ps_discovery->discoveredPubsMutex);
-
- celixThreadMutex_destroy(&ps_discovery->discoveredPubsMutex);
-
-
- celixThreadMutex_lock(&ps_discovery->listenerReferencesMutex);
-
- hashMap_destroy(ps_discovery->listenerReferences, false, false);
- ps_discovery->listenerReferences = NULL;
-
- celixThreadMutex_unlock(&ps_discovery->listenerReferencesMutex);
-
- celixThreadMutex_destroy(&ps_discovery->listenerReferencesMutex);
-
- free(ps_discovery);
-
- return status;
-}
-
-celix_status_t pubsub_discovery_start(pubsub_discovery_pt ps_discovery) {
- celix_status_t status = CELIX_SUCCESS;
- status = etcdCommon_init(ps_discovery->context);
- ps_discovery->writer = etcdWriter_create(ps_discovery);
-
- return status;
-}
-
-celix_status_t pubsub_discovery_stop(pubsub_discovery_pt ps_discovery) {
- celix_status_t status = CELIX_SUCCESS;
-
- const char* fwUUID = NULL;
-
- bundleContext_getProperty(ps_discovery->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &fwUUID);
- if (fwUUID == NULL) {
- printf("PSD: Cannot retrieve fwUUID.\n");
- return CELIX_INVALID_BUNDLE_CONTEXT;
- }
-
- celixThreadMutex_lock(&ps_discovery->watchersMutex);
-
- hash_map_iterator_pt iter = hashMapIterator_create(ps_discovery->watchers);
- while (hashMapIterator_hasNext(iter)) {
- struct watcher_info * wi = hashMapIterator_nextValue(iter);
- etcdWatcher_stop(wi->watcher);
- }
- hashMapIterator_destroy(iter);
-
- celixThreadMutex_lock(&ps_discovery->discoveredPubsMutex);
-
- /* Unexport all publishers for the local framework, and also delete from ETCD publisher belonging to the local framework */
-
- iter = hashMapIterator_create(ps_discovery->discoveredPubs);
- while (hashMapIterator_hasNext(iter)) {
- array_list_pt pubEP_list = (array_list_pt) hashMapIterator_nextValue(iter);
-
- int i;
- for (i = 0; i < arrayList_size(pubEP_list); i++) {
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt) arrayList_get(pubEP_list, i);
- if (strcmp(pubEP->frameworkUUID, fwUUID) == 0) {
- etcdWriter_deletePublisherEndpoint(ps_discovery->writer, pubEP);
- } else {
- pubsub_discovery_informPublishersListeners(ps_discovery, pubEP, false);
- arrayList_remove(pubEP_list, i);
- pubsubEndpoint_destroy(pubEP);
- i--;
- }
- }
- }
-
- hashMapIterator_destroy(iter);
-
- celixThreadMutex_unlock(&ps_discovery->discoveredPubsMutex);
- etcdWriter_destroy(ps_discovery->writer);
-
- iter = hashMapIterator_create(ps_discovery->watchers);
- while (hashMapIterator_hasNext(iter)) {
- struct watcher_info * wi = hashMapIterator_nextValue(iter);
- etcdWatcher_destroy(wi->watcher);
- }
- hashMapIterator_destroy(iter);
- hashMap_destroy(ps_discovery->watchers, true, true);
- celixThreadMutex_unlock(&ps_discovery->watchersMutex);
- return status;
-}
-
-/* Functions called by the etcd_watcher */
-
-celix_status_t pubsub_discovery_addNode(pubsub_discovery_pt pubsub_discovery, pubsub_endpoint_pt pubEP) {
- celix_status_t status = CELIX_SUCCESS;
- bool inform=false;
- celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex);
-
- char *pubs_key = createScopeTopicKey(pubEP->scope, pubEP->topic);
- array_list_pt pubEP_list = (array_list_pt)hashMap_get(pubsub_discovery->discoveredPubs,pubs_key);
- if(pubEP_list==NULL){
- arrayList_create(&pubEP_list);
- arrayList_add(pubEP_list,pubEP);
- hashMap_put(pubsub_discovery->discoveredPubs,strdup(pubs_key),pubEP_list);
- inform=true;
- }
- else{
- int i;
- bool found = false;
- for(i=0;i<arrayList_size(pubEP_list) && !found;i++){
- found = pubsubEndpoint_equals(pubEP,(pubsub_endpoint_pt)arrayList_get(pubEP_list,i));
- }
- if(found){
- pubsubEndpoint_destroy(pubEP);
- }
- else{
- arrayList_add(pubEP_list,pubEP);
- inform=true;
- }
- }
- free(pubs_key);
-
- celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex);
-
- if(inform){
- status = pubsub_discovery_informPublishersListeners(pubsub_discovery,pubEP,true);
- }
-
- return status;
-}
-
-celix_status_t pubsub_discovery_removeNode(pubsub_discovery_pt pubsub_discovery, pubsub_endpoint_pt pubEP) {
- celix_status_t status = CELIX_SUCCESS;
- pubsub_endpoint_pt p = NULL;
- bool found = false;
-
- celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex);
- char *pubs_key = createScopeTopicKey(pubEP->scope, pubEP->topic);
- array_list_pt pubEP_list = (array_list_pt) hashMap_get(pubsub_discovery->discoveredPubs, pubs_key);
- free(pubs_key);
- if (pubEP_list == NULL) {
- printf("PSD: Cannot find any registered publisher for topic %s. Something is not consistent.\n", pubEP->topic);
- status = CELIX_ILLEGAL_STATE;
- } else {
- int i;
-
- for (i = 0; !found && i < arrayList_size(pubEP_list); i++) {
- p = arrayList_get(pubEP_list, i);
- found = pubsubEndpoint_equals(pubEP, p);
- if (found) {
- arrayList_remove(pubEP_list, i);
- pubsubEndpoint_destroy(p);
- }
- }
- }
-
- celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex);
- if (found) {
- status = pubsub_discovery_informPublishersListeners(pubsub_discovery, pubEP, false);
- }
- pubsubEndpoint_destroy(pubEP);
-
- return status;
-}
-
-/* Callback to the pubsub_topology_manager */
-celix_status_t pubsub_discovery_informPublishersListeners(pubsub_discovery_pt pubsub_discovery, pubsub_endpoint_pt pubEP, bool epAdded) {
- celix_status_t status = CELIX_SUCCESS;
-
- // Inform listeners of new publisher endpoint
- celixThreadMutex_lock(&pubsub_discovery->listenerReferencesMutex);
-
- if (pubsub_discovery->listenerReferences != NULL) {
- hash_map_iterator_pt iter = hashMapIterator_create(pubsub_discovery->listenerReferences);
- while (hashMapIterator_hasNext(iter)) {
- service_reference_pt reference = hashMapIterator_nextKey(iter);
-
- publisher_endpoint_announce_pt listener = NULL;
-
- bundleContext_getService(pubsub_discovery->context, reference, (void**) &listener);
- if (epAdded) {
- listener->announcePublisher(listener->handle, pubEP);
- } else {
- listener->removePublisher(listener->handle, pubEP);
- }
- bundleContext_ungetService(pubsub_discovery->context, reference, NULL);
- }
- hashMapIterator_destroy(iter);
- }
-
- celixThreadMutex_unlock(&pubsub_discovery->listenerReferencesMutex);
-
- return status;
-}
-
-
-/* Service's functions implementation */
-celix_status_t pubsub_discovery_announcePublisher(void *handle, pubsub_endpoint_pt pubEP) {
- celix_status_t status = CELIX_SUCCESS;
- printf("pubsub_discovery_announcePublisher : %s / %s\n", pubEP->topic, pubEP->endpoint);
- pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt) handle;
-
- celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex);
-
- char *pub_key = createScopeTopicKey(pubEP->scope,pubEP->topic);
- array_list_pt pubEP_list = (array_list_pt)hashMap_get(pubsub_discovery->discoveredPubs,pub_key);
-
- if(pubEP_list==NULL){
- arrayList_create(&pubEP_list);
- hashMap_put(pubsub_discovery->discoveredPubs,strdup(pub_key),pubEP_list);
- }
- free(pub_key);
- pubsub_endpoint_pt p = NULL;
- pubsubEndpoint_clone(pubEP, &p);
-
- arrayList_add(pubEP_list,p);
-
- status = etcdWriter_addPublisherEndpoint(pubsub_discovery->writer,p,true);
-
- celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex);
-
- return status;
-}
-
-celix_status_t pubsub_discovery_removePublisher(void *handle, pubsub_endpoint_pt pubEP) {
- celix_status_t status = CELIX_SUCCESS;
-
- pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt) handle;
-
- celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex);
-
- char *pub_key = createScopeTopicKey(pubEP->scope,pubEP->topic);
- array_list_pt pubEP_list = (array_list_pt)hashMap_get(pubsub_discovery->discoveredPubs,pub_key);
- free(pub_key);
- if(pubEP_list==NULL){
- printf("PSD: Cannot find any registered publisher for topic %s. Something is not consistent.\n",pubEP->topic);
- status = CELIX_ILLEGAL_STATE;
- }
- else{
-
- int i;
- bool found = false;
- pubsub_endpoint_pt p = NULL;
-
- for(i=0;!found && i<arrayList_size(pubEP_list);i++){
- p = (pubsub_endpoint_pt)arrayList_get(pubEP_list,i);
- found = pubsubEndpoint_equals(pubEP,p);
- }
-
- if(!found){
- printf("PSD: Trying to remove a not existing endpoint. Something is not consistent.\n");
- status = CELIX_ILLEGAL_STATE;
- }
- else{
-
- arrayList_removeElement(pubEP_list,p);
-
- status = etcdWriter_deletePublisherEndpoint(pubsub_discovery->writer,p);
-
- pubsubEndpoint_destroy(p);
- }
- }
-
- celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex);
-
- return status;
-}
-
-celix_status_t pubsub_discovery_interestedInTopic(void *handle, const char* scope, const char* topic) {
- pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt) handle;
-
- char *scope_topic_key = createScopeTopicKey(scope, topic);
- celixThreadMutex_lock(&pubsub_discovery->watchersMutex);
- struct watcher_info * wi = hashMap_get(pubsub_discovery->watchers, scope_topic_key);
- if(wi) {
- wi->nr_references++;
- free(scope_topic_key);
- } else {
- wi = calloc(1, sizeof(*wi));
- etcdWatcher_create(pubsub_discovery, pubsub_discovery->context, scope, topic, &wi->watcher);
- wi->nr_references = 1;
- hashMap_put(pubsub_discovery->watchers, scope_topic_key, wi);
- }
-
- celixThreadMutex_unlock(&pubsub_discovery->watchersMutex);
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t pubsub_discovery_uninterestedInTopic(void *handle, const char* scope, const char* topic) {
- pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt) handle;
-
- char *scope_topic_key = createScopeTopicKey(scope, topic);
- celixThreadMutex_lock(&pubsub_discovery->watchersMutex);
-
- hash_map_entry_pt entry = hashMap_getEntry(pubsub_discovery->watchers, scope_topic_key);
- if(entry) {
- struct watcher_info * wi = hashMapEntry_getValue(entry);
- wi->nr_references--;
- if(wi->nr_references == 0) {
- char *key = hashMapEntry_getKey(entry);
- hashMap_remove(pubsub_discovery->watchers, scope_topic_key);
- free(key);
- free(scope_topic_key);
- etcdWatcher_stop(wi->watcher);
- etcdWatcher_destroy(wi->watcher);
- free(wi);
- }
- } else {
- fprintf(stderr, "[DISC] Inconsistency error: Removing unknown topic %s\n", topic);
- }
- celixThreadMutex_unlock(&pubsub_discovery->watchersMutex);
- return CELIX_SUCCESS;
-}
-
-/* pubsub_topology_manager tracker callbacks */
-
-celix_status_t pubsub_discovery_tmPublisherAnnounceAdded(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status = CELIX_SUCCESS;
-
- pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt)handle;
- publisher_endpoint_announce_pt listener = (publisher_endpoint_announce_pt)service;
-
- celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex);
- celixThreadMutex_lock(&pubsub_discovery->listenerReferencesMutex);
-
- /* Notify the PSTM about discovered publisher endpoints */
- hash_map_iterator_pt iter = hashMapIterator_create(pubsub_discovery->discoveredPubs);
- while(hashMapIterator_hasNext(iter)){
- array_list_pt pubEP_list = (array_list_pt)hashMapIterator_nextValue(iter);
- int i;
- for(i=0;i<arrayList_size(pubEP_list);i++){
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pubEP_list,i);
- status += listener->announcePublisher(listener->handle, pubEP);
- }
- }
-
- hashMapIterator_destroy(iter);
-
- hashMap_put(pubsub_discovery->listenerReferences, reference, NULL);
-
- celixThreadMutex_unlock(&pubsub_discovery->listenerReferencesMutex);
- celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex);
-
- printf("PSD: pubsub_tm_announce_publisher added.\n");
-
- return status;
-}
-
-celix_status_t pubsub_discovery_tmPublisherAnnounceModified(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status = CELIX_SUCCESS;
-
- status = pubsub_discovery_tmPublisherAnnounceRemoved(handle, reference, service);
- if (status == CELIX_SUCCESS) {
- status = pubsub_discovery_tmPublisherAnnounceAdded(handle, reference, service);
- }
-
- return status;
-}
-
-celix_status_t pubsub_discovery_tmPublisherAnnounceRemoved(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status = CELIX_SUCCESS;
- pubsub_discovery_pt pubsub_discovery = handle;
-
- celixThreadMutex_lock(&pubsub_discovery->listenerReferencesMutex);
-
- if (pubsub_discovery->listenerReferences != NULL) {
- if (hashMap_remove(pubsub_discovery->listenerReferences, reference)) {
- printf("PSD: pubsub_tm_announce_publisher removed.\n");
- }
- }
- celixThreadMutex_unlock(&pubsub_discovery->listenerReferencesMutex);
-
- return status;
-}
-
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/public/include/pubsub_discovery.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/public/include/pubsub_discovery.h b/pubsub/pubsub_discovery/public/include/pubsub_discovery.h
deleted file mode 100644
index f77905a..0000000
--- a/pubsub/pubsub_discovery/public/include/pubsub_discovery.h
+++ /dev/null
@@ -1,26 +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.
- */
-
-#ifndef PUBSUB_DISCOVERY_H_
-#define PUBSUB_DISCOVERY_H_
-
-typedef struct pubsub_discovery *pubsub_discovery_pt;
-
-
-#endif /* PUBSUB_DISCOVERY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/src/etcd_common.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/src/etcd_common.c b/pubsub/pubsub_discovery/src/etcd_common.c
new file mode 100644
index 0000000..c757801
--- /dev/null
+++ b/pubsub/pubsub_discovery/src/etcd_common.c
@@ -0,0 +1,82 @@
+/**
+ *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.
+ */
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "celix_log.h"
+#include "constants.h"
+
+#include <curl/curl.h>
+#include "etcd.h"
+#include "etcd_watcher.h"
+
+#include "pubsub_discovery.h"
+#include "pubsub_discovery_impl.h"
+
+
+#define MAX_ROOTNODE_LENGTH 128
+#define MAX_LOCALNODE_LENGTH 4096
+#define MAX_FIELD_LENGTH 128
+
+#define CFG_ETCD_SERVER_IP "PUBSUB_DISCOVERY_ETCD_SERVER_IP"
+#define DEFAULT_ETCD_SERVER_IP "127.0.0.1"
+
+#define CFG_ETCD_SERVER_PORT "PUBSUB_DISCOVERY_ETCD_SERVER_PORT"
+#define DEFAULT_ETCD_SERVER_PORT 2379
+
+// be careful - this should be higher than the curl timeout
+#define CFG_ETCD_TTL "DISCOVERY_ETCD_TTL"
+#define DEFAULT_ETCD_TTL 30
+
+
+celix_status_t etcdCommon_init(bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ const char* etcd_server = NULL;
+ const char* etcd_port_string = NULL;
+ int etcd_port = 0;
+
+ if ((bundleContext_getProperty(context, CFG_ETCD_SERVER_IP, &etcd_server) != CELIX_SUCCESS) || !etcd_server) {
+ etcd_server = DEFAULT_ETCD_SERVER_IP;
+ }
+
+ if ((bundleContext_getProperty(context, CFG_ETCD_SERVER_PORT, &etcd_port_string) != CELIX_SUCCESS) || !etcd_port_string) {
+ etcd_port = DEFAULT_ETCD_SERVER_PORT;
+ } else {
+ char* endptr = NULL;
+ errno = 0;
+ etcd_port = strtol(etcd_port_string, &endptr, 10);
+ if (*endptr || errno != 0) {
+ etcd_port = DEFAULT_ETCD_SERVER_PORT;
+ }
+ }
+
+ printf("PSD: Using discovery HOST:PORT: %s:%i\n", etcd_server, etcd_port);
+
+ if (etcd_init(etcd_server, etcd_port, CURL_GLOBAL_DEFAULT) != 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ status = CELIX_SUCCESS;
+ }
+
+ return status;
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/src/etcd_common.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/src/etcd_common.h b/pubsub/pubsub_discovery/src/etcd_common.h
new file mode 100644
index 0000000..7a3e7b6
--- /dev/null
+++ b/pubsub/pubsub_discovery/src/etcd_common.h
@@ -0,0 +1,28 @@
+/**
+ *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.
+ */
+
+#ifndef ETCD_COMMON_H_
+#define ETCD_COMMON_H_
+
+#include "bundle_context.h"
+#include "celix_errno.h"
+
+celix_status_t etcdCommon_init(bundle_context_pt context);
+
+#endif /* ETCD_COMMON_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/src/etcd_watcher.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/src/etcd_watcher.c b/pubsub/pubsub_discovery/src/etcd_watcher.c
new file mode 100644
index 0000000..3c3a5a8
--- /dev/null
+++ b/pubsub/pubsub_discovery/src/etcd_watcher.c
@@ -0,0 +1,290 @@
+/**
+ *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.
+ */
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "celix_log.h"
+#include "constants.h"
+
+#include "etcd.h"
+#include "etcd_watcher.h"
+
+#include "pubsub_discovery.h"
+#include "pubsub_discovery_impl.h"
+
+
+
+#define MAX_ROOTNODE_LENGTH 128
+#define MAX_LOCALNODE_LENGTH 4096
+#define MAX_FIELD_LENGTH 128
+
+#define CFG_ETCD_ROOT_PATH "PUBSUB_DISCOVERY_ETCD_ROOT_PATH"
+#define DEFAULT_ETCD_ROOTPATH "pubsub/discovery"
+
+#define CFG_ETCD_SERVER_IP "PUBSUB_DISCOVERY_ETCD_SERVER_IP"
+#define DEFAULT_ETCD_SERVER_IP "127.0.0.1"
+
+#define CFG_ETCD_SERVER_PORT "PUBSUB_DISCOVERY_ETCD_SERVER_PORT"
+#define DEFAULT_ETCD_SERVER_PORT 2379
+
+// be careful - this should be higher than the curl timeout
+#define CFG_ETCD_TTL "DISCOVERY_ETCD_TTL"
+#define DEFAULT_ETCD_TTL 30
+
+
+struct etcd_watcher {
+ pubsub_discovery_pt pubsub_discovery;
+
+ celix_thread_mutex_t watcherLock;
+ celix_thread_t watcherThread;
+
+ char *scope;
+ char *topic;
+ volatile bool running;
+};
+
+struct etcd_writer {
+ pubsub_discovery_pt pubsub_discovery;
+ celix_thread_mutex_t localPubsLock;
+ array_list_pt localPubs;
+ volatile bool running;
+ celix_thread_t writerThread;
+};
+
+
+// note that the rootNode shouldn't have a leading slash
+static celix_status_t etcdWatcher_getTopicRootPath(bundle_context_pt context, const char *scope, const char *topic, char* rootNode, int rootNodeLen) {
+ celix_status_t status = CELIX_SUCCESS;
+ const char* rootPath = NULL;
+
+ if (((bundleContext_getProperty(context, CFG_ETCD_ROOT_PATH, &rootPath)) != CELIX_SUCCESS) || (!rootPath)) {
+ snprintf(rootNode, rootNodeLen, "%s/%s/%s", DEFAULT_ETCD_ROOTPATH, scope, topic);
+ } else {
+ snprintf(rootNode, rootNodeLen, "%s/%s/%s", rootPath, scope, topic);
+ }
+
+ return status;
+}
+
+static celix_status_t etcdWatcher_getRootPath(bundle_context_pt context, char* rootNode) {
+ celix_status_t status = CELIX_SUCCESS;
+ const char* rootPath = NULL;
+
+ if (((bundleContext_getProperty(context, CFG_ETCD_ROOT_PATH, &rootPath)) != CELIX_SUCCESS) || (!rootPath)) {
+ strncpy(rootNode, DEFAULT_ETCD_ROOTPATH, MAX_ROOTNODE_LENGTH);
+ } else {
+ strncpy(rootNode, rootPath, MAX_ROOTNODE_LENGTH);
+ }
+
+ return status;
+}
+
+
+static void add_node(const char *key, const char *value, void* arg) {
+ pubsub_discovery_pt ps_discovery = (pubsub_discovery_pt) arg;
+ pubsub_endpoint_pt pubEP = NULL;
+ celix_status_t status = etcdWatcher_getPublisherEndpointFromKey(ps_discovery, key, value, &pubEP);
+ if(!status && pubEP) {
+ pubsub_discovery_addNode(ps_discovery, pubEP);
+ }
+}
+
+static celix_status_t etcdWatcher_addAlreadyExistingPublishers(pubsub_discovery_pt ps_discovery, const char *rootPath, long long * highestModified) {
+ celix_status_t status = CELIX_SUCCESS;
+ if(etcd_get_directory(rootPath, add_node, ps_discovery, highestModified)) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+ return status;
+}
+
+// gets everything from provided key
+celix_status_t etcdWatcher_getPublisherEndpointFromKey(pubsub_discovery_pt pubsub_discovery, const char* etcdKey, const char* etcdValue, pubsub_endpoint_pt* pubEP) {
+
+ celix_status_t status = CELIX_SUCCESS;
+
+ char rootPath[MAX_ROOTNODE_LENGTH];
+ char *expr = NULL;
+ char scope[MAX_FIELD_LENGTH];
+ char topic[MAX_FIELD_LENGTH];
+ char fwUUID[MAX_FIELD_LENGTH];
+ char serviceId[MAX_FIELD_LENGTH];
+
+ memset(rootPath,0,MAX_ROOTNODE_LENGTH);
+ memset(topic,0,MAX_FIELD_LENGTH);
+ memset(fwUUID,0,MAX_FIELD_LENGTH);
+ memset(serviceId,0,MAX_FIELD_LENGTH);
+
+ etcdWatcher_getRootPath(pubsub_discovery->context, rootPath);
+
+ asprintf(&expr, "/%s/%%[^/]/%%[^/]/%%[^/]/%%[^/].*", rootPath);
+ if(expr) {
+ int foundItems = sscanf(etcdKey, expr, scope, topic, fwUUID, serviceId);
+ free(expr);
+ if (foundItems != 4) { // Could happen when a directory is removed, just don't process this.
+ status = CELIX_ILLEGAL_STATE;
+ }
+ else{
+ status = pubsubEndpoint_create(fwUUID,scope,topic,strtol(serviceId,NULL,10),etcdValue,NULL,pubEP);
+ }
+ }
+ return status;
+}
+
+/*
+ * performs (blocking) etcd_watch calls to check for
+ * changing discovery endpoint information within etcd.
+ */
+static void* etcdWatcher_run(void* data) {
+ etcd_watcher_pt watcher = (etcd_watcher_pt) data;
+ time_t timeBeforeWatch = time(NULL);
+ char rootPath[MAX_ROOTNODE_LENGTH];
+ long long highestModified = 0;
+
+ pubsub_discovery_pt ps_discovery = watcher->pubsub_discovery;
+ bundle_context_pt context = ps_discovery->context;
+
+ memset(rootPath, 0, MAX_ROOTNODE_LENGTH);
+
+ //TODO: add topic to etcd key
+ etcdWatcher_getTopicRootPath(context, watcher->scope, watcher->topic, rootPath, MAX_ROOTNODE_LENGTH);
+ etcdWatcher_addAlreadyExistingPublishers(ps_discovery, rootPath, &highestModified);
+
+ while ((celixThreadMutex_lock(&watcher->watcherLock) == CELIX_SUCCESS) && watcher->running) {
+
+ char *rkey = NULL;
+ char *value = NULL;
+ char *preValue = NULL;
+ char *action = NULL;
+ long long modIndex;
+
+ celixThreadMutex_unlock(&watcher->watcherLock);
+
+ if (etcd_watch(rootPath, highestModified + 1, &action, &preValue, &value, &rkey, &modIndex) == 0 && action != NULL) {
+ pubsub_endpoint_pt pubEP = NULL;
+ if ((strcmp(action, "set") == 0) || (strcmp(action, "create") == 0)) {
+ if (etcdWatcher_getPublisherEndpointFromKey(ps_discovery, rkey, value, &pubEP) == CELIX_SUCCESS) {
+ pubsub_discovery_addNode(ps_discovery, pubEP);
+ }
+ } else if (strcmp(action, "delete") == 0) {
+ if (etcdWatcher_getPublisherEndpointFromKey(ps_discovery, rkey, preValue, &pubEP) == CELIX_SUCCESS) {
+ pubsub_discovery_removeNode(ps_discovery, pubEP);
+ }
+ } else if (strcmp(action, "expire") == 0) {
+ if (etcdWatcher_getPublisherEndpointFromKey(ps_discovery, rkey, preValue, &pubEP) == CELIX_SUCCESS) {
+ pubsub_discovery_removeNode(ps_discovery, pubEP);
+ }
+ } else if (strcmp(action, "update") == 0) {
+ if (etcdWatcher_getPublisherEndpointFromKey(ps_discovery, rkey, value, &pubEP) == CELIX_SUCCESS) {
+ pubsub_discovery_addNode(ps_discovery, pubEP);
+ }
+ } else {
+ fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "Unexpected action: %s", action);
+ }
+ highestModified = modIndex;
+ } else if (time(NULL) - timeBeforeWatch <= (DEFAULT_ETCD_TTL / 4)) {
+ sleep(DEFAULT_ETCD_TTL / 4);
+ }
+
+ FREE_MEM(action);
+ FREE_MEM(value);
+ FREE_MEM(preValue);
+ FREE_MEM(rkey);
+
+ /* prevent busy waiting, in case etcd_watch returns false */
+
+
+ if (time(NULL) - timeBeforeWatch > (DEFAULT_ETCD_TTL / 4)) {
+ timeBeforeWatch = time(NULL);
+ }
+
+ }
+
+ if (watcher->running == false) {
+ celixThreadMutex_unlock(&watcher->watcherLock);
+ }
+
+ return NULL;
+}
+
+celix_status_t etcdWatcher_create(pubsub_discovery_pt pubsub_discovery, bundle_context_pt context, const char *scope, const char *topic, etcd_watcher_pt *watcher) {
+ celix_status_t status = CELIX_SUCCESS;
+
+
+ if (pubsub_discovery == NULL) {
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+
+ (*watcher) = calloc(1, sizeof(struct etcd_watcher));
+
+ if(*watcher == NULL){
+ return CELIX_ENOMEM;
+ }
+
+ (*watcher)->pubsub_discovery = pubsub_discovery;
+ (*watcher)->scope = strdup(scope);
+ (*watcher)->topic = strdup(topic);
+
+
+ celixThreadMutex_create(&(*watcher)->watcherLock, NULL);
+
+ celixThreadMutex_lock(&(*watcher)->watcherLock);
+
+ status = celixThread_create(&(*watcher)->watcherThread, NULL, etcdWatcher_run, *watcher);
+ if (status == CELIX_SUCCESS) {
+ (*watcher)->running = true;
+ }
+
+ celixThreadMutex_unlock(&(*watcher)->watcherLock);
+
+
+ return status;
+}
+
+celix_status_t etcdWatcher_destroy(etcd_watcher_pt watcher) {
+
+ celix_status_t status = CELIX_SUCCESS;
+
+ char rootPath[MAX_ROOTNODE_LENGTH];
+ etcdWatcher_getTopicRootPath(watcher->pubsub_discovery->context, watcher->scope, watcher->topic, rootPath, MAX_ROOTNODE_LENGTH);
+ celixThreadMutex_destroy(&(watcher->watcherLock));
+
+ free(watcher->scope);
+ free(watcher->topic);
+ free(watcher);
+
+ return status;
+}
+
+celix_status_t etcdWatcher_stop(etcd_watcher_pt watcher){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&(watcher->watcherLock));
+ watcher->running = false;
+ celixThreadMutex_unlock(&(watcher->watcherLock));
+
+ celixThread_join(watcher->watcherThread, NULL);
+
+ return status;
+
+}
+
+
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/src/etcd_watcher.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/src/etcd_watcher.h b/pubsub/pubsub_discovery/src/etcd_watcher.h
new file mode 100644
index 0000000..c425e60
--- /dev/null
+++ b/pubsub/pubsub_discovery/src/etcd_watcher.h
@@ -0,0 +1,38 @@
+/**
+ *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.
+ */
+
+#ifndef ETCD_WATCHER_H_
+#define ETCD_WATCHER_H_
+
+#include "bundle_context.h"
+#include "celix_errno.h"
+
+#include "pubsub_discovery.h"
+#include "pubsub_endpoint.h"
+
+typedef struct etcd_watcher *etcd_watcher_pt;
+
+celix_status_t etcdWatcher_create(pubsub_discovery_pt discovery, bundle_context_pt context, const char *scope, const char* topic, etcd_watcher_pt *watcher);
+celix_status_t etcdWatcher_destroy(etcd_watcher_pt watcher);
+celix_status_t etcdWatcher_stop(etcd_watcher_pt watcher);
+
+celix_status_t etcdWatcher_getPublisherEndpointFromKey(pubsub_discovery_pt discovery, const char* key, const char* value, pubsub_endpoint_pt* pubEP);
+
+
+#endif /* ETCD_WATCHER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/src/etcd_writer.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/src/etcd_writer.c b/pubsub/pubsub_discovery/src/etcd_writer.c
new file mode 100644
index 0000000..1c423f3
--- /dev/null
+++ b/pubsub/pubsub_discovery/src/etcd_writer.c
@@ -0,0 +1,189 @@
+/**
+ *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.
+ */
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "celix_log.h"
+#include "constants.h"
+
+#include "etcd.h"
+#include "etcd_writer.h"
+
+#include "pubsub_discovery.h"
+#include "pubsub_discovery_impl.h"
+
+#define MAX_ROOTNODE_LENGTH 128
+
+#define CFG_ETCD_ROOT_PATH "PUBSUB_DISCOVERY_ETCD_ROOT_PATH"
+#define DEFAULT_ETCD_ROOTPATH "pubsub/discovery"
+
+#define CFG_ETCD_SERVER_IP "PUBSUB_DISCOVERY_ETCD_SERVER_IP"
+#define DEFAULT_ETCD_SERVER_IP "127.0.0.1"
+
+#define CFG_ETCD_SERVER_PORT "PUBSUB_DISCOVERY_ETCD_SERVER_PORT"
+#define DEFAULT_ETCD_SERVER_PORT 2379
+
+// be careful - this should be higher than the curl timeout
+#define CFG_ETCD_TTL "DISCOVERY_ETCD_TTL"
+#define DEFAULT_ETCD_TTL 30
+
+struct etcd_writer {
+ pubsub_discovery_pt pubsub_discovery;
+ celix_thread_mutex_t localPubsLock;
+ array_list_pt localPubs;
+ volatile bool running;
+ celix_thread_t writerThread;
+};
+
+
+static const char* etcdWriter_getRootPath(bundle_context_pt context);
+static void* etcdWriter_run(void* data);
+
+
+etcd_writer_pt etcdWriter_create(pubsub_discovery_pt disc) {
+ etcd_writer_pt writer = calloc(1, sizeof(*writer));
+ if(writer) {
+ celixThreadMutex_create(&writer->localPubsLock, NULL);
+ arrayList_create(&writer->localPubs);
+ writer->pubsub_discovery = disc;
+ writer->running = true;
+ celixThread_create(&writer->writerThread, NULL, etcdWriter_run, writer);
+ }
+ return writer;
+}
+
+void etcdWriter_destroy(etcd_writer_pt writer) {
+ char dir[MAX_ROOTNODE_LENGTH];
+ const char *rootPath = etcdWriter_getRootPath(writer->pubsub_discovery->context);
+
+ writer->running = false;
+ celixThread_join(writer->writerThread, NULL);
+
+ celixThreadMutex_lock(&writer->localPubsLock);
+ for(int i = 0; i < arrayList_size(writer->localPubs); i++) {
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(writer->localPubs,i);
+ memset(dir,0,MAX_ROOTNODE_LENGTH);
+ snprintf(dir,MAX_ROOTNODE_LENGTH,"%s/%s/%s/%s",rootPath,pubEP->scope,pubEP->topic,pubEP->frameworkUUID);
+ etcd_del(dir);
+ pubsubEndpoint_destroy(pubEP);
+ }
+ arrayList_destroy(writer->localPubs);
+
+ celixThreadMutex_unlock(&writer->localPubsLock);
+ celixThreadMutex_destroy(&(writer->localPubsLock));
+
+ free(writer);
+}
+
+celix_status_t etcdWriter_addPublisherEndpoint(etcd_writer_pt writer, pubsub_endpoint_pt pubEP, bool storeEP){
+ celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+
+ if(storeEP){
+ const char *fwUUID = NULL;
+ bundleContext_getProperty(writer->pubsub_discovery->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &fwUUID);
+ if(fwUUID && strcmp(pubEP->frameworkUUID, fwUUID) == 0) {
+ celixThreadMutex_lock(&writer->localPubsLock);
+ pubsub_endpoint_pt p = NULL;
+ pubsubEndpoint_clone(pubEP, &p);
+ arrayList_add(writer->localPubs,p);
+ celixThreadMutex_unlock(&writer->localPubsLock);
+ }
+ }
+
+ char *key;
+
+ const char* ttlStr = NULL;
+ int ttl = 0;
+
+ // determine ttl
+ if ((bundleContext_getProperty(writer->pubsub_discovery->context, CFG_ETCD_TTL, &ttlStr) != CELIX_SUCCESS) || !ttlStr) {
+ ttl = DEFAULT_ETCD_TTL;
+ } else {
+ char* endptr = NULL;
+ errno = 0;
+ ttl = strtol(ttlStr, &endptr, 10);
+ if (*endptr || errno != 0) {
+ ttl = DEFAULT_ETCD_TTL;
+ }
+ }
+
+ const char *rootPath = etcdWriter_getRootPath(writer->pubsub_discovery->context);
+
+ asprintf(&key,"%s/%s/%s/%s/%ld",rootPath,pubEP->scope,pubEP->topic,pubEP->frameworkUUID,pubEP->serviceID);
+
+ if(!etcd_set(key,pubEP->endpoint,ttl,false)){
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+ FREE_MEM(key);
+ return status;
+}
+
+celix_status_t etcdWriter_deletePublisherEndpoint(etcd_writer_pt writer, pubsub_endpoint_pt pubEP) {
+ celix_status_t status = CELIX_SUCCESS;
+ char *key = NULL;
+
+ const char *rootPath = etcdWriter_getRootPath(writer->pubsub_discovery->context);
+
+ asprintf(&key, "%s/%s/%s/%s/%ld", rootPath, pubEP->scope, pubEP->topic, pubEP->frameworkUUID, pubEP->serviceID);
+
+ celixThreadMutex_lock(&writer->localPubsLock);
+ for (unsigned int i = 0; i < arrayList_size(writer->localPubs); i++) {
+ pubsub_endpoint_pt ep = arrayList_get(writer->localPubs, i);
+ if (pubsubEndpoint_equals(ep, pubEP)) {
+ arrayList_remove(writer->localPubs, i);
+ pubsubEndpoint_destroy(ep);
+ break;
+ }
+ }
+ celixThreadMutex_unlock(&writer->localPubsLock);
+
+ if (etcd_del(key)) {
+ printf("Failed to remove key %s from ETCD\n",key);
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+ FREE_MEM(key);
+ return status;
+}
+
+static void* etcdWriter_run(void* data) {
+ etcd_writer_pt writer = (etcd_writer_pt)data;
+ while(writer->running) {
+ celixThreadMutex_lock(&writer->localPubsLock);
+ for(int i=0; i < arrayList_size(writer->localPubs); i++) {
+ etcdWriter_addPublisherEndpoint(writer,(pubsub_endpoint_pt)arrayList_get(writer->localPubs,i),false);
+ }
+ celixThreadMutex_unlock(&writer->localPubsLock);
+ sleep(DEFAULT_ETCD_TTL / 2);
+ }
+
+ return NULL;
+}
+
+static const char* etcdWriter_getRootPath(bundle_context_pt context) {
+ const char* rootPath = NULL;
+ bundleContext_getProperty(context, CFG_ETCD_ROOT_PATH, &rootPath);
+ if(rootPath == NULL) {
+ rootPath = DEFAULT_ETCD_ROOTPATH;
+ }
+ return rootPath;
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/src/etcd_writer.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/src/etcd_writer.h b/pubsub/pubsub_discovery/src/etcd_writer.h
new file mode 100644
index 0000000..3ff98b9
--- /dev/null
+++ b/pubsub/pubsub_discovery/src/etcd_writer.h
@@ -0,0 +1,39 @@
+/**
+ *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.
+ */
+
+#ifndef ETCD_WRITER_H_
+#define ETCD_WRITER_H_
+
+#include "bundle_context.h"
+#include "celix_errno.h"
+
+#include "pubsub_discovery.h"
+#include "pubsub_endpoint.h"
+
+typedef struct etcd_writer *etcd_writer_pt;
+
+
+etcd_writer_pt etcdWriter_create(pubsub_discovery_pt discovery);
+void etcdWriter_destroy(etcd_writer_pt writer);
+
+celix_status_t etcdWriter_addPublisherEndpoint(etcd_writer_pt writer, pubsub_endpoint_pt pubEP,bool storeEP);
+celix_status_t etcdWriter_deletePublisherEndpoint(etcd_writer_pt writer, pubsub_endpoint_pt pubEP);
+
+
+#endif /* ETCD_WRITER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/src/psd_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/src/psd_activator.c b/pubsub/pubsub_discovery/src/psd_activator.c
new file mode 100644
index 0000000..89a517d
--- /dev/null
+++ b/pubsub/pubsub_discovery/src/psd_activator.c
@@ -0,0 +1,171 @@
+/**
+ *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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "bundle_activator.h"
+#include "service_tracker.h"
+#include "service_registration.h"
+#include "constants.h"
+#include "celix_log.h"
+
+#include "pubsub_common.h"
+#include "publisher_endpoint_announce.h"
+#include "pubsub_discovery.h"
+#include "pubsub_discovery_impl.h"
+
+struct activator {
+ bundle_context_pt context;
+ pubsub_discovery_pt pubsub_discovery;
+
+ service_tracker_pt pstmPublishersTracker;
+
+ publisher_endpoint_announce_pt publisherEPAnnounce;
+ service_registration_pt publisherEPAnnounceService;
+};
+
+static celix_status_t createTMPublisherAnnounceTracker(struct activator *activator, service_tracker_pt *tracker) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ service_tracker_customizer_pt customizer = NULL;
+
+ status = serviceTrackerCustomizer_create(activator->pubsub_discovery,
+ NULL,
+ pubsub_discovery_tmPublisherAnnounceAdded,
+ pubsub_discovery_tmPublisherAnnounceModified,
+ pubsub_discovery_tmPublisherAnnounceRemoved,
+ &customizer);
+
+ if (status == CELIX_SUCCESS) {
+ status = serviceTracker_create(activator->context, (char *) PUBSUB_TM_ANNOUNCE_PUBLISHER_SERVICE, customizer, tracker);
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ struct activator* activator = calloc(1, sizeof(*activator));
+
+ if (activator) {
+ activator->context = context;
+ activator->pstmPublishersTracker = NULL;
+ activator->publisherEPAnnounce = NULL;
+ activator->publisherEPAnnounceService = NULL;
+
+ status = pubsub_discovery_create(context, &activator->pubsub_discovery);
+
+ if (status == CELIX_SUCCESS) {
+ status = createTMPublisherAnnounceTracker(activator, &(activator->pstmPublishersTracker));
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *userData = activator;
+ } else {
+ free(activator);
+ }
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ return status;
+
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ struct activator *activator = userData;
+
+ publisher_endpoint_announce_pt pubEPAnnouncer = calloc(1, sizeof(*pubEPAnnouncer));
+
+ if (pubEPAnnouncer) {
+
+ pubEPAnnouncer->handle = activator->pubsub_discovery;
+ pubEPAnnouncer->announcePublisher = pubsub_discovery_announcePublisher;
+ pubEPAnnouncer->removePublisher = pubsub_discovery_removePublisher;
+ pubEPAnnouncer->interestedInTopic = pubsub_discovery_interestedInTopic;
+ pubEPAnnouncer->uninterestedInTopic = pubsub_discovery_uninterestedInTopic;
+ activator->publisherEPAnnounce = pubEPAnnouncer;
+
+ properties_pt props = properties_create();
+ properties_set(props, "PUBSUB_DISCOVERY", "true");
+
+ // pubsub_discovery_start needs to be first to initalize the propert etcd_watcher values
+ status = pubsub_discovery_start(activator->pubsub_discovery);
+
+ if (status == CELIX_SUCCESS) {
+ status = serviceTracker_open(activator->pstmPublishersTracker);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = bundleContext_registerService(context, (char *) PUBSUB_DISCOVERY_SERVICE, pubEPAnnouncer, props, &activator->publisherEPAnnounceService);
+ }
+
+
+ }
+ else{
+ status = CELIX_ENOMEM;
+ }
+
+ if(status!=CELIX_SUCCESS && pubEPAnnouncer!=NULL){
+ free(pubEPAnnouncer);
+ }
+
+
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ status += pubsub_discovery_stop(activator->pubsub_discovery);
+
+ status += serviceTracker_close(activator->pstmPublishersTracker);
+
+ status += serviceRegistration_unregister(activator->publisherEPAnnounceService);
+
+ if (status == CELIX_SUCCESS) {
+ free(activator->publisherEPAnnounce);
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ status += serviceTracker_destroy(activator->pstmPublishersTracker);
+ status += pubsub_discovery_destroy(activator->pubsub_discovery);
+
+ activator->publisherEPAnnounce = NULL;
+ activator->publisherEPAnnounceService = NULL;
+ activator->pstmPublishersTracker = NULL;
+ activator->pubsub_discovery = NULL;
+ activator->context = NULL;
+
+ free(activator);
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/src/pubsub_discovery.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/src/pubsub_discovery.h b/pubsub/pubsub_discovery/src/pubsub_discovery.h
new file mode 100644
index 0000000..f77905a
--- /dev/null
+++ b/pubsub/pubsub_discovery/src/pubsub_discovery.h
@@ -0,0 +1,26 @@
+/**
+ *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.
+ */
+
+#ifndef PUBSUB_DISCOVERY_H_
+#define PUBSUB_DISCOVERY_H_
+
+typedef struct pubsub_discovery *pubsub_discovery_pt;
+
+
+#endif /* PUBSUB_DISCOVERY_H_ */
[05/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_dfi.c
new file mode 100644
index 0000000..9feab9f
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_dfi.c
@@ -0,0 +1,775 @@
+/**
+ *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.
+ */
+/*
+ * remote_service_admin_impl.c
+ *
+ * \date May 21, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <ifaddrs.h>
+#include <string.h>
+#include <uuid/uuid.h>
+#include <curl/curl.h>
+
+#include <jansson.h>
+#include "json_serializer.h"
+#include "remote_service_admin.h"
+#include "celix_threads.h"
+#include "hash_map.h"
+#include "array_list.h"
+
+#include "import_registration_dfi.h"
+#include "export_registration_dfi.h"
+#include "remote_service_admin_dfi.h"
+#include "dyn_interface.h"
+#include "json_rpc.h"
+
+#include "remote_constants.h"
+#include "constants.h"
+#include "civetweb.h"
+
+// defines how often the webserver is restarted (with an increased port number)
+#define MAX_NUMBER_OF_RESTARTS 5
+
+
+#define RSA_LOG_ERROR(admin, msg, ...) \
+ logHelper_log((admin)->loghelper, OSGI_LOGSERVICE_ERROR, (msg), ##__VA_ARGS__)
+
+#define RSA_LOG_WARNING(admin, msg, ...) \
+ logHelper_log((admin)->loghelper, OSGI_LOGSERVICE_ERROR, (msg), ##__VA_ARGS__)
+
+#define RSA_LOG_DEBUG(admin, msg, ...) \
+ logHelper_log((admin)->loghelper, OSGI_LOGSERVICE_ERROR, (msg), ##__VA_ARGS__)
+
+struct remote_service_admin {
+ bundle_context_pt context;
+ log_helper_pt loghelper;
+
+ celix_thread_mutex_t exportedServicesLock;
+ hash_map_pt exportedServices;
+
+ celix_thread_mutex_t importedServicesLock;
+ array_list_pt importedServices;
+
+ char *port;
+ char *ip;
+
+ struct mg_context *ctx;
+};
+
+struct post {
+ const char *readptr;
+ int size;
+};
+
+struct get {
+ char *writeptr;
+ int size;
+};
+
+#define OSGI_RSA_REMOTE_PROXY_FACTORY "remote_proxy_factory"
+#define OSGI_RSA_REMOTE_PROXY_TIMEOUT "remote_proxy_timeout"
+
+static const char *data_response_headers =
+ "HTTP/1.1 200 OK\r\n"
+ "Cache: no-cache\r\n"
+ "Content-Type: application/json\r\n"
+ "\r\n";
+
+static const char *no_content_response_headers =
+ "HTTP/1.1 204 OK\r\n";
+
+// TODO do we need to specify a non-Amdatu specific configuration type?!
+static const char * const CONFIGURATION_TYPE = "org.amdatu.remote.admin.http";
+static const char * const ENDPOINT_URL = "org.amdatu.remote.admin.http.url";
+
+static const char *DEFAULT_PORT = "8888";
+static const char *DEFAULT_IP = "127.0.0.1";
+
+static const unsigned int DEFAULT_TIMEOUT = 0;
+
+static int remoteServiceAdmin_callback(struct mg_connection *conn);
+static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, properties_pt props, char *interface, endpoint_description_pt *description);
+static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
+static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip);
+static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp);
+static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp);
+static void remoteServiceAdmin_log(remote_service_admin_pt admin, int level, const char *file, int line, const char *msg, ...);
+
+celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *admin = calloc(1, sizeof(**admin));
+
+ if (!*admin) {
+ status = CELIX_ENOMEM;
+ } else {
+ unsigned int port_counter = 0;
+ const char *port = NULL;
+ const char *ip = NULL;
+ char *detectedIp = NULL;
+ (*admin)->context = context;
+ (*admin)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL);
+ arrayList_create(&(*admin)->importedServices);
+
+ celixThreadMutex_create(&(*admin)->exportedServicesLock, NULL);
+ celixThreadMutex_create(&(*admin)->importedServicesLock, NULL);
+
+ if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
+ logHelper_start((*admin)->loghelper);
+ dynCommon_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
+ dynType_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
+ dynFunction_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
+ dynInterface_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
+ jsonSerializer_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
+ jsonRpc_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
+ }
+
+ bundleContext_getProperty(context, "RSA_PORT", &port);
+ if (port == NULL) {
+ port = (char *)DEFAULT_PORT;
+ }
+
+ bundleContext_getProperty(context, "RSA_IP", &ip);
+ if (ip == NULL) {
+ const char *interface = NULL;
+
+ bundleContext_getProperty(context, "RSA_INTERFACE", &interface);
+ if ((interface != NULL) && (remoteServiceAdmin_getIpAdress((char*)interface, &detectedIp) != CELIX_SUCCESS)) {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: Could not retrieve IP adress for interface %s", interface);
+ }
+
+ if (ip == NULL) {
+ remoteServiceAdmin_getIpAdress(NULL, &detectedIp);
+ }
+
+ ip = detectedIp;
+ }
+
+ if (ip != NULL) {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Using %s for service annunciation", ip);
+ (*admin)->ip = strdup(ip);
+ }
+ else {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No IP address for service annunciation set. Using %s", DEFAULT_IP);
+ (*admin)->ip = strdup((char*) DEFAULT_IP);
+ }
+
+ if (detectedIp != NULL) {
+ free(detectedIp);
+ }
+
+ // Prepare callbacks structure. We have only one callback, the rest are NULL.
+ struct mg_callbacks callbacks;
+ memset(&callbacks, 0, sizeof(callbacks));
+ callbacks.begin_request = remoteServiceAdmin_callback;
+
+ char newPort[10];
+
+ do {
+
+ const char *options[] = { "listening_ports", port, "num_threads", "5", NULL};
+
+ (*admin)->ctx = mg_start(&callbacks, (*admin), options);
+
+ if ((*admin)->ctx != NULL) {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Start webserver: %s", port);
+ (*admin)->port = strdup(port);
+
+ }
+ else {
+ errno = 0;
+ char* endptr = (char*)port;
+ int currentPort = strtol(port, &endptr, 10);
+
+ if (*endptr || errno != 0) {
+ currentPort = strtol(DEFAULT_PORT, NULL, 10);
+ }
+
+ port_counter++;
+ snprintf(&newPort[0], 6, "%d", (currentPort+1));
+
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_ERROR, "Error while starting rsa server on port %s - retrying on port %s...", port, newPort);
+ port = newPort;
+ }
+ } while(((*admin)->ctx == NULL) && (port_counter < MAX_NUMBER_OF_RESTARTS));
+
+ }
+
+ return status;
+}
+
+
+celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin)
+{
+ celix_status_t status = CELIX_SUCCESS;
+
+ free((*admin)->ip);
+ free((*admin)->port);
+ free(*admin);
+
+ //TODO destroy exports/imports
+
+ *admin = NULL;
+
+ return status;
+}
+
+
+celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&admin->exportedServicesLock);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(admin->exportedServices);
+ while (hashMapIterator_hasNext(iter)) {
+ array_list_pt exports = hashMapIterator_nextValue(iter);
+ int i;
+ for (i = 0; i < arrayList_size(exports); i++) {
+ export_registration_pt export = arrayList_get(exports, i);
+ if (export != NULL) {
+ exportRegistration_stop(export);
+ exportRegistration_destroy(export);
+ }
+ }
+ arrayList_destroy(exports);
+ }
+ hashMapIterator_destroy(iter);
+ celixThreadMutex_unlock(&admin->exportedServicesLock);
+
+ celixThreadMutex_lock(&admin->importedServicesLock);
+ int i;
+ int size = arrayList_size(admin->importedServices);
+ for (i = 0; i < size ; i += 1) {
+ import_registration_pt import = arrayList_get(admin->importedServices, i);
+ if (import != NULL) {
+ importRegistration_stop(import);
+ importRegistration_destroy(import);
+ }
+ }
+ celixThreadMutex_unlock(&admin->importedServicesLock);
+
+ if (admin->ctx != NULL) {
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Stopping webserver...");
+ mg_stop(admin->ctx);
+ admin->ctx = NULL;
+ }
+
+ hashMap_destroy(admin->exportedServices, false, false);
+ arrayList_destroy(admin->importedServices);
+
+ logHelper_stop(admin->loghelper);
+ logHelper_destroy(&admin->loghelper);
+
+ return status;
+}
+
+/**
+ * Request: http://host:port/services/{service}/{request}
+ */
+//void *remoteServiceAdmin_callback(enum mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info) {
+
+celix_status_t importRegistration_getFactory(import_registration_pt import, service_factory_pt *factory);
+
+static int remoteServiceAdmin_callback(struct mg_connection *conn) {
+ int result = 1; // zero means: let civetweb handle it further, any non-zero value means it is handled by us...
+
+ const struct mg_request_info *request_info = mg_get_request_info(conn);
+ if (request_info->uri != NULL) {
+ remote_service_admin_pt rsa = request_info->user_data;
+
+
+ if (strncmp(request_info->uri, "/service/", 9) == 0 && strcmp("POST", request_info->request_method) == 0) {
+
+ // uri = /services/myservice/call
+ const char *uri = request_info->uri;
+ // rest = myservice/call
+
+ const char *rest = uri+9;
+ char *interfaceStart = strchr(rest, '/');
+ int pos = interfaceStart - rest;
+ char service[pos+1];
+ strncpy(service, rest, pos);
+ service[pos] = '\0';
+ unsigned long serviceId = strtoul(service,NULL,10);
+
+ celixThreadMutex_lock(&rsa->exportedServicesLock);
+
+ //find endpoint
+ export_registration_pt export = NULL;
+ hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ array_list_pt exports = hashMapEntry_getValue(entry);
+ int expIt = 0;
+ for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
+ export_registration_pt check = arrayList_get(exports, expIt);
+ export_reference_pt ref = NULL;
+ exportRegistration_getExportReference(check, &ref);
+ endpoint_description_pt checkEndpoint = NULL;
+ exportReference_getExportedEndpoint(ref, &checkEndpoint);
+ if (serviceId == checkEndpoint->serviceId) {
+ export = check;
+ free(ref);
+ break;
+ }
+ free(ref);
+ }
+ }
+ hashMapIterator_destroy(iter);
+
+ if (export != NULL) {
+
+ uint64_t datalength = request_info->content_length;
+ char* data = malloc(datalength + 1);
+ mg_read(conn, data, datalength);
+ data[datalength] = '\0';
+
+ char *response = NULL;
+ int responceLength = 0;
+ int rc = exportRegistration_call(export, data, -1, &response, &responceLength);
+ if (rc != CELIX_SUCCESS) {
+ RSA_LOG_ERROR(rsa, "Error trying to invoke remove service, got error %i\n", rc);
+ }
+
+ if (rc == CELIX_SUCCESS && response != NULL) {
+ mg_write(conn, data_response_headers, strlen(data_response_headers));
+ mg_write(conn, response, strlen(response));
+ free(response);
+ } else {
+ mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
+ }
+ result = 1;
+
+ free(data);
+ } else {
+ result = 0;
+ RSA_LOG_WARNING(rsa, "NO export registration found for service id %lu", serviceId);
+ }
+
+ celixThreadMutex_unlock(&rsa->exportedServicesLock);
+
+ }
+ }
+
+ return result;
+}
+
+celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations) {
+ celix_status_t status;
+
+ arrayList_create(registrations);
+ array_list_pt references = NULL;
+ service_reference_pt reference = NULL;
+ char filter [256];
+
+ snprintf(filter, 256, "(%s=%s)", (char *)OSGI_FRAMEWORK_SERVICE_ID, serviceId);
+
+ status = bundleContext_getServiceReferences(admin->context, NULL, filter, &references);
+
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: exportService called for serviceId %s", serviceId);
+
+ int i;
+ int size = arrayList_size(references);
+ for (i = 0; i < size; i += 1) {
+ if (i == 0) {
+ reference = arrayList_get(references, i);
+ } else {
+ bundleContext_ungetServiceReference(admin->context, arrayList_get(references, i));
+ }
+ }
+ arrayList_destroy(references);
+
+ if (reference == NULL) {
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "ERROR: expected a reference for service id %s.", serviceId);
+ status = CELIX_ILLEGAL_STATE;
+ }
+
+ const char *exports = NULL;
+ const char *provided = NULL;
+ if (status == CELIX_SUCCESS) {
+ serviceReference_getProperty(reference, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exports);
+ serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_OBJECTCLASS, &provided);
+
+ if (exports == NULL || provided == NULL || strcmp(exports, provided) != 0) {
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No Services to export.");
+ status = CELIX_ILLEGAL_STATE;
+ } else {
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Export service (%s)", provided);
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ const char *interface = provided;
+ endpoint_description_pt endpoint = NULL;
+ export_registration_pt registration = NULL;
+
+ remoteServiceAdmin_createEndpointDescription(admin, reference, properties, (char*)interface, &endpoint);
+ //TODO precheck if descriptor exists
+ status = exportRegistration_create(admin->loghelper, reference, endpoint, admin->context, ®istration);
+ if (status == CELIX_SUCCESS) {
+ status = exportRegistration_start(registration);
+ if (status == CELIX_SUCCESS) {
+ arrayList_add(*registrations, registration);
+ }
+ }
+ }
+
+
+ if (status == CELIX_SUCCESS) {
+ celixThreadMutex_lock(&admin->exportedServicesLock);
+ hashMap_put(admin->exportedServices, reference, *registrations);
+ celixThreadMutex_unlock(&admin->exportedServicesLock);
+ }
+ else{
+ arrayList_destroy(*registrations);
+ *registrations = NULL;
+ }
+
+ return status;
+}
+
+celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration) {
+ celix_status_t status;
+
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_DFI: Removing exported service");
+
+ export_reference_pt ref = NULL;
+ status = exportRegistration_getExportReference(registration, &ref);
+
+ if (status == CELIX_SUCCESS && ref != NULL) {
+ service_reference_pt servRef;
+ celixThreadMutex_lock(&admin->exportedServicesLock);
+ exportReference_getExportedService(ref, &servRef);
+
+ array_list_pt exports = (array_list_pt)hashMap_remove(admin->exportedServices, servRef);
+ if(exports!=NULL){
+ arrayList_destroy(exports);
+ }
+
+ exportRegistration_close(registration);
+ exportRegistration_destroy(registration);
+
+ celixThreadMutex_unlock(&admin->exportedServicesLock);
+
+ free(ref);
+
+ } else {
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "Cannot find reference for registration");
+ }
+
+ return status;
+}
+
+static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, properties_pt props, char *interface, endpoint_description_pt *endpoint) {
+
+ celix_status_t status = CELIX_SUCCESS;
+ properties_pt endpointProperties = properties_create();
+
+
+ unsigned int size = 0;
+ char **keys;
+
+ serviceReference_getPropertyKeys(reference, &keys, &size);
+ for (int i = 0; i < size; i++) {
+ char *key = keys[i];
+ const char *value = NULL;
+
+ if (serviceReference_getProperty(reference, key, &value) == CELIX_SUCCESS
+ && strcmp(key, (char*) OSGI_RSA_SERVICE_EXPORTED_INTERFACES) != 0
+ && strcmp(key, (char*) OSGI_FRAMEWORK_OBJECTCLASS) != 0) {
+ properties_set(endpointProperties, key, value);
+ }
+ }
+
+ hash_map_entry_pt entry = hashMap_getEntry(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
+
+ char* key = hashMapEntry_getKey(entry);
+ char *serviceId = (char *) hashMap_remove(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
+ const char *uuid = NULL;
+
+ char buf[512];
+ snprintf(buf, 512, "/service/%s/%s", serviceId, interface);
+
+ char url[1024];
+ snprintf(url, 1024, "http://%s:%s%s", admin->ip, admin->port, buf);
+
+ uuid_t endpoint_uid;
+ uuid_generate(endpoint_uid);
+ char endpoint_uuid[37];
+ uuid_unparse_lower(endpoint_uid, endpoint_uuid);
+
+ bundleContext_getProperty(admin->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
+ properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
+ properties_set(endpointProperties, (char*) OSGI_FRAMEWORK_OBJECTCLASS, interface);
+ properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_SERVICE_ID, serviceId);
+ properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID, endpoint_uuid);
+ properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED, "true");
+ properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED_CONFIGS, (char*) CONFIGURATION_TYPE);
+ properties_set(endpointProperties, (char*) ENDPOINT_URL, url);
+
+ if (props != NULL) {
+ hash_map_iterator_pt propIter = hashMapIterator_create(props);
+ while (hashMapIterator_hasNext(propIter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(propIter);
+ properties_set(endpointProperties, (char*)hashMapEntry_getKey(entry), (char*)hashMapEntry_getValue(entry));
+ }
+ hashMapIterator_destroy(propIter);
+ }
+
+ *endpoint = calloc(1, sizeof(**endpoint));
+ if (!*endpoint) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*endpoint)->id = (char*)properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID);
+ const char *serviceId = NULL;
+ serviceReference_getProperty(reference, (char*) OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
+ (*endpoint)->serviceId = strtoull(serviceId, NULL, 0);
+ (*endpoint)->frameworkUUID = (char*) properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
+ (*endpoint)->service = strndup(interface, 1024*10);
+ (*endpoint)->properties = endpointProperties;
+ }
+
+ free(key);
+ free(serviceId);
+ free(keys);
+
+ return status;
+}
+
+static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip) {
+ celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+
+ struct ifaddrs *ifaddr, *ifa;
+ char host[NI_MAXHOST];
+
+ if (getifaddrs(&ifaddr) != -1)
+ {
+ for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
+ {
+ if (ifa->ifa_addr == NULL)
+ continue;
+
+ if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
+ if (interface == NULL) {
+ *ip = strdup(host);
+ status = CELIX_SUCCESS;
+ }
+ else if (strcmp(ifa->ifa_name, interface) == 0) {
+ *ip = strdup(host);
+ status = CELIX_SUCCESS;
+ }
+ }
+ }
+
+ freeifaddrs(ifaddr);
+ }
+
+ return status;
+}
+
+
+celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description)
+{
+ celix_status_t status = CELIX_SUCCESS;
+
+ properties_destroy((*description)->properties);
+ free((*description)->service);
+ free(*description);
+
+ return status;
+}
+
+
+celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpointDescription, import_registration_pt *out) {
+ celix_status_t status = CELIX_SUCCESS;
+ import_registration_pt import = NULL;
+
+ const char *objectClass = properties_get(endpointDescription->properties, "objectClass");
+ const char *serviceVersion = properties_get(endpointDescription->properties, (char*) CELIX_FRAMEWORK_SERVICE_VERSION);
+
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Import service %s", endpointDescription->service);
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "Registering service factory (proxy) for service '%s'\n", objectClass);
+
+ if (objectClass != NULL) {
+ status = importRegistration_create(admin->context, endpointDescription, objectClass, serviceVersion, &import);
+ }
+ if (status == CELIX_SUCCESS && import != NULL) {
+ importRegistration_setSendFn(import, (send_func_type) remoteServiceAdmin_send, admin);
+ }
+
+ if (status == CELIX_SUCCESS && import != NULL) {
+ status = importRegistration_start(import);
+ }
+
+ celixThreadMutex_lock(&admin->importedServicesLock);
+ arrayList_add(admin->importedServices, import);
+ celixThreadMutex_unlock(&admin->importedServicesLock);
+
+ if (status == CELIX_SUCCESS) {
+ *out = import;
+ }
+
+ return status;
+}
+
+
+celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_DFI: Removing imported service");
+
+ celixThreadMutex_lock(&admin->importedServicesLock);
+ int i;
+ int size = arrayList_size(admin->importedServices);
+ import_registration_pt current = NULL;
+ for (i = 0; i < size; i += 1) {
+ current = arrayList_get(admin->importedServices, i);
+ if (current == registration) {
+ arrayList_remove(admin->importedServices, i);
+ importRegistration_close(current);
+ importRegistration_destroy(current);
+ break;
+ }
+ }
+ celixThreadMutex_unlock(&admin->importedServicesLock);
+
+ return status;
+}
+
+
+static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus) {
+ remote_service_admin_pt rsa = handle;
+ struct post post;
+ post.readptr = request;
+ post.size = strlen(request);
+
+ struct get get;
+ get.size = 0;
+ get.writeptr = malloc(1);
+
+ char *serviceUrl = (char*)properties_get(endpointDescription->properties, (char*) ENDPOINT_URL);
+ char url[256];
+ snprintf(url, 256, "%s", serviceUrl);
+
+ // assume the default timeout
+ int timeout = DEFAULT_TIMEOUT;
+
+ const char *timeoutStr = NULL;
+ // Check if the endpoint has a timeout, if so, use it.
+ timeoutStr = (char*) properties_get(endpointDescription->properties, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT);
+ if (timeoutStr == NULL) {
+ // If not, get the global variable and use that one.
+ bundleContext_getProperty(rsa->context, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT, &timeoutStr);
+ }
+
+ // Update timeout if a property is used to set it.
+ if (timeoutStr != NULL) {
+ timeout = atoi(timeoutStr);
+ }
+
+ celix_status_t status = CELIX_SUCCESS;
+ CURL *curl;
+ CURLcode res;
+
+ curl = curl_easy_init();
+ if(!curl) {
+ status = CELIX_ILLEGAL_STATE;
+ } else {
+ curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_POST, 1L);
+ curl_easy_setopt(curl, CURLOPT_READFUNCTION, remoteServiceAdmin_readCallback);
+ curl_easy_setopt(curl, CURLOPT_READDATA, &post);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, remoteServiceAdmin_write);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&get);
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)post.size);
+ logHelper_log(rsa->loghelper, OSGI_LOGSERVICE_DEBUG, "RSA: Performing curl post\n");
+ res = curl_easy_perform(curl);
+
+ *reply = get.writeptr;
+ *replyStatus = res;
+
+ curl_easy_cleanup(curl);
+ }
+
+ return status;
+}
+
+static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp) {
+ struct post *post = userp;
+
+ if (post->size) {
+ *(char *) ptr = post->readptr[0];
+ post->readptr++;
+ post->size--;
+ return 1;
+ }
+
+ return 0;
+}
+
+static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp) {
+ size_t realsize = size * nmemb;
+ struct get *mem = (struct get *)userp;
+
+ mem->writeptr = realloc(mem->writeptr, mem->size + realsize + 1);
+ if (mem->writeptr == NULL) {
+ /* out of memory! */
+ printf("not enough memory (realloc returned NULL)");
+ exit(EXIT_FAILURE);
+ }
+
+ memcpy(&(mem->writeptr[mem->size]), contents, realsize);
+ mem->size += realsize;
+ mem->writeptr[mem->size] = 0;
+
+ return realsize;
+}
+
+
+static void remoteServiceAdmin_log(remote_service_admin_pt admin, int level, const char *file, int line, const char *msg, ...) {
+ va_list ap;
+ va_start(ap, msg);
+ int levels[5] = {0, OSGI_LOGSERVICE_ERROR, OSGI_LOGSERVICE_WARNING, OSGI_LOGSERVICE_INFO, OSGI_LOGSERVICE_DEBUG};
+
+ char buf1[256];
+ snprintf(buf1, 256, "FILE:%s, LINE:%i, MSG:", file, line);
+
+ char buf2[256];
+ vsnprintf(buf2, 256, msg, ap);
+ logHelper_log(admin->loghelper, levels[level], "%s%s", buf1, buf2);
+ va_end(ap);
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_dfi.h b/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_dfi.h
new file mode 100644
index 0000000..8b282f1
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_dfi.h
@@ -0,0 +1,57 @@
+/**
+ *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.
+ */
+/*
+ * remote_service_admin_http_impl.h
+ *
+ * \date Sep 30, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
+#define REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
+
+
+#include "bundle_context.h"
+#include "endpoint_description.h"
+
+//typedef struct remote_service_admin *remote_service_admin_pt;
+
+celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin);
+celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin);
+
+celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin);
+
+celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
+celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration);
+celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services);
+celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services);
+celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
+celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration);
+
+
+celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint);
+celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service);
+
+celix_status_t importReference_getImportedEndpoint(import_reference_pt reference);
+celix_status_t importReference_getImportedService(import_reference_pt reference);
+
+celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description);
+
+#endif /* REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt b/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
index 543d5a1..b3b272e 100644
--- a/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
@@ -31,10 +31,8 @@ add_executable(test_rsa_dfi
run_tests.cpp
rsa_tests.cpp
rsa_client_server_tests.cpp
-
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
)
-target_link_libraries(test_rsa_dfi Celix::framework ${CURL_LIBRARIES} ${CPPUTEST_LIBRARY})
+target_link_libraries(test_rsa_dfi PRIVATE Celix::framework ${CURL_LIBRARIES} ${CPPUTEST_LIBRARY} remote_service_admin_common)
get_property(rsa_bundle_file TARGET remote_service_admin_dfi PROPERTY BUNDLE_FILE)
get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE_FILE)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt
index 27c3804..65b18e8 100644
--- a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt
@@ -15,14 +15,6 @@
# specific language governing permissions and limitations
# under the License.
-include_directories(
- ${CPPUTEST_INCLUDE_DIR}
- ${PROJECT_SOURCE_DIR}/framework/public/include
- ${PROJECT_SOURCE_DIR}/utils/public/include
- ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include
-)
-
-
add_bundle(rsa_dfi_tst_bundle
VERSION 0.0.1
SOURCES
@@ -30,8 +22,8 @@ add_bundle(rsa_dfi_tst_bundle
)
bundle_files(rsa_dfi_tst_bundle
- ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
+ ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_api/include/org.apache.celix.calc.api.Calculator2.descriptor
DESTINATION .
)
-
-target_link_libraries(rsa_dfi_tst_bundle PRIVATE ${CPPUTEST_LIBRARY} )
+target_include_directories(rsa_dfi_tst_bundle PRIVATE calculator)
+target_link_libraries(rsa_dfi_tst_bundle PRIVATE ${CPPUTEST_LIBRARY} calculator_api)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/topology_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/CMakeLists.txt b/remote_services/topology_manager/CMakeLists.txt
index 4bac4fd..defee5c 100644
--- a/remote_services/topology_manager/CMakeLists.txt
+++ b/remote_services/topology_manager/CMakeLists.txt
@@ -16,27 +16,19 @@
# under the License.
celix_subproject(RSA_TOPOLOGY_MANAGER "Option to enable building the Remote Service Admin Service SHM bundle" ON DEPS REMOTE_SERVICE_ADMIN_DFI)
if (RSA_TOPOLOGY_MANAGER)
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/topology_manager/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/topology_manager/public/include")
- add_bundle(topology_manager SOURCES
- private/src/topology_manager
- private/src/scope
- private/src/activator
-
- private/include/topology_manager.h
- public/include/tm_scope.h
+ add_bundle(topology_manager
+ SOURCES
+ src/topology_manager
+ src/scope
+ src/activator
VERSION 0.9.0
SYMBOLIC_NAME "apache_celix_rs_topology_manager"
- NAME
- "Apache Celix RS Topology Manager"
+ NAME "Apache Celix RS Topology Manager"
)
- target_link_libraries(topology_manager PRIVATE Celix::log_helper)
+ target_include_directories(topology_manager PRIVATE src)
+ target_include_directories(topology_manager PUBLIC include)
+ target_link_libraries(topology_manager PRIVATE Celix::log_helper remote_service_admin_api)
install_bundle(topology_manager)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/topology_manager/include/tm_scope.h
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/include/tm_scope.h b/remote_services/topology_manager/include/tm_scope.h
new file mode 100644
index 0000000..d4f60ca
--- /dev/null
+++ b/remote_services/topology_manager/include/tm_scope.h
@@ -0,0 +1,46 @@
+/**
+ *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.
+ */
+/*
+ * tm_scope.h
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef TM_SCOPE_H_
+#define TM_SCOPE_H_
+
+#include "celix_errno.h"
+
+#define TOPOLOGYMANAGER_SCOPE_SERVICE "tm_scope"
+
+
+struct tm_scope_service {
+ void *handle; // scope_pt
+ celix_status_t (*addExportScope)(void *handle, char *filter, properties_pt props);
+ celix_status_t (*removeExportScope)(void *handle, char *filter);
+ celix_status_t (*addImportScope)(void *handle, char *filter);
+ celix_status_t (*removeImportScope)(void *handle, char *filter);
+};
+
+typedef struct tm_scope_service tm_scope_service_t;
+typedef tm_scope_service_t *tm_scope_service_pt;
+
+#endif /* TM_SCOPE_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/topology_manager/private/include/scope.h
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/private/include/scope.h b/remote_services/topology_manager/private/include/scope.h
deleted file mode 100644
index 4035e2c..0000000
--- a/remote_services/topology_manager/private/include/scope.h
+++ /dev/null
@@ -1,150 +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.
- */
-/*
- * scope.h
- *
- * \date Sep 29, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef TOPOLOGY_SCOPE_H_
-#define TOPOLOGY_SCOPE_H_
-
-#include "celixbool.h"
-#include "celix_errno.h"
-#include "celix_threads.h"
-#include "hash_map.h"
-#include "endpoint_description.h"
-#include "properties.h"
-#include "service_reference.h"
-#include "tm_scope.h"
-
-typedef struct scope *scope_pt;
-
-
-
-/* \brief create scope structure
- *
- * \param owning component pointer
- * \param scope to be created
- *
- * \return CELIX_SUCCESS
- * CELIX_ENOMEM
- */
-celix_status_t scope_scopeCreate(void *handle, scope_pt *scope);
-
-/* \brief destroy scope structure
- *
- * \param scope to be destroyed
- *
- * \return CELIX_SUCCESS
- */
-celix_status_t scope_scopeDestroy(scope_pt scope);
-
-/* \brief register export scope change callback of topology manager
- *
- * \param scope structure
- * \param changed function pointer
- *
- * \return -
- */
-void scope_setExportScopeChangedCallback(scope_pt scope, celix_status_t (*changed)(void *handle, char *servName));
-
-/* \brief register import scope change callback of topology manager
- *
- * \param scope structure
- * \param changed function pointer
- *
- * \return -
- */
-void scope_setImportScopeChangedCallback(scope_pt scope, celix_status_t (*changed)(void *handle, char *servName));
-
-
-/* \brief Test if scope allows import of service
- *
- * \param scope containing import rules
- * \param endpoint import service endpoint description
- *
- * \return true import allowed
- * false import not allowed
- */
-bool scope_allowImport(scope_pt scope, endpoint_description_pt endpoint);
-
-/* \brief Test if scope allows import of service
- *
- * \param scope containing export rules
- * \param reference to service
- * \param props, additional properties defining restrictions for the exported service
- * NULL if no additional restrictions found
- *
- * \return CELIX_SUCCESS
- *
- */
-celix_status_t scope_getExportProperties(scope_pt scope, service_reference_pt reference, properties_pt *props);
-
-/* \brief add restricted scope for specified exported service
- *
- * \param handle pointer to scope
- * \param filter, filter string
- * \param props additional properties defining restrictions for the exported service
- *
- * \return CELIX_SUCCESS if added to scope
- * CELIX_ILLEGAL_ARGUMENT if service scope is already restricted before
- *
- */
-celix_status_t tm_addExportScope(void *handle, char *filter, properties_pt props);
-
-/* \brief remove restricted scope for specified exported service
- *
- * \param handle pointer to scope
- * \param filter, filter string
- *
- * \return CELIX_SUCCESS if removed
- * CELIX_ILLEGAL_ARGUMENT if service not found in scope
- *
- */
-celix_status_t tm_removeExportScope(void *handle, char *filter);
-
-/* \brief add restricted scope for specified imported service
- *
- * \param handle pointer to scope
- * \param filter, filter string
- * \param props additional properties defining restrictions for the imported service
- *
- * \return CELIX_SUCCESS if added to scope
- * CELIX_ILLEGAL_ARGUMENT if service scope is already restricted before
- *
- */
-celix_status_t tm_addImportScope(void *handle, char *filter);
-
-
-/* \brief remove restricted scope for specified imported service
- *
- * \param handle pointer to scope
- * \param filter, filter string
- *
- * \return CELIX_SUCCESS if removed
- * CELIX_ILLEGAL_ARGUMENT if service not found in scope
- *
- */
-celix_status_t tm_removeImportScope(void *handle, char *filter);
-
-
-#endif // TOPOLOGY_SCOPE_H_
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/topology_manager/private/include/topology_manager.h
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/private/include/topology_manager.h b/remote_services/topology_manager/private/include/topology_manager.h
deleted file mode 100644
index 7e5e917..0000000
--- a/remote_services/topology_manager/private/include/topology_manager.h
+++ /dev/null
@@ -1,65 +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.
- */
-/*
- * topology_manager.h
- *
- * \date Sep 29, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef TOPOLOGY_MANAGER_H_
-#define TOPOLOGY_MANAGER_H_
-
-#include "endpoint_listener.h"
-#include "service_reference.h"
-#include "bundle_context.h"
-#include "log_helper.h"
-#include "scope.h"
-
-#define OSGI_RSA_REMOTE_SERVICE_ADMIN "remote_service_admin"
-
-typedef struct topology_manager *topology_manager_pt;
-
-celix_status_t topologyManager_create(bundle_context_pt context, log_helper_pt logHelper, topology_manager_pt *manager, void **scope);
-celix_status_t topologyManager_destroy(topology_manager_pt manager);
-celix_status_t topologyManager_closeImports(topology_manager_pt manager);
-
-celix_status_t topologyManager_rsaAdding(void *handle, service_reference_pt reference, void **service);
-celix_status_t topologyManager_rsaAdded(void *handle, service_reference_pt reference, void *service);
-celix_status_t topologyManager_rsaModified(void *handle, service_reference_pt reference, void *service);
-celix_status_t topologyManager_rsaRemoved(void *handle, service_reference_pt reference, void *service);
-
-celix_status_t topologyManager_endpointListenerAdding(void* handle, service_reference_pt reference, void** service);
-celix_status_t topologyManager_endpointListenerAdded(void* handle, service_reference_pt reference, void* service);
-celix_status_t topologyManager_endpointListenerModified(void * handle, service_reference_pt reference, void* service);
-celix_status_t topologyManager_endpointListenerRemoved(void * handle, service_reference_pt reference, void* service);
-
-celix_status_t topologyManager_serviceChanged(void *listener, service_event_pt event);
-
-celix_status_t topologyManager_addImportedService(void *handle, endpoint_description_pt endpoint, char *matchedFilter);
-celix_status_t topologyManager_removeImportedService(void *handle, endpoint_description_pt endpoint, char *matchedFilter);
-
-celix_status_t topologyManager_addExportedService(topology_manager_pt manager, service_reference_pt reference, char *serviceId);
-celix_status_t topologyManager_removeExportedService(topology_manager_pt manager, service_reference_pt reference, char *serviceId);
-
-celix_status_t topologyManager_listenerAdded(void *handle, array_list_pt listeners);
-celix_status_t topologyManager_listenerRemoved(void *handle, array_list_pt listeners);
-
-#endif /* TOPOLOGY_MANAGER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/topology_manager/private/src/activator.c
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/private/src/activator.c b/remote_services/topology_manager/private/src/activator.c
deleted file mode 100644
index 7f39a25..0000000
--- a/remote_services/topology_manager/private/src/activator.c
+++ /dev/null
@@ -1,289 +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.
- */
-/*
- * activator.c
- *
- * \date Sep 29, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "constants.h"
-#include "bundle_activator.h"
-#include "service_tracker.h"
-#include "service_registration.h"
-
-#include "topology_manager.h"
-#include "endpoint_listener.h"
-#include "remote_constants.h"
-#include "listener_hook_service.h"
-#include "log_service.h"
-#include "log_helper.h"
-#include "scope.h"
-#include "tm_scope.h"
-#include "topology_manager.h"
-
-struct activator {
- bundle_context_pt context;
-
- topology_manager_pt manager;
-
- service_tracker_pt endpointListenerTracker;
- service_tracker_pt remoteServiceAdminTracker;
- service_listener_pt serviceListener;
-
- endpoint_listener_pt endpointListener;
- service_registration_pt endpointListenerService;
-
- listener_hook_service_pt hookService;
- service_registration_pt hook;
-
- tm_scope_service_pt scopeService;
- service_registration_pt scopeReg;
-
- log_helper_pt loghelper;
-};
-
-
-static celix_status_t bundleActivator_createEPLTracker(struct activator *activator, service_tracker_pt *tracker);
-static celix_status_t bundleActivator_createRSATracker(struct activator *activator, service_tracker_pt *tracker);
-static celix_status_t bundleActivator_createServiceListener(struct activator *activator, service_listener_pt *listener);
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = NULL;
- void *scope;
-
- activator = calloc(1, sizeof(struct activator));
-
- if (!activator) {
- return CELIX_ENOMEM;
- }
-
- activator->context = context;
- activator->endpointListenerService = NULL;
- activator->endpointListenerTracker = NULL;
- activator->hook = NULL;
- activator->manager = NULL;
- activator->remoteServiceAdminTracker = NULL;
- activator->serviceListener = NULL;
- activator->scopeService = calloc(1, sizeof(*(activator->scopeService)));
- if (activator->scopeService == NULL)
- {
- free(activator);
- return CELIX_ENOMEM;
- }
-
- activator->scopeService->addExportScope = tm_addExportScope;
- activator->scopeService->removeExportScope = tm_removeExportScope;
- activator->scopeService->addImportScope = tm_addImportScope;
- activator->scopeService->removeImportScope = tm_removeImportScope;
- activator->scopeReg = NULL; // explicitly needed, otherwise exception
-
- logHelper_create(context, &activator->loghelper);
- logHelper_start(activator->loghelper);
-
- status = topologyManager_create(context, activator->loghelper, &activator->manager, &scope);
- activator->scopeService->handle = scope;
-
- if (status == CELIX_SUCCESS) {
- status = bundleActivator_createEPLTracker(activator, &activator->endpointListenerTracker);
- if (status == CELIX_SUCCESS) {
- status = bundleActivator_createRSATracker(activator, &activator->remoteServiceAdminTracker);
- if (status == CELIX_SUCCESS) {
- status = bundleActivator_createServiceListener(activator, &activator->serviceListener);
- if (status == CELIX_SUCCESS) {
- *userData = activator;
- }
- }
- }
- }
-
- if(status != CELIX_SUCCESS){
- bundleActivator_destroy(activator,context);
- }
-
- return status;
-}
-
-static celix_status_t bundleActivator_createEPLTracker(struct activator *activator, service_tracker_pt *tracker) {
- celix_status_t status;
-
- service_tracker_customizer_pt customizer = NULL;
-
- status = serviceTrackerCustomizer_create(activator->manager, topologyManager_endpointListenerAdding, topologyManager_endpointListenerAdded, topologyManager_endpointListenerModified,
- topologyManager_endpointListenerRemoved, &customizer);
-
- if (status == CELIX_SUCCESS) {
- status = serviceTracker_create(activator->context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, customizer, tracker);
- }
-
- return status;
-}
-
-static celix_status_t bundleActivator_createRSATracker(struct activator *activator, service_tracker_pt *tracker) {
- celix_status_t status;
-
- service_tracker_customizer_pt customizer = NULL;
-
- status = serviceTrackerCustomizer_create(activator->manager, topologyManager_rsaAdding, topologyManager_rsaAdded, topologyManager_rsaModified, topologyManager_rsaRemoved, &customizer);
-
- if (status == CELIX_SUCCESS) {
- status = serviceTracker_create(activator->context, OSGI_RSA_REMOTE_SERVICE_ADMIN, customizer, tracker);
- }
-
- return status;
-}
-
-static celix_status_t bundleActivator_createServiceListener(struct activator *activator, service_listener_pt *listener) {
- celix_status_t status = CELIX_SUCCESS;
-
- *listener = malloc(sizeof(**listener));
- if (!*listener) {
- return CELIX_ENOMEM;
- }
-
- (*listener)->handle = activator->manager;
- (*listener)->serviceChanged = topologyManager_serviceChanged;
-
- return status;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status;
- struct activator *activator = userData;
-
- endpoint_listener_pt endpointListener = malloc(sizeof(*endpointListener));
- endpointListener->handle = activator->manager;
- endpointListener->endpointAdded = topologyManager_addImportedService;
- endpointListener->endpointRemoved = topologyManager_removeImportedService;
- activator->endpointListener = endpointListener;
-
- const char *uuid = NULL;
- status = bundleContext_getProperty(activator->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
- if (!uuid) {
- logHelper_log(activator->loghelper, OSGI_LOGSERVICE_ERROR, "TOPOLOGY_MANAGER: no framework UUID defined?!");
- return CELIX_ILLEGAL_STATE;
- }
-
- size_t len = 14 + strlen(OSGI_FRAMEWORK_OBJECTCLASS) + strlen(OSGI_RSA_ENDPOINT_FRAMEWORK_UUID) + strlen(uuid);
- char *scope = malloc(len);
- if (!scope) {
- return CELIX_ENOMEM;
- }
-
- snprintf(scope, len, "(&(%s=*)(!(%s=%s)))", OSGI_FRAMEWORK_OBJECTCLASS, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
-
- logHelper_log(activator->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: endpoint listener scope is %s", scope);
-
- properties_pt props = properties_create();
- properties_set(props, (char *) OSGI_ENDPOINT_LISTENER_SCOPE, scope);
-
- // We can release the scope, as properties_set makes a copy of the key & value...
- free(scope);
-
- bundleContext_registerService(context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, endpointListener, props, &activator->endpointListenerService);
-
- listener_hook_service_pt hookService = malloc(sizeof(*hookService));
- hookService->handle = activator->manager;
- hookService->added = topologyManager_listenerAdded;
- hookService->removed = topologyManager_listenerRemoved;
- activator->hookService = hookService;
-
- bundleContext_registerService(context, (char *) OSGI_FRAMEWORK_LISTENER_HOOK_SERVICE_NAME, hookService, NULL, &activator->hook);
- bundleContext_addServiceListener(context, activator->serviceListener, "(service.exported.interfaces=*)");
-
- if (status == CELIX_SUCCESS) {
- serviceTracker_open(activator->remoteServiceAdminTracker);
- }
-
- if (status == CELIX_SUCCESS) {
- status = serviceTracker_open(activator->endpointListenerTracker);
- }
-
- bundleContext_registerService(context, (char *) TOPOLOGYMANAGER_SCOPE_SERVICE, activator->scopeService, NULL, &activator->scopeReg);
-
- array_list_pt references = NULL;
- bundleContext_getServiceReferences(context, NULL, "(service.exported.interfaces=*)", &references);
- int i;
- for (i = 0; i < arrayList_size(references); i++) {
- service_reference_pt reference = arrayList_get(references, i);
- const char* serviceId = NULL;
- status = CELIX_DO_IF(status, serviceReference_getProperty(reference, OSGI_FRAMEWORK_SERVICE_ID, &serviceId));
-
- CELIX_DO_IF(status, topologyManager_addExportedService(activator->manager, reference, (char*)serviceId));
- }
- arrayList_destroy(references);
-
- return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- if (serviceTracker_close(activator->remoteServiceAdminTracker) == CELIX_SUCCESS) {
- serviceTracker_destroy(activator->remoteServiceAdminTracker);
- }
-
- if (serviceTracker_close(activator->endpointListenerTracker) == CELIX_SUCCESS) {
- serviceTracker_destroy(activator->endpointListenerTracker);
- }
-
- bundleContext_removeServiceListener(context, activator->serviceListener);
- free(activator->serviceListener);
-
- serviceRegistration_unregister(activator->hook);
- free(activator->hookService);
-
- serviceRegistration_unregister(activator->endpointListenerService);
- free(activator->endpointListener);
-
- serviceRegistration_unregister(activator->scopeReg);
-
- topologyManager_closeImports(activator->manager);
-
- return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
-
- struct activator *activator = userData;
- if (!activator || !activator->manager) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- logHelper_stop(activator->loghelper);
- logHelper_destroy(&activator->loghelper);
-
- status = topologyManager_destroy(activator->manager);
-
- if (activator->scopeService) {
- free(activator->scopeService);
- }
-
- free(activator);
- }
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/topology_manager/private/src/scope.c
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/private/src/scope.c b/remote_services/topology_manager/private/src/scope.c
deleted file mode 100644
index b81d050..0000000
--- a/remote_services/topology_manager/private/src/scope.c
+++ /dev/null
@@ -1,326 +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.
- */
-/*
- * scope.c
- *
- * \date Sep 29, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "scope.h"
-#include "tm_scope.h"
-#include "topology_manager.h"
-#include "utils.h"
-
-struct scope_item {
- properties_pt props;
-};
-
-struct scope {
- void *manager; // owner of the scope datastructure
- celix_thread_mutex_t exportScopeLock;
- hash_map_pt exportScopes; // key is filter, value is scope_item (properties set)
-
- celix_thread_mutex_t importScopeLock;
- array_list_pt importScopes; // list of filters
-
- celix_status_t (*exportScopeChangedHandler)(void* manager, char *filter);
- celix_status_t (*importScopeChangedHandler)(void* manager, char *filter);
-};
-
-static celix_status_t import_equal(const void *, const void *, bool *equals);
-
-/*
- * SERVICES
- */
-
-celix_status_t tm_addExportScope(void *handle, char *filter, properties_pt props) {
- celix_status_t status = CELIX_SUCCESS;
- scope_pt scope = (scope_pt) handle;
- properties_pt present;
-
- if (handle == NULL)
- return CELIX_ILLEGAL_ARGUMENT;
-
- if (celixThreadMutex_lock(&scope->exportScopeLock) == CELIX_SUCCESS) {
- // For now we just don't allow two exactly the same filters
- // TODO: What we actually need is the following
- // If part of the new filter is already present in any of the filters in exportScopes
- // we have to assure that the new filter defines other property keys than the property keys
- // in the already defined filter!
- present = (properties_pt) hashMap_get(scope->exportScopes, filter);
- if (present == NULL) {
- struct scope_item *item = calloc(1, sizeof(*item));
- if (item == NULL) {
- status = CELIX_ENOMEM;
- } else {
- item->props = props;
- hashMap_put(scope->exportScopes, (void*) strdup(filter), (void*) item);
- }
- } else {
- // don't allow the same filter twice
- properties_destroy(props);
- status = CELIX_ILLEGAL_ARGUMENT;
- }
- celixThreadMutex_unlock(&scope->exportScopeLock);
- }
-
- if (scope->exportScopeChangedHandler != NULL) {
- status = CELIX_DO_IF(status, scope->exportScopeChangedHandler(scope->manager, filter));
- }
-
- return status;
-}
-
-celix_status_t tm_removeExportScope(void *handle, char *filter) {
- celix_status_t status = CELIX_SUCCESS;
- scope_pt scope = (scope_pt) handle;
-
- if (handle == NULL)
- return CELIX_ILLEGAL_ARGUMENT;
-
- if (celixThreadMutex_lock(&scope->exportScopeLock) == CELIX_SUCCESS) {
- struct scope_item *present = (struct scope_item *) hashMap_get(scope->exportScopes, filter);
- if (present == NULL) {
- status = CELIX_ILLEGAL_ARGUMENT;
- } else {
- properties_destroy(present->props);
- hashMap_remove(scope->exportScopes, filter); // frees also the item!
- }
- celixThreadMutex_unlock(&scope->exportScopeLock);
- }
- if (scope->exportScopeChangedHandler != NULL) {
- status = CELIX_DO_IF(status, scope->exportScopeChangedHandler(scope->manager, filter));
- }
- return status;
-}
-
-celix_status_t tm_addImportScope(void *handle, char *filter) {
- celix_status_t status = CELIX_SUCCESS;
- scope_pt scope = (scope_pt) handle;
-
- filter_pt new;
-
- if (handle == NULL)
- return CELIX_ILLEGAL_ARGUMENT;
- new = filter_create(filter);
- if (new == NULL) {
- return CELIX_ILLEGAL_ARGUMENT; // filter not parseble
- }
- if (celixThreadMutex_lock(&scope->importScopeLock) == CELIX_SUCCESS) {
- int index = arrayList_indexOf(scope->importScopes, new);
- filter_pt present = (filter_pt) arrayList_get(scope->importScopes, index);
- if (present == NULL) {
- arrayList_add(scope->importScopes, new);
- } else {
- filter_destroy(new);
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- celixThreadMutex_unlock(&scope->importScopeLock);
- }
- if (scope->importScopeChangedHandler != NULL) {
- status = CELIX_DO_IF(status, scope->importScopeChangedHandler(scope->manager, filter));
- }
- return status;
-}
-
-celix_status_t tm_removeImportScope(void *handle, char *filter) {
- celix_status_t status = CELIX_SUCCESS;
- scope_pt scope = (scope_pt) handle;
- filter_pt new;
-
- if (handle == NULL)
- return CELIX_ILLEGAL_ARGUMENT;
-
- new = filter_create(filter);
- if (new == NULL) {
- return CELIX_ILLEGAL_ARGUMENT; // filter not parseble
- }
-
- if (celixThreadMutex_lock(&scope->importScopeLock) == CELIX_SUCCESS) {
- int index = arrayList_indexOf(scope->importScopes, new);
- filter_pt present = (filter_pt) arrayList_get(scope->importScopes, index);
- if (present == NULL)
- status = CELIX_ILLEGAL_ARGUMENT;
- else {
- arrayList_removeElement(scope->importScopes, present);
- filter_destroy(present);
- }
- celixThreadMutex_unlock(&scope->importScopeLock);
- }
- if (scope->importScopeChangedHandler != NULL) {
- status = CELIX_DO_IF(status, scope->importScopeChangedHandler(scope->manager, filter));
- }
- filter_destroy(new);
- return status;
-}
-
-/*****************************************************************************
- * GLOBAL FUNCTIONS
- *****************************************************************************/
-
-void scope_setExportScopeChangedCallback(scope_pt scope, celix_status_t (*changed)(void *handle, char *servName)) {
- scope->exportScopeChangedHandler = changed;
-}
-
-void scope_setImportScopeChangedCallback(scope_pt scope, celix_status_t (*changed)(void *handle, char *servName)) {
- scope->importScopeChangedHandler = changed;
-}
-
-celix_status_t scope_scopeCreate(void *handle, scope_pt *scope) {
- celix_status_t status = CELIX_SUCCESS;
-
- *scope = calloc(1, sizeof **scope);
-
- if (*scope == NULL) {
- return CELIX_ENOMEM;
- }
-
- (*scope)->manager = handle;
- celixThreadMutex_create(&(*scope)->exportScopeLock, NULL);
- celixThreadMutex_create(&(*scope)->importScopeLock, NULL);
-
- (*scope)->exportScopes = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- arrayList_createWithEquals(import_equal, &((*scope)->importScopes));
- (*scope)->exportScopeChangedHandler = NULL;
-
- return status;
-}
-
-celix_status_t scope_scopeDestroy(scope_pt scope) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (celixThreadMutex_lock(&scope->exportScopeLock) == CELIX_SUCCESS) {
- hash_map_iterator_pt iter = hashMapIterator_create(scope->exportScopes);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt scopedEntry = hashMapIterator_nextEntry(iter);
- struct scope_item *item = (struct scope_item*) hashMapEntry_getValue(scopedEntry);
- properties_destroy(item->props);
- }
- hashMapIterator_destroy(iter);
- hashMap_destroy(scope->exportScopes, true, true); // free keys, free values
- celixThreadMutex_unlock(&scope->exportScopeLock);
- }
-
- if (celixThreadMutex_lock(&scope->importScopeLock) == CELIX_SUCCESS) {
- array_list_iterator_pt imp_iter = arrayListIterator_create(scope->importScopes);
- while (arrayListIterator_hasNext(imp_iter)) {
- filter_pt element = (filter_pt) arrayListIterator_next(imp_iter);
- filter_destroy(element);
- // no need to call arrayList_removeElement(element) because complete list is destroyed
- }
- arrayListIterator_destroy(imp_iter);
- arrayList_destroy(scope->importScopes);
- celixThreadMutex_unlock(&scope->importScopeLock);
- }
-
- celixThreadMutex_destroy(&scope->exportScopeLock);
- celixThreadMutex_destroy(&scope->importScopeLock);
- free(scope);
- return status;
-}
-
-/*****************************************************************************
- * STATIC FUNCTIONS
- *****************************************************************************/
-static celix_status_t import_equal(const void *src, const void *dest, bool *equals) {
- celix_status_t status;
-
- filter_pt src_filter = (filter_pt) src;
- filter_pt dest_filter = (filter_pt) dest;
- status = filter_match_filter(src_filter, dest_filter, equals);
- return status;
-}
-
-bool scope_allowImport(scope_pt scope, endpoint_description_pt endpoint) {
- bool allowImport = false;
- array_list_iterator_pt iter;
-
- if (celixThreadMutex_lock(&(scope->importScopeLock)) == CELIX_SUCCESS) {
- if (arrayList_size(scope->importScopes) == 0) {
- allowImport = true;
- } else {
- iter = arrayListIterator_create(scope->importScopes);
- while ((allowImport == false) && arrayListIterator_hasNext(iter)) {
- filter_pt element = (filter_pt) arrayListIterator_next(iter);
- filter_match(element, endpoint->properties, &allowImport);
- }
- arrayListIterator_destroy(iter);
- }
- celixThreadMutex_unlock(&scope->importScopeLock);
- }
- return allowImport;
-}
-
-celix_status_t scope_getExportProperties(scope_pt scope, service_reference_pt reference, properties_pt *props) {
- celix_status_t status = CELIX_SUCCESS;
- unsigned int size = 0;
- char **keys;
- bool found = false;
-
- *props = NULL;
- properties_pt serviceProperties = properties_create(); // GB: not sure if a copy is needed
- // or serviceReference_getProperties() is
- // is acceptable
-
- serviceReference_getPropertyKeys(reference, &keys, &size);
- for (int i = 0; i < size; i++) {
- char *key = keys[i];
- const char* value = NULL;
-
- if (serviceReference_getProperty(reference, key, &value) == CELIX_SUCCESS) {
-// && strcmp(key, (char*) OSGI_RSA_SERVICE_EXPORTED_INTERFACES) != 0
-// && strcmp(key, (char*) OSGI_FRAMEWORK_OBJECTCLASS) != 0) {
- properties_set(serviceProperties, key, value);
- }
-
- }
-
- free(keys);
-
- if (celixThreadMutex_lock(&(scope->exportScopeLock)) == CELIX_SUCCESS) {
- hash_map_iterator_pt scopedPropIter = hashMapIterator_create(scope->exportScopes);
- // TODO: now stopping if first filter matches, alternatively we could build up
- // the additional output properties for each filter that matches?
- while ((!found) && hashMapIterator_hasNext(scopedPropIter)) {
- hash_map_entry_pt scopedEntry = hashMapIterator_nextEntry(scopedPropIter);
- char *filterStr = (char *) hashMapEntry_getKey(scopedEntry);
- filter_pt filter = filter_create(filterStr);
- if (filter != NULL) {
- // test if the scope filter matches the exported service properties
- status = filter_match(filter, serviceProperties, &found);
- if (found) {
- struct scope_item *item = (struct scope_item *) hashMapEntry_getValue(scopedEntry);
- *props = item->props;
- }
- }
- filter_destroy(filter);
- }
- hashMapIterator_destroy(scopedPropIter);
- properties_destroy(serviceProperties);
-
- celixThreadMutex_unlock(&(scope->exportScopeLock));
- }
-
- return status;
-}
[26/54] [abbrv] celix git commit: CELIX-417: Refactors CMake usage
for the RSA bundles
Posted by pn...@apache.org.
CELIX-417: Refactors CMake usage for the RSA bundles
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/27a2aa75
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/27a2aa75
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/27a2aa75
Branch: refs/heads/develop
Commit: 27a2aa756025018dd2406cc5b423d2ff5e38cf87
Parents: 2a670f2
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Nov 24 11:38:49 2017 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Fri Nov 24 11:38:49 2017 +0100
----------------------------------------------------------------------
cmake/cmake_celix/BundlePackaging.cmake | 6 +-
cmake/cmake_celix/DeployPackaging.cmake | 2 +-
dfi/CMakeLists.txt | 41 +-
framework/src/bundle_context.c | 2 +-
log_service/loghelper_include/log_helper.h | 1 +
log_writer/CMakeLists.txt | 2 +-
remote_services/CMakeLists.txt | 2 +
remote_services/civetweb/CMakeLists.txt | 23 +
remote_services/civetweb/include/civetweb.h | 657 ++
remote_services/civetweb/src/civetweb.c | 7907 ++++++++++++++++++
remote_services/civetweb/src/md5.inl | 461 +
remote_services/discovery_common/CMakeLists.txt | 18 +-
.../discovery_common/include/civetweb.h | 657 --
.../discovery_common/include/discovery.h | 23 +-
.../discovery_common/include/discovery_type.h | 27 +
.../include/endpoint_discovery_poller.h | 9 +-
.../include/endpoint_discovery_server.h | 11 +-
remote_services/discovery_common/src/civetweb.c | 7907 ------------------
.../discovery_common/src/discovery.c | 1 -
.../src/endpoint_discovery_poller.c | 7 +-
.../src/endpoint_discovery_server.c | 20 +-
remote_services/discovery_common/src/md5.inl | 461 -
.../discovery_configured/CMakeLists.txt | 10 +-
.../discovery_configured/src/discovery_impl.c | 4 +-
.../discovery_configured/src/discovery_impl.h | 28 +-
remote_services/discovery_etcd/CMakeLists.txt | 16 +-
.../discovery_etcd/src/discovery_impl.c | 44 +-
.../discovery_etcd/src/discovery_impl.h | 16 +-
.../discovery_etcd/src/etcd_watcher.h | 1 +
remote_services/discovery_shm/CMakeLists.txt | 6 +-
.../discovery_shm/src/discovery_impl.c | 42 +-
.../discovery_shm/src/discovery_impl.h | 21 +-
.../discovery_shm/src/discovery_shmWatcher.c | 19 +-
.../discovery_shm/src/discovery_shmWatcher.h | 1 +
.../remote_service_admin_common/CMakeLists.txt | 4 +-
.../remote_service_admin_dfi/CMakeLists.txt | 32 +-
.../remote_service_admin_dfi/rsa/CMakeLists.txt | 34 -
.../rsa/src/dfi_utils.c | 98 -
.../rsa/src/dfi_utils.h | 30 -
.../rsa/src/export_registration_dfi.c | 251 -
.../rsa/src/export_registration_dfi.h | 38 -
.../rsa/src/import_registration_dfi.c | 402 -
.../rsa/src/import_registration_dfi.h | 44 -
.../rsa/src/remote_service_admin_activator.c | 124 -
.../rsa/src/remote_service_admin_dfi.c | 775 --
.../rsa/src/remote_service_admin_dfi.h | 57 -
.../rsa_tst/CMakeLists.txt | 52 -
.../rsa_tst/bundle/CMakeLists.txt | 29 -
.../rsa_tst/bundle/tst_activator.c | 153 -
.../rsa_tst/bundle/tst_service.h | 32 -
.../rsa_tst/client.properties.in | 8 -
.../rsa_tst/config.properties.in | 20 -
.../rsa_tst/rsa_client_server_tests.cpp | 133 -
.../rsa_tst/rsa_tests.cpp | 234 -
.../rsa_tst/run_tests.cpp | 25 -
.../rsa_tst/server.properties.in | 23 -
.../remote_service_admin_dfi/src/dfi_utils.c | 108 +
.../remote_service_admin_dfi/src/dfi_utils.h | 30 +
.../src/export_registration_dfi.c | 251 +
.../src/export_registration_dfi.h | 38 +
.../src/import_registration_dfi.c | 402 +
.../src/import_registration_dfi.h | 44 +
.../src/remote_service_admin_activator.c | 124 +
.../src/remote_service_admin_dfi.c | 771 ++
.../src/remote_service_admin_dfi.h | 57 +
.../test/CMakeLists.txt | 61 +
.../test/client.properties.in | 8 +
.../test/config.properties.in | 20 +
.../test/server.properties.in | 23 +
.../test/src/rsa_client_server_tests.cpp | 133 +
.../test/src/rsa_tests.cpp | 234 +
.../test/src/run_tests.cpp | 25 +
.../test/src/tst_activator.c | 162 +
.../test/src/tst_service.h | 32 +
.../topology_manager/src/topology_manager.h | 1 +
.../topology_manager/tms_tst/CMakeLists.txt | 20 +-
.../tms_tst/bundle/CMakeLists.txt | 2 +-
.../tms_tst/disc_mock/CMakeLists.txt | 8 +-
.../tms_tst/disc_mock/disc_mock_activator.c | 1 -
79 files changed, 11847 insertions(+), 11759 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/cmake/cmake_celix/BundlePackaging.cmake
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/BundlePackaging.cmake b/cmake/cmake_celix/BundlePackaging.cmake
index c5d75d6..205bec1 100644
--- a/cmake/cmake_celix/BundlePackaging.cmake
+++ b/cmake/cmake_celix/BundlePackaging.cmake
@@ -145,14 +145,14 @@ function(add_bundle)
set_library_version(${BUNDLE_TARGET_NAME} ${BUNDLE_VERSION})
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES
"BUNDLE_TARGET_IS_LIB" TRUE
- "BUNDLE_BUILD_BUNDLE_TARGET" "${BUNDLE_TARGET_NAME}_bundle"
+ "BUNDLE_TARGET" "${BUNDLE_TARGET_NAME}_bundle"
)
target_link_libraries(${BUNDLE_TARGET_NAME} PRIVATE Celix::framework)
else()
add_custom_target(${BUNDLE_TARGET_NAME})
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES
"BUNDLE_TARGET_IS_LIB" FALSE
- "BUNDLE_BUILD_BUNDLE_TARGET" "${BUNDLE_TARGET_NAME}_bundle"
+ "BUNDLE_TARGET" "${BUNDLE_TARGET_NAME}_bundle"
)
endif()
add_custom_target(${BUNDLE_TARGET_NAME}_bundle
@@ -213,7 +213,7 @@ function(add_bundle)
#############################
#alreadyer set
# BUNDLE_TARGET_IS_LIB -> true (can be use to test if target is bundle target
- # BUNDLE_BUILD_BUNDLE_TARGET -> refers to the _bundle target which is responsible for building the zip file
+ # BUNDLE_TARGET -> refers to the _bundle target which is responsible for building the zip file
#internal use
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_IS_BUNDLE_TARGET" TRUE) #indicate that this is a bundle target
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_DEPEND_TARGETS" "") #bundle target dependencies. Note can be extended after the add_bundle call
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/cmake/cmake_celix/DeployPackaging.cmake
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/DeployPackaging.cmake b/cmake/cmake_celix/DeployPackaging.cmake
index e7f8dc6..dfef9dd 100644
--- a/cmake/cmake_celix/DeployPackaging.cmake
+++ b/cmake/cmake_celix/DeployPackaging.cmake
@@ -227,7 +227,7 @@ function(celix_container_bundles_dir)
COMMENT "Copying bundle '${BUNDLE}' to '${CONTAINER_LOC}/${BD_DIR_NAME}'"
DEPENDS $<TARGET_PROPERTY:${BUNDLE},BUNDLE_BUILD_BUNDLE_TARGET>
)
- get_target_property(BUILD_BUNDLE_TARGET ${BUNDLE} BUNDLE_BUILD_BUNDLE_TARGET)
+ get_target_property(BUILD_BUNDLE_TARGET ${BUNDLE} BUNDLE_TARGET)
add_dependencies(${CONTAINER_TARGET} ${BUILD_BUNDLE_TARGET}) #ensure the the deploy depends on the _bundle target, custom_command depends on add_library
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/dfi/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/dfi/CMakeLists.txt b/dfi/CMakeLists.txt
index ad3a41f..642ac68 100644
--- a/dfi/CMakeLists.txt
+++ b/dfi/CMakeLists.txt
@@ -18,36 +18,37 @@
find_package(FFI REQUIRED)
find_package(Jansson REQUIRED)
-add_library(dfi SHARED
- src/dyn_common.c
- src/dyn_type.c
- src/dyn_function.c
- src/dyn_interface.c
- src/dyn_message.c
- src/json_serializer.c
- src/json_rpc.c
-)
-set_target_properties(dfi PROPERTIES OUTPUT_NAME "celix_dfi")
-
-target_include_directories(dfi PUBLIC
- include
- ${JANSSON_INCLUDE_DIRS}
-)
-target_include_directories(dfi PRIVATE
- src
- ${FFI_INCLUDE_DIRS}
+set(SOURCES
+ src/dyn_common.c
+ src/dyn_type.c
+ src/dyn_function.c
+ src/dyn_interface.c
+ src/dyn_message.c
+ src/json_serializer.c
+ src/json_rpc.c
)
+add_library(dfi SHARED ${SOURCES})
+set_target_properties(dfi PROPERTIES OUTPUT_NAME "celix_dfi")
+target_include_directories(dfi PUBLIC include ${JANSSON_INCLUDE_DIRS})
+target_include_directories(dfi PRIVATE src ${FFI_INCLUDE_DIRS})
target_link_libraries(dfi PUBLIC ${JANSSON_LIBRARY})
target_link_libraries(dfi PRIVATE Celix::utils ${FFI_LIBRARIES})
-
set_target_properties(dfi PROPERTIES "SOVERSION" 1)
-install(TARGETS dfi DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT framework)
+add_library(dfi_static STATIC ${SOURCES})
+set_target_properties(dfi_static PROPERTIES OUTPUT_NAME "celix_dfi_static")
+target_include_directories(dfi_static PUBLIC include ${JANSSON_INCLUDE_DIRS})
+target_include_directories(dfi_static PRIVATE src ${FFI_INCLUDE_DIRS})
+target_link_libraries(dfi_static PUBLIC ${JANSSON_LIBRARY})
+target_link_libraries(dfi_static PRIVATE Celix::utils ${FFI_LIBRARIES})
+
+install(TARGETS dfi dfi_static DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT framework)
#Alias setup to match external usage
add_library(Celix::dfi ALIAS dfi)
+add_library(Celix::dfi_static ALIAS dfi_static)
if (ENABLE_TESTING)
find_package(CppUTest REQUIRED)
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/framework/src/bundle_context.c
----------------------------------------------------------------------
diff --git a/framework/src/bundle_context.c b/framework/src/bundle_context.c
index face85d..928a7a4 100644
--- a/framework/src/bundle_context.c
+++ b/framework/src/bundle_context.c
@@ -222,7 +222,7 @@ celix_status_t bundleContext_ungetServiceReference(bundle_context_pt context, se
celix_status_t bundleContext_getService(bundle_context_pt context, service_reference_pt reference, void** service_instance) {
celix_status_t status = CELIX_SUCCESS;
- if (context != NULL && reference != NULL && *service_instance == NULL) {
+ if (context != NULL && reference != NULL && service_instance != NULL) {
/*NOTE argument service_instance should be considerd a 'const void**'.
To ensure backwards compatiblity a cast is made instead.
*/
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/log_service/loghelper_include/log_helper.h
----------------------------------------------------------------------
diff --git a/log_service/loghelper_include/log_helper.h b/log_service/loghelper_include/log_helper.h
index 04e4bb2..2ae9d83 100644
--- a/log_service/loghelper_include/log_helper.h
+++ b/log_service/loghelper_include/log_helper.h
@@ -24,6 +24,7 @@
#include "bundle_context.h"
#include "log_service.h"
+typedef struct log_helper log_helper_t;
typedef struct log_helper* log_helper_pt;
celix_status_t logHelper_create(bundle_context_pt context, log_helper_pt* log_helper);
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/log_writer/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/log_writer/CMakeLists.txt b/log_writer/CMakeLists.txt
index 340af15..e44ef65 100644
--- a/log_writer/CMakeLists.txt
+++ b/log_writer/CMakeLists.txt
@@ -23,5 +23,5 @@ if (LOG_WRITER)
#Setup target aliases to match external usage
add_library(Celix::log_writer_stdout ALIAS log_writer_stdout)
- add_library(Celix::log_writer_syslog ALIAS log_writer_syslog)
+ #add_library(Celix::log_writer_syslog ALIAS log_writer_syslog)
endif (LOG_WRITER)
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/CMakeLists.txt b/remote_services/CMakeLists.txt
index 7ca1c44..4e1f5b3 100644
--- a/remote_services/CMakeLists.txt
+++ b/remote_services/CMakeLists.txt
@@ -22,6 +22,8 @@ if (REMOTE_SERVICE_ADMIN)
add_subdirectory(topology_manager)
+ add_subdirectory(civetweb)
+
add_subdirectory(discovery_common)
add_subdirectory(discovery_configured)
add_subdirectory(discovery_etcd)
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/civetweb/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/civetweb/CMakeLists.txt b/remote_services/civetweb/CMakeLists.txt
new file mode 100644
index 0000000..e9e272e
--- /dev/null
+++ b/remote_services/civetweb/CMakeLists.txt
@@ -0,0 +1,23 @@
+# 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.
+
+
+add_library(civetweb OBJECT
+ src/civetweb.c
+ src/md5.inl
+)
+target_include_directories(civetweb PUBLIC include)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/civetweb/include/civetweb.h
----------------------------------------------------------------------
diff --git a/remote_services/civetweb/include/civetweb.h b/remote_services/civetweb/include/civetweb.h
new file mode 100644
index 0000000..61a8e98
--- /dev/null
+++ b/remote_services/civetweb/include/civetweb.h
@@ -0,0 +1,657 @@
+/* Copyright (c) 2013-2014 the Civetweb developers
+ * Copyright (c) 2004-2013 Sergey Lyubka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef CIVETWEB_HEADER_INCLUDED
+#define CIVETWEB_HEADER_INCLUDED
+
+#ifndef CIVETWEB_VERSION
+#define CIVETWEB_VERSION "1.7"
+#endif
+
+#ifndef CIVETWEB_API
+ #if defined(_WIN32)
+ #if defined(CIVETWEB_DLL_EXPORTS)
+ #define CIVETWEB_API __declspec(dllexport)
+ #elif defined(CIVETWEB_DLL_IMPORTS)
+ #define CIVETWEB_API __declspec(dllimport)
+ #else
+ #define CIVETWEB_API
+ #endif
+ #else
+ #define CIVETWEB_API
+ #endif
+#endif
+
+#include <stdio.h>
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+struct mg_context; /* Handle for the HTTP service itself */
+struct mg_connection; /* Handle for the individual connection */
+
+
+/* This structure contains information about the HTTP request. */
+struct mg_request_info {
+ const char *request_method; /* "GET", "POST", etc */
+ const char *uri; /* URL-decoded URI */
+ const char *http_version; /* E.g. "1.0", "1.1" */
+ const char *query_string; /* URL part after '?', not including '?', or
+ NULL */
+ const char *remote_user; /* Authenticated user, or NULL if no auth
+ used */
+ char remote_addr[48]; /* Client's IP address as a string. */
+ long remote_ip; /* Client's IP address. Deprecated: use remote_addr instead */
+
+ long long content_length; /* Length (in bytes) of the request body,
+ can be -1 if no length was given. */
+ int remote_port; /* Client's port */
+ int is_ssl; /* 1 if SSL-ed, 0 if not */
+ void *user_data; /* User data pointer passed to mg_start() */
+ void *conn_data; /* Connection-specific user data */
+
+ int num_headers; /* Number of HTTP headers */
+ struct mg_header {
+ const char *name; /* HTTP header name */
+ const char *value; /* HTTP header value */
+ } http_headers[64]; /* Maximum 64 headers */
+};
+
+
+/* This structure needs to be passed to mg_start(), to let civetweb know
+ which callbacks to invoke. For a detailed description, see
+ https://github.com/bel2125/civetweb/blob/master/docs/UserManual.md */
+struct mg_callbacks {
+ /* Called when civetweb has received new HTTP request.
+ If the callback returns one, it must process the request
+ by sending valid HTTP headers and a body. Civetweb will not do
+ any further processing. Otherwise it must return zero.
+ Note that since V1.7 the "begin_request" function is called
+ before an authorization check. If an authorization check is
+ required, use a request_handler instead.
+ Return value:
+ 0: civetweb will process the request itself. In this case,
+ the callback must not send any data to the client.
+ 1: callback already processed the request. Civetweb will
+ not send any data after the callback returned. */
+ int (*begin_request)(struct mg_connection *);
+
+ /* Called when civetweb has finished processing request. */
+ void (*end_request)(const struct mg_connection *, int reply_status_code);
+
+ /* Called when civetweb is about to log a message. If callback returns
+ non-zero, civetweb does not log anything. */
+ int (*log_message)(const struct mg_connection *, const char *message);
+
+ /* Called when civetweb initializes SSL library.
+ Parameters:
+ user_data: parameter user_data passed when starting the server.
+ Return value:
+ 0: civetweb will set up the SSL certificate.
+ 1: civetweb assumes the callback already set up the certificate.
+ -1: initializing ssl fails. */
+ int (*init_ssl)(void *ssl_context, void *user_data);
+
+ /* Called when websocket request is received, before websocket handshake.
+ Return value:
+ 0: civetweb proceeds with websocket handshake.
+ 1: connection is closed immediately. */
+ int (*websocket_connect)(const struct mg_connection *);
+
+ /* Called when websocket handshake is successfully completed, and
+ connection is ready for data exchange. */
+ void (*websocket_ready)(struct mg_connection *);
+
+ /* Called when data frame has been received from the client.
+ Parameters:
+ bits: first byte of the websocket frame, see websocket RFC at
+ http://tools.ietf.org/html/rfc6455, section 5.2
+ data, data_len: payload, with mask (if any) already applied.
+ Return value:
+ 1: keep this websocket connection open.
+ 0: close this websocket connection. */
+ int (*websocket_data)(struct mg_connection *, int bits,
+ char *data, size_t data_len);
+
+ /* Called when civetweb is closing a connection. The per-context mutex is
+ locked when this is invoked. This is primarily useful for noting when
+ a websocket is closing and removing it from any application-maintained
+ list of clients. */
+ void (*connection_close)(struct mg_connection *);
+
+ /* Called when civetweb tries to open a file. Used to intercept file open
+ calls, and serve file data from memory instead.
+ Parameters:
+ path: Full path to the file to open.
+ data_len: Placeholder for the file size, if file is served from
+ memory.
+ Return value:
+ NULL: do not serve file from memory, proceed with normal file open.
+ non-NULL: pointer to the file contents in memory. data_len must be
+ initilized with the size of the memory block. */
+ const char * (*open_file)(const struct mg_connection *,
+ const char *path, size_t *data_len);
+
+ /* Called when civetweb is about to serve Lua server page, if
+ Lua support is enabled.
+ Parameters:
+ lua_context: "lua_State *" pointer. */
+ void (*init_lua)(struct mg_connection *, void *lua_context);
+
+ /* Called when civetweb has uploaded a file to a temporary directory as a
+ result of mg_upload() call.
+ Parameters:
+ file_name: full path name to the uploaded file. */
+ void (*upload)(struct mg_connection *, const char *file_name);
+
+ /* Called when civetweb is about to send HTTP error to the client.
+ Implementing this callback allows to create custom error pages.
+ Parameters:
+ status: HTTP error status code.
+ Return value:
+ 1: run civetweb error handler.
+ 0: callback already handled the error. */
+ int (*http_error)(struct mg_connection *, int status);
+
+ /* Called after civetweb context has been created, before requests
+ are processed.
+ Parameters:
+ ctx: context handle */
+ void (*init_context)(struct mg_context * ctx);
+
+ /* Called when civetweb context is deleted.
+ Parameters:
+ ctx: context handle */
+ void (*exit_context)(struct mg_context * ctx);
+};
+
+
+/* Start web server.
+
+ Parameters:
+ callbacks: mg_callbacks structure with user-defined callbacks.
+ options: NULL terminated list of option_name, option_value pairs that
+ specify Civetweb configuration parameters.
+
+ Side-effects: on UNIX, ignores SIGCHLD and SIGPIPE signals. If custom
+ processing is required for these, signal handlers must be set up
+ after calling mg_start().
+
+
+ Example:
+ const char *options[] = {
+ "document_root", "/var/www",
+ "listening_ports", "80,443s",
+ NULL
+ };
+ struct mg_context *ctx = mg_start(&my_func, NULL, options);
+
+ Refer to https://github.com/bel2125/civetweb/blob/master/docs/UserManual.md
+ for the list of valid option and their possible values.
+
+ Return:
+ web server context, or NULL on error. */
+CIVETWEB_API struct mg_context *mg_start(const struct mg_callbacks *callbacks,
+ void *user_data,
+ const char **configuration_options);
+
+
+/* Stop the web server.
+
+ Must be called last, when an application wants to stop the web server and
+ release all associated resources. This function blocks until all Civetweb
+ threads are stopped. Context pointer becomes invalid. */
+CIVETWEB_API void mg_stop(struct mg_context *);
+
+
+/* mg_request_handler
+
+ Called when a new request comes in. This callback is URI based
+ and configured with mg_set_request_handler().
+
+ Parameters:
+ conn: current connection information.
+ cbdata: the callback data configured with mg_set_request_handler().
+ Returns:
+ 0: the handler could not handle the request, so fall through.
+ 1: the handler processed the request. */
+typedef int (* mg_request_handler)(struct mg_connection *conn, void *cbdata);
+
+
+/* mg_set_request_handler
+
+ Sets or removes a URI mapping for a request handler.
+
+ URI's are ordered and prefixed URI's are supported. For example,
+ consider two URIs: /a/b and /a
+ /a matches /a
+ /a/b matches /a/b
+ /a/c matches /a
+
+ Parameters:
+ ctx: server context
+ uri: the URI to configure
+ handler: the callback handler to use when the URI is requested.
+ If NULL, the URI will be removed.
+ cbdata: the callback data to give to the handler when it s requested. */
+CIVETWEB_API void mg_set_request_handler(struct mg_context *ctx, const char *uri, mg_request_handler handler, void *cbdata);
+
+
+/* Get the value of particular configuration parameter.
+ The value returned is read-only. Civetweb does not allow changing
+ configuration at run time.
+ If given parameter name is not valid, NULL is returned. For valid
+ names, return value is guaranteed to be non-NULL. If parameter is not
+ set, zero-length string is returned. */
+CIVETWEB_API const char *mg_get_option(const struct mg_context *ctx, const char *name);
+
+
+/* Get context from connection. */
+CIVETWEB_API struct mg_context *mg_get_context(struct mg_connection *conn);
+
+
+/* Get user data passed to mg_start from context. */
+CIVETWEB_API void *mg_get_user_data(struct mg_context *ctx);
+
+
+#if defined(MG_LEGACY_INTERFACE)
+/* Return array of strings that represent valid configuration options.
+ For each option, option name and default value is returned, i.e. the
+ number of entries in the array equals to number_of_options x 2.
+ Array is NULL terminated. */
+/* Deprecated: Use mg_get_valid_options instead. */
+CIVETWEB_API const char **mg_get_valid_option_names(void);
+#endif
+
+
+struct mg_option {
+ const char * name;
+ int type;
+ const char * default_value;
+};
+
+enum {
+ CONFIG_TYPE_UNKNOWN = 0x0,
+ CONFIG_TYPE_NUMBER = 0x1,
+ CONFIG_TYPE_STRING = 0x2,
+ CONFIG_TYPE_FILE = 0x3,
+ CONFIG_TYPE_DIRECTORY = 0x4,
+ CONFIG_TYPE_BOOLEAN = 0x5,
+ CONFIG_TYPE_EXT_PATTERN = 0x6
+};
+
+
+/* Return array of struct mg_option, representing all valid configuration
+ options of civetweb.c.
+ The array is terminated by a NULL name option. */
+CIVETWEB_API const struct mg_option *mg_get_valid_options(void);
+
+
+/* Get the list of ports that civetweb is listening on.
+ size is the size of the ports int array and ssl int array to fill.
+ It is the caller's responsibility to make sure ports and ssl each
+ contain at least size int elements worth of memory to write into.
+ Return value is the number of ports and ssl information filled in.
+ The value returned is read-only. Civetweb does not allow changing
+ configuration at run time. */
+CIVETWEB_API size_t mg_get_ports(const struct mg_context *ctx, size_t size, int* ports, int* ssl);
+
+
+/* Add, edit or delete the entry in the passwords file.
+
+ This function allows an application to manipulate .htpasswd files on the
+ fly by adding, deleting and changing user records. This is one of the
+ several ways of implementing authentication on the server side. For another,
+ cookie-based way please refer to the examples/chat in the source tree.
+
+ If password is not NULL, entry is added (or modified if already exists).
+ If password is NULL, entry is deleted.
+
+ Return:
+ 1 on success, 0 on error. */
+CIVETWEB_API int mg_modify_passwords_file(const char *passwords_file_name,
+ const char *domain,
+ const char *user,
+ const char *password);
+
+
+/* Return information associated with the request. */
+CIVETWEB_API struct mg_request_info *mg_get_request_info(struct mg_connection *);
+
+
+/* Send data to the client.
+ Return:
+ 0 when the connection has been closed
+ -1 on error
+ >0 number of bytes written on success */
+CIVETWEB_API int mg_write(struct mg_connection *, const void *buf, size_t len);
+
+
+/* Send data to a websocket client wrapped in a websocket frame. Uses mg_lock
+ to ensure that the transmission is not interrupted, i.e., when the
+ application is proactively communicating and responding to a request
+ simultaneously.
+
+ Send data to a websocket client wrapped in a websocket frame.
+ This function is available when civetweb is compiled with -DUSE_WEBSOCKET
+
+ Return:
+ 0 when the connection has been closed
+ -1 on error
+ >0 number of bytes written on success */
+CIVETWEB_API int mg_websocket_write(struct mg_connection* conn, int opcode,
+ const char *data, size_t data_len);
+
+
+/* Blocks until unique access is obtained to this connection. Intended for use
+ with websockets only.
+ Invoke this before mg_write or mg_printf when communicating with a
+ websocket if your code has server-initiated communication as well as
+ communication in direct response to a message. */
+CIVETWEB_API void mg_lock_connection(struct mg_connection* conn);
+CIVETWEB_API void mg_unlock_connection(struct mg_connection* conn);
+
+#if defined(MG_LEGACY_INTERFACE)
+#define mg_lock mg_lock_connection
+#define mg_unlock mg_unlock_connection
+#endif
+
+/* Lock server context. This lock may be used to protect ressources
+ that are shared between different connection/worker threads. */
+CIVETWEB_API void mg_lock_context(struct mg_context* ctx);
+CIVETWEB_API void mg_unlock_context(struct mg_context* ctx);
+
+
+/* Opcodes, from http://tools.ietf.org/html/rfc6455 */
+enum {
+ WEBSOCKET_OPCODE_CONTINUATION = 0x0,
+ WEBSOCKET_OPCODE_TEXT = 0x1,
+ WEBSOCKET_OPCODE_BINARY = 0x2,
+ WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
+ WEBSOCKET_OPCODE_PING = 0x9,
+ WEBSOCKET_OPCODE_PONG = 0xa
+};
+
+
+/* Macros for enabling compiler-specific checks forprintf-like arguments. */
+#undef PRINTF_FORMAT_STRING
+#if defined(_MSC_VER) && _MSC_VER >= 1400
+#include <sal.h>
+#if defined(_MSC_VER) && _MSC_VER > 1400
+#define PRINTF_FORMAT_STRING(s) _Printf_format_string_ s
+#else
+#define PRINTF_FORMAT_STRING(s) __format_string s
+#endif
+#else
+#define PRINTF_FORMAT_STRING(s) s
+#endif
+
+#ifdef __GNUC__
+#define PRINTF_ARGS(x, y) __attribute__((format(printf, x, y)))
+#else
+#define PRINTF_ARGS(x, y)
+#endif
+
+/* Send data to the client usingprintf() semantics.
+ Works exactly like mg_write(), but allows to do message formatting. */
+CIVETWEB_API int mg_printf(struct mg_connection *,
+ PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(2, 3);
+
+
+/* Send contents of the entire file together with HTTP headers. */
+CIVETWEB_API void mg_send_file(struct mg_connection *conn, const char *path);
+
+
+/* Read data from the remote end, return number of bytes read.
+ Return:
+ 0 connection has been closed by peer. No more data could be read.
+ < 0 read error. No more data could be read from the connection.
+ > 0 number of bytes read into the buffer. */
+CIVETWEB_API int mg_read(struct mg_connection *, void *buf, size_t len);
+
+
+/* Get the value of particular HTTP header.
+
+ This is a helper function. It traverses request_info->http_headers array,
+ and if the header is present in the array, returns its value. If it is
+ not present, NULL is returned. */
+CIVETWEB_API const char *mg_get_header(const struct mg_connection *, const char *name);
+
+
+/* Get a value of particular form variable.
+
+ Parameters:
+ data: pointer to form-uri-encoded buffer. This could be either POST data,
+ or request_info.query_string.
+ data_len: length of the encoded data.
+ var_name: variable name to decode from the buffer
+ dst: destination buffer for the decoded variable
+ dst_len: length of the destination buffer
+
+ Return:
+ On success, length of the decoded variable.
+ On error:
+ -1 (variable not found).
+ -2 (destination buffer is NULL, zero length or too small to hold the
+ decoded variable).
+
+ Destination buffer is guaranteed to be '\0' - terminated if it is not
+ NULL or zero length. */
+CIVETWEB_API int mg_get_var(const char *data, size_t data_len,
+ const char *var_name, char *dst, size_t dst_len);
+
+
+/* Get a value of particular form variable.
+
+ Parameters:
+ data: pointer to form-uri-encoded buffer. This could be either POST data,
+ or request_info.query_string.
+ data_len: length of the encoded data.
+ var_name: variable name to decode from the buffer
+ dst: destination buffer for the decoded variable
+ dst_len: length of the destination buffer
+ occurrence: which occurrence of the variable, 0 is the first, 1 the
+ second...
+ this makes it possible to parse a query like
+ b=x&a=y&a=z which will have occurrence values b:0, a:0 and a:1
+
+ Return:
+ On success, length of the decoded variable.
+ On error:
+ -1 (variable not found).
+ -2 (destination buffer is NULL, zero length or too small to hold the
+ decoded variable).
+
+ Destination buffer is guaranteed to be '\0' - terminated if it is not
+ NULL or zero length. */
+CIVETWEB_API int mg_get_var2(const char *data, size_t data_len,
+ const char *var_name, char *dst, size_t dst_len, size_t occurrence);
+
+
+/* Fetch value of certain cookie variable into the destination buffer.
+
+ Destination buffer is guaranteed to be '\0' - terminated. In case of
+ failure, dst[0] == '\0'. Note that RFC allows many occurrences of the same
+ parameter. This function returns only first occurrence.
+
+ Return:
+ On success, value length.
+ On error:
+ -1 (either "Cookie:" header is not present at all or the requested
+ parameter is not found).
+ -2 (destination buffer is NULL, zero length or too small to hold the
+ value). */
+CIVETWEB_API int mg_get_cookie(const char *cookie, const char *var_name,
+ char *buf, size_t buf_len);
+
+
+/* Download data from the remote web server.
+ host: host name to connect to, e.g. "foo.com", or "10.12.40.1".
+ port: port number, e.g. 80.
+ use_ssl: wether to use SSL connection.
+ error_buffer, error_buffer_size: error message placeholder.
+ request_fmt,...: HTTP request.
+ Return:
+ On success, valid pointer to the new connection, suitable for mg_read().
+ On error, NULL. error_buffer contains error message.
+ Example:
+ char ebuf[100];
+ struct mg_connection *conn;
+ conn = mg_download("google.com", 80, 0, ebuf, sizeof(ebuf),
+ "%s", "GET / HTTP/1.0\r\nHost: google.com\r\n\r\n");
+ */
+CIVETWEB_API struct mg_connection *mg_download(const char *host, int port, int use_ssl,
+ char *error_buffer, size_t error_buffer_size,
+ PRINTF_FORMAT_STRING(const char *request_fmt),
+ ...) PRINTF_ARGS(6, 7);
+
+
+/* Close the connection opened by mg_download(). */
+CIVETWEB_API void mg_close_connection(struct mg_connection *conn);
+
+
+/* File upload functionality. Each uploaded file gets saved into a temporary
+ file and MG_UPLOAD event is sent.
+ Return number of uploaded files. */
+CIVETWEB_API int mg_upload(struct mg_connection *conn, const char *destination_dir);
+
+
+/* Convenience function -- create detached thread.
+ Return: 0 on success, non-0 on error. */
+typedef void * (*mg_thread_func_t)(void *);
+CIVETWEB_API int mg_start_thread(mg_thread_func_t f, void *p);
+
+
+/* Return builtin mime type for the given file name.
+ For unrecognized extensions, "text/plain" is returned. */
+CIVETWEB_API const char *mg_get_builtin_mime_type(const char *file_name);
+
+
+/* Return Civetweb version. */
+CIVETWEB_API const char *mg_version(void);
+
+
+/* URL-decode input buffer into destination buffer.
+ 0-terminate the destination buffer.
+ form-url-encoded data differs from URI encoding in a way that it
+ uses '+' as character for space, see RFC 1866 section 8.2.1
+ http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
+ Return: length of the decoded data, or -1 if dst buffer is too small. */
+CIVETWEB_API int mg_url_decode(const char *src, int src_len, char *dst,
+ int dst_len, int is_form_url_encoded);
+
+
+/* URL-encode input buffer into destination buffer.
+ returns the length of the resulting buffer or -1
+ is the buffer is too small. */
+CIVETWEB_API int mg_url_encode(const char *src, char *dst, size_t dst_len);
+
+
+/* MD5 hash given strings.
+ Buffer 'buf' must be 33 bytes long. Varargs is a NULL terminated list of
+ ASCIIz strings. When function returns, buf will contain human-readable
+ MD5 hash. Example:
+ char buf[33];
+ mg_md5(buf, "aa", "bb", NULL); */
+CIVETWEB_API char *mg_md5(char buf[33], ...);
+
+
+/* Print error message to the opened error log stream.
+ This utilizes the provided logging configuration.
+ conn: connection
+ fmt: format string without the line return
+ ...: variable argument list
+ Example:
+ mg_cry(conn,"i like %s", "logging"); */
+CIVETWEB_API void mg_cry(struct mg_connection *conn,
+ PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(2, 3);
+
+
+/* utility method to compare two buffers, case incensitive. */
+CIVETWEB_API int mg_strncasecmp(const char *s1, const char *s2, size_t len);
+
+/* Connect to a websocket as a client
+ Parameters:
+ host: host to connect to, i.e. "echo.websocket.org" or "192.168.1.1" or "localhost"
+ port: server port
+ use_ssl: make a secure connection to server
+ error_buffer, error_buffer_size: buffer for an error message
+ path: server path you are trying to connect to, i.e. if connection to localhost/app, path should be "/app"
+ origin: value of the Origin HTTP header
+ data_func: callback that should be used when data is received from the server
+ user_data: user supplied argument
+
+ Return:
+ On success, valid mg_connection object.
+ On error, NULL. Se error_buffer for details.
+*/
+
+typedef int (*websocket_data_func)(struct mg_connection *, int bits,
+ char *data, size_t data_len);
+
+typedef void (*websocket_close_func)(struct mg_connection *);
+
+CIVETWEB_API struct mg_connection *mg_connect_websocket_client(const char *host, int port, int use_ssl,
+ char *error_buffer, size_t error_buffer_size,
+ const char *path, const char *origin,
+ websocket_data_func data_func, websocket_close_func close_func,
+ void * user_data);
+
+/* Connect to a TCP server as a client (can be used to connect to a HTTP server)
+ Parameters:
+ host: host to connect to, i.e. "www.wikipedia.org" or "192.168.1.1" or "localhost"
+ port: server port
+ use_ssl: make a secure connection to server
+ error_buffer, error_buffer_size: buffer for an error message
+
+ Return:
+ On success, valid mg_connection object.
+ On error, NULL. Se error_buffer for details.
+*/
+CIVETWEB_API struct mg_connection *mg_connect_client(const char *host, int port, int use_ssl,
+ char *error_buffer, size_t error_buffer_size);
+
+
+enum {
+ TIMEOUT_INFINITE = -1
+};
+
+/* Wait for a response from the server
+ Parameters:
+ conn: connection
+ ebuf, ebuf_len: error message placeholder.
+ timeout: time to wait for a response in milliseconds (if < 0 then wait forever)
+
+ Return:
+ On success, >= 0
+ On error/timeout, < 0
+*/
+CIVETWEB_API int mg_get_response(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int timeout);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* CIVETWEB_HEADER_INCLUDED */
[31/54] [abbrv] celix git commit: Merge commit
'ee29b00d7a80af43d351e61916d5a5aa90f97e46' into
feature/CELIX-417-cmake-refactor
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/framework/src/celix_launcher.c
----------------------------------------------------------------------
diff --cc framework/src/celix_launcher.c
index ba83f25,0000000..fe5d0c0
mode 100644,000000..100644
--- a/framework/src/celix_launcher.c
+++ b/framework/src/celix_launcher.c
@@@ -1,242 -1,0 +1,315 @@@
+/**
+ *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_launcher.c
+ *
+ * \date Mar 23, 2010
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include "celix_launcher.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <libgen.h>
+#include <signal.h>
+
+#ifndef CELIX_NO_CURLINIT
+#include <curl/curl.h>
+#endif
+
+#include <string.h>
+#include <curl/curl.h>
+#include <signal.h>
+#include <libgen.h>
+#include "celix_launcher.h"
+#include "framework.h"
+#include "linked_list_iterator.h"
+
+static void show_usage(char* prog_name);
+static void shutdown_framework(int signal);
+static void ignore(int signal);
+
++static int celixLauncher_launchWithConfigAndProps(const char *configFile, framework_pt *framework, properties_pt packedConfig);
++static int celixLauncher_launchWithStreamAndProps(FILE *stream, framework_pt *framework, properties_pt packedConfig);
++
+#define DEFAULT_CONFIG_FILE "config.properties"
+
+static framework_pt framework = NULL;
+
++/**
++ * Method kept because of usage in examples & unit tests
++ */
+int celixLauncher_launchWithArgs(int argc, char *argv[]) {
++ return celixLauncher_launchWithArgsAndProps(argc, argv, NULL);
++}
++
++int celixLauncher_launchWithArgsAndProps(int argc, char *argv[], properties_pt packedConfig) {
+ // Perform some minimal command-line option parsing...
+ char *opt = NULL;
+ if (argc > 1) {
+ opt = argv[1];
+ }
+
+ char *config_file = NULL;
+
+ if (opt) {
+ // Check whether the user wants some help...
+ if (strcmp("-h", opt) == 0 || strcmp("-help", opt) == 0) {
+ show_usage(argv[0]);
+ return 0;
+ } else {
+ config_file = opt;
+ }
+ } else {
+ config_file = DEFAULT_CONFIG_FILE;
+ }
+
+ struct sigaction sigact;
+ memset(&sigact, 0, sizeof(sigact));
+ sigact.sa_handler = shutdown_framework;
+ sigaction(SIGINT, &sigact, NULL);
+ sigaction(SIGTERM, &sigact, NULL);
+
+ memset(&sigact, 0, sizeof(sigact));
+ sigact.sa_handler = ignore;
+ sigaction(SIGUSR1, &sigact, NULL);
+ sigaction(SIGUSR2, &sigact, NULL);
+
- int rc = celixLauncher_launch(config_file, &framework);
++ int rc = celixLauncher_launchWithConfigAndProps(config_file, &framework, packedConfig);
+ if (rc == 0) {
+ celixLauncher_waitForShutdown(framework);
+ celixLauncher_destroy(framework);
+ }
+ return rc;
+}
+
+static void show_usage(char* prog_name) {
+ printf("Usage:\n %s [path/to/config.properties]\n\n", basename(prog_name));
+}
+
+static void shutdown_framework(int signal) {
+ if (framework != NULL) {
+ celixLauncher_stop(framework); //NOTE main thread will destroy
+ }
+}
+
+static void ignore(int signal) {
+ //ignoring for signal SIGUSR1, SIGUSR2. Can be used on threads
+}
+
+int celixLauncher_launch(const char *configFile, framework_pt *framework) {
++ return celixLauncher_launchWithConfigAndProps(configFile, framework, NULL);
++}
++
++static int celixLauncher_launchWithConfigAndProps(const char *configFile, framework_pt *framework, properties_pt packedConfig){
+ int status = 0;
+ FILE *config = fopen(configFile, "r");
- if (config != NULL) {
++
++ if (config != NULL && packedConfig != NULL) {
++ status = celixLauncher_launchWithStreamAndProps(config, framework, packedConfig);
++ } else if (config != NULL) {
+ status = celixLauncher_launchWithStream(config, framework);
++ } else if (packedConfig != NULL) {
++ status = celixLauncher_launchWithProperties(packedConfig, framework);
+ } else {
+ fprintf(stderr, "Error: invalid or non-existing configuration file: '%s'.", configFile);
+ perror("");
+ status = 1;
+ }
++
+ return status;
+}
+
+int celixLauncher_launchWithStream(FILE *stream, framework_pt *framework) {
+ int status = 0;
+
+ properties_pt config = properties_loadWithStream(stream);
+ fclose(stream);
+ // Make sure we've read it and that nothing went wrong with the file access...
+ if (config == NULL) {
+ fprintf(stderr, "Error: invalid configuration file");
+ perror(NULL);
+ status = 1;
+ }
+ else {
+ status = celixLauncher_launchWithProperties(config, framework);
+ }
+
+ return status;
+}
+
++static int celixLauncher_launchWithStreamAndProps(FILE *stream, framework_pt *framework, properties_pt packedConfig){
++ int status = 0;
++
++ properties_pt runtimeConfig = properties_loadWithStream(stream);
++ fclose(stream);
++
++ // Make sure we've read it and that nothing went wrong with the file access...
++ // If there is no runtimeConfig, the packedConfig can be stored as global config
++ if (runtimeConfig == NULL){
++ runtimeConfig = packedConfig;
++ }
++
++ if (runtimeConfig == NULL) {
++ fprintf(stderr, "Error: invalid configuration file");
++ perror(NULL);
++ status = 1;
++ } else {
++ // Check if there's a pre-compiled config available
++ if (packedConfig != NULL){
++ // runtimeConfig and packedConfig must be merged
++ // when a duplicate of a key is available, the runtimeConfig must be prioritized
++
++ hash_map_iterator_t iter = hashMapIterator_construct(packedConfig);
++
++ hash_map_entry_pt entry = hashMapIterator_nextEntry(&iter);
++
++ while (entry != NULL) {
++ const char * key = (const char *) hashMapEntry_getKey(entry);
++ const char * value = (const char *) hashMapEntry_getValue(entry);
++
++ // Check existence of key in runtimeConfig
++ if (!hashMap_containsKey(runtimeConfig, key)) {
++ properties_set(runtimeConfig, key, value);
++ }
++
++ entry = hashMapIterator_nextEntry(&iter);
++ if (entry != NULL) {
++ key = (const char *) hashMapEntry_getKey(entry);
++ value = (const char *) hashMapEntry_getValue(entry);
++ }
++ }
++
++ // normally, the framework_destroy will clean up the properties_pt
++ // since there are 2 properties_pt available (runtimeConfig and packedConfig)
++ // the packedConfig must be destroyed
++ properties_destroy(packedConfig);
++ }
++
++ status = celixLauncher_launchWithProperties(runtimeConfig, framework);
++ }
++
++ return status;
++}
+
+int celixLauncher_launchWithProperties(properties_pt config, framework_pt *framework) {
+ celix_status_t status;
+#ifndef CELIX_NO_CURLINIT
+ // Before doing anything else, let's setup Curl
+ curl_global_init(CURL_GLOBAL_NOTHING);
+#endif
+
+ const char* autoStartProp = properties_get(config, "cosgi.auto.start.1");
+ char* autoStart = NULL;
+ if (autoStartProp != NULL) {
+ autoStart = strndup(autoStartProp, 1024*10);
+ }
+
+ status = framework_create(framework, config);
+ bundle_pt fwBundle = NULL;
+ if (status == CELIX_SUCCESS) {
+ status = fw_init(*framework);
+ if (status == CELIX_SUCCESS) {
+ // Start the system bundle
+ status = framework_getFrameworkBundle(*framework, &fwBundle);
+
+ if(status == CELIX_SUCCESS){
+ bundle_start(fwBundle);
+
+ char delims[] = " ";
+ char *result = NULL;
+ char *save_ptr = NULL;
+ linked_list_pt bundles;
+ array_list_pt installed = NULL;
+ bundle_context_pt context = NULL;
+ linked_list_iterator_pt iter = NULL;
+ unsigned int i;
+
+ linkedList_create(&bundles);
+ result = strtok_r(autoStart, delims, &save_ptr);
+ while (result != NULL) {
+ char *location = strdup(result);
+ linkedList_addElement(bundles, location);
+ result = strtok_r(NULL, delims, &save_ptr);
+ }
+ // First install all bundles
+ // Afterwards start them
+ arrayList_create(&installed);
+ bundle_getContext(fwBundle, &context);
+ iter = linkedListIterator_create(bundles, 0);
+ while (linkedListIterator_hasNext(iter)) {
+ bundle_pt current = NULL;
+ char *location = (char *) linkedListIterator_next(iter);
+ if (bundleContext_installBundle(context, location, ¤t) == CELIX_SUCCESS) {
+ // Only add bundle if it is installed correctly
+ arrayList_add(installed, current);
+ } else {
+ printf("Could not install bundle from %s\n", location);
+ }
+ linkedListIterator_remove(iter);
+ free(location);
+ }
+ linkedListIterator_destroy(iter);
+ linkedList_destroy(bundles);
+
+ for (i = 0; i < arrayList_size(installed); i++) {
+ bundle_pt installedBundle = (bundle_pt) arrayList_get(installed, i);
+ bundle_startWithOptions(installedBundle, 0);
+ }
+
+ arrayList_destroy(installed);
+ }
+ }
+ }
+
+ if (status != CELIX_SUCCESS) {
+ printf("Problem creating framework\n");
+ }
+
+ printf("Launcher: Framework Started\n");
+
+ free(autoStart);
+
+ return status;
+}
+
+void celixLauncher_waitForShutdown(framework_pt framework) {
+ framework_waitForStop(framework);
+}
+
+void celixLauncher_destroy(framework_pt framework) {
+ framework_destroy(framework);
+
+#ifndef CELIX_NO_CURLINIT
+ // Cleanup Curl
+ curl_global_cleanup();
+#endif
+
+ printf("Launcher: Exit\n");
+}
+
+void celixLauncher_stop(framework_pt framework) {
+ bundle_pt fwBundle = NULL;
+ if( framework_getFrameworkBundle(framework, &fwBundle) == CELIX_SUCCESS){
+ bundle_stop(fwBundle);
+ }
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/pubsub/pubsub_admin_udp_mc/src/topic_publication.c
----------------------------------------------------------------------
diff --cc pubsub/pubsub_admin_udp_mc/src/topic_publication.c
index e43ec29,0000000..44106df
mode 100644,000000..100644
--- a/pubsub/pubsub_admin_udp_mc/src/topic_publication.c
+++ b/pubsub/pubsub_admin_udp_mc/src/topic_publication.c
@@@ -1,444 -1,0 +1,437 @@@
+/**
+ *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
+ *
- * htPSA_UDP_MC_TP://www.apache.org/licenses/LICENSE-2.0
++ * 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.
+ */
- /*
- * topic_publication.c
- *
- * \date Sep 24, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "array_list.h"
+#include "celixbool.h"
+#include "service_registration.h"
+#include "utils.h"
+#include "service_factory.h"
+#include "version.h"
+
+#include "topic_publication.h"
+#include "pubsub_common.h"
+#include "publisher.h"
+#include "large_udp.h"
+
+#include "pubsub_serializer.h"
+
+#define EP_ADDRESS_LEN 32
+
+#define FIRST_SEND_DELAY 2
+
+struct topic_publication {
+ int sendSocket;
+ char* endpoint;
+ service_registration_pt svcFactoryReg;
+ array_list_pt pub_ep_list; //List<pubsub_endpoint>
+ hash_map_pt boundServices; //<bundle_pt,bound_service>
+ celix_thread_mutex_t tp_lock;
+ pubsub_serializer_service_t *serializer;
+ struct sockaddr_in destAddr;
+};
+
+typedef struct publish_bundle_bound_service {
+ topic_publication_pt parent;
+ pubsub_publisher_t service;
+ bundle_pt bundle;
+ char *scope;
+ char *topic;
+ hash_map_pt msgTypes;
+ unsigned short getCount;
+ celix_thread_mutex_t mp_lock;
+ largeUdp_pt largeUdpHandle;
+}* publish_bundle_bound_service_pt;
+
+
+typedef struct pubsub_msg{
+ pubsub_msg_header_pt header;
+ char* payload;
+ unsigned int payloadSize;
+} pubsub_msg_t;
+
+
+static unsigned int rand_range(unsigned int min, unsigned int max);
+
+static celix_status_t pubsub_topicPublicationGetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service);
+static celix_status_t pubsub_topicPublicationUngetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service);
+
+static publish_bundle_bound_service_pt pubsub_createPublishBundleBoundService(topic_publication_pt tp,bundle_pt bundle);
+static void pubsub_destroyPublishBundleBoundService(publish_bundle_bound_service_pt boundSvc);
+
+static int pubsub_topicPublicationSend(void* handle,unsigned int msgTypeId, const void *msg);
+
+static int pubsub_localMsgTypeIdForUUID(void* handle, const char* msgType, unsigned int* msgTypeId);
+
+
+static void delay_first_send_for_late_joiners(void);
+
+
+celix_status_t pubsub_topicPublicationCreate(int sendSocket, pubsub_endpoint_pt pubEP, pubsub_serializer_service_t *best_serializer, char* bindIP, topic_publication_pt *out){
+
+ char* ep = malloc(EP_ADDRESS_LEN);
+ memset(ep,0,EP_ADDRESS_LEN);
+ unsigned int port = pubEP->serviceID + rand_range(UDP_BASE_PORT+pubEP->serviceID+3, UDP_MAX_PORT);
+ snprintf(ep,EP_ADDRESS_LEN,"udp://%s:%u",bindIP,port);
+
+
+ topic_publication_pt pub = calloc(1,sizeof(*pub));
+
+ arrayList_create(&(pub->pub_ep_list));
+ pub->boundServices = hashMap_create(NULL,NULL,NULL,NULL);
+ celixThreadMutex_create(&(pub->tp_lock),NULL);
+
+ pub->endpoint = ep;
+ pub->sendSocket = sendSocket;
+ pub->destAddr.sin_family = AF_INET;
+ pub->destAddr.sin_addr.s_addr = inet_addr(bindIP);
+ pub->destAddr.sin_port = htons(port);
+
+ pub->serializer = best_serializer;
+
+ pubsub_topicPublicationAddPublisherEP(pub,pubEP);
+
+ *out = pub;
+
+ return CELIX_SUCCESS;
+}
+
+celix_status_t pubsub_topicPublicationDestroy(topic_publication_pt pub){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&(pub->tp_lock));
+
+ free(pub->endpoint);
+ arrayList_destroy(pub->pub_ep_list);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(pub->boundServices);
+ while(hashMapIterator_hasNext(iter)){
+ publish_bundle_bound_service_pt bound = hashMapIterator_nextValue(iter);
+ pubsub_destroyPublishBundleBoundService(bound);
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(pub->boundServices,false,false);
+
+ pub->svcFactoryReg = NULL;
+ pub->serializer = NULL;
+
+ if(close(pub->sendSocket) != 0){
+ status = CELIX_FILE_IO_EXCEPTION;
+ }
+
+ celixThreadMutex_unlock(&(pub->tp_lock));
+
+ celixThreadMutex_destroy(&(pub->tp_lock));
+
+ free(pub);
+
+ return status;
+}
+
+celix_status_t pubsub_topicPublicationStart(bundle_context_pt bundle_context,topic_publication_pt pub,service_factory_pt* svcFactory){
+ celix_status_t status = CELIX_SUCCESS;
+
+ /* Let's register the new service */
+
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pub->pub_ep_list,0);
+
+ if(pubEP!=NULL){
+ service_factory_pt factory = calloc(1, sizeof(*factory));
+ factory->handle = pub;
+ factory->getService = pubsub_topicPublicationGetService;
+ factory->ungetService = pubsub_topicPublicationUngetService;
+
+ properties_pt props = properties_create();
+ properties_set(props,PUBSUB_PUBLISHER_SCOPE,pubEP->scope);
+ properties_set(props,PUBSUB_PUBLISHER_TOPIC,pubEP->topic);
+
+ status = bundleContext_registerServiceFactory(bundle_context,PUBSUB_PUBLISHER_SERVICE_NAME,factory,props,&(pub->svcFactoryReg));
+
+ if(status != CELIX_SUCCESS){
+ properties_destroy(props);
+ printf("PSA_UDP_MC_PSA_UDP_MC_TP: Cannot register ServiceFactory for topic %s, topic %s (bundle %ld).\n",pubEP->scope, pubEP->topic,pubEP->serviceID);
+ }
+ else{
+ *svcFactory = factory;
+ }
+ }
+ else{
+ printf("PSA_UDP_MC_PSA_UDP_MC_TP: Cannot find pubsub_endpoint after adding it...Should never happen!\n");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+
+ return status;
+}
+
+celix_status_t pubsub_topicPublicationStop(topic_publication_pt pub){
+ return serviceRegistration_unregister(pub->svcFactoryReg);
+}
+
+celix_status_t pubsub_topicPublicationAddPublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep){
+
+ celixThreadMutex_lock(&(pub->tp_lock));
+ ep->endpoint = strdup(pub->endpoint);
+ arrayList_add(pub->pub_ep_list,ep);
+ celixThreadMutex_unlock(&(pub->tp_lock));
+
+ return CELIX_SUCCESS;
+}
+
+celix_status_t pubsub_topicPublicationRemovePublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep){
+
+ celixThreadMutex_lock(&(pub->tp_lock));
+ arrayList_removeElement(pub->pub_ep_list,ep);
+ celixThreadMutex_unlock(&(pub->tp_lock));
+
+ return CELIX_SUCCESS;
+}
+
+array_list_pt pubsub_topicPublicationGetPublisherList(topic_publication_pt pub){
+ array_list_pt list = NULL;
+ celixThreadMutex_lock(&(pub->tp_lock));
+ list = arrayList_clone(pub->pub_ep_list);
+ celixThreadMutex_unlock(&(pub->tp_lock));
+ return list;
+}
+
+
+static celix_status_t pubsub_topicPublicationGetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ topic_publication_pt publish = (topic_publication_pt)handle;
+
+ celixThreadMutex_lock(&(publish->tp_lock));
+
+ publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt)hashMap_get(publish->boundServices,bundle);
+ if(bound==NULL){
+ bound = pubsub_createPublishBundleBoundService(publish,bundle);
+ if(bound!=NULL){
+ hashMap_put(publish->boundServices,bundle,bound);
+ }
+ }
+ else{
+ bound->getCount++;
+ }
+
+ if (bound != NULL) {
+ *service = &bound->service;
+ }
+
+ celixThreadMutex_unlock(&(publish->tp_lock));
+
+ return status;
+}
+
+static celix_status_t pubsub_topicPublicationUngetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service) {
+
+ topic_publication_pt publish = (topic_publication_pt)handle;
+
+ celixThreadMutex_lock(&(publish->tp_lock));
+
+ publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt)hashMap_get(publish->boundServices,bundle);
+ if(bound!=NULL){
+
+ bound->getCount--;
+ if(bound->getCount==0){
+ pubsub_destroyPublishBundleBoundService(bound);
+ hashMap_remove(publish->boundServices,bundle);
+ }
+
+ }
+ else{
+ long bundleId = -1;
+ bundle_getBundleId(bundle,&bundleId);
+ printf("PSA_UDP_MC_TP: Unexpected ungetService call for bundle %ld.\n", bundleId);
+ }
+
+ /* service should be never used for unget, so let's set the pointer to NULL */
+ *service = NULL;
+
+ celixThreadMutex_unlock(&(publish->tp_lock));
+
+ return CELIX_SUCCESS;
+}
+
+static bool send_pubsub_msg(publish_bundle_bound_service_pt bound, pubsub_msg_t* msg, bool last, pubsub_release_callback_t *releaseCallback){
+ const int iovec_len = 3; // header + size + payload
+ bool ret = true;
+
+ struct iovec msg_iovec[iovec_len];
+ msg_iovec[0].iov_base = msg->header;
+ msg_iovec[0].iov_len = sizeof(*msg->header);
+ msg_iovec[1].iov_base = &msg->payloadSize;
+ msg_iovec[1].iov_len = sizeof(msg->payloadSize);
+ msg_iovec[2].iov_base = msg->payload;
+ msg_iovec[2].iov_len = msg->payloadSize;
+
+ delay_first_send_for_late_joiners();
+
+ if(largeUdp_sendmsg(bound->largeUdpHandle, bound->parent->sendSocket, msg_iovec, iovec_len, 0, &bound->parent->destAddr, sizeof(bound->parent->destAddr)) == -1) {
+ perror("send_pubsub_msg:sendSocket");
+ ret = false;
+ }
+
+ if(releaseCallback) {
+ releaseCallback->release(msg->payload, bound);
+ }
+ return ret;
+
+}
+
+
+static int pubsub_topicPublicationSend(void* handle, unsigned int msgTypeId, const void *inMsg) {
+ int status = 0;
+ publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt) handle;
+
+ celixThreadMutex_lock(&(bound->parent->tp_lock));
+ celixThreadMutex_lock(&(bound->mp_lock));
+
- pubsub_msg_serializer_t* msgSer = (pubsub_msg_serializer_t*)hashMap_get(bound->msgTypes, (void*)(uintptr_t)msgTypeId);
++ pubsub_msg_serializer_t* msgSer = (pubsub_msg_serializer_t*)hashMap_get(bound->msgTypes, (void*)(intptr_t)msgTypeId);
+
+ if (msgSer != NULL) {
+ int major=0, minor=0;
+
+ pubsub_msg_header_pt msg_hdr = calloc(1,sizeof(struct pubsub_msg_header));
+ strncpy(msg_hdr->topic,bound->topic,MAX_TOPIC_LEN-1);
+ msg_hdr->type = msgTypeId;
+
+
+ if (msgSer->msgVersion != NULL){
+ version_getMajor(msgSer->msgVersion, &major);
+ version_getMinor(msgSer->msgVersion, &minor);
+ msg_hdr->major = major;
+ msg_hdr->minor = minor;
+ }
+
+ void* serializedOutput = NULL;
+ size_t serializedOutputLen = 0;
+ msgSer->serialize(msgSer,inMsg,&serializedOutput, &serializedOutputLen);
+
+ pubsub_msg_t *msg = calloc(1,sizeof(pubsub_msg_t));
+ msg->header = msg_hdr;
+ msg->payload = (char*)serializedOutput;
+ msg->payloadSize = serializedOutputLen;
+
+
+ if(send_pubsub_msg(bound, msg,true, NULL) == false) {
+ status = -1;
+ }
+ free(msg_hdr);
+ free(msg);
+ free(serializedOutput);
+
+
+ } else {
+ printf("PSA_UDP_MC_TP: No msg serializer available for msg type id %d\n", msgTypeId);
+ status=-1;
+ }
+
+ celixThreadMutex_unlock(&(bound->mp_lock));
+ celixThreadMutex_unlock(&(bound->parent->tp_lock));
+
+ return status;
+}
+
+static int pubsub_localMsgTypeIdForUUID(void* handle, const char* msgType, unsigned int* msgTypeId){
+ *msgTypeId = utils_stringHash(msgType);
+ return 0;
+}
+
+
+static unsigned int rand_range(unsigned int min, unsigned int max){
+
+ double scaled = (double)(((double)random())/((double)RAND_MAX));
+ return (max-min+1)*scaled + min;
+
+}
+
+static publish_bundle_bound_service_pt pubsub_createPublishBundleBoundService(topic_publication_pt tp,bundle_pt bundle){
+
+ publish_bundle_bound_service_pt bound = calloc(1, sizeof(*bound));
+
+ if (bound != NULL) {
+
+ bound->parent = tp;
+ bound->bundle = bundle;
+ bound->getCount = 1;
+ celixThreadMutex_create(&bound->mp_lock,NULL);
+
+ if(tp->serializer != NULL){
+ tp->serializer->createSerializerMap(tp->serializer->handle,bundle,&bound->msgTypes);
+ }
+
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(bound->parent->pub_ep_list,0);
+ bound->scope=strdup(pubEP->scope);
+ bound->topic=strdup(pubEP->topic);
+ bound->largeUdpHandle = largeUdp_create(1);
+
+ bound->service.handle = bound;
+ bound->service.localMsgTypeIdForMsgType = pubsub_localMsgTypeIdForUUID;
+ bound->service.send = pubsub_topicPublicationSend;
+ bound->service.sendMultipart = NULL; //Multipart not supported for UDP
+
+ }
+
+ return bound;
+}
+
+static void pubsub_destroyPublishBundleBoundService(publish_bundle_bound_service_pt boundSvc){
+
+ celixThreadMutex_lock(&boundSvc->mp_lock);
+
+ if(boundSvc->parent->serializer != NULL && boundSvc->msgTypes != NULL){
+ boundSvc->parent->serializer->destroySerializerMap(boundSvc->parent->serializer->handle, boundSvc->msgTypes);
+ }
+
+ if(boundSvc->scope!=NULL){
+ free(boundSvc->scope);
+ }
+
+ if(boundSvc->topic!=NULL){
+ free(boundSvc->topic);
+ }
+
+ largeUdp_destroy(boundSvc->largeUdpHandle);
+
+ celixThreadMutex_unlock(&boundSvc->mp_lock);
+ celixThreadMutex_destroy(&boundSvc->mp_lock);
+
+ free(boundSvc);
+
+}
+
+static void delay_first_send_for_late_joiners(){
+
+ static bool firstSend = true;
+
+ if(firstSend){
+ printf("PSA_UDP_MC_TP: Delaying first send for late joiners...\n");
+ sleep(FIRST_SEND_DELAY);
+ firstSend = false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/shell/CMakeLists.txt
----------------------------------------------------------------------
diff --cc shell/CMakeLists.txt
index ae8cf3f,11a16c1..b8aaac3
--- a/shell/CMakeLists.txt
+++ b/shell/CMakeLists.txt
@@@ -18,35 -18,38 +18,35 @@@ celix_subproject(SHELL "Option to enabl
if (SHELL)
find_package(CURL REQUIRED)
+ add_library(shell_api INTERFACE)
+ target_include_directories(shell_api INTERFACE include)
+
add_bundle(shell
SYMBOLIC_NAME "apache_celix_shell"
- VERSION "2.0.0"
+ VERSION "2.1.0"
NAME "Apache Celix Shell"
-
SOURCES
+ src/activator
+ src/shell
+ src/lb_command
+ src/start_command
+ src/stop_command
+ src/install_command
+ src/update_command
+ src/uninstall_command
+ src/log_command
+ src/inspect_command
+ src/help_command
+ )
+ target_include_directories(shell PRIVATE src ${CURL_INCLUDE_DIRS})
+ target_link_libraries(shell PRIVATE Celix::shell_api ${CURL_LIBRARIES} Celix::log_service_api Celix::log_helper)
- private/src/activator
- private/src/shell
- private/src/lb_command
- private/src/start_command
- private/src/stop_command
- private/src/install_command
- private/src/update_command
- private/src/uninstall_command
- private/src/log_command
- private/src/inspect_command
- private/src/help_command
-
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
-
- )
-
- install_bundle(shell
+ install_bundle(shell
HEADERS
- public/include/shell.h public/include/command.h public/include/shell_constants.h
- )
+ include/shell.h include/command.h include/shell_constants.h
+ )
- include_directories("public/include")
- include_directories("private/include")
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
- include_directories(${CURL_INCLUDE_DIRS})
- target_link_libraries(shell celix_framework ${CURL_LIBRARIES})
+ #Setup target aliases to match external usage
+ add_library(Celix::shell_api ALIAS shell_api)
+ add_library(Celix::shell ALIAS shell)
endif (SHELL)
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/utils/include/properties.h
----------------------------------------------------------------------
diff --cc utils/include/properties.h
index cf93ca0,0000000..5c6dc4d
mode 100644,000000..100644
--- a/utils/include/properties.h
+++ b/utils/include/properties.h
@@@ -1,66 -1,0 +1,68 @@@
+/**
+ *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 properties_pt properties_loadFromString(const char *input);
++
+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/ac0d0d77/utils/src/properties.c
----------------------------------------------------------------------
diff --cc utils/src/properties.c
index 0bd6dc3,0000000..1e097a0
mode 100644,000000..100644
--- a/utils/src/properties.c
+++ b/utils/src/properties.c
@@@ -1,302 -1,0 +1,330 @@@
+/**
+ *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.c
+ *
+ * \date Apr 27, 2010
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include "celixbool.h"
+#include "properties.h"
+#include "utils.h"
+
+#define MALLOC_BLOCK_SIZE 5
+
+static void parseLine(const char* line, properties_pt props);
+
+properties_pt properties_create(void) {
+ return hashMap_create(utils_stringHash, utils_stringHash, utils_stringEquals, utils_stringEquals);
+}
+
+void properties_destroy(properties_pt properties) {
+ hash_map_iterator_pt iter = hashMapIterator_create(properties);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ free(hashMapEntry_getKey(entry));
+ free(hashMapEntry_getValue(entry));
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(properties, false, false);
+}
+
+properties_pt properties_load(const char* filename) {
+ FILE *file = fopen(filename, "r");
+ if(file==NULL){
+ return NULL;
+ }
+ properties_pt props = properties_loadWithStream(file);
+ fclose(file);
+ return props;
+}
+
+properties_pt properties_loadWithStream(FILE *file) {
+ properties_pt props = NULL;
+
+
+ if (file != NULL ) {
+ char *saveptr;
+ char *filebuffer = NULL;
+ char *line = NULL;
+ size_t file_size = 0;
+
+ props = properties_create();
+ fseek(file, 0, SEEK_END);
+ file_size = ftell(file);
+ fseek(file, 0, SEEK_SET);
+
+ if(file_size > 0){
+ filebuffer = calloc(file_size + 1, sizeof(char));
+ if(filebuffer) {
+ size_t rs = fread(filebuffer, sizeof(char), file_size, file);
+ if(rs != file_size){
+ fprintf(stderr,"fread read only %lu bytes out of %lu\n",rs,file_size);
+ }
+ filebuffer[file_size]='\0';
+ line = strtok_r(filebuffer, "\n", &saveptr);
+ while ( line != NULL ) {
+ parseLine(line, props);
+ line = strtok_r(NULL, "\n", &saveptr);
+ }
+ free(filebuffer);
+ }
+ }
+ }
+
+ return props;
+}
+
++properties_pt properties_loadFromString(const char *input){
++ properties_pt props = properties_create();
++
++ char *in = strdup(input);
++ char *line = NULL;
++ char *saveLinePointer = NULL;
++
++ bool firstTime = true;
++ do {
++ if (firstTime){
++ line = strtok_r(in, "\n", &saveLinePointer);
++ firstTime = false;
++ }else {
++ line = strtok_r(NULL, "\n", &saveLinePointer);
++ }
++
++ if (line == NULL){
++ break;
++ }
++
++ parseLine(line, props);
++ } while(line != NULL);
++
++ free(in);
++
++ return props;
++}
++
+
+/**
+ * Header is ignored for now, cannot handle comments yet
+ */
+void properties_store(properties_pt properties, const char* filename, const char* header) {
+ FILE *file = fopen ( filename, "w+" );
+ char *str;
+
+ if (file != NULL) {
+ if (hashMap_size(properties) > 0) {
+ hash_map_iterator_pt iterator = hashMapIterator_create(properties);
+ while (hashMapIterator_hasNext(iterator)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);
+ str = hashMapEntry_getKey(entry);
+ for (int i = 0; i < strlen(str); i += 1) {
+ if (str[i] == '#' || str[i] == '!' || str[i] == '=' || str[i] == ':') {
+ fputc('\\', file);
+ }
+ fputc(str[i], file);
+ }
+
+ fputc('=', file);
+
+ str = hashMapEntry_getValue(entry);
+ for (int i = 0; i < strlen(str); i += 1) {
+ if (str[i] == '#' || str[i] == '!' || str[i] == '=' || str[i] == ':') {
+ fputc('\\', file);
+ }
+ fputc(str[i], file);
+ }
+
+ fputc('\n', file);
+
+ }
+ hashMapIterator_destroy(iterator);
+ }
+ fclose(file);
+ } else {
+ perror("File is null");
+ }
+}
+
+celix_status_t properties_copy(properties_pt properties, properties_pt *out) {
+ celix_status_t status = CELIX_SUCCESS;
+ properties_pt copy = properties_create();
+
+ if (copy != NULL) {
+ hash_map_iterator_pt iter = hashMapIterator_create(properties);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ char *key = hashMapEntry_getKey(entry);
+ char *value = hashMapEntry_getValue(entry);
+ properties_set(copy, key, value);
+ }
+ hashMapIterator_destroy(iter);
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *out = copy;
+ }
+
+ return status;
+}
+
+const char* properties_get(properties_pt properties, const char* key) {
+ return hashMap_get(properties, (void*)key);
+}
+
+const char* properties_getWithDefault(properties_pt properties, const char* key, const char* defaultValue) {
+ const char* value = properties_get(properties, key);
+ return value == NULL ? defaultValue : value;
+}
+
+void properties_set(properties_pt properties, const char* key, const char* value) {
+ hash_map_entry_pt entry = hashMap_getEntry(properties, key);
+ char* oldValue = NULL;
+ if (entry != NULL) {
+ char* oldKey = hashMapEntry_getKey(entry);
+ oldValue = hashMapEntry_getValue(entry);
+ hashMap_put(properties, oldKey, strndup(value, 1024*10));
+ } else {
+ hashMap_put(properties, strndup(key, 1024*10), strndup(value, 1024*10));
+ }
+ free(oldValue);
+}
+
+static void updateBuffers(char **key, char ** value, char **output, int outputPos, int *key_len, int *value_len) {
+ if (*output == *key) {
+ if (outputPos == (*key_len) - 1) {
+ (*key_len) += MALLOC_BLOCK_SIZE;
+ *key = realloc(*key, *key_len);
+ *output = *key;
+ }
+ }
+ else {
+ if (outputPos == (*value_len) - 1) {
+ (*value_len) += MALLOC_BLOCK_SIZE;
+ *value = realloc(*value, *value_len);
+ *output = *value;
+ }
+ }
+}
+
+static void parseLine(const char* line, properties_pt props) {
+ int linePos = 0;
+ bool precedingCharIsBackslash = false;
+ bool isComment = false;
+ int outputPos = 0;
+ char *output = NULL;
+ int key_len = MALLOC_BLOCK_SIZE;
+ int value_len = MALLOC_BLOCK_SIZE;
+ linePos = 0;
+ precedingCharIsBackslash = false;
+ isComment = false;
+ output = NULL;
+ outputPos = 0;
+
+ //Ignore empty lines
+ if (line[0] == '\n' && line[1] == '\0') {
+ return;
+ }
+
+ char *key = calloc(1, key_len);
+ char *value = calloc(1, value_len);
+ key[0] = '\0';
+ value[0] = '\0';
+
+ while (line[linePos] != '\0') {
+ if (line[linePos] == ' ' || line[linePos] == '\t') {
+ if (output == NULL) {
+ //ignore
+ linePos += 1;
+ continue;
+ }
+ }
+ else {
+ if (output == NULL) {
+ output = key;
+ }
+ }
+ if (line[linePos] == '=' || line[linePos] == ':' || line[linePos] == '#' || line[linePos] == '!') {
+ if (precedingCharIsBackslash) {
+ //escaped special character
+ output[outputPos++] = line[linePos];
+ updateBuffers(&key, &value, &output, outputPos, &key_len, &value_len);
+ precedingCharIsBackslash = false;
+ }
+ else {
+ if (line[linePos] == '#' || line[linePos] == '!') {
+ if (outputPos == 0) {
+ isComment = true;
+ break;
+ }
+ else {
+ output[outputPos++] = line[linePos];
+ updateBuffers(&key, &value, &output, outputPos, &key_len, &value_len);
+ }
+ }
+ else { // = or :
+ if (output == value) { //already have a seperator
+ output[outputPos++] = line[linePos];
+ updateBuffers(&key, &value, &output, outputPos, &key_len, &value_len);
+ }
+ else {
+ output[outputPos++] = '\0';
+ updateBuffers(&key, &value, &output, outputPos, &key_len, &value_len);
+ output = value;
+ outputPos = 0;
+ }
+ }
+ }
+ }
+ else if (line[linePos] == '\\') {
+ if (precedingCharIsBackslash) { //double backslash -> backslash
+ output[outputPos++] = '\\';
+ updateBuffers(&key, &value, &output, outputPos, &key_len, &value_len);
+ }
+ precedingCharIsBackslash = true;
+ }
+ else { //normal character
+ precedingCharIsBackslash = false;
+ output[outputPos++] = line[linePos];
+ updateBuffers(&key, &value, &output, outputPos, &key_len, &value_len);
+ }
+ linePos += 1;
+ }
+ if (output != NULL) {
+ output[outputPos] = '\0';
+ }
+
+ if (!isComment) {
+ //printf("putting 'key'/'value' '%s'/'%s' in properties\n", utils_stringTrim(key), utils_stringTrim(value));
+ properties_set(props, utils_stringTrim(key), utils_stringTrim(value));
+ }
+ if(key) {
+ free(key);
+ }
+ if(value) {
+ free(value);
+ }
+
+}
[37/54] [abbrv] celix git commit: CELIX-417: Refactors cmake usage of
pubsub and rsa. Started with installing exported targets
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_discovery/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/CMakeLists.txt b/pubsub/pubsub_discovery/CMakeLists.txt
index 0e7d6c5..f92f81c 100644
--- a/pubsub/pubsub_discovery/CMakeLists.txt
+++ b/pubsub/pubsub_discovery/CMakeLists.txt
@@ -18,7 +18,7 @@
find_package(CURL REQUIRED)
find_package(Jansson REQUIRED)
-add_bundle(org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
+add_bundle(celix_pubsub_discovery_etcd
BUNDLE_SYMBOLICNAME "apache_celix_pubsub_discovery_etcd"
VERSION "1.0.0"
SOURCES
@@ -27,16 +27,15 @@ add_bundle(org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
src/etcd_common.c
src/etcd_watcher.c
src/etcd_writer.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_endpoint.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
)
-target_include_directories(org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery PRIVATE
+target_include_directories(celix_pubsub_discovery_etcd PRIVATE
src
- include
${CURL_INCLUDE_DIR}
${JANSSON_INCLUDE_DIR}
- )
+)
+
+target_link_libraries(celix_pubsub_discovery_etcd PRIVATE Celix::pubsub_spi Celix::framework Celix::etcdlib_static ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
+install_bundle(celix_pubsub_discovery_etcd)
-target_link_libraries(org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery PRIVATE Celix::framework Celix::etcdlib_static ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
-install_bundle(org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery)
+add_library(Celix::pubsub_discovery_etcd ALIAS celix_pubsub_discovery_etcd)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_serializer_json/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_serializer_json/CMakeLists.txt b/pubsub/pubsub_serializer_json/CMakeLists.txt
index b86f30e..1269cad 100644
--- a/pubsub/pubsub_serializer_json/CMakeLists.txt
+++ b/pubsub/pubsub_serializer_json/CMakeLists.txt
@@ -18,22 +18,23 @@
find_package(Jansson REQUIRED)
-add_bundle(org.apache.celix.pubsub_serializer.PubSubSerializerJson
+add_bundle(celix_pubsub_serializer_json
BUNDLE_SYMBOLICNAME "apache_celix_pubsub_serializer_json"
VERSION "1.0.0"
SOURCES
src/ps_activator.c
src/pubsub_serializer_impl.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
)
-target_include_directories(org.apache.celix.pubsub_serializer.PubSubSerializerJson PRIVATE
+target_include_directories(celix_pubsub_serializer_json PRIVATE
src
${JANSSON_INCLUDE_DIR}
)
-set_target_properties(org.apache.celix.pubsub_serializer.PubSubSerializerJson PROPERTIES INSTALL_RPATH "$ORIGIN")
-target_link_libraries(org.apache.celix.pubsub_serializer.PubSubSerializerJson PRIVATE Celix::framework Celix::dfi ${JANSSON_LIBRARIES} Celix::log_helper)
+set_target_properties(celix_pubsub_serializer_json PROPERTIES INSTALL_RPATH "$ORIGIN")
+target_link_libraries(celix_pubsub_serializer_json PRIVATE Celix::pubsub_spi Celix::framework Celix::dfi ${JANSSON_LIBRARIES} Celix::log_helper)
-install_bundle(org.apache.celix.pubsub_serializer.PubSubSerializerJson)
+install_bundle(celix_pubsub_serializer_json)
+
+add_library(Celix::pubsub_serializer_json ALIAS celix_pubsub_serializer_json)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_spi/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/CMakeLists.txt b/pubsub/pubsub_spi/CMakeLists.txt
new file mode 100644
index 0000000..118dd3a
--- /dev/null
+++ b/pubsub/pubsub_spi/CMakeLists.txt
@@ -0,0 +1,35 @@
+# 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.
+
+add_library(celix_pubsub_spi STATIC
+ src/pubsub_admin_match.c
+ src/pubsub_endpoint.c
+ src/pubsub_utils.c
+)
+target_include_directories(celix_pubsub_spi PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
+ $<INSTALL_INTERFACE:include/celix/pubsub_spi>
+)
+target_link_libraries(celix_pubsub_spi PUBLIC Celix::framework Celix::pubsub_api)
+
+set_target_properties(celix_pubsub_spi PROPERTIES TOPIC_INFO_DESCRIPTOR ${CMAKE_CURRENT_LIST_DIR}/include/pubsub_topic_info.descriptor)
+#TODO how to make this descriptor available for imported targets? $<INSTALL_INTERFACE:include/celix/pubsub_spi/pubsub_topic_info.descriptor>
+
+add_library(Celix::pubsub_spi ALIAS celix_pubsub_spi)
+
+install(TARGETS celix_pubsub_spi EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT pubsub)
+install(DIRECTORY include/ DESTINATION include/celix/pubsub_spi COMPONENT pubsub)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_spi/include/publisher_endpoint_announce.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/include/publisher_endpoint_announce.h b/pubsub/pubsub_spi/include/publisher_endpoint_announce.h
new file mode 100644
index 0000000..bd39fc0
--- /dev/null
+++ b/pubsub/pubsub_spi/include/publisher_endpoint_announce.h
@@ -0,0 +1,36 @@
+/**
+ *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.
+ */
+
+#ifndef PUBLISHER_ENDPOINT_ANNOUNCE_H_
+#define PUBLISHER_ENDPOINT_ANNOUNCE_H_
+
+#include "pubsub_endpoint.h"
+
+struct publisher_endpoint_announce {
+ void *handle;
+ celix_status_t (*announcePublisher)(void *handle, pubsub_endpoint_pt pubEP);
+ celix_status_t (*removePublisher)(void *handle, pubsub_endpoint_pt pubEP);
+ celix_status_t (*interestedInTopic)(void* handle, const char *scope, const char *topic);
+ celix_status_t (*uninterestedInTopic)(void* handle, const char *scope, const char *topic);
+};
+
+typedef struct publisher_endpoint_announce *publisher_endpoint_announce_pt;
+
+
+#endif /* PUBLISHER_ENDPOINT_ANNOUNCE_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_spi/include/pubsub_admin.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/include/pubsub_admin.h b/pubsub/pubsub_spi/include/pubsub_admin.h
new file mode 100644
index 0000000..f24d825
--- /dev/null
+++ b/pubsub/pubsub_spi/include/pubsub_admin.h
@@ -0,0 +1,72 @@
+/**
+ *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.
+ */
+/*
+ * pubsub_admin.h
+ *
+ * \date Sep 30, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PUBSUB_ADMIN_H_
+#define PUBSUB_ADMIN_H_
+
+#include "service_reference.h"
+
+#include "pubsub_common.h"
+#include "pubsub_endpoint.h"
+
+#define PSA_IP "PSA_IP"
+#define PSA_ITF "PSA_INTERFACE"
+#define PSA_MULTICAST_IP_PREFIX "PSA_MC_PREFIX"
+
+#define PUBSUB_ADMIN_TYPE_KEY "pubsub_admin.type"
+
+typedef struct pubsub_admin *pubsub_admin_pt;
+
+struct pubsub_admin_service {
+ pubsub_admin_pt admin;
+
+ celix_status_t (*addSubscription)(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
+ celix_status_t (*removeSubscription)(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
+
+ celix_status_t (*addPublication)(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
+ celix_status_t (*removePublication)(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
+
+ celix_status_t (*closeAllPublications)(pubsub_admin_pt admin,char* scope, char* topic);
+ celix_status_t (*closeAllSubscriptions)(pubsub_admin_pt admin,char* scope, char* topic);
+
+ /* Match principle:
+ * - A full matching pubsub_admin gives 200 points
+ * - A full matching serializer gives 100 points
+ * - If QoS = sample
+ * - fallback pubsub_admin order of selection is: udp_mc, zmq. Points allocation is 100,75.
+ * - fallback serializers order of selection is: json, void. Points allocation is 30,20.
+ * - If QoS = control
+ * - fallback pubsub_admin order of selection is: zmq,udp_mc. Points allocation is 100,75.
+ * - fallback serializers order of selection is: json, void. Points allocation is 30,20.
+ * - If nothing is specified, QoS = sample is assumed, so the same score applies, just divided by two.
+ *
+ */
+ celix_status_t (*matchEndpoint)(pubsub_admin_pt admin, pubsub_endpoint_pt endpoint, double* score);
+};
+
+typedef struct pubsub_admin_service *pubsub_admin_service_pt;
+
+#endif /* PUBSUB_ADMIN_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_spi/include/pubsub_admin_match.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/include/pubsub_admin_match.h b/pubsub/pubsub_spi/include/pubsub_admin_match.h
new file mode 100644
index 0000000..e95ca7d
--- /dev/null
+++ b/pubsub/pubsub_spi/include/pubsub_admin_match.h
@@ -0,0 +1,40 @@
+/**
+ *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.
+ */
+
+
+#ifndef PUBSUB_ADMIN_MATCH_H_
+#define PUBSUB_ADMIN_MATCH_H_
+
+#include "celix_errno.h"
+#include "properties.h"
+#include "array_list.h"
+
+#include "pubsub_serializer.h"
+
+#define QOS_ATTRIBUTE_KEY "attribute.qos"
+#define QOS_TYPE_SAMPLE "sample" /* A.k.a. unreliable connection */
+#define QOS_TYPE_CONTROL "control" /* A.k.a. reliable connection */
+
+#define PUBSUB_ADMIN_FULL_MATCH_SCORE 200.0F
+#define SERIALIZER_FULL_MATCH_SCORE 100.0F
+
+celix_status_t pubsub_admin_match(properties_pt endpoint_props, const char *pubsub_admin_type, array_list_pt serializerList, double *score);
+celix_status_t pubsub_admin_get_best_serializer(properties_pt endpoint_props, array_list_pt serializerList, pubsub_serializer_service_t **serSvc);
+
+#endif /* PUBSUB_ADMIN_MATCH_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_spi/include/pubsub_common.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/include/pubsub_common.h b/pubsub/pubsub_spi/include/pubsub_common.h
new file mode 100644
index 0000000..5dfd8fd
--- /dev/null
+++ b/pubsub/pubsub_spi/include/pubsub_common.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.
+ */
+/*
+ * pubsub_common.h
+ *
+ * \date Sep 17, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PUBSUB_COMMON_H_
+#define PUBSUB_COMMON_H_
+
+#define PUBSUB_SERIALIZER_SERVICE "pubsub_serializer"
+#define PUBSUB_ADMIN_SERVICE "pubsub_admin"
+#define PUBSUB_DISCOVERY_SERVICE "pubsub_discovery"
+#define PUBSUB_TM_ANNOUNCE_PUBLISHER_SERVICE "pubsub_tm_announce_publisher"
+
+#define PUBSUB_ANY_SUB_TOPIC "any"
+
+#define PUBSUB_BUNDLE_ID "bundle.id"
+
+#define MAX_SCOPE_LEN 1024
+#define MAX_TOPIC_LEN 1024
+
+struct pubsub_msg_header{
+ char topic[MAX_TOPIC_LEN];
+ unsigned int type;
+ unsigned char major;
+ unsigned char minor;
+};
+
+typedef struct pubsub_msg_header* pubsub_msg_header_pt;
+
+
+#endif /* PUBSUB_COMMON_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_spi/include/pubsub_endpoint.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/include/pubsub_endpoint.h b/pubsub/pubsub_spi/include/pubsub_endpoint.h
new file mode 100644
index 0000000..4c39d2f
--- /dev/null
+++ b/pubsub/pubsub_spi/include/pubsub_endpoint.h
@@ -0,0 +1,58 @@
+/**
+ *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.
+ */
+/*
+ * pubsub_endpoint.h
+ *
+ * \date Sep 21, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PUBSUB_ENDPOINT_H_
+#define PUBSUB_ENDPOINT_H_
+
+#include "service_reference.h"
+#include "listener_hook_service.h"
+#include "properties.h"
+
+#include "pubsub/publisher.h"
+#include "pubsub/subscriber.h"
+
+struct pubsub_endpoint {
+ char *frameworkUUID;
+ char *scope;
+ char *topic;
+ long serviceID;
+ char* endpoint;
+ bool is_secure;
+ properties_pt topic_props;
+};
+
+typedef struct pubsub_endpoint *pubsub_endpoint_pt;
+
+celix_status_t pubsubEndpoint_create(const char* fwUUID, const char* scope, const char* topic, long serviceId,const char* endpoint,properties_pt topic_props,pubsub_endpoint_pt* psEp);
+celix_status_t pubsubEndpoint_createFromServiceReference(service_reference_pt reference,pubsub_endpoint_pt* psEp, bool isPublisher);
+celix_status_t pubsubEndpoint_createFromListenerHookInfo(listener_hook_info_pt info,pubsub_endpoint_pt* psEp, bool isPublisher);
+celix_status_t pubsubEndpoint_clone(pubsub_endpoint_pt in, pubsub_endpoint_pt *out);
+celix_status_t pubsubEndpoint_destroy(pubsub_endpoint_pt psEp);
+bool pubsubEndpoint_equals(pubsub_endpoint_pt psEp1,pubsub_endpoint_pt psEp2);
+
+char *createScopeTopicKey(const char* scope, const char* topic);
+
+#endif /* PUBSUB_ENDPOINT_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_spi/include/pubsub_serializer.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/include/pubsub_serializer.h b/pubsub/pubsub_spi/include/pubsub_serializer.h
new file mode 100644
index 0000000..4489fa4
--- /dev/null
+++ b/pubsub/pubsub_spi/include/pubsub_serializer.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.
+ */
+/*
+ * pubsub_serializer.h
+ *
+ * \date Mar 24, 2017
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PUBSUB_SERIALIZER_SERVICE_H_
+#define PUBSUB_SERIALIZER_SERVICE_H_
+
+#include "service_reference.h"
+#include "hash_map.h"
+
+#include "pubsub_common.h"
+
+#define PUBSUB_SERIALIZER_TYPE_KEY "pubsub_serializer.type"
+
+/**
+ * There should be a pubsub_serializer_t
+ * per msg type (msg id) per bundle
+ *
+ * The pubsub_serializer_service can create
+ * a serializer_map per bundle. Potentially using
+ * the extender pattern.
+ */
+
+typedef struct pubsub_msg_serializer {
+ void* handle;
+ unsigned int msgId;
+ const char* msgName;
+ version_pt msgVersion;
+
+ celix_status_t (*serialize)(void* handle, const void* input, void** out, size_t* outLen);
+ celix_status_t (*deserialize)(void* handle, const void* input, size_t inputLen, void** out); //note inputLen can be 0 if predefined size is not needed
+ void (*freeMsg)(void* handle, void* msg);
+
+} pubsub_msg_serializer_t;
+
+typedef struct pubsub_serializer_service {
+ void* handle;
+
+ celix_status_t (*createSerializerMap)(void* handle, bundle_pt bundle, hash_map_pt* serializerMap);
+ celix_status_t (*destroySerializerMap)(void* handle, hash_map_pt serializerMap);
+
+} pubsub_serializer_service_t;
+
+#endif /* PUBSUB_SERIALIZER_SERVICE_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_spi/include/pubsub_topic_info.descriptor
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/include/pubsub_topic_info.descriptor b/pubsub/pubsub_spi/include/pubsub_topic_info.descriptor
new file mode 100644
index 0000000..c01a2fd
--- /dev/null
+++ b/pubsub/pubsub_spi/include/pubsub_topic_info.descriptor
@@ -0,0 +1,10 @@
+:header
+type=interface
+name=pubsub_topic_info
+version=1.0.0
+:annotations
+:types
+:methods
+getParticipantsNumber(t)i=getParticipantsNumber(#am=handle;Pt#am=pre;*i)N
+getSubscribersNumber(t)i=getSubscribersNumber(#am=handle;Pt#am=pre;*i)N
+getPublishersNumber(t)i=getPublishersNumber(#am=handle;Pt#am=pre;*i)N
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_spi/include/pubsub_utils.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/include/pubsub_utils.h b/pubsub/pubsub_spi/include/pubsub_utils.h
new file mode 100644
index 0000000..aff5c72
--- /dev/null
+++ b/pubsub/pubsub_spi/include/pubsub_utils.h
@@ -0,0 +1,39 @@
+/**
+ *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.
+ */
+/*
+ * pubsub_utils.h
+ *
+ * \date Sep 24, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PUBSUB_UTILS_H_
+#define PUBSUB_UTILS_H_
+
+#include "bundle_context.h"
+#include "array_list.h"
+
+char* pubsub_getScopeFromFilter(char* bundle_filter);
+char* pubsub_getTopicFromFilter(char* bundle_filter);
+char* pubsub_getKeysBundleDir(bundle_context_pt ctx);
+array_list_pt pubsub_getTopicsFromString(char* string);
+
+
+#endif /* PUBSUB_UTILS_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_spi/src/pubsub_admin_match.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/src/pubsub_admin_match.c b/pubsub/pubsub_spi/src/pubsub_admin_match.c
new file mode 100644
index 0000000..2a695c1
--- /dev/null
+++ b/pubsub/pubsub_spi/src/pubsub_admin_match.c
@@ -0,0 +1,320 @@
+/**
+ *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.
+ */
+
+
+#include <string.h>
+#include "service_reference.h"
+
+#include "pubsub_admin.h"
+
+#include "pubsub_admin_match.h"
+
+#define KNOWN_PUBSUB_ADMIN_NUM 2
+#define KNOWN_SERIALIZER_NUM 2
+
+static char* qos_sample_pubsub_admin_prio_list[KNOWN_PUBSUB_ADMIN_NUM] = {"udp_mc","zmq"};
+static char* qos_sample_serializer_prio_list[KNOWN_SERIALIZER_NUM] = {"json","void"};
+
+static char* qos_control_pubsub_admin_prio_list[KNOWN_PUBSUB_ADMIN_NUM] = {"zmq","udp_mc"};
+static char* qos_control_serializer_prio_list[KNOWN_SERIALIZER_NUM] = {"json","void"};
+
+static double qos_pubsub_admin_score[KNOWN_PUBSUB_ADMIN_NUM] = {100.0F,75.0F};
+static double qos_serializer_score[KNOWN_SERIALIZER_NUM] = {30.0F,20.0F};
+
+static void get_serializer_type(service_reference_pt svcRef, char **serializerType);
+static void manage_service_from_reference(service_reference_pt svcRef, void **svc, bool getService);
+
+celix_status_t pubsub_admin_match(properties_pt endpoint_props, const char *pubsub_admin_type, array_list_pt serializerList, double *score){
+
+ celix_status_t status = CELIX_SUCCESS;
+ double final_score = 0;
+ int i = 0, j = 0;
+
+ const char *requested_admin_type = NULL;
+ const char *requested_serializer_type = NULL;
+ const char *requested_qos_type = NULL;
+
+ if(endpoint_props!=NULL){
+ requested_admin_type = properties_get(endpoint_props,PUBSUB_ADMIN_TYPE_KEY);
+ requested_serializer_type = properties_get(endpoint_props,PUBSUB_SERIALIZER_TYPE_KEY);
+ requested_qos_type = properties_get(endpoint_props,QOS_ATTRIBUTE_KEY);
+ }
+
+ /* Analyze the pubsub_admin */
+ if(requested_admin_type != NULL){ /* We got precise specification on the pubsub_admin we want */
+ if(strncmp(requested_admin_type,pubsub_admin_type,strlen(pubsub_admin_type))==0){ //Full match
+ final_score += PUBSUB_ADMIN_FULL_MATCH_SCORE;
+ }
+ }
+ else if(requested_qos_type != NULL){ /* We got QoS specification that will determine the selected PSA */
+ if(strncmp(requested_qos_type,QOS_TYPE_SAMPLE,strlen(QOS_TYPE_SAMPLE))==0){
+ for(i=0;i<KNOWN_PUBSUB_ADMIN_NUM;i++){
+ if(strncmp(qos_sample_pubsub_admin_prio_list[i],pubsub_admin_type,strlen(pubsub_admin_type))==0){
+ final_score += qos_pubsub_admin_score[i];
+ break;
+ }
+ }
+ }
+ else if(strncmp(requested_qos_type,QOS_TYPE_CONTROL,strlen(QOS_TYPE_CONTROL))==0){
+ for(i=0;i<KNOWN_PUBSUB_ADMIN_NUM;i++){
+ if(strncmp(qos_control_pubsub_admin_prio_list[i],pubsub_admin_type,strlen(pubsub_admin_type))==0){
+ final_score += qos_pubsub_admin_score[i];
+ break;
+ }
+ }
+ }
+ else{
+ printf("Unknown QoS type '%s'\n",requested_qos_type);
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+ }
+ else{ /* We got no specification: fallback to Qos=Sample, but count half the score */
+ for(i=0;i<KNOWN_PUBSUB_ADMIN_NUM;i++){
+ if(strncmp(qos_sample_pubsub_admin_prio_list[i],pubsub_admin_type,strlen(pubsub_admin_type))==0){
+ final_score += (qos_pubsub_admin_score[i]/2);
+ break;
+ }
+ }
+ }
+
+ char *serializer_type = NULL;
+ /* Analyze the serializers */
+ if(requested_serializer_type != NULL){ /* We got precise specification on the serializer we want */
+ for(i=0;i<arrayList_size(serializerList);i++){
+ service_reference_pt svcRef = (service_reference_pt)arrayList_get(serializerList,i);
+ get_serializer_type(svcRef, &serializer_type);
+ if(serializer_type != NULL){
+ if(strncmp(requested_serializer_type,serializer_type,strlen(serializer_type))==0){
+ final_score += SERIALIZER_FULL_MATCH_SCORE;
+ break;
+ }
+ }
+ }
+ }
+ else if(requested_qos_type != NULL){ /* We got QoS specification that will determine the selected serializer */
+ if(strncmp(requested_qos_type,QOS_TYPE_SAMPLE,strlen(QOS_TYPE_SAMPLE))==0){
+ bool ser_found = false;
+ for(i=0;i<KNOWN_SERIALIZER_NUM && !ser_found;i++){
+ for(j=0;j<arrayList_size(serializerList) && !ser_found;j++){
+ service_reference_pt svcRef = (service_reference_pt)arrayList_get(serializerList,j);
+ get_serializer_type(svcRef, &serializer_type);
+ if(serializer_type != NULL){
+ if(strncmp(qos_sample_serializer_prio_list[i],serializer_type,strlen(serializer_type))==0){
+ ser_found = true;
+ }
+ }
+ }
+ if(ser_found){
+ final_score += qos_serializer_score[i];
+ }
+ }
+ }
+ else if(strncmp(requested_qos_type,QOS_TYPE_CONTROL,strlen(QOS_TYPE_CONTROL))==0){
+ bool ser_found = false;
+ for(i=0;i<KNOWN_SERIALIZER_NUM && !ser_found;i++){
+ for(j=0;j<arrayList_size(serializerList) && !ser_found;j++){
+ service_reference_pt svcRef = (service_reference_pt)arrayList_get(serializerList,j);
+ get_serializer_type(svcRef, &serializer_type);
+ if(serializer_type != NULL){
+ if(strncmp(qos_control_serializer_prio_list[i],serializer_type,strlen(serializer_type))==0){
+ ser_found = true;
+ }
+ }
+ }
+ if(ser_found){
+ final_score += qos_serializer_score[i];
+ }
+ }
+ }
+ else{
+ printf("Unknown QoS type '%s'\n",requested_qos_type);
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+ }
+ else{ /* We got no specification: fallback to Qos=Sample, but count half the score */
+ bool ser_found = false;
+ for(i=0;i<KNOWN_SERIALIZER_NUM && !ser_found;i++){
+ for(j=0;j<arrayList_size(serializerList) && !ser_found;j++){
+ service_reference_pt svcRef = (service_reference_pt)arrayList_get(serializerList,j);
+ get_serializer_type(svcRef, &serializer_type);
+ if(serializer_type != NULL){
+ if(strncmp(qos_sample_serializer_prio_list[i],serializer_type,strlen(serializer_type))==0){
+ ser_found = true;
+ }
+ }
+ }
+ if(ser_found){
+ final_score += (qos_serializer_score[i]/2);
+ }
+ }
+ }
+
+ *score = final_score;
+
+ printf("Score for pair <%s,%s> = %f\n",pubsub_admin_type,serializer_type,final_score);
+
+ return status;
+}
+
+celix_status_t pubsub_admin_get_best_serializer(properties_pt endpoint_props, array_list_pt serializerList, pubsub_serializer_service_t **serSvc){
+ celix_status_t status = CELIX_SUCCESS;
+
+ int i = 0, j = 0;
+
+ const char *requested_serializer_type = NULL;
+ const char *requested_qos_type = NULL;
+
+ if (endpoint_props != NULL){
+ requested_serializer_type = properties_get(endpoint_props,PUBSUB_SERIALIZER_TYPE_KEY);
+ requested_qos_type = properties_get(endpoint_props,QOS_ATTRIBUTE_KEY);
+ }
+
+ service_reference_pt svcRef = NULL;
+ void *svc = NULL;
+
+ /* Analyze the serializers */
+ if(requested_serializer_type != NULL){ /* We got precise specification on the serializer we want */
+ for(i=0;i<arrayList_size(serializerList);i++){
+ svcRef = (service_reference_pt)arrayList_get(serializerList,i);
+ char *serializer_type = NULL;
+ get_serializer_type(svcRef, &serializer_type);
+ if(serializer_type != NULL){
+ if(strncmp(requested_serializer_type,serializer_type,strlen(serializer_type))==0){
+ manage_service_from_reference(svcRef, &svc,true);
+ if(svc==NULL){
+ printf("Cannot get pubsub_serializer_service from serviceReference %p\n",svcRef);
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ *serSvc = svc;
+ break;
+ }
+ }
+ }
+ }
+ else if(requested_qos_type != NULL){ /* We got QoS specification that will determine the selected serializer */
+ if(strncmp(requested_qos_type,QOS_TYPE_SAMPLE,strlen(QOS_TYPE_SAMPLE))==0){
+ bool ser_found = false;
+ for(i=0;i<KNOWN_SERIALIZER_NUM && !ser_found;i++){
+ for(j=0;j<arrayList_size(serializerList) && !ser_found;j++){
+ svcRef = (service_reference_pt)arrayList_get(serializerList,j);
+ char *serializer_type = NULL;
+ get_serializer_type(svcRef, &serializer_type);
+ if(serializer_type != NULL){
+ if(strncmp(qos_sample_serializer_prio_list[i],serializer_type,strlen(serializer_type))==0){
+ manage_service_from_reference(svcRef, &svc,true);
+ if(svc==NULL){
+ printf("Cannot get pubsub_serializer_service from serviceReference %p\n",svcRef);
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ else{
+ *serSvc = svc;
+ ser_found = true;
+ printf("Selected %s serializer as best for QoS=%s\n",qos_sample_serializer_prio_list[i],QOS_TYPE_SAMPLE);
+ }
+ }
+ }
+ }
+ }
+ }
+ else if(strncmp(requested_qos_type,QOS_TYPE_CONTROL,strlen(QOS_TYPE_CONTROL))==0){
+ bool ser_found = false;
+ for(i=0;i<KNOWN_SERIALIZER_NUM && !ser_found;i++){
+ for(j=0;j<arrayList_size(serializerList) && !ser_found;j++){
+ svcRef = (service_reference_pt)arrayList_get(serializerList,j);
+ char *serializer_type = NULL;
+ get_serializer_type(svcRef, &serializer_type);
+ if(serializer_type != NULL){
+ if(strncmp(qos_control_serializer_prio_list[i],serializer_type,strlen(serializer_type))==0){
+ manage_service_from_reference(svcRef, &svc,true);
+ if(svc==NULL){
+ printf("Cannot get pubsub_serializer_service from serviceReference %p\n",svcRef);
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ else{
+ *serSvc = svc;
+ ser_found = true;
+ printf("Selected %s serializer as best for QoS=%s\n",qos_control_serializer_prio_list[i],QOS_TYPE_CONTROL);
+ }
+ }
+ }
+ }
+ }
+ }
+ else{
+ printf("Unknown QoS type '%s'\n",requested_qos_type);
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+ }
+ else{ /* We got no specification: fallback to Qos=Sample, but count half the score */
+ bool ser_found = false;
+ for(i=0;i<KNOWN_SERIALIZER_NUM && !ser_found;i++){
+ for(j=0;j<arrayList_size(serializerList) && !ser_found;j++){
+ svcRef = (service_reference_pt)arrayList_get(serializerList,j);
+ char *serializer_type = NULL;
+ get_serializer_type(svcRef, &serializer_type);
+ if(serializer_type != NULL){
+ if(strncmp(qos_sample_serializer_prio_list[i],serializer_type,strlen(serializer_type))==0){
+ manage_service_from_reference(svcRef, &svc,true);
+ if(svc==NULL){
+ printf("Cannot get pubsub_serializer_service from serviceReference %p\n",svcRef);
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ else{
+ *serSvc = svc;
+ ser_found = true;
+ printf("Selected %s serializer as best without any specification\n",qos_sample_serializer_prio_list[i]);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if(svc!=NULL && svcRef!=NULL){
+ manage_service_from_reference(svcRef, svc, false);
+ }
+
+ return status;
+}
+
+static void get_serializer_type(service_reference_pt svcRef, char **serializerType){
+
+ const char *serType = NULL;
+ serviceReference_getProperty(svcRef, PUBSUB_SERIALIZER_TYPE_KEY,&serType);
+ if(serType != NULL){
+ *serializerType = (char*)serType;
+ }
+ else{
+ printf("Serializer serviceReference %p has no pubsub_serializer.type property specified\n",svcRef);
+ *serializerType = NULL;
+ }
+}
+
+static void manage_service_from_reference(service_reference_pt svcRef, void **svc, bool getService){
+ bundle_context_pt context = NULL;
+ bundle_pt bundle = NULL;
+ serviceReference_getBundle(svcRef, &bundle);
+ bundle_getContext(bundle, &context);
+ if(getService){
+ bundleContext_getService(context, svcRef, svc);
+ }
+ else{
+ bundleContext_ungetService(context, svcRef, NULL);
+ }
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_spi/src/pubsub_endpoint.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/src/pubsub_endpoint.c b/pubsub/pubsub_spi/src/pubsub_endpoint.c
new file mode 100644
index 0000000..c3fd293
--- /dev/null
+++ b/pubsub/pubsub_spi/src/pubsub_endpoint.c
@@ -0,0 +1,254 @@
+/**
+ *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.
+ */
+/*
+ * endpoint_description.c
+ *
+ * \date 25 Jul 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "celix_errno.h"
+#include "celix_log.h"
+
+#include "pubsub_common.h"
+#include "pubsub_endpoint.h"
+#include "constants.h"
+
+#include "pubsub_utils.h"
+
+
+static void pubsubEndpoint_setFields(pubsub_endpoint_pt psEp, const char* fwUUID, const char* scope, const char* topic, long serviceId,const char* endpoint,properties_pt topic_props, bool cloneProps);
+static properties_pt pubsubEndpoint_getTopicProperties(bundle_pt bundle, const char *topic, bool isPublisher);
+
+static void pubsubEndpoint_setFields(pubsub_endpoint_pt psEp, const char* fwUUID, const char* scope, const char* topic, long serviceId,const char* endpoint,properties_pt topic_props, bool cloneProps){
+
+ if (fwUUID != NULL) {
+ psEp->frameworkUUID = strdup(fwUUID);
+ }
+
+ if (scope != NULL) {
+ psEp->scope = strdup(scope);
+ }
+
+ if (topic != NULL) {
+ psEp->topic = strdup(topic);
+ }
+
+ psEp->serviceID = serviceId;
+
+ if(endpoint != NULL) {
+ psEp->endpoint = strdup(endpoint);
+ }
+
+ if(topic_props != NULL){
+ if(cloneProps){
+ properties_copy(topic_props, &(psEp->topic_props));
+ }
+ else{
+ psEp->topic_props = topic_props;
+ }
+ }
+}
+
+static properties_pt pubsubEndpoint_getTopicProperties(bundle_pt bundle, const char *topic, bool isPublisher){
+
+ properties_pt topic_props = NULL;
+
+ bool isSystemBundle = false;
+ bundle_isSystemBundle(bundle, &isSystemBundle);
+ long bundleId = -1;
+ bundle_isSystemBundle(bundle, &isSystemBundle);
+ bundle_getBundleId(bundle,&bundleId);
+
+ if(isSystemBundle == false) {
+
+ char *bundleRoot = NULL;
+ char* topicPropertiesPath = NULL;
+ bundle_getEntry(bundle, ".", &bundleRoot);
+
+ if(bundleRoot != NULL){
+
+ asprintf(&topicPropertiesPath, "%s/META-INF/topics/%s/%s.properties", bundleRoot, isPublisher?"pub":"sub", topic);
+ topic_props = properties_load(topicPropertiesPath);
+ if(topic_props==NULL){
+ printf("PSEP: Could not load properties for %s on topic %s, bundleId=%ld\n", isPublisher?"publication":"subscription", topic,bundleId);
+ }
+
+ free(topicPropertiesPath);
+ free(bundleRoot);
+ }
+ }
+
+ return topic_props;
+}
+
+celix_status_t pubsubEndpoint_create(const char* fwUUID, const char* scope, const char* topic, long serviceId,const char* endpoint,properties_pt topic_props,pubsub_endpoint_pt* psEp){
+ celix_status_t status = CELIX_SUCCESS;
+
+ *psEp = calloc(1, sizeof(**psEp));
+
+ pubsubEndpoint_setFields(*psEp, fwUUID, scope, topic, serviceId, endpoint, topic_props, true);
+
+ return status;
+
+}
+
+celix_status_t pubsubEndpoint_clone(pubsub_endpoint_pt in, pubsub_endpoint_pt *out){
+ celix_status_t status = CELIX_SUCCESS;
+
+ *out = calloc(1,sizeof(**out));
+
+ pubsubEndpoint_setFields(*out, in->frameworkUUID, in->scope, in->topic, in->serviceID, in->endpoint, in->topic_props, true);
+
+ return status;
+
+}
+
+celix_status_t pubsubEndpoint_createFromServiceReference(service_reference_pt reference, pubsub_endpoint_pt* psEp, bool isPublisher){
+ celix_status_t status = CELIX_SUCCESS;
+
+ pubsub_endpoint_pt ep = calloc(1,sizeof(*ep));
+
+ bundle_pt bundle = NULL;
+ bundle_context_pt ctxt = NULL;
+ const char* fwUUID = NULL;
+ serviceReference_getBundle(reference,&bundle);
+ bundle_getContext(bundle,&ctxt);
+ bundleContext_getProperty(ctxt,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
+
+ const char* scope = NULL;
+ serviceReference_getProperty(reference, PUBSUB_SUBSCRIBER_SCOPE,&scope);
+
+ const char* topic = NULL;
+ serviceReference_getProperty(reference, PUBSUB_SUBSCRIBER_TOPIC,&topic);
+
+ const char* serviceId = NULL;
+ serviceReference_getProperty(reference,(char*)OSGI_FRAMEWORK_SERVICE_ID,&serviceId);
+
+ /* TODO: is topic_props==NULL a fatal error such that EP cannot be created? */
+ properties_pt topic_props = pubsubEndpoint_getTopicProperties(bundle, topic, isPublisher);
+
+ pubsubEndpoint_setFields(ep, fwUUID, scope!=NULL?scope:PUBSUB_SUBSCRIBER_SCOPE_DEFAULT, topic, strtol(serviceId,NULL,10), NULL, topic_props, false);
+
+ if (!ep->frameworkUUID || !ep->serviceID || !ep->scope || !ep->topic) {
+ fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "PUBSUB_ENDPOINT: incomplete description!.");
+ status = CELIX_BUNDLE_EXCEPTION;
+ pubsubEndpoint_destroy(ep);
+ *psEp = NULL;
+ }
+ else{
+ *psEp = ep;
+ }
+
+ return status;
+
+}
+
+celix_status_t pubsubEndpoint_createFromListenerHookInfo(listener_hook_info_pt info,pubsub_endpoint_pt* psEp, bool isPublisher){
+ celix_status_t status = CELIX_SUCCESS;
+
+ const char* fwUUID=NULL;
+ bundleContext_getProperty(info->context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
+
+ if(fwUUID==NULL){
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+
+ char* topic = pubsub_getTopicFromFilter(info->filter);
+ if(topic==NULL){
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+
+ *psEp = calloc(1, sizeof(**psEp));
+
+ char* scope = pubsub_getScopeFromFilter(info->filter);
+ if(scope == NULL) {
+ scope = strdup(PUBSUB_PUBLISHER_SCOPE_DEFAULT);
+ }
+
+ bundle_pt bundle = NULL;
+ long bundleId = -1;
+ bundleContext_getBundle(info->context,&bundle);
+
+ bundle_getBundleId(bundle,&bundleId);
+
+ properties_pt topic_props = pubsubEndpoint_getTopicProperties(bundle, topic, isPublisher);
+
+ /* TODO: is topic_props==NULL a fatal error such that EP cannot be created? */
+ pubsubEndpoint_setFields(*psEp, fwUUID, scope!=NULL?scope:PUBSUB_SUBSCRIBER_SCOPE_DEFAULT, topic, bundleId, NULL, topic_props, false);
+
+ free(topic);
+ free(scope);
+
+
+ return status;
+}
+
+celix_status_t pubsubEndpoint_destroy(pubsub_endpoint_pt psEp){
+
+ if(psEp->frameworkUUID!=NULL){
+ free(psEp->frameworkUUID);
+ psEp->frameworkUUID = NULL;
+ }
+
+ if(psEp->scope!=NULL){
+ free(psEp->scope);
+ psEp->scope = NULL;
+ }
+
+ if(psEp->topic!=NULL){
+ free(psEp->topic);
+ psEp->topic = NULL;
+ }
+
+ if(psEp->endpoint!=NULL){
+ free(psEp->endpoint);
+ psEp->endpoint = NULL;
+ }
+
+ if(psEp->topic_props != NULL){
+ properties_destroy(psEp->topic_props);
+ }
+
+ free(psEp);
+
+ return CELIX_SUCCESS;
+
+}
+
+bool pubsubEndpoint_equals(pubsub_endpoint_pt psEp1,pubsub_endpoint_pt psEp2){
+
+ return ((strcmp(psEp1->frameworkUUID,psEp2->frameworkUUID)==0) &&
+ (strcmp(psEp1->scope,psEp2->scope)==0) &&
+ (strcmp(psEp1->topic,psEp2->topic)==0) &&
+ (psEp1->serviceID == psEp2->serviceID) /*&&
+ ((psEp1->endpoint==NULL && psEp2->endpoint==NULL)||(strcmp(psEp1->endpoint,psEp2->endpoint)==0))*/
+ );
+}
+
+char *createScopeTopicKey(const char* scope, const char* topic) {
+ char *result = NULL;
+ asprintf(&result, "%s:%s", scope, topic);
+
+ return result;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_spi/src/pubsub_utils.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/src/pubsub_utils.c b/pubsub/pubsub_spi/src/pubsub_utils.c
new file mode 100644
index 0000000..19b2271
--- /dev/null
+++ b/pubsub/pubsub_spi/src/pubsub_utils.c
@@ -0,0 +1,170 @@
+/**
+ *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.
+ */
+/*
+ * pubsub_utils.c
+ *
+ * \date Sep 24, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "constants.h"
+
+#include "pubsub_common.h"
+#include "pubsub/publisher.h"
+#include "pubsub_utils.h"
+
+#include "array_list.h"
+#include "bundle.h"
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#define MAX_KEYBUNDLE_LENGTH 256
+
+char* pubsub_getScopeFromFilter(char* bundle_filter){
+
+ char* scope = NULL;
+
+ char* filter = strdup(bundle_filter);
+
+ char* oc = strstr(filter,OSGI_FRAMEWORK_OBJECTCLASS);
+ if(oc!=NULL){
+ oc+=strlen(OSGI_FRAMEWORK_OBJECTCLASS)+1;
+ if(strncmp(oc,PUBSUB_PUBLISHER_SERVICE_NAME,strlen(PUBSUB_PUBLISHER_SERVICE_NAME))==0){
+
+ char* scopes = strstr(filter,PUBSUB_PUBLISHER_SCOPE);
+ if(scopes!=NULL){
+
+ scopes+=strlen(PUBSUB_PUBLISHER_SCOPE)+1;
+ char* bottom=strchr(scopes,')');
+ *bottom='\0';
+
+ scope=strdup(scopes);
+ } else {
+ scope=strdup(PUBSUB_PUBLISHER_SCOPE_DEFAULT);
+ }
+ }
+ }
+
+ free(filter);
+
+ return scope;
+}
+
+char* pubsub_getTopicFromFilter(char* bundle_filter){
+
+ char* topic = NULL;
+
+ char* filter = strdup(bundle_filter);
+
+ char* oc = strstr(filter,OSGI_FRAMEWORK_OBJECTCLASS);
+ if(oc!=NULL){
+ oc+=strlen(OSGI_FRAMEWORK_OBJECTCLASS)+1;
+ if(strncmp(oc,PUBSUB_PUBLISHER_SERVICE_NAME,strlen(PUBSUB_PUBLISHER_SERVICE_NAME))==0){
+
+ char* topics = strstr(filter,PUBSUB_PUBLISHER_TOPIC);
+ if(topics!=NULL){
+
+ topics+=strlen(PUBSUB_PUBLISHER_TOPIC)+1;
+ char* bottom=strchr(topics,')');
+ *bottom='\0';
+
+ topic=strdup(topics);
+
+ }
+ }
+ }
+
+ free(filter);
+
+ return topic;
+
+}
+
+array_list_pt pubsub_getTopicsFromString(char* string){
+
+ array_list_pt topic_list = NULL;
+ arrayList_create(&topic_list);
+
+ char* topics = strdup(string);
+
+ char* topic = strtok(topics,",;|# ");
+ arrayList_add(topic_list,strdup(topic));
+
+ while( (topic = strtok(NULL,",;|# ")) !=NULL){
+ arrayList_add(topic_list,strdup(topic));
+ }
+
+ free(topics);
+
+ return topic_list;
+
+}
+
+/**
+ * Loop through all bundles and look for the bundle with the keys inside.
+ * If no key bundle found, return NULL
+ *
+ * Caller is responsible for freeing the object
+ */
+char* pubsub_getKeysBundleDir(bundle_context_pt ctx)
+{
+ array_list_pt bundles = NULL;
+ bundleContext_getBundles(ctx, &bundles);
+ int nrOfBundles = arrayList_size(bundles);
+ long bundle_id = -1;
+ char* result = NULL;
+
+ for (int i = 0; i < nrOfBundles; i++){
+ bundle_pt b = arrayList_get(bundles, i);
+
+ /* Skip bundle 0 (framework bundle) since it has no path nor revisions */
+ bundle_getBundleId(b, &bundle_id);
+ if(bundle_id==0){
+ continue;
+ }
+
+ char* dir = NULL;
+ bundle_getEntry(b, ".", &dir);
+
+ char cert_dir[MAX_KEYBUNDLE_LENGTH];
+ snprintf(cert_dir, MAX_KEYBUNDLE_LENGTH, "%s/META-INF/keys", dir);
+
+ struct stat s;
+ int err = stat(cert_dir, &s);
+ if (err != -1){
+ if (S_ISDIR(s.st_mode)){
+ result = dir;
+ break;
+ }
+ }
+
+ free(dir);
+ }
+
+ arrayList_destroy(bundles);
+
+ return result;
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_topology_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_topology_manager/CMakeLists.txt b/pubsub/pubsub_topology_manager/CMakeLists.txt
index 784ca21..73b9ecb 100644
--- a/pubsub/pubsub_topology_manager/CMakeLists.txt
+++ b/pubsub/pubsub_topology_manager/CMakeLists.txt
@@ -15,22 +15,23 @@
# specific language governing permissions and limitations
# under the License.
-add_bundle(org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
+add_bundle(celix_pubsub_topology_manager
BUNDLE_SYMBOLICNAME "apache_celix_pubsub_topology_manager"
VERSION "1.0.0"
SOURCES
- private/src/pstm_activator.c
- private/src/pubsub_topology_manager.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_endpoint.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
+ src/pstm_activator.c
+ src/pubsub_topology_manager.c
+ src/pubsub_topology_manager.h
)
+target_link_libraries(celix_pubsub_topology_manager PRIVATE Celix::framework Celix::log_helper Celix::pubsub_spi)
-bundle_files(org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include/pubsub_topic_info.descriptor
+get_target_property(DESC Celix::pubsub_spi TOPIC_INFO_DESCRIPTOR)
+bundle_files(celix_pubsub_topology_manager
+ ${DESC}
DESTINATION "META-INF/descriptors/services"
)
-target_link_libraries(org.apache.celix.pubsub_topology_manager.PubSubTopologyManager PRIVATE Celix::framework Celix::log_helper)
+install_bundle(celix_pubsub_topology_manager)
-install_bundle(org.apache.celix.pubsub_topology_manager.PubSubTopologyManager)
+add_library(Celix::pubsub_topology_manager ALIAS celix_pubsub_topology_manager)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_topology_manager/private/include/pubsub_topology_manager.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_topology_manager/private/include/pubsub_topology_manager.h b/pubsub/pubsub_topology_manager/private/include/pubsub_topology_manager.h
deleted file mode 100644
index 7614e0c..0000000
--- a/pubsub/pubsub_topology_manager/private/include/pubsub_topology_manager.h
+++ /dev/null
@@ -1,83 +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.
- */
-/*
- * pubsub_topology_manager.h
- *
- * \date Sep 29, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PUBSUB_TOPOLOGY_MANAGER_H_
-#define PUBSUB_TOPOLOGY_MANAGER_H_
-
-#include "endpoint_listener.h"
-#include "service_reference.h"
-#include "bundle_context.h"
-#include "log_helper.h"
-
-#include "pubsub_common.h"
-#include "pubsub_endpoint.h"
-#include "publisher.h"
-#include "subscriber.h"
-
-
-struct pubsub_topology_manager {
- bundle_context_pt context;
-
- celix_thread_mutex_t psaListLock;
- array_list_pt psaList;
-
- celix_thread_mutex_t discoveryListLock;
- hash_map_pt discoveryList; //<serviceReference,NULL>
-
- celix_thread_mutex_t publicationsLock;
- hash_map_pt publications; //<topic(string),list<pubsub_ep>>
-
- celix_thread_mutex_t subscriptionsLock;
- hash_map_pt subscriptions; //<topic(string),list<pubsub_ep>>
-
- log_helper_pt loghelper;
-};
-
-typedef struct pubsub_topology_manager *pubsub_topology_manager_pt;
-
-celix_status_t pubsub_topologyManager_create(bundle_context_pt context, log_helper_pt logHelper, pubsub_topology_manager_pt *manager);
-celix_status_t pubsub_topologyManager_destroy(pubsub_topology_manager_pt manager);
-celix_status_t pubsub_topologyManager_closeImports(pubsub_topology_manager_pt manager);
-
-celix_status_t pubsub_topologyManager_psaAdded(void *handle, service_reference_pt reference, void *service);
-celix_status_t pubsub_topologyManager_psaModified(void *handle, service_reference_pt reference, void *service);
-celix_status_t pubsub_topologyManager_psaRemoved(void *handle, service_reference_pt reference, void *service);
-
-celix_status_t pubsub_topologyManager_pubsubDiscoveryAdded(void* handle, service_reference_pt reference, void* service);
-celix_status_t pubsub_topologyManager_pubsubDiscoveryModified(void * handle, service_reference_pt reference, void* service);
-celix_status_t pubsub_topologyManager_pubsubDiscoveryRemoved(void * handle, service_reference_pt reference, void* service);
-
-celix_status_t pubsub_topologyManager_subscriberAdded(void * handle, service_reference_pt reference, void * service);
-celix_status_t pubsub_topologyManager_subscriberModified(void * handle, service_reference_pt reference, void * service);
-celix_status_t pubsub_topologyManager_subscriberRemoved(void * handle, service_reference_pt reference, void * service);
-
-celix_status_t pubsub_topologyManager_publisherTrackerAdded(void *handle, array_list_pt listeners);
-celix_status_t pubsub_topologyManager_publisherTrackerRemoved(void *handle, array_list_pt listeners);
-
-celix_status_t pubsub_topologyManager_announcePublisher(void *handle, pubsub_endpoint_pt pubEP);
-celix_status_t pubsub_topologyManager_removePublisher(void *handle, pubsub_endpoint_pt pubEP);
-
-#endif /* PUBSUB_TOPOLOGY_MANAGER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_topology_manager/private/src/pstm_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_topology_manager/private/src/pstm_activator.c b/pubsub/pubsub_topology_manager/private/src/pstm_activator.c
deleted file mode 100644
index 4d6dd27..0000000
--- a/pubsub/pubsub_topology_manager/private/src/pstm_activator.c
+++ /dev/null
@@ -1,246 +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.
- */
-/*
- * pstm_activator.c
- *
- * \date Sep 29, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "constants.h"
-#include "bundle_activator.h"
-#include "service_tracker.h"
-#include "service_registration.h"
-
-#include "endpoint_listener.h"
-#include "remote_constants.h"
-#include "listener_hook_service.h"
-#include "log_service.h"
-#include "log_helper.h"
-
-
-#include "pubsub_topology_manager.h"
-#include "publisher_endpoint_announce.h"
-
-struct activator {
- bundle_context_pt context;
-
- pubsub_topology_manager_pt manager;
-
- service_tracker_pt pubsubDiscoveryTracker;
- service_tracker_pt pubsubAdminTracker;
- service_tracker_pt pubsubSubscribersTracker;
-
- listener_hook_service_pt hookService;
- service_registration_pt hook;
-
- publisher_endpoint_announce_pt publisherEPDiscover;
- service_registration_pt publisherEPDiscoverService;
-
- log_helper_pt loghelper;
-};
-
-
-static celix_status_t bundleActivator_createPSDTracker(struct activator *activator, service_tracker_pt *tracker);
-static celix_status_t bundleActivator_createPSATracker(struct activator *activator, service_tracker_pt *tracker);
-static celix_status_t bundleActivator_createPSSubTracker(struct activator *activator, service_tracker_pt *tracker);
-
-
-static celix_status_t bundleActivator_createPSDTracker(struct activator *activator, service_tracker_pt *tracker) {
- celix_status_t status;
-
- service_tracker_customizer_pt customizer = NULL;
-
- status = serviceTrackerCustomizer_create(activator->manager,
- NULL,
- pubsub_topologyManager_pubsubDiscoveryAdded,
- pubsub_topologyManager_pubsubDiscoveryModified,
- pubsub_topologyManager_pubsubDiscoveryRemoved,
- &customizer);
-
- if (status == CELIX_SUCCESS) {
- status = serviceTracker_create(activator->context, (char *) PUBSUB_DISCOVERY_SERVICE, customizer, tracker);
- }
-
- return status;
-}
-
-static celix_status_t bundleActivator_createPSATracker(struct activator *activator, service_tracker_pt *tracker) {
- celix_status_t status = CELIX_SUCCESS;
-
- service_tracker_customizer_pt customizer = NULL;
-
- status = serviceTrackerCustomizer_create(activator->manager,
- NULL,
- pubsub_topologyManager_psaAdded,
- pubsub_topologyManager_psaModified,
- pubsub_topologyManager_psaRemoved,
- &customizer);
-
- if (status == CELIX_SUCCESS) {
- status = serviceTracker_create(activator->context, PUBSUB_ADMIN_SERVICE, customizer, tracker);
- }
-
- return status;
-}
-
-static celix_status_t bundleActivator_createPSSubTracker(struct activator *activator, service_tracker_pt *tracker) {
- celix_status_t status = CELIX_SUCCESS;
-
- service_tracker_customizer_pt customizer = NULL;
-
- status = serviceTrackerCustomizer_create(activator->manager,
- NULL,
- pubsub_topologyManager_subscriberAdded,
- pubsub_topologyManager_subscriberModified,
- pubsub_topologyManager_subscriberRemoved,
- &customizer);
-
- if (status == CELIX_SUCCESS) {
- status = serviceTracker_create(activator->context, PUBSUB_SUBSCRIBER_SERVICE_NAME, customizer, tracker);
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = NULL;
-
- activator = calloc(1,sizeof(struct activator));
-
- if (!activator) {
- return CELIX_ENOMEM;
- }
-
- activator->context = context;
-
- logHelper_create(context, &activator->loghelper);
- logHelper_start(activator->loghelper);
-
- status = pubsub_topologyManager_create(context, activator->loghelper, &activator->manager);
- if (status == CELIX_SUCCESS) {
- status = bundleActivator_createPSDTracker(activator, &activator->pubsubDiscoveryTracker);
- if (status == CELIX_SUCCESS) {
- status = bundleActivator_createPSATracker(activator, &activator->pubsubAdminTracker);
- if (status == CELIX_SUCCESS) {
- status = bundleActivator_createPSSubTracker(activator, &activator->pubsubSubscribersTracker);
- if (status == CELIX_SUCCESS) {
- *userData = activator;
- }
- }
- }
- }
-
- if(status != CELIX_SUCCESS){
- bundleActivator_destroy(activator, context);
- }
-
- return status;
-}
-
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- publisher_endpoint_announce_pt pubEPDiscover = calloc(1, sizeof(*pubEPDiscover));
- pubEPDiscover->handle = activator->manager;
- pubEPDiscover->announcePublisher = pubsub_topologyManager_announcePublisher;
- pubEPDiscover->removePublisher = pubsub_topologyManager_removePublisher;
- activator->publisherEPDiscover = pubEPDiscover;
-
- status += bundleContext_registerService(context, (char *) PUBSUB_TM_ANNOUNCE_PUBLISHER_SERVICE, pubEPDiscover, NULL, &activator->publisherEPDiscoverService);
-
-
- listener_hook_service_pt hookService = calloc(1,sizeof(*hookService));
- hookService->handle = activator->manager;
- hookService->added = pubsub_topologyManager_publisherTrackerAdded;
- hookService->removed = pubsub_topologyManager_publisherTrackerRemoved;
- activator->hookService = hookService;
-
- status += bundleContext_registerService(context, (char *) OSGI_FRAMEWORK_LISTENER_HOOK_SERVICE_NAME, hookService, NULL, &activator->hook);
-
- /* NOTE: Enable those line in order to remotely expose the topic_info service
- properties_pt props = properties_create();
- properties_set(props, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, (char *) PUBSUB_TOPIC_INFO_SERVICE);
- status += bundleContext_registerService(context, (char *) PUBSUB_TOPIC_INFO_SERVICE, activator->topicInfo, props, &activator->topicInfoService);
- */
- status += serviceTracker_open(activator->pubsubAdminTracker);
-
- status += serviceTracker_open(activator->pubsubDiscoveryTracker);
-
- status += serviceTracker_open(activator->pubsubSubscribersTracker);
-
-
- return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- serviceTracker_close(activator->pubsubSubscribersTracker);
- serviceTracker_close(activator->pubsubDiscoveryTracker);
- serviceTracker_close(activator->pubsubAdminTracker);
-
- serviceRegistration_unregister(activator->publisherEPDiscoverService);
- free(activator->publisherEPDiscover);
-
- serviceRegistration_unregister(activator->hook);
- free(activator->hookService);
-
- return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
-
- struct activator *activator = userData;
- if (activator == NULL) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
-
- if(activator->pubsubSubscribersTracker!=NULL){
- serviceTracker_destroy(activator->pubsubSubscribersTracker);
- }
- if(activator->pubsubDiscoveryTracker!=NULL){
- serviceTracker_destroy(activator->pubsubDiscoveryTracker);
- }
- if(activator->pubsubAdminTracker!=NULL){
- serviceTracker_destroy(activator->pubsubAdminTracker);
- }
-
- if(activator->manager!=NULL){
- status = pubsub_topologyManager_destroy(activator->manager);
- }
-
- logHelper_stop(activator->loghelper);
- logHelper_destroy(&activator->loghelper);
-
- free(activator);
- }
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_topology_manager/private/src/pubsub_topology_manager.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_topology_manager/private/src/pubsub_topology_manager.c b/pubsub/pubsub_topology_manager/private/src/pubsub_topology_manager.c
deleted file mode 100644
index 987d864..0000000
--- a/pubsub/pubsub_topology_manager/private/src/pubsub_topology_manager.c
+++ /dev/null
@@ -1,723 +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.
- */
-/*
- * pubsub_topology_manager.c
- *
- * \date Sep 29, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdbool.h>
-
-#include "hash_map.h"
-#include "array_list.h"
-#include "bundle_context.h"
-#include "constants.h"
-#include "module.h"
-#include "bundle.h"
-#include "remote_service_admin.h"
-#include "remote_constants.h"
-#include "filter.h"
-#include "listener_hook_service.h"
-#include "utils.h"
-#include "service_reference.h"
-#include "service_registration.h"
-#include "log_service.h"
-#include "log_helper.h"
-
-#include "publisher_endpoint_announce.h"
-#include "pubsub_topology_manager.h"
-#include "pubsub_endpoint.h"
-#include "pubsub_admin.h"
-#include "pubsub_utils.h"
-
-
-celix_status_t pubsub_topologyManager_create(bundle_context_pt context, log_helper_pt logHelper, pubsub_topology_manager_pt *manager) {
- celix_status_t status = CELIX_SUCCESS;
-
- *manager = calloc(1, sizeof(**manager));
- if (!*manager) {
- return CELIX_ENOMEM;
- }
-
- (*manager)->context = context;
-
- celix_thread_mutexattr_t psaAttr;
- celixThreadMutexAttr_create(&psaAttr);
- celixThreadMutexAttr_settype(&psaAttr, CELIX_THREAD_MUTEX_RECURSIVE);
- status = celixThreadMutex_create(&(*manager)->psaListLock, &psaAttr);
- celixThreadMutexAttr_destroy(&psaAttr);
-
- status = celixThreadMutex_create(&(*manager)->publicationsLock, NULL);
- status = celixThreadMutex_create(&(*manager)->subscriptionsLock, NULL);
- status = celixThreadMutex_create(&(*manager)->discoveryListLock, NULL);
-
- arrayList_create(&(*manager)->psaList);
-
- (*manager)->discoveryList = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
- (*manager)->publications = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- (*manager)->subscriptions = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
-
- (*manager)->loghelper = logHelper;
-
- return status;
-}
-
-celix_status_t pubsub_topologyManager_destroy(pubsub_topology_manager_pt manager) {
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&manager->discoveryListLock);
- hashMap_destroy(manager->discoveryList, false, false);
- celixThreadMutex_unlock(&manager->discoveryListLock);
- celixThreadMutex_destroy(&manager->discoveryListLock);
-
- celixThreadMutex_lock(&manager->psaListLock);
- arrayList_destroy(manager->psaList);
- celixThreadMutex_unlock(&manager->psaListLock);
- celixThreadMutex_destroy(&manager->psaListLock);
-
- celixThreadMutex_lock(&manager->publicationsLock);
- hash_map_iterator_pt pubit = hashMapIterator_create(manager->publications);
- while(hashMapIterator_hasNext(pubit)){
- array_list_pt l = (array_list_pt)hashMapIterator_nextValue(pubit);
- int i;
- for(i=0;i<arrayList_size(l);i++){
- pubsubEndpoint_destroy((pubsub_endpoint_pt)arrayList_get(l,i));
- }
- arrayList_destroy(l);
- }
- hashMapIterator_destroy(pubit);
- hashMap_destroy(manager->publications, true, false);
- celixThreadMutex_unlock(&manager->publicationsLock);
- celixThreadMutex_destroy(&manager->publicationsLock);
-
- celixThreadMutex_lock(&manager->subscriptionsLock);
- hash_map_iterator_pt subit = hashMapIterator_create(manager->subscriptions);
- while(hashMapIterator_hasNext(subit)){
- array_list_pt l = (array_list_pt)hashMapIterator_nextValue(subit);
- int i;
- for(i=0;i<arrayList_size(l);i++){
- pubsubEndpoint_destroy((pubsub_endpoint_pt)arrayList_get(l,i));
- }
- arrayList_destroy(l);
- }
- hashMapIterator_destroy(subit);
- hashMap_destroy(manager->subscriptions, true, false);
- celixThreadMutex_unlock(&manager->subscriptionsLock);
- celixThreadMutex_destroy(&manager->subscriptionsLock);
-
- free(manager);
-
- return status;
-}
-
-celix_status_t pubsub_topologyManager_psaAdded(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status = CELIX_SUCCESS;
- pubsub_topology_manager_pt manager = handle;
- int i;
-
- pubsub_admin_service_pt psa = (pubsub_admin_service_pt) service;
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "PSTM: Added PSA");
-
- celixThreadMutex_lock(&manager->psaListLock);
- arrayList_add(manager->psaList, psa);
- celixThreadMutex_unlock(&manager->psaListLock);
-
- // Add already detected subscriptions to new PSA
- celixThreadMutex_lock(&manager->subscriptionsLock);
- hash_map_iterator_pt subscriptionsIterator = hashMapIterator_create(manager->subscriptions);
-
- while (hashMapIterator_hasNext(subscriptionsIterator)) {
- array_list_pt sub_ep_list = hashMapIterator_nextValue(subscriptionsIterator);
- for(i=0;i<arrayList_size(sub_ep_list);i++){
- status += psa->addSubscription(psa->admin, (pubsub_endpoint_pt)arrayList_get(sub_ep_list,i));
- }
- }
-
- hashMapIterator_destroy(subscriptionsIterator);
-
- celixThreadMutex_unlock(&manager->subscriptionsLock);
-
- // Add already detected publications to new PSA
- status = celixThreadMutex_lock(&manager->publicationsLock);
- hash_map_iterator_pt publicationsIterator = hashMapIterator_create(manager->publications);
-
- while (hashMapIterator_hasNext(publicationsIterator)) {
- array_list_pt pub_ep_list = hashMapIterator_nextValue(publicationsIterator);
- for(i=0;i<arrayList_size(pub_ep_list);i++){
- status += psa->addPublication(psa->admin, (pubsub_endpoint_pt)arrayList_get(pub_ep_list,i));
- }
- }
-
- hashMapIterator_destroy(publicationsIterator);
-
- celixThreadMutex_unlock(&manager->publicationsLock);
-
- return status;
-}
-
-celix_status_t pubsub_topologyManager_psaModified(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status = CELIX_SUCCESS;
-
- // Nop...
-
- return status;
-}
-
-celix_status_t pubsub_topologyManager_psaRemoved(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status = CELIX_SUCCESS;
- pubsub_topology_manager_pt manager = handle;
-
- pubsub_admin_service_pt psa = (pubsub_admin_service_pt) service;
-
- /* Deactivate all publications */
- celixThreadMutex_lock(&manager->publicationsLock);
-
- hash_map_iterator_pt pubit = hashMapIterator_create(manager->publications);
- while(hashMapIterator_hasNext(pubit)){
- hash_map_entry_pt pub_entry = hashMapIterator_nextEntry(pubit);
- char* scope_topic_key = (char*)hashMapEntry_getKey(pub_entry);
- // Extract scope/topic name from key
- char scope[MAX_SCOPE_LEN];
- char topic[MAX_TOPIC_LEN];
- sscanf(scope_topic_key, "%[^:]:%s", scope, topic );
- array_list_pt pubEP_list = (array_list_pt)hashMapEntry_getValue(pub_entry);
-
- status = psa->closeAllPublications(psa->admin,scope,topic);
-
- if(status==CELIX_SUCCESS){
- celixThreadMutex_lock(&manager->discoveryListLock);
- hash_map_iterator_pt iter = hashMapIterator_create(manager->discoveryList);
- while(hashMapIterator_hasNext(iter)){
- service_reference_pt disc_sr = (service_reference_pt)hashMapIterator_nextKey(iter);
- publisher_endpoint_announce_pt disc = NULL;
- bundleContext_getService(manager->context, disc_sr, (void**) &disc);
- const char* fwUUID = NULL;
- bundleContext_getProperty(manager->context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
- int i;
- for(i=0;i<arrayList_size(pubEP_list);i++){
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pubEP_list,i);
- if(strcmp(pubEP->frameworkUUID,fwUUID)==0){
- disc->removePublisher(disc->handle,pubEP);
- }
- }
- bundleContext_ungetService(manager->context, disc_sr, NULL);
- }
- hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&manager->discoveryListLock);
- }
- }
- hashMapIterator_destroy(pubit);
-
- celixThreadMutex_unlock(&manager->publicationsLock);
-
- /* Deactivate all subscriptions */
- celixThreadMutex_lock(&manager->subscriptionsLock);
- hash_map_iterator_pt subit = hashMapIterator_create(manager->subscriptions);
- while(hashMapIterator_hasNext(subit)){
- // TODO do some error checking
- char* scope_topic = (char*)hashMapIterator_nextKey(subit);
- char scope[MAX_TOPIC_LEN];
- char topic[MAX_TOPIC_LEN];
- memset(scope, 0 , MAX_TOPIC_LEN*sizeof(char));
- memset(topic, 0 , MAX_TOPIC_LEN*sizeof(char));
- sscanf(scope_topic, "%[^:]:%s", scope, topic );
- status += psa->closeAllSubscriptions(psa->admin,scope, topic);
- }
- hashMapIterator_destroy(subit);
- celixThreadMutex_unlock(&manager->subscriptionsLock);
-
- celixThreadMutex_lock(&manager->psaListLock);
- arrayList_removeElement(manager->psaList, psa);
- celixThreadMutex_unlock(&manager->psaListLock);
-
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "PSTM: Removed PSA");
-
- return status;
-}
-
-celix_status_t pubsub_topologyManager_subscriberAdded(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status = CELIX_SUCCESS;
- pubsub_topology_manager_pt manager = handle;
- //subscriber_service_pt subscriber = (subscriber_service_pt)service;
-
- pubsub_endpoint_pt sub = NULL;
- if(pubsubEndpoint_createFromServiceReference(reference,&sub,false) == CELIX_SUCCESS){
- celixThreadMutex_lock(&manager->subscriptionsLock);
- char *sub_key = createScopeTopicKey(sub->scope, sub->topic);
-
- array_list_pt sub_list_by_topic = hashMap_get(manager->subscriptions,sub_key);
- if(sub_list_by_topic==NULL){
- arrayList_create(&sub_list_by_topic);
- hashMap_put(manager->subscriptions,strdup(sub_key),sub_list_by_topic);
- }
- free(sub_key);
- arrayList_add(sub_list_by_topic,sub);
-
- celixThreadMutex_unlock(&manager->subscriptionsLock);
-
- int j;
- double score = 0;
- double best_score = 0;
- pubsub_admin_service_pt best_psa = NULL;
- celixThreadMutex_lock(&manager->psaListLock);
- for(j=0;j<arrayList_size(manager->psaList);j++){
- pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,j);
- psa->matchEndpoint(psa->admin,sub,&score);
- if(score>best_score){ /* We have a new winner! */
- best_score = score;
- best_psa = psa;
- }
- }
-
- if(best_psa != NULL && best_score>0){
- best_psa->addSubscription(best_psa->admin,sub);
- }
-
- // Inform discoveries for interest in the topic
- celixThreadMutex_lock(&manager->discoveryListLock);
- hash_map_iterator_pt iter = hashMapIterator_create(manager->discoveryList);
- while(hashMapIterator_hasNext(iter)){
- service_reference_pt disc_sr = (service_reference_pt)hashMapIterator_nextKey(iter);
- publisher_endpoint_announce_pt disc = NULL;
- bundleContext_getService(manager->context, disc_sr, (void**) &disc);
- disc->interestedInTopic(disc->handle, sub->scope, sub->topic);
- bundleContext_ungetService(manager->context, disc_sr, NULL);
- }
- hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&manager->discoveryListLock);
-
- celixThreadMutex_unlock(&manager->psaListLock);
- }
- else{
- status=CELIX_INVALID_BUNDLE_CONTEXT;
- }
-
- return status;
-}
-
-celix_status_t pubsub_topologyManager_subscriberModified(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status = CELIX_SUCCESS;
-
- // Nop...
-
- return status;
-}
-
-celix_status_t pubsub_topologyManager_subscriberRemoved(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status = CELIX_SUCCESS;
- pubsub_topology_manager_pt manager = handle;
-
- pubsub_endpoint_pt subcmp = NULL;
- if(pubsubEndpoint_createFromServiceReference(reference,&subcmp,false) == CELIX_SUCCESS){
-
- int j,k;
-
- // Inform discoveries that we not interested in the topic any more
- celixThreadMutex_lock(&manager->discoveryListLock);
- hash_map_iterator_pt iter = hashMapIterator_create(manager->discoveryList);
- while(hashMapIterator_hasNext(iter)){
- service_reference_pt disc_sr = (service_reference_pt)hashMapIterator_nextKey(iter);
- publisher_endpoint_announce_pt disc = NULL;
- bundleContext_getService(manager->context, disc_sr, (void**) &disc);
- disc->uninterestedInTopic(disc->handle, subcmp->scope, subcmp->topic);
- bundleContext_ungetService(manager->context, disc_sr, NULL);
- }
- hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&manager->discoveryListLock);
-
- celixThreadMutex_lock(&manager->subscriptionsLock);
- celixThreadMutex_lock(&manager->psaListLock);
-
- char *sub_key = createScopeTopicKey(subcmp->scope,subcmp->topic);
- array_list_pt sub_list_by_topic = hashMap_get(manager->subscriptions,sub_key);
- free(sub_key);
- if(sub_list_by_topic!=NULL){
- for(j=0;j<arrayList_size(sub_list_by_topic);j++){
- pubsub_endpoint_pt sub = arrayList_get(sub_list_by_topic,j);
- if(pubsubEndpoint_equals(sub,subcmp)){
- for(k=0;k<arrayList_size(manager->psaList);k++){
- /* No problem with invoking removal on all psa's, only the one that manage this topic will do something */
- pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,k);
- psa->removeSubscription(psa->admin,sub);
- }
-
- }
- arrayList_remove(sub_list_by_topic,j);
-
- /* If it was the last subscriber for this topic, tell PSA to close the ZMQ socket */
- if(arrayList_size(sub_list_by_topic)==0){
- for(k=0;k<arrayList_size(manager->psaList);k++){
- pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,k);
- psa->closeAllSubscriptions(psa->admin,sub->scope, sub->topic);
- }
- }
-
- pubsubEndpoint_destroy(sub);
-
- }
- }
-
- celixThreadMutex_unlock(&manager->psaListLock);
- celixThreadMutex_unlock(&manager->subscriptionsLock);
-
- pubsubEndpoint_destroy(subcmp);
-
- }
- else{
- status=CELIX_INVALID_BUNDLE_CONTEXT;
- }
-
- return status;
-
-}
-
-celix_status_t pubsub_topologyManager_pubsubDiscoveryAdded(void* handle, service_reference_pt reference, void* service) {
- celix_status_t status = CELIX_SUCCESS;
- pubsub_topology_manager_pt manager = (pubsub_topology_manager_pt)handle;
- publisher_endpoint_announce_pt disc = (publisher_endpoint_announce_pt)service;
-
- const char* fwUUID = NULL;
-
- bundleContext_getProperty(manager->context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
- if(fwUUID==NULL){
- printf("PSD: ERRROR: Cannot retrieve fwUUID.\n");
- return CELIX_INVALID_BUNDLE_CONTEXT;
- }
-
- celixThreadMutex_lock(&manager->publicationsLock);
-
- celixThreadMutex_lock(&manager->discoveryListLock);
- hashMap_put(manager->discoveryList, reference, NULL);
- celixThreadMutex_unlock(&manager->discoveryListLock);
-
- hash_map_iterator_pt iter = hashMapIterator_create(manager->publications);
- while(hashMapIterator_hasNext(iter)){
- array_list_pt pubEP_list = (array_list_pt)hashMapIterator_nextValue(iter);
- for(int i = 0; i < arrayList_size(pubEP_list); i++) {
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pubEP_list,i);
- if( (strcmp(pubEP->frameworkUUID,fwUUID)==0) && (pubEP->endpoint!=NULL)){
- status += disc->announcePublisher(disc->handle,pubEP);
- }
- }
- }
- hashMapIterator_destroy(iter);
-
- celixThreadMutex_unlock(&manager->publicationsLock);
-
- celixThreadMutex_lock(&manager->subscriptionsLock);
- iter = hashMapIterator_create(manager->subscriptions);
-
- while(hashMapIterator_hasNext(iter)) {
- array_list_pt l = (array_list_pt)hashMapIterator_nextValue(iter);
- int i;
- for(i=0;i<arrayList_size(l);i++){
- pubsub_endpoint_pt subEp = (pubsub_endpoint_pt)arrayList_get(l,i);
-
- disc->interestedInTopic(disc->handle, subEp->scope, subEp->topic);
- }
- }
- hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&manager->subscriptionsLock);
-
- return status;
-}
-
-celix_status_t pubsub_topologyManager_pubsubDiscoveryModified(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status = CELIX_SUCCESS;
-
- status = pubsub_topologyManager_pubsubDiscoveryRemoved(handle, reference, service);
- if (status == CELIX_SUCCESS) {
- status = pubsub_topologyManager_pubsubDiscoveryAdded(handle, reference, service);
- }
-
- return status;
-}
-
-celix_status_t pubsub_topologyManager_pubsubDiscoveryRemoved(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status = CELIX_SUCCESS;
-
- pubsub_topology_manager_pt manager = handle;
-
- celixThreadMutex_lock(&manager->discoveryListLock);
-
-
- if (hashMap_remove(manager->discoveryList, reference)) {
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "EndpointListener Removed");
- }
-
- celixThreadMutex_unlock(&manager->discoveryListLock);
-
- return status;
-}
-
-
-celix_status_t pubsub_topologyManager_publisherTrackerAdded(void *handle, array_list_pt listeners) {
-
- celix_status_t status = CELIX_SUCCESS;
- pubsub_topology_manager_pt manager = handle;
-
- int l_index;
-
- for (l_index = 0; l_index < arrayList_size(listeners); l_index++) {
-
- listener_hook_info_pt info = arrayList_get(listeners, l_index);
-
- pubsub_endpoint_pt pub = NULL;
- if(pubsubEndpoint_createFromListenerHookInfo(info, &pub, true) == CELIX_SUCCESS){
-
- celixThreadMutex_lock(&manager->publicationsLock);
- char *pub_key = createScopeTopicKey(pub->scope, pub->topic);
- array_list_pt pub_list_by_topic = hashMap_get(manager->publications, pub_key);
- if(pub_list_by_topic==NULL){
- arrayList_create(&pub_list_by_topic);
- hashMap_put(manager->publications,strdup(pub_key),pub_list_by_topic);
- }
- free(pub_key);
- arrayList_add(pub_list_by_topic,pub);
-
- celixThreadMutex_unlock(&manager->publicationsLock);
-
- int j;
- double score = 0;
- double best_score = 0;
- pubsub_admin_service_pt best_psa = NULL;
- celixThreadMutex_lock(&manager->psaListLock);
-
- for(j=0;j<arrayList_size(manager->psaList);j++){
- pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,j);
- psa->matchEndpoint(psa->admin,pub,&score);
- if(score>best_score){ /* We have a new winner! */
- best_score = score;
- best_psa = psa;
- }
- }
-
- if(best_psa != NULL && best_score>0){
- status = best_psa->addPublication(best_psa->admin,pub);
- if(status==CELIX_SUCCESS){
- celixThreadMutex_lock(&manager->discoveryListLock);
- hash_map_iterator_pt iter = hashMapIterator_create(manager->discoveryList);
- while(hashMapIterator_hasNext(iter)){
- service_reference_pt disc_sr = (service_reference_pt)hashMapIterator_nextKey(iter);
- publisher_endpoint_announce_pt disc = NULL;
- bundleContext_getService(manager->context, disc_sr, (void**) &disc);
- disc->announcePublisher(disc->handle,pub);
- bundleContext_ungetService(manager->context, disc_sr, NULL);
- }
- hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&manager->discoveryListLock);
- }
- }
-
- celixThreadMutex_unlock(&manager->psaListLock);
-
- }
-
- }
-
- return status;
-
-}
-
-
-celix_status_t pubsub_topologyManager_publisherTrackerRemoved(void *handle, array_list_pt listeners) {
- celix_status_t status = CELIX_SUCCESS;
- pubsub_topology_manager_pt manager = handle;
-
- int l_index;
-
- for (l_index = 0; l_index < arrayList_size(listeners); l_index++) {
-
- listener_hook_info_pt info = arrayList_get(listeners, l_index);
-
- pubsub_endpoint_pt pubcmp = NULL;
- if(pubsubEndpoint_createFromListenerHookInfo(info,&pubcmp,true) == CELIX_SUCCESS){
-
-
- int j,k;
- celixThreadMutex_lock(&manager->psaListLock);
- celixThreadMutex_lock(&manager->publicationsLock);
-
- char *pub_key = createScopeTopicKey(pubcmp->scope, pubcmp->topic);
- array_list_pt pub_list_by_topic = hashMap_get(manager->publications,pub_key);
- if(pub_list_by_topic!=NULL){
- for(j=0;j<arrayList_size(pub_list_by_topic);j++){
- pubsub_endpoint_pt pub = arrayList_get(pub_list_by_topic,j);
- if(pubsubEndpoint_equals(pub,pubcmp)){
- for(k=0;k<arrayList_size(manager->psaList);k++){
- pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,k);
- status = psa->removePublication(psa->admin,pub);
- if(status==CELIX_SUCCESS){ /* We found the one that manages this endpoint */
- celixThreadMutex_lock(&manager->discoveryListLock);
- hash_map_iterator_pt iter = hashMapIterator_create(manager->discoveryList);
- while(hashMapIterator_hasNext(iter)){
- service_reference_pt disc_sr = (service_reference_pt)hashMapIterator_nextKey(iter);
- publisher_endpoint_announce_pt disc = NULL;
- bundleContext_getService(manager->context, disc_sr, (void**) &disc);
- disc->removePublisher(disc->handle,pub);
- bundleContext_ungetService(manager->context, disc_sr, NULL);
- }
- hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&manager->discoveryListLock);
- }
- else if(status == CELIX_ILLEGAL_ARGUMENT){ /* Not a real error, just saying this psa does not handle this endpoint */
- status = CELIX_SUCCESS;
- }
- }
- //}
- arrayList_remove(pub_list_by_topic,j);
-
- /* If it was the last publisher for this topic, tell PSA to close the ZMQ socket and then inform the discovery */
- if(arrayList_size(pub_list_by_topic)==0){
- for(k=0;k<arrayList_size(manager->psaList);k++){
- pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,k);
- psa->closeAllPublications(psa->admin,pub->scope, pub->topic);
- }
- }
-
- pubsubEndpoint_destroy(pub);
- }
-
- }
- }
-
- celixThreadMutex_unlock(&manager->publicationsLock);
- celixThreadMutex_unlock(&manager->psaListLock);
-
- free(pub_key);
-
- pubsubEndpoint_destroy(pubcmp);
-
- }
-
- }
-
- return status;
-}
-
-celix_status_t pubsub_topologyManager_announcePublisher(void *handle, pubsub_endpoint_pt pubEP){
- celix_status_t status = CELIX_SUCCESS;
- printf("PSTM: New publisher discovered for topic %s [fwUUID=%s, ep=%s]\n",pubEP->topic,pubEP->frameworkUUID,pubEP->endpoint);
-
- pubsub_topology_manager_pt manager = handle;
- celixThreadMutex_lock(&manager->psaListLock);
- celixThreadMutex_lock(&manager->publicationsLock);
-
- char *pub_key = createScopeTopicKey(pubEP->scope, pubEP->topic);
-
- array_list_pt pub_list_by_topic = hashMap_get(manager->publications,pub_key);
- if(pub_list_by_topic==NULL){
- arrayList_create(&pub_list_by_topic);
- hashMap_put(manager->publications,strdup(pub_key),pub_list_by_topic);
- }
- free(pub_key);
-
- /* Shouldn't be any other duplicate, since it's filtered out by the discovery */
- pubsub_endpoint_pt p = NULL;
- pubsubEndpoint_clone(pubEP, &p);
- arrayList_add(pub_list_by_topic,p);
-
- int j;
- double score = 0;
- double best_score = 0;
- pubsub_admin_service_pt best_psa = NULL;
-
- for(j=0;j<arrayList_size(manager->psaList);j++){
- pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,j);
- psa->matchEndpoint(psa->admin,p,&score);
- if(score>best_score){ /* We have a new winner! */
- best_score = score;
- best_psa = psa;
- }
- }
-
- if(best_psa != NULL && best_score>0){
- best_psa->addPublication(best_psa->admin,p);
- }
- else{
- status = CELIX_ILLEGAL_STATE;
- }
-
- celixThreadMutex_unlock(&manager->publicationsLock);
- celixThreadMutex_unlock(&manager->psaListLock);
-
- return status;
-}
-
-celix_status_t pubsub_topologyManager_removePublisher(void *handle, pubsub_endpoint_pt pubEP){
- celix_status_t status = CELIX_SUCCESS;
- printf("PSTM: Publisher removed for topic %s [fwUUID=%s, ep=%s]\n",pubEP->topic,pubEP->frameworkUUID,pubEP->endpoint);
-
- pubsub_topology_manager_pt manager = handle;
- celixThreadMutex_lock(&manager->psaListLock);
- celixThreadMutex_lock(&manager->publicationsLock);
- int i;
-
- char *pub_key = createScopeTopicKey(pubEP->scope, pubEP->topic);
- array_list_pt pub_list_by_topic = hashMap_get(manager->publications,pub_key);
- if(pub_list_by_topic==NULL){
- printf("PSTM: ERROR: Cannot find topic for known endpoint [%s,%s,%s]. Something is inconsistent.\n",pub_key,pubEP->frameworkUUID,pubEP->endpoint);
- status = CELIX_ILLEGAL_STATE;
- }
- else{
-
- pubsub_endpoint_pt p = NULL;
- bool found = false;
-
- for(i=0;!found && i<arrayList_size(pub_list_by_topic);i++){
- p = (pubsub_endpoint_pt)arrayList_get(pub_list_by_topic,i);
- found = pubsubEndpoint_equals(p,pubEP);
- }
-
- if(found && p !=NULL){
-
- for(i=0;i<arrayList_size(manager->psaList);i++){
- pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,i);
- /* No problem with invoking removal on all psa's, only the one that manage this topic will do something */
- psa->removePublication(psa->admin,p);
- }
-
- arrayList_removeElement(pub_list_by_topic,p);
-
- /* If it was the last publisher for this topic, tell PSA to close the ZMQ socket */
- if(arrayList_size(pub_list_by_topic)==0){
-
- for(i=0;i<arrayList_size(manager->psaList);i++){
- pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,i);
- psa->closeAllPublications(psa->admin,p->scope, p->topic);
- }
- }
-
- pubsubEndpoint_destroy(p);
- }
-
-
- }
- free(pub_key);
- celixThreadMutex_unlock(&manager->publicationsLock);
- celixThreadMutex_unlock(&manager->psaListLock);
-
-
- return status;
-}
-
[47/54] [abbrv] celix git commit: CELIX-417: Adds initial
CelixConfig.cmake, export lib/exe target and exporting bundle target
Posted by pn...@apache.org.
CELIX-417: Adds initial CelixConfig.cmake, export lib/exe target and exporting bundle target
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/ae8e2e3c
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/ae8e2e3c
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/ae8e2e3c
Branch: refs/heads/develop
Commit: ae8e2e3c6fe14bb3775f7947c26b868966af0921
Parents: 0c64ca6
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Mon Jan 29 20:59:39 2018 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon Jan 29 20:59:39 2018 +0100
----------------------------------------------------------------------
CMakeLists.txt | 30 ++--
cmake/CMakeCelix.cmake | 31 ----
cmake/CelixConfig.cmake | 71 ++++++++
cmake/CelixConfigVersion.cmake.in | 28 +++
cmake/FindCELIX.cmake | 143 ----------------
cmake/FindCUnit.cmake | 65 -------
cmake/FindCZMQ.cmake | 42 -----
cmake/FindCppUTest.cmake | 54 ------
cmake/FindFFI.cmake | 57 -------
cmake/FindJansson.cmake | 42 -----
cmake/FindSlp.cmake | 42 -----
cmake/FindSyslog.cmake | 26 ---
cmake/FindUUID.cmake | 37 ----
cmake/FindZMQ.cmake | 42 -----
cmake/Modules/FindCUnit.cmake | 65 +++++++
cmake/Modules/FindCZMQ.cmake | 42 +++++
cmake/Modules/FindCppUTest.cmake | 54 ++++++
cmake/Modules/FindFFI.cmake | 57 +++++++
cmake/Modules/FindJansson.cmake | 42 +++++
cmake/Modules/FindSlp.cmake | 42 +++++
cmake/Modules/FindSyslog.cmake | 26 +++
cmake/Modules/FindUUID.cmake | 37 ++++
cmake/Modules/FindZMQ.cmake | 42 +++++
cmake/UseDoxygen.cmake | 170 -------------------
cmake/celix_project/ApacheRat.cmake | 30 ++++
cmake/celix_project/CelixProject.cmake | 80 +++++++++
cmake/celix_project/CodeCoverage.cmake | 126 ++++++++++++++
cmake/cmake_celix/ApacheRat.cmake | 30 ----
cmake/cmake_celix/BuildOptions.cmake | 24 ---
cmake/cmake_celix/BundlePackaging.cmake | 93 +++++++++-
cmake/cmake_celix/CodeCoverage.cmake | 126 --------------
cmake/cmake_celix/Dependencies.cmake | 69 --------
cmake/cmake_celix/DeployPackaging.cmake | 42 ++++-
cmake/cmake_celix/UseCelix.cmake | 13 +-
dependency_manager/CMakeLists.txt | 4 +-
dependency_manager_cxx/CMakeLists.txt | 6 +-
examples/CMakeLists.txt | 7 +-
examples/dm_example/CMakeLists.txt | 2 +-
examples/dm_example/phase3/CMakeLists.txt | 2 +-
examples/dm_example_cxx/CMakeLists.txt | 2 +-
examples/mongoose/CMakeLists.txt | 2 +-
framework/CMakeLists.txt | 4 -
log_service/CMakeLists.txt | 1 +
log_writer/log_writer_stdout/CMakeLists.txt | 2 +-
log_writer/log_writer_syslog/CMakeLists.txt | 2 +-
remote_services/topology_manager/CMakeLists.txt | 2 +-
shell/CMakeLists.txt | 8 +-
shell_tui/CMakeLists.txt | 2 +-
48 files changed, 920 insertions(+), 1046 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index aa26d8e..21117bb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,10 +21,8 @@ cmake_policy(SET CMP0042 NEW)
project (Celix C CXX)
-include(GNUInstallDirs)
-
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
-
+include(cmake/celix_project/CelixProject.cmake)
+include(cmake/cmake_celix/UseCelix.cmake)
# see https://public.kitware.com/Bug/view.php?id=15696
IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} EQUAL 3.3 AND ${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
@@ -52,7 +50,6 @@ ENDIF()
set(CELIX_MAJOR "1")
set(CELIX_MINOR "0")
set(CELIX_MICRO "0")
-set(CELIX_QUALIFIER "")
option(ENABLE_TESTING "Enables unit/bundle testing" FALSE)
@@ -60,10 +57,6 @@ if (ENABLE_TESTING)
enable_testing()
endif()
-
-include(CMakeCelix)
-include(UseDoxygen)
-
# Default bundle version
set(DEFAULT_VERSION 1.0.0)
@@ -95,9 +88,22 @@ add_subdirectory(pubsub)
add_subdirectory(dependency_manager)
add_subdirectory(dependency_manager_cxx)
+#Example as last, because some example will check if underlining options are enabled
+add_subdirectory(examples)
#export targets
-install(EXPORT celix NAMESPACE Celix:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/celix)
+install(EXPORT celix NAMESPACE Celix:: DESTINATION share/celix/cmake FILE CelixTargets.cmake COMPONENT cmake)
+install_celix_bundle_targets(celix NAMESPACE Celix:: DESTINATION share/celix/cmake FILE CelixBundleTargets.cmake COMPONENT cmake)
-#Example as last, because some example will check if underlining options are enabled
-add_subdirectory(examples)
+#install celix cmake modules
+install(DIRECTORY ${CMAKE_SOURCE_DIR}/cmake/Modules/ DESTINATION share/celix/cmake/Modules)
+install(DIRECTORY ${CMAKE_SOURCE_DIR}/cmake/cmake_celix/ DESTINATION share/celix/cmake/cmake_celix)
+
+#configure and install CelixConfig and CelixConfigVersion files
+configure_file(cmake/CelixConfigVersion.cmake.in
+ "${PROJECT_BINARY_DIR}/celix/gen/CelixConfigVersion.cmake" @ONLY)
+
+install(FILES
+ "cmake/CelixConfig.cmake"
+ "${PROJECT_BINARY_DIR}/celix/gen/CelixConfigVersion.cmake"
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/CMake/Celix" COMPONENT cmake)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/CMakeCelix.cmake
----------------------------------------------------------------------
diff --git a/cmake/CMakeCelix.cmake b/cmake/CMakeCelix.cmake
deleted file mode 100644
index f67648b..0000000
--- a/cmake/CMakeCelix.cmake
+++ /dev/null
@@ -1,31 +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.
-
-set(CELIX_CMAKE_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
-
-include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/Dependencies.cmake)
-include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/ApacheRat.cmake)
-include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/CodeCoverage.cmake)
-include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/BuildOptions.cmake)
-
-include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/UseCelix.cmake)
-
-#UseCelix includes:
-#include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/BundlePackaging.cmake)
-#include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/DeployPackaging.cmake)
-#include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/DockerPackaging.cmake)
-#include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/Runtimes.cmake)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/CelixConfig.cmake
----------------------------------------------------------------------
diff --git a/cmake/CelixConfig.cmake b/cmake/CelixConfig.cmake
new file mode 100644
index 0000000..c2d73d7
--- /dev/null
+++ b/cmake/CelixConfig.cmake
@@ -0,0 +1,71 @@
+# 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.
+
+# - Config file for the Apache Celix framework
+# It defines the following variables
+# CELIX_CMAKE_MODULES_DIR - The directory containing the Celix CMake modules
+# CELIX_INCLUDE_DIRS - include directories for the Celix framework
+# CELIX_LIBRARIES - libraries to link against
+# CELIX_LAUNCHER - The Celix launcher
+
+set(REL_INSTALL_DIR "${CMAKE_CURRENT_LIST_DIR}/../../..") #from lib/Cmake/Celix
+
+set(CELIX_CMAKE_MODULES_DIR ${REL_INSTALL_DIR}/share/celix/cmake/Modules)
+set(CELIX_FRAMEWORK_INCLUDE_DIR "${REL_INSTALL_DIR}/include/celix")
+set(CELIX_UTILS_INCLUDE_DIR "${REL_INSTALL_DIR}/include/utils")
+set(CELIX_DFI_INCLUDE_DIR "${REL_INSTALL_DIR}/include/dfi")
+
+include("${REL_INSTALL_DIR}/share/celix/cmake/cmake_celix/UseCelix.cmake")
+
+if(NOT TARGET Celix::framework)
+ include("${REL_INSTALL_DIR}/share/celix/cmake/CelixTargets.cmake")
+ include("${REL_INSTALL_DIR}/share/celix/cmake/CelixBundleTargets.cmake")
+endif()
+
+
+# The rest is added to ensure backwards compatiblity with project using the cmake lib/include var instead of targets.
+set(CELIX_LIBRARIES Celix::framework Celix::utils Celix::dfi)
+set(CELIX_INCLUDE_DIRS
+ $<TARGET_PROPERTY:Celix::framework,INTERFACE_INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::utils, INTERFACE_INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::dfi, INTERFACE_INCLUDE_DIRECTORIES>
+)
+
+set(CELIX_FRAMEWORK_LIBRARY Celix::framework)
+set(CELIX_UTILS_LIBRARY Celix::utils)
+set(CELIX_DFI_LIBRARY Celix::dfi)
+
+set(CELIX_LAUNCHER Celix::launcher)
+
+if (TARGET Celix::etcdlib)
+ set(CELIX_ETCD_INCLUDE_DIRS $<TARGET_PROPERTY:Celix::etcdlib,INTERFACE_INCLUDE_DIRECTORIES>)
+ set(CELIX_ETCD_LIB Celix::etcdlib)
+endif ()
+
+if (TARGET Celix::dependency_manager_so)
+ set(CELIX_DM_LIB Celix::dependency_manager_so)
+ set(CELIX_DM_INCLUDE_DIR $<TARGET_PROPERTY:Celix::dependency_manager_so,INTERFACE_INCLUDE_DIRECTORIES>)
+ set(CELIX_DM_STATIC_LIB Celix::dependency_manager_static)
+endif ()
+if (TARGET Celix::dependency_manager_cxx)
+ set(CELIX_DM_STATIC_CXX_LIB Celix::dependency_manager_cxx)
+ set(CELIX_DM_CXX_STATIC_LIB $<TARGET_PROPERTY:Celix::dependency_manager_cxx,INTERFACE_INCLUDE_DIRECTORIES>)
+endif ()
+
+set(CELIX_BUNDLES_DIR ${REL_INSTALL_DIR}/share/celix/bundles)
+set(CELIX_SHELL_BUNDLE ${CELIX_BUNDLES_DIR}/shell.zip)
+set(CELIX_SHELL_TUI_BUNDLE ${CELIX_BUNDLES_DIR}/shell_tui.zip)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/CelixConfigVersion.cmake.in
----------------------------------------------------------------------
diff --git a/cmake/CelixConfigVersion.cmake.in b/cmake/CelixConfigVersion.cmake.in
new file mode 100644
index 0000000..60eb8fe
--- /dev/null
+++ b/cmake/CelixConfigVersion.cmake.in
@@ -0,0 +1,28 @@
+# 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.
+
+set(PACKAGE_VERSION "@CELIX_MAJOR@.@CELIX_MINOR@.@CELIX_MICRO@")
+
+# Check whether the requested PACKAGE_FIND_VERSION is compatible
+if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+else()
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
+ set(PACKAGE_VERSION_EXACT TRUE)
+ endif()
+endif()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/FindCELIX.cmake
----------------------------------------------------------------------
diff --git a/cmake/FindCELIX.cmake b/cmake/FindCELIX.cmake
deleted file mode 100644
index ce31bc9..0000000
--- a/cmake/FindCELIX.cmake
+++ /dev/null
@@ -1,143 +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.
-
-
-# - Try to find Celix define the variables for the binaries/headers and include
-# the Celix cmake modules needed to build bundles
-#
-# Once done this will define
-# CELIX_FOUND - System has Apache Celix
-# CELIX_INCLUDE_DIRS - The Apache Celix include directories
-# CELIX_LIBRARIES - The libraries needed to use Apache Celix (framework,utils and dfi)
-# CELIX_LAUNCHER - The path to the celix launcher
-# CELIX_FRAMEWORK_LIBRARY - The path to the celix framework library
-# CELIX_UTILS_LIBRARY - The path to the celix utils library
-# CELIX_DFI_LIBRARY - The path to the celix dfi libary
-#
-#
-# CELIX_BUNDLES_DIR - The path where the Celix provided bundles are installed
-# CELIX_DM_LIB - The Celix Dependency Manager library
-# CELIX_DM_STATIC_LIB - The Celix Dependency Manager static library
-# CELIX_DM_STATIC_CXX_LIB - The Celix C++ Dependency Manager static library
-
-set(CELIX_DIR_FROM_FINDCELIX "${CMAKE_CURRENT_LIST_DIR}/../../../..")
-
-
-#Find libraries celix_framework, celix_utils, etcdlib and celix_dfi
-#Find celix launcher
-find_path(CELIX_INCLUDE_DIR NAMES celix_errno.h
- PATHS ${CELIX_DIR_FROM_FINDCELIX} $ENV{CELIX_DIR} ${CELIX_DIR} /usr /usr/local
- PATH_SUFFIXES include include/celix
-)
-
-find_path(CELIX_ETCD_INCLUDE_DIR NAMES etcd.h
- PATHS ${CELIX_DIR_FROM_FINDCELIX} $ENV{CELIX_DIR} ${CELIX_DIR} /usr /usr/local
- PATH_SUFFIXES include include/etcdlib
- )
-
-find_library(CELIX_FRAMEWORK_LIBRARY NAMES celix_framework
- PATHS ${CELIX_DIR_FROM_FINDCELIX} $ENV{CELIX_DIR} ${CELIX_DIR} /usr /usr/local
- PATH_SUFFIXES lib lib64
-)
-
-find_library(CELIX_UTILS_LIBRARY NAMES celix_utils
- PATHS ${CELIX_DIR_FROM_FINDCELIX} $ENV{CELIX_DIR} ${CELIX_DIR} /usr /usr/local
- PATH_SUFFIXES lib lib64
-)
-
-find_library(CELIX_DFI_LIBRARY NAMES celix_dfi
- PATHS ${CELIX_DIR_FROM_FINDCELIX} $ENV{CELIX_DIR} ${CELIX_DIR} /usr /usr/local
- PATH_SUFFIXES lib lib64
-)
-
-find_program(CELIX_LAUNCHER NAMES celix
- PATHS ${CELIX_DIR_FROM_FINDCELIX} $ENV{CELIX_DIR} ${CELIX_DIR} /usr /usr/local
- PATH_SUFFIXES bin
-)
-
-find_file(CELIX_USECELIX_FILE NAMES UseCelix.cmake
- PATHS ${CELIX_DIR_FROM_FINDCELIX} $ENV{CELIX_DIR} ${CELIX_DIR} /usr /usr/local
- PATH_SUFFIXES share/celix/cmake/modules/cmake_celix
-)
-
-
-
-
-#Finding dependency manager libraries for C and C++
-find_library(CELIX_DM_LIB NAMES dependency_manager_so
- PATHS ${CELIX_DIR_FROM_FINDCELIX} $ENV{CELIX_DIR} ${CELIX_DIR} /usr /usr/local
- PATH_SUFFIXES lib lib64
- )
-
-find_library(CELIX_DM_STATIC_LIB NAMES dependency_manager_static
- PATHS ${CELIX_DIR_FROM_FINDCELIX} $ENV{CELIX_DIR} ${CELIX_DIR} /usr /usr/local
- PATH_SUFFIXES lib lib64
- )
-
-find_library(CELIX_DM_STATIC_CXX_LIB NAMES dependency_manager_cxx_static
- PATHS ${CELIX_DIR_FROM_FINDCELIX} $ENV{CELIX_DIR} ${CELIX_DIR} /usr /usr/local
- PATH_SUFFIXES lib lib64
- )
-
-find_library(CELIX_ETCD_LIB NAMES etcdlib
- PATHS ${CELIX_DIR_FROM_FINDCELIX} $ENV{CELIX_DIR} ${CELIX_DIR} /usr /usr/local
- PATH_SUFFIXES lib lib64
- )
-
-
-#Finding bundles dir.
-find_path(CELIX_BUNDLES_DIR shell.zip #NOTE assuming shell.zip is always installed.
- PATHS ${CELIX_DIR_FROM_FINDCELIX} $ENV{CELIX_DIR} ${CELIX_DIR} /usr /usr/local
- PATH_SUFFIXES share/celix/bundles
-)
-
-#Finding bundles. If not found the <BUNDLEVAR>_BUNDLE var will be set to <BUNDLEVAR>-NOTFOUND
-find_file(CELIX_SHELL_BUNDLE shell.zip
- PATHS ${CELIX_BUNDLES_DIR}
- NO_DEFAULT_PATH
- )
-find_file(CELIX_SHELL_TUI_BUNDLE shell_tui.zip
- PATHS ${CELIX_BUNDLES_DIR}
- NO_DEFAULT_PATH
- )
-
-
-if (CELIX_DM_STATIC_LIB)
- set(CELIX_DM_INCLUDE_DIR ${CELIX_INCLUDE_DIR}/dependency_manager)
-endif()
-if (CELIX_DM_LIB)
- set(CELIX_DM_INCLUDE_DIR ${CELIX_INCLUDE_DIR}/dependency_manager)
-endif ()
-if (CELIX_DM_STATIC_CXX_LIB)
- set(CELIX_DM_CXX_STATIC_LIB ${CELIX_DM_STATIC_CXX_LIB}) #Ensure that var name from verion 2.0.0 is still valid
- set(CELIX_DM_CXX_INCLUDE_DIR ${CELIX_INCLUDE_DIR}/dependency_manager_cxx)
-endif ()
-
-include(FindPackageHandleStandardArgs)
-# handle the QUIETLY and REQUIRED arguments and set CELIX_FOUND to TRUE
-# if all listed variables are TRUE
-find_package_handle_standard_args(CELIX DEFAULT_MSG
- CELIX_FRAMEWORK_LIBRARY CELIX_UTILS_LIBRARY CELIX_DFI_LIBRARY CELIX_DM_LIB CELIX_DM_STATIC_LIB CELIX_DM_STATIC_CXX_LIB CELIX_INCLUDE_DIR CELIX_LAUNCHER CELIX_CMAKECELIX_FILE)
-mark_as_advanced(CELIX_INCLUDE_DIR CELIX_ETCD_INCLUDE_DIR CELIX_USECELIX_FILE)
-
-if(CELIX_FOUND)
- set(CELIX_LIBRARIES ${CELIX_FRAMEWORK_LIBRARY} ${CELIX_UTILS_LIBRARY} ${CELIX_DFI_LIBRARY})
- set(CELIX_INCLUDE_DIRS ${CELIX_INCLUDE_DIR} ${CELIX_ETCD_INCLUDE_DIR} ${CELIX_DM_INCLUDE_DIR} ${CELIX_DM_CXX_INCLUDE_DIR})
-
- include(${CELIX_USECELIX_FILE})
-endif()
-
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/FindCUnit.cmake
----------------------------------------------------------------------
diff --git a/cmake/FindCUnit.cmake b/cmake/FindCUnit.cmake
deleted file mode 100644
index 830f551..0000000
--- a/cmake/FindCUnit.cmake
+++ /dev/null
@@ -1,65 +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.
-
-if (NOT WIN32)
- include(FindCurses)
-endif (NOT WIN32)
-
-FIND_PATH(CUNIT_INCLUDE_DIR CUnit/Basic.h
- /usr/local/include
- /usr/include
- /opt/local/include
-)
-
-FIND_PATH(CUNIT_SHARE_DIR CUnit-List.dtd
- /usr/local/share/Cunit
- /usr/share/CUnit
- /opt/local/share/CUnit
-)
-
-# On unix system, debug and release have the same name
-FIND_LIBRARY(CUNIT_LIBRARY cunit
- ${CUNIT_INCLUDE_DIR}/../../lib
- /usr/local/lib
- /usr/lib
- )
-FIND_LIBRARY(CUNIT_DEBUG_LIBRARY cunit
- ${CUNIT_INCLUDE_DIR}/../../lib
- /usr/local/lib
- /usr/lib
- )
-
-IF(CUNIT_INCLUDE_DIR)
- IF(CUNIT_LIBRARY)
- SET(CUNIT_FOUND "YES")
- if (WIN32)
- SET(CUNIT_LIBRARIES ${CUNIT_LIBRARY})
- SET(CUNIT_DEBUG_LIBRARIES ${CUNIT_DEBUG_LIBRARY})
- else (WIN32)
- SET(CUNIT_LIBRARIES ${CUNIT_LIBRARY} ${CURSES_LIBRARY})
- SET(CUNIT_DEBUG_LIBRARIES ${CUNIT_DEBUG_LIBRARY} ${CURSES_DEBUG_LIBRARY})
- endif (WIN32)
- ENDIF(CUNIT_LIBRARY)
- IF(CUNIT_INCLUDE_DIR)
- if (WIN32)
- SET(CUNIT_INCLUDE_DIRS ${CUNIT_INCLUDE_DIR})
- else (WIN32)
- MESSAGE(STATUS "Found CUNIT: ${CUNIT_INCLUDE_DIR}")
- SET(CUNIT_INCLUDE_DIRS ${CUNIT_INCLUDE_DIR} ${CURSES_INCLUDE_DIR})
- endif (WIN32)
- ENDIF(CUNIT_INCLUDE_DIR)
-ENDIF(CUNIT_INCLUDE_DIR)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/FindCZMQ.cmake
----------------------------------------------------------------------
diff --git a/cmake/FindCZMQ.cmake b/cmake/FindCZMQ.cmake
deleted file mode 100644
index 4f4891c..0000000
--- a/cmake/FindCZMQ.cmake
+++ /dev/null
@@ -1,42 +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.
-
-
-# - Try to find CZMQ
-# Once done this will define
-# CZMQ_FOUND - System has Zmq
-# CZMQ_INCLUDE_DIRS - The Zmq include directories
-# CZMQ_LIBRARIES - The libraries needed to use Zmq
-# CZMQ_DEFINITIONS - Compiler switches required for using Zmq
-
-find_path(CZMQ_INCLUDE_DIR czmq.h
- /usr/include
- /usr/local/include )
-
-find_library(CZMQ_LIBRARY NAMES czmq
- PATHS /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64 )
-
-set(CZMQ_LIBRARIES ${CZMQ_LIBRARY} )
-set(CZMQ_INCLUDE_DIRS ${CZMQ_INCLUDE_DIR} )
-
-include(FindPackageHandleStandardArgs)
-# handle the QUIETLY and REQUIRED arguments and set CZMQ_FOUND to TRUE
-# if all listed variables are TRUE
-find_package_handle_standard_args(Czmq DEFAULT_MSG
- CZMQ_LIBRARY CZMQ_INCLUDE_DIR)
-
-mark_as_advanced(CZMQ_INCLUDE_DIR CZMQ_LIBRARY )
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/FindCppUTest.cmake
----------------------------------------------------------------------
diff --git a/cmake/FindCppUTest.cmake b/cmake/FindCppUTest.cmake
deleted file mode 100644
index 516bc52..0000000
--- a/cmake/FindCppUTest.cmake
+++ /dev/null
@@ -1,54 +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.
-
-FIND_PATH(CPPUTEST_INCLUDE_DIR NAMES CppUTest/TestHarness.h
- PATHS $ENV{CPPUTEST_DIR} ${CPPUTEST_DIR} /usr /usr/local /opt/local
- PATH_SUFFIXES include
-)
-
-FIND_PATH(CPPUTEST_EXT_INCLUDE_DIR NAMES CppUTestExt/MockSupport.h
- PATHS $ENV{CPPUTEST_DIR} ${CPPUTEST_DIR} /usr /usr/local /opt/local
- PATH_SUFFIXES include
-)
-
-FIND_LIBRARY(CPPUTEST_LIBRARY NAMES CppUTest
- PATHS $ENV{CPPUTEST_DIR} ${CPPUTEST_DIR} /usr /usr/local /opt/local
- PATH_SUFFIXES lib lib64
-)
-
-FIND_LIBRARY(CPPUTEST_EXT_LIBRARY NAMES CppUTestExt
- PATHS $ENV{CPPUTEST_DIR} ${CPPUTEST_DIR} /usr /usr/local /opt/local
- PATH_SUFFIXES lib lib64
-)
-
-# handle the QUIETLY and REQUIRED arguments and set CURL_FOUND to TRUE if
-# all listed variables are TRUE
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(CPPUTEST DEFAULT_MSG CPPUTEST_LIBRARY CPPUTEST_INCLUDE_DIR)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(CPPUTEST_EXT DEFAULT_MSG CPPUTEST_EXT_LIBRARY CPPUTEST_EXT_INCLUDE_DIR)
-
-mark_as_advanced(CPPUTEST_INCLUDE_DIR CPPUTEST_LIBRARY CPPUTEST_EXT_LIBRARY CPPUTEST_INCLUDE_DIR)
-
-IF(CPPUTEST_FOUND)
- SET(CPPUTEST_LIBRARIES ${CPPUTEST_LIBRARY})
- SET(CPPUTEST_INCLUDE_DIRS ${CPPUTEST_INCLUDE_DIR})
-ENDIF(CPPUTEST_FOUND)
-
-IF(CPPUTEST_EXT_FOUND)
- SET(CPPUTEST_EXT_LIBRARIES ${CPPUTEST_EXT_LIBRARY})
- SET(CPPUTEST_EXT_INCLUDE_DIRS ${CPPUTEST_EXT_INCLUDE_DIR})
-ENDIF(CPPUTEST_EXT_FOUND)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/FindFFI.cmake
----------------------------------------------------------------------
diff --git a/cmake/FindFFI.cmake b/cmake/FindFFI.cmake
deleted file mode 100644
index b94642d..0000000
--- a/cmake/FindFFI.cmake
+++ /dev/null
@@ -1,57 +0,0 @@
-
-# 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.
-
-
-# - Try to find libffi define the variables for the binaries/headers and include
-#
-# Once done this will define
-# FFI_FOUND - System has libffi
-# FFI_INCLUDE_DIRS - The package include directories
-# FFI_LIBRARIES - The libraries needed to use this package
-
-if (NOT WIN32)
- # try using pkg-config to get the directories and then use these values
- # in the find_path() and find_library() calls
- find_package(PkgConfig QUIET)
- PKG_CHECK_MODULES(PC_LIBFFI QUIET libffi)
-endif ()
-
-mark_as_advanced(GNUTLS_INCLUDE_DIR GNUTLS_LIBRARY)
-
-find_library(FFI_LIBRARY NAMES ffi libffi
- PATHS $ENV{FFI_DIR} ${FFI_DIR} /usr /usr/local /opt/local
- PATH_SUFFIXES lib lib64 x86_64-linux-gnu lib/x86_64-linux-gnu
- HINTS ${PC_LIBFFI_LIBDIR} ${PC_LIBFFI_LIBRARY_DIRS}
-)
-
-find_path(FFI_INCLUDE_DIR ffi.h
- PATHS $ENV{FFI_DIR} ${FFI_DIR} /usr /usr/local /opt/local
- PATH_SUFFIXES include include/ffi include/x86_64-linux-gnu x86_64-linux-gnu
- HINTS ${PC_LIBFFI_INCLUDEDIR} ${PC_LIBFFI_INCLUDE_DIRS}
-)
-
-include(FindPackageHandleStandardArgs)
-# handle the QUIETLY and REQUIRED arguments and set FFI_FOUND to TRUE
-# if all listed variables are TRUE
-find_package_handle_standard_args(FFI DEFAULT_MSG
- FFI_LIBRARY FFI_INCLUDE_DIR)
-mark_as_advanced(FFI_INCLUDE_DIR FFI_LIBRARY)
-
-if(FFI_FOUND)
- set(FFI_LIBRARIES ${FFI_LIBRARY})
- set(FFI_INCLUDE_DIRS ${FFI_INCLUDE_DIR})
-endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/FindJansson.cmake
----------------------------------------------------------------------
diff --git a/cmake/FindJansson.cmake b/cmake/FindJansson.cmake
deleted file mode 100644
index bedf8be..0000000
--- a/cmake/FindJansson.cmake
+++ /dev/null
@@ -1,42 +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.
-
-
-# - Try to find Jansson
-# Once done this will define
-# JANSSON_FOUND - System has Jansson
-# JANSSON_INCLUDE_DIRS - The Jansson include directories
-# JANSSON_LIBRARIES - The libraries needed to use Jansson
-# JANSSON_DEFINITIONS - Compiler switches required for using Jansson
-
-find_path(JANSSON_INCLUDE_DIR jansson.h
- /usr/include
- /usr/local/include )
-
-find_library(JANSSON_LIBRARY NAMES jansson
- PATHS /usr/lib /usr/local/lib )
-
-set(JANSSON_LIBRARIES ${JANSSON_LIBRARY} )
-set(JANSSON_INCLUDE_DIRS ${JANSSON_INCLUDE_DIR} )
-
-include(FindPackageHandleStandardArgs)
-# handle the QUIETLY and REQUIRED arguments and set JANSSON_FOUND to TRUE
-# if all listed variables are TRUE
-find_package_handle_standard_args(Jansson DEFAULT_MSG
- JANSSON_LIBRARY JANSSON_INCLUDE_DIR)
-
-mark_as_advanced(JANSSON_INCLUDE_DIR JANSSON_LIBRARY )
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/FindSlp.cmake
----------------------------------------------------------------------
diff --git a/cmake/FindSlp.cmake b/cmake/FindSlp.cmake
deleted file mode 100644
index 3461456..0000000
--- a/cmake/FindSlp.cmake
+++ /dev/null
@@ -1,42 +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.
-
-
-# - Try to find Slp
-# Once done this will define
-# SLP_FOUND - System has Slp
-# SLP_INCLUDE_DIRS - The Slp include directories
-# SLP_LIBRARIES - The libraries needed to use Slp
-# SLP_DEFINITIONS - Compiler switches required for using Slp
-
-find_path(SLP_INCLUDE_DIR slp.h
- /usr/include
- /usr/local/include )
-
-find_library(SLP_LIBRARY NAMES slp
- PATHS /usr/lib /usr/local/lib )
-
-set(SLP_LIBRARIES ${SLP_LIBRARY} )
-set(SLP_INCLUDE_DIRS ${SLP_INCLUDE_DIR} )
-
-include(FindPackageHandleStandardArgs)
-# handle the QUIETLY and REQUIRED arguments and set SLP_FOUND to TRUE
-# if all listed variables are TRUE
-find_package_handle_standard_args(Slp DEFAULT_MSG
- SLP_LIBRARY SLP_INCLUDE_DIR)
-
-mark_as_advanced(SLP_INCLUDE_DIR SLP_LIBRARY )
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/FindSyslog.cmake
----------------------------------------------------------------------
diff --git a/cmake/FindSyslog.cmake b/cmake/FindSyslog.cmake
deleted file mode 100644
index 769b806..0000000
--- a/cmake/FindSyslog.cmake
+++ /dev/null
@@ -1,26 +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.
-
-
-find_path(SYSLOG_INCLUDE_DIR syslog.h /usr/include)
-
-include(FindPackageHandleStandardArgs)
-
-find_package_handle_standard_args(Syslog DEFAULT_MSG
- SYSLOG_INCLUDE_DIR)
-
-mark_as_advanced(SYSLOG_INCLUDE_DIR)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/FindUUID.cmake
----------------------------------------------------------------------
diff --git a/cmake/FindUUID.cmake b/cmake/FindUUID.cmake
deleted file mode 100644
index 63bfafb..0000000
--- a/cmake/FindUUID.cmake
+++ /dev/null
@@ -1,37 +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.
-
-
-find_path(UUID_INCLUDE_DIR uuid/uuid.h
- /usr/include
- /usr/local/include )
-
-find_library(UUID_LIBRARY NAMES uuid
- PATHS /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64 /lib/i386-linux-gnu /lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu)
-
-include(FindPackageHandleStandardArgs)
-if (APPLE)
-find_package_handle_standard_args(UUID DEFAULT_MSG
- UUID_INCLUDE_DIR)
-else ()
-find_package_handle_standard_args(UUID DEFAULT_MSG
- UUID_LIBRARY UUID_INCLUDE_DIR)
-endif ()
-
-
-mark_as_advanced(UUID_INCLUDE_DIR UUID_LIBRARY)
-
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/FindZMQ.cmake
----------------------------------------------------------------------
diff --git a/cmake/FindZMQ.cmake b/cmake/FindZMQ.cmake
deleted file mode 100644
index b2c2663..0000000
--- a/cmake/FindZMQ.cmake
+++ /dev/null
@@ -1,42 +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.
-
-
-# - Try to find ZMQ
-# Once done this will define
-# ZMQ_FOUND - System has Zmq
-# ZMQ_INCLUDE_DIRS - The Zmq include directories
-# ZMQ_LIBRARIES - The libraries needed to use Zmq
-# ZMQ_DEFINITIONS - Compiler switches required for using Zmq
-
-find_path(ZMQ_INCLUDE_DIR zmq.h zmq_utils.h
- /usr/include
- /usr/local/include )
-
-find_library(ZMQ_LIBRARY NAMES zmq
- PATHS /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64 )
-
-set(ZMQ_LIBRARIES ${ZMQ_LIBRARY} )
-set(ZMQ_INCLUDE_DIRS ${ZMQ_INCLUDE_DIR} )
-
-include(FindPackageHandleStandardArgs)
-# handle the QUIETLY and REQUIRED arguments and set ZMQ_FOUND to TRUE
-# if all listed variables are TRUE
-find_package_handle_standard_args(Zmq DEFAULT_MSG
- ZMQ_LIBRARY ZMQ_INCLUDE_DIR)
-
-mark_as_advanced(ZMQ_INCLUDE_DIR ZMQ_LIBRARY )
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/Modules/FindCUnit.cmake
----------------------------------------------------------------------
diff --git a/cmake/Modules/FindCUnit.cmake b/cmake/Modules/FindCUnit.cmake
new file mode 100644
index 0000000..830f551
--- /dev/null
+++ b/cmake/Modules/FindCUnit.cmake
@@ -0,0 +1,65 @@
+# 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.
+
+if (NOT WIN32)
+ include(FindCurses)
+endif (NOT WIN32)
+
+FIND_PATH(CUNIT_INCLUDE_DIR CUnit/Basic.h
+ /usr/local/include
+ /usr/include
+ /opt/local/include
+)
+
+FIND_PATH(CUNIT_SHARE_DIR CUnit-List.dtd
+ /usr/local/share/Cunit
+ /usr/share/CUnit
+ /opt/local/share/CUnit
+)
+
+# On unix system, debug and release have the same name
+FIND_LIBRARY(CUNIT_LIBRARY cunit
+ ${CUNIT_INCLUDE_DIR}/../../lib
+ /usr/local/lib
+ /usr/lib
+ )
+FIND_LIBRARY(CUNIT_DEBUG_LIBRARY cunit
+ ${CUNIT_INCLUDE_DIR}/../../lib
+ /usr/local/lib
+ /usr/lib
+ )
+
+IF(CUNIT_INCLUDE_DIR)
+ IF(CUNIT_LIBRARY)
+ SET(CUNIT_FOUND "YES")
+ if (WIN32)
+ SET(CUNIT_LIBRARIES ${CUNIT_LIBRARY})
+ SET(CUNIT_DEBUG_LIBRARIES ${CUNIT_DEBUG_LIBRARY})
+ else (WIN32)
+ SET(CUNIT_LIBRARIES ${CUNIT_LIBRARY} ${CURSES_LIBRARY})
+ SET(CUNIT_DEBUG_LIBRARIES ${CUNIT_DEBUG_LIBRARY} ${CURSES_DEBUG_LIBRARY})
+ endif (WIN32)
+ ENDIF(CUNIT_LIBRARY)
+ IF(CUNIT_INCLUDE_DIR)
+ if (WIN32)
+ SET(CUNIT_INCLUDE_DIRS ${CUNIT_INCLUDE_DIR})
+ else (WIN32)
+ MESSAGE(STATUS "Found CUNIT: ${CUNIT_INCLUDE_DIR}")
+ SET(CUNIT_INCLUDE_DIRS ${CUNIT_INCLUDE_DIR} ${CURSES_INCLUDE_DIR})
+ endif (WIN32)
+ ENDIF(CUNIT_INCLUDE_DIR)
+ENDIF(CUNIT_INCLUDE_DIR)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/Modules/FindCZMQ.cmake
----------------------------------------------------------------------
diff --git a/cmake/Modules/FindCZMQ.cmake b/cmake/Modules/FindCZMQ.cmake
new file mode 100644
index 0000000..4f4891c
--- /dev/null
+++ b/cmake/Modules/FindCZMQ.cmake
@@ -0,0 +1,42 @@
+# 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.
+
+
+# - Try to find CZMQ
+# Once done this will define
+# CZMQ_FOUND - System has Zmq
+# CZMQ_INCLUDE_DIRS - The Zmq include directories
+# CZMQ_LIBRARIES - The libraries needed to use Zmq
+# CZMQ_DEFINITIONS - Compiler switches required for using Zmq
+
+find_path(CZMQ_INCLUDE_DIR czmq.h
+ /usr/include
+ /usr/local/include )
+
+find_library(CZMQ_LIBRARY NAMES czmq
+ PATHS /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64 )
+
+set(CZMQ_LIBRARIES ${CZMQ_LIBRARY} )
+set(CZMQ_INCLUDE_DIRS ${CZMQ_INCLUDE_DIR} )
+
+include(FindPackageHandleStandardArgs)
+# handle the QUIETLY and REQUIRED arguments and set CZMQ_FOUND to TRUE
+# if all listed variables are TRUE
+find_package_handle_standard_args(Czmq DEFAULT_MSG
+ CZMQ_LIBRARY CZMQ_INCLUDE_DIR)
+
+mark_as_advanced(CZMQ_INCLUDE_DIR CZMQ_LIBRARY )
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/Modules/FindCppUTest.cmake
----------------------------------------------------------------------
diff --git a/cmake/Modules/FindCppUTest.cmake b/cmake/Modules/FindCppUTest.cmake
new file mode 100644
index 0000000..516bc52
--- /dev/null
+++ b/cmake/Modules/FindCppUTest.cmake
@@ -0,0 +1,54 @@
+# 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.
+
+FIND_PATH(CPPUTEST_INCLUDE_DIR NAMES CppUTest/TestHarness.h
+ PATHS $ENV{CPPUTEST_DIR} ${CPPUTEST_DIR} /usr /usr/local /opt/local
+ PATH_SUFFIXES include
+)
+
+FIND_PATH(CPPUTEST_EXT_INCLUDE_DIR NAMES CppUTestExt/MockSupport.h
+ PATHS $ENV{CPPUTEST_DIR} ${CPPUTEST_DIR} /usr /usr/local /opt/local
+ PATH_SUFFIXES include
+)
+
+FIND_LIBRARY(CPPUTEST_LIBRARY NAMES CppUTest
+ PATHS $ENV{CPPUTEST_DIR} ${CPPUTEST_DIR} /usr /usr/local /opt/local
+ PATH_SUFFIXES lib lib64
+)
+
+FIND_LIBRARY(CPPUTEST_EXT_LIBRARY NAMES CppUTestExt
+ PATHS $ENV{CPPUTEST_DIR} ${CPPUTEST_DIR} /usr /usr/local /opt/local
+ PATH_SUFFIXES lib lib64
+)
+
+# handle the QUIETLY and REQUIRED arguments and set CURL_FOUND to TRUE if
+# all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(CPPUTEST DEFAULT_MSG CPPUTEST_LIBRARY CPPUTEST_INCLUDE_DIR)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(CPPUTEST_EXT DEFAULT_MSG CPPUTEST_EXT_LIBRARY CPPUTEST_EXT_INCLUDE_DIR)
+
+mark_as_advanced(CPPUTEST_INCLUDE_DIR CPPUTEST_LIBRARY CPPUTEST_EXT_LIBRARY CPPUTEST_INCLUDE_DIR)
+
+IF(CPPUTEST_FOUND)
+ SET(CPPUTEST_LIBRARIES ${CPPUTEST_LIBRARY})
+ SET(CPPUTEST_INCLUDE_DIRS ${CPPUTEST_INCLUDE_DIR})
+ENDIF(CPPUTEST_FOUND)
+
+IF(CPPUTEST_EXT_FOUND)
+ SET(CPPUTEST_EXT_LIBRARIES ${CPPUTEST_EXT_LIBRARY})
+ SET(CPPUTEST_EXT_INCLUDE_DIRS ${CPPUTEST_EXT_INCLUDE_DIR})
+ENDIF(CPPUTEST_EXT_FOUND)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/Modules/FindFFI.cmake
----------------------------------------------------------------------
diff --git a/cmake/Modules/FindFFI.cmake b/cmake/Modules/FindFFI.cmake
new file mode 100644
index 0000000..b94642d
--- /dev/null
+++ b/cmake/Modules/FindFFI.cmake
@@ -0,0 +1,57 @@
+
+# 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.
+
+
+# - Try to find libffi define the variables for the binaries/headers and include
+#
+# Once done this will define
+# FFI_FOUND - System has libffi
+# FFI_INCLUDE_DIRS - The package include directories
+# FFI_LIBRARIES - The libraries needed to use this package
+
+if (NOT WIN32)
+ # try using pkg-config to get the directories and then use these values
+ # in the find_path() and find_library() calls
+ find_package(PkgConfig QUIET)
+ PKG_CHECK_MODULES(PC_LIBFFI QUIET libffi)
+endif ()
+
+mark_as_advanced(GNUTLS_INCLUDE_DIR GNUTLS_LIBRARY)
+
+find_library(FFI_LIBRARY NAMES ffi libffi
+ PATHS $ENV{FFI_DIR} ${FFI_DIR} /usr /usr/local /opt/local
+ PATH_SUFFIXES lib lib64 x86_64-linux-gnu lib/x86_64-linux-gnu
+ HINTS ${PC_LIBFFI_LIBDIR} ${PC_LIBFFI_LIBRARY_DIRS}
+)
+
+find_path(FFI_INCLUDE_DIR ffi.h
+ PATHS $ENV{FFI_DIR} ${FFI_DIR} /usr /usr/local /opt/local
+ PATH_SUFFIXES include include/ffi include/x86_64-linux-gnu x86_64-linux-gnu
+ HINTS ${PC_LIBFFI_INCLUDEDIR} ${PC_LIBFFI_INCLUDE_DIRS}
+)
+
+include(FindPackageHandleStandardArgs)
+# handle the QUIETLY and REQUIRED arguments and set FFI_FOUND to TRUE
+# if all listed variables are TRUE
+find_package_handle_standard_args(FFI DEFAULT_MSG
+ FFI_LIBRARY FFI_INCLUDE_DIR)
+mark_as_advanced(FFI_INCLUDE_DIR FFI_LIBRARY)
+
+if(FFI_FOUND)
+ set(FFI_LIBRARIES ${FFI_LIBRARY})
+ set(FFI_INCLUDE_DIRS ${FFI_INCLUDE_DIR})
+endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/Modules/FindJansson.cmake
----------------------------------------------------------------------
diff --git a/cmake/Modules/FindJansson.cmake b/cmake/Modules/FindJansson.cmake
new file mode 100644
index 0000000..bedf8be
--- /dev/null
+++ b/cmake/Modules/FindJansson.cmake
@@ -0,0 +1,42 @@
+# 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.
+
+
+# - Try to find Jansson
+# Once done this will define
+# JANSSON_FOUND - System has Jansson
+# JANSSON_INCLUDE_DIRS - The Jansson include directories
+# JANSSON_LIBRARIES - The libraries needed to use Jansson
+# JANSSON_DEFINITIONS - Compiler switches required for using Jansson
+
+find_path(JANSSON_INCLUDE_DIR jansson.h
+ /usr/include
+ /usr/local/include )
+
+find_library(JANSSON_LIBRARY NAMES jansson
+ PATHS /usr/lib /usr/local/lib )
+
+set(JANSSON_LIBRARIES ${JANSSON_LIBRARY} )
+set(JANSSON_INCLUDE_DIRS ${JANSSON_INCLUDE_DIR} )
+
+include(FindPackageHandleStandardArgs)
+# handle the QUIETLY and REQUIRED arguments and set JANSSON_FOUND to TRUE
+# if all listed variables are TRUE
+find_package_handle_standard_args(Jansson DEFAULT_MSG
+ JANSSON_LIBRARY JANSSON_INCLUDE_DIR)
+
+mark_as_advanced(JANSSON_INCLUDE_DIR JANSSON_LIBRARY )
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/Modules/FindSlp.cmake
----------------------------------------------------------------------
diff --git a/cmake/Modules/FindSlp.cmake b/cmake/Modules/FindSlp.cmake
new file mode 100644
index 0000000..3461456
--- /dev/null
+++ b/cmake/Modules/FindSlp.cmake
@@ -0,0 +1,42 @@
+# 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.
+
+
+# - Try to find Slp
+# Once done this will define
+# SLP_FOUND - System has Slp
+# SLP_INCLUDE_DIRS - The Slp include directories
+# SLP_LIBRARIES - The libraries needed to use Slp
+# SLP_DEFINITIONS - Compiler switches required for using Slp
+
+find_path(SLP_INCLUDE_DIR slp.h
+ /usr/include
+ /usr/local/include )
+
+find_library(SLP_LIBRARY NAMES slp
+ PATHS /usr/lib /usr/local/lib )
+
+set(SLP_LIBRARIES ${SLP_LIBRARY} )
+set(SLP_INCLUDE_DIRS ${SLP_INCLUDE_DIR} )
+
+include(FindPackageHandleStandardArgs)
+# handle the QUIETLY and REQUIRED arguments and set SLP_FOUND to TRUE
+# if all listed variables are TRUE
+find_package_handle_standard_args(Slp DEFAULT_MSG
+ SLP_LIBRARY SLP_INCLUDE_DIR)
+
+mark_as_advanced(SLP_INCLUDE_DIR SLP_LIBRARY )
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/Modules/FindSyslog.cmake
----------------------------------------------------------------------
diff --git a/cmake/Modules/FindSyslog.cmake b/cmake/Modules/FindSyslog.cmake
new file mode 100644
index 0000000..769b806
--- /dev/null
+++ b/cmake/Modules/FindSyslog.cmake
@@ -0,0 +1,26 @@
+# 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.
+
+
+find_path(SYSLOG_INCLUDE_DIR syslog.h /usr/include)
+
+include(FindPackageHandleStandardArgs)
+
+find_package_handle_standard_args(Syslog DEFAULT_MSG
+ SYSLOG_INCLUDE_DIR)
+
+mark_as_advanced(SYSLOG_INCLUDE_DIR)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/Modules/FindUUID.cmake
----------------------------------------------------------------------
diff --git a/cmake/Modules/FindUUID.cmake b/cmake/Modules/FindUUID.cmake
new file mode 100644
index 0000000..63bfafb
--- /dev/null
+++ b/cmake/Modules/FindUUID.cmake
@@ -0,0 +1,37 @@
+# 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.
+
+
+find_path(UUID_INCLUDE_DIR uuid/uuid.h
+ /usr/include
+ /usr/local/include )
+
+find_library(UUID_LIBRARY NAMES uuid
+ PATHS /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64 /lib/i386-linux-gnu /lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu)
+
+include(FindPackageHandleStandardArgs)
+if (APPLE)
+find_package_handle_standard_args(UUID DEFAULT_MSG
+ UUID_INCLUDE_DIR)
+else ()
+find_package_handle_standard_args(UUID DEFAULT_MSG
+ UUID_LIBRARY UUID_INCLUDE_DIR)
+endif ()
+
+
+mark_as_advanced(UUID_INCLUDE_DIR UUID_LIBRARY)
+
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/Modules/FindZMQ.cmake
----------------------------------------------------------------------
diff --git a/cmake/Modules/FindZMQ.cmake b/cmake/Modules/FindZMQ.cmake
new file mode 100644
index 0000000..b2c2663
--- /dev/null
+++ b/cmake/Modules/FindZMQ.cmake
@@ -0,0 +1,42 @@
+# 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.
+
+
+# - Try to find ZMQ
+# Once done this will define
+# ZMQ_FOUND - System has Zmq
+# ZMQ_INCLUDE_DIRS - The Zmq include directories
+# ZMQ_LIBRARIES - The libraries needed to use Zmq
+# ZMQ_DEFINITIONS - Compiler switches required for using Zmq
+
+find_path(ZMQ_INCLUDE_DIR zmq.h zmq_utils.h
+ /usr/include
+ /usr/local/include )
+
+find_library(ZMQ_LIBRARY NAMES zmq
+ PATHS /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64 )
+
+set(ZMQ_LIBRARIES ${ZMQ_LIBRARY} )
+set(ZMQ_INCLUDE_DIRS ${ZMQ_INCLUDE_DIR} )
+
+include(FindPackageHandleStandardArgs)
+# handle the QUIETLY and REQUIRED arguments and set ZMQ_FOUND to TRUE
+# if all listed variables are TRUE
+find_package_handle_standard_args(Zmq DEFAULT_MSG
+ ZMQ_LIBRARY ZMQ_INCLUDE_DIR)
+
+mark_as_advanced(ZMQ_INCLUDE_DIR ZMQ_LIBRARY )
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/UseDoxygen.cmake
----------------------------------------------------------------------
diff --git a/cmake/UseDoxygen.cmake b/cmake/UseDoxygen.cmake
deleted file mode 100644
index 376dbe2..0000000
--- a/cmake/UseDoxygen.cmake
+++ /dev/null
@@ -1,170 +0,0 @@
-# Redistribution and use is allowed according to the terms of the New
-# BSD license:
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# 1. Redistributions of source code must retain the copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. The name of the author may not be used to endorse or promote products
-# derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-# - Run Doxygen
-#
-# Adds a doxygen target that runs doxygen to generate the html
-# and optionally the LaTeX API documentation.
-# The doxygen target is added to the doc target as a dependency.
-# i.e.: the API documentation is built with:
-# make doc
-#
-# USAGE: GLOBAL INSTALL
-#
-# Install it with:
-# cmake ./ && sudo make install
-# Add the following to the CMakeLists.txt of your project:
-# include(UseDoxygen OPTIONAL)
-# Optionally copy Doxyfile.in in the directory of CMakeLists.txt and edit it.
-#
-# USAGE: INCLUDE IN PROJECT
-#
-# set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
-# include(UseDoxygen)
-# Add the Doxyfile.in and UseDoxygen.cmake files to the projects source directory.
-#
-#
-# CONFIGURATION
-#
-# To configure Doxygen you can edit Doxyfile.in and set some variables in cmake.
-# Variables you may define are:
-# DOXYFILE_SOURCE_DIR - Path where the Doxygen input files are.
-# Defaults to the current source directory.
-# DOXYFILE_EXTRA_SOURCES - Additional source diretories/files for Doxygen to scan.
-# The Paths should be in double quotes and separated by space. e.g.:
-# "${CMAKE_CURRENT_BINARY_DIR}/foo.c" "${CMAKE_CURRENT_BINARY_DIR}/bar/"
-#
-# DOXYFILE_OUTPUT_DIR - Path where the Doxygen output is stored.
-# Defaults to "${CMAKE_CURRENT_BINARY_DIR}/doc".
-#
-# DOXYFILE_LATEX - ON/OFF; Set to "ON" if you want the LaTeX documentation
-# to be built.
-# DOXYFILE_LATEX_DIR - Directory relative to DOXYFILE_OUTPUT_DIR where
-# the Doxygen LaTeX output is stored. Defaults to "latex".
-#
-# DOXYFILE_HTML_DIR - Directory relative to DOXYFILE_OUTPUT_DIR where
-# the Doxygen html output is stored. Defaults to "html".
-#
-
-#
-# Copyright (c) 2009, 2010, 2011 Tobias Rautenkranz <to...@rautenkranz.ch>
-#
-# Redistribution and use is allowed according to the terms of the New
-# BSD license.
-#
-
-macro(usedoxygen_set_default name value type docstring)
- if(NOT DEFINED "${name}")
- set("${name}" "${value}" CACHE "${type}" "${docstring}")
- endif()
-endmacro()
-
-find_package(Doxygen)
-
-if(DOXYGEN_FOUND)
- find_file(DOXYFILE_IN "Doxyfile.in"
- PATHS "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_ROOT}/Modules/"
- NO_DEFAULT_PATH
- DOC "Path to the doxygen configuration template file")
- set(DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
- include(FindPackageHandleStandardArgs)
- find_package_handle_standard_args(DOXYFILE_IN DEFAULT_MSG "DOXYFILE_IN")
-endif()
-
-if(DOXYGEN_FOUND AND DOXYFILE_IN_FOUND)
- usedoxygen_set_default(DOXYFILE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/doc"
- PATH "Doxygen output directory")
- usedoxygen_set_default(DOXYFILE_HTML_DIR "html"
- STRING "Doxygen HTML output directory")
- usedoxygen_set_default(DOXYFILE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
- PATH "Input files source directory")
- usedoxygen_set_default(DOXYFILE_EXTRA_SOURCE_DIRS ""
- STRING "Additional source files/directories separated by space")
- set(DOXYFILE_SOURE_DIRS "\"${DOXYFILE_SOURCE_DIR}\" ${DOXYFILE_EXTRA_SOURCES}")
-
- usedoxygen_set_default(DOXYFILE_LATEX YES BOOL "Generate LaTeX API documentation" OFF)
- usedoxygen_set_default(DOXYFILE_LATEX_DIR "latex" STRING "LaTex output directory")
-
- mark_as_advanced(DOXYFILE_OUTPUT_DIR DOXYFILE_HTML_DIR DOXYFILE_LATEX_DIR
- DOXYFILE_SOURCE_DIR DOXYFILE_EXTRA_SOURCE_DIRS DOXYFILE_IN)
-
-
- set_property(DIRECTORY
- APPEND PROPERTY
- ADDITIONAL_MAKE_CLEAN_FILES
- "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_HTML_DIR}")
-
- add_custom_target(doxygen
- COMMAND "${DOXYGEN_EXECUTABLE}"
- "${DOXYFILE}"
- COMMENT "Writing documentation to ${DOXYFILE_OUTPUT_DIR}..."
- WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
-
- ## LaTeX
- set(DOXYFILE_PDFLATEX "NO")
- set(DOXYFILE_DOT "NO")
-
- set_property(DIRECTORY APPEND PROPERTY
- ADDITIONAL_MAKE_CLEAN_FILES
- "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}")
-
- if(DOXYFILE_LATEX STREQUAL "ON")
- set(DOXYFILE_GENERATE_LATEX "YES")
- find_package(LATEX)
- find_program(DOXYFILE_MAKE make)
- mark_as_advanced(DOXYFILE_MAKE)
- if(LATEX_COMPILER AND MAKEINDEX_COMPILER AND DOXYFILE_MAKE)
- if(PDFLATEX_COMPILER)
- set(DOXYFILE_PDFLATEX "YES")
- endif()
- if(DOXYGEN_DOT_EXECUTABLE)
- set(DOXYFILE_DOT "YES")
- endif()
-
- add_custom_command(TARGET doxygen
- POST_BUILD
- COMMAND "${DOXYFILE_MAKE}"
- COMMENT "Running LaTeX for Doxygen documentation in ${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}..."
- WORKING_DIRECTORY "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}")
- else()
- set(DOXYGEN_LATEX "NO")
- endif()
- else()
- set(DOXYFILE_GENERATE_LATEX "NO")
- endif()
-
-
- configure_file("${DOXYFILE_IN}" "${DOXYFILE}" @ONLY)
-
- if(TARGET doc)
- get_target_property(DOC_TARGET doc TYPE)
- endif()
- if(NOT DOC_TARGET)
- add_custom_target(doc)
- endif()
-
- add_dependencies(doc doxygen)
-endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/celix_project/ApacheRat.cmake
----------------------------------------------------------------------
diff --git a/cmake/celix_project/ApacheRat.cmake b/cmake/celix_project/ApacheRat.cmake
new file mode 100644
index 0000000..f35cab7
--- /dev/null
+++ b/cmake/celix_project/ApacheRat.cmake
@@ -0,0 +1,30 @@
+# 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.
+
+find_package(Java COMPONENTS Runtime)
+
+if(Java_Runtime_FOUND)
+ set(APACHE_RAT "NOT_FOUND" CACHE FILEPATH "Full path to the Apache RAT JAR file")
+
+ add_custom_target(rat
+ COMMAND ${Java_JAVA_EXECUTABLE} -jar ${APACHE_RAT} -E rat-excludes.txt -d .
+
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ )
+else(Java_Runtime_FOUND)
+ MESSAGE(STATUS "Java not found, cannot execute Apache RAT checks")
+endif(Java_Runtime_FOUND)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/celix_project/CelixProject.cmake
----------------------------------------------------------------------
diff --git a/cmake/celix_project/CelixProject.cmake b/cmake/celix_project/CelixProject.cmake
new file mode 100644
index 0000000..490c359
--- /dev/null
+++ b/cmake/celix_project/CelixProject.cmake
@@ -0,0 +1,80 @@
+# 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.
+
+option(ENABLE_ADDRESS_SANITIZER "Enabled building with address sanitizer. Note for gcc libasan must be installed" OFF)
+
+if (ENABLE_ADDRESS_SANITIZER)
+ set(CMAKE_C_FLAGS "-lasan -fsanitize=address ${CMAKE_C_FLAGS}")
+ set(CMAKE_CXX_FLAGS "-lasan -fsanitize=address ${CMAKE_CXX_FLAGS}")
+endif()
+
+
+MACRO(celix_subproject)
+ set(ARGS "${ARGN}")
+
+ list(GET ARGS 0 OPTION_NAME)
+ list(REMOVE_AT ARGS 0)
+
+ list(GET ARGS 0 OPTION_DESCRIPTION)
+ list(REMOVE_AT ARGS 0)
+
+ list(GET ARGS 0 OPTION_DEFAULT)
+ list(REMOVE_AT ARGS 0)
+
+ set(OPTIONS )
+ set(ONE_VAL_ARGS )
+ set(MULTI_VAL_ARGS DEPS)
+ cmake_parse_arguments(OPTION "${OPTIONS}" "${ONE_VAL_ARGS}" "${MULTI_VAL_ARGS}" ${ARGS})
+
+ string(TOUPPER ${OPTION_NAME} UC_OPTION_NAME)
+ set(NAME "BUILD_${UC_OPTION_NAME}")
+
+ option(${NAME} "${OPTION_DESCRIPTION}" ${OPTION_DEFAULT})
+
+ get_property(BUILD GLOBAL PROPERTY ${NAME}_INTERNAL)
+ if (NOT DEFINED BUILD)
+ set(BUILD "OFF")
+ endif (NOT DEFINED BUILD)
+
+ IF (${NAME} OR ${BUILD})
+ set(${OPTION_NAME} "ON")
+ set_property(GLOBAL PROPERTY ${NAME}_INTERNAL "ON")
+
+ FOREACH (DEP ${OPTION_DEPS})
+ string(TOUPPER ${DEP} UC_DEP)
+ set(DEP_NAME "BUILD_${UC_DEP}")
+ set_property(GLOBAL PROPERTY ${DEP_NAME}_INTERNAL "ON")
+ ENDFOREACH (DEP)
+ ELSE (${NAME} OR ${BUILD})
+ set(${OPTION_NAME} "OFF")
+ ENDIF (${NAME} OR ${BUILD})
+ENDMACRO(celix_subproject)
+
+MACRO(is_enabled name)
+ string(TOUPPER "BUILD_${name}_INTERNAL" OPTION)
+
+ get_property(BUILD GLOBAL PROPERTY ${OPTION})
+
+ if(BUILD)
+ set(${name} "ON")
+ else()
+ set(${name} "OFF")
+ endif()
+ENDMACRO(is_enabled)
+
+include(${CMAKE_CURRENT_LIST_DIR}/ApacheRat.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/CodeCoverage.cmake)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/celix_project/CodeCoverage.cmake
----------------------------------------------------------------------
diff --git a/cmake/celix_project/CodeCoverage.cmake b/cmake/celix_project/CodeCoverage.cmake
new file mode 100644
index 0000000..51b5001
--- /dev/null
+++ b/cmake/celix_project/CodeCoverage.cmake
@@ -0,0 +1,126 @@
+# Boost Software License - Version 1.0 - August 17th, 2003
+#
+# Permission is hereby granted, free of charge, to any person or organization
+# obtaining a copy of the software and accompanying documentation covered by
+# this license (the "Software") to use, reproduce, display, distribute,
+# execute, and transmit the Software, and to prepare derivative works of the
+# Software, and to permit third-parties to whom the Software is furnished to
+# do so, all subject to the following:
+#
+# The copyright notices in the Software and this entire statement, including
+# the above license grant, this restriction and the following disclaimer,
+# must be included in all copies of the Software, in whole or in part, and
+# all derivative works of the Software, unless such copies or derivative
+# works are solely in the form of machine-executable object code generated by
+# a source language processor.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+# SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+# FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+# - Enable Code Coverage
+#
+# 2012-01-31, Lars Bilke
+#
+# USAGE:
+# 1. Copy this file into your cmake modules path
+# 2. Add the following line to your CMakeLists.txt:
+# INCLUDE(CodeCoverage)
+#
+# 3. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target
+# which runs your test executable and produces a lcov code coverage report.
+#
+
+# - Changes made by Celix
+# 1. Added compiler options using --coverage instead of GCC specific strings
+# 2. Added custom target to generate HTML pages for combined coverage results
+# 3. Added each coverage target to the overall "coverage" target
+# 4. Added "mock" to exclude list for coverage results
+# 5. Removed HTML generation from the coverage setup function
+# 6. Removed unneeded Cobertura function
+#
+
+# Option to enable/disable coverage
+option(ENABLE_CODE_COVERAGE "Enables code coverage" FALSE)
+
+# Check if coverage is enabled
+IF(ENABLE_CODE_COVERAGE)
+
+ # Check prereqs
+ FIND_PROGRAM( GCOV_PATH gcov )
+ FIND_PROGRAM( LCOV_PATH lcov )
+ FIND_PROGRAM( GENHTML_PATH genhtml )
+ FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests)
+
+ IF(NOT GCOV_PATH)
+ MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
+ ENDIF() # NOT GCOV_PATH
+
+ #IF(NOT CMAKE_COMPILER_IS_GNUCXX)
+ # MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
+ #ENDIF() # NOT CMAKE_COMPILER_IS_GNUCXX
+
+ IF ( NOT CMAKE_BUILD_TYPE STREQUAL "Debug" )
+ MESSAGE( WARNING "Code coverage results with an optimised (non-Debug) build may be misleading" )
+ ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
+
+ # Setup compiler options
+ ADD_DEFINITIONS(--coverage)
+ set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
+ set(CMAKE_EXE_LINKER_FLAGS "--coverage")
+
+ IF(NOT TARGET coverage)
+ add_custom_target(coverage
+ COMMAND ${CMAKE_COMMAND} -E make_directory coverage_results
+ COMMAND ${GENHTML_PATH} -o coverage_results coverage/*/*.info.cleaned
+
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ COMMENT "Generating report.\nOpen ./${_outputname}/index.html in your browser to view the coverage report."
+ )
+
+ SET_TARGET_PROPERTIES(coverage PROPERTIES COVERAGE_TARGET_ADDED "")
+ ENDIF()
+
+ENDIF(ENABLE_CODE_COVERAGE)
+
+# Param _targetname The name of new the custom make target
+# Param _testrunner The name of the target which runs the tests
+# Param _outputname lcov output is generated as _outputname.info
+# HTML report is generated in _outputname/index.html
+# Optional fourth parameter is passed as arguments to _testrunner
+# Pass them in list form, e.g.: "-j;2" for -j 2
+FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
+ IF(ENABLE_CODE_COVERAGE)
+ IF(NOT LCOV_PATH)
+ MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
+ ENDIF() # NOT LCOV_PATH
+
+ IF(NOT GENHTML_PATH)
+ MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
+ ENDIF() # NOT GENHTML_PATH
+
+ # Setup target
+ ADD_CUSTOM_TARGET(${_targetname}_coverage
+
+ # Cleanup lcov
+ ${LCOV_PATH} --directory . --zerocounters
+
+ # Run tests
+ COMMAND ${_testrunner} ${ARGV3}
+
+ # Capturing lcov counters and generating report
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/coverage
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/coverage/${_testrunner}
+ COMMAND ${LCOV_PATH} --directory . --capture --output-file ${_outputname}.info
+ COMMAND ${LCOV_PATH} --remove ${_outputname}.info 'mock/*' 'test/*' '/usr/*' --output-file ${_outputname}.info.cleaned
+
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
+ )
+ ADD_DEPENDENCIES(coverage ${_targetname}_coverage)
+ ENDIF(ENABLE_CODE_COVERAGE)
+ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/cmake_celix/ApacheRat.cmake
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/ApacheRat.cmake b/cmake/cmake_celix/ApacheRat.cmake
deleted file mode 100644
index f35cab7..0000000
--- a/cmake/cmake_celix/ApacheRat.cmake
+++ /dev/null
@@ -1,30 +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.
-
-find_package(Java COMPONENTS Runtime)
-
-if(Java_Runtime_FOUND)
- set(APACHE_RAT "NOT_FOUND" CACHE FILEPATH "Full path to the Apache RAT JAR file")
-
- add_custom_target(rat
- COMMAND ${Java_JAVA_EXECUTABLE} -jar ${APACHE_RAT} -E rat-excludes.txt -d .
-
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
- )
-else(Java_Runtime_FOUND)
- MESSAGE(STATUS "Java not found, cannot execute Apache RAT checks")
-endif(Java_Runtime_FOUND)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/cmake_celix/BuildOptions.cmake
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/BuildOptions.cmake b/cmake/cmake_celix/BuildOptions.cmake
deleted file mode 100644
index 7420cd0..0000000
--- a/cmake/cmake_celix/BuildOptions.cmake
+++ /dev/null
@@ -1,24 +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.
-
-
-option(ENABLE_ADDRESS_SANITIZER "Enabled building with address sanitizer. Note for gcc libasan must be installed" OFF)
-
-if (ENABLE_ADDRESS_SANITIZER)
- set(CMAKE_C_FLAGS "-lasan -fsanitize=address ${CMAKE_C_FLAGS}")
- set(CMAKE_CXX_FLAGS "-lasan -fsanitize=address ${CMAKE_CXX_FLAGS}")
-endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/cmake_celix/BundlePackaging.cmake
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/BundlePackaging.cmake b/cmake/cmake_celix/BundlePackaging.cmake
index 44e7382..1196912 100644
--- a/cmake/cmake_celix/BundlePackaging.cmake
+++ b/cmake/cmake_celix/BundlePackaging.cmake
@@ -168,7 +168,7 @@ function(add_celix_bundle)
##### MANIFEST configuration and generation ##################
#Step1 configure the file so that the target name is present in in the template
- configure_file(${CELIX_CMAKE_DIRECTORY}/cmake_celix/Manifest.template.in ${BUNDLE_GEN_DIR}/MANIFEST.step1)
+ configure_file(${CELIX_CMAKE_DIRECTORY}/Manifest.template.in ${BUNDLE_GEN_DIR}/MANIFEST.step1)
#Step2 replace headers with target property values. Note this is done build time
file(GENERATE
@@ -222,7 +222,8 @@ function(add_celix_bundle)
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_IS_BUNDLE_TARGET" TRUE) #indicate that this is a bundle target
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_DEPEND_TARGETS" "") #bundle target dependencies. Note can be extended after the add_bundle call
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_GEN_DIR" ${BUNDLE_GEN_DIR}) #location for generated output.
- set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_CREATE_BUNDLE_TARGET" ${BUNDLE_TARGET_NAME}_bundle)
+ set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_CREATE_BUNDLE_TARGET" ${BUNDLE_TARGET_NAME}_bundle) #target which creat the bundle zip
+ set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_IMPORTED" FALSE) #whethet target is a imported (bundle) target
#bundle specific
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_CONTENT_DIR" ${BUNDLE_CONTENT_DIR}) #location where the content to be jar/zipped.
@@ -482,7 +483,7 @@ function(install_celix_bundle)
list(REMOVE_AT ARGN 0)
set(OPTIONS )
- set(ONE_VAL_ARGS PROJECT_NAME BUNDLE_NAME)
+ set(ONE_VAL_ARGS PROJECT_NAME BUNDLE_NAME EXPORT)
set(MULTI_VAL_ARGS HEADERS RESOURCES)
cmake_parse_arguments(INSTALL "${OPTIONS}" "${ONE_VAL_ARGS}" "${MULTI_VAL_ARGS}" ${ARGN})
@@ -494,6 +495,23 @@ function(install_celix_bundle)
endif()
install(FILES "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILE>" DESTINATION share/${INSTALL_PROJECT_NAME}/bundles COMPONENT ${BUNDLE})
+
+ if (INSTALL_EXPORT)
+ get_target_property(CURRENT_EXPORT_BUNDLES celix-bundles EXPORT_${INSTALL_EXPORT}_BUNDLES)
+
+ if (NOT CURRENT_EXPORT_BUNDLES)
+ set(CURRENT_EXPORT_BUNDLES ${BUNDLE})
+ else ()
+ list(APPEND CURRENT_EXPORT_BUNDLES ${BUNDLE})
+ endif ()
+
+ list(REMOVE_DUPLICATES CURRENT_EXPORT_BUNDLES)
+
+ set_target_properties(celix-bundles PROPERTIES
+ EXPORT_${INSTALL_EXPORT}_BUNDLES "${CURRENT_EXPORT_BUNDLES}"
+ )
+ endif ()
+
if(INSTALL_HEADERS)
install (FILES ${INSTALL_HEADERS} DESTINATION include/${INSTALL_PROJECT_NAME}/${INSTALL_BUNDLE_NAME} COMPONENT ${BUNDLE})
endif()
@@ -502,3 +520,72 @@ function(install_celix_bundle)
endif()
endfunction()
+
+function(install_celix_bundle_targets)
+ #0 is the export name
+ list(GET ARGN 0 EXPORT_NAME)
+ list(REMOVE_AT ARGN 0)
+
+ set(OPTIONS )
+ set(ONE_VAL_ARGS NAMESPACE DESTINATION FILE COMPONENT PROJECT_NAME)
+ set(MULTI_VAL_ARGS )
+ cmake_parse_arguments(EXPORT "${OPTIONS}" "${ONE_VAL_ARGS}" "${MULTI_VAL_ARGS}" ${ARGN})
+
+ get_target_property(EXPORT_BUNDLES celix-bundles EXPORT_${EXPORT_NAME}_BUNDLES)
+
+ if (NOT EXPORT_BUNDLES)
+ message(FATAL_ERROR "Export ${EXPORT_NAME} not defined. Did you forgot to use a install_celix_bundle with the 'EXPORT ${EXPORT_NAME}' option?")
+ endif ()
+
+ if (NOT EXPORT_FILE)
+ set(EXPORT_FILE ${EXPORT_NAME}BundleTargets.cmake)
+ endif ()
+ if (NOT EXPORT_PROJECT_NAME)
+ string(TOLOWER ${PROJECT_NAME} EXPORT_PROJECT_NAME)
+ endif()
+ if (NOT EXPORT_DESTINATION)
+ set(EXPORT_DESTINATION share/${EXPORT_PROJECT_NAME}/cmake)
+ endif ()
+ if (EXPORT_COMPONENT)
+ set(CMP_OPT "COMPONENT ${EXPORT_COMPONENT}")
+ endif ()
+
+ #extract number of .. needed ot reach install prefix (e.g. howto calculte _IMPORT_PREFIX
+ file(TO_CMAKE_PATH ${EXPORT_DESTINATION} DEST_PATH)
+ string(REGEX MATCHALL "/" SLASH_MATCHES ${DEST_PATH})
+ list(LENGTH SLASH_MATCHES NR_OF_SUB_DIRS)
+
+ set(CONF_IN_FILE "${CMAKE_BINARY_DIR}/celix/gen/${EXPORT_NAME}-ImportedBundleTargets.cmake.in")
+ set(CONF_FILE "${CMAKE_BINARY_DIR}/celix/gen/${EXPORT_NAME}-ImportedBundleTargets.cmake")
+ file(REMOVE "${CONF_IN_FILE}")
+
+
+ file(APPEND "${CONF_IN_FILE}" "# Compute the installation prefix relative to this file.
+get_filename_component(_IMPORT_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)
+")
+ foreach(_VAR RANGE ${NR_OF_SUB_DIRS})
+ file(APPEND "${CONF_IN_FILE}" "get_filename_component(_IMPORT_PREFIX \"\${_IMPORT_PREFIX}\" PATH)
+")
+ endforeach()
+ file(APPEND "${CONF_IN_FILE}" "
+")
+
+ foreach(BUNDLE_TARGET IN LISTS EXPORT_BUNDLES)
+ set(TN "${EXPORT_NAMESPACE}${BUNDLE_TARGET}")
+ file(APPEND "${CONF_IN_FILE}" "
+add_library(${TN} SHARED IMPORTED)
+set_target_properties(${TN} PROPERTIES
+ BUNDLE_IMPORTED TRUE
+ BUNDLE_FILE \"\${_IMPORT_PREFIX}/share/${EXPORT_PROJECT_NAME}/bundles/$<TARGET_PROPERTY:${BUNDLE_TARGET},BUNDLE_FILENAME>\"
+ BUNDLE_FILENAME \"$<TARGET_PROPERTY:${BUNDLE_TARGET},BUNDLE_FILENAME>\"
+)
+")
+ endforeach()
+ file(GENERATE OUTPUT "${CONF_FILE}" INPUT "${CONF_IN_FILE}")
+
+ if (EXPORT_COMPONENT)
+ install(FILES "${CONF_FILE}" DESTINATION ${EXPORT_DESTINATION} RENAME ${EXPORT_FILE} COMPONENT ${EXPORT_COMPONENT})
+ else ()
+ install(FILES "${CONF_FILE}" DESTINATION ${EXPORT_DESTINATION} RENAME ${EXPORT_FILE})
+ endif ()
+endfunction()
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/cmake_celix/CodeCoverage.cmake
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/CodeCoverage.cmake b/cmake/cmake_celix/CodeCoverage.cmake
deleted file mode 100644
index 51b5001..0000000
--- a/cmake/cmake_celix/CodeCoverage.cmake
+++ /dev/null
@@ -1,126 +0,0 @@
-# Boost Software License - Version 1.0 - August 17th, 2003
-#
-# Permission is hereby granted, free of charge, to any person or organization
-# obtaining a copy of the software and accompanying documentation covered by
-# this license (the "Software") to use, reproduce, display, distribute,
-# execute, and transmit the Software, and to prepare derivative works of the
-# Software, and to permit third-parties to whom the Software is furnished to
-# do so, all subject to the following:
-#
-# The copyright notices in the Software and this entire statement, including
-# the above license grant, this restriction and the following disclaimer,
-# must be included in all copies of the Software, in whole or in part, and
-# all derivative works of the Software, unless such copies or derivative
-# works are solely in the form of machine-executable object code generated by
-# a source language processor.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
-# SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
-# FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
-# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-# DEALINGS IN THE SOFTWARE.
-
-# - Enable Code Coverage
-#
-# 2012-01-31, Lars Bilke
-#
-# USAGE:
-# 1. Copy this file into your cmake modules path
-# 2. Add the following line to your CMakeLists.txt:
-# INCLUDE(CodeCoverage)
-#
-# 3. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target
-# which runs your test executable and produces a lcov code coverage report.
-#
-
-# - Changes made by Celix
-# 1. Added compiler options using --coverage instead of GCC specific strings
-# 2. Added custom target to generate HTML pages for combined coverage results
-# 3. Added each coverage target to the overall "coverage" target
-# 4. Added "mock" to exclude list for coverage results
-# 5. Removed HTML generation from the coverage setup function
-# 6. Removed unneeded Cobertura function
-#
-
-# Option to enable/disable coverage
-option(ENABLE_CODE_COVERAGE "Enables code coverage" FALSE)
-
-# Check if coverage is enabled
-IF(ENABLE_CODE_COVERAGE)
-
- # Check prereqs
- FIND_PROGRAM( GCOV_PATH gcov )
- FIND_PROGRAM( LCOV_PATH lcov )
- FIND_PROGRAM( GENHTML_PATH genhtml )
- FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests)
-
- IF(NOT GCOV_PATH)
- MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
- ENDIF() # NOT GCOV_PATH
-
- #IF(NOT CMAKE_COMPILER_IS_GNUCXX)
- # MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
- #ENDIF() # NOT CMAKE_COMPILER_IS_GNUCXX
-
- IF ( NOT CMAKE_BUILD_TYPE STREQUAL "Debug" )
- MESSAGE( WARNING "Code coverage results with an optimised (non-Debug) build may be misleading" )
- ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
-
- # Setup compiler options
- ADD_DEFINITIONS(--coverage)
- set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
- set(CMAKE_EXE_LINKER_FLAGS "--coverage")
-
- IF(NOT TARGET coverage)
- add_custom_target(coverage
- COMMAND ${CMAKE_COMMAND} -E make_directory coverage_results
- COMMAND ${GENHTML_PATH} -o coverage_results coverage/*/*.info.cleaned
-
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
- COMMENT "Generating report.\nOpen ./${_outputname}/index.html in your browser to view the coverage report."
- )
-
- SET_TARGET_PROPERTIES(coverage PROPERTIES COVERAGE_TARGET_ADDED "")
- ENDIF()
-
-ENDIF(ENABLE_CODE_COVERAGE)
-
-# Param _targetname The name of new the custom make target
-# Param _testrunner The name of the target which runs the tests
-# Param _outputname lcov output is generated as _outputname.info
-# HTML report is generated in _outputname/index.html
-# Optional fourth parameter is passed as arguments to _testrunner
-# Pass them in list form, e.g.: "-j;2" for -j 2
-FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
- IF(ENABLE_CODE_COVERAGE)
- IF(NOT LCOV_PATH)
- MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
- ENDIF() # NOT LCOV_PATH
-
- IF(NOT GENHTML_PATH)
- MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
- ENDIF() # NOT GENHTML_PATH
-
- # Setup target
- ADD_CUSTOM_TARGET(${_targetname}_coverage
-
- # Cleanup lcov
- ${LCOV_PATH} --directory . --zerocounters
-
- # Run tests
- COMMAND ${_testrunner} ${ARGV3}
-
- # Capturing lcov counters and generating report
- COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/coverage
- COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/coverage/${_testrunner}
- COMMAND ${LCOV_PATH} --directory . --capture --output-file ${_outputname}.info
- COMMAND ${LCOV_PATH} --remove ${_outputname}.info 'mock/*' 'test/*' '/usr/*' --output-file ${_outputname}.info.cleaned
-
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
- COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
- )
- ADD_DEPENDENCIES(coverage ${_targetname}_coverage)
- ENDIF(ENABLE_CODE_COVERAGE)
-ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
[25/54] [abbrv] celix git commit: CELIX-417: Refactors CMake usage
for the RSA bundles
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/civetweb/src/civetweb.c
----------------------------------------------------------------------
diff --git a/remote_services/civetweb/src/civetweb.c b/remote_services/civetweb/src/civetweb.c
new file mode 100644
index 0000000..a6093b7
--- /dev/null
+++ b/remote_services/civetweb/src/civetweb.c
@@ -0,0 +1,7907 @@
+ /* Copyright (c) 2013-2015 the Civetweb developers
+ * Copyright (c) 2004-2013 Sergey Lyubka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#if defined(_WIN32)
+#if !defined(_CRT_SECURE_NO_WARNINGS)
+#define _CRT_SECURE_NO_WARNINGS /* Disable deprecation warning in VS2005 */
+#endif
+#else
+#ifdef __linux__
+#define _XOPEN_SOURCE 600 /* For flockfile() on Linux */
+#endif
+#ifndef _LARGEFILE_SOURCE
+#define _LARGEFILE_SOURCE /* For fseeko(), ftello() */
+#endif
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64 /* Use 64-bit file offsets by default */
+#endif
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS /* <inttypes.h> wants this for C++ */
+#endif
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS /* C++ wants that for INT64_MAX */
+#endif
+#endif
+
+#if defined (_MSC_VER)
+/* 'type cast' : conversion from 'int' to 'HANDLE' of greater size */
+#pragma warning (disable : 4306 )
+/* conditional expression is constant: introduced by FD_SET(..) */
+#pragma warning (disable : 4127)
+/* non-constant aggregate initializer: issued due to missing C99 support */
+#pragma warning (disable : 4204)
+#endif
+
+/* Disable WIN32_LEAN_AND_MEAN.
+ This makes windows.h always include winsock2.h */
+#if defined(WIN32_LEAN_AND_MEAN)
+#undef WIN32_LEAN_AND_MEAN
+#endif
+
+#if defined USE_IPV6 && defined(_WIN32)
+#include <ws2tcpip.h>
+#endif
+
+#if defined(__SYMBIAN32__)
+#define NO_SSL /* SSL is not supported */
+#define NO_CGI /* CGI is not supported */
+#define PATH_MAX FILENAME_MAX
+#endif /* __SYMBIAN32__ */
+
+#ifndef IGNORE_UNUSED_RESULT
+#define IGNORE_UNUSED_RESULT(a) (void)((a) && 1)
+#endif
+
+#ifndef _WIN32_WCE /* Some ANSI #includes are not available on Windows CE */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <signal.h>
+#include <fcntl.h>
+#endif /* !_WIN32_WCE */
+
+#include <time.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <string.h>
+#include <ctype.h>
+#include <limits.h>
+#include <stddef.h>
+#include <stdio.h>
+
+#ifndef MAX_WORKER_THREADS
+#define MAX_WORKER_THREADS (1024*64)
+#endif
+
+#if defined(_WIN32) && !defined(__SYMBIAN32__) /* Windows specific */
+#if defined(_MSC_VER) && _MSC_VER <= 1400
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x0400 /* To make it link in VS2005 */
+#endif
+#include <windows.h>
+typedef const char * SOCK_OPT_TYPE;
+
+#ifndef PATH_MAX
+#define PATH_MAX MAX_PATH
+#endif
+
+#ifndef _IN_PORT_T
+#ifndef in_port_t
+#define in_port_t u_short
+#endif
+#endif
+
+#ifndef _WIN32_WCE
+#include <process.h>
+#include <direct.h>
+#include <io.h>
+#else /* _WIN32_WCE */
+#define NO_CGI /* WinCE has no pipes */
+
+typedef long off_t;
+
+#define errno GetLastError()
+#define strerror(x) _ultoa(x, (char *) _alloca(sizeof(x) *3 ), 10)
+#endif /* _WIN32_WCE */
+
+#define MAKEUQUAD(lo, hi) ((uint64_t)(((uint32_t)(lo)) | \
+ ((uint64_t)((uint32_t)(hi))) << 32))
+#define RATE_DIFF 10000000 /* 100 nsecs */
+#define EPOCH_DIFF MAKEUQUAD(0xd53e8000, 0x019db1de)
+#define SYS2UNIX_TIME(lo, hi) \
+ (time_t) ((MAKEUQUAD((lo), (hi)) - EPOCH_DIFF) / RATE_DIFF)
+
+/* Visual Studio 6 does not know __func__ or __FUNCTION__
+ The rest of MS compilers use __FUNCTION__, not C99 __func__
+ Also use _strtoui64 on modern M$ compilers */
+#if defined(_MSC_VER) && _MSC_VER < 1300
+#define STRX(x) #x
+#define STR(x) STRX(x)
+#define __func__ __FILE__ ":" STR(__LINE__)
+#define strtoull(x, y, z) (unsigned __int64) _atoi64(x)
+#define strtoll(x, y, z) _atoi64(x)
+#else
+#define __func__ __FUNCTION__
+#define strtoull(x, y, z) _strtoui64(x, y, z)
+#define strtoll(x, y, z) _strtoi64(x, y, z)
+#endif /* _MSC_VER */
+
+#define ERRNO GetLastError()
+#define NO_SOCKLEN_T
+#define SSL_LIB "ssleay32.dll"
+#define CRYPTO_LIB "libeay32.dll"
+#define O_NONBLOCK 0
+#define W_OK (2) /* http://msdn.microsoft.com/en-us/library/1w06ktdy.aspx */
+#if !defined(EWOULDBLOCK)
+#define EWOULDBLOCK WSAEWOULDBLOCK
+#endif /* !EWOULDBLOCK */
+#define _POSIX_
+#define INT64_FMT "I64d"
+
+#define WINCDECL __cdecl
+#define SHUT_WR 1
+#define snprintf _snprintf
+#define vsnprintf _vsnprintf
+#define access _access
+#define mg_sleep(x) Sleep(x)
+
+#define pipe(x) _pipe(x, MG_BUF_LEN, _O_BINARY)
+#ifndef popen
+#define popen(x, y) _popen(x, y)
+#endif
+#ifndef pclose
+#define pclose(x) _pclose(x)
+#endif
+#define close(x) _close(x)
+#define dlsym(x,y) GetProcAddress((HINSTANCE) (x), (y))
+#define RTLD_LAZY 0
+#define fseeko(x, y, z) _lseeki64(_fileno(x), (y), (z))
+#define fdopen(x, y) _fdopen((x), (y))
+#define write(x, y, z) _write((x), (y), (unsigned) z)
+#define read(x, y, z) _read((x), (y), (unsigned) z)
+#define flockfile(x) EnterCriticalSection(&global_log_file_lock)
+#define funlockfile(x) LeaveCriticalSection(&global_log_file_lock)
+#define sleep(x) Sleep((x) * 1000)
+#define rmdir(x) _rmdir(x)
+
+#if defined(USE_LUA) && defined(USE_WEBSOCKET)
+#define USE_TIMERS
+#endif
+
+#if !defined(va_copy)
+#define va_copy(x, y) x = y
+#endif /* !va_copy MINGW #defines va_copy */
+
+#if !defined(fileno)
+#define fileno(x) _fileno(x)
+#endif /* !fileno MINGW #defines fileno */
+
+typedef HANDLE pthread_mutex_t;
+typedef DWORD pthread_key_t;
+typedef HANDLE pthread_t;
+typedef struct {
+ CRITICAL_SECTION threadIdSec;
+ int waitingthreadcount; /* The number of threads queued. */
+ pthread_t *waitingthreadhdls; /* The thread handles. */
+} pthread_cond_t;
+
+#ifndef __clockid_t_defined
+typedef DWORD clockid_t;
+#endif
+#ifndef CLOCK_MONOTONIC
+#define CLOCK_MONOTONIC (1)
+#endif
+#ifndef CLOCK_REALTIME
+#define CLOCK_REALTIME (2)
+#endif
+
+#ifndef _TIMESPEC_DEFINED
+struct timespec {
+ time_t tv_sec; /* seconds */
+ long tv_nsec; /* nanoseconds */
+};
+#endif
+
+#define pid_t HANDLE /* MINGW typedefs pid_t to int. Using #define here. */
+
+static int pthread_mutex_lock(pthread_mutex_t *);
+static int pthread_mutex_unlock(pthread_mutex_t *);
+static void to_unicode(const char *path, wchar_t *wbuf, size_t wbuf_len);
+struct file;
+static char *mg_fgets(char *buf, size_t size, struct file *filep, char **p);
+
+#if defined(HAVE_STDINT)
+#include <stdint.h>
+#else
+typedef unsigned int uint32_t;
+typedef unsigned short uint16_t;
+typedef unsigned __int64 uint64_t;
+typedef __int64 int64_t;
+#define INT64_MAX 9223372036854775807
+#endif /* HAVE_STDINT */
+
+/* POSIX dirent interface */
+struct dirent {
+ char d_name[PATH_MAX];
+};
+
+typedef struct DIR {
+ HANDLE handle;
+ WIN32_FIND_DATAW info;
+ struct dirent result;
+} DIR;
+
+#if !defined(USE_IPV6) && defined(_WIN32)
+#ifndef HAVE_POLL
+struct pollfd {
+ SOCKET fd;
+ short events;
+ short revents;
+};
+#define POLLIN 1
+#endif
+#endif
+
+/* Mark required libraries */
+#ifdef _MSC_VER
+#pragma comment(lib, "Ws2_32.lib")
+#endif
+
+#else /* UNIX specific */
+#include <sys/wait.h>
+#include <sys/socket.h>
+#include <sys/poll.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/time.h>
+#include <sys/utsname.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <netdb.h>
+typedef const void * SOCK_OPT_TYPE;
+
+//#if defined(ANDROID)
+typedef unsigned short int in_port_t;
+//#endif
+
+#include <pwd.h>
+#include <unistd.h>
+#include <dirent.h>
+#if !defined(NO_SSL_DL) && !defined(NO_SSL)
+#include <dlfcn.h>
+#endif
+#include <pthread.h>
+#if defined(__MACH__)
+#define SSL_LIB "libssl.dylib"
+#define CRYPTO_LIB "libcrypto.dylib"
+#else
+#if !defined(SSL_LIB)
+#define SSL_LIB "libssl.so"
+#endif
+#if !defined(CRYPTO_LIB)
+#define CRYPTO_LIB "libcrypto.so"
+#endif
+#endif
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif /* O_BINARY */
+#define closesocket(a) close(a)
+#define mg_mkdir(x, y) mkdir(x, y)
+#define mg_remove(x) remove(x)
+#define mg_sleep(x) usleep((x) * 1000)
+#define ERRNO errno
+#define INVALID_SOCKET (-1)
+#define INT64_FMT PRId64
+typedef int SOCKET;
+#define WINCDECL
+
+#endif /* End of Windows and UNIX specific includes */
+
+#ifdef _WIN32
+static CRITICAL_SECTION global_log_file_lock;
+static DWORD pthread_self(void)
+{
+ return GetCurrentThreadId();
+}
+
+int pthread_key_create(pthread_key_t *key, void (*_must_be_zero)(void*) /* destructor function not supported for windows */)
+{
+ assert(_must_be_zero == NULL);
+ if ((key!=0) && (_must_be_zero == NULL)) {
+ *key = TlsAlloc();
+ return (*key != TLS_OUT_OF_INDEXES) ? 0 : -1;
+ }
+ return -2;
+}
+
+int pthread_key_delete(pthread_key_t key)
+{
+ return TlsFree(key) ? 0 : 1;
+}
+
+int pthread_setspecific(pthread_key_t key, void * value)
+{
+ return TlsSetValue(key, value) ? 0 : 1;
+}
+
+void *pthread_getspecific(pthread_key_t key)
+{
+ return TlsGetValue(key);
+}
+#endif /* _WIN32 */
+
+
+#include "civetweb.h"
+
+#define PASSWORDS_FILE_NAME ".htpasswd"
+#define CGI_ENVIRONMENT_SIZE 4096
+#define MAX_CGI_ENVIR_VARS 64
+#define MG_BUF_LEN 8192
+#ifndef MAX_REQUEST_SIZE
+#define MAX_REQUEST_SIZE 16384
+#endif
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
+
+#if !defined(DEBUG_TRACE)
+#if defined(CWDEBUG)
+
+static void DEBUG_TRACE_FUNC(const char *func, unsigned line, PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(3, 4);
+
+static void DEBUG_TRACE_FUNC(const char *func, unsigned line, const char *fmt, ...) {
+
+ va_list args;
+ flockfile(stdout);
+ printf("*** %lu.%p.%s.%u: ",
+ (unsigned long) time(NULL), (void *) pthread_self(),
+ func, line);
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+ putchar('\n');
+ fflush(stdout);
+ funlockfile(stdout);
+}
+
+#define DEBUG_TRACE(fmt, ...) DEBUG_TRACE_FUNC(__func__, __LINE__, fmt, __VA_ARGS__)
+
+#else
+#define DEBUG_TRACE(fmt, ...)
+#endif /* CWDEBUG */
+#endif /* DEBUG_TRACE */
+
+#if defined(MEMORY_DEBUGGING)
+static unsigned long blockCount = 0;
+static unsigned long totalMemUsed = 0;
+
+static void * mg_malloc_ex(size_t size, const char * file, unsigned line) {
+
+ void * data = malloc(size + sizeof(size_t));
+ void * memory = 0;
+ char mallocStr[256];
+
+ if (data) {
+ *(size_t*)data = size;
+ totalMemUsed += size;
+ blockCount++;
+ memory = (void *)(((char*)data)+sizeof(size_t));
+ }
+
+ sprintf(mallocStr, "MEM: %p %5lu alloc %7lu %4lu --- %s:%u\n", memory, (unsigned long)size, totalMemUsed, blockCount, file, line);
+#if defined(_WIN32)
+ OutputDebugStringA(mallocStr);
+#else
+ DEBUG_TRACE("%s", mallocStr);
+#endif
+
+ return memory;
+}
+
+static void * mg_calloc_ex(size_t count, size_t size, const char * file, unsigned line) {
+
+ void * data = mg_malloc_ex(size*count, file, line);
+ if (data) memset(data, 0, size);
+
+ return data;
+}
+
+static void mg_free_ex(void * memory, const char * file, unsigned line) {
+
+ char mallocStr[256];
+ void * data = (void *)(((char*)memory)-sizeof(size_t));
+ size_t size;
+
+ if (memory) {
+ size = *(size_t*)data;
+ totalMemUsed -= size;
+ blockCount--;
+ sprintf(mallocStr, "MEM: %p %5lu free %7lu %4lu --- %s:%u\n", memory, (unsigned long)size, totalMemUsed, blockCount, file, line);
+#if defined(_WIN32)
+ OutputDebugStringA(mallocStr);
+#else
+ DEBUG_TRACE("%s", mallocStr);
+#endif
+
+ free(data);
+ }
+}
+
+static void * mg_realloc_ex(void * memory, size_t newsize, const char * file, unsigned line) {
+
+ char mallocStr[256];
+ void * data;
+ void * _realloc;
+ size_t oldsize;
+
+ if (newsize) {
+ if (memory) {
+ data = (void *)(((char*)memory)-sizeof(size_t));
+ oldsize = *(size_t*)data;
+ _realloc = realloc(data, newsize+sizeof(size_t));
+ if (_realloc) {
+ data = _realloc;
+ totalMemUsed -= oldsize;
+ sprintf(mallocStr, "MEM: %p %5lu r-free %7lu %4lu --- %s:%u\n", memory, (unsigned long)oldsize, totalMemUsed, blockCount, file, line);
+#if defined(_WIN32)
+ OutputDebugStringA(mallocStr);
+#else
+ DEBUG_TRACE("%s", mallocStr);
+#endif
+ totalMemUsed += newsize;
+ sprintf(mallocStr, "MEM: %p %5lu r-alloc %7lu %4lu --- %s:%u\n", memory, (unsigned long)newsize, totalMemUsed, blockCount, file, line);
+#if defined(_WIN32)
+ OutputDebugStringA(mallocStr);
+#else
+ DEBUG_TRACE("%s", mallocStr);
+#endif
+ *(size_t*)data = newsize;
+ data = (void *)(((char*)data)+sizeof(size_t));
+ } else {
+#if defined(_WIN32)
+ OutputDebugStringA("MEM: realloc failed\n");
+#else
+ DEBUG_TRACE("%s", "MEM: realloc failed\n");
+#endif
+ return _realloc;
+ }
+ } else {
+ data = mg_malloc_ex(newsize, file, line);
+ }
+ } else {
+ data = 0;
+ mg_free_ex(memory, file, line);
+ }
+
+ return data;
+}
+
+#define mg_malloc(a) mg_malloc_ex(a, __FILE__, __LINE__)
+#define mg_calloc(a,b) mg_calloc_ex(a, b, __FILE__, __LINE__)
+#define mg_realloc(a, b) mg_realloc_ex(a, b, __FILE__, __LINE__)
+#define mg_free(a) mg_free_ex(a, __FILE__, __LINE__)
+
+#else
+static __inline void * mg_malloc(size_t a) {return malloc(a);}
+static __inline void * mg_calloc(size_t a, size_t b) {return calloc(a, b);}
+static __inline void * mg_realloc(void * a, size_t b) {return realloc(a, b);}
+static __inline void mg_free(void * a) {free(a);}
+#endif
+
+/* This following lines are just meant as a reminder to use the mg-functions for memory management */
+#ifdef malloc
+ #undef malloc
+#endif
+#ifdef calloc
+ #undef calloc
+#endif
+#ifdef realloc
+ #undef realloc
+#endif
+#ifdef free
+ #undef free
+#endif
+#define malloc DO_NOT_USE_THIS_FUNCTION__USE_mg_malloc
+#define calloc DO_NOT_USE_THIS_FUNCTION__USE_mg_calloc
+#define realloc DO_NOT_USE_THIS_FUNCTION__USE_mg_realloc
+#define free DO_NOT_USE_THIS_FUNCTION__USE_mg_free
+
+
+#define MD5_STATIC static
+#include "md5.inl"
+
+/* Darwin prior to 7.0 and Win32 do not have socklen_t */
+#ifdef NO_SOCKLEN_T
+typedef int socklen_t;
+#endif /* NO_SOCKLEN_T */
+#define _DARWIN_UNLIMITED_SELECT
+
+#define IP_ADDR_STR_LEN 50 /* IPv6 hex string is 46 chars */
+
+#if !defined(MSG_NOSIGNAL)
+#define MSG_NOSIGNAL 0
+#endif
+
+#if !defined(SOMAXCONN)
+#define SOMAXCONN 100
+#endif
+
+#if !defined(PATH_MAX)
+#define PATH_MAX 4096
+#endif
+
+/* Size of the accepted socket queue */
+#if !defined(MGSQLEN)
+#define MGSQLEN 20
+#endif
+
+#if defined(NO_SSL_DL)
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+#else
+/* SSL loaded dynamically from DLL.
+ I put the prototypes here to be independent from OpenSSL source
+ installation. */
+
+typedef struct ssl_st SSL;
+typedef struct ssl_method_st SSL_METHOD;
+typedef struct ssl_ctx_st SSL_CTX;
+
+struct ssl_func {
+ const char *name; /* SSL function name */
+ void (*ptr)(void); /* Function pointer */
+};
+
+#define SSL_free (* (void (*)(SSL *)) ssl_sw[0].ptr)
+#define SSL_accept (* (int (*)(SSL *)) ssl_sw[1].ptr)
+#define SSL_connect (* (int (*)(SSL *)) ssl_sw[2].ptr)
+#define SSL_read (* (int (*)(SSL *, void *, int)) ssl_sw[3].ptr)
+#define SSL_write (* (int (*)(SSL *, const void *,int)) ssl_sw[4].ptr)
+#define SSL_get_error (* (int (*)(SSL *, int)) ssl_sw[5].ptr)
+#define SSL_set_fd (* (int (*)(SSL *, SOCKET)) ssl_sw[6].ptr)
+#define SSL_new (* (SSL * (*)(SSL_CTX *)) ssl_sw[7].ptr)
+#define SSL_CTX_new (* (SSL_CTX * (*)(SSL_METHOD *)) ssl_sw[8].ptr)
+#define SSLv23_server_method (* (SSL_METHOD * (*)(void)) ssl_sw[9].ptr)
+#define SSL_library_init (* (int (*)(void)) ssl_sw[10].ptr)
+#define SSL_CTX_use_PrivateKey_file (* (int (*)(SSL_CTX *, \
+ const char *, int)) ssl_sw[11].ptr)
+#define SSL_CTX_use_certificate_file (* (int (*)(SSL_CTX *, \
+ const char *, int)) ssl_sw[12].ptr)
+#define SSL_CTX_set_default_passwd_cb \
+ (* (void (*)(SSL_CTX *, mg_callback_t)) ssl_sw[13].ptr)
+#define SSL_CTX_free (* (void (*)(SSL_CTX *)) ssl_sw[14].ptr)
+#define SSL_load_error_strings (* (void (*)(void)) ssl_sw[15].ptr)
+#define SSL_CTX_use_certificate_chain_file \
+ (* (int (*)(SSL_CTX *, const char *)) ssl_sw[16].ptr)
+#define SSLv23_client_method (* (SSL_METHOD * (*)(void)) ssl_sw[17].ptr)
+#define SSL_pending (* (int (*)(SSL *)) ssl_sw[18].ptr)
+#define SSL_CTX_set_verify (* (void (*)(SSL_CTX *, int, int)) ssl_sw[19].ptr)
+#define SSL_shutdown (* (int (*)(SSL *)) ssl_sw[20].ptr)
+
+#define CRYPTO_num_locks (* (int (*)(void)) crypto_sw[0].ptr)
+#define CRYPTO_set_locking_callback \
+ (* (void (*)(void (*)(int, int, const char *, int))) crypto_sw[1].ptr)
+#define CRYPTO_set_id_callback \
+ (* (void (*)(unsigned long (*)(void))) crypto_sw[2].ptr)
+#define ERR_get_error (* (unsigned long (*)(void)) crypto_sw[3].ptr)
+#define ERR_error_string (* (char * (*)(unsigned long,char *)) crypto_sw[4].ptr)
+
+/* set_ssl_option() function updates this array.
+ It loads SSL library dynamically and changes NULLs to the actual addresses
+ of respective functions. The macros above (like SSL_connect()) are really
+ just calling these functions indirectly via the pointer. */
+static struct ssl_func ssl_sw[] = {
+ {"SSL_free", NULL},
+ {"SSL_accept", NULL},
+ {"SSL_connect", NULL},
+ {"SSL_read", NULL},
+ {"SSL_write", NULL},
+ {"SSL_get_error", NULL},
+ {"SSL_set_fd", NULL},
+ {"SSL_new", NULL},
+ {"SSL_CTX_new", NULL},
+ {"SSLv23_server_method", NULL},
+ {"SSL_library_init", NULL},
+ {"SSL_CTX_use_PrivateKey_file", NULL},
+ {"SSL_CTX_use_certificate_file",NULL},
+ {"SSL_CTX_set_default_passwd_cb",NULL},
+ {"SSL_CTX_free", NULL},
+ {"SSL_load_error_strings", NULL},
+ {"SSL_CTX_use_certificate_chain_file", NULL},
+ {"SSLv23_client_method", NULL},
+ {"SSL_pending", NULL},
+ {"SSL_CTX_set_verify", NULL},
+ {"SSL_shutdown", NULL},
+ {NULL, NULL}
+};
+
+/* Similar array as ssl_sw. These functions could be located in different
+ lib. */
+#if !defined(NO_SSL)
+static struct ssl_func crypto_sw[] = {
+ {"CRYPTO_num_locks", NULL},
+ {"CRYPTO_set_locking_callback", NULL},
+ {"CRYPTO_set_id_callback", NULL},
+ {"ERR_get_error", NULL},
+ {"ERR_error_string", NULL},
+ {NULL, NULL}
+};
+#endif /* NO_SSL */
+#endif /* NO_SSL_DL */
+
+static const char *month_names[] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+
+/* Unified socket address. For IPv6 support, add IPv6 address structure
+ in the union u. */
+union usa {
+ struct sockaddr sa;
+ struct sockaddr_in sin;
+#if defined(USE_IPV6)
+ struct sockaddr_in6 sin6;
+#endif
+};
+
+/* Describes a string (chunk of memory). */
+struct vec {
+ const char *ptr;
+ size_t len;
+};
+
+struct file {
+ int is_directory;
+ time_t modification_time;
+ int64_t size;
+ FILE *fp;
+ const char *membuf; /* Non-NULL if file data is in memory */
+ /* set to 1 if the content is gzipped
+ in which case we need a content-encoding: gzip header */
+ int gzipped;
+};
+#define STRUCT_FILE_INITIALIZER {0, 0, 0, NULL, NULL, 0}
+
+/* Describes listening socket, or socket which was accept()-ed by the master
+ thread and queued for future handling by the worker thread. */
+struct socket {
+ SOCKET sock; /* Listening socket */
+ union usa lsa; /* Local socket address */
+ union usa rsa; /* Remote socket address */
+ unsigned is_ssl:1; /* Is port SSL-ed */
+ unsigned ssl_redir:1; /* Is port supposed to redirect everything to SSL
+ port */
+};
+
+/* NOTE(lsm): this enum shoulds be in sync with the config_options below. */
+enum {
+ CGI_EXTENSIONS, CGI_ENVIRONMENT, PUT_DELETE_PASSWORDS_FILE, CGI_INTERPRETER,
+ PROTECT_URI, AUTHENTICATION_DOMAIN, SSI_EXTENSIONS, THROTTLE,
+ ACCESS_LOG_FILE, ENABLE_DIRECTORY_LISTING, ERROR_LOG_FILE,
+ GLOBAL_PASSWORDS_FILE, INDEX_FILES, ENABLE_KEEP_ALIVE, ACCESS_CONTROL_LIST,
+ EXTRA_MIME_TYPES, LISTENING_PORTS, DOCUMENT_ROOT, SSL_CERTIFICATE,
+ NUM_THREADS, RUN_AS_USER, REWRITE, HIDE_FILES, REQUEST_TIMEOUT,
+ DECODE_URL,
+
+#if defined(USE_LUA)
+ LUA_PRELOAD_FILE, LUA_SCRIPT_EXTENSIONS, LUA_SERVER_PAGE_EXTENSIONS,
+#endif
+#if defined(USE_WEBSOCKET)
+ WEBSOCKET_ROOT,
+#endif
+#if defined(USE_LUA) && defined(USE_WEBSOCKET)
+ LUA_WEBSOCKET_EXTENSIONS,
+#endif
+ ACCESS_CONTROL_ALLOW_ORIGIN, ERROR_PAGES,
+
+ NUM_OPTIONS
+};
+
+/* Config option name, config types, default value */
+static struct mg_option config_options[] = {
+ {"cgi_pattern", CONFIG_TYPE_EXT_PATTERN, "**.cgi$|**.pl$|**.php$"},
+ {"cgi_environment", CONFIG_TYPE_STRING, NULL},
+ {"put_delete_auth_file", CONFIG_TYPE_FILE, NULL},
+ {"cgi_interpreter", CONFIG_TYPE_FILE, NULL},
+ {"protect_uri", CONFIG_TYPE_STRING, NULL},
+ {"authentication_domain", CONFIG_TYPE_STRING, "mydomain.com"},
+ {"ssi_pattern", CONFIG_TYPE_EXT_PATTERN, "**.shtml$|**.shtm$"},
+ {"throttle", CONFIG_TYPE_STRING, NULL},
+ {"access_log_file", CONFIG_TYPE_FILE, NULL},
+ {"enable_directory_listing", CONFIG_TYPE_BOOLEAN, "yes"},
+ {"error_log_file", CONFIG_TYPE_FILE, NULL},
+ {"global_auth_file", CONFIG_TYPE_FILE, NULL},
+ {"index_files", CONFIG_TYPE_STRING,
+#ifdef USE_LUA
+ "index.xhtml,index.html,index.htm,index.lp,index.lsp,index.lua,index.cgi,index.shtml,index.php"},
+#else
+ "index.xhtml,index.html,index.htm,index.cgi,index.shtml,index.php"},
+#endif
+ {"enable_keep_alive", CONFIG_TYPE_BOOLEAN, "no"},
+ {"access_control_list", CONFIG_TYPE_STRING, NULL},
+ {"extra_mime_types", CONFIG_TYPE_STRING, NULL},
+ {"listening_ports", CONFIG_TYPE_STRING, "8080"},
+ {"document_root", CONFIG_TYPE_DIRECTORY, NULL},
+ {"ssl_certificate", CONFIG_TYPE_FILE, NULL},
+ {"num_threads", CONFIG_TYPE_NUMBER, "50"},
+ {"run_as_user", CONFIG_TYPE_STRING, NULL},
+ {"url_rewrite_patterns", CONFIG_TYPE_STRING, NULL},
+ {"hide_files_patterns", CONFIG_TYPE_EXT_PATTERN, NULL},
+ {"request_timeout_ms", CONFIG_TYPE_NUMBER, "30000"},
+ {"decode_url", CONFIG_TYPE_BOOLEAN, "yes"},
+
+#if defined(USE_LUA)
+ {"lua_preload_file", CONFIG_TYPE_FILE, NULL},
+ {"lua_script_pattern", CONFIG_TYPE_EXT_PATTERN, "**.lua$"},
+ {"lua_server_page_pattern", CONFIG_TYPE_EXT_PATTERN, "**.lp$|**.lsp$"},
+#endif
+#if defined(USE_WEBSOCKET)
+ {"websocket_root", CONFIG_TYPE_DIRECTORY, NULL},
+#endif
+#if defined(USE_LUA) && defined(USE_WEBSOCKET)
+ {"lua_websocket_pattern", CONFIG_TYPE_EXT_PATTERN, "**.lua$"},
+#endif
+ {"access_control_allow_origin", CONFIG_TYPE_STRING, "*"},
+ {"error_pages", CONFIG_TYPE_DIRECTORY, NULL},
+
+ {NULL, CONFIG_TYPE_UNKNOWN, NULL}
+};
+
+struct mg_request_handler_info {
+ char *uri;
+ size_t uri_len;
+ mg_request_handler handler;
+
+ void *cbdata;
+ struct mg_request_handler_info *next;
+};
+
+struct mg_context {
+ volatile int stop_flag; /* Should we stop event loop */
+ SSL_CTX *ssl_ctx; /* SSL context */
+ char *config[NUM_OPTIONS]; /* Civetweb configuration parameters */
+ struct mg_callbacks callbacks; /* User-defined callback function */
+ void *user_data; /* User-defined data */
+ int context_type; /* 1 = server context, 2 = client context */
+
+ struct socket *listening_sockets;
+ in_port_t *listening_ports;
+ int num_listening_sockets;
+
+ volatile int num_threads; /* Number of threads */
+ pthread_mutex_t thread_mutex; /* Protects (max|num)_threads */
+ pthread_cond_t thread_cond; /* Condvar for tracking workers terminations */
+
+ struct socket queue[MGSQLEN]; /* Accepted sockets */
+ volatile int sq_head; /* Head of the socket queue */
+ volatile int sq_tail; /* Tail of the socket queue */
+ pthread_cond_t sq_full; /* Signaled when socket is produced */
+ pthread_cond_t sq_empty; /* Signaled when socket is consumed */
+ pthread_t masterthreadid; /* The master thread ID */
+ int workerthreadcount; /* The amount of worker threads. */
+ pthread_t *workerthreadids; /* The worker thread IDs */
+
+ unsigned long start_time; /* Server start time, used for authentication */
+ pthread_mutex_t nonce_mutex; /* Protects nonce_count */
+ unsigned long nonce_count; /* Used nonces, used for authentication */
+
+ char *systemName; /* What operating system is running */
+
+ /* linked list of uri handlers */
+ struct mg_request_handler_info *request_handlers;
+
+#if defined(USE_LUA) && defined(USE_WEBSOCKET)
+ /* linked list of shared lua websockets */
+ struct mg_shared_lua_websocket_list *shared_lua_websockets;
+#endif
+
+#ifdef USE_TIMERS
+ struct ttimers * timers;
+#endif
+};
+
+struct mg_connection {
+ struct mg_request_info request_info;
+ struct mg_context *ctx;
+ SSL *ssl; /* SSL descriptor */
+ SSL_CTX *client_ssl_ctx; /* SSL context for client connections */
+ struct socket client; /* Connected client */
+ time_t birth_time; /* Time when request was received */
+ int64_t num_bytes_sent; /* Total bytes sent to client */
+ int64_t content_len; /* Content-Length header value */
+ int64_t consumed_content; /* How many bytes of content have been read */
+ char *buf; /* Buffer for received data */
+ char *path_info; /* PATH_INFO part of the URL */
+ int must_close; /* 1 if connection must be closed */
+ int in_error_handler; /* 1 if in handler for user defined error pages */
+ int buf_size; /* Buffer size */
+ int request_len; /* Size of the request + headers in a buffer */
+ int data_len; /* Total size of data in a buffer */
+ int status_code; /* HTTP reply status code, e.g. 200 */
+ int throttle; /* Throttling, bytes/sec. <= 0 means no throttle */
+ time_t last_throttle_time; /* Last time throttled data was sent */
+ int64_t last_throttle_bytes; /* Bytes sent this second */
+ pthread_mutex_t mutex; /* Used by mg_lock_connection/mg_unlock_connection to ensure atomic transmissions for websockets */
+#if defined(USE_LUA) && defined(USE_WEBSOCKET)
+ void * lua_websocket_state; /* Lua_State for a websocket connection */
+#endif
+};
+
+static pthread_key_t sTlsKey; /* Thread local storage index */
+static int sTlsInit = 0;
+
+struct mg_workerTLS {
+ int is_master;
+#if defined(_WIN32) && !defined(__SYMBIAN32__)
+ HANDLE pthread_cond_helper_mutex;
+#endif
+};
+
+/* Directory entry */
+struct de {
+ struct mg_connection *conn;
+ char *file_name;
+ struct file file;
+};
+
+#if defined(USE_WEBSOCKET)
+static int is_websocket_protocol(const struct mg_connection *conn);
+#else
+#define is_websocket_protocol(conn) (0)
+#endif
+
+int mg_atomic_inc(volatile int * addr)
+{
+ int ret;
+#if defined(_WIN32) && !defined(__SYMBIAN32__)
+ ret = InterlockedIncrement((volatile unsigned int *) addr);
+#elif defined(__GNUC__)
+ ret = __sync_add_and_fetch(addr, 1);
+#else
+ ret = (++(*addr));
+#endif
+ return ret;
+}
+
+int mg_atomic_dec(volatile int * addr)
+{
+ int ret;
+#if defined(_WIN32) && !defined(__SYMBIAN32__)
+ ret = InterlockedDecrement((volatile unsigned int *) addr);
+#elif defined(__GNUC__)
+ ret = __sync_sub_and_fetch(addr, 1);
+#else
+ ret = (--(*addr));
+#endif
+ return ret;
+}
+
+#if !defined(NO_THREAD_NAME)
+#if defined(_WIN32) && defined(_MSC_VER)
+/* Set the thread name for debugging purposes in Visual Studio
+ http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
+*/
+#pragma pack(push,8)
+typedef struct tagTHREADNAME_INFO
+{
+ DWORD dwType; /* Must be 0x1000. */
+ LPCSTR szName; /* Pointer to name (in user addr space). */
+ DWORD dwThreadID; /* Thread ID (-1=caller thread). */
+ DWORD dwFlags; /* Reserved for future use, must be zero. */
+} THREADNAME_INFO;
+#pragma pack(pop)
+#elif defined(__linux__)
+#include <sys/prctl.h>
+#endif
+
+void mg_set_thread_name(const char* name)
+{
+ char threadName[16]; /* Max. thread length in Linux/OSX/.. */
+
+ if (snprintf(threadName, sizeof(threadName), "civetweb-%s", name)<0) return;
+ threadName[sizeof(threadName)-1] = 0;
+
+#if defined(_WIN32)
+#if defined(_MSC_VER)
+ /* Windows and Visual Studio Compiler */
+ __try
+ {
+ THREADNAME_INFO info;
+ info.dwType = 0x1000;
+ info.szName = threadName;
+ info.dwThreadID = -1;
+ info.dwFlags = 0;
+
+ RaiseException(0x406D1388, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info);
+ }
+ __except(EXCEPTION_EXECUTE_HANDLER)
+ {
+ }
+#elif defined(__MINGW32__)
+ /* No option known to set thread name for MinGW */
+#endif
+#elif defined(__linux__)
+ /* Linux */
+ (void)prctl(PR_SET_NAME,threadName,0,0,0);
+#elif defined(__APPLE__) || defined(__MACH__)
+ /* OS X (TODO: test) */
+ (void)pthread_setname_np(threadName);
+#elif defined(BSD) || defined(__FreeBSD__) || defined(__OpenBSD__)
+ /* BSD (TODO: test) */
+ pthread_set_name_np(pthread_self(), threadName);
+#else
+ /* POSIX */
+ (void)pthread_setname_np(pthread_self(), threadName);
+#endif
+}
+#else /* !defined(NO_THREAD_NAME) */
+void mg_set_thread_name(const char* threadName) {}
+#endif
+
+#if defined(MG_LEGACY_INTERFACE)
+const char **mg_get_valid_option_names(void)
+{
+ static const char * data[2 * sizeof(config_options) / sizeof(config_options[0])] = {0};
+ int i;
+
+ for (i=0; config_options[i].name != NULL; i++) {
+ data[i * 2] = config_options[i].name;
+ data[i * 2 + 1] = config_options[i].default_value;
+ }
+
+ return data;
+}
+#endif
+
+const struct mg_option *mg_get_valid_options(void)
+{
+ return config_options;
+}
+
+
+static int is_file_in_memory(struct mg_connection *conn, const char *path,
+ struct file *filep)
+{
+ size_t size = 0;
+ if ((filep->membuf = conn->ctx->callbacks.open_file == NULL ? NULL :
+ conn->ctx->callbacks.open_file(conn, path, &size)) != NULL) {
+ /* NOTE: override filep->size only on success. Otherwise, it might
+ break constructs like if (!mg_stat() || !mg_fopen()) ... */
+ filep->size = size;
+ }
+ return filep->membuf != NULL;
+}
+
+static int is_file_opened(const struct file *filep)
+{
+ return filep->membuf != NULL || filep->fp != NULL;
+}
+
+static int mg_fopen(struct mg_connection *conn, const char *path,
+ const char *mode, struct file *filep)
+{
+ if (!is_file_in_memory(conn, path, filep)) {
+#ifdef _WIN32
+ wchar_t wbuf[PATH_MAX], wmode[20];
+ to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
+ MultiByteToWideChar(CP_UTF8, 0, mode, -1, wmode, ARRAY_SIZE(wmode));
+ filep->fp = _wfopen(wbuf, wmode);
+#else
+ filep->fp = fopen(path, mode);
+#endif
+ }
+
+ return is_file_opened(filep);
+}
+
+static void mg_fclose(struct file *filep)
+{
+ if (filep != NULL && filep->fp != NULL) {
+ fclose(filep->fp);
+ }
+}
+
+static void mg_strlcpy(register char *dst, register const char *src, size_t n)
+{
+ for (; *src != '\0' && n > 1; n--) {
+ *dst++ = *src++;
+ }
+ *dst = '\0';
+}
+
+static int lowercase(const char *s)
+{
+ return tolower(* (const unsigned char *) s);
+}
+
+int mg_strncasecmp(const char *s1, const char *s2, size_t len)
+{
+ int diff = 0;
+
+ if (len > 0)
+ do {
+ diff = lowercase(s1++) - lowercase(s2++);
+ } while (diff == 0 && s1[-1] != '\0' && --len > 0);
+
+ return diff;
+}
+
+static int mg_strcasecmp(const char *s1, const char *s2)
+{
+ int diff;
+
+ do {
+ diff = lowercase(s1++) - lowercase(s2++);
+ } while (diff == 0 && s1[-1] != '\0');
+
+ return diff;
+}
+
+static char * mg_strndup(const char *ptr, size_t len)
+{
+ char *p;
+
+ if ((p = (char *) mg_malloc(len + 1)) != NULL) {
+ mg_strlcpy(p, ptr, len + 1);
+ }
+
+ return p;
+}
+
+static char * mg_strdup(const char *str)
+{
+ return mg_strndup(str, strlen(str));
+}
+
+static const char *mg_strcasestr(const char *big_str, const char *small_str)
+{
+ int i, big_len = (int)strlen(big_str), small_len = (int)strlen(small_str);
+
+ for (i = 0; i <= big_len - small_len; i++) {
+ if (mg_strncasecmp(big_str + i, small_str, small_len) == 0) {
+ return big_str + i;
+ }
+ }
+
+ return NULL;
+}
+
+/* Like snprintf(), but never returns negative value, or a value
+ that is larger than a supplied buffer.
+ Thanks to Adam Zeldis to pointing snprintf()-caused vulnerability
+ in his audit report. */
+static int mg_vsnprintf(struct mg_connection *conn, char *buf, size_t buflen,
+ const char *fmt, va_list ap)
+{
+ int n;
+
+ if (buflen == 0)
+ return 0;
+
+ n = vsnprintf(buf, buflen, fmt, ap);
+
+ if (n < 0) {
+ mg_cry(conn, "vsnprintf error");
+ n = 0;
+ } else if (n >= (int) buflen) {
+ mg_cry(conn, "truncating vsnprintf buffer: [%.*s]",
+ n > 200 ? 200 : n, buf);
+ n = (int) buflen - 1;
+ }
+ buf[n] = '\0';
+
+ return n;
+}
+
+static int mg_snprintf(struct mg_connection *conn, char *buf, size_t buflen,
+ PRINTF_FORMAT_STRING(const char *fmt), ...)
+PRINTF_ARGS(4, 5);
+
+static int mg_snprintf(struct mg_connection *conn, char *buf, size_t buflen,
+ const char *fmt, ...)
+{
+ va_list ap;
+ int n;
+
+ va_start(ap, fmt);
+ n = mg_vsnprintf(conn, buf, buflen, fmt, ap);
+ va_end(ap);
+
+ return n;
+}
+
+static int get_option_index(const char *name)
+{
+ int i;
+
+ for (i = 0; config_options[i].name != NULL; i++) {
+ if (strcmp(config_options[i].name, name) == 0) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+const char *mg_get_option(const struct mg_context *ctx, const char *name)
+{
+ int i;
+ if ((i = get_option_index(name)) == -1) {
+ return NULL;
+ } else if (ctx->config[i] == NULL) {
+ return "";
+ } else {
+ return ctx->config[i];
+ }
+}
+
+struct mg_context *mg_get_context(struct mg_connection * conn)
+{
+ return (conn == NULL) ? (struct mg_context *)NULL : (conn->ctx);
+}
+
+void *mg_get_user_data(struct mg_context *ctx)
+{
+ return (ctx == NULL) ? NULL : ctx->user_data;
+}
+
+size_t mg_get_ports(const struct mg_context *ctx, size_t size, int* ports, int* ssl)
+{
+ size_t i;
+ for (i = 0; i < size && i < (size_t)ctx->num_listening_sockets; i++)
+ {
+ ssl[i] = ctx->listening_sockets[i].is_ssl;
+ ports[i] = ctx->listening_ports[i];
+ }
+ return i;
+}
+
+static void sockaddr_to_string(char *buf, size_t len,
+ const union usa *usa)
+{
+ buf[0] = '\0';
+#if defined(USE_IPV6)
+ inet_ntop(usa->sa.sa_family, usa->sa.sa_family == AF_INET ?
+ (void *) &usa->sin.sin_addr :
+ (void *) &usa->sin6.sin6_addr, buf, len);
+#elif defined(_WIN32)
+ /* Only Windows Vista (and newer) have inet_ntop() */
+ mg_strlcpy(buf, inet_ntoa(usa->sin.sin_addr), len);
+#else
+ inet_ntop(usa->sa.sa_family, (void *) &usa->sin.sin_addr, buf, len);
+#endif
+}
+
+/* Convert time_t to a string. According to RFC2616, Sec 14.18, this must be included in all responses other than 100, 101, 5xx. */
+static void gmt_time_string(char *buf, size_t buf_len, time_t *t)
+{
+ struct tm *tm;
+
+ tm = gmtime(t);
+ if (tm != NULL) {
+ strftime(buf, buf_len, "%a, %d %b %Y %H:%M:%S GMT", tm);
+ } else {
+ mg_strlcpy(buf, "Thu, 01 Jan 1970 00:00:00 GMT", buf_len);
+ buf[buf_len - 1] = '\0';
+ }
+}
+
+/* Print error message to the opened error log stream. */
+void mg_cry(struct mg_connection *conn, const char *fmt, ...)
+{
+ char buf[MG_BUF_LEN], src_addr[IP_ADDR_STR_LEN];
+ va_list ap;
+ FILE *fp;
+ time_t timestamp;
+
+ va_start(ap, fmt);
+ IGNORE_UNUSED_RESULT(vsnprintf(buf, sizeof(buf), fmt, ap));
+ va_end(ap);
+
+ /* Do not lock when getting the callback value, here and below.
+ I suppose this is fine, since function cannot disappear in the
+ same way string option can. */
+ if (conn->ctx->callbacks.log_message == NULL ||
+ conn->ctx->callbacks.log_message(conn, buf) == 0) {
+ fp = conn->ctx->config[ERROR_LOG_FILE] == NULL ? NULL :
+ fopen(conn->ctx->config[ERROR_LOG_FILE], "a+");
+
+ if (fp != NULL) {
+ flockfile(fp);
+ timestamp = time(NULL);
+
+ sockaddr_to_string(src_addr, sizeof(src_addr), &conn->client.rsa);
+ fprintf(fp, "[%010lu] [error] [client %s] ", (unsigned long) timestamp,
+ src_addr);
+
+ if (conn->request_info.request_method != NULL) {
+ fprintf(fp, "%s %s: ", conn->request_info.request_method,
+ conn->request_info.uri);
+ }
+
+ fprintf(fp, "%s", buf);
+ fputc('\n', fp);
+ funlockfile(fp);
+ fclose(fp);
+ }
+ }
+}
+
+/* Return fake connection structure. Used for logging, if connection
+ is not applicable at the moment of logging. */
+static struct mg_connection *fc(struct mg_context *ctx)
+{
+ static struct mg_connection fake_connection;
+ fake_connection.ctx = ctx;
+ return &fake_connection;
+}
+
+const char *mg_version(void)
+{
+ return CIVETWEB_VERSION;
+}
+
+struct mg_request_info *mg_get_request_info(struct mg_connection *conn)
+{
+ return &conn->request_info;
+}
+
+/* Skip the characters until one of the delimiters characters found.
+ 0-terminate resulting word. Skip the delimiter and following whitespaces.
+ Advance pointer to buffer to the next word. Return found 0-terminated word.
+ Delimiters can be quoted with quotechar. */
+static char *skip_quoted(char **buf, const char *delimiters,
+ const char *whitespace, char quotechar)
+{
+ char *p, *begin_word, *end_word, *end_whitespace;
+
+ begin_word = *buf;
+ end_word = begin_word + strcspn(begin_word, delimiters);
+
+ /* Check for quotechar */
+ if (end_word > begin_word) {
+ p = end_word - 1;
+ while (*p == quotechar) {
+ /* TODO (bel): it seems this code is never reached, so quotechar is actually
+ not needed - check if this code may be droped */
+
+ /* If there is anything beyond end_word, copy it */
+ if (*end_word == '\0') {
+ *p = '\0';
+ break;
+ } else {
+ size_t end_off = strcspn(end_word + 1, delimiters);
+ memmove (p, end_word, end_off + 1);
+ p += end_off; /* p must correspond to end_word - 1 */
+ end_word += end_off + 1;
+ }
+ }
+ for (p++; p < end_word; p++) {
+ *p = '\0';
+ }
+ }
+
+ if (*end_word == '\0') {
+ *buf = end_word;
+ } else {
+ end_whitespace = end_word + 1 + strspn(end_word + 1, whitespace);
+
+ for (p = end_word; p < end_whitespace; p++) {
+ *p = '\0';
+ }
+
+ *buf = end_whitespace;
+ }
+
+ return begin_word;
+}
+
+/* Simplified version of skip_quoted without quote char
+ and whitespace == delimiters */
+static char *skip(char **buf, const char *delimiters)
+{
+ return skip_quoted(buf, delimiters, delimiters, 0);
+}
+
+
+/* Return HTTP header value, or NULL if not found. */
+static const char *get_header(const struct mg_request_info *ri,
+ const char *name)
+{
+ int i;
+
+ for (i = 0; i < ri->num_headers; i++)
+ if (!mg_strcasecmp(name, ri->http_headers[i].name))
+ return ri->http_headers[i].value;
+
+ return NULL;
+}
+
+const char *mg_get_header(const struct mg_connection *conn, const char *name)
+{
+ return get_header(&conn->request_info, name);
+}
+
+/* A helper function for traversing a comma separated list of values.
+ It returns a list pointer shifted to the next value, or NULL if the end
+ of the list found.
+ Value is stored in val vector. If value has form "x=y", then eq_val
+ vector is initialized to point to the "y" part, and val vector length
+ is adjusted to point only to "x". */
+static const char *next_option(const char *list, struct vec *val,
+ struct vec *eq_val)
+{
+ if (list == NULL || *list == '\0') {
+ /* End of the list */
+ list = NULL;
+ } else {
+ val->ptr = list;
+ if ((list = strchr(val->ptr, ',')) != NULL) {
+ /* Comma found. Store length and shift the list ptr */
+ val->len = list - val->ptr;
+ list++;
+ } else {
+ /* This value is the last one */
+ list = val->ptr + strlen(val->ptr);
+ val->len = list - val->ptr;
+ }
+
+ if (eq_val != NULL) {
+ /* Value has form "x=y", adjust pointers and lengths
+ so that val points to "x", and eq_val points to "y". */
+ eq_val->len = 0;
+ eq_val->ptr = (const char *) memchr(val->ptr, '=', val->len);
+ if (eq_val->ptr != NULL) {
+ eq_val->ptr++; /* Skip over '=' character */
+ eq_val->len = val->ptr + val->len - eq_val->ptr;
+ val->len = (eq_val->ptr - val->ptr) - 1;
+ }
+ }
+ }
+
+ return list;
+}
+
+/* Perform case-insensitive match of string against pattern */
+static int match_prefix(const char *pattern, int pattern_len, const char *str)
+{
+ const char *or_str;
+ int i, j, len, res;
+
+ if ((or_str = (const char *) memchr(pattern, '|', pattern_len)) != NULL) {
+ res = match_prefix(pattern, (int)(or_str - pattern), str);
+ return res > 0 ? res :
+ match_prefix(or_str + 1, (int)((pattern + pattern_len) - (or_str + 1)), str);
+ }
+
+ i = j = 0;
+ for (; i < pattern_len; i++, j++) {
+ if (pattern[i] == '?' && str[j] != '\0') {
+ continue;
+ } else if (pattern[i] == '$') {
+ return str[j] == '\0' ? j : -1;
+ } else if (pattern[i] == '*') {
+ i++;
+ if (pattern[i] == '*') {
+ i++;
+ len = (int) strlen(str + j);
+ } else {
+ len = (int) strcspn(str + j, "/");
+ }
+ if (i == pattern_len) {
+ return j + len;
+ }
+ do {
+ res = match_prefix(pattern + i, pattern_len - i, str + j + len);
+ } while (res == -1 && len-- > 0);
+ return res == -1 ? -1 : j + res + len;
+ } else if (lowercase(&pattern[i]) != lowercase(&str[j])) {
+ return -1;
+ }
+ }
+ return j;
+}
+
+/* HTTP 1.1 assumes keep alive if "Connection:" header is not set
+ This function must tolerate situations when connection info is not
+ set up, for example if request parsing failed. */
+static int should_keep_alive(const struct mg_connection *conn)
+{
+ const char *http_version = conn->request_info.http_version;
+ const char *header = mg_get_header(conn, "Connection");
+ if (conn->must_close ||
+ conn->status_code == 401 ||
+ mg_strcasecmp(conn->ctx->config[ENABLE_KEEP_ALIVE], "yes") != 0 ||
+ (header != NULL && mg_strcasecmp(header, "keep-alive") != 0) ||
+ (header == NULL && http_version && 0!=strcmp(http_version, "1.1"))) {
+ return 0;
+ }
+ return 1;
+}
+
+static int should_decode_url(const struct mg_connection *conn)
+{
+ return (mg_strcasecmp(conn->ctx->config[DECODE_URL], "yes") == 0);
+}
+
+static const char *suggest_connection_header(const struct mg_connection *conn)
+{
+ return should_keep_alive(conn) ? "keep-alive" : "close";
+}
+
+static void handle_file_based_request(struct mg_connection *conn, const char *path, struct file *filep);
+static int mg_stat(struct mg_connection *conn, const char *path, struct file *filep);
+
+static const char *mg_get_response_code_text(int response_code, struct mg_connection *conn)
+{
+ switch (response_code)
+ {
+ /* RFC2616 Section 10.1 - Informational 1xx */
+ case 100: return "Continue"; /* RFC2616 Section 10.1.1 */
+ case 101: return "Switching Protocols"; /* RFC2616 Section 10.1.2 */
+ case 102: return "Processing"; /* RFC2518 Section 10.1 */
+
+ /* RFC2616 Section 10.2 - Successful 2xx */
+ case 200: return "OK"; /* RFC2616 Section 10.2.1 */
+ case 201: return "Created"; /* RFC2616 Section 10.2.2 */
+ case 202: return "Accepted"; /* RFC2616 Section 10.2.3 */
+ case 203: return "Non-Authoritative Information"; /* RFC2616 Section 10.2.4 */
+ case 204: return "No Content"; /* RFC2616 Section 10.2.5 */
+ case 205: return "Reset Content"; /* RFC2616 Section 10.2.6 */
+ case 206: return "Partial Content"; /* RFC2616 Section 10.2.7 */
+ case 207: return "Multi-Status"; /* RFC2518 Section 10.2, RFC4918 Section 11.1 */
+
+ /* RFC2616 Section 10.3 - Redirection 3xx */
+ case 300: return "Multiple Choices"; /* RFC2616 Section 10.3.1 */
+ case 301: return "Moved Permanently"; /* RFC2616 Section 10.3.2 */
+ case 302: return "Found"; /* RFC2616 Section 10.3.3 */
+ case 303: return "See Other"; /* RFC2616 Section 10.3.4 */
+ case 304: return "Not Modified"; /* RFC2616 Section 10.3.5 */
+ case 305: return "Use Proxy"; /* RFC2616 Section 10.3.6 */
+ case 307: return "Temporary Redirect"; /* RFC2616 Section 10.3.8 */
+
+ /* RFC2616 Section 10.4 - Client Error 4xx */
+ case 400: return "Bad Request"; /* RFC2616 Section 10.4.1 */
+ case 401: return "Unauthorized"; /* RFC2616 Section 10.4.2 */
+ case 402: return "Payment Required"; /* RFC2616 Section 10.4.3 */
+ case 403: return "Forbidden"; /* RFC2616 Section 10.4.4 */
+ case 404: return "Not Found"; /* RFC2616 Section 10.4.5 */
+ case 405: return "Method Not Allowed"; /* RFC2616 Section 10.4.6 */
+ case 406: return "Not Acceptable"; /* RFC2616 Section 10.4.7 */
+ case 407: return "Proxy Authentication Required"; /* RFC2616 Section 10.4.8 */
+ case 408: return "Request Time-out"; /* RFC2616 Section 10.4.9 */
+ case 409: return "Conflict"; /* RFC2616 Section 10.4.10 */
+ case 410: return "Gone"; /* RFC2616 Section 10.4.11 */
+ case 411: return "Length Required"; /* RFC2616 Section 10.4.12 */
+ case 412: return "Precondition Failed"; /* RFC2616 Section 10.4.13 */
+ case 413: return "Request Entity Too Large"; /* RFC2616 Section 10.4.14 */
+ case 414: return "Request-URI Too Large"; /* RFC2616 Section 10.4.15 */
+ case 415: return "Unsupported Media Type"; /* RFC2616 Section 10.4.16 */
+ case 416: return "Requested range not satisfiable"; /* RFC2616 Section 10.4.17 */
+ case 417: return "Expectation Failed"; /* RFC2616 Section 10.4.18 */
+ case 422: return "Unproccessable entity"; /* RFC2518 Section 10.3, RFC4918 Section 11.2 */
+ case 423: return "Locked"; /* RFC2518 Section 10.4, RFC4918 Section 11.3 */
+ case 424: return "Failed Dependency"; /* RFC2518 Section 10.5, RFC4918 Section 11.4 */
+ case 428: return "Precondition Required"; /* RFC 6585, Section 3 */
+ case 429: return "Too Many Requests"; /* RFC 6585, Section 4 */
+ case 431: return "Request Header Fields Too Large"; /* RFC 6585, Section 5 */
+
+ /* RFC2616 Section 10.5 - Server Error 5xx */
+ case 500: return "Internal Server Error"; /* RFC2616 Section 10.5.1 */
+ case 501: return "Not Implemented"; /* RFC2616 Section 10.5.2 */
+ case 502: return "Bad Gateway"; /* RFC2616 Section 10.5.3 */
+ case 503: return "Service Unavailable"; /* RFC2616 Section 10.5.4 */
+ case 504: return "Gateway Time-out"; /* RFC2616 Section 10.5.5 */
+ case 505: return "HTTP Version not supported"; /* RFC2616 Section 10.5.6 */
+ case 507: return "Insufficient Storage"; /* RFC2518 Section 10.6, , RFC4918 Section 11.5 */
+ case 511: return "Network Authentication Required"; /* RFC 6585, Section 6 */
+
+ /* Other RFCs */
+ case 426: return "Upgrade Required"; /* RFC 2817 */
+
+ /* Return codes from non normative RFCs: */
+ /* Informative and experimental RFCs, "de facto" standards due to common use, ... */
+ case 208: return "Already Reported"; /* RFC5842 Section 7.1 */
+ case 226: return "IM used"; /* RFC3229 Section 10.4.1 */
+ case 308: return "Permanent Redirect"; /* RFC7238 Section 3 */
+ case 418: return "I am a teapot"; /* RFC2324 Section 2.3.2 */
+ case 419: return "Authentication Timeout"; /* common use */
+ case 451: return "Unavailable For Legal Reasons"; /* draft-tbray-http-legally-restricted-status-05, Section 3 */
+ case 506: return "Variant Also Negotiates"; /* RFC 2295, Section 8.1 */
+ case 508: return "Loop Detected"; /* RFC5842 Section 7.1 */
+ case 510: return "Not Extended"; /* RFC 2774, Section 7 */
+
+ default:
+ /* This error code is unknown. This should not happen. */
+ if (conn) {
+ mg_cry(conn, "Unknown HTTP response code: %u", response_code);
+ }
+
+ /* Return at least a category according to RFC 2616 Section 10. */
+ if (response_code>=100 && response_code<200) {
+ /* Unknown informational status code */
+ return "Information";
+ }
+ if (response_code>=200 && response_code<300) {
+ /* Unknown success code */
+ return "Success";
+ }
+ if (response_code>=300 && response_code<400) {
+ /* Unknown redirection code */
+ return "Redirection";
+ }
+ if (response_code>=400 && response_code<500) {
+ /* Unknown request error code */
+ return "Client Error";
+ }
+ if (response_code>=500 && response_code<600) {
+ /* Unknown server error code */
+ return "Server Error";
+ }
+
+ /* Response code not even within reasonable range */
+ return "";
+ }
+}
+
+
+static void send_http_error(struct mg_connection *, int, const char *,
+ PRINTF_FORMAT_STRING(const char *fmt), ...)
+PRINTF_ARGS(4, 5);
+
+
+static void send_http_error(struct mg_connection *conn, int status,
+ const char *reason, const char *fmt, ...)
+{
+ char buf[MG_BUF_LEN];
+ va_list ap;
+ int len = 0, i, page_handler_found, scope;
+ char date[64];
+ time_t curtime = time(NULL);
+ const char *error_handler = NULL;
+ struct file error_page_file = STRUCT_FILE_INITIALIZER;
+ const char *error_page_file_ext, *tstr;
+
+ if (!reason) {
+ reason = mg_get_response_code_text(status, conn);
+ }
+
+ conn->status_code = status;
+ if (conn->in_error_handler ||
+ conn->ctx->callbacks.http_error == NULL ||
+ conn->ctx->callbacks.http_error(conn, status)) {
+
+ if (!conn->in_error_handler) {
+ /* Send user defined error pages, if defined */
+ error_handler = conn->ctx->config[ERROR_PAGES];
+ error_page_file_ext = conn->ctx->config[INDEX_FILES];
+ page_handler_found = 0;
+ if (error_handler != NULL) {
+ for (scope=1; (scope<=3) && !page_handler_found; scope++) {
+ switch (scope) {
+ case 1:
+ len = mg_snprintf(conn, buf, sizeof(buf)-32, "%serror%03u.", error_handler, status);
+ break;
+ case 2:
+ len = mg_snprintf(conn, buf, sizeof(buf)-32, "%serror%01uxx.", error_handler, status/100);
+ break;
+ default:
+ len = mg_snprintf(conn, buf, sizeof(buf)-32, "%serror.", error_handler);
+ break;
+ }
+ tstr = strchr(error_page_file_ext, '.');
+ while (tstr) {
+ for (i=1; i<32 && tstr[i]!=0 && tstr[i]!=','; i++) buf[len+i-1]=tstr[i];
+ buf[len+i-1]=0;
+ if (mg_stat(conn, buf, &error_page_file)) {
+ page_handler_found = 1;
+ break;
+ }
+ tstr = strchr(tstr+i, '.');
+ }
+ }
+ }
+
+ if (page_handler_found) {
+ conn->in_error_handler = 1;
+ handle_file_based_request(conn, buf, &error_page_file);
+ conn->in_error_handler = 0;
+ return;
+ }
+ }
+
+ buf[0] = '\0';
+ gmt_time_string(date, sizeof(date), &curtime);
+
+ /* Errors 1xx, 204 and 304 MUST NOT send a body */
+ if (status > 199 && status != 204 && status != 304) {
+ len = mg_snprintf(conn, buf, sizeof(buf)-1, "Error %d: %s", status, reason);
+ buf[len] = '\n';
+ len++;
+ buf[len] = 0;
+
+ va_start(ap, fmt);
+ len += mg_vsnprintf(conn, buf + len, sizeof(buf) - len, fmt, ap);
+ va_end(ap);
+ }
+ DEBUG_TRACE("[%s]", buf);
+
+ mg_printf(conn, "HTTP/1.1 %d %s\r\n"
+ "Content-Length: %d\r\n"
+ "Date: %s\r\n"
+ "Connection: %s\r\n\r\n",
+ status, reason, len, date,
+ suggest_connection_header(conn));
+ conn->num_bytes_sent += mg_printf(conn, "%s", buf);
+ }
+}
+
+#if defined(_WIN32) && !defined(__SYMBIAN32__)
+static int pthread_mutex_init(pthread_mutex_t *mutex, void *unused)
+{
+ (void) unused;
+ *mutex = CreateMutex(NULL, FALSE, NULL);
+ return *mutex == NULL ? -1 : 0;
+}
+
+static int pthread_mutex_destroy(pthread_mutex_t *mutex)
+{
+ return CloseHandle(*mutex) == 0 ? -1 : 0;
+}
+
+static int pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+ return WaitForSingleObject(*mutex, INFINITE) == WAIT_OBJECT_0 ? 0 : -1;
+}
+
+static int pthread_mutex_trylock(pthread_mutex_t *mutex)
+{
+ switch (WaitForSingleObject(*mutex, 0)) {
+ case WAIT_OBJECT_0:
+ return 0;
+ case WAIT_TIMEOUT:
+ return -2; /* EBUSY */
+ }
+ return -1;
+}
+
+static int pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+ return ReleaseMutex(*mutex) == 0 ? -1 : 0;
+}
+
+#ifndef WIN_PTHREADS_TIME_H
+static int clock_gettime(clockid_t clk_id, struct timespec *tp)
+{
+ FILETIME ft;
+ ULARGE_INTEGER li;
+ BOOL ok = FALSE;
+ double d;
+ static double perfcnt_per_sec = 0.0;
+
+ if (tp) {
+ if (clk_id == CLOCK_REALTIME) {
+ GetSystemTimeAsFileTime(&ft);
+ li.LowPart = ft.dwLowDateTime;
+ li.HighPart = ft.dwHighDateTime;
+ li.QuadPart -= 116444736000000000; /* 1.1.1970 in filedate */
+ tp->tv_sec = (time_t)(li.QuadPart / 10000000);
+ tp->tv_nsec = (long)(li.QuadPart % 10000000) * 100;
+ ok = TRUE;
+ } else if (clk_id == CLOCK_MONOTONIC) {
+ if (perfcnt_per_sec == 0.0) {
+ QueryPerformanceFrequency((LARGE_INTEGER *) &li);
+ perfcnt_per_sec = 1.0 / li.QuadPart;
+ }
+ if (perfcnt_per_sec != 0.0) {
+ QueryPerformanceCounter((LARGE_INTEGER *) &li);
+ d = li.QuadPart * perfcnt_per_sec;
+ tp->tv_sec = (time_t)d;
+ d -= tp->tv_sec;
+ tp->tv_nsec = (long)(d*1.0E9);
+ ok = TRUE;
+ }
+ }
+ }
+
+ return ok ? 0 : -1;
+}
+#endif
+
+static int pthread_cond_init(pthread_cond_t *cv, const void *unused)
+{
+ (void) unused;
+ InitializeCriticalSection(&cv->threadIdSec);
+ cv->waitingthreadcount = 0;
+ cv->waitingthreadhdls = (pthread_t *) mg_calloc(MAX_WORKER_THREADS, sizeof(pthread_t));
+ return (cv->waitingthreadhdls!=NULL) ? 0 : -1;
+}
+
+static int pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t *mutex, const struct timespec * abstime)
+{
+ struct mg_workerTLS * tls = (struct mg_workerTLS *)TlsGetValue(sTlsKey);
+ int ok;
+ struct timespec tsnow;
+ int64_t nsnow, nswaitabs, nswaitrel;
+ DWORD mswaitrel;
+
+ EnterCriticalSection(&cv->threadIdSec);
+ assert(cv->waitingthreadcount < MAX_WORKER_THREADS);
+ cv->waitingthreadhdls[cv->waitingthreadcount] = tls->pthread_cond_helper_mutex;
+ cv->waitingthreadcount++;
+ LeaveCriticalSection(&cv->threadIdSec);
+
+ if (abstime) {
+ clock_gettime(CLOCK_REALTIME, &tsnow);
+ nsnow = (((uint64_t)tsnow.tv_sec)*1000000000) + tsnow.tv_nsec;
+ nswaitabs = (((uint64_t)abstime->tv_sec)*1000000000) + abstime->tv_nsec;
+ nswaitrel = nswaitabs - nsnow;
+ if (nswaitrel<0) nswaitrel=0;
+ mswaitrel = (DWORD)(nswaitrel / 1000000);
+ } else {
+ mswaitrel = INFINITE;
+ }
+
+ pthread_mutex_unlock(mutex);
+ ok = (WAIT_OBJECT_0 == WaitForSingleObject(tls->pthread_cond_helper_mutex, mswaitrel));
+ pthread_mutex_lock(mutex);
+
+ return ok ? 0 : -1;
+}
+
+static int pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex)
+{
+ return pthread_cond_timedwait(cv, mutex, NULL);
+}
+
+static int pthread_cond_signal(pthread_cond_t *cv)
+{
+ int i;
+ HANDLE wkup = NULL;
+ BOOL ok = FALSE;
+
+ EnterCriticalSection(&cv->threadIdSec);
+ if (cv->waitingthreadcount) {
+ wkup = cv->waitingthreadhdls[0];
+ ok = SetEvent(wkup);
+
+ for (i=1; i<cv->waitingthreadcount; i++) {
+ cv->waitingthreadhdls[i-1] = cv->waitingthreadhdls[i];
+ }
+ cv->waitingthreadcount--;
+
+ assert(ok);
+ }
+ LeaveCriticalSection(&cv->threadIdSec);
+
+ return ok ? 0 : 1;
+}
+
+static int pthread_cond_broadcast(pthread_cond_t *cv)
+{
+ EnterCriticalSection(&cv->threadIdSec);
+ while (cv->waitingthreadcount) {
+ pthread_cond_signal(cv);
+ }
+ LeaveCriticalSection(&cv->threadIdSec);
+
+ return 0;
+}
+
+static int pthread_cond_destroy(pthread_cond_t *cv)
+{
+ EnterCriticalSection(&cv->threadIdSec);
+ assert(cv->waitingthreadcount==0);
+ mg_free(cv->waitingthreadhdls);
+ cv->waitingthreadhdls = 0;
+ LeaveCriticalSection(&cv->threadIdSec);
+ DeleteCriticalSection(&cv->threadIdSec);
+
+ return 0;
+}
+
+/* For Windows, change all slashes to backslashes in path names. */
+static void change_slashes_to_backslashes(char *path)
+{
+ int i;
+
+ for (i = 0; path[i] != '\0'; i++) {
+ if (path[i] == '/')
+ path[i] = '\\';
+ /* i > 0 check is to preserve UNC paths, like \\server\file.txt */
+ if (path[i] == '\\' && i > 0)
+ while (path[i + 1] == '\\' || path[i + 1] == '/')
+ (void) memmove(path + i + 1,
+ path + i + 2, strlen(path + i + 1));
+ }
+}
+
+/* Encode 'path' which is assumed UTF-8 string, into UNICODE string.
+ wbuf and wbuf_len is a target buffer and its length. */
+static void to_unicode(const char *path, wchar_t *wbuf, size_t wbuf_len)
+{
+ char buf[PATH_MAX], buf2[PATH_MAX];
+
+ mg_strlcpy(buf, path, sizeof(buf));
+ change_slashes_to_backslashes(buf);
+
+ /* Convert to Unicode and back. If doubly-converted string does not
+ match the original, something is fishy, reject. */
+ memset(wbuf, 0, wbuf_len * sizeof(wchar_t));
+ MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, (int) wbuf_len);
+ WideCharToMultiByte(CP_UTF8, 0, wbuf, (int) wbuf_len, buf2, sizeof(buf2),
+ NULL, NULL);
+ if (strcmp(buf, buf2) != 0) {
+ wbuf[0] = L'\0';
+ }
+}
+
+#if defined(_WIN32_WCE)
+static time_t time(time_t *ptime)
+{
+ time_t t;
+ SYSTEMTIME st;
+ FILETIME ft;
+
+ GetSystemTime(&st);
+ SystemTimeToFileTime(&st, &ft);
+ t = SYS2UNIX_TIME(ft.dwLowDateTime, ft.dwHighDateTime);
+
+ if (ptime != NULL) {
+ *ptime = t;
+ }
+
+ return t;
+}
+
+static struct tm *localtime(const time_t *ptime, struct tm *ptm)
+{
+ int64_t t = ((int64_t) *ptime) * RATE_DIFF + EPOCH_DIFF;
+ FILETIME ft, lft;
+ SYSTEMTIME st;
+ TIME_ZONE_INFORMATION tzinfo;
+
+ if (ptm == NULL) {
+ return NULL;
+ }
+
+ * (int64_t *) &ft = t;
+ FileTimeToLocalFileTime(&ft, &lft);
+ FileTimeToSystemTime(&lft, &st);
+ ptm->tm_year = st.wYear - 1900;
+ ptm->tm_mon = st.wMonth - 1;
+ ptm->tm_wday = st.wDayOfWeek;
+ ptm->tm_mday = st.wDay;
+ ptm->tm_hour = st.wHour;
+ ptm->tm_min = st.wMinute;
+ ptm->tm_sec = st.wSecond;
+ ptm->tm_yday = 0; /* hope nobody uses this */
+ ptm->tm_isdst =
+ GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_DAYLIGHT ? 1 : 0;
+
+ return ptm;
+}
+
+static struct tm *gmtime(const time_t *ptime, struct tm *ptm)
+{
+ /* FIXME(lsm): fix this. */
+ return localtime(ptime, ptm);
+}
+
+static size_t strftime(char *dst, size_t dst_size, const char *fmt,
+ const struct tm *tm)
+{
+ (void) snprintf(dst, dst_size, "implement strftime() for WinCE");
+ return 0;
+}
+#endif
+
+/* Windows happily opens files with some garbage at the end of file name.
+ For example, fopen("a.cgi ", "r") on Windows successfully opens
+ "a.cgi", despite one would expect an error back.
+ This function returns non-0 if path ends with some garbage. */
+static int path_cannot_disclose_cgi(const char *path)
+{
+ static const char *allowed_last_characters = "_-";
+ int last = path[strlen(path) - 1];
+ return isalnum(last) || strchr(allowed_last_characters, last) != NULL;
+}
+
+static int mg_stat(struct mg_connection *conn, const char *path, struct file *filep)
+{
+ wchar_t wbuf[PATH_MAX];
+ WIN32_FILE_ATTRIBUTE_DATA info;
+
+ if (!is_file_in_memory(conn, path, filep)) {
+ to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
+ if (GetFileAttributesExW(wbuf, GetFileExInfoStandard, &info) != 0) {
+ filep->size = MAKEUQUAD(info.nFileSizeLow, info.nFileSizeHigh);
+ filep->modification_time = SYS2UNIX_TIME(
+ info.ftLastWriteTime.dwLowDateTime,
+ info.ftLastWriteTime.dwHighDateTime);
+ filep->is_directory = info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
+ /* If file name is fishy, reset the file structure and return
+ error.
+ Note it is important to reset, not just return the error, cause
+ functions like is_file_opened() check the struct. */
+ if (!filep->is_directory && !path_cannot_disclose_cgi(path)) {
+ memset(filep, 0, sizeof(*filep));
+ }
+ }
+ }
+
+ return filep->membuf != NULL || filep->modification_time != 0;
+}
+
+static int mg_remove(const char *path)
+{
+ wchar_t wbuf[PATH_MAX];
+ to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
+ return DeleteFileW(wbuf) ? 0 : -1;
+}
+
+static int mg_mkdir(const char *path, int mode)
+{
+ char buf[PATH_MAX];
+ wchar_t wbuf[PATH_MAX];
+
+ (void) mode;
+ mg_strlcpy(buf, path, sizeof(buf));
+ change_slashes_to_backslashes(buf);
+
+ (void) MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, ARRAY_SIZE(wbuf));
+
+ return CreateDirectoryW(wbuf, NULL) ? 0 : -1;
+}
+
+/* Implementation of POSIX opendir/closedir/readdir for Windows. */
+static DIR * opendir(const char *name)
+{
+ DIR *dir = NULL;
+ wchar_t wpath[PATH_MAX];
+ DWORD attrs;
+
+ if (name == NULL) {
+ SetLastError(ERROR_BAD_ARGUMENTS);
+ } else if ((dir = (DIR *) mg_malloc(sizeof(*dir))) == NULL) {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ } else {
+ to_unicode(name, wpath, ARRAY_SIZE(wpath));
+ attrs = GetFileAttributesW(wpath);
+ if (attrs != 0xFFFFFFFF &&
+ ((attrs & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)) {
+ (void) wcscat(wpath, L"\\*");
+ dir->handle = FindFirstFileW(wpath, &dir->info);
+ dir->result.d_name[0] = '\0';
+ } else {
+ mg_free(dir);
+ dir = NULL;
+ }
+ }
+
+ return dir;
+}
+
+static int closedir(DIR *dir)
+{
+ int result = 0;
+
+ if (dir != NULL) {
+ if (dir->handle != INVALID_HANDLE_VALUE)
+ result = FindClose(dir->handle) ? 0 : -1;
+
+ mg_free(dir);
+ } else {
+ result = -1;
+ SetLastError(ERROR_BAD_ARGUMENTS);
+ }
+
+ return result;
+}
+
+static struct dirent *readdir(DIR *dir)
+{
+ struct dirent *result = 0;
+
+ if (dir) {
+ if (dir->handle != INVALID_HANDLE_VALUE) {
+ result = &dir->result;
+ (void) WideCharToMultiByte(CP_UTF8, 0,
+ dir->info.cFileName, -1, result->d_name,
+ sizeof(result->d_name), NULL, NULL);
+
+ if (!FindNextFileW(dir->handle, &dir->info)) {
+ (void) FindClose(dir->handle);
+ dir->handle = INVALID_HANDLE_VALUE;
+ }
+
+ } else {
+ SetLastError(ERROR_FILE_NOT_FOUND);
+ }
+ } else {
+ SetLastError(ERROR_BAD_ARGUMENTS);
+ }
+
+ return result;
+}
+
+#ifndef HAVE_POLL
+static int poll(struct pollfd *pfd, int n, int milliseconds)
+{
+ struct timeval tv;
+ fd_set set;
+ int i, result;
+ SOCKET maxfd = 0;
+
+ tv.tv_sec = milliseconds / 1000;
+ tv.tv_usec = (milliseconds % 1000) * 1000;
+ FD_ZERO(&set);
+
+ for (i = 0; i < n; i++) {
+ FD_SET((SOCKET) pfd[i].fd, &set);
+ pfd[i].revents = 0;
+
+ if (pfd[i].fd > maxfd) {
+ maxfd = pfd[i].fd;
+ }
+ }
+
+ if ((result = select((int)maxfd + 1, &set, NULL, NULL, &tv)) > 0) {
+ for (i = 0; i < n; i++) {
+ if (FD_ISSET(pfd[i].fd, &set)) {
+ pfd[i].revents = POLLIN;
+ }
+ }
+ }
+
+ return result;
+}
+#endif /* HAVE_POLL */
+
+static void set_close_on_exec(SOCKET sock, struct mg_connection *conn /* may be null */)
+{
+ (void) conn; /* Unused. */
+ (void) SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0);
+}
+
+int mg_start_thread(mg_thread_func_t f, void *p)
+{
+#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
+ /* Compile-time option to control stack size, e.g. -DUSE_STACK_SIZE=16384 */
+ return ((_beginthread((void (__cdecl *)(void *)) f, USE_STACK_SIZE, p) == ((uintptr_t)(-1L))) ? -1 : 0);
+#else
+ return ((_beginthread((void (__cdecl *)(void *)) f, 0, p) == ((uintptr_t)(-1L))) ? -1 : 0);
+#endif /* defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1) */
+}
+
+/* Start a thread storing the thread context. */
+
+static int mg_start_thread_with_id(unsigned (__stdcall *f)(void *), void *p,
+ pthread_t *threadidptr)
+{
+ uintptr_t uip;
+ HANDLE threadhandle;
+ int result = -1;
+
+ uip = _beginthreadex(NULL, 0, (unsigned (__stdcall *)(void *)) f, p, 0,
+ NULL);
+ threadhandle = (HANDLE) uip;
+ if ((uip != (uintptr_t)(-1L)) && (threadidptr != NULL)) {
+ *threadidptr = threadhandle;
+ result = 0;
+ }
+
+ return result;
+}
+
+/* Wait for a thread to finish. */
+
+static int mg_join_thread(pthread_t threadid)
+{
+ int result;
+ DWORD dwevent;
+
+ result = -1;
+ dwevent = WaitForSingleObject(threadid, INFINITE);
+ if (dwevent == WAIT_FAILED) {
+ int err;
+
+ err = GetLastError();
+ DEBUG_TRACE("WaitForSingleObject() failed, error %d", err);
+ } else {
+ if (dwevent == WAIT_OBJECT_0) {
+ CloseHandle(threadid);
+ result = 0;
+ }
+ }
+
+ return result;
+}
+
+static HANDLE dlopen(const char *dll_name, int flags)
+{
+ wchar_t wbuf[PATH_MAX];
+ (void) flags;
+ to_unicode(dll_name, wbuf, ARRAY_SIZE(wbuf));
+ return LoadLibraryW(wbuf);
+}
+
+static int dlclose(void *handle)
+{
+ int result;
+
+ if (FreeLibrary((HMODULE) handle) != 0) {
+ result = 0;
+ } else {
+ result = -1;
+ }
+
+ return result;
+}
+
+#if !defined(NO_CGI)
+#define SIGKILL 0
+static int kill(pid_t pid, int sig_num)
+{
+ (void) TerminateProcess(pid, sig_num);
+ (void) CloseHandle(pid);
+ return 0;
+}
+
+static void trim_trailing_whitespaces(char *s)
+{
+ char *e = s + strlen(s) - 1;
+ while (e > s && isspace(* (unsigned char *) e)) {
+ *e-- = '\0';
+ }
+}
+
+static pid_t spawn_process(struct mg_connection *conn, const char *prog,
+ char *envblk, char *envp[], int fdin,
+ int fdout, const char *dir)
+{
+ HANDLE me;
+ char *p, *interp, full_interp[PATH_MAX], full_dir[PATH_MAX],
+ cmdline[PATH_MAX], buf[PATH_MAX];
+ struct file file = STRUCT_FILE_INITIALIZER;
+ STARTUPINFOA si;
+ PROCESS_INFORMATION pi = { 0 };
+
+ (void) envp;
+
+ memset(&si, 0, sizeof(si));
+ si.cb = sizeof(si);
+
+ /* TODO(lsm): redirect CGI errors to the error log file */
+ si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
+ si.wShowWindow = SW_HIDE;
+
+ me = GetCurrentProcess();
+ DuplicateHandle(me, (HANDLE) _get_osfhandle(fdin), me,
+ &si.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS);
+ DuplicateHandle(me, (HANDLE) _get_osfhandle(fdout), me,
+ &si.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS);
+
+ /* If CGI file is a script, try to read the interpreter line */
+ interp = conn->ctx->config[CGI_INTERPRETER];
+ if (interp == NULL) {
+ buf[0] = buf[1] = '\0';
+
+ /* Read the first line of the script into the buffer */
+ snprintf(cmdline, sizeof(cmdline), "%s%c%s", dir, '/', prog);
+ if (mg_fopen(conn, cmdline, "r", &file)) {
+ p = (char *) file.membuf;
+ mg_fgets(buf, sizeof(buf), &file, &p);
+ mg_fclose(&file);
+ buf[sizeof(buf) - 1] = '\0';
+ }
+
+ if (buf[0] == '#' && buf[1] == '!') {
+ trim_trailing_whitespaces(buf + 2);
+ } else {
+ buf[2] = '\0';
+ }
+ interp = buf + 2;
+ }
+
+ if (interp[0] != '\0') {
+ GetFullPathNameA(interp, sizeof(full_interp), full_interp, NULL);
+ interp = full_interp;
+ }
+ GetFullPathNameA(dir, sizeof(full_dir), full_dir, NULL);
+
+ mg_snprintf(conn, cmdline, sizeof(cmdline), "%s%s\"%s\\%s\"",
+ interp, interp[0] == '\0' ? "" : " ", full_dir, prog);
+
+ DEBUG_TRACE("Running [%s]", cmdline);
+ if (CreateProcessA(NULL, cmdline, NULL, NULL, TRUE,
+ CREATE_NEW_PROCESS_GROUP, envblk, NULL, &si, &pi) == 0) {
+ mg_cry(conn, "%s: CreateProcess(%s): %ld",
+ __func__, cmdline, ERRNO);
+ pi.hProcess = (pid_t) -1;
+ }
+
+ (void) CloseHandle(si.hStdOutput);
+ (void) CloseHandle(si.hStdInput);
+ if (pi.hThread != NULL)
+ (void) CloseHandle(pi.hThread);
+
+ return (pid_t) pi.hProcess;
+}
+#endif /* !NO_CGI */
+
+static int set_non_blocking_mode(SOCKET sock)
+{
+ unsigned long on = 1;
+ return ioctlsocket(sock, FIONBIO, &on);
+}
+
+#else
+static int mg_stat(struct mg_connection *conn, const char *path,
+ struct file *filep)
+{
+ struct stat st;
+
+ if (!is_file_in_memory(conn, path, filep) && !stat(path, &st)) {
+ filep->size = st.st_size;
+ filep->modification_time = st.st_mtime;
+ filep->is_directory = S_ISDIR(st.st_mode);
+ } else {
+ filep->modification_time = (time_t) 0;
+ }
+
+ return filep->membuf != NULL || filep->modification_time != (time_t) 0;
+}
+
+static void set_close_on_exec(int fd, struct mg_connection *conn /* may be null */)
+{
+ if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) {
+ if (conn) {
+ mg_cry(conn, "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s", __func__, strerror(ERRNO));
+ }
+ }
+}
+
+int mg_start_thread(mg_thread_func_t func, void *param)
+{
+ pthread_t thread_id;
+ pthread_attr_t attr;
+ int result;
+
+ (void) pthread_attr_init(&attr);
+ (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
+ /* Compile-time option to control stack size,
+ e.g. -DUSE_STACK_SIZE=16384 */
+ (void) pthread_attr_setstacksize(&attr, USE_STACK_SIZE);
+#endif /* defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1) */
+
+ result = pthread_create(&thread_id, &attr, func, param);
+ pthread_attr_destroy(&attr);
+
+ return result;
+}
+
+/* Start a thread storing the thread context. */
+
+static int mg_start_thread_with_id(mg_thread_func_t func, void *param, pthread_t *threadidptr)
+{
+ pthread_t thread_id;
+ pthread_attr_t attr;
+ int result;
+
+ (void) pthread_attr_init(&attr);
+
+#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
+ /* Compile-time option to control stack size,
+ e.g. -DUSE_STACK_SIZE=16384 */
+ (void) pthread_attr_setstacksize(&attr, USE_STACK_SIZE);
+#endif /* defined(USE_STACK_SIZE) && USE_STACK_SIZE > 1 */
+
+ result = pthread_create(&thread_id, &attr, func, param);
+ pthread_attr_destroy(&attr);
+ if ((result == 0) && (threadidptr != NULL)) {
+ *threadidptr = thread_id;
+ }
+ return result;
+}
+
+/* Wait for a thread to finish. */
+
+static int mg_join_thread(pthread_t threadid)
+{
+ int result;
+
+ result = pthread_join(threadid, NULL);
+ return result;
+}
+
+#ifndef NO_CGI
+static pid_t spawn_process(struct mg_connection *conn, const char *prog,
+ char *envblk, char *envp[], int fdin,
+ int fdout, const char *dir)
+{
+ pid_t pid;
+ const char *interp;
+
+ (void) envblk;
+
+ if ((pid = fork()) == -1) {
+ /* Parent */
+ send_http_error(conn, 500, NULL,
+ "Error: Creating CGI process\nfork(): %s", strerror(ERRNO));
+ } else if (pid == 0) {
+ /* Child */
+ if (chdir(dir) != 0) {
+ mg_cry(conn, "%s: chdir(%s): %s", __func__, dir, strerror(ERRNO));
+ } else if (dup2(fdin, 0) == -1) {
+ mg_cry(conn, "%s: dup2(%d, 0): %s", __func__, fdin, strerror(ERRNO));
+ } else if (dup2(fdout, 1) == -1) {
+ mg_cry(conn, "%s: dup2(%d, 1): %s", __func__, fdout, strerror(ERRNO));
+ } else {
+ /* Not redirecting stderr to stdout, to avoid output being littered
+ with the error messages. */
+ (void) close(fdin);
+ (void) close(fdout);
+
+ /* After exec, all signal handlers are restored to their default
+ values, with one exception of SIGCHLD. According to
+ POSIX.1-2001 and Linux's implementation, SIGCHLD's handler will
+ leave unchanged after exec if it was set to be ignored. Restore
+ it to default action. */
+ signal(SIGCHLD, SIG_DFL);
+
+ interp = conn->ctx->config[CGI_INTERPRETER];
+ if (interp == NULL) {
+ (void) execle(prog, prog, NULL, envp);
+ mg_cry(conn, "%s: execle(%s): %s", __func__, prog, strerror(ERRNO));
+ } else {
+ (void) execle(interp, interp, prog, NULL, envp);
+ mg_cry(conn, "%s: execle(%s %s): %s", __func__, interp, prog,
+ strerror(ERRNO));
+ }
+ }
+ exit(EXIT_FAILURE);
+ }
+
+ return pid;
+}
+#endif /* !NO_CGI */
+
+static int set_non_blocking_mode(SOCKET sock)
+{
+ int flags;
+
+ flags = fcntl(sock, F_GETFL, 0);
+ (void) fcntl(sock, F_SETFL, flags | O_NONBLOCK);
+
+ return 0;
+}
+#endif /* _WIN32 */
+
+/* Write data to the IO channel - opened file descriptor, socket or SSL
+ descriptor. Return number of bytes written. */
+static int64_t push(FILE *fp, SOCKET sock, SSL *ssl, const char *buf, int64_t len)
+{
+ int64_t sent;
+ int n, k;
+
+ (void) ssl; /* Get rid of warning */
+ sent = 0;
+ while (sent < len) {
+
+ /* How many bytes we send in this iteration */
+ k = len - sent > INT_MAX ? INT_MAX : (int) (len - sent);
+
+#ifndef NO_SSL
+ if (ssl != NULL) {
+ n = SSL_write(ssl, buf + sent, k);
+ } else
+#endif
+ if (fp != NULL) {
+ n = (int) fwrite(buf + sent, 1, (size_t) k, fp);
+ if (ferror(fp))
+ n = -1;
+ } else {
+ n = send(sock, buf + sent, (size_t) k, MSG_NOSIGNAL);
+ }
+
+ if (n <= 0)
+ break;
+
+ sent += n;
+ }
+
+ return sent;
+}
+
+/* Read from IO channel - opened file descriptor, socket, or SSL descriptor.
+ Return negative value on error, or number of bytes read on success. */
+static int pull(FILE *fp, struct mg_connection *conn, char *buf, int len)
+{
+ int nread;
+
+ if (fp != NULL) {
+ /* Use read() instead of fread(), because if we're reading from the
+ CGI pipe, fread() may block until IO buffer is filled up. We cannot
+ afford to block and must pass all read bytes immediately to the
+ client. */
+ nread = read(fileno(fp), buf, (size_t) len);
+#ifndef NO_SSL
+ } else if (conn->ssl != NULL) {
+ nread = SSL_read(conn->ssl, buf, len);
+#endif
+ } else {
+ nread = recv(conn->client.sock, buf, (size_t) len, 0);
+ }
+
+ return conn->ctx->stop_flag ? -1 : nread;
+}
+
+static int pull_all(FILE *fp, struct mg_connection *conn, char *buf, int len)
+{
+ int n, nread = 0;
+
+ while (len > 0 && conn->ctx->stop_flag == 0) {
+ n = pull(fp, conn, buf + nread, len);
+ if (n < 0) {
+ nread = n; /* Propagate the error */
+ break;
+ } else if (n == 0) {
+ break; /* No more data to read */
+ } else {
+ conn->consumed_content += n;
+ nread += n;
+ len -= n;
+ }
+ }
+
+ return nread;
+}
+
+int mg_read(struct mg_connection *conn, void *buf, size_t len)
+{
+ int64_t n, buffered_len, nread;
+ int64_t len64 = (int64_t)(len > INT_MAX ? INT_MAX : len); /* since the return value is int, we may not read more bytes */
+ const char *body;
+
+ /* If Content-Length is not set for a PUT or POST request, read until socket is closed */
+ if (conn->consumed_content == 0 && conn->content_len == -1) {
+ conn->content_len = INT64_MAX;
+ conn->must_close = 1;
+ }
+
+ nread = 0;
+ if (conn->consumed_content < conn->content_len) {
+ /* Adjust number of bytes to read. */
+ int64_t left_to_read = conn->content_len - conn->consumed_content;
+ if (left_to_read < len64) {
+ /* Do not reade more than the total content length of the request. */
+ len64 = left_to_read;
+ }
+
+ /* Return buffered data */
+ buffered_len = (int64_t)(conn->data_len) - (int64_t)conn->request_len - conn->consumed_content;
+ if (buffered_len > 0) {
+ if (len64 < buffered_len) {
+ buffered_len = len64;
+ }
+ body = conn->buf + conn->request_len + conn->consumed_content;
+ memcpy(buf, body, (size_t) buffered_len);
+ len64 -= buffered_len;
+ conn->consumed_content += buffered_len;
+ nread += buffered_len;
+ buf = (char *) buf + buffered_len;
+ }
+
+ /* We have returned all buffered data. Read new data from the remote
+ socket. */
+ if ((n = pull_all(NULL, conn, (char *) buf, (int)len64)) >= 0) {
+ nread += n;
+ } else {
+ nread = (nread > 0 ? nread : n);
+ }
+ }
+ return (int)nread;
+}
+
+int mg_write(struct mg_connection *conn, const void *buf, size_t len)
+{
+ time_t now;
+ int64_t n, total, allowed;
+
+ if (conn->throttle > 0) {
+ if ((now = time(NULL)) != conn->last_throttle_time) {
+ conn->last_throttle_time = now;
+ conn->last_throttle_bytes = 0;
+ }
+ allowed = conn->throttle - conn->last_throttle_bytes;
+ if (allowed > (int64_t) len) {
+ allowed = len;
+ }
+ if ((total = push(NULL, conn->client.sock, conn->ssl, (const char *) buf,
+ (int64_t) allowed)) == allowed) {
+ buf = (char *) buf + total;
+ conn->last_throttle_bytes += total;
+ while (total < (int64_t) len && conn->ctx->stop_flag == 0) {
+ allowed = conn->throttle > (int64_t) len - total ?
+ (int64_t) len - total : conn->throttle;
+ if ((n = push(NULL, conn->client.sock, conn->ssl, (const char *) buf,
+ (int64_t) allowed)) != allowed) {
+ break;
+ }
+ sleep(1);
+ conn->last_throttle_bytes = allowed;
+ conn->last_throttle_time = time(NULL);
+ buf = (char *) buf + n;
+ total += n;
+ }
+ }
+ } else {
+ total = push(NULL, conn->client.sock, conn->ssl, (const char *) buf,
+ (int64_t) len);
+ }
+ return (int) total;
+}
+
+/* Alternative alloc_vprintf() for non-compliant C runtimes */
+static int alloc_vprintf2(char **buf, const char *fmt, va_list ap)
+{
+ va_list ap_copy;
+ int size = MG_BUF_LEN;
+ int len = -1;
+
+ *buf = NULL;
+ while (len == -1) {
+ if (*buf) mg_free(*buf);
+ *buf = (char *)mg_malloc(size *= 4);
+ if (!*buf) break;
+ va_copy(ap_copy, ap);
+ len = vsnprintf(*buf, size, fmt, ap_copy);
+ va_end(ap_copy);
+ }
+
+ return len;
+}
+
+/* Print message to buffer. If buffer is large enough to hold the message,
+ return buffer. If buffer is to small, allocate large enough buffer on heap,
+ and return allocated buffer. */
+static int alloc_vprintf(char **buf, size_t size, const char *fmt, va_list ap)
+{
+ va_list ap_copy;
+ int len;
+
+ /* Windows is not standard-compliant, and vsnprintf() returns -1 if
+ buffer is too small. Also, older versions of msvcrt.dll do not have
+ _vscprintf(). However, if size is 0, vsnprintf() behaves correctly.
+ Therefore, we make two passes: on first pass, get required message
+ length.
+ On second pass, actually print the message. */
+ va_copy(ap_copy, ap);
+ len = vsnprintf(NULL, 0, fmt, ap_copy);
+ va_end(ap_copy);
+
+ if (len < 0) {
+ /* C runtime is not standard compliant, vsnprintf() returned -1.
+ Switch to alternative code path that uses incremental allocations.
+ */
+ va_copy(ap_copy, ap);
+ len = alloc_vprintf2(buf, fmt, ap);
+ va_end(ap_copy);
+ } else if (len > (int) size &&
+ (size = len + 1) > 0 &&
+ (*buf = (char *) mg_malloc(size)) == NULL) {
+ len = -1; /* Allocation failed, mark failure */
+ } else {
+ va_copy(ap_copy, ap);
+ IGNORE_UNUSED_RESULT(vsnprintf(*buf, size, fmt, ap_copy));
+ va_end(ap_copy);
+ }
+
+ return len;
+}
+
+int mg_vprintf(struct mg_connection *conn, const char *fmt, va_list ap)
+{
+ char mem[MG_BUF_LEN], *buf = mem;
+ int len;
+
+ if ((len = alloc_vprintf(&buf, sizeof(mem), fmt, ap)) > 0) {
+ len = mg_write(conn, buf, (size_t) len);
+ }
+ if (buf != mem && buf != NULL) {
+ mg_free(buf);
+ }
+
+ return len;
+}
+
+int mg_printf(struct mg_connection *conn, const char *fmt, ...)
+{
+ va_list ap;
+ int result;
+
+ va_start(ap, fmt);
+ result = mg_vprintf(conn, fmt, ap);
+ va_end(ap);
+
+ return result;
+}
+
+int mg_url_decode(const char *src, int src_len, char *dst,
+ int dst_len, int is_form_url_encoded)
+{
+ int i, j, a, b;
+#define HEXTOI(x) (isdigit(x) ? x - '0' : x - 'W')
+
+ for (i = j = 0; i < src_len && j < dst_len - 1; i++, j++) {
+ if (i < src_len - 2 && src[i] == '%' &&
+ isxdigit(* (const unsigned char *) (src + i + 1)) &&
+ isxdigit(* (const unsigned char *) (src + i + 2))) {
+ a = tolower(* (const unsigned char *) (src + i + 1));
+ b = tolower(* (const unsigned char *) (src + i + 2));
+ dst[j] = (char) ((HEXTOI(a) << 4) | HEXTOI(b));
+ i += 2;
+ } else if (is_form_url_encoded && src[i] == '+') {
+ dst[j] = ' ';
+ } else {
+ dst[j] = src[i];
+ }
+ }
+
+ dst[j] = '\0'; /* Null-terminate the destination */
+
+ return i >= src_len ? j : -1;
+}
+
+int mg_get_var(const char *data, size_t data_len, const char *name,
+ char *dst, size_t dst_len)
+{
+ return mg_get_var2(data,data_len,name,dst,dst_len,0);
+}
+
+int mg_get_var2(const char *data, size_t data_len, const char *name,
+ char *dst, size_t dst_len, size_t occurrence)
+{
+ const char *p, *e, *s;
+ size_t name_len;
+ int len;
+
+ if (dst == NULL || dst_len == 0) {
+ len = -2;
+ } else if (data == NULL || name == NULL || data_len == 0) {
+ len = -1;
+ dst[0] = '\0';
+ } else {
+ name_len = strlen(name);
+ e = data + data_len;
+ len = -1;
+ dst[0] = '\0';
+
+ /* data is "var1=val1&var2=val2...". Find variable first */
+ for (p = data; p + name_len < e; p++) {
+ if ((p == data || p[-1] == '&') && p[name_len] == '=' &&
+ !mg_strncasecmp(name, p, name_len) && 0 == occurrence--) {
+
+ /* Point p to variable value */
+ p += name_len + 1;
+
+ /* Point s to the end of the value */
+ s = (const char *) memchr(p, '&', (size_t)(e - p));
+ if (s == NULL) {
+ s = e;
+ }
+ assert(s >= p);
+
+ /* Decode variable into destination buffer */
+ len = mg_url_decode(p, (int)(s - p), dst, (int)dst_len, 1);
+
+ /* Redirect error code from -1 to -2 (destination buffer too
+ small). */
+ if (len == -1) {
+ len = -2;
+ }
+ break;
+ }
+ }
+ }
+
+ return len;
+}
+
+int mg_get_cookie(const char *cookie_header, const char *var_name,
+ char *dst, size_t dst_size)
+{
+ const char *s, *p, *end;
+ int name_len, len = -1;
+
+ if (dst == NULL || dst_size == 0) {
+ len = -2;
+ } else if (var_name == NULL || (s = cookie_header) == NULL) {
+ len = -1;
+ dst[0] = '\0';
+ } else {
+ name_len = (int) strlen(var_name);
+ end = s + strlen(s);
+ dst[0] = '\0';
+
+ for (; (s = mg_strcasestr(s, var_name)) != NULL; s += name_len) {
+ if (s[name_len] == '=')
<TRUNCATED>
[04/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/topology_manager/private/src/topology_manager.c
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/private/src/topology_manager.c b/remote_services/topology_manager/private/src/topology_manager.c
deleted file mode 100644
index 6472b01..0000000
--- a/remote_services/topology_manager/private/src/topology_manager.c
+++ /dev/null
@@ -1,985 +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.
- */
-/*
- * topology_manager.c
- *
- * \date Sep 29, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "celixbool.h"
-#include "topology_manager.h"
-#include "bundle_context.h"
-#include "constants.h"
-#include "bundle.h"
-#include "remote_service_admin.h"
-#include "remote_constants.h"
-#include "filter.h"
-#include "listener_hook_service.h"
-#include "utils.h"
-#include "service_reference.h"
-#include "service_registration.h"
-#include "log_service.h"
-#include "log_helper.h"
-#include "topology_manager.h"
-#include "scope.h"
-#include "hash_map.h"
-
-struct topology_manager {
- bundle_context_pt context;
-
- celix_thread_mutex_t rsaListLock;
- celix_thread_mutexattr_t rsaListLockAttr;
- array_list_pt rsaList;
-
- celix_thread_mutex_t listenerListLock;
- hash_map_pt listenerList;
-
- celix_thread_mutex_t exportedServicesLock;
- hash_map_pt exportedServices;
-
- celix_thread_mutex_t importedServicesLock;
- celix_thread_mutexattr_t importedServicesLockAttr;
- hash_map_pt importedServices;
-
- scope_pt scope;
-
- log_helper_pt loghelper;
-};
-
-celix_status_t topologyManager_exportScopeChanged(void *handle, char *service_name);
-celix_status_t topologyManager_importScopeChanged(void *handle, char *service_name);
-celix_status_t topologyManager_notifyListenersEndpointAdded(topology_manager_pt manager, remote_service_admin_service_pt rsa, array_list_pt registrations);
-celix_status_t topologyManager_notifyListenersEndpointRemoved(topology_manager_pt manager, remote_service_admin_service_pt rsa, export_registration_pt export);
-
-celix_status_t topologyManager_create(bundle_context_pt context, log_helper_pt logHelper, topology_manager_pt *manager, void **scope) {
- celix_status_t status = CELIX_SUCCESS;
-
- *manager = calloc(1, sizeof(**manager));
-
- if (!*manager) {
- return CELIX_ENOMEM;
- }
-
- (*manager)->context = context;
- (*manager)->rsaList = NULL;
-
- arrayList_create(&(*manager)->rsaList);
-
-
- celixThreadMutexAttr_create(&(*manager)->rsaListLockAttr);
- celixThreadMutexAttr_settype(&(*manager)->rsaListLockAttr, CELIX_THREAD_MUTEX_RECURSIVE);
- celixThreadMutex_create(&(*manager)->rsaListLock, &(*manager)->rsaListLockAttr);
-
- celixThreadMutexAttr_create(&(*manager)->importedServicesLockAttr);
- celixThreadMutexAttr_settype(&(*manager)->importedServicesLockAttr, CELIX_THREAD_MUTEX_RECURSIVE);
- celixThreadMutex_create(&(*manager)->importedServicesLock, &(*manager)->importedServicesLockAttr);
-
- celixThreadMutex_create(&(*manager)->exportedServicesLock, NULL);
- celixThreadMutex_create(&(*manager)->listenerListLock, NULL);
-
- (*manager)->listenerList = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
- (*manager)->exportedServices = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
- (*manager)->importedServices = hashMap_create(NULL, NULL, NULL, NULL);
-
- status = scope_scopeCreate(*manager, &(*manager)->scope);
- scope_setExportScopeChangedCallback((*manager)->scope, topologyManager_exportScopeChanged);
- scope_setImportScopeChangedCallback((*manager)->scope, topologyManager_importScopeChanged);
- *scope = (*manager)->scope;
-
- (*manager)->loghelper = logHelper;
-
-
- return status;
-}
-
-celix_status_t topologyManager_destroy(topology_manager_pt manager) {
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&manager->listenerListLock);
- hashMap_destroy(manager->listenerList, false, false);
-
- celixThreadMutex_unlock(&manager->listenerListLock);
- celixThreadMutex_destroy(&manager->listenerListLock);
-
- celixThreadMutex_lock(&manager->rsaListLock);
-
- arrayList_destroy(manager->rsaList);
-
- celixThreadMutex_unlock(&manager->rsaListLock);
- celixThreadMutex_destroy(&manager->rsaListLock);
- celixThreadMutexAttr_destroy(&manager->rsaListLockAttr);
-
- celixThreadMutex_lock(&manager->exportedServicesLock);
-
- hashMap_destroy(manager->exportedServices, false, false);
-
- celixThreadMutex_unlock(&manager->exportedServicesLock);
- celixThreadMutex_destroy(&manager->exportedServicesLock);
-
- celixThreadMutex_lock(&manager->importedServicesLock);
-
- hashMap_destroy(manager->importedServices, false, false);
-
- celixThreadMutex_unlock(&manager->importedServicesLock);
- celixThreadMutex_destroy(&manager->importedServicesLock);
- celixThreadMutexAttr_destroy(&manager->importedServicesLockAttr);
-
- scope_scopeDestroy(manager->scope);
- free(manager);
-
- return status;
-}
-
-celix_status_t topologyManager_closeImports(topology_manager_pt manager) {
- celix_status_t status;
-
- status = celixThreadMutex_lock(&manager->importedServicesLock);
-
- hash_map_iterator_pt iter = hashMapIterator_create(manager->importedServices);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- endpoint_description_pt ep = hashMapEntry_getKey(entry);
- hash_map_pt imports = hashMapEntry_getValue(entry);
-
- if (imports != NULL) {
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Remove imported service (%s; %s).", ep->service, ep->id);
- hash_map_iterator_pt importsIter = hashMapIterator_create(imports);
-
- while (hashMapIterator_hasNext(importsIter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(importsIter);
-
- remote_service_admin_service_pt rsa = hashMapEntry_getKey(entry);
- import_registration_pt import = hashMapEntry_getValue(entry);
-
- status = rsa->importRegistration_close(rsa->admin, import);
- if (status == CELIX_SUCCESS) {
- hashMapIterator_remove(importsIter);
- }
- }
- hashMapIterator_destroy(importsIter);
-
- hashMapIterator_remove(iter);
-
- hashMap_destroy(imports, false, false);
- }
- }
- hashMapIterator_destroy(iter);
-
- status = celixThreadMutex_unlock(&manager->importedServicesLock);
-
- return status;
-}
-
-celix_status_t topologyManager_rsaAdding(void * handle, service_reference_pt reference, void **service) {
- celix_status_t status;
- topology_manager_pt manager = (topology_manager_pt) handle;
-
- status = bundleContext_getService(manager->context, reference, service);
-
- return status;
-}
-
-celix_status_t topologyManager_rsaAdded(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status;
- topology_manager_pt manager = (topology_manager_pt) handle;
- properties_pt serviceProperties = NULL;
- remote_service_admin_service_pt rsa = (remote_service_admin_service_pt) service;
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Added RSA");
-
- status = celixThreadMutex_lock(&manager->rsaListLock);
-
- if (status == CELIX_SUCCESS) {
- arrayList_add(manager->rsaList, rsa);
- status = celixThreadMutex_unlock(&manager->rsaListLock);
- }
-
- // add already imported services to new rsa
- if (status == CELIX_SUCCESS) {
- status = celixThreadMutex_lock(&manager->importedServicesLock);
-
- if (status == CELIX_SUCCESS) {
- hash_map_iterator_pt importedServicesIterator = hashMapIterator_create(manager->importedServices);
-
- while (hashMapIterator_hasNext(importedServicesIterator)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(importedServicesIterator);
- endpoint_description_pt endpoint = hashMapEntry_getKey(entry);
- if (scope_allowImport(manager->scope, endpoint)) {
- import_registration_pt import = NULL;
- status = rsa->importService(rsa->admin, endpoint, &import);
-
- if (status == CELIX_SUCCESS) {
- hash_map_pt imports = hashMapEntry_getValue(entry);
-
- if (imports == NULL) {
- imports = hashMap_create(NULL, NULL, NULL, NULL);
- hashMap_put(manager->importedServices,endpoint,imports);
- }
-
- hashMap_put(imports, service, import);
- }
- }
- }
-
- hashMapIterator_destroy(importedServicesIterator);
-
- celixThreadMutex_unlock(&manager->importedServicesLock);
- }
- }
-
- // add already exported services to new rsa
- if (status == CELIX_SUCCESS) {
- status = celixThreadMutex_lock(&manager->exportedServicesLock);
-
- if (status == CELIX_SUCCESS) {
- hash_map_iterator_pt exportedServicesIterator = hashMapIterator_create(manager->exportedServices);
-
- while (hashMapIterator_hasNext(exportedServicesIterator)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(exportedServicesIterator);
- service_reference_pt reference = hashMapEntry_getKey(entry);
- const char* serviceId = NULL;
-
- serviceReference_getProperty(reference, OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
-
- scope_getExportProperties(manager->scope, reference, &serviceProperties);
-
- array_list_pt endpoints = NULL;
- status = rsa->exportService(rsa->admin, (char*)serviceId, serviceProperties, &endpoints);
-
- if (status == CELIX_SUCCESS) {
- hash_map_pt exports = hashMapEntry_getValue(entry);
-
- if (exports == NULL) {
- exports = hashMap_create(NULL, NULL, NULL, NULL);
- hashMap_put(manager->exportedServices,reference,exports);
- }
-
- hashMap_put(exports, rsa, endpoints);
- status = topologyManager_notifyListenersEndpointAdded(manager, rsa, endpoints);
- }
- }
-
- hashMapIterator_destroy(exportedServicesIterator);
-
- celixThreadMutex_unlock(&manager->exportedServicesLock);
- }
- }
- return status;
-}
-
-celix_status_t topologyManager_rsaModified(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status = CELIX_SUCCESS;
-
- // Nop...
-
- return status;
-}
-
-celix_status_t topologyManager_rsaRemoved(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status = CELIX_SUCCESS;
- topology_manager_pt manager = (topology_manager_pt) handle;
- remote_service_admin_service_pt rsa = (remote_service_admin_service_pt) service;
-
- if (celixThreadMutex_lock(&manager->exportedServicesLock) == CELIX_SUCCESS) {
- hash_map_iterator_pt iter = hashMapIterator_create(manager->exportedServices);
-
- while (hashMapIterator_hasNext(iter)) {
-
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- service_reference_pt key = hashMapEntry_getKey(entry);
- hash_map_pt exports = hashMapEntry_getValue(entry);
-
- /*
- * the problem here is that also the rsa has a a list of
- * endpoints which is destroyed when closing the exportRegistration
- */
- array_list_pt exports_list = hashMap_get(exports, rsa);
-
- if (exports_list != NULL) {
- int exportsIter = 0;
- int exportListSize = arrayList_size(exports_list);
- for (exportsIter = 0; exports_list != NULL && exportsIter < exportListSize; exportsIter++) {
- export_registration_pt export = arrayList_get(exports_list, exportsIter);
- topologyManager_notifyListenersEndpointRemoved(manager, rsa, export);
- rsa->exportRegistration_close(rsa->admin, export);
- }
- }
-
- hashMap_remove(exports, rsa);
- /*if(exports_list!=NULL){
- arrayList_destroy(exports_list);
- }*/
-
- if (hashMap_size(exports) == 0) {
- hashMap_remove(manager->exportedServices, key);
- hashMap_destroy(exports, false, false);
-
- hashMapIterator_destroy(iter);
- iter = hashMapIterator_create(manager->exportedServices);
- }
- }
- hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&manager->exportedServicesLock);
- }
-
- if (celixThreadMutex_lock(&manager->importedServicesLock) == CELIX_SUCCESS) {
- hash_map_iterator_pt iter = hashMapIterator_create(manager->importedServices);
-
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- hash_map_pt imports = hashMapEntry_getValue(entry);
-
- import_registration_pt import = hashMap_get(imports, rsa);
-
- if (import != NULL) {
- celix_status_t subStatus = rsa->importRegistration_close(rsa->admin, import);
-
- if (subStatus == CELIX_SUCCESS) {
- hashMap_remove(imports, rsa);
- } else {
- status = subStatus;
- }
- }
- }
- hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&manager->importedServicesLock);
- }
-
- if (celixThreadMutex_lock(&manager->rsaListLock) == CELIX_SUCCESS) {
- arrayList_removeElement(manager->rsaList, rsa);
- celixThreadMutex_unlock(&manager->rsaListLock);
- }
-
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Removed RSA");
-
- return status;
-}
-
-
-celix_status_t topologyManager_serviceChanged(void *listener, service_event_pt event) {
- celix_status_t status = CELIX_SUCCESS;
- service_listener_pt listen = listener;
- topology_manager_pt manager = listen->handle;
-
- const char* export = NULL;
- const char* serviceId = NULL;
- serviceReference_getProperty(event->reference, OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &export);
- serviceReference_getProperty(event->reference, OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
-
- if (!export) {
- // Nothing needs to be done: we're not interested...
- return status;
- }
-
- switch (event->type) {
- case OSGI_FRAMEWORK_SERVICE_EVENT_REGISTERED:
- status = topologyManager_addExportedService(manager, event->reference, (char*)serviceId);
- break;
- case OSGI_FRAMEWORK_SERVICE_EVENT_MODIFIED:
- status = topologyManager_removeExportedService(manager, event->reference, (char*)serviceId);
-
- if (status == CELIX_SUCCESS) {
- status = topologyManager_addExportedService(manager, event->reference, (char*)serviceId);
- }
- break;
- case OSGI_FRAMEWORK_SERVICE_EVENT_UNREGISTERING:
- status = topologyManager_removeExportedService(manager, event->reference, (char*)serviceId);
- break;
- case OSGI_FRAMEWORK_SERVICE_EVENT_MODIFIED_ENDMATCH:
- break;
- }
-
- return status;
-}
-
-celix_status_t topologyManager_exportScopeChanged(void *handle, char *filterStr) {
- celix_status_t status = CELIX_SUCCESS;
- topology_manager_pt manager = (topology_manager_pt) handle;
- service_registration_pt reg = NULL;
- const char* serviceId = NULL;
- bool found;
- properties_pt props;
- filter_pt filter = filter_create(filterStr);
-
- if (filter == NULL) {
- printf("filter creating failed\n");
- return CELIX_ENOMEM;
- }
-
- // add already exported services to new rsa
- if (celixThreadMutex_lock(&manager->exportedServicesLock) == CELIX_SUCCESS) {
- hash_map_iterator_pt exportedServicesIterator = hashMapIterator_create(manager->exportedServices);
- int size = hashMap_size(manager->exportedServices);
- service_reference_pt *srvRefs = (service_reference_pt *) calloc(size, sizeof(service_reference_pt));
- char **srvIds = (char **) calloc(size, sizeof(char*));
- int nrFound = 0;
-
- found = false;
-
- while (hashMapIterator_hasNext(exportedServicesIterator)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(exportedServicesIterator);
- service_reference_pt reference = hashMapEntry_getKey(entry);
- reg = NULL;
- serviceReference_getServiceRegistration(reference, ®);
- if (reg != NULL) {
- props = NULL;
- serviceRegistration_getProperties(reg, &props);
- status = filter_match(filter, props, &found);
- if (found) {
- srvRefs[nrFound] = reference;
- serviceReference_getProperty(reference, OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
- srvIds[nrFound++] = (char*)serviceId;
- }
- }
- }
-
- hashMapIterator_destroy(exportedServicesIterator);
- celixThreadMutex_unlock(&manager->exportedServicesLock);
-
- if (nrFound > 0) {
- for (int i = 0; i < nrFound; i++) {
- // Question: can srvRefs become invalid meanwhile??
- const char* export = NULL;
- serviceReference_getProperty(srvRefs[i], (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &export);
-
- if (export) {
- celix_status_t substatus = topologyManager_removeExportedService(manager, srvRefs[i], srvIds[i]);
-
- if (substatus != CELIX_SUCCESS) {
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_ERROR, "TOPOLOGY_MANAGER: Removal of exported service (%s) failed.", srvIds[i]);
- } else {
- substatus = topologyManager_addExportedService(manager, srvRefs[i], srvIds[i]);
- }
-
- if (substatus != CELIX_SUCCESS) {
- status = substatus;
- }
- }
- }
- }
-
- free(srvRefs);
- free(srvIds);
- }
-
- filter_destroy(filter);
-
- return status;
-}
-
-celix_status_t topologyManager_importScopeChanged(void *handle, char *service_name) {
- celix_status_t status = CELIX_SUCCESS;
- endpoint_description_pt endpoint;
- topology_manager_pt manager = (topology_manager_pt) handle;
- bool found = false;
-
- // add already exported services to new rsa
- if (celixThreadMutex_lock(&manager->importedServicesLock) == CELIX_SUCCESS) {
- hash_map_iterator_pt importedServicesIterator = hashMapIterator_create(manager->importedServices);
- while (!found && hashMapIterator_hasNext(importedServicesIterator)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(importedServicesIterator);
- endpoint = hashMapEntry_getKey(entry);
-
- entry = hashMap_getEntry(endpoint->properties, (void *) OSGI_FRAMEWORK_OBJECTCLASS);
- char* name = (char *) hashMapEntry_getValue(entry);
- // Test if a service with the same name is imported
- if (strcmp(name, service_name) == 0) {
- found = true;
- }
- }
- hashMapIterator_destroy(importedServicesIterator);
- celixThreadMutex_unlock(&manager->importedServicesLock);
- }
-
- if (found) {
- status = topologyManager_removeImportedService(manager, endpoint, NULL);
-
- if (status != CELIX_SUCCESS) {
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_ERROR, "TOPOLOGY_MANAGER: Removal of imported service (%s; %s) failed.", endpoint->service, endpoint->id);
- } else {
- status = topologyManager_addImportedService(manager, endpoint, NULL);
- }
- }
- return status;
-}
-
-celix_status_t topologyManager_addImportedService(void *handle, endpoint_description_pt endpoint, char *matchedFilter) {
- celix_status_t status = CELIX_SUCCESS;
- topology_manager_pt manager = handle;
-
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Add imported service (%s; %s).", endpoint->service, endpoint->id);
-
- if (celixThreadMutex_lock(&manager->importedServicesLock) == CELIX_SUCCESS) {
-
- hash_map_pt imports = hashMap_create(NULL, NULL, NULL, NULL);
- hashMap_put(manager->importedServices, endpoint, imports);
-
- if (scope_allowImport(manager->scope, endpoint)) {
- if (celixThreadMutex_lock(&manager->rsaListLock) == CELIX_SUCCESS) {
- int size = arrayList_size(manager->rsaList);
-
- for (int iter = 0; iter < size; iter++) {
- import_registration_pt import = NULL;
- remote_service_admin_service_pt rsa = arrayList_get(manager->rsaList, iter);
- celix_status_t substatus = rsa->importService(rsa->admin, endpoint, &import);
- if (substatus == CELIX_SUCCESS) {
- hashMap_put(imports, rsa, import);
- } else {
- status = substatus;
- }
- }
- celixThreadMutex_unlock(&manager->rsaListLock);
- }
-
- }
-
- celixThreadMutex_unlock(&manager->importedServicesLock);
- }
-
-
- return status;
-}
-
-celix_status_t topologyManager_removeImportedService(void *handle, endpoint_description_pt endpoint, char *matchedFilter) {
- celix_status_t status = CELIX_SUCCESS;
- topology_manager_pt manager = handle;
-
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Remove imported service (%s; %s).", endpoint->service, endpoint->id);
-
- if (celixThreadMutex_lock(&manager->importedServicesLock) == CELIX_SUCCESS) {
-
- hash_map_iterator_pt iter = hashMapIterator_create(manager->importedServices);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- endpoint_description_pt ep = hashMapEntry_getKey(entry);
- hash_map_pt imports = hashMapEntry_getValue(entry);
-
- if (imports != NULL && strcmp(endpoint->id, ep->id) == 0) {
- hash_map_iterator_pt importsIter = hashMapIterator_create(imports);
-
- while (hashMapIterator_hasNext(importsIter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(importsIter);
- remote_service_admin_service_pt rsa = hashMapEntry_getKey(entry);
- import_registration_pt import = hashMapEntry_getValue(entry);
- celix_status_t substatus = rsa->importRegistration_close(rsa->admin, import);
- if (substatus == CELIX_SUCCESS) {
- hashMapIterator_remove(importsIter);
- } else {
- status = substatus;
- }
- }
- hashMapIterator_destroy(importsIter);
- hashMapIterator_remove(iter);
-
- hashMap_destroy(imports, false, false);
- }
- }
- hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&manager->importedServicesLock);
- }
-
- return status;
-}
-
-celix_status_t topologyManager_addExportedService(topology_manager_pt manager, service_reference_pt reference, char *serviceId) {
- celix_status_t status = CELIX_SUCCESS;
- properties_pt serviceProperties = NULL;
-
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Add exported service (%s).", serviceId);
-
- if (celixThreadMutex_lock(&manager->exportedServicesLock) == CELIX_SUCCESS) {
- scope_getExportProperties(manager->scope, reference, &serviceProperties);
- hash_map_pt exports = hashMap_create(NULL, NULL, NULL, NULL);
- hashMap_put(manager->exportedServices, reference, exports);
-
- if (celixThreadMutex_lock(&manager->rsaListLock) == CELIX_SUCCESS) {
- int size = arrayList_size(manager->rsaList);
-
- if (size == 0) {
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_WARNING, "TOPOLOGY_MANAGER: No RSA available yet.");
- }
-
- for (int iter = 0; iter < size; iter++) {
- remote_service_admin_service_pt rsa = arrayList_get(manager->rsaList, iter);
-
- array_list_pt endpoints = NULL;
- celix_status_t substatus = rsa->exportService(rsa->admin, serviceId, serviceProperties, &endpoints);
-
- if (substatus == CELIX_SUCCESS) {
- hashMap_put(exports, rsa, endpoints);
- topologyManager_notifyListenersEndpointAdded(manager, rsa, endpoints);
- } else {
- status = substatus;
- }
- }
- celixThreadMutex_unlock(&manager->rsaListLock);
- }
- celixThreadMutex_unlock(&manager->exportedServicesLock);
- }
-
- return status;
-}
-
-celix_status_t topologyManager_removeExportedService(topology_manager_pt manager, service_reference_pt reference, char *serviceId) {
- celix_status_t status = CELIX_SUCCESS;
-
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Remove exported service (%s).", serviceId);
-
- if (celixThreadMutex_lock(&manager->exportedServicesLock) == CELIX_SUCCESS) {
- hash_map_pt exports = hashMap_get(manager->exportedServices, reference);
- if (exports) {
- hash_map_iterator_pt iter = hashMapIterator_create(exports);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- remote_service_admin_service_pt rsa = hashMapEntry_getKey(entry);
- array_list_pt exportRegistrations = hashMapEntry_getValue(entry);
-
- int size = arrayList_size(exportRegistrations);
-
- for (int exportsIter = 0; exportsIter < size; exportsIter++) {
- export_registration_pt export = arrayList_get(exportRegistrations, exportsIter);
- topologyManager_notifyListenersEndpointRemoved(manager, rsa, export);
- rsa->exportRegistration_close(rsa->admin, export);
- }
-
- hashMap_remove(exports, rsa);
- //arrayList_destroy(exportRegistrations);
- hashMapIterator_destroy(iter);
- iter = hashMapIterator_create(exports);
-
- }
- hashMapIterator_destroy(iter);
- }
- exports = hashMap_remove(manager->exportedServices, reference);
-
- if (exports != NULL) {
- hashMap_destroy(exports, false, false);
- }
-
- celixThreadMutex_unlock(&manager->exportedServicesLock);
- }
-
- return status;
-}
-
-celix_status_t topologyManager_getEndpointDescriptionForExportRegistration(remote_service_admin_service_pt rsa, export_registration_pt export, endpoint_description_pt *endpoint) {
- celix_status_t status;
-
- export_reference_pt reference = NULL;
- status = rsa->exportRegistration_getExportReference(export, &reference);
-
- if (status == CELIX_SUCCESS) {
- status = rsa->exportReference_getExportedEndpoint(reference, endpoint);
- }
-
- free(reference);
-
- return status;
-}
-
-celix_status_t topologyManager_endpointListenerAdding(void* handle, service_reference_pt reference, void** service) {
- celix_status_t status = CELIX_SUCCESS;
- topology_manager_pt manager = (topology_manager_pt) handle;
-
- bundleContext_getService(manager->context, reference, service);
-
- return status;
-}
-
-celix_status_t topologyManager_endpointListenerAdded(void* handle, service_reference_pt reference, void* service) {
- celix_status_t status = CELIX_SUCCESS;
- topology_manager_pt manager = handle;
- const char* scope = NULL;
-
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Added ENDPOINT_LISTENER");
-
- if (celixThreadMutex_lock(&manager->listenerListLock) == CELIX_SUCCESS) {
- hashMap_put(manager->listenerList, reference, NULL);
- celixThreadMutex_unlock(&manager->listenerListLock);
-
- serviceReference_getProperty(reference, OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
-
- filter_pt filter = filter_create(scope);
- hash_map_iterator_pt refIter = hashMapIterator_create(manager->exportedServices);
-
- while (hashMapIterator_hasNext(refIter)) {
- hash_map_pt rsaExports = hashMapIterator_nextValue(refIter);
- hash_map_iterator_pt rsaIter = hashMapIterator_create(rsaExports);
-
- while (hashMapIterator_hasNext(rsaIter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(rsaIter);
- remote_service_admin_service_pt rsa = hashMapEntry_getKey(entry);
- array_list_pt registrations = hashMapEntry_getValue(entry);
-
- int arrayListSize = arrayList_size(registrations);
- int cnt = 0;
-
- for (; cnt < arrayListSize; cnt++) {
- export_registration_pt export = arrayList_get(registrations, cnt);
- endpoint_description_pt endpoint = NULL;
-
- status = topologyManager_getEndpointDescriptionForExportRegistration(rsa, export, &endpoint);
- if (status == CELIX_SUCCESS) {
- bool matchResult = false;
- filter_match(filter, endpoint->properties, &matchResult);
- if (matchResult) {
- endpoint_listener_pt listener = (endpoint_listener_pt) service;
- status = listener->endpointAdded(listener->handle, endpoint, (char*)scope);
- }
- }
- }
- }
- hashMapIterator_destroy(rsaIter);
- }
- hashMapIterator_destroy(refIter);
-
- filter_destroy(filter);
- }
-
- return status;
-}
-
-celix_status_t topologyManager_endpointListenerModified(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status;
-
- status = topologyManager_endpointListenerRemoved(handle, reference, service);
-
- if (status == CELIX_SUCCESS) {
- status = topologyManager_endpointListenerAdded(handle, reference, service);
- }
-
- return status;
-}
-
-celix_status_t topologyManager_endpointListenerRemoved(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status = CELIX_SUCCESS;
- topology_manager_pt manager = handle;
-
- if (celixThreadMutex_lock(&manager->listenerListLock) == CELIX_SUCCESS) {
-
- if (hashMap_remove(manager->listenerList, reference)) {
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "EndpointListener Removed");
- }
-
- celixThreadMutex_unlock(&manager->listenerListLock);
- }
-
- return status;
-}
-
-celix_status_t topologyManager_notifyListenersEndpointAdded(topology_manager_pt manager, remote_service_admin_service_pt rsa, array_list_pt registrations) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (celixThreadMutex_lock(&manager->listenerListLock) == CELIX_SUCCESS) {
-
- hash_map_iterator_pt iter = hashMapIterator_create(manager->listenerList);
- while (hashMapIterator_hasNext(iter)) {
- const char* scope = NULL;
- endpoint_listener_pt epl = NULL;
- service_reference_pt reference = hashMapIterator_nextKey(iter);
-
- serviceReference_getProperty(reference, OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
-
- status = bundleContext_getService(manager->context, reference, (void **) &epl);
- if (status == CELIX_SUCCESS) {
- filter_pt filter = filter_create(scope);
-
- int regSize = arrayList_size(registrations);
- for (int regIt = 0; regIt < regSize; regIt++) {
- export_registration_pt export = arrayList_get(registrations, regIt);
- endpoint_description_pt endpoint = NULL;
- celix_status_t substatus = topologyManager_getEndpointDescriptionForExportRegistration(rsa, export, &endpoint);
- if (substatus == CELIX_SUCCESS) {
- bool matchResult = false;
- filter_match(filter, endpoint->properties, &matchResult);
- if (matchResult) {
- status = epl->endpointAdded(epl->handle, endpoint, (char*)scope);
- }
- } else {
- status = substatus;
- }
- }
- filter_destroy(filter);
- }
- }
- hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&manager->listenerListLock);
- }
-
- return status;
-}
-
-celix_status_t topologyManager_notifyListenersEndpointRemoved(topology_manager_pt manager, remote_service_admin_service_pt rsa, export_registration_pt export) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (celixThreadMutex_lock(&manager->listenerListLock) == CELIX_SUCCESS) {
- hash_map_iterator_pt iter = hashMapIterator_create(manager->listenerList);
- while (hashMapIterator_hasNext(iter)) {
- endpoint_description_pt endpoint = NULL;
- endpoint_listener_pt epl = NULL;
- celix_status_t substatus;
- const char* scope = NULL;
-
- service_reference_pt reference = hashMapIterator_nextKey(iter);
- serviceReference_getProperty(reference, OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
-
- substatus = bundleContext_getService(manager->context, reference, (void **) &epl);
-
- if (substatus == CELIX_SUCCESS) {
- substatus = topologyManager_getEndpointDescriptionForExportRegistration(rsa, export, &endpoint);
- }
-
- if (substatus == CELIX_SUCCESS) {
- substatus = epl->endpointRemoved(epl->handle, endpoint, NULL);
- }
-
- /* if (substatus != CELIX_SUCCESS) {
- status = substatus;
-
- }
- */
- }
- hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&manager->listenerListLock);
- }
-
- return status;
-}
-
-celix_status_t topologyManager_extendFilter(topology_manager_pt manager, char *filter, char **updatedFilter) {
- celix_status_t status;
- bundle_context_pt context = manager->context;
- const char* uuid = NULL;
-
- status = bundleContext_getProperty(context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
-
- if (!uuid) {
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_ERROR, "TOPOLOGY_MANAGER: no framework UUID defined?!");
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- int len = 10 + strlen(filter) + strlen(OSGI_RSA_ENDPOINT_FRAMEWORK_UUID) + strlen(uuid);
- *updatedFilter = malloc(len);
- if (!*updatedFilter) {
- return CELIX_ENOMEM;
- }
-
- snprintf(*updatedFilter, len, "(&%s(!(%s=%s)))", filter, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
-
- return status;
-}
-
-celix_status_t topologyManager_listenerAdded(void *handle, array_list_pt listeners) {
- celix_status_t status = CELIX_SUCCESS;
- topology_manager_pt manager = handle;
-
- for (int i = 0; i < arrayList_size(listeners); i++) {
- listener_hook_info_pt info = arrayList_get(listeners, i);
- bundle_pt bundle = NULL, self = NULL;
- bundleContext_getBundle(info->context, &bundle);
- bundleContext_getBundle(manager->context, &self);
- if (bundle == self) {
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "TOPOLOGY_MANAGER: Ignore myself.");
- continue;
- }
-
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: listener with filter \"%s\" added", info->filter);
-
- char *filter = NULL;
- bool free_filter = true;
- status = topologyManager_extendFilter(manager, info->filter, &filter);
-#if 0
- if(filter != NULL){
- // TODO: add status handling
- status = celixThreadMutex_lock(&manager->importScopesLock);
-
- struct scope *interest = hashMap_get(manager->importScopes, filter);
- if (interest) {
- interest->refs++;
- free(filter);
- filter = NULL;
- } else {
- interest = malloc(sizeof(*interest));
- interest->filter = filter;
- interest->refs = 1;
- hashMap_put(manager->importScopes, filter, interest);
- free_filter = false;
- }
-
- status = celixThreadMutex_unlock(&manager->importScopesLock);
- }
-#endif
-
- if (filter != NULL && free_filter) {
- free(filter);
- }
-
- }
-
- return status;
-}
-
-celix_status_t topologyManager_listenerRemoved(void *handle, array_list_pt listeners) {
- celix_status_t status = CELIX_SUCCESS;
- topology_manager_pt manager = handle;
-
- for (int i = 0; i < arrayList_size(listeners); i++) {
- listener_hook_info_pt info = arrayList_get(listeners, i);
-
- bundle_pt bundle = NULL, self = NULL;
- bundleContext_getBundle(info->context, &bundle);
- bundleContext_getBundle(manager->context, &self);
- if (bundle == self) {
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "TOPOLOGY_MANAGER: Ignore myself.");
- continue;
- }
-
- logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: listener with filter \"%s\" removed.", info->filter);
-
- char *filter = NULL;
- topologyManager_extendFilter(manager, info->filter, &filter);
-#if 0
- status = celixThreadMutex_lock(&manager->importScopesLock);
-
- struct scope *interest = hashMap_get(manager->importScopes, filter);
- if (interest != NULL && --interest->refs <= 0) {
- // last reference, remove from scope
- hash_map_entry_pt entry = hashMap_getEntry(manager->importScopes, filter);
- char* key = (char*) hashMapEntry_getKey(entry);
- interest = hashMap_remove(manager->importScopes, filter);
- free(key);
- free(interest);
- }
-#endif
-
- if (filter != NULL) {
- free(filter);
- }
-#if 0
- status = celixThreadMutex_unlock(&manager->importScopesLock);
-#endif
- }
-
- return status;
-}
-
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/topology_manager/public/include/tm_scope.h
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/public/include/tm_scope.h b/remote_services/topology_manager/public/include/tm_scope.h
deleted file mode 100644
index d4f60ca..0000000
--- a/remote_services/topology_manager/public/include/tm_scope.h
+++ /dev/null
@@ -1,46 +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.
- */
-/*
- * tm_scope.h
- *
- * \date Oct 29, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef TM_SCOPE_H_
-#define TM_SCOPE_H_
-
-#include "celix_errno.h"
-
-#define TOPOLOGYMANAGER_SCOPE_SERVICE "tm_scope"
-
-
-struct tm_scope_service {
- void *handle; // scope_pt
- celix_status_t (*addExportScope)(void *handle, char *filter, properties_pt props);
- celix_status_t (*removeExportScope)(void *handle, char *filter);
- celix_status_t (*addImportScope)(void *handle, char *filter);
- celix_status_t (*removeImportScope)(void *handle, char *filter);
-};
-
-typedef struct tm_scope_service tm_scope_service_t;
-typedef tm_scope_service_t *tm_scope_service_pt;
-
-#endif /* TM_SCOPE_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/topology_manager/src/activator.c
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/src/activator.c b/remote_services/topology_manager/src/activator.c
new file mode 100644
index 0000000..7f39a25
--- /dev/null
+++ b/remote_services/topology_manager/src/activator.c
@@ -0,0 +1,289 @@
+/**
+ *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.
+ */
+/*
+ * activator.c
+ *
+ * \date Sep 29, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "constants.h"
+#include "bundle_activator.h"
+#include "service_tracker.h"
+#include "service_registration.h"
+
+#include "topology_manager.h"
+#include "endpoint_listener.h"
+#include "remote_constants.h"
+#include "listener_hook_service.h"
+#include "log_service.h"
+#include "log_helper.h"
+#include "scope.h"
+#include "tm_scope.h"
+#include "topology_manager.h"
+
+struct activator {
+ bundle_context_pt context;
+
+ topology_manager_pt manager;
+
+ service_tracker_pt endpointListenerTracker;
+ service_tracker_pt remoteServiceAdminTracker;
+ service_listener_pt serviceListener;
+
+ endpoint_listener_pt endpointListener;
+ service_registration_pt endpointListenerService;
+
+ listener_hook_service_pt hookService;
+ service_registration_pt hook;
+
+ tm_scope_service_pt scopeService;
+ service_registration_pt scopeReg;
+
+ log_helper_pt loghelper;
+};
+
+
+static celix_status_t bundleActivator_createEPLTracker(struct activator *activator, service_tracker_pt *tracker);
+static celix_status_t bundleActivator_createRSATracker(struct activator *activator, service_tracker_pt *tracker);
+static celix_status_t bundleActivator_createServiceListener(struct activator *activator, service_listener_pt *listener);
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = NULL;
+ void *scope;
+
+ activator = calloc(1, sizeof(struct activator));
+
+ if (!activator) {
+ return CELIX_ENOMEM;
+ }
+
+ activator->context = context;
+ activator->endpointListenerService = NULL;
+ activator->endpointListenerTracker = NULL;
+ activator->hook = NULL;
+ activator->manager = NULL;
+ activator->remoteServiceAdminTracker = NULL;
+ activator->serviceListener = NULL;
+ activator->scopeService = calloc(1, sizeof(*(activator->scopeService)));
+ if (activator->scopeService == NULL)
+ {
+ free(activator);
+ return CELIX_ENOMEM;
+ }
+
+ activator->scopeService->addExportScope = tm_addExportScope;
+ activator->scopeService->removeExportScope = tm_removeExportScope;
+ activator->scopeService->addImportScope = tm_addImportScope;
+ activator->scopeService->removeImportScope = tm_removeImportScope;
+ activator->scopeReg = NULL; // explicitly needed, otherwise exception
+
+ logHelper_create(context, &activator->loghelper);
+ logHelper_start(activator->loghelper);
+
+ status = topologyManager_create(context, activator->loghelper, &activator->manager, &scope);
+ activator->scopeService->handle = scope;
+
+ if (status == CELIX_SUCCESS) {
+ status = bundleActivator_createEPLTracker(activator, &activator->endpointListenerTracker);
+ if (status == CELIX_SUCCESS) {
+ status = bundleActivator_createRSATracker(activator, &activator->remoteServiceAdminTracker);
+ if (status == CELIX_SUCCESS) {
+ status = bundleActivator_createServiceListener(activator, &activator->serviceListener);
+ if (status == CELIX_SUCCESS) {
+ *userData = activator;
+ }
+ }
+ }
+ }
+
+ if(status != CELIX_SUCCESS){
+ bundleActivator_destroy(activator,context);
+ }
+
+ return status;
+}
+
+static celix_status_t bundleActivator_createEPLTracker(struct activator *activator, service_tracker_pt *tracker) {
+ celix_status_t status;
+
+ service_tracker_customizer_pt customizer = NULL;
+
+ status = serviceTrackerCustomizer_create(activator->manager, topologyManager_endpointListenerAdding, topologyManager_endpointListenerAdded, topologyManager_endpointListenerModified,
+ topologyManager_endpointListenerRemoved, &customizer);
+
+ if (status == CELIX_SUCCESS) {
+ status = serviceTracker_create(activator->context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, customizer, tracker);
+ }
+
+ return status;
+}
+
+static celix_status_t bundleActivator_createRSATracker(struct activator *activator, service_tracker_pt *tracker) {
+ celix_status_t status;
+
+ service_tracker_customizer_pt customizer = NULL;
+
+ status = serviceTrackerCustomizer_create(activator->manager, topologyManager_rsaAdding, topologyManager_rsaAdded, topologyManager_rsaModified, topologyManager_rsaRemoved, &customizer);
+
+ if (status == CELIX_SUCCESS) {
+ status = serviceTracker_create(activator->context, OSGI_RSA_REMOTE_SERVICE_ADMIN, customizer, tracker);
+ }
+
+ return status;
+}
+
+static celix_status_t bundleActivator_createServiceListener(struct activator *activator, service_listener_pt *listener) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *listener = malloc(sizeof(**listener));
+ if (!*listener) {
+ return CELIX_ENOMEM;
+ }
+
+ (*listener)->handle = activator->manager;
+ (*listener)->serviceChanged = topologyManager_serviceChanged;
+
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+ celix_status_t status;
+ struct activator *activator = userData;
+
+ endpoint_listener_pt endpointListener = malloc(sizeof(*endpointListener));
+ endpointListener->handle = activator->manager;
+ endpointListener->endpointAdded = topologyManager_addImportedService;
+ endpointListener->endpointRemoved = topologyManager_removeImportedService;
+ activator->endpointListener = endpointListener;
+
+ const char *uuid = NULL;
+ status = bundleContext_getProperty(activator->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
+ if (!uuid) {
+ logHelper_log(activator->loghelper, OSGI_LOGSERVICE_ERROR, "TOPOLOGY_MANAGER: no framework UUID defined?!");
+ return CELIX_ILLEGAL_STATE;
+ }
+
+ size_t len = 14 + strlen(OSGI_FRAMEWORK_OBJECTCLASS) + strlen(OSGI_RSA_ENDPOINT_FRAMEWORK_UUID) + strlen(uuid);
+ char *scope = malloc(len);
+ if (!scope) {
+ return CELIX_ENOMEM;
+ }
+
+ snprintf(scope, len, "(&(%s=*)(!(%s=%s)))", OSGI_FRAMEWORK_OBJECTCLASS, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
+
+ logHelper_log(activator->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: endpoint listener scope is %s", scope);
+
+ properties_pt props = properties_create();
+ properties_set(props, (char *) OSGI_ENDPOINT_LISTENER_SCOPE, scope);
+
+ // We can release the scope, as properties_set makes a copy of the key & value...
+ free(scope);
+
+ bundleContext_registerService(context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, endpointListener, props, &activator->endpointListenerService);
+
+ listener_hook_service_pt hookService = malloc(sizeof(*hookService));
+ hookService->handle = activator->manager;
+ hookService->added = topologyManager_listenerAdded;
+ hookService->removed = topologyManager_listenerRemoved;
+ activator->hookService = hookService;
+
+ bundleContext_registerService(context, (char *) OSGI_FRAMEWORK_LISTENER_HOOK_SERVICE_NAME, hookService, NULL, &activator->hook);
+ bundleContext_addServiceListener(context, activator->serviceListener, "(service.exported.interfaces=*)");
+
+ if (status == CELIX_SUCCESS) {
+ serviceTracker_open(activator->remoteServiceAdminTracker);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = serviceTracker_open(activator->endpointListenerTracker);
+ }
+
+ bundleContext_registerService(context, (char *) TOPOLOGYMANAGER_SCOPE_SERVICE, activator->scopeService, NULL, &activator->scopeReg);
+
+ array_list_pt references = NULL;
+ bundleContext_getServiceReferences(context, NULL, "(service.exported.interfaces=*)", &references);
+ int i;
+ for (i = 0; i < arrayList_size(references); i++) {
+ service_reference_pt reference = arrayList_get(references, i);
+ const char* serviceId = NULL;
+ status = CELIX_DO_IF(status, serviceReference_getProperty(reference, OSGI_FRAMEWORK_SERVICE_ID, &serviceId));
+
+ CELIX_DO_IF(status, topologyManager_addExportedService(activator->manager, reference, (char*)serviceId));
+ }
+ arrayList_destroy(references);
+
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ if (serviceTracker_close(activator->remoteServiceAdminTracker) == CELIX_SUCCESS) {
+ serviceTracker_destroy(activator->remoteServiceAdminTracker);
+ }
+
+ if (serviceTracker_close(activator->endpointListenerTracker) == CELIX_SUCCESS) {
+ serviceTracker_destroy(activator->endpointListenerTracker);
+ }
+
+ bundleContext_removeServiceListener(context, activator->serviceListener);
+ free(activator->serviceListener);
+
+ serviceRegistration_unregister(activator->hook);
+ free(activator->hookService);
+
+ serviceRegistration_unregister(activator->endpointListenerService);
+ free(activator->endpointListener);
+
+ serviceRegistration_unregister(activator->scopeReg);
+
+ topologyManager_closeImports(activator->manager);
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ struct activator *activator = userData;
+ if (!activator || !activator->manager) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ logHelper_stop(activator->loghelper);
+ logHelper_destroy(&activator->loghelper);
+
+ status = topologyManager_destroy(activator->manager);
+
+ if (activator->scopeService) {
+ free(activator->scopeService);
+ }
+
+ free(activator);
+ }
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/topology_manager/src/scope.c
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/src/scope.c b/remote_services/topology_manager/src/scope.c
new file mode 100644
index 0000000..b81d050
--- /dev/null
+++ b/remote_services/topology_manager/src/scope.c
@@ -0,0 +1,326 @@
+/**
+ *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.
+ */
+/*
+ * scope.c
+ *
+ * \date Sep 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "scope.h"
+#include "tm_scope.h"
+#include "topology_manager.h"
+#include "utils.h"
+
+struct scope_item {
+ properties_pt props;
+};
+
+struct scope {
+ void *manager; // owner of the scope datastructure
+ celix_thread_mutex_t exportScopeLock;
+ hash_map_pt exportScopes; // key is filter, value is scope_item (properties set)
+
+ celix_thread_mutex_t importScopeLock;
+ array_list_pt importScopes; // list of filters
+
+ celix_status_t (*exportScopeChangedHandler)(void* manager, char *filter);
+ celix_status_t (*importScopeChangedHandler)(void* manager, char *filter);
+};
+
+static celix_status_t import_equal(const void *, const void *, bool *equals);
+
+/*
+ * SERVICES
+ */
+
+celix_status_t tm_addExportScope(void *handle, char *filter, properties_pt props) {
+ celix_status_t status = CELIX_SUCCESS;
+ scope_pt scope = (scope_pt) handle;
+ properties_pt present;
+
+ if (handle == NULL)
+ return CELIX_ILLEGAL_ARGUMENT;
+
+ if (celixThreadMutex_lock(&scope->exportScopeLock) == CELIX_SUCCESS) {
+ // For now we just don't allow two exactly the same filters
+ // TODO: What we actually need is the following
+ // If part of the new filter is already present in any of the filters in exportScopes
+ // we have to assure that the new filter defines other property keys than the property keys
+ // in the already defined filter!
+ present = (properties_pt) hashMap_get(scope->exportScopes, filter);
+ if (present == NULL) {
+ struct scope_item *item = calloc(1, sizeof(*item));
+ if (item == NULL) {
+ status = CELIX_ENOMEM;
+ } else {
+ item->props = props;
+ hashMap_put(scope->exportScopes, (void*) strdup(filter), (void*) item);
+ }
+ } else {
+ // don't allow the same filter twice
+ properties_destroy(props);
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+ celixThreadMutex_unlock(&scope->exportScopeLock);
+ }
+
+ if (scope->exportScopeChangedHandler != NULL) {
+ status = CELIX_DO_IF(status, scope->exportScopeChangedHandler(scope->manager, filter));
+ }
+
+ return status;
+}
+
+celix_status_t tm_removeExportScope(void *handle, char *filter) {
+ celix_status_t status = CELIX_SUCCESS;
+ scope_pt scope = (scope_pt) handle;
+
+ if (handle == NULL)
+ return CELIX_ILLEGAL_ARGUMENT;
+
+ if (celixThreadMutex_lock(&scope->exportScopeLock) == CELIX_SUCCESS) {
+ struct scope_item *present = (struct scope_item *) hashMap_get(scope->exportScopes, filter);
+ if (present == NULL) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ } else {
+ properties_destroy(present->props);
+ hashMap_remove(scope->exportScopes, filter); // frees also the item!
+ }
+ celixThreadMutex_unlock(&scope->exportScopeLock);
+ }
+ if (scope->exportScopeChangedHandler != NULL) {
+ status = CELIX_DO_IF(status, scope->exportScopeChangedHandler(scope->manager, filter));
+ }
+ return status;
+}
+
+celix_status_t tm_addImportScope(void *handle, char *filter) {
+ celix_status_t status = CELIX_SUCCESS;
+ scope_pt scope = (scope_pt) handle;
+
+ filter_pt new;
+
+ if (handle == NULL)
+ return CELIX_ILLEGAL_ARGUMENT;
+ new = filter_create(filter);
+ if (new == NULL) {
+ return CELIX_ILLEGAL_ARGUMENT; // filter not parseble
+ }
+ if (celixThreadMutex_lock(&scope->importScopeLock) == CELIX_SUCCESS) {
+ int index = arrayList_indexOf(scope->importScopes, new);
+ filter_pt present = (filter_pt) arrayList_get(scope->importScopes, index);
+ if (present == NULL) {
+ arrayList_add(scope->importScopes, new);
+ } else {
+ filter_destroy(new);
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ celixThreadMutex_unlock(&scope->importScopeLock);
+ }
+ if (scope->importScopeChangedHandler != NULL) {
+ status = CELIX_DO_IF(status, scope->importScopeChangedHandler(scope->manager, filter));
+ }
+ return status;
+}
+
+celix_status_t tm_removeImportScope(void *handle, char *filter) {
+ celix_status_t status = CELIX_SUCCESS;
+ scope_pt scope = (scope_pt) handle;
+ filter_pt new;
+
+ if (handle == NULL)
+ return CELIX_ILLEGAL_ARGUMENT;
+
+ new = filter_create(filter);
+ if (new == NULL) {
+ return CELIX_ILLEGAL_ARGUMENT; // filter not parseble
+ }
+
+ if (celixThreadMutex_lock(&scope->importScopeLock) == CELIX_SUCCESS) {
+ int index = arrayList_indexOf(scope->importScopes, new);
+ filter_pt present = (filter_pt) arrayList_get(scope->importScopes, index);
+ if (present == NULL)
+ status = CELIX_ILLEGAL_ARGUMENT;
+ else {
+ arrayList_removeElement(scope->importScopes, present);
+ filter_destroy(present);
+ }
+ celixThreadMutex_unlock(&scope->importScopeLock);
+ }
+ if (scope->importScopeChangedHandler != NULL) {
+ status = CELIX_DO_IF(status, scope->importScopeChangedHandler(scope->manager, filter));
+ }
+ filter_destroy(new);
+ return status;
+}
+
+/*****************************************************************************
+ * GLOBAL FUNCTIONS
+ *****************************************************************************/
+
+void scope_setExportScopeChangedCallback(scope_pt scope, celix_status_t (*changed)(void *handle, char *servName)) {
+ scope->exportScopeChangedHandler = changed;
+}
+
+void scope_setImportScopeChangedCallback(scope_pt scope, celix_status_t (*changed)(void *handle, char *servName)) {
+ scope->importScopeChangedHandler = changed;
+}
+
+celix_status_t scope_scopeCreate(void *handle, scope_pt *scope) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *scope = calloc(1, sizeof **scope);
+
+ if (*scope == NULL) {
+ return CELIX_ENOMEM;
+ }
+
+ (*scope)->manager = handle;
+ celixThreadMutex_create(&(*scope)->exportScopeLock, NULL);
+ celixThreadMutex_create(&(*scope)->importScopeLock, NULL);
+
+ (*scope)->exportScopes = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ arrayList_createWithEquals(import_equal, &((*scope)->importScopes));
+ (*scope)->exportScopeChangedHandler = NULL;
+
+ return status;
+}
+
+celix_status_t scope_scopeDestroy(scope_pt scope) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (celixThreadMutex_lock(&scope->exportScopeLock) == CELIX_SUCCESS) {
+ hash_map_iterator_pt iter = hashMapIterator_create(scope->exportScopes);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt scopedEntry = hashMapIterator_nextEntry(iter);
+ struct scope_item *item = (struct scope_item*) hashMapEntry_getValue(scopedEntry);
+ properties_destroy(item->props);
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(scope->exportScopes, true, true); // free keys, free values
+ celixThreadMutex_unlock(&scope->exportScopeLock);
+ }
+
+ if (celixThreadMutex_lock(&scope->importScopeLock) == CELIX_SUCCESS) {
+ array_list_iterator_pt imp_iter = arrayListIterator_create(scope->importScopes);
+ while (arrayListIterator_hasNext(imp_iter)) {
+ filter_pt element = (filter_pt) arrayListIterator_next(imp_iter);
+ filter_destroy(element);
+ // no need to call arrayList_removeElement(element) because complete list is destroyed
+ }
+ arrayListIterator_destroy(imp_iter);
+ arrayList_destroy(scope->importScopes);
+ celixThreadMutex_unlock(&scope->importScopeLock);
+ }
+
+ celixThreadMutex_destroy(&scope->exportScopeLock);
+ celixThreadMutex_destroy(&scope->importScopeLock);
+ free(scope);
+ return status;
+}
+
+/*****************************************************************************
+ * STATIC FUNCTIONS
+ *****************************************************************************/
+static celix_status_t import_equal(const void *src, const void *dest, bool *equals) {
+ celix_status_t status;
+
+ filter_pt src_filter = (filter_pt) src;
+ filter_pt dest_filter = (filter_pt) dest;
+ status = filter_match_filter(src_filter, dest_filter, equals);
+ return status;
+}
+
+bool scope_allowImport(scope_pt scope, endpoint_description_pt endpoint) {
+ bool allowImport = false;
+ array_list_iterator_pt iter;
+
+ if (celixThreadMutex_lock(&(scope->importScopeLock)) == CELIX_SUCCESS) {
+ if (arrayList_size(scope->importScopes) == 0) {
+ allowImport = true;
+ } else {
+ iter = arrayListIterator_create(scope->importScopes);
+ while ((allowImport == false) && arrayListIterator_hasNext(iter)) {
+ filter_pt element = (filter_pt) arrayListIterator_next(iter);
+ filter_match(element, endpoint->properties, &allowImport);
+ }
+ arrayListIterator_destroy(iter);
+ }
+ celixThreadMutex_unlock(&scope->importScopeLock);
+ }
+ return allowImport;
+}
+
+celix_status_t scope_getExportProperties(scope_pt scope, service_reference_pt reference, properties_pt *props) {
+ celix_status_t status = CELIX_SUCCESS;
+ unsigned int size = 0;
+ char **keys;
+ bool found = false;
+
+ *props = NULL;
+ properties_pt serviceProperties = properties_create(); // GB: not sure if a copy is needed
+ // or serviceReference_getProperties() is
+ // is acceptable
+
+ serviceReference_getPropertyKeys(reference, &keys, &size);
+ for (int i = 0; i < size; i++) {
+ char *key = keys[i];
+ const char* value = NULL;
+
+ if (serviceReference_getProperty(reference, key, &value) == CELIX_SUCCESS) {
+// && strcmp(key, (char*) OSGI_RSA_SERVICE_EXPORTED_INTERFACES) != 0
+// && strcmp(key, (char*) OSGI_FRAMEWORK_OBJECTCLASS) != 0) {
+ properties_set(serviceProperties, key, value);
+ }
+
+ }
+
+ free(keys);
+
+ if (celixThreadMutex_lock(&(scope->exportScopeLock)) == CELIX_SUCCESS) {
+ hash_map_iterator_pt scopedPropIter = hashMapIterator_create(scope->exportScopes);
+ // TODO: now stopping if first filter matches, alternatively we could build up
+ // the additional output properties for each filter that matches?
+ while ((!found) && hashMapIterator_hasNext(scopedPropIter)) {
+ hash_map_entry_pt scopedEntry = hashMapIterator_nextEntry(scopedPropIter);
+ char *filterStr = (char *) hashMapEntry_getKey(scopedEntry);
+ filter_pt filter = filter_create(filterStr);
+ if (filter != NULL) {
+ // test if the scope filter matches the exported service properties
+ status = filter_match(filter, serviceProperties, &found);
+ if (found) {
+ struct scope_item *item = (struct scope_item *) hashMapEntry_getValue(scopedEntry);
+ *props = item->props;
+ }
+ }
+ filter_destroy(filter);
+ }
+ hashMapIterator_destroy(scopedPropIter);
+ properties_destroy(serviceProperties);
+
+ celixThreadMutex_unlock(&(scope->exportScopeLock));
+ }
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/topology_manager/src/scope.h
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/src/scope.h b/remote_services/topology_manager/src/scope.h
new file mode 100644
index 0000000..4035e2c
--- /dev/null
+++ b/remote_services/topology_manager/src/scope.h
@@ -0,0 +1,150 @@
+/**
+ *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.
+ */
+/*
+ * scope.h
+ *
+ * \date Sep 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef TOPOLOGY_SCOPE_H_
+#define TOPOLOGY_SCOPE_H_
+
+#include "celixbool.h"
+#include "celix_errno.h"
+#include "celix_threads.h"
+#include "hash_map.h"
+#include "endpoint_description.h"
+#include "properties.h"
+#include "service_reference.h"
+#include "tm_scope.h"
+
+typedef struct scope *scope_pt;
+
+
+
+/* \brief create scope structure
+ *
+ * \param owning component pointer
+ * \param scope to be created
+ *
+ * \return CELIX_SUCCESS
+ * CELIX_ENOMEM
+ */
+celix_status_t scope_scopeCreate(void *handle, scope_pt *scope);
+
+/* \brief destroy scope structure
+ *
+ * \param scope to be destroyed
+ *
+ * \return CELIX_SUCCESS
+ */
+celix_status_t scope_scopeDestroy(scope_pt scope);
+
+/* \brief register export scope change callback of topology manager
+ *
+ * \param scope structure
+ * \param changed function pointer
+ *
+ * \return -
+ */
+void scope_setExportScopeChangedCallback(scope_pt scope, celix_status_t (*changed)(void *handle, char *servName));
+
+/* \brief register import scope change callback of topology manager
+ *
+ * \param scope structure
+ * \param changed function pointer
+ *
+ * \return -
+ */
+void scope_setImportScopeChangedCallback(scope_pt scope, celix_status_t (*changed)(void *handle, char *servName));
+
+
+/* \brief Test if scope allows import of service
+ *
+ * \param scope containing import rules
+ * \param endpoint import service endpoint description
+ *
+ * \return true import allowed
+ * false import not allowed
+ */
+bool scope_allowImport(scope_pt scope, endpoint_description_pt endpoint);
+
+/* \brief Test if scope allows import of service
+ *
+ * \param scope containing export rules
+ * \param reference to service
+ * \param props, additional properties defining restrictions for the exported service
+ * NULL if no additional restrictions found
+ *
+ * \return CELIX_SUCCESS
+ *
+ */
+celix_status_t scope_getExportProperties(scope_pt scope, service_reference_pt reference, properties_pt *props);
+
+/* \brief add restricted scope for specified exported service
+ *
+ * \param handle pointer to scope
+ * \param filter, filter string
+ * \param props additional properties defining restrictions for the exported service
+ *
+ * \return CELIX_SUCCESS if added to scope
+ * CELIX_ILLEGAL_ARGUMENT if service scope is already restricted before
+ *
+ */
+celix_status_t tm_addExportScope(void *handle, char *filter, properties_pt props);
+
+/* \brief remove restricted scope for specified exported service
+ *
+ * \param handle pointer to scope
+ * \param filter, filter string
+ *
+ * \return CELIX_SUCCESS if removed
+ * CELIX_ILLEGAL_ARGUMENT if service not found in scope
+ *
+ */
+celix_status_t tm_removeExportScope(void *handle, char *filter);
+
+/* \brief add restricted scope for specified imported service
+ *
+ * \param handle pointer to scope
+ * \param filter, filter string
+ * \param props additional properties defining restrictions for the imported service
+ *
+ * \return CELIX_SUCCESS if added to scope
+ * CELIX_ILLEGAL_ARGUMENT if service scope is already restricted before
+ *
+ */
+celix_status_t tm_addImportScope(void *handle, char *filter);
+
+
+/* \brief remove restricted scope for specified imported service
+ *
+ * \param handle pointer to scope
+ * \param filter, filter string
+ *
+ * \return CELIX_SUCCESS if removed
+ * CELIX_ILLEGAL_ARGUMENT if service not found in scope
+ *
+ */
+celix_status_t tm_removeImportScope(void *handle, char *filter);
+
+
+#endif // TOPOLOGY_SCOPE_H_
[39/54] [abbrv] celix git commit: CELIX-417: Refactors cmake usage of
pubsub and rsa. Started with installing exported targets
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/private/src/zmq_crypto.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/private/src/zmq_crypto.c b/pubsub/pubsub_admin_zmq/private/src/zmq_crypto.c
deleted file mode 100644
index fe444bd..0000000
--- a/pubsub/pubsub_admin_zmq/private/src/zmq_crypto.c
+++ /dev/null
@@ -1,281 +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.
- */
-/*
- * zmq_crypto.c
- *
- * \date Dec 2, 2016
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include "zmq_crypto.h"
-
-#include <zmq.h>
-#include <openssl/conf.h>
-#include <openssl/evp.h>
-#include <openssl/err.h>
-
-#include <string.h>
-
-#define MAX_FILE_PATH_LENGTH 512
-#define ZMQ_KEY_LENGTH 40
-#define AES_KEY_LENGTH 32
-#define AES_IV_LENGTH 16
-
-#define KEY_TO_GET "aes_key"
-#define IV_TO_GET "aes_iv"
-
-static char* read_file_content(char* filePath, char* fileName);
-static void parse_key_lines(char *keysBuffer, char **key, char **iv);
-static void parse_key_line(char *line, char **key, char **iv);
-static void extract_keys_from_buffer(unsigned char *input, int inputlen, char **publicKey, char **secretKey);
-
-/**
- * Return a valid zcert_t from an encoded file
- * Caller is responsible for freeing by calling zcert_destroy(zcert** cert);
- */
-zcert_t* get_zcert_from_encoded_file(char* keysFilePath, char* keysFileName, char* file_path)
-{
-
- if (keysFilePath == NULL){
- keysFilePath = DEFAULT_KEYS_FILE_PATH;
- }
-
- if (keysFileName == NULL){
- keysFileName = DEFAULT_KEYS_FILE_NAME;
- }
-
- char* keys_data = read_file_content(keysFilePath, keysFileName);
- if (keys_data == NULL){
- return NULL;
- }
-
- char *key = NULL;
- char *iv = NULL;
- parse_key_lines(keys_data, &key, &iv);
- free(keys_data);
-
- if (key == NULL || iv == NULL){
- free(key);
- free(iv);
-
- printf("CRYPTO: Loading AES key and/or AES iv failed!\n");
- return NULL;
- }
-
- //At this point, we know an aes key and iv are stored and loaded
-
- // generate sha256 hashes
- unsigned char key_digest[EVP_MAX_MD_SIZE];
- unsigned char iv_digest[EVP_MAX_MD_SIZE];
- generate_sha256_hash((char*) key, key_digest);
- generate_sha256_hash((char*) iv, iv_digest);
-
- zchunk_t* encoded_secret = zchunk_slurp (file_path, 0);
- if (encoded_secret == NULL){
- free(key);
- free(iv);
-
- return NULL;
- }
-
- int encoded_secret_size = (int) zchunk_size (encoded_secret);
- char* encoded_secret_data = zchunk_strdup(encoded_secret);
- zchunk_destroy (&encoded_secret);
-
- // Decryption of data
- int decryptedtext_len;
- unsigned char decryptedtext[encoded_secret_size];
- decryptedtext_len = decrypt((unsigned char *) encoded_secret_data, encoded_secret_size, key_digest, iv_digest, decryptedtext);
- decryptedtext[decryptedtext_len] = '\0';
-
- EVP_cleanup();
-
- free(encoded_secret_data);
- free(key);
- free(iv);
-
- // The public and private keys are retrieved
- char* public_text = NULL;
- char* secret_text = NULL;
-
- extract_keys_from_buffer(decryptedtext, decryptedtext_len, &public_text, &secret_text);
-
- byte public_key [32] = { 0 };
- byte secret_key [32] = { 0 };
-
- zmq_z85_decode (public_key, public_text);
- zmq_z85_decode (secret_key, secret_text);
-
- zcert_t* cert_loaded = zcert_new_from(public_key, secret_key);
-
- free(public_text);
- free(secret_text);
-
- return cert_loaded;
-}
-
-int generate_sha256_hash(char* text, unsigned char* digest)
-{
- unsigned int digest_len;
-
- EVP_MD_CTX * mdctx = EVP_MD_CTX_new();
- EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL);
- EVP_DigestUpdate(mdctx, text, strlen(text));
- EVP_DigestFinal_ex(mdctx, digest, &digest_len);
- EVP_MD_CTX_free(mdctx);
-
- return digest_len;
-}
-
-int decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, unsigned char *iv, unsigned char *plaintext)
-{
- int len;
- int plaintext_len;
-
- EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
-
- EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv);
- EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len);
- plaintext_len = len;
- EVP_DecryptFinal_ex(ctx, plaintext + len, &len);
- plaintext_len += len;
-
- EVP_CIPHER_CTX_free(ctx);
-
- return plaintext_len;
-}
-
-/**
- * Caller is responsible for freeing the returned value
- */
-static char* read_file_content(char* filePath, char* fileName){
-
- char fileNameWithPath[MAX_FILE_PATH_LENGTH];
- snprintf(fileNameWithPath, MAX_FILE_PATH_LENGTH, "%s/%s", filePath, fileName);
- int rc = 0;
-
- if (!zsys_file_exists(fileNameWithPath)){
- printf("CRYPTO: Keys file '%s' doesn't exist!\n", fileNameWithPath);
- return NULL;
- }
-
- zfile_t* keys_file = zfile_new (filePath, fileName);
- rc = zfile_input (keys_file);
- if (rc != 0){
- zfile_destroy(&keys_file);
- printf("CRYPTO: Keys file '%s' not readable!\n", fileNameWithPath);
- return NULL;
- }
-
- ssize_t keys_file_size = zsys_file_size (fileNameWithPath);
- zchunk_t* keys_chunk = zfile_read (keys_file, keys_file_size, 0);
- if (keys_chunk == NULL){
- zfile_close(keys_file);
- zfile_destroy(&keys_file);
- printf("CRYPTO: Can't read file '%s'!\n", fileNameWithPath);
- return NULL;
- }
-
- char* keys_data = zchunk_strdup(keys_chunk);
- zchunk_destroy(&keys_chunk);
- zfile_close(keys_file);
- zfile_destroy (&keys_file);
-
- return keys_data;
-}
-
-static void parse_key_lines(char *keysBuffer, char **key, char **iv){
- char *line = NULL, *saveLinePointer = NULL;
-
- bool firstTime = true;
- do {
- if (firstTime){
- line = strtok_r(keysBuffer, "\n", &saveLinePointer);
- firstTime = false;
- }else {
- line = strtok_r(NULL, "\n", &saveLinePointer);
- }
-
- if (line == NULL){
- break;
- }
-
- parse_key_line(line, key, iv);
-
- } while((*key == NULL || *iv == NULL) && line != NULL);
-
-}
-
-static void parse_key_line(char *line, char **key, char **iv){
- char *detectedKey = NULL, *detectedValue= NULL;
-
- char* sep_at = strchr(line, ':');
- if (sep_at == NULL){
- return;
- }
-
- *sep_at = '\0'; // overwrite first separator, creating two strings.
- detectedKey = line;
- detectedValue = sep_at + 1;
-
- if (detectedKey == NULL || detectedValue == NULL){
- return;
- }
- if (detectedKey[0] == '\0' || detectedValue[0] == '\0'){
- return;
- }
-
- if (*key == NULL && strcmp(detectedKey, KEY_TO_GET) == 0){
- *key = strndup(detectedValue, AES_KEY_LENGTH);
- } else if (*iv == NULL && strcmp(detectedKey, IV_TO_GET) == 0){
- *iv = strndup(detectedValue, AES_IV_LENGTH);
- }
-}
-
-static void extract_keys_from_buffer(unsigned char *input, int inputlen, char **publicKey, char **secretKey) {
- // Load decrypted text buffer
- zchunk_t* secret_decrypted = zchunk_new(input, inputlen);
- if (secret_decrypted == NULL){
- printf("CRYPTO: Failed to create zchunk\n");
- return;
- }
-
- zconfig_t* secret_config = zconfig_chunk_load (secret_decrypted);
- zchunk_destroy (&secret_decrypted);
- if (secret_config == NULL){
- printf("CRYPTO: Failed to create zconfig\n");
- return;
- }
-
- // Extract public and secret key from text buffer
- char* public_text = zconfig_get (secret_config, "/curve/public-key", NULL);
- char* secret_text = zconfig_get (secret_config, "/curve/secret-key", NULL);
-
- if (public_text == NULL || secret_text == NULL){
- zconfig_destroy(&secret_config);
- printf("CRYPTO: Loading public / secret key from text-buffer failed!\n");
- return;
- }
-
- *publicKey = strndup(public_text, ZMQ_KEY_LENGTH + 1);
- *secretKey = strndup(secret_text, ZMQ_KEY_LENGTH + 1);
-
- zconfig_destroy(&secret_config);
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/src/psa_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/src/psa_activator.c b/pubsub/pubsub_admin_zmq/src/psa_activator.c
new file mode 100644
index 0000000..fd07310
--- /dev/null
+++ b/pubsub/pubsub_admin_zmq/src/psa_activator.c
@@ -0,0 +1,142 @@
+/**
+ *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.
+ */
+/*
+ * psa_activator.c
+ *
+ * \date Sep 30, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+
+#include "bundle_activator.h"
+#include "service_registration.h"
+#include "service_tracker.h"
+
+#include "pubsub_admin_impl.h"
+
+
+struct activator {
+ pubsub_admin_pt admin;
+ pubsub_admin_service_pt adminService;
+ service_registration_pt registration;
+ service_tracker_pt serializerTracker;
+};
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator;
+
+ activator = calloc(1, sizeof(*activator));
+ if (!activator) {
+ status = CELIX_ENOMEM;
+ }
+ else{
+ *userData = activator;
+
+ status = pubsubAdmin_create(context, &(activator->admin));
+
+ if(status == CELIX_SUCCESS){
+ service_tracker_customizer_pt customizer = NULL;
+ status = serviceTrackerCustomizer_create(activator->admin,
+ NULL,
+ pubsubAdmin_serializerAdded,
+ NULL,
+ pubsubAdmin_serializerRemoved,
+ &customizer);
+ if(status == CELIX_SUCCESS){
+ status = serviceTracker_create(context, PUBSUB_SERIALIZER_SERVICE, customizer, &(activator->serializerTracker));
+ if(status != CELIX_SUCCESS){
+ serviceTrackerCustomizer_destroy(customizer);
+ pubsubAdmin_destroy(activator->admin);
+ }
+ }
+ else{
+ pubsubAdmin_destroy(activator->admin);
+ }
+ }
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+ pubsub_admin_service_pt pubsubAdminSvc = calloc(1, sizeof(*pubsubAdminSvc));
+
+ if (!pubsubAdminSvc) {
+ status = CELIX_ENOMEM;
+ }
+ else{
+ pubsubAdminSvc->admin = activator->admin;
+
+ pubsubAdminSvc->addPublication = pubsubAdmin_addPublication;
+ pubsubAdminSvc->removePublication = pubsubAdmin_removePublication;
+
+ pubsubAdminSvc->addSubscription = pubsubAdmin_addSubscription;
+ pubsubAdminSvc->removeSubscription = pubsubAdmin_removeSubscription;
+
+ pubsubAdminSvc->closeAllPublications = pubsubAdmin_closeAllPublications;
+ pubsubAdminSvc->closeAllSubscriptions = pubsubAdmin_closeAllSubscriptions;
+
+ pubsubAdminSvc->matchEndpoint = pubsubAdmin_matchEndpoint;
+
+ activator->adminService = pubsubAdminSvc;
+
+ status = bundleContext_registerService(context, PUBSUB_ADMIN_SERVICE, pubsubAdminSvc, NULL, &activator->registration);
+
+ status += serviceTracker_open(activator->serializerTracker);
+
+ }
+
+
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ status += serviceTracker_close(activator->serializerTracker);
+ status += serviceRegistration_unregister(activator->registration);
+
+ activator->registration = NULL;
+
+ free(activator->adminService);
+ activator->adminService = NULL;
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ serviceTracker_destroy(activator->serializerTracker);
+ pubsubAdmin_destroy(activator->admin);
+ activator->admin = NULL;
+
+ free(activator);
+
+ return status;
+}
+
+
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.c b/pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.c
new file mode 100644
index 0000000..29ead0c
--- /dev/null
+++ b/pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.c
@@ -0,0 +1,1040 @@
+/**
+ *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.
+ */
+/*
+ * pubsub_admin_impl.c
+ *
+ * \date Sep 30, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include "pubsub_admin_impl.h"
+#include <zmq.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+#ifndef ANDROID
+#include <ifaddrs.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "constants.h"
+#include "utils.h"
+#include "hash_map.h"
+#include "array_list.h"
+#include "bundle_context.h"
+#include "bundle.h"
+#include "service_reference.h"
+#include "service_registration.h"
+#include "log_helper.h"
+#include "log_service.h"
+#include "celix_threads.h"
+#include "service_factory.h"
+
+#include "topic_subscription.h"
+#include "topic_publication.h"
+#include "pubsub_endpoint.h"
+#include "pubsub_utils.h"
+#include "subscriber.h"
+
+#define MAX_KEY_FOLDER_PATH_LENGTH 512
+
+static const char *DEFAULT_IP = "127.0.0.1";
+
+static celix_status_t pubsubAdmin_getIpAdress(const char* interface, char** ip);
+static celix_status_t pubsubAdmin_addSubscriptionToPendingList(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
+static celix_status_t pubsubAdmin_addAnySubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
+
+static celix_status_t pubsubAdmin_getBestSerializer(pubsub_admin_pt admin,pubsub_endpoint_pt ep, pubsub_serializer_service_t **serSvc);
+static void connectTopicPubSubToSerializer(pubsub_admin_pt admin,pubsub_serializer_service_t *serializer,void *topicPubSub,bool isPublication);
+static void disconnectTopicPubSubFromSerializer(pubsub_admin_pt admin,void *topicPubSub,bool isPublication);
+
+celix_status_t pubsubAdmin_create(bundle_context_pt context, pubsub_admin_pt *admin) {
+ celix_status_t status = CELIX_SUCCESS;
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ if (!zsys_has_curve()){
+ printf("PSA_ZMQ: zeromq curve unsupported\n");
+ return CELIX_SERVICE_EXCEPTION;
+ }
+#endif
+
+ *admin = calloc(1, sizeof(**admin));
+
+ if (!*admin) {
+ status = CELIX_ENOMEM;
+ }
+ else{
+
+ const char *ip = NULL;
+ char *detectedIp = NULL;
+ (*admin)->bundle_context= context;
+ (*admin)->localPublications = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ (*admin)->subscriptions = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ (*admin)->pendingSubscriptions = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ (*admin)->externalPublications = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ (*admin)->topicSubscriptionsPerSerializer = hashMap_create(NULL, NULL, NULL, NULL);
+ (*admin)->topicPublicationsPerSerializer = hashMap_create(NULL, NULL, NULL, NULL);
+ arrayList_create(&((*admin)->noSerializerSubscriptions));
+ arrayList_create(&((*admin)->noSerializerPublications));
+ arrayList_create(&((*admin)->serializerList));
+
+ celixThreadMutex_create(&(*admin)->localPublicationsLock, NULL);
+ celixThreadMutex_create(&(*admin)->subscriptionsLock, NULL);
+ celixThreadMutex_create(&(*admin)->externalPublicationsLock, NULL);
+ celixThreadMutex_create(&(*admin)->serializerListLock, NULL);
+ celixThreadMutex_create(&(*admin)->usedSerializersLock, NULL);
+
+ celixThreadMutexAttr_create(&(*admin)->noSerializerPendingsAttr);
+ celixThreadMutexAttr_settype(&(*admin)->noSerializerPendingsAttr, CELIX_THREAD_MUTEX_RECURSIVE);
+ celixThreadMutex_create(&(*admin)->noSerializerPendingsLock, &(*admin)->noSerializerPendingsAttr);
+
+ celixThreadMutexAttr_create(&(*admin)->pendingSubscriptionsAttr);
+ celixThreadMutexAttr_settype(&(*admin)->pendingSubscriptionsAttr, CELIX_THREAD_MUTEX_RECURSIVE);
+ celixThreadMutex_create(&(*admin)->pendingSubscriptionsLock, &(*admin)->pendingSubscriptionsAttr);
+
+ if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
+ logHelper_start((*admin)->loghelper);
+ }
+
+ bundleContext_getProperty(context,PSA_IP , &ip);
+
+#ifndef ANDROID
+ if (ip == NULL) {
+ const char *interface = NULL;
+
+ bundleContext_getProperty(context, PSA_ITF, &interface);
+ if (pubsubAdmin_getIpAdress(interface, &detectedIp) != CELIX_SUCCESS) {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "PSA_ZMQ: Could not retrieve IP adress for interface %s", interface);
+ }
+
+ ip = detectedIp;
+ }
+#endif
+
+ if (ip != NULL) {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "PSA_ZMQ: Using %s for service annunciation", ip);
+ (*admin)->ipAddress = strdup(ip);
+ }
+ else {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "PSA_ZMQ: No IP address for service annunciation set. Using %s", DEFAULT_IP);
+ (*admin)->ipAddress = strdup(DEFAULT_IP);
+ }
+
+ if (detectedIp != NULL) {
+ free(detectedIp);
+ }
+
+ const char* basePortStr = NULL;
+ const char* maxPortStr = NULL;
+ char* endptrBase = NULL;
+ char* endptrMax = NULL;
+ bundleContext_getPropertyWithDefault(context, PSA_ZMQ_BASE_PORT, "PSA_ZMQ_DEFAULT_BASE_PORT", &basePortStr);
+ bundleContext_getPropertyWithDefault(context, PSA_ZMQ_MAX_PORT, "PSA_ZMQ_DEFAULT_MAX_PORT", &maxPortStr);
+ (*admin)->basePort = strtol(basePortStr, &endptrBase, 10);
+ (*admin)->maxPort = strtol(maxPortStr, &endptrMax, 10);
+ if (*endptrBase != '\0') {
+ (*admin)->basePort = PSA_ZMQ_DEFAULT_BASE_PORT;
+ }
+ if (*endptrMax != '\0') {
+ (*admin)->maxPort = PSA_ZMQ_DEFAULT_MAX_PORT;
+ }
+
+ printf("PSA Using base port %u to max port %u\n", (*admin)->basePort, (*admin)->maxPort);
+
+ // Disable Signal Handling by CZMQ
+ setenv("ZSYS_SIGHANDLER", "false", true);
+
+ const char *nrZmqThreads = NULL;
+ bundleContext_getProperty(context, "PSA_NR_ZMQ_THREADS", &nrZmqThreads);
+
+ if(nrZmqThreads != NULL) {
+ char *endPtr = NULL;
+ unsigned int nrThreads = strtoul(nrZmqThreads, &endPtr, 10);
+ if(endPtr != nrZmqThreads && nrThreads > 0 && nrThreads < 50) {
+ zsys_set_io_threads(nrThreads);
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "PSA_ZMQ: Using %d threads for ZMQ", nrThreads);
+ printf("PSA_ZMQ: Using %d threads for ZMQ\n", nrThreads);
+ }
+ }
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ // Setup authenticator
+ zactor_t* auth = zactor_new (zauth, NULL);
+ zstr_sendx(auth, "VERBOSE", NULL);
+
+ // Load all public keys of subscribers into the application
+ // This step is done for authenticating subscribers
+ char curve_folder_path[MAX_KEY_FOLDER_PATH_LENGTH];
+ char* keys_bundle_dir = pubsub_getKeysBundleDir(context);
+ snprintf(curve_folder_path, MAX_KEY_FOLDER_PATH_LENGTH, "%s/META-INF/keys/subscriber/public", keys_bundle_dir);
+ zstr_sendx (auth, "CURVE", curve_folder_path, NULL);
+ free(keys_bundle_dir);
+
+ (*admin)->zmq_auth = auth;
+#endif
+
+ }
+
+ return status;
+}
+
+
+celix_status_t pubsubAdmin_destroy(pubsub_admin_pt admin)
+{
+ celix_status_t status = CELIX_SUCCESS;
+
+ free(admin->ipAddress);
+
+ celixThreadMutex_lock(&admin->pendingSubscriptionsLock);
+ hash_map_iterator_pt iter = hashMapIterator_create(admin->pendingSubscriptions);
+ while(hashMapIterator_hasNext(iter)){
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ free((char*)hashMapEntry_getKey(entry));
+ arrayList_destroy((array_list_pt)hashMapEntry_getValue(entry));
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(admin->pendingSubscriptions,false,false);
+ celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);
+
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+ hashMap_destroy(admin->subscriptions,false,false);
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ hashMap_destroy(admin->localPublications,true,false);
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+ celixThreadMutex_lock(&admin->externalPublicationsLock);
+ iter = hashMapIterator_create(admin->externalPublications);
+ while(hashMapIterator_hasNext(iter)){
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ free((char*)hashMapEntry_getKey(entry));
+ arrayList_destroy((array_list_pt)hashMapEntry_getValue(entry));
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(admin->externalPublications,false,false);
+ celixThreadMutex_unlock(&admin->externalPublicationsLock);
+
+ celixThreadMutex_lock(&admin->serializerListLock);
+ arrayList_destroy(admin->serializerList);
+ celixThreadMutex_unlock(&admin->serializerListLock);
+
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_destroy(admin->noSerializerSubscriptions);
+ arrayList_destroy(admin->noSerializerPublications);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+
+
+ celixThreadMutex_lock(&admin->usedSerializersLock);
+
+ iter = hashMapIterator_create(admin->topicSubscriptionsPerSerializer);
+ while(hashMapIterator_hasNext(iter)){
+ arrayList_destroy((array_list_pt)hashMapIterator_nextValue(iter));
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(admin->topicSubscriptionsPerSerializer,false,false);
+
+ iter = hashMapIterator_create(admin->topicPublicationsPerSerializer);
+ while(hashMapIterator_hasNext(iter)){
+ arrayList_destroy((array_list_pt)hashMapIterator_nextValue(iter));
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(admin->topicPublicationsPerSerializer,false,false);
+
+ celixThreadMutex_unlock(&admin->usedSerializersLock);
+
+ celixThreadMutex_destroy(&admin->usedSerializersLock);
+ celixThreadMutex_destroy(&admin->serializerListLock);
+ celixThreadMutex_destroy(&admin->pendingSubscriptionsLock);
+
+ celixThreadMutexAttr_destroy(&admin->noSerializerPendingsAttr);
+ celixThreadMutex_destroy(&admin->noSerializerPendingsLock);
+
+ celixThreadMutexAttr_destroy(&admin->pendingSubscriptionsAttr);
+ celixThreadMutex_destroy(&admin->subscriptionsLock);
+
+ celixThreadMutex_destroy(&admin->localPublicationsLock);
+ celixThreadMutex_destroy(&admin->externalPublicationsLock);
+
+ logHelper_stop(admin->loghelper);
+
+ logHelper_destroy(&admin->loghelper);
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ if (admin->zmq_auth != NULL){
+ zactor_destroy(&(admin->zmq_auth));
+ }
+#endif
+
+ free(admin);
+
+ return status;
+}
+
+static celix_status_t pubsubAdmin_addAnySubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+
+ topic_subscription_pt any_sub = hashMap_get(admin->subscriptions,PUBSUB_ANY_SUB_TOPIC);
+
+ if(any_sub==NULL){
+
+ int i;
+ pubsub_serializer_service_t *best_serializer = NULL;
+ if( (status=pubsubAdmin_getBestSerializer(admin, subEP, &best_serializer)) == CELIX_SUCCESS){
+ status = pubsub_topicSubscriptionCreate(admin->bundle_context, PUBSUB_SUBSCRIBER_SCOPE_DEFAULT, PUBSUB_ANY_SUB_TOPIC, best_serializer, &any_sub);
+ }
+ else{
+ printf("PSA_ZMQ: Cannot find a serializer for subscribing topic %s. Adding it to pending list.\n",subEP->topic);
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_add(admin->noSerializerSubscriptions,subEP);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+
+ if (status == CELIX_SUCCESS){
+
+ /* Connect all internal publishers */
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ hash_map_iterator_pt lp_iter =hashMapIterator_create(admin->localPublications);
+ while(hashMapIterator_hasNext(lp_iter)){
+ service_factory_pt factory = (service_factory_pt)hashMapIterator_nextValue(lp_iter);
+ topic_publication_pt topic_pubs = (topic_publication_pt)factory->handle;
+ array_list_pt topic_publishers = pubsub_topicPublicationGetPublisherList(topic_pubs);
+
+ if(topic_publishers!=NULL){
+ for(i=0;i<arrayList_size(topic_publishers);i++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(topic_publishers,i);
+ if(pubEP->endpoint !=NULL){
+ status += pubsub_topicSubscriptionConnectPublisher(any_sub,pubEP->endpoint);
+ }
+ }
+ arrayList_destroy(topic_publishers);
+ }
+ }
+ hashMapIterator_destroy(lp_iter);
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+ /* Connect also all external publishers */
+ celixThreadMutex_lock(&admin->externalPublicationsLock);
+ hash_map_iterator_pt extp_iter =hashMapIterator_create(admin->externalPublications);
+ while(hashMapIterator_hasNext(extp_iter)){
+ array_list_pt ext_pub_list = (array_list_pt)hashMapIterator_nextValue(extp_iter);
+ if(ext_pub_list!=NULL){
+ for(i=0;i<arrayList_size(ext_pub_list);i++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
+ if(pubEP->endpoint !=NULL){
+ status += pubsub_topicSubscriptionConnectPublisher(any_sub,pubEP->endpoint);
+ }
+ }
+ }
+ }
+ hashMapIterator_destroy(extp_iter);
+ celixThreadMutex_unlock(&admin->externalPublicationsLock);
+
+
+ pubsub_topicSubscriptionAddSubscriber(any_sub,subEP);
+
+ status += pubsub_topicSubscriptionStart(any_sub);
+
+ }
+
+ if (status == CELIX_SUCCESS){
+ hashMap_put(admin->subscriptions,strdup(PUBSUB_ANY_SUB_TOPIC),any_sub);
+ connectTopicPubSubToSerializer(admin, best_serializer, any_sub, false);
+ }
+
+ }
+
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ return status;
+}
+
+celix_status_t pubsubAdmin_addSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ printf("PSA_ZMQ: Received subscription [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n",subEP->frameworkUUID,subEP->serviceID,subEP->scope, subEP->topic);
+
+ if(strcmp(subEP->topic,PUBSUB_ANY_SUB_TOPIC)==0){
+ return pubsubAdmin_addAnySubscription(admin,subEP);
+ }
+
+ /* Check if we already know some publisher about this topic, otherwise let's put the subscription in the pending hashmap */
+ celixThreadMutex_lock(&admin->pendingSubscriptionsLock);
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ celixThreadMutex_lock(&admin->externalPublicationsLock);
+
+ char* scope_topic = createScopeTopicKey(subEP->scope, subEP->topic);
+
+ service_factory_pt factory = (service_factory_pt)hashMap_get(admin->localPublications,scope_topic);
+ array_list_pt ext_pub_list = (array_list_pt)hashMap_get(admin->externalPublications,scope_topic);
+
+ if(factory==NULL && ext_pub_list==NULL){ //No (local or external) publishers yet for this topic
+ pubsubAdmin_addSubscriptionToPendingList(admin,subEP);
+ }
+ else{
+ int i;
+ topic_subscription_pt subscription = hashMap_get(admin->subscriptions, scope_topic);
+
+ if(subscription == NULL) {
+ pubsub_serializer_service_t *best_serializer = NULL;
+ if( (status=pubsubAdmin_getBestSerializer(admin, subEP, &best_serializer)) == CELIX_SUCCESS){
+ status += pubsub_topicSubscriptionCreate(admin->bundle_context,subEP->scope, subEP->topic, best_serializer, &subscription);
+ }
+ else{
+ printf("PSA_ZMQ: Cannot find a serializer for subscribing topic %s. Adding it to pending list.\n",subEP->topic);
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_add(admin->noSerializerSubscriptions,subEP);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+
+ if (status==CELIX_SUCCESS){
+
+ /* Try to connect internal publishers */
+ if(factory!=NULL){
+ topic_publication_pt topic_pubs = (topic_publication_pt)factory->handle;
+ array_list_pt topic_publishers = pubsub_topicPublicationGetPublisherList(topic_pubs);
+
+ if(topic_publishers!=NULL){
+ for(i=0;i<arrayList_size(topic_publishers);i++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(topic_publishers,i);
+ if(pubEP->endpoint !=NULL){
+ status += pubsub_topicSubscriptionConnectPublisher(subscription,pubEP->endpoint);
+ }
+ }
+ arrayList_destroy(topic_publishers);
+ }
+
+ }
+
+ /* Look also for external publishers */
+ if(ext_pub_list!=NULL){
+ for(i=0;i<arrayList_size(ext_pub_list);i++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
+ if(pubEP->endpoint !=NULL){
+ status += pubsub_topicSubscriptionConnectPublisher(subscription,pubEP->endpoint);
+ }
+ }
+ }
+
+ pubsub_topicSubscriptionAddSubscriber(subscription,subEP);
+
+ status += pubsub_topicSubscriptionStart(subscription);
+
+ }
+
+ if(status==CELIX_SUCCESS){
+
+ hashMap_put(admin->subscriptions,strdup(scope_topic),subscription);
+
+ connectTopicPubSubToSerializer(admin, best_serializer, subscription, false);
+ }
+ }
+
+ if (status == CELIX_SUCCESS){
+ pubsub_topicIncreaseNrSubscribers(subscription);
+ }
+ }
+
+ free(scope_topic);
+ celixThreadMutex_unlock(&admin->externalPublicationsLock);
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+ celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);
+
+ return status;
+
+}
+
+celix_status_t pubsubAdmin_removeSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ printf("PSA_ZMQ: Removing subscription [FWUUID=%s bundleID=%ld topic=%s]\n",subEP->frameworkUUID,subEP->serviceID,subEP->topic);
+
+ char* scope_topic = createScopeTopicKey(subEP->scope, subEP->topic);
+
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+ topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic);
+ if(sub!=NULL){
+ pubsub_topicDecreaseNrSubscribers(sub);
+ if(pubsub_topicGetNrSubscribers(sub) == 0) {
+ status = pubsub_topicSubscriptionRemoveSubscriber(sub,subEP);
+ }
+ }
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ if(sub==NULL){
+ /* Maybe the endpoint was pending */
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ if(!arrayList_removeElement(admin->noSerializerSubscriptions, subEP)){
+ status = CELIX_ILLEGAL_STATE;
+ }
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+
+ free(scope_topic);
+
+
+
+ return status;
+
+}
+
+celix_status_t pubsubAdmin_addPublication(pubsub_admin_pt admin, pubsub_endpoint_pt pubEP) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ printf("PSA_ZMQ: Received publication [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n", pubEP->frameworkUUID, pubEP->serviceID, pubEP->scope, pubEP->topic);
+
+ const char* fwUUID = NULL;
+
+ bundleContext_getProperty(admin->bundle_context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &fwUUID);
+ if (fwUUID == NULL) {
+ printf("PSA_ZMQ: Cannot retrieve fwUUID.\n");
+ return CELIX_INVALID_BUNDLE_CONTEXT;
+ }
+
+ char *scope_topic = createScopeTopicKey(pubEP->scope, pubEP->topic);
+
+ if ((strcmp(pubEP->frameworkUUID, fwUUID) == 0) && (pubEP->endpoint == NULL)) {
+
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+
+ service_factory_pt factory = (service_factory_pt) hashMap_get(admin->localPublications, scope_topic);
+
+ if (factory == NULL) {
+ topic_publication_pt pub = NULL;
+ pubsub_serializer_service_t *best_serializer = NULL;
+ if( (status=pubsubAdmin_getBestSerializer(admin, pubEP, &best_serializer)) == CELIX_SUCCESS){
+ status = pubsub_topicPublicationCreate(admin->bundle_context, pubEP, best_serializer, admin->ipAddress, admin->basePort, admin->maxPort, &pub);
+ }
+ else{
+ printf("PSA_ZMQ: Cannot find a serializer for publishing topic %s. Adding it to pending list.\n", pubEP->topic);
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_add(admin->noSerializerPublications,pubEP);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = pubsub_topicPublicationStart(admin->bundle_context, pub, &factory);
+ if (status == CELIX_SUCCESS && factory != NULL) {
+ hashMap_put(admin->localPublications, strdup(scope_topic), factory);
+ connectTopicPubSubToSerializer(admin, best_serializer, pub, true);
+ }
+ } else {
+ printf("PSA_ZMQ: Cannot create a topicPublication for scope=%s, topic=%s (bundle %ld).\n", pubEP->scope, pubEP->topic, pubEP->serviceID);
+ }
+ } else {
+ //just add the new EP to the list
+ topic_publication_pt pub = (topic_publication_pt) factory->handle;
+ pubsub_topicPublicationAddPublisherEP(pub, pubEP);
+ }
+
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+ }
+ else{
+
+ celixThreadMutex_lock(&admin->externalPublicationsLock);
+ array_list_pt ext_pub_list = (array_list_pt) hashMap_get(admin->externalPublications, scope_topic);
+ if (ext_pub_list == NULL) {
+ arrayList_create(&ext_pub_list);
+ hashMap_put(admin->externalPublications, strdup(scope_topic), ext_pub_list);
+ }
+
+ arrayList_add(ext_pub_list, pubEP);
+
+ celixThreadMutex_unlock(&admin->externalPublicationsLock);
+ }
+
+ /* Re-evaluate the pending subscriptions */
+ celixThreadMutex_lock(&admin->pendingSubscriptionsLock);
+
+ hash_map_entry_pt pendingSub = hashMap_getEntry(admin->pendingSubscriptions, scope_topic);
+ if (pendingSub != NULL) { //There were pending subscription for the just published topic. Let's connect them.
+ char* topic = (char*) hashMapEntry_getKey(pendingSub);
+ array_list_pt pendingSubList = (array_list_pt) hashMapEntry_getValue(pendingSub);
+ int i;
+ for (i = 0; i < arrayList_size(pendingSubList); i++) {
+ pubsub_endpoint_pt subEP = (pubsub_endpoint_pt) arrayList_get(pendingSubList, i);
+ pubsubAdmin_addSubscription(admin, subEP);
+ }
+ hashMap_remove(admin->pendingSubscriptions, scope_topic);
+ arrayList_clear(pendingSubList);
+ arrayList_destroy(pendingSubList);
+ free(topic);
+ }
+
+ celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);
+
+ /* Connect the new publisher to the subscription for his topic, if there is any */
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+
+ topic_subscription_pt sub = (topic_subscription_pt) hashMap_get(admin->subscriptions, scope_topic);
+ if (sub != NULL && pubEP->endpoint != NULL) {
+ pubsub_topicSubscriptionAddConnectPublisherToPendingList(sub, pubEP->endpoint);
+ }
+
+ /* And check also for ANY subscription */
+ topic_subscription_pt any_sub = (topic_subscription_pt) hashMap_get(admin->subscriptions, PUBSUB_ANY_SUB_TOPIC);
+ if (any_sub != NULL && pubEP->endpoint != NULL) {
+ pubsub_topicSubscriptionAddConnectPublisherToPendingList(any_sub, pubEP->endpoint);
+ }
+
+ free(scope_topic);
+
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ return status;
+
+}
+
+celix_status_t pubsubAdmin_removePublication(pubsub_admin_pt admin,pubsub_endpoint_pt pubEP){
+ celix_status_t status = CELIX_SUCCESS;
+ int count = 0;
+
+ printf("PSA_ZMQ: Removing publication [FWUUID=%s bundleID=%ld topic=%s]\n",pubEP->frameworkUUID,pubEP->serviceID,pubEP->topic);
+
+ const char* fwUUID = NULL;
+
+ bundleContext_getProperty(admin->bundle_context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
+ if(fwUUID==NULL){
+ printf("PSA_ZMQ: Cannot retrieve fwUUID.\n");
+ return CELIX_INVALID_BUNDLE_CONTEXT;
+ }
+ char *scope_topic = createScopeTopicKey(pubEP->scope, pubEP->topic);
+
+ if(strcmp(pubEP->frameworkUUID,fwUUID)==0){
+
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ service_factory_pt factory = (service_factory_pt)hashMap_get(admin->localPublications,scope_topic);
+ if(factory!=NULL){
+ topic_publication_pt pub = (topic_publication_pt)factory->handle;
+ pubsub_topicPublicationRemovePublisherEP(pub,pubEP);
+ }
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+ if(factory==NULL){
+ /* Maybe the endpoint was pending */
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ if(!arrayList_removeElement(admin->noSerializerPublications, pubEP)){
+ status = CELIX_ILLEGAL_STATE;
+ }
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+ }
+ else{
+
+ celixThreadMutex_lock(&admin->externalPublicationsLock);
+ array_list_pt ext_pub_list = (array_list_pt)hashMap_get(admin->externalPublications,scope_topic);
+ if(ext_pub_list!=NULL){
+ int i;
+ bool found = false;
+ for(i=0;!found && i<arrayList_size(ext_pub_list);i++){
+ pubsub_endpoint_pt p = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
+ found = pubsubEndpoint_equals(pubEP,p);
+ if (found){
+ arrayList_remove(ext_pub_list,i);
+ }
+ }
+ // Check if there are more publishers on the same endpoint (happens when 1 celix-instance with multiple bundles publish in same topic)
+ for(i=0; i<arrayList_size(ext_pub_list);i++) {
+ pubsub_endpoint_pt p = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
+ if (strcmp(pubEP->endpoint,p->endpoint) == 0) {
+ count++;
+ }
+ }
+
+ if(arrayList_size(ext_pub_list)==0){
+ hash_map_entry_pt entry = hashMap_getEntry(admin->externalPublications,scope_topic);
+ char* topic = (char*)hashMapEntry_getKey(entry);
+ array_list_pt list = (array_list_pt)hashMapEntry_getValue(entry);
+ hashMap_remove(admin->externalPublications,topic);
+ arrayList_destroy(list);
+ free(topic);
+ }
+ }
+
+ celixThreadMutex_unlock(&admin->externalPublicationsLock);
+ }
+
+ /* Check if this publisher was connected to one of our subscribers*/
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+
+ topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic);
+ if(sub!=NULL && pubEP->endpoint!=NULL && count == 0){
+ pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(sub,pubEP->endpoint);
+ }
+
+ /* And check also for ANY subscription */
+ topic_subscription_pt any_sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,PUBSUB_ANY_SUB_TOPIC);
+ if(any_sub!=NULL && pubEP->endpoint!=NULL && count == 0){
+ pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(any_sub,pubEP->endpoint);
+ }
+
+ free(scope_topic);
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ return status;
+
+}
+
+celix_status_t pubsubAdmin_closeAllPublications(pubsub_admin_pt admin, char *scope, char* topic){
+ celix_status_t status = CELIX_SUCCESS;
+
+ printf("PSA_ZMQ: Closing all publications\n");
+
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ char *scope_topic = createScopeTopicKey(scope, topic);
+ hash_map_entry_pt pubsvc_entry = (hash_map_entry_pt)hashMap_getEntry(admin->localPublications,scope_topic);
+ if(pubsvc_entry!=NULL){
+ char* key = (char*)hashMapEntry_getKey(pubsvc_entry);
+ service_factory_pt factory= (service_factory_pt)hashMapEntry_getValue(pubsvc_entry);
+ topic_publication_pt pub = (topic_publication_pt)factory->handle;
+ status += pubsub_topicPublicationStop(pub);
+ disconnectTopicPubSubFromSerializer(admin, pub, true);
+ status += pubsub_topicPublicationDestroy(pub);
+ hashMap_remove(admin->localPublications,scope_topic);
+ free(key);
+ free(factory);
+ }
+ free(scope_topic);
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+ return status;
+
+}
+
+celix_status_t pubsubAdmin_closeAllSubscriptions(pubsub_admin_pt admin,char* scope,char* topic){
+ celix_status_t status = CELIX_SUCCESS;
+
+ printf("PSA_ZMQ: Closing all subscriptions\n");
+
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+ char *scope_topic = createScopeTopicKey(scope, topic);
+ hash_map_entry_pt sub_entry = (hash_map_entry_pt)hashMap_getEntry(admin->subscriptions,scope_topic);
+ if(sub_entry!=NULL){
+ char* topic = (char*)hashMapEntry_getKey(sub_entry);
+
+ topic_subscription_pt ts = (topic_subscription_pt)hashMapEntry_getValue(sub_entry);
+ status += pubsub_topicSubscriptionStop(ts);
+ disconnectTopicPubSubFromSerializer(admin, ts, false);
+ status += pubsub_topicSubscriptionDestroy(ts);
+ hashMap_remove(admin->subscriptions,scope_topic);
+ free(topic);
+
+ }
+ free(scope_topic);
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ return status;
+
+}
+
+
+#ifndef ANDROID
+static celix_status_t pubsubAdmin_getIpAdress(const char* interface, char** ip) {
+ celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+
+ struct ifaddrs *ifaddr, *ifa;
+ char host[NI_MAXHOST];
+
+ if (getifaddrs(&ifaddr) != -1)
+ {
+ for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
+ {
+ if (ifa->ifa_addr == NULL)
+ continue;
+
+ if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
+ if (interface == NULL) {
+ *ip = strdup(host);
+ status = CELIX_SUCCESS;
+ }
+ else if (strcmp(ifa->ifa_name, interface) == 0) {
+ *ip = strdup(host);
+ status = CELIX_SUCCESS;
+ }
+ }
+ }
+
+ freeifaddrs(ifaddr);
+ }
+
+ return status;
+}
+#endif
+
+static celix_status_t pubsubAdmin_addSubscriptionToPendingList(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+ char* scope_topic = createScopeTopicKey(subEP->scope, subEP->topic);
+ array_list_pt pendingListPerTopic = hashMap_get(admin->pendingSubscriptions,scope_topic);
+ if(pendingListPerTopic==NULL){
+ arrayList_create(&pendingListPerTopic);
+ hashMap_put(admin->pendingSubscriptions,strdup(scope_topic),pendingListPerTopic);
+ }
+ arrayList_add(pendingListPerTopic,subEP);
+ free(scope_topic);
+ return status;
+}
+
+celix_status_t pubsubAdmin_serializerAdded(void * handle, service_reference_pt reference, void * service){
+ /* Assumption: serializers are all available at startup.
+ * If a new (possibly better) serializer is installed and started, already created topic_publications/subscriptions will not be destroyed and recreated */
+
+ celix_status_t status = CELIX_SUCCESS;
+ int i=0;
+
+ const char *serType = NULL;
+ serviceReference_getProperty(reference, PUBSUB_SERIALIZER_TYPE_KEY,&serType);
+ if(serType == NULL){
+ printf("Serializer serviceReference %p has no pubsub_serializer.type property specified\n",reference);
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+ pubsub_admin_pt admin = (pubsub_admin_pt)handle;
+ celixThreadMutex_lock(&admin->serializerListLock);
+ arrayList_add(admin->serializerList, reference);
+ celixThreadMutex_unlock(&admin->serializerListLock);
+
+ /* Now let's re-evaluate the pending */
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+
+ for(i=0;i<arrayList_size(admin->noSerializerSubscriptions);i++){
+ pubsub_endpoint_pt ep = (pubsub_endpoint_pt)arrayList_get(admin->noSerializerSubscriptions,i);
+ pubsub_serializer_service_t *best_serializer = NULL;
+ pubsubAdmin_getBestSerializer(admin, ep, &best_serializer);
+ if(best_serializer != NULL){ /* Finally we have a valid serializer! */
+ pubsubAdmin_addSubscription(admin, ep);
+ }
+ }
+
+ for(i=0;i<arrayList_size(admin->noSerializerPublications);i++){
+ pubsub_endpoint_pt ep = (pubsub_endpoint_pt)arrayList_get(admin->noSerializerPublications,i);
+ pubsub_serializer_service_t *best_serializer = NULL;
+ pubsubAdmin_getBestSerializer(admin, ep, &best_serializer);
+ if(best_serializer != NULL){ /* Finally we have a valid serializer! */
+ pubsubAdmin_addPublication(admin, ep);
+ }
+ }
+
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+
+ printf("PSA_ZMQ: %s serializer added\n",serType);
+
+ return status;
+}
+
+celix_status_t pubsubAdmin_serializerRemoved(void * handle, service_reference_pt reference, void * service){
+
+ pubsub_admin_pt admin = (pubsub_admin_pt)handle;
+ int i=0, j=0;
+ const char *serType = NULL;
+
+ serviceReference_getProperty(reference, PUBSUB_SERIALIZER_TYPE_KEY,&serType);
+ if(serType == NULL){
+ printf("Serializer serviceReference %p has no pubsub_serializer.type property specified\n",reference);
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+ celixThreadMutex_lock(&admin->serializerListLock);
+ /* Remove the serializer from the list */
+ arrayList_removeElement(admin->serializerList, reference);
+ celixThreadMutex_unlock(&admin->serializerListLock);
+
+
+ celixThreadMutex_lock(&admin->usedSerializersLock);
+ array_list_pt topicPubList = (array_list_pt)hashMap_remove(admin->topicPublicationsPerSerializer, service);
+ array_list_pt topicSubList = (array_list_pt)hashMap_remove(admin->topicSubscriptionsPerSerializer, service);
+ celixThreadMutex_unlock(&admin->usedSerializersLock);
+
+ /* Now destroy the topicPublications, but first put back the pubsub_endpoints back to the noSerializer pending list */
+ if(topicPubList!=NULL){
+ for(i=0;i<arrayList_size(topicPubList);i++){
+ topic_publication_pt topicPub = (topic_publication_pt)arrayList_get(topicPubList,i);
+ /* Stop the topic publication */
+ pubsub_topicPublicationStop(topicPub);
+ /* Get the endpoints that are going to be orphan */
+ array_list_pt pubList = pubsub_topicPublicationGetPublisherList(topicPub);
+ for(j=0;j<arrayList_size(pubList);j++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pubList,j);
+ /* Remove the publication */
+ pubsubAdmin_removePublication(admin, pubEP);
+ /* Reset the endpoint field, so that will be recreated from scratch when a new serializer will be found */
+ if(pubEP->endpoint!=NULL){
+ free(pubEP->endpoint);
+ pubEP->endpoint = NULL;
+ }
+ /* Add the orphan endpoint to the noSerializer pending list */
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_add(admin->noSerializerPublications,pubEP);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+ arrayList_destroy(pubList);
+
+ /* Cleanup also the localPublications hashmap*/
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ hash_map_iterator_pt iter = hashMapIterator_create(admin->localPublications);
+ char *key = NULL;
+ service_factory_pt factory = NULL;
+ while(hashMapIterator_hasNext(iter)){
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ factory = (service_factory_pt)hashMapEntry_getValue(entry);
+ topic_publication_pt pub = (topic_publication_pt)factory->handle;
+ if(pub==topicPub){
+ key = (char*)hashMapEntry_getKey(entry);
+ break;
+ }
+ }
+ hashMapIterator_destroy(iter);
+ if(key!=NULL){
+ hashMap_remove(admin->localPublications, key);
+ free(factory);
+ free(key);
+ }
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+ /* Finally destroy the topicPublication */
+ pubsub_topicPublicationDestroy(topicPub);
+ }
+ arrayList_destroy(topicPubList);
+ }
+
+ /* Now destroy the topicSubscriptions, but first put back the pubsub_endpoints back to the noSerializer pending list */
+ if(topicSubList!=NULL){
+ for(i=0;i<arrayList_size(topicSubList);i++){
+ topic_subscription_pt topicSub = (topic_subscription_pt)arrayList_get(topicSubList,i);
+ /* Stop the topic subscription */
+ pubsub_topicSubscriptionStop(topicSub);
+ /* Get the endpoints that are going to be orphan */
+ array_list_pt subList = pubsub_topicSubscriptionGetSubscribersList(topicSub);
+ for(j=0;j<arrayList_size(subList);j++){
+ pubsub_endpoint_pt subEP = (pubsub_endpoint_pt)arrayList_get(subList,j);
+ /* Remove the subscription */
+ pubsubAdmin_removeSubscription(admin, subEP);
+ /* Reset the endpoint field, so that will be recreated from scratch when a new serializer will be found */
+ if(subEP->endpoint!=NULL){
+ free(subEP->endpoint);
+ subEP->endpoint = NULL;
+ }
+ /* Add the orphan endpoint to the noSerializer pending list */
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_add(admin->noSerializerSubscriptions,subEP);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+
+ /* Cleanup also the subscriptions hashmap*/
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+ hash_map_iterator_pt iter = hashMapIterator_create(admin->subscriptions);
+ char *key = NULL;
+ while(hashMapIterator_hasNext(iter)){
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ topic_subscription_pt sub = (topic_subscription_pt)hashMapEntry_getValue(entry);
+ if(sub==topicSub){
+ key = (char*)hashMapEntry_getKey(entry);
+ break;
+ }
+ }
+ hashMapIterator_destroy(iter);
+ if(key!=NULL){
+ hashMap_remove(admin->subscriptions, key);
+ free(key);
+ }
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ /* Finally destroy the topicSubscription */
+ pubsub_topicSubscriptionDestroy(topicSub);
+ }
+ arrayList_destroy(topicSubList);
+ }
+
+
+
+ printf("PSA_ZMQ: %s serializer removed\n",serType);
+
+
+ return CELIX_SUCCESS;
+}
+
+celix_status_t pubsubAdmin_matchEndpoint(pubsub_admin_pt admin, pubsub_endpoint_pt endpoint, double* score){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&admin->serializerListLock);
+ status = pubsub_admin_match(endpoint->topic_props,PUBSUB_ADMIN_TYPE,admin->serializerList,score);
+ celixThreadMutex_unlock(&admin->serializerListLock);
+
+ return status;
+}
+
+/* This one recall the same logic as in the match function */
+static celix_status_t pubsubAdmin_getBestSerializer(pubsub_admin_pt admin,pubsub_endpoint_pt ep, pubsub_serializer_service_t **serSvc){
+
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&admin->serializerListLock);
+ status = pubsub_admin_get_best_serializer(ep->topic_props, admin->serializerList, serSvc);
+ celixThreadMutex_unlock(&admin->serializerListLock);
+
+ return status;
+
+}
+
+static void connectTopicPubSubToSerializer(pubsub_admin_pt admin,pubsub_serializer_service_t *serializer,void *topicPubSub,bool isPublication){
+
+ celixThreadMutex_lock(&admin->usedSerializersLock);
+
+ hash_map_pt map = isPublication?admin->topicPublicationsPerSerializer:admin->topicSubscriptionsPerSerializer;
+ array_list_pt list = (array_list_pt)hashMap_get(map,serializer);
+ if(list==NULL){
+ arrayList_create(&list);
+ hashMap_put(map,serializer,list);
+ }
+ arrayList_add(list,topicPubSub);
+
+ celixThreadMutex_unlock(&admin->usedSerializersLock);
+
+}
+
+static void disconnectTopicPubSubFromSerializer(pubsub_admin_pt admin,void *topicPubSub,bool isPublication){
+
+ celixThreadMutex_lock(&admin->usedSerializersLock);
+
+ hash_map_pt map = isPublication?admin->topicPublicationsPerSerializer:admin->topicSubscriptionsPerSerializer;
+ hash_map_iterator_pt iter = hashMapIterator_create(map);
+ while(hashMapIterator_hasNext(iter)){
+ array_list_pt list = (array_list_pt)hashMapIterator_nextValue(iter);
+ if(arrayList_removeElement(list, topicPubSub)){ //Found it!
+ break;
+ }
+ }
+ hashMapIterator_destroy(iter);
+
+ celixThreadMutex_unlock(&admin->usedSerializersLock);
+
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.h b/pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.h
new file mode 100644
index 0000000..03e8556
--- /dev/null
+++ b/pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.h
@@ -0,0 +1,109 @@
+/**
+ *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.
+ */
+/*
+ * pubsub_admin_impl.h
+ *
+ * \date Dec 5, 2013
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PUBSUB_ADMIN_ZMQ_IMPL_H_
+#define PUBSUB_ADMIN_ZMQ_IMPL_H_
+
+#include <czmq.h>
+/* The following undefs prevent the collision between:
+ * - sys/syslog.h (which is included within czmq)
+ * - celix/dfi/dfi_log_util.h
+ */
+#undef LOG_DEBUG
+#undef LOG_WARNING
+#undef LOG_INFO
+#undef LOG_WARNING
+
+#include "pubsub_admin.h"
+#include "pubsub_admin_match.h"
+#include "log_helper.h"
+
+#define PSA_ZMQ_BASE_PORT "PSA_ZMQ_BASE_PORT"
+#define PSA_ZMQ_MAX_PORT "PSA_ZMQ_MAX_PORT"
+
+#define PSA_ZMQ_DEFAULT_BASE_PORT 5501
+#define PSA_ZMQ_DEFAULT_MAX_PORT 6000
+
+#define PUBSUB_ADMIN_TYPE "zmq"
+
+struct pubsub_admin {
+
+ bundle_context_pt bundle_context;
+ log_helper_pt loghelper;
+
+ /* List of the available serializers */
+ celix_thread_mutex_t serializerListLock; // List<serializers>
+ array_list_pt serializerList;
+
+ celix_thread_mutex_t localPublicationsLock;
+ hash_map_pt localPublications;//<topic(string),service_factory_pt>
+
+ celix_thread_mutex_t externalPublicationsLock;
+ hash_map_pt externalPublications;//<topic(string),List<pubsub_ep>>
+
+ celix_thread_mutex_t subscriptionsLock;
+ hash_map_pt subscriptions; //<topic(string),topic_subscription>
+
+ celix_thread_mutex_t pendingSubscriptionsLock;
+ celix_thread_mutexattr_t pendingSubscriptionsAttr;
+ hash_map_pt pendingSubscriptions; //<topic(string),List<pubsub_ep>>
+
+ /* Those are used to keep track of valid subscriptions/publications that still have no valid serializer */
+ celix_thread_mutex_t noSerializerPendingsLock;
+ celix_thread_mutexattr_t noSerializerPendingsAttr;
+ array_list_pt noSerializerSubscriptions; // List<pubsub_ep>
+ array_list_pt noSerializerPublications; // List<pubsub_ep>
+
+ celix_thread_mutex_t usedSerializersLock;
+ hash_map_pt topicSubscriptionsPerSerializer; // <serializer,List<topicSubscription>>
+ hash_map_pt topicPublicationsPerSerializer; // <serializer,List<topicPublications>>
+
+ char* ipAddress;
+
+ zactor_t* zmq_auth;
+
+ unsigned int basePort;
+ unsigned int maxPort;
+};
+
+celix_status_t pubsubAdmin_create(bundle_context_pt context, pubsub_admin_pt *admin);
+celix_status_t pubsubAdmin_destroy(pubsub_admin_pt admin);
+
+celix_status_t pubsubAdmin_addSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
+celix_status_t pubsubAdmin_removeSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
+
+celix_status_t pubsubAdmin_addPublication(pubsub_admin_pt admin,pubsub_endpoint_pt pubEP);
+celix_status_t pubsubAdmin_removePublication(pubsub_admin_pt admin,pubsub_endpoint_pt pubEP);
+
+celix_status_t pubsubAdmin_closeAllPublications(pubsub_admin_pt admin,char* scope, char* topic);
+celix_status_t pubsubAdmin_closeAllSubscriptions(pubsub_admin_pt admin,char* scope,char* topic);
+
+celix_status_t pubsubAdmin_serializerAdded(void * handle, service_reference_pt reference, void * service);
+celix_status_t pubsubAdmin_serializerRemoved(void * handle, service_reference_pt reference, void * service);
+
+celix_status_t pubsubAdmin_matchEndpoint(pubsub_admin_pt admin, pubsub_endpoint_pt endpoint, double* score);
+
+#endif /* PUBSUB_ADMIN_ZMQ_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/src/topic_publication.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/src/topic_publication.c b/pubsub/pubsub_admin_zmq/src/topic_publication.c
new file mode 100644
index 0000000..e405866
--- /dev/null
+++ b/pubsub/pubsub_admin_zmq/src/topic_publication.c
@@ -0,0 +1,630 @@
+/**
+ *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.
+ */
+
+#include <czmq.h>
+/* The following undefs prevent the collision between:
+ * - sys/syslog.h (which is included within czmq)
+ * - celix/dfi/dfi_log_util.h
+ */
+#undef LOG_DEBUG
+#undef LOG_WARNING
+#undef LOG_INFO
+#undef LOG_WARNING
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "array_list.h"
+#include "celixbool.h"
+#include "service_registration.h"
+#include "utils.h"
+#include "service_factory.h"
+#include "version.h"
+
+#include "pubsub_common.h"
+#include "pubsub_utils.h"
+#include "publisher.h"
+
+#include "topic_publication.h"
+
+#include "pubsub_serializer.h"
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ #include "zmq_crypto.h"
+
+ #define MAX_CERT_PATH_LENGTH 512
+#endif
+
+#define EP_ADDRESS_LEN 32
+#define ZMQ_BIND_MAX_RETRY 5
+
+#define FIRST_SEND_DELAY 2
+
+struct topic_publication {
+ zsock_t* zmq_socket;
+ celix_thread_mutex_t socket_lock; //Protects zmq_socket access
+ zcert_t * zmq_cert;
+ char* endpoint;
+ service_registration_pt svcFactoryReg;
+ array_list_pt pub_ep_list; //List<pubsub_endpoint>
+ hash_map_pt boundServices; //<bundle_pt,bound_service>
+ pubsub_serializer_service_t *serializer;
+ celix_thread_mutex_t tp_lock;
+};
+
+typedef struct publish_bundle_bound_service {
+ topic_publication_pt parent;
+ pubsub_publisher_t service;
+ bundle_pt bundle;
+ char *topic;
+ hash_map_pt msgTypes;
+ unsigned short getCount;
+ celix_thread_mutex_t mp_lock; //Protects publish_bundle_bound_service data structure
+ bool mp_send_in_progress;
+ array_list_pt mp_parts;
+}* publish_bundle_bound_service_pt;
+
+/* Note: correct locking order is
+ * 1. tp_lock
+ * 2. mp_lock
+ * 3. socket_lock
+ *
+ * tp_lock and socket_lock are independent.
+ */
+
+typedef struct pubsub_msg{
+ pubsub_msg_header_pt header;
+ char* payload;
+ int payloadSize;
+}* pubsub_msg_pt;
+
+static unsigned int rand_range(unsigned int min, unsigned int max);
+
+static celix_status_t pubsub_topicPublicationGetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service);
+static celix_status_t pubsub_topicPublicationUngetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service);
+
+static publish_bundle_bound_service_pt pubsub_createPublishBundleBoundService(topic_publication_pt tp,bundle_pt bundle);
+static void pubsub_destroyPublishBundleBoundService(publish_bundle_bound_service_pt boundSvc);
+
+static int pubsub_topicPublicationSend(void* handle,unsigned int msgTypeId, const void *msg);
+static int pubsub_topicPublicationSendMultipart(void *handle, unsigned int msgTypeId, const void *inMsg, int flags);
+static int pubsub_localMsgTypeIdForUUID(void* handle, const char* msgType, unsigned int* msgTypeId);
+
+static void delay_first_send_for_late_joiners(void);
+
+celix_status_t pubsub_topicPublicationCreate(bundle_context_pt bundle_context, pubsub_endpoint_pt pubEP, pubsub_serializer_service_t *best_serializer, char* bindIP, unsigned int basePort, unsigned int maxPort, topic_publication_pt *out){
+ celix_status_t status = CELIX_SUCCESS;
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ char* secure_topics = NULL;
+ bundleContext_getProperty(bundle_context, "SECURE_TOPICS", (const char **) &secure_topics);
+
+ if (secure_topics){
+ array_list_pt secure_topics_list = pubsub_getTopicsFromString(secure_topics);
+
+ int i;
+ int secure_topics_size = arrayList_size(secure_topics_list);
+ for (i = 0; i < secure_topics_size; i++){
+ char* top = arrayList_get(secure_topics_list, i);
+ if (strcmp(pubEP->topic, top) == 0){
+ printf("PSA_ZMQ_TP: Secure topic: '%s'\n", top);
+ pubEP->is_secure = true;
+ }
+ free(top);
+ top = NULL;
+ }
+
+ arrayList_destroy(secure_topics_list);
+ }
+
+ zcert_t* pub_cert = NULL;
+ if (pubEP->is_secure){
+ char* keys_bundle_dir = pubsub_getKeysBundleDir(bundle_context);
+ if (keys_bundle_dir == NULL){
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+ const char* keys_file_path = NULL;
+ const char* keys_file_name = NULL;
+ bundleContext_getProperty(bundle_context, PROPERTY_KEYS_FILE_PATH, &keys_file_path);
+ bundleContext_getProperty(bundle_context, PROPERTY_KEYS_FILE_NAME, &keys_file_name);
+
+ char cert_path[MAX_CERT_PATH_LENGTH];
+
+ //certificate path ".cache/bundle{id}/version0.0/./META-INF/keys/publisher/private/pub_{topic}.key"
+ snprintf(cert_path, MAX_CERT_PATH_LENGTH, "%s/META-INF/keys/publisher/private/pub_%s.key.enc", keys_bundle_dir, pubEP->topic);
+ free(keys_bundle_dir);
+ printf("PSA_ZMQ_TP: Loading key '%s'\n", cert_path);
+
+ pub_cert = get_zcert_from_encoded_file((char *) keys_file_path, (char *) keys_file_name, cert_path);
+ if (pub_cert == NULL){
+ printf("PSA_ZMQ_TP: Cannot load key '%s'\n", cert_path);
+ printf("PSA_ZMQ_TP: Topic '%s' NOT SECURED !\n", pubEP->topic);
+ pubEP->is_secure = false;
+ }
+ }
+#endif
+
+ zsock_t* socket = zsock_new (ZMQ_PUB);
+ if(socket==NULL){
+ #ifdef BUILD_WITH_ZMQ_SECURITY
+ if (pubEP->is_secure){
+ zcert_destroy(&pub_cert);
+ }
+ #endif
+
+ perror("Error for zmq_socket");
+ return CELIX_SERVICE_EXCEPTION;
+ }
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ if (pubEP->is_secure){
+ zcert_apply (pub_cert, socket); // apply certificate to socket
+ zsock_set_curve_server (socket, true); // setup the publisher's socket to use the curve functions
+ }
+#endif
+
+ int rv = -1, retry=0;
+ char* ep = malloc(EP_ADDRESS_LEN);
+ char bindAddress[EP_ADDRESS_LEN];
+
+ while(rv==-1 && retry<ZMQ_BIND_MAX_RETRY){
+ /* Randomized part due to same bundle publishing on different topics */
+ unsigned int port = rand_range(basePort,maxPort);
+ memset(ep,0,EP_ADDRESS_LEN);
+ memset(bindAddress, 0, EP_ADDRESS_LEN);
+
+ snprintf(ep,EP_ADDRESS_LEN,"tcp://%s:%u",bindIP,port);
+ snprintf(bindAddress, EP_ADDRESS_LEN, "tcp://0.0.0.0:%u", port); //NOTE using a different bind addres than endpoint address
+ rv = zsock_bind (socket, "%s", bindAddress);
+ if (rv == -1) {
+ perror("Error for zmq_bind");
+ }
+ retry++;
+ }
+
+ if(rv == -1){
+ free(ep);
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+ /* ZMQ stuffs are all fine at this point. Let's create and initialize the structure */
+
+ topic_publication_pt pub = calloc(1,sizeof(*pub));
+
+ arrayList_create(&(pub->pub_ep_list));
+ pub->boundServices = hashMap_create(NULL,NULL,NULL,NULL);
+ celixThreadMutex_create(&(pub->tp_lock),NULL);
+
+ pub->endpoint = ep;
+ pub->zmq_socket = socket;
+ pub->serializer = best_serializer;
+
+ celixThreadMutex_create(&(pub->socket_lock),NULL);
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ if (pubEP->is_secure){
+ pub->zmq_cert = pub_cert;
+ }
+#endif
+
+ pubsub_topicPublicationAddPublisherEP(pub,pubEP);
+
+ *out = pub;
+
+ return status;
+}
+
+celix_status_t pubsub_topicPublicationDestroy(topic_publication_pt pub){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&(pub->tp_lock));
+
+ free(pub->endpoint);
+ arrayList_destroy(pub->pub_ep_list);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(pub->boundServices);
+ while(hashMapIterator_hasNext(iter)){
+ publish_bundle_bound_service_pt bound = hashMapIterator_nextValue(iter);
+ pubsub_destroyPublishBundleBoundService(bound);
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(pub->boundServices,false,false);
+
+ pub->svcFactoryReg = NULL;
+ pub->serializer = NULL;
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ zcert_destroy(&(pub->zmq_cert));
+#endif
+
+ celixThreadMutex_unlock(&(pub->tp_lock));
+
+ celixThreadMutex_destroy(&(pub->tp_lock));
+
+ celixThreadMutex_lock(&(pub->socket_lock));
+ zsock_destroy(&(pub->zmq_socket));
+ celixThreadMutex_unlock(&(pub->socket_lock));
+
+ celixThreadMutex_destroy(&(pub->socket_lock));
+
+ free(pub);
+
+ return status;
+}
+
+celix_status_t pubsub_topicPublicationStart(bundle_context_pt bundle_context,topic_publication_pt pub,service_factory_pt* svcFactory){
+ celix_status_t status = CELIX_SUCCESS;
+
+ /* Let's register the new service */
+
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pub->pub_ep_list,0);
+
+ if(pubEP!=NULL){
+ service_factory_pt factory = calloc(1, sizeof(*factory));
+ factory->handle = pub;
+ factory->getService = pubsub_topicPublicationGetService;
+ factory->ungetService = pubsub_topicPublicationUngetService;
+
+ properties_pt props = properties_create();
+ properties_set(props,PUBSUB_PUBLISHER_TOPIC,pubEP->topic);
+ properties_set(props,PUBSUB_PUBLISHER_SCOPE,pubEP->scope);
+ properties_set(props,"service.version", PUBSUB_PUBLISHER_SERVICE_VERSION);
+
+ status = bundleContext_registerServiceFactory(bundle_context,PUBSUB_PUBLISHER_SERVICE_NAME,factory,props,&(pub->svcFactoryReg));
+
+ if(status != CELIX_SUCCESS){
+ properties_destroy(props);
+ printf("PSA_ZMQ_PSA_ZMQ_TP: Cannot register ServiceFactory for topic %s (bundle %ld).\n",pubEP->topic,pubEP->serviceID);
+ }
+ else{
+ *svcFactory = factory;
+ }
+ }
+ else{
+ printf("PSA_ZMQ_PSA_ZMQ_TP: Cannot find pubsub_endpoint after adding it...Should never happen!\n");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+
+ return status;
+}
+
+celix_status_t pubsub_topicPublicationStop(topic_publication_pt pub){
+ return serviceRegistration_unregister(pub->svcFactoryReg);
+}
+
+celix_status_t pubsub_topicPublicationAddPublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep){
+
+ celixThreadMutex_lock(&(pub->tp_lock));
+ ep->endpoint = strdup(pub->endpoint);
+ arrayList_add(pub->pub_ep_list,ep);
+ celixThreadMutex_unlock(&(pub->tp_lock));
+
+ return CELIX_SUCCESS;
+}
+
+celix_status_t pubsub_topicPublicationRemovePublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep){
+
+ celixThreadMutex_lock(&(pub->tp_lock));
+ for (int i = 0; i < arrayList_size(pub->pub_ep_list); i++) {
+ pubsub_endpoint_pt e = arrayList_get(pub->pub_ep_list, i);
+ if(pubsubEndpoint_equals(ep, e)) {
+ arrayList_removeElement(pub->pub_ep_list,ep);
+ break;
+ }
+ }
+ celixThreadMutex_unlock(&(pub->tp_lock));
+
+ return CELIX_SUCCESS;
+}
+
+array_list_pt pubsub_topicPublicationGetPublisherList(topic_publication_pt pub){
+ array_list_pt list = NULL;
+ celixThreadMutex_lock(&(pub->tp_lock));
+ list = arrayList_clone(pub->pub_ep_list);
+ celixThreadMutex_unlock(&(pub->tp_lock));
+ return list;
+}
+
+
+static celix_status_t pubsub_topicPublicationGetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ topic_publication_pt publish = (topic_publication_pt)handle;
+
+ celixThreadMutex_lock(&(publish->tp_lock));
+
+ publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt)hashMap_get(publish->boundServices,bundle);
+ if(bound==NULL){
+ bound = pubsub_createPublishBundleBoundService(publish,bundle);
+ if(bound!=NULL){
+ hashMap_put(publish->boundServices,bundle,bound);
+ }
+ }
+ else{
+ bound->getCount++;
+ }
+
+ *service = &bound->service;
+
+ celixThreadMutex_unlock(&(publish->tp_lock));
+
+ return status;
+}
+
+static celix_status_t pubsub_topicPublicationUngetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service) {
+
+ topic_publication_pt publish = (topic_publication_pt)handle;
+
+ celixThreadMutex_lock(&(publish->tp_lock));
+
+ publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt)hashMap_get(publish->boundServices,bundle);
+ if(bound!=NULL){
+
+ bound->getCount--;
+ if(bound->getCount==0){
+ pubsub_destroyPublishBundleBoundService(bound);
+ hashMap_remove(publish->boundServices,bundle);
+ }
+
+ }
+ else{
+ long bundleId = -1;
+ bundle_getBundleId(bundle,&bundleId);
+ printf("PSA_ZMQ_TP: Unexpected ungetService call for bundle %ld.\n", bundleId);
+ }
+
+ /* service should be never used for unget, so let's set the pointer to NULL */
+ *service = NULL;
+
+ celixThreadMutex_unlock(&(publish->tp_lock));
+
+ return CELIX_SUCCESS;
+}
+
+static bool send_pubsub_msg(zsock_t* zmq_socket, pubsub_msg_pt msg, bool last){
+
+ bool ret = true;
+
+ zframe_t* headerMsg = zframe_new(msg->header, sizeof(struct pubsub_msg_header));
+ if (headerMsg == NULL) ret=false;
+ zframe_t* payloadMsg = zframe_new(msg->payload, msg->payloadSize);
+ if (payloadMsg == NULL) ret=false;
+
+ delay_first_send_for_late_joiners();
+
+ if( zframe_send(&headerMsg,zmq_socket, ZFRAME_MORE) == -1) ret=false;
+
+ if(!last){
+ if( zframe_send(&payloadMsg,zmq_socket, ZFRAME_MORE) == -1) ret=false;
+ }
+ else{
+ if( zframe_send(&payloadMsg,zmq_socket, 0) == -1) ret=false;
+ }
+
+ if (!ret){
+ zframe_destroy(&headerMsg);
+ zframe_destroy(&payloadMsg);
+ }
+
+ free(msg->header);
+ free(msg->payload);
+ free(msg);
+
+ return ret;
+
+}
+
+static bool send_pubsub_mp_msg(zsock_t* zmq_socket, array_list_pt mp_msg_parts){
+
+ bool ret = true;
+
+ unsigned int i = 0;
+ unsigned int mp_num = arrayList_size(mp_msg_parts);
+ for(;i<mp_num;i++){
+ ret = ret && send_pubsub_msg(zmq_socket, (pubsub_msg_pt)arrayList_get(mp_msg_parts,i), (i==mp_num-1));
+ }
+ arrayList_clear(mp_msg_parts);
+
+ return ret;
+
+}
+
+static int pubsub_topicPublicationSend(void* handle, unsigned int msgTypeId, const void *msg) {
+
+ return pubsub_topicPublicationSendMultipart(handle,msgTypeId,msg, PUBSUB_PUBLISHER_FIRST_MSG | PUBSUB_PUBLISHER_LAST_MSG);
+
+}
+
+static int pubsub_topicPublicationSendMultipart(void *handle, unsigned int msgTypeId, const void *inMsg, int flags){
+
+ int status = 0;
+
+ publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt) handle;
+
+ celixThreadMutex_lock(&(bound->parent->tp_lock));
+ celixThreadMutex_lock(&(bound->mp_lock));
+ if( (flags & PUBSUB_PUBLISHER_FIRST_MSG) && !(flags & PUBSUB_PUBLISHER_LAST_MSG) && bound->mp_send_in_progress){ //means a real mp_msg
+ printf("PSA_ZMQ_TP: Multipart send already in progress. Cannot process a new one.\n");
+ celixThreadMutex_unlock(&(bound->mp_lock));
+ celixThreadMutex_unlock(&(bound->parent->tp_lock));
+ return -3;
+ }
+
+ pubsub_msg_serializer_t* msgSer = (pubsub_msg_serializer_t*)hashMap_get(bound->msgTypes, (void*)(uintptr_t)msgTypeId);
+
+ if (msgSer!= NULL) {
+ int major=0, minor=0;
+
+ pubsub_msg_header_pt msg_hdr = calloc(1,sizeof(struct pubsub_msg_header));
+ strncpy(msg_hdr->topic,bound->topic,MAX_TOPIC_LEN-1);
+ msg_hdr->type = msgTypeId;
+
+ if (msgSer->msgVersion != NULL){
+ version_getMajor(msgSer->msgVersion, &major);
+ version_getMinor(msgSer->msgVersion, &minor);
+ msg_hdr->major = major;
+ msg_hdr->minor = minor;
+ }
+
+ void *serializedOutput = NULL;
+ size_t serializedOutputLen = 0;
+ msgSer->serialize(msgSer,inMsg,&serializedOutput, &serializedOutputLen);
+
+ pubsub_msg_pt msg = calloc(1,sizeof(struct pubsub_msg));
+ msg->header = msg_hdr;
+ msg->payload = (char*)serializedOutput;
+ msg->payloadSize = serializedOutputLen;
+ bool snd = true;
+
+ switch(flags){
+ case PUBSUB_PUBLISHER_FIRST_MSG:
+ bound->mp_send_in_progress = true;
+ arrayList_add(bound->mp_parts,msg);
+ break;
+ case PUBSUB_PUBLISHER_PART_MSG:
+ if(!bound->mp_send_in_progress){
+ printf("PSA_ZMQ_TP: ERROR: received msg part without the first part.\n");
+ status = -4;
+ }
+ else{
+ arrayList_add(bound->mp_parts,msg);
+ }
+ break;
+ case PUBSUB_PUBLISHER_LAST_MSG:
+ if(!bound->mp_send_in_progress){
+ printf("PSA_ZMQ_TP: ERROR: received end msg without the first part.\n");
+ status = -4;
+ }
+ else{
+ arrayList_add(bound->mp_parts,msg);
+ snd = send_pubsub_mp_msg(bound->parent->zmq_socket,bound->mp_parts);
+ bound->mp_send_in_progress = false;
+ }
+ break;
+ case PUBSUB_PUBLISHER_FIRST_MSG | PUBSUB_PUBLISHER_LAST_MSG: //Normal send case
+ snd = send_pubsub_msg(bound->parent->zmq_socket,msg,true);
+ break;
+ default:
+ printf("PSA_ZMQ_TP: ERROR: Invalid MP flags combination\n");
+ status = -4;
+ break;
+ }
+
+ if(status==-4){
+ free(msg);
+ }
+
+ if(!snd){
+ printf("PSA_ZMQ_TP: Failed to send %s message %u.\n",flags == (PUBSUB_PUBLISHER_FIRST_MSG | PUBSUB_PUBLISHER_LAST_MSG) ? "single" : "multipart", msgTypeId);
+ }
+
+ } else {
+ printf("PSA_ZMQ_TP: No msg serializer available for msg type id %d\n", msgTypeId);
+ status=-1;
+ }
+
+ celixThreadMutex_unlock(&(bound->mp_lock));
+ celixThreadMutex_unlock(&(bound->parent->tp_lock));
+
+ return status;
+
+}
+
+static int pubsub_localMsgTypeIdForUUID(void* handle, const char* msgType, unsigned int* msgTypeId){
+ *msgTypeId = utils_stringHash(msgType);
+ return 0;
+}
+
+
+static unsigned int rand_range(unsigned int min, unsigned int max){
+
+ double scaled = (double)(((double)random())/((double)RAND_MAX));
+ return (max-min+1)*scaled + min;
+
+}
+
+static publish_bundle_bound_service_pt pubsub_createPublishBundleBoundService(topic_publication_pt tp,bundle_pt bundle){
+
+ //PRECOND lock on tp->lock
+
+ publish_bundle_bound_service_pt bound = calloc(1, sizeof(*bound));
+
+ if (bound != NULL) {
+
+ bound->parent = tp;
+ bound->bundle = bundle;
+ bound->getCount = 1;
+ bound->mp_send_in_progress = false;
+ celixThreadMutex_create(&bound->mp_lock,NULL);
+
+ if(tp->serializer != NULL){
+ tp->serializer->createSerializerMap(tp->serializer->handle,bundle,&bound->msgTypes);
+ }
+
+ arrayList_create(&bound->mp_parts);
+
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(bound->parent->pub_ep_list,0);
+ bound->topic=strdup(pubEP->topic);
+
+ bound->service.handle = bound;
+ bound->service.localMsgTypeIdForMsgType = pubsub_localMsgTypeIdForUUID;
+ bound->service.send = pubsub_topicPublicationSend;
+ bound->service.sendMultipart = pubsub_topicPublicationSendMultipart;
+
+ }
+
+ return bound;
+}
+
+static void pubsub_destroyPublishBundleBoundService(publish_bundle_bound_service_pt boundSvc){
+
+ //PRECOND lock on tp->lock
+
+ celixThreadMutex_lock(&boundSvc->mp_lock);
+
+
+ if(boundSvc->parent->serializer != NULL && boundSvc->msgTypes != NULL){
+ boundSvc->parent->serializer->destroySerializerMap(boundSvc->parent->serializer->handle, boundSvc->msgTypes);
+ }
+
+ if(boundSvc->mp_parts!=NULL){
+ arrayList_destroy(boundSvc->mp_parts);
+ }
+
+ if(boundSvc->topic!=NULL){
+ free(boundSvc->topic);
+ }
+
+ celixThreadMutex_unlock(&boundSvc->mp_lock);
+ celixThreadMutex_destroy(&boundSvc->mp_lock);
+
+ free(boundSvc);
+
+}
+
+static void delay_first_send_for_late_joiners(){
+
+ static bool firstSend = true;
+
+ if(firstSend){
+ printf("PSA_ZMQ_TP: Delaying first send for late joiners...\n");
+ sleep(FIRST_SEND_DELAY);
+ firstSend = false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/src/topic_publication.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/src/topic_publication.h b/pubsub/pubsub_admin_zmq/src/topic_publication.h
new file mode 100644
index 0000000..3457263
--- /dev/null
+++ b/pubsub/pubsub_admin_zmq/src/topic_publication.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.
+ */
+/*
+ * topic_publication.h
+ *
+ * \date Sep 24, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef TOPIC_PUBLICATION_H_
+#define TOPIC_PUBLICATION_H_
+
+#include "publisher.h"
+#include "pubsub_endpoint.h"
+#include "pubsub_common.h"
+
+#include "pubsub_serializer.h"
+
+typedef struct topic_publication *topic_publication_pt;
+
+celix_status_t pubsub_topicPublicationCreate(bundle_context_pt bundle_context,pubsub_endpoint_pt pubEP, pubsub_serializer_service_t *best_serializer, char* bindIP, unsigned int basePort, unsigned int maxPort, topic_publication_pt *out);
+celix_status_t pubsub_topicPublicationDestroy(topic_publication_pt pub);
+
+celix_status_t pubsub_topicPublicationAddPublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep);
+celix_status_t pubsub_topicPublicationRemovePublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep);
+
+celix_status_t pubsub_topicPublicationStart(bundle_context_pt bundle_context,topic_publication_pt pub,service_factory_pt* svcFactory);
+celix_status_t pubsub_topicPublicationStop(topic_publication_pt pub);
+
+array_list_pt pubsub_topicPublicationGetPublisherList(topic_publication_pt pub);
+
+#endif /* TOPIC_PUBLICATION_H_ */
[41/54] [abbrv] celix git commit: CELIX-417: Refactors cmake usage of
pubsub and rsa. Started with installing exported targets
Posted by pn...@apache.org.
CELIX-417: Refactors cmake usage of pubsub and rsa. Started with installing exported targets
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/81804e00
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/81804e00
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/81804e00
Branch: refs/heads/develop
Commit: 81804e001001de1cd7ffd86d671ef53b8e74a429
Parents: ac0d0d7
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Jan 24 19:30:21 2018 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Jan 24 19:30:21 2018 +0100
----------------------------------------------------------------------
CMakeLists.txt | 4 +
framework/CMakeLists.txt | 18 +-
log_service/CMakeLists.txt | 15 +-
pubsub/CMakeLists.txt | 38 +-
pubsub/api/pubsub/publisher.h | 88 --
pubsub/api/pubsub/subscriber.h | 75 --
pubsub/deploy/CMakeLists.txt | 229 ----
pubsub/examples/CMakeLists.txt | 213 ++++
.../examples/mp_pubsub/publisher/CMakeLists.txt | 11 +-
.../private/include/mp_publisher_private.h | 2 +-
.../publisher/private/src/mp_pub_activator.c | 48 +-
.../publisher/private/src/mp_publisher.c | 1 -
.../mp_pubsub/subscriber/CMakeLists.txt | 17 +-
.../private/include/mp_subscriber_private.h | 3 +-
.../subscriber/private/src/mp_sub_activator.c | 40 +-
pubsub/examples/pubsub/publisher/CMakeLists.txt | 21 +-
.../private/include/pubsub_publisher_private.h | 2 +-
.../publisher/private/src/ps_pub_activator.c | 54 +-
.../publisher/private/src/pubsub_publisher.c | 1 -
.../examples/pubsub/publisher2/CMakeLists.txt | 23 +-
.../examples/pubsub/subscriber/CMakeLists.txt | 27 +-
.../private/include/pubsub_subscriber_private.h | 3 +-
.../subscriber/private/src/ps_sub_activator.c | 38 +-
pubsub/mock/CMakeLists.txt | 20 +-
pubsub/pubsub_admin_udp_mc/CMakeLists.txt | 15 +-
.../pubsub_admin_udp_mc/src/pubsub_admin_impl.c | 2 +-
.../pubsub_admin_udp_mc/src/topic_publication.c | 2 +-
.../pubsub_admin_udp_mc/src/topic_publication.h | 2 +-
.../src/topic_subscription.c | 4 +-
pubsub/pubsub_admin_zmq/CMakeLists.txt | 48 +-
.../private/include/pubsub_admin_impl.h | 109 --
.../private/include/topic_publication.h | 49 -
.../private/include/topic_subscription.h | 60 -
.../private/include/zmq_crypto.h | 41 -
.../private/src/psa_activator.c | 142 ---
.../private/src/pubsub_admin_impl.c | 1040 ------------------
.../private/src/topic_publication.c | 630 -----------
.../private/src/topic_subscription.c | 732 ------------
.../pubsub_admin_zmq/private/src/zmq_crypto.c | 281 -----
pubsub/pubsub_admin_zmq/src/psa_activator.c | 142 +++
pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.c | 1040 ++++++++++++++++++
pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.h | 109 ++
pubsub/pubsub_admin_zmq/src/topic_publication.c | 630 +++++++++++
pubsub/pubsub_admin_zmq/src/topic_publication.h | 49 +
.../pubsub_admin_zmq/src/topic_subscription.c | 732 ++++++++++++
.../pubsub_admin_zmq/src/topic_subscription.h | 60 +
pubsub/pubsub_admin_zmq/src/zmq_crypto.c | 281 +++++
pubsub/pubsub_admin_zmq/src/zmq_crypto.h | 41 +
pubsub/pubsub_api/CMakeLists.txt | 32 +
pubsub/pubsub_api/include/pubsub/publisher.h | 88 ++
pubsub/pubsub_api/include/pubsub/subscriber.h | 75 ++
.../include/publisher_endpoint_announce.h | 36 -
.../pubsub_common/public/include/pubsub_admin.h | 72 --
.../public/include/pubsub_admin_match.h | 40 -
.../public/include/pubsub_common.h | 52 -
.../public/include/pubsub_endpoint.h | 58 -
.../public/include/pubsub_serializer.h | 66 --
.../public/include/pubsub_topic_info.descriptor | 10 -
.../pubsub_common/public/include/pubsub_utils.h | 39 -
.../public/src/pubsub_admin_match.c | 320 ------
.../pubsub_common/public/src/pubsub_endpoint.c | 254 -----
pubsub/pubsub_common/public/src/pubsub_utils.c | 170 ---
pubsub/pubsub_discovery/CMakeLists.txt | 15 +-
pubsub/pubsub_serializer_json/CMakeLists.txt | 13 +-
pubsub/pubsub_spi/CMakeLists.txt | 35 +
.../include/publisher_endpoint_announce.h | 36 +
pubsub/pubsub_spi/include/pubsub_admin.h | 72 ++
pubsub/pubsub_spi/include/pubsub_admin_match.h | 40 +
pubsub/pubsub_spi/include/pubsub_common.h | 52 +
pubsub/pubsub_spi/include/pubsub_endpoint.h | 58 +
pubsub/pubsub_spi/include/pubsub_serializer.h | 66 ++
.../include/pubsub_topic_info.descriptor | 10 +
pubsub/pubsub_spi/include/pubsub_utils.h | 39 +
pubsub/pubsub_spi/src/pubsub_admin_match.c | 320 ++++++
pubsub/pubsub_spi/src/pubsub_endpoint.c | 254 +++++
pubsub/pubsub_spi/src/pubsub_utils.c | 170 +++
pubsub/pubsub_topology_manager/CMakeLists.txt | 19 +-
.../private/include/pubsub_topology_manager.h | 83 --
.../private/src/pstm_activator.c | 246 -----
.../private/src/pubsub_topology_manager.c | 723 ------------
.../src/pstm_activator.c | 244 ++++
.../src/pubsub_topology_manager.c | 721 ++++++++++++
.../src/pubsub_topology_manager.h | 82 ++
pubsub/test/CMakeLists.txt | 10 +-
remote_services/CMakeLists.txt | 11 +-
remote_services/discovery_common/CMakeLists.txt | 2 +-
.../examples/calculator_service/CMakeLists.txt | 2 +-
.../remote_service_admin_api/CMakeLists.txt | 45 -
.../remote_service_admin_api/README.md | 11 -
.../include/endpoint_description.h | 50 -
.../include/endpoint_listener.h | 49 -
.../include/export_registration.h | 22 -
.../include/import_registration.h | 22 -
.../include/remote_constants.h | 38 -
.../include/remote_endpoint.h | 44 -
.../include/remote_endpoint_impl.h | 38 -
.../include/remote_proxy.h | 76 --
.../include/remote_service_admin.h | 73 --
.../remote_service_admin_common/CMakeLists.txt | 27 -
.../src/endpoint_description.c | 89 --
.../src/export_registration_impl.c | 257 -----
.../src/export_registration_impl.h | 61 -
.../src/import_registration_impl.c | 274 -----
.../src/import_registration_impl.h | 81 --
.../src/remote_proxy_factory_impl.c | 252 -----
.../src/remote_service_admin_impl.h | 49 -
.../remote_services_api/CMakeLists.txt | 28 +
remote_services/remote_services_api/README.md | 11 +
.../include/remote_constants.h | 31 +
remote_services/rsa_common/CMakeLists.txt | 29 +
.../rsa_common/src/endpoint_description.c | 89 ++
.../rsa_common/src/export_registration_impl.c | 257 +++++
.../rsa_common/src/export_registration_impl.h | 61 +
.../rsa_common/src/import_registration_impl.c | 274 +++++
.../rsa_common/src/import_registration_impl.h | 81 ++
.../rsa_common/src/remote_proxy_factory_impl.c | 252 +++++
.../rsa_common/src/remote_service_admin_impl.h | 49 +
remote_services/rsa_spi/CMakeLists.txt | 29 +
remote_services/rsa_spi/README.md | 11 +
.../rsa_spi/include/endpoint_description.h | 50 +
.../rsa_spi/include/endpoint_listener.h | 49 +
.../rsa_spi/include/export_registration.h | 22 +
.../rsa_spi/include/import_registration.h | 22 +
.../rsa_spi/include/remote_constants.h | 38 +
.../rsa_spi/include/remote_endpoint.h | 44 +
.../rsa_spi/include/remote_endpoint_impl.h | 38 +
remote_services/rsa_spi/include/remote_proxy.h | 76 ++
.../rsa_spi/include/remote_service_admin.h | 73 ++
remote_services/topology_manager/CMakeLists.txt | 2 +-
.../tms_tst/bundle/CMakeLists.txt | 2 +-
utils/CMakeLists.txt | 13 +-
131 files changed, 7540 insertions(+), 7516 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d05ec8a..aa26d8e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -95,5 +95,9 @@ add_subdirectory(pubsub)
add_subdirectory(dependency_manager)
add_subdirectory(dependency_manager_cxx)
+
+#export targets
+install(EXPORT celix NAMESPACE Celix:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/celix)
+
#Example as last, because some example will check if underlining options are enabled
add_subdirectory(examples)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/framework/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt
index a92910c..1716a7d 100644
--- a/framework/CMakeLists.txt
+++ b/framework/CMakeLists.txt
@@ -36,7 +36,10 @@ set(SOURCES
)
add_library(framework SHARED ${SOURCES})
set_target_properties(framework PROPERTIES OUTPUT_NAME "celix_framework")
-target_include_directories(framework PUBLIC include)
+target_include_directories(framework PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
+ $<INSTALL_INTERFACE:include/celix>
+)
target_include_directories(framework PRIVATE
src
${ZLIB_INCLUDE_DIR}
@@ -45,7 +48,6 @@ target_include_directories(framework PRIVATE
)
target_compile_definitions(framework PRIVATE -DUSE_FILE32API)
-include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
set_target_properties(framework PROPERTIES "SOVERSION" 2)
if(NOT APPLE)
@@ -54,16 +56,16 @@ endif()
target_link_libraries(framework PUBLIC Celix::utils)
target_link_libraries(framework PRIVATE ${UUID} ${ZLIB_LIBRARY} ${CURL_LIBRARIES})
-install(TARGETS framework DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT framework)
+install(TARGETS framework EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT framework)
+install(DIRECTORY include/ DESTINATION include/celix COMPONENT framework)
+install(DIRECTORY "${PROJECT_SOURCE_DIR}/cmake/" DESTINATION share/celix/cmake/modules COMPONENT framework
+ PATTERN "CMakeCelix-local.cmake" EXCLUDE
+)
+
#Alias setup to match external usage
add_library(Celix::framework ALIAS framework)
-install(DIRECTORY "${PROJECT_SOURCE_DIR}/cmake/" DESTINATION share/celix/cmake/modules
- COMPONENT framework
- PATTERN "CMakeCelix-local.cmake" EXCLUDE
-)
-
if (ENABLE_TESTING)
find_package(CppUTest REQUIRED)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/log_service/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/log_service/CMakeLists.txt b/log_service/CMakeLists.txt
index b9af374..70afb0e 100644
--- a/log_service/CMakeLists.txt
+++ b/log_service/CMakeLists.txt
@@ -19,12 +19,21 @@ celix_subproject(LOG_SERVICE "Option to enable building the Log Service bundles"
if (LOG_SERVICE)
add_library(log_service_api INTERFACE)
- target_include_directories(log_service_api INTERFACE include)
+ target_include_directories(log_service_api INTERFACE
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
+ $<INSTALL_INTERFACE:include/celix/log_service>
+ )
+ install(TARGETS log_service_api EXPORT celix)
+ install(DIRECTORY include/ DESTINATION include/celix/log_service)
add_library(log_helper STATIC src/log_helper.c)
- target_include_directories(log_helper PUBLIC loghelper_include)
+ target_include_directories(log_helper PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/loghelper_include>
+ $<INSTALL_INTERFACE:include/celix/log_helper>
+ )
target_link_libraries(log_helper PUBLIC Celix::framework log_service_api)
- #TODO install log helper
+ install(TARGETS log_helper EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT log_service)
+ install(DIRECTORY loghelper_include/ DESTINATION include/celix/log_helper COMPONENT log_service)
add_bundle(log_service
SYMBOLIC_NAME "apache_celix_log_service"
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/CMakeLists.txt b/pubsub/CMakeLists.txt
index 9d18175..79f8168 100644
--- a/pubsub/CMakeLists.txt
+++ b/pubsub/CMakeLists.txt
@@ -23,52 +23,24 @@ if (PUBSUB)
message(WARNING "Celix will now contain a dependency with a LGPL License (ZeroMQ). For more information about this, consult the pubsub/README.md file.")
option(BUILD_ZMQ_SECURITY "Build with security for ZeroMQ." OFF)
endif (BUILD_PUBSUB_PSA_ZMQ)
-
+
+ add_subdirectory(pubsub_api)
+ add_subdirectory(pubsub_spi)
add_subdirectory(pubsub_topology_manager)
add_subdirectory(pubsub_discovery)
add_subdirectory(pubsub_serializer_json)
add_subdirectory(pubsub_admin_zmq)
add_subdirectory(pubsub_admin_udp_mc)
- add_subdirectory(examples)
- add_subdirectory(deploy)
add_subdirectory(keygen)
add_subdirectory(mock)
+ add_subdirectory(examples)
if (ENABLE_TESTING)
- option(BUILD_PUBSUB_TESTS "Enable Tests for PUBSUB" OFF)
+ option(BUILD_PUBSUB_TESTS "Enable Tests for PUBSUB" OFF)
endif()
if (ENABLE_TESTING AND BUILD_PUBSUB_TESTS)
add_subdirectory(test)
endif()
- #api target
- add_library(pubsub_api INTERFACE)
- target_include_directories(pubsub_api INTERFACE api)
-
- #install api
- install(FILES api/pubsub/publisher.h api/pubsub/subscriber.h DESTINATION include/celix/pubsub COMPONENT framework)
-
- #install public common files
- install(FILES
- pubsub_common/public/include/pubsub_serializer.h
- pubsub_common/public/include/pubsub_utils.h
- pubsub_common/public/include/pubsub_common.h
- pubsub_common/public/include/pubsub_endpoint.h
- pubsub_common/public/include/pubsub_admin_match.h
- pubsub_common/public/include/publisher_endpoint_announce.h
- pubsub_common/public/include/pubsub_admin.h
- DESTINATION include/celix/pubsub
- COMPONENT framework
- )
- install(FILES
- pubsub_common/public/src/pubsub_admin_match.c
- pubsub_common/public/src/pubsub_utils.c
- pubsub_common/public/src/pubsub_endpoint.c
- DESTINATION share/celix/pubsub
- COMPONENT framework
- )
-
- #Setup target aliases to match external usage
- add_library(Celix::pubsub_api ALIAS pubsub_api)
endif(PUBSUB)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/api/pubsub/publisher.h
----------------------------------------------------------------------
diff --git a/pubsub/api/pubsub/publisher.h b/pubsub/api/pubsub/publisher.h
deleted file mode 100644
index 3eec149..0000000
--- a/pubsub/api/pubsub/publisher.h
+++ /dev/null
@@ -1,88 +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.
- */
-/*
- * publisher.h
- *
- * \date Jan 7, 2016
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef __PUBSUB_PUBLISHER_H_
-#define __PUBSUB_PUBLISHER_H_
-
-#include <stdlib.h>
-
-#define PUBSUB_PUBLISHER_SERVICE_NAME "pubsub.publisher"
-#define PUBSUB_PUBLISHER_SERVICE_VERSION "2.0.0"
-
-//properties
-#define PUBSUB_PUBLISHER_TOPIC "pubsub.topic"
-#define PUBSUB_PUBLISHER_SCOPE "pubsub.scope"
-#define PUBSUB_PUBLISHER_STRATEGY "pubsub.strategy"
-#define PUBSUB_PUBLISHER_CONFIG "pubsub.config"
-
-#define PUBSUB_PUBLISHER_SCOPE_DEFAULT "default"
-//flags
-#define PUBSUB_PUBLISHER_FIRST_MSG 01
-#define PUBSUB_PUBLISHER_PART_MSG 02
-#define PUBSUB_PUBLISHER_LAST_MSG 04
-
-struct pubsub_release_callback_struct {
- void *handle;
- void (*release)(char *buf, void *handle);
-};
-typedef struct pubsub_release_callback_struct pubsub_release_callback_t;
-typedef struct pubsub_release_callback_struct* pubsub_release_callback_pt;
-
-
-struct pubsub_publisher {
- void *handle;
-
- /**
- * Every msg is identifiable by msg type string. Because masg type string are performance wise not preferable (string compares),
- * a "local" (int / platform dependent) unique id will be generated runtime
- * with use of a distributed key/value store or communication between participation parties.
- * this is called the local message type id. This local message type id can be requested with the localMsgIdForMsgType method.
- * When return is successful the msgTypeId is always greater than 0. (Note this can be used to specify/detect uninitialized msg type ids in the consumer code).
- *
- * Returns 0 on success.
- */
- int (*localMsgTypeIdForMsgType)(void *handle, const char *msgType, unsigned int *msgTypeId);
-
- /**
- * send is a async function, but the msg can be safely deleted after send returns.
- * Returns 0 on success.
- */
- int (*send)(void *handle, unsigned int msgTypeId, const void *msg);
-
-
- /**
- * sendMultipart is a async function, but the msg can be safely deleted after send returns.
- * The first (primary) message of a multipart message must have the flag PUBLISHER_PRIMARY_MSG
- * The last message of a multipart message must have the flag PUBLISHER_LAST_MSG
- * Returns 0 on success.
- */
- int (*sendMultipart)(void *handle, unsigned int msgTypeId, const void *msg, int flags);
-
-};
-typedef struct pubsub_publisher pubsub_publisher_t;
-typedef struct pubsub_publisher* pubsub_publisher_pt;
-
-#endif // __PUBSUB_PUBLISHER_H_
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/api/pubsub/subscriber.h
----------------------------------------------------------------------
diff --git a/pubsub/api/pubsub/subscriber.h b/pubsub/api/pubsub/subscriber.h
deleted file mode 100644
index 5d87b8a..0000000
--- a/pubsub/api/pubsub/subscriber.h
+++ /dev/null
@@ -1,75 +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.
- */
-/*
- * subscriber.h
- *
- * \date Jan 7, 2016
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef __PUBSUB_SUBSCRIBER_H_
-#define __PUBSUB_SUBSCRIBER_H_
-
-#include <stdbool.h>
-
-#define PUBSUB_SUBSCRIBER_SERVICE_NAME "pubsub.subscriber"
-#define PUBSUB_SUBSCRIBER_SERVICE_VERSION "2.0.0"
-
-//properties
-#define PUBSUB_SUBSCRIBER_TOPIC "pubsub.topic"
-#define PUBSUB_SUBSCRIBER_SCOPE "pubsub.scope"
-#define PUBSUB_SUBSCRIBER_STRATEGY "pubsub.strategy"
-#define PUBSUB_SUBSCRIBER_CONFIG "pubsub.config"
-
-#define PUBSUB_SUBSCRIBER_SCOPE_DEFAULT "default"
-
-struct pubsub_multipart_callbacks_struct {
- void *handle;
- int (*localMsgTypeIdForMsgType)(void *handle, const char *msgType, unsigned int *msgId);
- int (*getMultipart)(void *handle, unsigned int msgTypeId, bool retain, void **part);
-};
-typedef struct pubsub_multipart_callbacks_struct pubsub_multipart_callbacks_t;
-typedef struct pubsub_multipart_callbacks_struct* pubsub_multipart_callbacks_pt;
-
-struct pubsub_subscriber_struct {
- void *handle;
-
- /**
- * When a new message for a topic is available the receive will be called.
- *
- * msgType contains fully qualified name of the type and msgTypeId is a local id which presents the type for performance reasons.
- * Release can be used to instruct the pubsubadmin to release (free) the message when receive function returns. Set it to false to take
- * over ownership of the msg (e.g. take the responsibility to free it).
- *
- * The callbacks argument is only valid inside the receive function, use the getMultipart callback, with retain=true, to keep multipart messages in memory.
- * results of the localMsgTypeIdForMsgType callback are valid during the complete lifecycle of the component, not just a single receive call.
- *
- * Return 0 implies a successful handling. If return is not 0, the msg will always be released by the pubsubadmin.
- *
- * this method can be NULL.
- */
- int (*receive)(void *handle, const char *msgType, unsigned int msgTypeId, void *msg, pubsub_multipart_callbacks_t *callbacks, bool *release);
-
-};
-typedef struct pubsub_subscriber_struct pubsub_subscriber_t;
-typedef struct pubsub_subscriber_struct* pubsub_subscriber_pt;
-
-
-#endif // __PUBSUB_SUBSCRIBER_H_
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/deploy/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/deploy/CMakeLists.txt b/pubsub/deploy/CMakeLists.txt
deleted file mode 100644
index e76f91b..0000000
--- a/pubsub/deploy/CMakeLists.txt
+++ /dev/null
@@ -1,229 +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.
-
-find_program(ETCD_CMD NAMES etcd)
-find_program(XTERM_CMD NAMES xterm)
-
-# UDP Multicast
-add_deploy(pubsub_publisher_udp_mc
- GROUP pubsub
- BUNDLES
- Celix::shell
- Celix::shell_tui
- org.apache.celix.pubsub_serializer.PubSubSerializerJson
- org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
- org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
- org.apache.celix.pubsub_admin.PubSubAdminUdpMc
- org.apache.celix.pubsub_publisher.PoiPublisher
- org.apache.celix.pubsub_publisher.PoiPublisher2
-)
-
-add_deploy("pubsub_subscriber_udp_mc"
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- org.apache.celix.pubsub_serializer.PubSubSerializerJson
- org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
- org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
- org.apache.celix.pubsub_admin.PubSubAdminUdpMc
- org.apache.celix.pubsub_subscriber.PoiSubscriber
-)
-
-add_deploy("pubsub_subscriber2_udp_mc"
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- org.apache.celix.pubsub_serializer.PubSubSerializerJson
- org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
- org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
- org.apache.celix.pubsub_admin.PubSubAdminUdpMc
- org.apache.celix.pubsub_subscriber.PoiSubscriber
-)
-
-if (ETCD_CMD AND XTERM_CMD)
- #Runtime starting a publish and subscriber for udp mc
- add_runtime(pubsub_rt_upd_mc
- NAME udp_mc
- GROUP pubsub
- DEPLOYMENTS
- pubsub_publisher_udp_mc
- pubsub_subscriber_udp_mc
- pubsub_subscriber2_udp_mc
- COMMANDS
- etcd
- USE_TERM
- )
-endif ()
-
-if (BUILD_PUBSUB_PSA_ZMQ)
-
- # Dynamic ZMQ / UDP admin
- add_deploy("pubsub_publisher"
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- org.apache.celix.pubsub_serializer.PubSubSerializerJson
- org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
- org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
- org.apache.celix.pubsub_admin.PubSubAdminZmq
- org.apache.celix.pubsub_admin.PubSubAdminUdpMc
- org.apache.celix.pubsub_publisher.PoiPublisher
- org.apache.celix.pubsub_publisher.PoiPublisher2
- PROPERTIES
- poi1.psa=zmq
- poi2.psa=udp
- )
-
- add_deploy("pubsub_subscriber"
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- org.apache.celix.pubsub_serializer.PubSubSerializerJson
- org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
- org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
- org.apache.celix.pubsub_admin.PubSubAdminZmq
- org.apache.celix.pubsub_admin.PubSubAdminUdpMc
- org.apache.celix.pubsub_subscriber.PoiSubscriber
- PROPERTIES
- poi1.psa=zmq
- poi2.psa=udp
- )
-
- # ZMQ
- add_deploy("pubsub_zmq"
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- org.apache.celix.pubsub_serializer.PubSubSerializerJson
- org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
- org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
- org.apache.celix.pubsub_admin.PubSubAdminZmq
- org.apache.celix.pubsub_publisher.PoiPublisher
- org.apache.celix.pubsub_subscriber.PoiSubscriber
- )
-
- add_deploy("pubsub_publisher_zmq"
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- org.apache.celix.pubsub_serializer.PubSubSerializerJson
- org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
- org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
- org.apache.celix.pubsub_admin.PubSubAdminZmq
- org.apache.celix.pubsub_publisher.PoiPublisher
- org.apache.celix.pubsub_publisher.PoiPublisher2
- PROPERTIES
- pubsub.scope=my_small_scope
- )
-
- add_deploy("pubsub_subscriber_zmq"
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- org.apache.celix.pubsub_serializer.PubSubSerializerJson
- org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
- org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
- org.apache.celix.pubsub_admin.PubSubAdminZmq
- org.apache.celix.pubsub_subscriber.PoiSubscriber
- )
-
- add_deploy("pubsub_subscriber2_zmq"
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- org.apache.celix.pubsub_serializer.PubSubSerializerJson
- org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
- org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
- org.apache.celix.pubsub_admin.PubSubAdminZmq
- org.apache.celix.pubsub_subscriber.PoiSubscriber
-
- )
-
- # ZMQ Multipart
- add_deploy("pubsub_mp_subscriber_zmq"
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- org.apache.celix.pubsub_serializer.PubSubSerializerJson
- org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
- org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
- org.apache.celix.pubsub_admin.PubSubAdminZmq
- org.apache.celix.pubsub_subscriber.MpSubscriber
- )
-
- add_deploy("pubsub_mp_publisher_zmq"
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- org.apache.celix.pubsub_serializer.PubSubSerializerJson
- org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
- org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
- org.apache.celix.pubsub_admin.PubSubAdminZmq
- org.apache.celix.pubsub_publisher.MpPublisher
- )
-
- if (ETCD_CMD AND XTERM_CMD)
- #Runtime starting two bundles using both zmq and upd mc pubsub
- add_runtime(pubsub_rt_zmq_udpmc_combi
- NAME combi
- GROUP pubsub
- DEPLOYMENTS
- pubsub_publisher_zmq
- pubsub_subscriber_zmq
- pubsub_subscriber_zmq
- COMMANDS
- etcd
- USE_TERM
- )
-
- #Runtime starting a publish and 2 subscribers for zmq
- add_runtime(pubsub_rt_zmq
- NAME zmq
- GROUP pubsub
- DEPLOYMENTS
- pubsub_publisher
- pubsub_subscriber_zmq
- pubsub_subscriber2_zmq
- COMMANDS
- etcd
- USE_TERM
- )
-
- #Runtime starting a multipart (multiple message in one send) publish and subscriber for zmq
- add_runtime(pubsub_rt_multipart_zmq
- NAME zmq_multipart
- GROUP pubsub
- DEPLOYMENTS
- pubsub_mp_subscriber_zmq
- pubsub_mp_publisher_zmq
- COMMANDS
- etcd
- USE_TERM
- )
- endif ()
-
-endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/examples/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/examples/CMakeLists.txt b/pubsub/examples/CMakeLists.txt
index 22ca5ca..b79b101 100644
--- a/pubsub/examples/CMakeLists.txt
+++ b/pubsub/examples/CMakeLists.txt
@@ -17,3 +17,216 @@
add_subdirectory(pubsub)
add_subdirectory(mp_pubsub)
+
+find_program(ETCD_CMD NAMES etcd)
+find_program(XTERM_CMD NAMES xterm)
+
+# UDP Multicast
+add_deploy(pubsub_publisher_udp_mc
+ GROUP pubsub
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_udp_multicast
+ celix_pubsub_poi_publisher
+ celix_pubsub_poi_publisher2
+ )
+
+add_deploy("pubsub_subscriber_udp_mc"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_udp_multicast
+ celix_pubsub_poi_subscriber
+ )
+
+add_deploy("pubsub_subscriber2_udp_mc"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_udp_multicast
+ celix_pubsub_poi_subscriber
+ )
+
+if (ETCD_CMD AND XTERM_CMD)
+ #Runtime starting a publish and subscriber for udp mc
+ add_runtime(pubsub_rt_upd_mc
+ NAME udp_mc
+ GROUP pubsub
+ DEPLOYMENTS
+ pubsub_publisher_udp_mc
+ pubsub_subscriber_udp_mc
+ pubsub_subscriber2_udp_mc
+ COMMANDS
+ etcd
+ USE_TERM
+ )
+endif ()
+
+if (BUILD_PUBSUB_PSA_ZMQ)
+
+ # Dynamic ZMQ / UDP admin
+ add_deploy("pubsub_publisher"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_zmq
+ Celix::pubsub_admin_udp_multicast
+ celix_pubsub_poi_publisher
+ celix_pubsub_poi_publisher2
+ PROPERTIES
+ poi1.psa=zmq
+ poi2.psa=udp
+ )
+
+ add_deploy("pubsub_subscriber"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_zmq
+ Celix::pubsub_admin_udp_multicast
+ celix_pubsub_poi_subscriber
+ PROPERTIES
+ poi1.psa=zmq
+ poi2.psa=udp
+ )
+
+ # ZMQ
+ add_deploy("pubsub_zmq"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ org.apache.celix.pubsub_admin.PubSubAdminZmq
+ celix_pubsub_poi_publisher
+ celix_pubsub_poi_subscriber
+ )
+
+ add_deploy("pubsub_publisher_zmq"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_zmq
+ celix_pubsub_poi_publisher
+ celix_pubsub_poi_publisher2
+ PROPERTIES
+ pubsub.scope=my_small_scope
+ )
+
+ add_deploy("pubsub_subscriber_zmq"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ org.apache.celix.pubsub_admin.PubSubAdminZmq
+ celix_pubsub_poi_subscriber
+ )
+
+ add_deploy("pubsub_subscriber2_zmq"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_zmq
+ celix_pubsub_poi_subscriber
+
+ )
+
+ # ZMQ Multipart
+ add_deploy("pubsub_mp_subscriber_zmq"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_zmq
+ org.apache.celix.pubsub_subscriber.MpSubscriber
+ )
+
+ add_deploy("pubsub_mp_publisher_zmq"
+ GROUP "pubsub"
+ BUNDLES
+ Celix::shell
+ Celix::shell_tui
+ Celix::pubsub_serializer_json
+ Celix::pubsub_discovery_etcd
+ Celix::pubsub_topology_manager
+ Celix::pubsub_admin_zmq
+ org.apache.celix.pubsub_publisher.MpPublisher
+ )
+
+ if (ETCD_CMD AND XTERM_CMD)
+ #Runtime starting two bundles using both zmq and upd mc pubsub
+ add_runtime(pubsub_rt_zmq_udpmc_combi
+ NAME combi
+ GROUP pubsub
+ DEPLOYMENTS
+ pubsub_publisher_zmq
+ pubsub_subscriber_zmq
+ pubsub_subscriber_zmq
+ COMMANDS
+ etcd
+ USE_TERM
+ )
+
+ #Runtime starting a publish and 2 subscribers for zmq
+ add_runtime(pubsub_rt_zmq
+ NAME zmq
+ GROUP pubsub
+ DEPLOYMENTS
+ pubsub_publisher
+ pubsub_subscriber_zmq
+ pubsub_subscriber2_zmq
+ COMMANDS
+ etcd
+ USE_TERM
+ )
+
+ #Runtime starting a multipart (multiple message in one send) publish and subscriber for zmq
+ add_runtime(pubsub_rt_multipart_zmq
+ NAME zmq_multipart
+ GROUP pubsub
+ DEPLOYMENTS
+ pubsub_mp_subscriber_zmq
+ pubsub_mp_publisher_zmq
+ COMMANDS
+ etcd
+ USE_TERM
+ )
+ endif ()
+
+endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/examples/mp_pubsub/publisher/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/examples/mp_pubsub/publisher/CMakeLists.txt b/pubsub/examples/mp_pubsub/publisher/CMakeLists.txt
index 1ef8645..e837d7f 100644
--- a/pubsub/examples/mp_pubsub/publisher/CMakeLists.txt
+++ b/pubsub/examples/mp_pubsub/publisher/CMakeLists.txt
@@ -15,20 +15,15 @@
# specific language governing permissions and limitations
# under the License.
-include_directories("private/include")
-include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/examples/mp_pubsub/common/include")
-
add_bundle(org.apache.celix.pubsub_publisher.MpPublisher
SYMBOLIC_NAME "apache_celix_pubsub_mp_publisher"
VERSION "1.0.0"
SOURCES
private/src/mp_pub_activator.c
private/src/mp_publisher.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
)
+target_link_libraries(org.apache.celix.pubsub_publisher.MpPublisher PRIVATE Celix::framework Celix::pubsub_api)
+target_include_directories(org.apache.celix.pubsub_publisher.MpPublisher PRIVATE private/include)
bundle_files(org.apache.celix.pubsub_publisher.MpPublisher
${PROJECT_SOURCE_DIR}/pubsub/examples/mp_pubsub/msg_descriptors/msg_ew.descriptor
@@ -46,5 +41,3 @@ bundle_files(org.apache.celix.pubsub_publisher.MpPublisher
${PROJECT_SOURCE_DIR}/pubsub/examples/keys/subscriber/public
DESTINATION "META-INF/keys/subscriber"
)
-
-target_link_libraries(org.apache.celix.pubsub_publisher.MpPublisher PRIVATE Celix::framework)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/examples/mp_pubsub/publisher/private/include/mp_publisher_private.h
----------------------------------------------------------------------
diff --git a/pubsub/examples/mp_pubsub/publisher/private/include/mp_publisher_private.h b/pubsub/examples/mp_pubsub/publisher/private/include/mp_publisher_private.h
index a9c070f..9c227fd 100644
--- a/pubsub/examples/mp_pubsub/publisher/private/include/mp_publisher_private.h
+++ b/pubsub/examples/mp_pubsub/publisher/private/include/mp_publisher_private.h
@@ -29,7 +29,7 @@
#include <celixbool.h>
-#include "publisher.h"
+#include "pubsub/publisher.h"
struct pubsub_sender {
array_list_pt trackers;
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/examples/mp_pubsub/publisher/private/src/mp_pub_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/examples/mp_pubsub/publisher/private/src/mp_pub_activator.c b/pubsub/examples/mp_pubsub/publisher/private/src/mp_pub_activator.c
index 5c8b145..464d1ab 100644
--- a/pubsub/examples/mp_pubsub/publisher/private/src/mp_pub_activator.c
+++ b/pubsub/examples/mp_pubsub/publisher/private/src/mp_pub_activator.c
@@ -32,11 +32,13 @@
#include "service_tracker.h"
#include "constants.h"
-#include "pubsub_common.h"
-#include "pubsub_utils.h"
#include "mp_publisher_private.h"
-#define PUB_TOPIC "multipart"
+static const char * PUB_TOPICS[] = {
+ "multipart",
+ NULL
+};
+
struct publisherActivator {
pubsub_sender_pt client;
@@ -78,40 +80,28 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
int i;
- array_list_pt topic_list = pubsub_getTopicsFromString(PUB_TOPIC);
-
- if(topic_list !=NULL){
-
+ if(PUB_TOPICS != NULL) {
char filter[128];
+ for(i=0; PUB_TOPICS[i] != NULL; i++){
+ const char* topic = PUB_TOPICS[i];
- for(i=0; i<arrayList_size(topic_list);i++){
- char* topic = arrayList_get(topic_list,i);
- if(strlen(topic)<MAX_TOPIC_LEN){
-
- bundle_pt bundle = NULL;
- long bundleId = 0;
- bundleContext_getBundle(context,&bundle);
- bundle_getBundleId(bundle,&bundleId);
+ bundle_pt bundle = NULL;
+ long bundleId = 0;
+ bundleContext_getBundle(context,&bundle);
+ bundle_getBundleId(bundle,&bundleId);
- service_tracker_pt tracker = NULL;
- memset(filter,0,128);
+ service_tracker_pt tracker = NULL;
+ memset(filter,0,128);
- snprintf(filter, 128, "(&(%s=%s)(%s=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_PUBLISHER_SERVICE_NAME, PUBSUB_PUBLISHER_TOPIC,topic);
+ snprintf(filter, 128, "(&(%s=%s)(%s=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_PUBLISHER_SERVICE_NAME, PUBSUB_PUBLISHER_TOPIC,topic);
- service_tracker_customizer_pt customizer = NULL;
+ service_tracker_customizer_pt customizer = NULL;
- serviceTrackerCustomizer_create(act->client,NULL,publisher_publishSvcAdded,NULL,publisher_publishSvcRemoved,&customizer);
- serviceTracker_createWithFilter(context, filter, customizer, &tracker);
+ serviceTrackerCustomizer_create(act->client,NULL,publisher_publishSvcAdded,NULL,publisher_publishSvcRemoved,&customizer);
+ serviceTracker_createWithFilter(context, filter, customizer, &tracker);
- arrayList_add(act->trackerList,tracker);
- }
- else{
- printf("Topic %s too long. Skipping publication.\n",topic);
- }
- free(topic);
+ arrayList_add(act->trackerList,tracker);
}
- arrayList_destroy(topic_list);
-
}
publisher_start(act->client);
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/examples/mp_pubsub/publisher/private/src/mp_publisher.c
----------------------------------------------------------------------
diff --git a/pubsub/examples/mp_pubsub/publisher/private/src/mp_publisher.c b/pubsub/examples/mp_pubsub/publisher/private/src/mp_publisher.c
index fa53487..f47be29 100644
--- a/pubsub/examples/mp_pubsub/publisher/private/src/mp_publisher.c
+++ b/pubsub/examples/mp_pubsub/publisher/private/src/mp_publisher.c
@@ -32,7 +32,6 @@
#include "service_tracker.h"
#include "celix_threads.h"
-#include "pubsub_common.h"
#include "ew.h"
#include "ide.h"
#include "kinematics.h"
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/examples/mp_pubsub/subscriber/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/examples/mp_pubsub/subscriber/CMakeLists.txt b/pubsub/examples/mp_pubsub/subscriber/CMakeLists.txt
index e281ab1..858efb5 100644
--- a/pubsub/examples/mp_pubsub/subscriber/CMakeLists.txt
+++ b/pubsub/examples/mp_pubsub/subscriber/CMakeLists.txt
@@ -15,20 +15,15 @@
# specific language governing permissions and limitations
# under the License.
-include_directories("private/include")
-include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/examples/mp_pubsub/common/include")
-
-add_bundle( org.apache.celix.pubsub_subscriber.MpSubscriber
+add_bundle(org.apache.celix.pubsub_subscriber.MpSubscriber
SYMBOLIC_NAME "apache_celix_pubsub_mp_subscriber"
VERSION "1.0.0"
SOURCES
private/src/mp_sub_activator.c
private/src/mp_subscriber.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
)
+target_link_libraries(org.apache.celix.pubsub_subscriber.MpSubscriber PRIVATE Celix::framework Celix::pubsub_api)
+target_include_directories(org.apache.celix.pubsub_subscriber.MpSubscriber PRIVATE private/include)
bundle_files( org.apache.celix.pubsub_subscriber.MpSubscriber
${PROJECT_SOURCE_DIR}/pubsub/examples/mp_pubsub/msg_descriptors/msg_ew.descriptor
@@ -43,8 +38,6 @@ bundle_files(org.apache.celix.pubsub_subscriber.MpSubscriber
)
bundle_files(org.apache.celix.pubsub_subscriber.MpSubscriber
- ${PROJECT_SOURCE_DIR}/pubsub/examples/keys/publisher/public
+ ${PROJECT_SOURCE_DIR}/pubsub/examples/keys/publisher/public
DESTINATION "META-INF/keys/publisher"
-)
-
-target_link_libraries(org.apache.celix.pubsub_subscriber.MpSubscriber PRIVATE Celix::framework)
+)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/examples/mp_pubsub/subscriber/private/include/mp_subscriber_private.h
----------------------------------------------------------------------
diff --git a/pubsub/examples/mp_pubsub/subscriber/private/include/mp_subscriber_private.h b/pubsub/examples/mp_pubsub/subscriber/private/include/mp_subscriber_private.h
index 1cc7270..2d582b3 100644
--- a/pubsub/examples/mp_pubsub/subscriber/private/include/mp_subscriber_private.h
+++ b/pubsub/examples/mp_pubsub/subscriber/private/include/mp_subscriber_private.h
@@ -32,8 +32,7 @@
#include "celixbool.h"
-#include "pubsub_common.h"
-#include "subscriber.h"
+#include "pubsub/subscriber.h"
struct pubsub_receiver {
char * name;
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/examples/mp_pubsub/subscriber/private/src/mp_sub_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/examples/mp_pubsub/subscriber/private/src/mp_sub_activator.c b/pubsub/examples/mp_pubsub/subscriber/private/src/mp_sub_activator.c
index ecd4245..df9cb0f 100644
--- a/pubsub/examples/mp_pubsub/subscriber/private/src/mp_sub_activator.c
+++ b/pubsub/examples/mp_pubsub/subscriber/private/src/mp_sub_activator.c
@@ -26,17 +26,20 @@
#include <stdlib.h>
+#include "pubsub/subscriber.h"
#include "bundle_activator.h"
-#include "pubsub_common.h"
-#include "pubsub_utils.h"
#include "mp_subscriber_private.h"
-#define SUB_TOPIC "multipart"
+#define SUB_NAME "multipart"
+static const char * SUB_TOPICS[] = {
+ "multipart",
+ NULL
+};
struct subscriberActivator {
array_list_pt registrationList; //List<service_registration_pt>
- pubsub_subscriber_pt subsvc;
+ pubsub_subscriber_t* subsvc;
};
celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
@@ -51,33 +54,24 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
pubsub_subscriber_pt subsvc = calloc(1,sizeof(*subsvc));
- pubsub_receiver_pt sub = subscriber_create(SUB_TOPIC);
+ pubsub_receiver_pt sub = subscriber_create(SUB_NAME);
subsvc->handle = sub;
subsvc->receive = pubsub_subscriber_recv;
act->subsvc = subsvc;
- array_list_pt topic_list = pubsub_getTopicsFromString(SUB_TOPIC);
-
- if(topic_list !=NULL){
+ if (SUB_TOPICS !=NULL) {
int i;
- for(i=0; i<arrayList_size(topic_list);i++){
- char* topic = arrayList_get(topic_list,i);
- if(strlen(topic)<MAX_TOPIC_LEN){
- properties_pt props = properties_create();
- properties_set(props, PUBSUB_SUBSCRIBER_TOPIC,topic);
- service_registration_pt reg = NULL;
- bundleContext_registerService(context, PUBSUB_SUBSCRIBER_SERVICE_NAME, subsvc, props, ®);
- arrayList_add(act->registrationList,reg);
- }
- else{
- printf("Topic %s too long. Skipping subscription.\n",topic);
- }
- free(topic);
+ for(i=0; SUB_TOPICS[i] != NULL; i++){
+ const char* topic = SUB_TOPICS[i];
+
+ properties_pt props = properties_create();
+ properties_set(props, PUBSUB_SUBSCRIBER_TOPIC,topic);
+ service_registration_pt reg = NULL;
+ bundleContext_registerService(context, PUBSUB_SUBSCRIBER_SERVICE_NAME, subsvc, props, ®);
+ arrayList_add(act->registrationList,reg);
}
- arrayList_destroy(topic_list);
-
}
subscriber_start((pubsub_receiver_pt)act->subsvc->handle);
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/examples/pubsub/publisher/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/examples/pubsub/publisher/CMakeLists.txt b/pubsub/examples/pubsub/publisher/CMakeLists.txt
index fcf50c7..43eabd8 100644
--- a/pubsub/examples/pubsub/publisher/CMakeLists.txt
+++ b/pubsub/examples/pubsub/publisher/CMakeLists.txt
@@ -15,40 +15,35 @@
# specific language governing permissions and limitations
# under the License.
-include_directories("private/include")
-include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-
-add_bundle(org.apache.celix.pubsub_publisher.PoiPublisher
+add_bundle(celix_pubsub_poi_publisher
SYMBOLIC_NAME "apache_celix_pubsub_poi_publisher"
VERSION "1.0.0"
SOURCES
private/src/ps_pub_activator.c
private/src/pubsub_publisher.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
)
-bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher
+target_link_libraries(celix_pubsub_poi_publisher PRIVATE Celix::framework Celix::pubsub_api)
+target_include_directories(celix_pubsub_poi_publisher PRIVATE private/include)
+
+bundle_files(celix_pubsub_poi_publisher
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/msg_poi1.descriptor
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/msg_poi2.descriptor
DESTINATION "META-INF/descriptors"
)
-bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher
+bundle_files(celix_pubsub_poi_publisher
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/poi1.properties
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/poi2.properties
DESTINATION "META-INF/topics/pub"
)
-bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher
+bundle_files(celix_pubsub_poi_publisher
${PROJECT_SOURCE_DIR}/pubsub/examples/keys/publisher
DESTINATION "META-INF/keys"
)
-bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher
+bundle_files(celix_pubsub_poi_publisher
${PROJECT_SOURCE_DIR}/pubsub/examples/keys/subscriber/public
DESTINATION "META-INF/keys/subscriber"
)
-
-target_link_libraries(org.apache.celix.pubsub_publisher.PoiPublisher PRIVATE Celix::framework)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/examples/pubsub/publisher/private/include/pubsub_publisher_private.h
----------------------------------------------------------------------
diff --git a/pubsub/examples/pubsub/publisher/private/include/pubsub_publisher_private.h b/pubsub/examples/pubsub/publisher/private/include/pubsub_publisher_private.h
index 834dada..56ec678 100644
--- a/pubsub/examples/pubsub/publisher/private/include/pubsub_publisher_private.h
+++ b/pubsub/examples/pubsub/publisher/private/include/pubsub_publisher_private.h
@@ -29,7 +29,7 @@
#include <celixbool.h>
#include <pthread.h>
-#include "publisher.h"
+#include "pubsub/publisher.h"
struct pubsub_sender {
array_list_pt trackers;
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c b/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c
index e6c7a3b..a1f2dc8 100644
--- a/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c
+++ b/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c
@@ -32,12 +32,15 @@
#include "service_tracker.h"
#include "constants.h"
-#include "pubsub_common.h"
-#include "pubsub_utils.h"
-#include "publisher.h"
+#include "pubsub/publisher.h"
#include "pubsub_publisher_private.h"
-#define PUB_TOPIC "poi1;poi2"
+static const char * PUB_TOPICS[] = {
+ "poi1",
+ "poi2",
+ NULL
+};
+
struct publisherActivator {
pubsub_sender_pt client;
@@ -73,22 +76,19 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
struct publisherActivator * act = (struct publisherActivator *) userData;
int i;
- array_list_pt topic_list = pubsub_getTopicsFromString(PUB_TOPIC);
-
- if(topic_list !=NULL){
+ if(PUB_TOPICS !=NULL){
char filter[128];
- for(i=0; i<arrayList_size(topic_list);i++){
- char* topic = arrayList_get(topic_list,i);
- if(strlen(topic)<MAX_TOPIC_LEN){
+ for(i=0; PUB_TOPICS[i] != NULL; i++){
+ const char* topic = PUB_TOPICS[i];
- bundle_pt bundle = NULL;
- long bundleId = 0;
- bundleContext_getBundle(context,&bundle);
- bundle_getBundleId(bundle,&bundleId);
+ bundle_pt bundle = NULL;
+ long bundleId = 0;
+ bundleContext_getBundle(context,&bundle);
+ bundle_getBundleId(bundle,&bundleId);
- service_tracker_pt tracker = NULL;
- memset(filter,0,128);
+ service_tracker_pt tracker = NULL;
+ memset(filter,0,128);
#ifdef USE_SCOPE
char *scope;
asprintf(&scope, "my_scope_%d", i);
@@ -98,23 +98,15 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
PUBLISHER_SCOPE, scope);
free(scope);
#else
- snprintf(filter, 128, "(&(%s=%s)(%s=%s))",
- (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_PUBLISHER_SERVICE_NAME,
- PUBSUB_PUBLISHER_TOPIC, topic);
+ snprintf(filter, 128, "(&(%s=%s)(%s=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_PUBLISHER_SERVICE_NAME, PUBSUB_PUBLISHER_TOPIC, topic);
#endif
- service_tracker_customizer_pt customizer = NULL;
- serviceTrackerCustomizer_create(act->client,NULL,publisher_publishSvcAdded,NULL,publisher_publishSvcRemoved,&customizer);
- serviceTracker_createWithFilter(context, filter, customizer, &tracker);
-
- arrayList_add(act->trackerList,tracker);
- }
- else{
- printf("Topic %s too long. Skipping publication.\n",topic);
- }
- free(topic);
- }
- arrayList_destroy(topic_list);
+ service_tracker_customizer_pt customizer = NULL;
+ serviceTrackerCustomizer_create(act->client,NULL,publisher_publishSvcAdded,NULL,publisher_publishSvcRemoved,&customizer);
+ serviceTracker_createWithFilter(context, filter, customizer, &tracker);
+
+ arrayList_add(act->trackerList,tracker);
+ }
}
publisher_start(act->client);
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/examples/pubsub/publisher/private/src/pubsub_publisher.c
----------------------------------------------------------------------
diff --git a/pubsub/examples/pubsub/publisher/private/src/pubsub_publisher.c b/pubsub/examples/pubsub/publisher/private/src/pubsub_publisher.c
index 7e7602e..9a7aedc 100644
--- a/pubsub/examples/pubsub/publisher/private/src/pubsub_publisher.c
+++ b/pubsub/examples/pubsub/publisher/private/src/pubsub_publisher.c
@@ -32,7 +32,6 @@
#include "service_tracker.h"
#include "celix_threads.h"
-#include "pubsub_common.h"
#include "poi.h"
#include "pubsub_publisher_private.h"
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/examples/pubsub/publisher2/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/examples/pubsub/publisher2/CMakeLists.txt b/pubsub/examples/pubsub/publisher2/CMakeLists.txt
index 82ffb75..ba007c2 100644
--- a/pubsub/examples/pubsub/publisher2/CMakeLists.txt
+++ b/pubsub/examples/pubsub/publisher2/CMakeLists.txt
@@ -15,40 +15,37 @@
# specific language governing permissions and limitations
# under the License.
-include_directories("../publisher/private/include")
-include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-
-add_bundle(org.apache.celix.pubsub_publisher.PoiPublisher2
+add_bundle(celix_pubsub_poi_publisher2
SYMBOLIC_NAME "apache_celix_pubsub_poi_publisher2"
VERSION "1.0.0"
SOURCES
../publisher/private/src/ps_pub_activator.c
../publisher/private/src/pubsub_publisher.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
)
+target_link_libraries(celix_pubsub_poi_publisher2 PRIVATE Celix::framework Celix::pubsub_api)
+target_include_directories(celix_pubsub_poi_publisher2 PRIVATE ../publisher/private/include)
+
-bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher2
+bundle_files(celix_pubsub_poi_publisher2
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/msg_poi1.descriptor
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/msg_poi2.descriptor
DESTINATION "META-INF/descriptors"
)
-bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher2
+bundle_files(celix_pubsub_poi_publisher2
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/poi1.properties
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/poi2.properties
DESTINATION "META-INF/topics/pub"
)
-bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher2
+bundle_files(celix_pubsub_poi_publisher2
${PROJECT_SOURCE_DIR}/pubsub/examples/keys/publisher
DESTINATION "META-INF/keys"
)
-bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher2
- ${PROJECT_SOURCE_DIR}/pubsub/examples/keys/subscriber/public
+bundle_files(celix_pubsub_poi_publisher2
+ ${PROJECT_SOURCE_DIR}/pubsub/examples/keys/subscriber/public
DESTINATION "META-INF/keys/subscriber"
)
-target_link_libraries(org.apache.celix.pubsub_publisher.PoiPublisher2 PRIVATE Celix::framework)
+target_link_libraries(celix_pubsub_poi_publisher2 PRIVATE Celix::framework)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/examples/pubsub/subscriber/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/examples/pubsub/subscriber/CMakeLists.txt b/pubsub/examples/pubsub/subscriber/CMakeLists.txt
index 28569b0..1ffd39a 100644
--- a/pubsub/examples/pubsub/subscriber/CMakeLists.txt
+++ b/pubsub/examples/pubsub/subscriber/CMakeLists.txt
@@ -15,41 +15,36 @@
# specific language governing permissions and limitations
# under the License.
-include_directories("private/include")
-include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/common/include")
-
-add_bundle(org.apache.celix.pubsub_subscriber.PoiSubscriber
+add_bundle(celix_pubsub_poi_subscriber
SYMBOLIC_NAME "apache_celix_pubsub_poi_subscriber"
VERSION "1.0.0"
SOURCES
private/src/ps_sub_activator.c
- private/src/pubsub_subscriber.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
+ private/src/pubsub_subscriber.c
)
-bundle_files(org.apache.celix.pubsub_subscriber.PoiSubscriber
+target_link_libraries(celix_pubsub_poi_subscriber PRIVATE Celix::framework Celix::pubsub_api)
+target_include_directories(celix_pubsub_poi_subscriber PRIVATE private/include)
+
+
+bundle_files(celix_pubsub_poi_subscriber
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/msg_poi1.descriptor
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/msg_poi2.descriptor
DESTINATION "META-INF/descriptors"
)
-bundle_files(org.apache.celix.pubsub_subscriber.PoiSubscriber
+bundle_files(celix_pubsub_poi_subscriber
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/poi1.properties
${PROJECT_SOURCE_DIR}/pubsub/examples/pubsub/msg_descriptors/poi2.properties
DESTINATION "META-INF/topics/sub"
)
-bundle_files(org.apache.celix.pubsub_subscriber.PoiSubscriber
+bundle_files(celix_pubsub_poi_subscriber
${PROJECT_SOURCE_DIR}/pubsub/examples/keys/subscriber
DESTINATION "META-INF/keys"
)
-bundle_files(org.apache.celix.pubsub_subscriber.PoiSubscriber
+bundle_files(celix_pubsub_poi_subscriber
${PROJECT_SOURCE_DIR}/pubsub/examples/keys/publisher/public
DESTINATION "META-INF/keys/publisher"
-)
-
-target_link_libraries(org.apache.celix.pubsub_subscriber.PoiSubscriber PRIVATE Celix::framework)
+)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/examples/pubsub/subscriber/private/include/pubsub_subscriber_private.h
----------------------------------------------------------------------
diff --git a/pubsub/examples/pubsub/subscriber/private/include/pubsub_subscriber_private.h b/pubsub/examples/pubsub/subscriber/private/include/pubsub_subscriber_private.h
index c6072df..00ca9b4 100644
--- a/pubsub/examples/pubsub/subscriber/private/include/pubsub_subscriber_private.h
+++ b/pubsub/examples/pubsub/subscriber/private/include/pubsub_subscriber_private.h
@@ -32,8 +32,7 @@
#include "celixbool.h"
-#include "pubsub_common.h"
-#include "subscriber.h"
+#include "pubsub/subscriber.h"
struct pubsub_receiver {
char * name;
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c b/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c
index efd34c9..4738abd 100644
--- a/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c
+++ b/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c
@@ -25,14 +25,18 @@
*/
#include <stdlib.h>
+#include <pubsub/subscriber.h>
#include "bundle_activator.h"
-#include "pubsub_common.h"
-#include "pubsub_utils.h"
#include "pubsub_subscriber_private.h"
-#define SUB_TOPIC "poi1;poi2"
+#define SUB_NAME "poi1;poi2"
+static const char * SUB_TOPICS[] = {
+ "poi1",
+ "poi2",
+ NULL
+};
struct subscriberActivator {
array_list_pt registrationList; //List<service_registration_pt>
@@ -51,39 +55,29 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
pubsub_subscriber_pt subsvc = calloc(1,sizeof(*subsvc));
- pubsub_receiver_pt sub = subscriber_create(SUB_TOPIC);
+ pubsub_receiver_pt sub = subscriber_create(SUB_NAME);
subsvc->handle = sub;
subsvc->receive = pubsub_subscriber_recv;
act->subsvc = subsvc;
- array_list_pt topic_list = pubsub_getTopicsFromString(SUB_TOPIC);
-
- if(topic_list !=NULL){
+ if (SUB_TOPICS !=NULL){
int i;
- for(i=0; i<arrayList_size(topic_list);i++){
- char* topic = arrayList_get(topic_list,i);
- if(strlen(topic)<MAX_TOPIC_LEN){
- properties_pt props = properties_create();
- properties_set(props, PUBSUB_SUBSCRIBER_TOPIC,topic);
+ for(i=0; SUB_TOPICS[i] != NULL ;i++){
+ const char* topic = SUB_TOPICS[i];
+ properties_pt props = properties_create();
+ properties_set(props, PUBSUB_SUBSCRIBER_TOPIC,topic);
#ifdef USE_SCOPE
char *scope;
asprintf(&scope, "my_scope_%d", i);
properties_set(props,SUBSCRIBER_SCOPE,scope);
free(scope);
#endif
- service_registration_pt reg = NULL;
- bundleContext_registerService(context, PUBSUB_SUBSCRIBER_SERVICE_NAME, subsvc, props, ®);
- arrayList_add(act->registrationList,reg);
- }
- else{
- printf("Topic %s too long. Skipping subscription.\n",topic);
- }
- free(topic);
+ service_registration_pt reg = NULL;
+ bundleContext_registerService(context, PUBSUB_SUBSCRIBER_SERVICE_NAME, subsvc, props, ®);
+ arrayList_add(act->registrationList,reg);
}
- arrayList_destroy(topic_list);
-
}
subscriber_start((pubsub_receiver_pt)act->subsvc->handle);
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/mock/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/mock/CMakeLists.txt b/pubsub/mock/CMakeLists.txt
index 6313987..ccc3d20 100644
--- a/pubsub/mock/CMakeLists.txt
+++ b/pubsub/mock/CMakeLists.txt
@@ -18,28 +18,22 @@
#only install if CppuTest is available
find_package(CppUTest QUIET)
if (CPPUTEST_FOUND)
- include_directories(
- ../api
- api
+
+ add_library(celix_pubsub_mock STATIC
+ src/publisher_mock.cc
)
- include_directories(SYSTEM
+ target_include_directories(celix_pubsub_mock PUBLIC api)
+ target_link_libraries(celix_pubsub_mock PRIVATE Celix::pubsub_spi ${CPPUTEST_LIBRARY})
+ target_include_directories(celix_pubsub_mock PRIVATE SYSTEM
${CPPUTEST_INCLUDE_DIR}
)
- add_library(celix_pubsubmock STATIC
- src/publisher_mock.cc
- ../test/test/msg.h)
- target_link_libraries(celix_pubsubmock ${CPPUTEST_LIBRARY})
-
- install(TARGETS celix_pubsubmock DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT framework)
- install(FILES api/pubsub/publisher_mock.h DESTINATION include/celix/pubsub COMPONENT framework)
-
if (ENABLE_TESTING)
add_executable(pubsubmock_test
tst/pubsubmock_test.cc
tst/run_tests.cc
)
- target_link_libraries(pubsubmock_test celix_pubsubmock ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY})
+ target_link_libraries(pubsubmock_test celix_pubsub_mock ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} Celix::framework)
add_test(NAME pubsubmock_test COMMAND pubsubmock_test)
endif()
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_udp_mc/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/CMakeLists.txt b/pubsub/pubsub_admin_udp_mc/CMakeLists.txt
index a57693f..87858e3 100644
--- a/pubsub/pubsub_admin_udp_mc/CMakeLists.txt
+++ b/pubsub/pubsub_admin_udp_mc/CMakeLists.txt
@@ -17,7 +17,7 @@
find_package(Jansson REQUIRED)
-add_bundle(org.apache.celix.pubsub_admin.PubSubAdminUdpMc
+add_bundle(celix_pubsub_admin_udp_multicast
BUNDLE_SYMBOLICNAME "apache_celix_pubsub_admin_udp_multicast"
VERSION "1.0.0"
SOURCES
@@ -26,20 +26,19 @@ add_bundle(org.apache.celix.pubsub_admin.PubSubAdminUdpMc
src/topic_subscription.c
src/topic_publication.c
src/large_udp.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_endpoint.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_admin_match.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
)
-target_include_directories(org.apache.celix.pubsub_admin.PubSubAdminUdpMc PRIVATE
+target_include_directories(celix_pubsub_admin_udp_multicast PRIVATE
src
${JANSSON_INCLUDE_DIR}
)
-set_target_properties(org.apache.celix.pubsub_admin.PubSubAdminUdpMc PROPERTIES INSTALL_RPATH "$ORIGIN")
-target_link_libraries(org.apache.celix.pubsub_admin.PubSubAdminUdpMc PRIVATE Celix::framework Celix::dfi Celix::log_helper)
+set_target_properties(celix_pubsub_admin_udp_multicast PROPERTIES INSTALL_RPATH "$ORIGIN")
+target_link_libraries(celix_pubsub_admin_udp_multicast PRIVATE Celix::pubsub_spi Celix::framework Celix::dfi Celix::log_helper)
-install_bundle(org.apache.celix.pubsub_admin.PubSubAdminUdpMc)
+install_bundle(celix_pubsub_admin_udp_multicast)
+
+add_library(Celix::pubsub_admin_udp_multicast ALIAS celix_pubsub_admin_udp_multicast)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_udp_mc/src/pubsub_admin_impl.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/src/pubsub_admin_impl.c b/pubsub/pubsub_admin_udp_mc/src/pubsub_admin_impl.c
index 1fbdb08..674f817 100644
--- a/pubsub/pubsub_admin_udp_mc/src/pubsub_admin_impl.c
+++ b/pubsub/pubsub_admin_udp_mc/src/pubsub_admin_impl.c
@@ -59,7 +59,7 @@
#include "topic_subscription.h"
#include "topic_publication.h"
#include "pubsub_endpoint.h"
-#include "subscriber.h"
+#include "pubsub/subscriber.h"
#include "pubsub_admin_match.h"
static const char *DEFAULT_MC_IP = "224.100.1.1";
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_udp_mc/src/topic_publication.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/src/topic_publication.c b/pubsub/pubsub_admin_udp_mc/src/topic_publication.c
index 44106df..15af108 100644
--- a/pubsub/pubsub_admin_udp_mc/src/topic_publication.c
+++ b/pubsub/pubsub_admin_udp_mc/src/topic_publication.c
@@ -36,7 +36,7 @@
#include "topic_publication.h"
#include "pubsub_common.h"
-#include "publisher.h"
+#include "pubsub/publisher.h"
#include "large_udp.h"
#include "pubsub_serializer.h"
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_udp_mc/src/topic_publication.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/src/topic_publication.h b/pubsub/pubsub_admin_udp_mc/src/topic_publication.h
index 4363d71..8f47deb 100644
--- a/pubsub/pubsub_admin_udp_mc/src/topic_publication.h
+++ b/pubsub/pubsub_admin_udp_mc/src/topic_publication.h
@@ -27,7 +27,7 @@
#ifndef TOPIC_PUBLICATION_H_
#define TOPIC_PUBLICATION_H_
-#include "publisher.h"
+#include "pubsub/publisher.h"
#include "pubsub_endpoint.h"
#include "pubsub_common.h"
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_udp_mc/src/topic_subscription.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/src/topic_subscription.c b/pubsub/pubsub_admin_udp_mc/src/topic_subscription.c
index d8e6f45..6d0768b 100644
--- a/pubsub/pubsub_admin_udp_mc/src/topic_subscription.c
+++ b/pubsub/pubsub_admin_udp_mc/src/topic_subscription.c
@@ -42,8 +42,8 @@
#include "topic_subscription.h"
#include "topic_publication.h"
-#include "subscriber.h"
-#include "publisher.h"
+#include "pubsub/subscriber.h"
+#include "pubsub/publisher.h"
#include "large_udp.h"
#include "pubsub_serializer.h"
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/CMakeLists.txt b/pubsub/pubsub_admin_zmq/CMakeLists.txt
index d71aedb..9d57756 100644
--- a/pubsub/pubsub_admin_zmq/CMakeLists.txt
+++ b/pubsub/pubsub_admin_zmq/CMakeLists.txt
@@ -21,17 +21,6 @@ if (BUILD_PUBSUB_PSA_ZMQ)
find_package(CZMQ REQUIRED)
find_package(Jansson REQUIRED)
- include_directories("${ZMQ_INCLUDE_DIR}")
- include_directories("${CZMQ_INCLUDE_DIR}")
- include_directories("${JANSSON_INCLUDE_DIR}")
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/dfi/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
- include_directories("private/include")
- include_directories("public/include")
-
if (BUILD_ZMQ_SECURITY)
add_definitions(-DBUILD_WITH_ZMQ_SECURITY=1)
@@ -41,24 +30,31 @@ if (BUILD_PUBSUB_PSA_ZMQ)
set (ZMQ_CRYPTO_C "private/src/zmq_crypto.c")
endif()
- add_bundle(org.apache.celix.pubsub_admin.PubSubAdminZmq
- BUNDLE_SYMBOLICNAME "apache_celix_pubsub_admin_zmq"
- VERSION "1.0.0"
- SOURCES
- private/src/psa_activator.c
- private/src/pubsub_admin_impl.c
- private/src/topic_subscription.c
- private/src/topic_publication.c
- ${ZMQ_CRYPTO_C}
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_endpoint.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_admin_match.c
+ add_bundle(celix_pubsub_admin_zmq
+ BUNDLE_SYMBOLICNAME "apache_celix_pubsub_admin_zmq"
+ VERSION "1.0.0"
+ SOURCES
+ src/psa_activator.c
+ src/pubsub_admin_impl.c
+ src/topic_subscription.c
+ src/topic_publication.c
+ ${ZMQ_CRYPTO_C}
)
- set_target_properties(org.apache.celix.pubsub_admin.PubSubAdminZmq PROPERTIES INSTALL_RPATH "$ORIGIN")
- target_link_libraries(org.apache.celix.pubsub_admin.PubSubAdminZmq PRIVATE
+ set_target_properties(celix_pubsub_admin_zmq PROPERTIES INSTALL_RPATH "$ORIGIN")
+ target_link_libraries(celix_pubsub_admin_zmq PRIVATE
+ Celix::pubsub_spi
Celix::framework Celix::dfi Celix::log_helper
- ${ZMQ_LIBRARIES} ${CZMQ_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARY})
+ ${ZMQ_LIBRARIES} ${CZMQ_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARY}
+ )
+ target_include_directories(celix_pubsub_admin_zmq PRIVATE
+ ${ZMQ_INCLUDE_DIR}
+ ${CZMQ_INCLUDE_DIR}
+ ${JANSSON_INCLUDE_DIR}
+ src
+ )
+
install_bundle(org.apache.celix.pubsub_admin.PubSubAdminZmq)
+ add_library(Celix::pubsub_admin_zmq ALIAS celix_pubsub_admin_zmq)
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/private/include/pubsub_admin_impl.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/private/include/pubsub_admin_impl.h b/pubsub/pubsub_admin_zmq/private/include/pubsub_admin_impl.h
deleted file mode 100644
index 03e8556..0000000
--- a/pubsub/pubsub_admin_zmq/private/include/pubsub_admin_impl.h
+++ /dev/null
@@ -1,109 +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.
- */
-/*
- * pubsub_admin_impl.h
- *
- * \date Dec 5, 2013
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PUBSUB_ADMIN_ZMQ_IMPL_H_
-#define PUBSUB_ADMIN_ZMQ_IMPL_H_
-
-#include <czmq.h>
-/* The following undefs prevent the collision between:
- * - sys/syslog.h (which is included within czmq)
- * - celix/dfi/dfi_log_util.h
- */
-#undef LOG_DEBUG
-#undef LOG_WARNING
-#undef LOG_INFO
-#undef LOG_WARNING
-
-#include "pubsub_admin.h"
-#include "pubsub_admin_match.h"
-#include "log_helper.h"
-
-#define PSA_ZMQ_BASE_PORT "PSA_ZMQ_BASE_PORT"
-#define PSA_ZMQ_MAX_PORT "PSA_ZMQ_MAX_PORT"
-
-#define PSA_ZMQ_DEFAULT_BASE_PORT 5501
-#define PSA_ZMQ_DEFAULT_MAX_PORT 6000
-
-#define PUBSUB_ADMIN_TYPE "zmq"
-
-struct pubsub_admin {
-
- bundle_context_pt bundle_context;
- log_helper_pt loghelper;
-
- /* List of the available serializers */
- celix_thread_mutex_t serializerListLock; // List<serializers>
- array_list_pt serializerList;
-
- celix_thread_mutex_t localPublicationsLock;
- hash_map_pt localPublications;//<topic(string),service_factory_pt>
-
- celix_thread_mutex_t externalPublicationsLock;
- hash_map_pt externalPublications;//<topic(string),List<pubsub_ep>>
-
- celix_thread_mutex_t subscriptionsLock;
- hash_map_pt subscriptions; //<topic(string),topic_subscription>
-
- celix_thread_mutex_t pendingSubscriptionsLock;
- celix_thread_mutexattr_t pendingSubscriptionsAttr;
- hash_map_pt pendingSubscriptions; //<topic(string),List<pubsub_ep>>
-
- /* Those are used to keep track of valid subscriptions/publications that still have no valid serializer */
- celix_thread_mutex_t noSerializerPendingsLock;
- celix_thread_mutexattr_t noSerializerPendingsAttr;
- array_list_pt noSerializerSubscriptions; // List<pubsub_ep>
- array_list_pt noSerializerPublications; // List<pubsub_ep>
-
- celix_thread_mutex_t usedSerializersLock;
- hash_map_pt topicSubscriptionsPerSerializer; // <serializer,List<topicSubscription>>
- hash_map_pt topicPublicationsPerSerializer; // <serializer,List<topicPublications>>
-
- char* ipAddress;
-
- zactor_t* zmq_auth;
-
- unsigned int basePort;
- unsigned int maxPort;
-};
-
-celix_status_t pubsubAdmin_create(bundle_context_pt context, pubsub_admin_pt *admin);
-celix_status_t pubsubAdmin_destroy(pubsub_admin_pt admin);
-
-celix_status_t pubsubAdmin_addSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
-celix_status_t pubsubAdmin_removeSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
-
-celix_status_t pubsubAdmin_addPublication(pubsub_admin_pt admin,pubsub_endpoint_pt pubEP);
-celix_status_t pubsubAdmin_removePublication(pubsub_admin_pt admin,pubsub_endpoint_pt pubEP);
-
-celix_status_t pubsubAdmin_closeAllPublications(pubsub_admin_pt admin,char* scope, char* topic);
-celix_status_t pubsubAdmin_closeAllSubscriptions(pubsub_admin_pt admin,char* scope,char* topic);
-
-celix_status_t pubsubAdmin_serializerAdded(void * handle, service_reference_pt reference, void * service);
-celix_status_t pubsubAdmin_serializerRemoved(void * handle, service_reference_pt reference, void * service);
-
-celix_status_t pubsubAdmin_matchEndpoint(pubsub_admin_pt admin, pubsub_endpoint_pt endpoint, double* score);
-
-#endif /* PUBSUB_ADMIN_ZMQ_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/private/include/topic_publication.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/private/include/topic_publication.h b/pubsub/pubsub_admin_zmq/private/include/topic_publication.h
deleted file mode 100644
index 3457263..0000000
--- a/pubsub/pubsub_admin_zmq/private/include/topic_publication.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.
- */
-/*
- * topic_publication.h
- *
- * \date Sep 24, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef TOPIC_PUBLICATION_H_
-#define TOPIC_PUBLICATION_H_
-
-#include "publisher.h"
-#include "pubsub_endpoint.h"
-#include "pubsub_common.h"
-
-#include "pubsub_serializer.h"
-
-typedef struct topic_publication *topic_publication_pt;
-
-celix_status_t pubsub_topicPublicationCreate(bundle_context_pt bundle_context,pubsub_endpoint_pt pubEP, pubsub_serializer_service_t *best_serializer, char* bindIP, unsigned int basePort, unsigned int maxPort, topic_publication_pt *out);
-celix_status_t pubsub_topicPublicationDestroy(topic_publication_pt pub);
-
-celix_status_t pubsub_topicPublicationAddPublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep);
-celix_status_t pubsub_topicPublicationRemovePublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep);
-
-celix_status_t pubsub_topicPublicationStart(bundle_context_pt bundle_context,topic_publication_pt pub,service_factory_pt* svcFactory);
-celix_status_t pubsub_topicPublicationStop(topic_publication_pt pub);
-
-array_list_pt pubsub_topicPublicationGetPublisherList(topic_publication_pt pub);
-
-#endif /* TOPIC_PUBLICATION_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/private/include/topic_subscription.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/private/include/topic_subscription.h b/pubsub/pubsub_admin_zmq/private/include/topic_subscription.h
deleted file mode 100644
index 7267103..0000000
--- a/pubsub/pubsub_admin_zmq/private/include/topic_subscription.h
+++ /dev/null
@@ -1,60 +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.
- */
-/*
- * topic_subscription.h
- *
- * \date Sep 22, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef TOPIC_SUBSCRIPTION_H_
-#define TOPIC_SUBSCRIPTION_H_
-
-#include "celix_threads.h"
-#include "array_list.h"
-#include "celixbool.h"
-#include "service_tracker.h"
-
-#include "pubsub_endpoint.h"
-#include "pubsub_common.h"
-#include "pubsub_serializer.h"
-
-typedef struct topic_subscription* topic_subscription_pt;
-
-celix_status_t pubsub_topicSubscriptionCreate(bundle_context_pt bundle_context,char* scope, char* topic, pubsub_serializer_service_t *best_serializer, topic_subscription_pt* out);
-celix_status_t pubsub_topicSubscriptionDestroy(topic_subscription_pt ts);
-celix_status_t pubsub_topicSubscriptionStart(topic_subscription_pt ts);
-celix_status_t pubsub_topicSubscriptionStop(topic_subscription_pt ts);
-
-celix_status_t pubsub_topicSubscriptionAddConnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL);
-celix_status_t pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL);
-
-celix_status_t pubsub_topicSubscriptionConnectPublisher(topic_subscription_pt ts, char* pubURL);
-celix_status_t pubsub_topicSubscriptionDisconnectPublisher(topic_subscription_pt ts, char* pubURL);
-
-celix_status_t pubsub_topicSubscriptionAddSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP);
-celix_status_t pubsub_topicSubscriptionRemoveSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP);
-
-array_list_pt pubsub_topicSubscriptionGetSubscribersList(topic_subscription_pt sub);
-celix_status_t pubsub_topicIncreaseNrSubscribers(topic_subscription_pt subscription);
-celix_status_t pubsub_topicDecreaseNrSubscribers(topic_subscription_pt subscription);
-unsigned int pubsub_topicGetNrSubscribers(topic_subscription_pt subscription);
-
-#endif /*TOPIC_SUBSCRIPTION_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/private/include/zmq_crypto.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/private/include/zmq_crypto.h b/pubsub/pubsub_admin_zmq/private/include/zmq_crypto.h
deleted file mode 100644
index f1a990f..0000000
--- a/pubsub/pubsub_admin_zmq/private/include/zmq_crypto.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.
- */
-/*
- * zmq_crypto.h
- *
- * \date Dec 2, 2016
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef ZMQ_CRYPTO_H_
-#define ZMQ_CRYPTO_H_
-
-#include <czmq.h>
-
-#define PROPERTY_KEYS_FILE_PATH "keys.file.path"
-#define PROPERTY_KEYS_FILE_NAME "keys.file.name"
-#define DEFAULT_KEYS_FILE_PATH "/etc/"
-#define DEFAULT_KEYS_FILE_NAME "pubsub.keys"
-
-zcert_t* get_zcert_from_encoded_file(char* keysFilePath, char* keysFileName, char* file_path);
-int generate_sha256_hash(char* text, unsigned char* digest);
-int decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, unsigned char *iv, unsigned char *plaintext);
-
-#endif
[30/54] [abbrv] celix git commit: CELIX-417: Fixes CMake linking
setup for the rsa discovery bundles
Posted by pn...@apache.org.
CELIX-417: Fixes CMake linking setup for the rsa discovery bundles
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/5ecaa64f
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/5ecaa64f
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/5ecaa64f
Branch: refs/heads/develop
Commit: 5ecaa64f672d2bc741279c2b91afc4e5e8048441
Parents: 1836cf8
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Nov 24 16:19:48 2017 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Fri Nov 24 16:19:48 2017 +0100
----------------------------------------------------------------------
remote_services/discovery_configured/CMakeLists.txt | 2 +-
remote_services/discovery_etcd/CMakeLists.txt | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/5ecaa64f/remote_services/discovery_configured/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/discovery_configured/CMakeLists.txt b/remote_services/discovery_configured/CMakeLists.txt
index bea485e..83b18c7 100644
--- a/remote_services/discovery_configured/CMakeLists.txt
+++ b/remote_services/discovery_configured/CMakeLists.txt
@@ -33,7 +33,7 @@ if (RSA_DISCOVERY_CONFIGURED)
$<TARGET_PROPERTY:Celix::rsa_discovery_common,INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:Celix::civetweb,INCLUDE_DIRECTORIES>
)
- target_link_libraries(rsa_discovery_configured PRIVATE ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} Celix::log_helper)
+ target_link_libraries(rsa_discovery_configured PRIVATE ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} Celix::log_helper Celix::rsa_common)
install_bundle(rsa_discovery_configured)
http://git-wip-us.apache.org/repos/asf/celix/blob/5ecaa64f/remote_services/discovery_etcd/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/discovery_etcd/CMakeLists.txt b/remote_services/discovery_etcd/CMakeLists.txt
index 19726fc..fe88532 100644
--- a/remote_services/discovery_etcd/CMakeLists.txt
+++ b/remote_services/discovery_etcd/CMakeLists.txt
@@ -31,7 +31,7 @@ if (RSA_DISCOVERY_ETCD)
$<TARGET_OBJECTS:Celix::rsa_discovery_common>
$<TARGET_OBJECTS:Celix::civetweb>
)
- target_link_libraries(rsa_discovery_etcd PRIVATE Celix::log_helper Celix::etcdlib_static)
+ target_link_libraries(rsa_discovery_etcd PRIVATE Celix::log_helper Celix::etcdlib_static Celix::rsa_common)
target_include_directories(rsa_discovery_etcd PRIVATE src)
target_include_directories(rsa_discovery_etcd PRIVATE
$<TARGET_PROPERTY:Celix::rsa_discovery_common,INCLUDE_DIRECTORIES>
[20/54] [abbrv] celix git commit: CELIX-417: Refactors CMake usage
for the RSA bundles
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c
new file mode 100644
index 0000000..0b8dcf7
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c
@@ -0,0 +1,402 @@
+/**
+ *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.
+ */
+
+#include <stdlib.h>
+#include <jansson.h>
+#include <json_rpc.h>
+#include <assert.h>
+#include "version.h"
+#include "json_serializer.h"
+#include "dyn_interface.h"
+#include "import_registration.h"
+#include "import_registration_dfi.h"
+
+struct import_registration {
+ bundle_context_pt context;
+ endpoint_description_pt endpoint; //TODO owner? -> free when destroyed
+ const char *classObject; //NOTE owned by endpoint
+ version_pt version;
+
+ celix_thread_mutex_t mutex; //protects send & sendhandle
+ send_func_type send;
+ void *sendHandle;
+
+ service_factory_pt factory;
+ service_registration_pt factoryReg;
+
+ hash_map_pt proxies; //key -> bundle, value -> service_proxy
+ celix_thread_mutex_t proxiesMutex; //protects proxies
+};
+
+struct service_proxy {
+ dyn_interface_type *intf;
+ void *service;
+ size_t count;
+};
+
+static celix_status_t importRegistration_createProxy(import_registration_pt import, bundle_pt bundle,
+ struct service_proxy **proxy);
+static void importRegistration_proxyFunc(void *userData, void *args[], void *returnVal);
+static void importRegistration_destroyProxy(struct service_proxy *proxy);
+static void importRegistration_clearProxies(import_registration_pt import);
+
+celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt endpoint, const char *classObject, const char* serviceVersion,
+ import_registration_pt *out) {
+ celix_status_t status = CELIX_SUCCESS;
+ import_registration_pt reg = calloc(1, sizeof(*reg));
+
+ if (reg != NULL) {
+ reg->factory = calloc(1, sizeof(*reg->factory));
+ }
+
+ if (reg != NULL && reg->factory != NULL) {
+ reg->context = context;
+ reg->endpoint = endpoint;
+ reg->classObject = classObject;
+ reg->proxies = hashMap_create(NULL, NULL, NULL, NULL);
+
+ celixThreadMutex_create(®->mutex, NULL);
+ celixThreadMutex_create(®->proxiesMutex, NULL);
+ status = version_createVersionFromString((char*)serviceVersion,&(reg->version));
+
+ reg->factory->handle = reg;
+ reg->factory->getService = (void *)importRegistration_getService;
+ reg->factory->ungetService = (void *)importRegistration_ungetService;
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ //printf("IMPORT REGISTRATION IS %p\n", reg);
+ *out = reg;
+ }
+ else{
+ importRegistration_destroy(reg);
+ }
+
+ return status;
+}
+
+
+celix_status_t importRegistration_setSendFn(import_registration_pt reg,
+ send_func_type send,
+ void *handle) {
+ celixThreadMutex_lock(®->mutex);
+ reg->send = send;
+ reg->sendHandle = handle;
+ celixThreadMutex_unlock(®->mutex);
+
+ return CELIX_SUCCESS;
+}
+
+static void importRegistration_clearProxies(import_registration_pt import) {
+ if (import != NULL) {
+ pthread_mutex_lock(&import->proxiesMutex);
+ if (import->proxies != NULL) {
+ hash_map_iterator_pt iter = hashMapIterator_create(import->proxies);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ struct service_proxy *proxy = hashMapEntry_getValue(entry);
+ importRegistration_destroyProxy(proxy);
+ }
+ hashMapIterator_destroy(iter);
+ }
+ pthread_mutex_unlock(&import->proxiesMutex);
+ }
+}
+
+void importRegistration_destroy(import_registration_pt import) {
+ if (import != NULL) {
+ if (import->proxies != NULL) {
+ hashMap_destroy(import->proxies, false, false);
+ import->proxies = NULL;
+ }
+
+ pthread_mutex_destroy(&import->mutex);
+ pthread_mutex_destroy(&import->proxiesMutex);
+
+ if (import->factory != NULL) {
+ free(import->factory);
+ }
+
+ if(import->version!=NULL){
+ version_destroy(import->version);
+ }
+ free(import);
+ }
+}
+
+celix_status_t importRegistration_start(import_registration_pt import) {
+ celix_status_t status = CELIX_SUCCESS;
+ if (import->factoryReg == NULL && import->factory != NULL) {
+ properties_pt props = NULL;
+ properties_copy(import->endpoint->properties, &props);
+ status = bundleContext_registerServiceFactory(import->context, (char *)import->classObject, import->factory, props, &import->factoryReg);
+ } else {
+ status = CELIX_ILLEGAL_STATE;
+ }
+ return status;
+}
+
+celix_status_t importRegistration_stop(import_registration_pt import) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (import->factoryReg != NULL) {
+ serviceRegistration_unregister(import->factoryReg);
+ import->factoryReg = NULL;
+ }
+
+ importRegistration_clearProxies(import);
+
+ return status;
+}
+
+
+celix_status_t importRegistration_getService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **out) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ /*
+ module_pt module = NULL;
+ char *name = NULL;
+ bundle_getCurrentModule(bundle, &module);
+ module_getSymbolicName(module, &name);
+ printf("getting service for bundle '%s'\n", name);
+ */
+
+
+ pthread_mutex_lock(&import->proxiesMutex);
+ struct service_proxy *proxy = hashMap_get(import->proxies, bundle);
+ if (proxy == NULL) {
+ status = importRegistration_createProxy(import, bundle, &proxy);
+ if (status == CELIX_SUCCESS) {
+ hashMap_put(import->proxies, bundle, proxy);
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ proxy->count += 1;
+ *out = proxy->service;
+ }
+ pthread_mutex_unlock(&import->proxiesMutex);
+
+ return status;
+}
+
+static celix_status_t importRegistration_createProxy(import_registration_pt import, bundle_pt bundle, struct service_proxy **out) {
+ celix_status_t status;
+ dyn_interface_type* intf = NULL;
+ FILE *descriptor = NULL;
+
+ status = dfi_findDescriptor(import->context, bundle, import->classObject, &descriptor);
+
+ if (status != CELIX_SUCCESS || descriptor == NULL) {
+ //TODO use log helper logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Cannot find/open descriptor for '%s'", import->classObject);
+ fprintf(stderr, "RSA_DFI: Cannot find/open descriptor for '%s'", import->classObject);
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ int rc = dynInterface_parse(descriptor, &intf);
+ fclose(descriptor);
+ if (rc != 0 || intf==NULL) {
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+ }
+
+ /* Check if the imported service version is compatible with the one in the consumer descriptor */
+ version_pt consumerVersion = NULL;
+ bool isCompatible = false;
+ dynInterface_getVersion(intf,&consumerVersion);
+ version_isCompatible(consumerVersion,import->version,&isCompatible);
+
+ if(!isCompatible){
+ char* cVerString = NULL;
+ char* pVerString = NULL;
+ version_toString(consumerVersion,&cVerString);
+ version_toString(import->version,&pVerString);
+ printf("Service version mismatch: consumer has %s, provider has %s. NOT creating proxy.\n",cVerString,pVerString);
+ dynInterface_destroy(intf);
+ free(cVerString);
+ free(pVerString);
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+
+ struct service_proxy *proxy = NULL;
+ if (status == CELIX_SUCCESS) {
+ proxy = calloc(1, sizeof(*proxy));
+ if (proxy == NULL) {
+ status = CELIX_ENOMEM;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ proxy->intf = intf;
+ size_t count = dynInterface_nrOfMethods(proxy->intf);
+ proxy->service = calloc(1 + count, sizeof(void *));
+ if (proxy->service == NULL) {
+ status = CELIX_ENOMEM;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ void **serv = proxy->service;
+ serv[0] = import;
+
+ struct methods_head *list = NULL;
+ dynInterface_methods(proxy->intf, &list);
+ struct method_entry *entry = NULL;
+ void (*fn)(void) = NULL;
+ int index = 0;
+ TAILQ_FOREACH(entry, list, entries) {
+ int rc = dynFunction_createClosure(entry->dynFunc, importRegistration_proxyFunc, entry, &fn);
+ serv[index + 1] = fn;
+ index += 1;
+
+ if (rc != 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ break;
+ }
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *out = proxy;
+ } else if (proxy != NULL) {
+ if (proxy->intf != NULL) {
+ dynInterface_destroy(proxy->intf);
+ proxy->intf = NULL;
+ }
+ free(proxy->service);
+ free(proxy);
+ }
+
+ return status;
+}
+
+static void importRegistration_proxyFunc(void *userData, void *args[], void *returnVal) {
+ int status = CELIX_SUCCESS;
+ struct method_entry *entry = userData;
+ import_registration_pt import = *((void **)args[0]);
+
+ if (import == NULL || import->send == NULL) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+
+ char *invokeRequest = NULL;
+ if (status == CELIX_SUCCESS) {
+ status = jsonRpc_prepareInvokeRequest(entry->dynFunc, entry->id, args, &invokeRequest);
+ //printf("Need to send following json '%s'\n", invokeRequest);
+ }
+
+
+ if (status == CELIX_SUCCESS) {
+ char *reply = NULL;
+ int rc = 0;
+ //printf("sending request\n");
+ celixThreadMutex_lock(&import->mutex);
+ if (import->send != NULL) {
+ import->send(import->sendHandle, import->endpoint, invokeRequest, &reply, &rc);
+ }
+ celixThreadMutex_unlock(&import->mutex);
+ //printf("request sended. got reply '%s' with status %i\n", reply, rc);
+
+ if (rc == 0) {
+ //fjprintf("Handling reply '%s'\n", reply);
+ status = jsonRpc_handleReply(entry->dynFunc, reply, args);
+ }
+
+ *(int *) returnVal = rc;
+
+ free(invokeRequest); //Allocated by json_dumps in jsonRpc_prepareInvokeRequest
+ free(reply); //Allocated by json_dumps in remoteServiceAdmin_send through curl call
+ }
+
+ if (status != CELIX_SUCCESS) {
+ //TODO log error
+ }
+}
+
+celix_status_t importRegistration_ungetService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **out) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ assert(import != NULL);
+ assert(import->proxies != NULL);
+
+ pthread_mutex_lock(&import->proxiesMutex);
+
+ struct service_proxy *proxy = hashMap_get(import->proxies, bundle);
+ if (proxy != NULL) {
+ if (*out == proxy->service) {
+ proxy->count -= 1;
+ } else {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (proxy->count == 0) {
+ hashMap_remove(import->proxies, bundle);
+ importRegistration_destroyProxy(proxy);
+ }
+ }
+
+ pthread_mutex_unlock(&import->proxiesMutex);
+
+ return status;
+}
+
+static void importRegistration_destroyProxy(struct service_proxy *proxy) {
+ if (proxy != NULL) {
+ if (proxy->intf != NULL) {
+ dynInterface_destroy(proxy->intf);
+ }
+ if (proxy->service != NULL) {
+ free(proxy->service);
+ }
+ free(proxy);
+ }
+}
+
+
+celix_status_t importRegistration_close(import_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ importRegistration_stop(registration);
+ return status;
+}
+
+celix_status_t importRegistration_getException(import_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ //TODO
+ return status;
+}
+
+celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ //TODO
+ return status;
+}
+
+celix_status_t importReference_getImportedEndpoint(import_reference_pt reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t importReference_getImportedService(import_reference_pt reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/src/import_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/src/import_registration_dfi.h b/remote_services/remote_service_admin_dfi/src/import_registration_dfi.h
new file mode 100644
index 0000000..aac4bc7
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/src/import_registration_dfi.h
@@ -0,0 +1,44 @@
+/**
+ *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.
+ */
+
+#ifndef CELIX_IMPORT_REGISTRATION_DFI_H
+#define CELIX_IMPORT_REGISTRATION_DFI_H
+
+#include "import_registration.h"
+#include "dfi_utils.h"
+
+#include <celix_errno.h>
+
+typedef void (*send_func_type)(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
+
+celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt description, const char *classObject, const char* serviceVersion,
+ import_registration_pt *import);
+celix_status_t importRegistration_close(import_registration_pt import);
+void importRegistration_destroy(import_registration_pt import);
+
+celix_status_t importRegistration_setSendFn(import_registration_pt reg,
+ send_func_type,
+ void *handle);
+celix_status_t importRegistration_start(import_registration_pt import);
+celix_status_t importRegistration_stop(import_registration_pt import);
+
+celix_status_t importRegistration_getService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **service);
+celix_status_t importRegistration_ungetService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **service);
+
+#endif //CELIX_IMPORT_REGISTRATION_DFI_H
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/src/remote_service_admin_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/src/remote_service_admin_activator.c b/remote_services/remote_service_admin_dfi/src/remote_service_admin_activator.c
new file mode 100644
index 0000000..d4cc765
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/src/remote_service_admin_activator.c
@@ -0,0 +1,124 @@
+/**
+ *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.
+ */
+/*
+ * remote_service_admin_activator.c
+ *
+ * \date Sep 30, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <remote_service_admin.h>
+
+#include "remote_service_admin_dfi.h"
+
+#include "bundle_activator.h"
+#include "service_registration.h"
+
+#include "export_registration_dfi.h"
+#include "import_registration_dfi.h"
+
+struct activator {
+ remote_service_admin_pt admin;
+ remote_service_admin_service_pt adminService;
+ service_registration_pt registration;
+};
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator;
+
+ activator = calloc(1, sizeof(*activator));
+ if (!activator) {
+ status = CELIX_ENOMEM;
+ } else {
+ activator->admin = NULL;
+ activator->registration = NULL;
+
+ *userData = activator;
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+ remote_service_admin_service_pt remoteServiceAdmin = NULL;
+
+ status = remoteServiceAdmin_create(context, &activator->admin);
+ if (status == CELIX_SUCCESS) {
+ remoteServiceAdmin = calloc(1, sizeof(*remoteServiceAdmin));
+ if (!remoteServiceAdmin) {
+ status = CELIX_ENOMEM;
+ } else {
+ remoteServiceAdmin->admin = activator->admin;
+ remoteServiceAdmin->exportService = remoteServiceAdmin_exportService;
+
+ remoteServiceAdmin->getExportedServices = remoteServiceAdmin_getExportedServices;
+ remoteServiceAdmin->getImportedEndpoints = remoteServiceAdmin_getImportedEndpoints;
+ remoteServiceAdmin->importService = remoteServiceAdmin_importService;
+
+ remoteServiceAdmin->exportReference_getExportedEndpoint = exportReference_getExportedEndpoint;
+ remoteServiceAdmin->exportReference_getExportedService = exportReference_getExportedService;
+
+ remoteServiceAdmin->exportRegistration_close = remoteServiceAdmin_removeExportedService;
+ remoteServiceAdmin->exportRegistration_getException = exportRegistration_getException;
+ remoteServiceAdmin->exportRegistration_getExportReference = exportRegistration_getExportReference;
+
+ remoteServiceAdmin->importReference_getImportedEndpoint = importReference_getImportedEndpoint;
+ remoteServiceAdmin->importReference_getImportedService = importReference_getImportedService;
+
+ remoteServiceAdmin->importRegistration_close = remoteServiceAdmin_removeImportedService;
+ remoteServiceAdmin->importRegistration_getException = importRegistration_getException;
+ remoteServiceAdmin->importRegistration_getImportReference = importRegistration_getImportReference;
+
+ status = bundleContext_registerService(context, OSGI_RSA_REMOTE_SERVICE_ADMIN, remoteServiceAdmin, NULL, &activator->registration);
+ activator->adminService = remoteServiceAdmin;
+ }
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ serviceRegistration_unregister(activator->registration);
+ activator->registration = NULL;
+
+ remoteServiceAdmin_stop(activator->admin);
+ remoteServiceAdmin_destroy(&activator->admin);
+
+ free(activator->adminService);
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ free(activator);
+
+ return status;
+}
+
+
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c
new file mode 100644
index 0000000..6effc94
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c
@@ -0,0 +1,771 @@
+/**
+ *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.
+ */
+/*
+ * remote_service_admin_impl.c
+ *
+ * \date May 21, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <ifaddrs.h>
+#include <string.h>
+#include <uuid/uuid.h>
+#include <curl/curl.h>
+
+#include <jansson.h>
+#include "json_serializer.h"
+#include "remote_service_admin.h"
+
+#include "import_registration_dfi.h"
+#include "export_registration_dfi.h"
+#include "remote_service_admin_dfi.h"
+#include "json_rpc.h"
+
+#include "remote_constants.h"
+#include "constants.h"
+#include "civetweb.h"
+
+// defines how often the webserver is restarted (with an increased port number)
+#define MAX_NUMBER_OF_RESTARTS 5
+
+
+#define RSA_LOG_ERROR(admin, msg, ...) \
+ logHelper_log((admin)->loghelper, OSGI_LOGSERVICE_ERROR, (msg), ##__VA_ARGS__)
+
+#define RSA_LOG_WARNING(admin, msg, ...) \
+ logHelper_log((admin)->loghelper, OSGI_LOGSERVICE_ERROR, (msg), ##__VA_ARGS__)
+
+#define RSA_LOG_DEBUG(admin, msg, ...) \
+ logHelper_log((admin)->loghelper, OSGI_LOGSERVICE_ERROR, (msg), ##__VA_ARGS__)
+
+struct remote_service_admin {
+ bundle_context_pt context;
+ log_helper_pt loghelper;
+
+ celix_thread_mutex_t exportedServicesLock;
+ hash_map_pt exportedServices;
+
+ celix_thread_mutex_t importedServicesLock;
+ array_list_pt importedServices;
+
+ char *port;
+ char *ip;
+
+ struct mg_context *ctx;
+};
+
+struct post {
+ const char *readptr;
+ int size;
+};
+
+struct get {
+ char *writeptr;
+ int size;
+};
+
+#define OSGI_RSA_REMOTE_PROXY_FACTORY "remote_proxy_factory"
+#define OSGI_RSA_REMOTE_PROXY_TIMEOUT "remote_proxy_timeout"
+
+static const char *data_response_headers =
+ "HTTP/1.1 200 OK\r\n"
+ "Cache: no-cache\r\n"
+ "Content-Type: application/json\r\n"
+ "\r\n";
+
+static const char *no_content_response_headers =
+ "HTTP/1.1 204 OK\r\n";
+
+// TODO do we need to specify a non-Amdatu specific configuration type?!
+static const char * const CONFIGURATION_TYPE = "org.amdatu.remote.admin.http";
+static const char * const ENDPOINT_URL = "org.amdatu.remote.admin.http.url";
+
+static const char *DEFAULT_PORT = "8888";
+static const char *DEFAULT_IP = "127.0.0.1";
+
+static const unsigned int DEFAULT_TIMEOUT = 0;
+
+static int remoteServiceAdmin_callback(struct mg_connection *conn);
+static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, properties_pt props, char *interface, endpoint_description_pt *description);
+static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
+static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip);
+static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp);
+static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp);
+static void remoteServiceAdmin_log(remote_service_admin_pt admin, int level, const char *file, int line, const char *msg, ...);
+
+celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *admin = calloc(1, sizeof(**admin));
+
+ if (!*admin) {
+ status = CELIX_ENOMEM;
+ } else {
+ unsigned int port_counter = 0;
+ const char *port = NULL;
+ const char *ip = NULL;
+ char *detectedIp = NULL;
+ (*admin)->context = context;
+ (*admin)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL);
+ arrayList_create(&(*admin)->importedServices);
+
+ celixThreadMutex_create(&(*admin)->exportedServicesLock, NULL);
+ celixThreadMutex_create(&(*admin)->importedServicesLock, NULL);
+
+ if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
+ logHelper_start((*admin)->loghelper);
+ dynCommon_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
+ dynType_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
+ dynFunction_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
+ dynInterface_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
+ jsonSerializer_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
+ jsonRpc_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
+ }
+
+ bundleContext_getProperty(context, "RSA_PORT", &port);
+ if (port == NULL) {
+ port = (char *)DEFAULT_PORT;
+ }
+
+ bundleContext_getProperty(context, "RSA_IP", &ip);
+ if (ip == NULL) {
+ const char *interface = NULL;
+
+ bundleContext_getProperty(context, "RSA_INTERFACE", &interface);
+ if ((interface != NULL) && (remoteServiceAdmin_getIpAdress((char*)interface, &detectedIp) != CELIX_SUCCESS)) {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: Could not retrieve IP adress for interface %s", interface);
+ }
+
+ if (ip == NULL) {
+ remoteServiceAdmin_getIpAdress(NULL, &detectedIp);
+ }
+
+ ip = detectedIp;
+ }
+
+ if (ip != NULL) {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Using %s for service annunciation", ip);
+ (*admin)->ip = strdup(ip);
+ }
+ else {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No IP address for service annunciation set. Using %s", DEFAULT_IP);
+ (*admin)->ip = strdup((char*) DEFAULT_IP);
+ }
+
+ if (detectedIp != NULL) {
+ free(detectedIp);
+ }
+
+ // Prepare callbacks structure. We have only one callback, the rest are NULL.
+ struct mg_callbacks callbacks;
+ memset(&callbacks, 0, sizeof(callbacks));
+ callbacks.begin_request = remoteServiceAdmin_callback;
+
+ char newPort[10];
+
+ do {
+
+ const char *options[] = { "listening_ports", port, "num_threads", "5", NULL};
+
+ (*admin)->ctx = mg_start(&callbacks, (*admin), options);
+
+ if ((*admin)->ctx != NULL) {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Start webserver: %s", port);
+ (*admin)->port = strdup(port);
+
+ }
+ else {
+ errno = 0;
+ char* endptr = (char*)port;
+ int currentPort = strtol(port, &endptr, 10);
+
+ if (*endptr || errno != 0) {
+ currentPort = strtol(DEFAULT_PORT, NULL, 10);
+ }
+
+ port_counter++;
+ snprintf(&newPort[0], 6, "%d", (currentPort+1));
+
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_ERROR, "Error while starting rsa server on port %s - retrying on port %s...", port, newPort);
+ port = newPort;
+ }
+ } while(((*admin)->ctx == NULL) && (port_counter < MAX_NUMBER_OF_RESTARTS));
+
+ }
+
+ return status;
+}
+
+
+celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin)
+{
+ celix_status_t status = CELIX_SUCCESS;
+
+ free((*admin)->ip);
+ free((*admin)->port);
+ free(*admin);
+
+ //TODO destroy exports/imports
+
+ *admin = NULL;
+
+ return status;
+}
+
+
+celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&admin->exportedServicesLock);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(admin->exportedServices);
+ while (hashMapIterator_hasNext(iter)) {
+ array_list_pt exports = hashMapIterator_nextValue(iter);
+ int i;
+ for (i = 0; i < arrayList_size(exports); i++) {
+ export_registration_pt export = arrayList_get(exports, i);
+ if (export != NULL) {
+ exportRegistration_stop(export);
+ exportRegistration_destroy(export);
+ }
+ }
+ arrayList_destroy(exports);
+ }
+ hashMapIterator_destroy(iter);
+ celixThreadMutex_unlock(&admin->exportedServicesLock);
+
+ celixThreadMutex_lock(&admin->importedServicesLock);
+ int i;
+ int size = arrayList_size(admin->importedServices);
+ for (i = 0; i < size ; i += 1) {
+ import_registration_pt import = arrayList_get(admin->importedServices, i);
+ if (import != NULL) {
+ importRegistration_stop(import);
+ importRegistration_destroy(import);
+ }
+ }
+ celixThreadMutex_unlock(&admin->importedServicesLock);
+
+ if (admin->ctx != NULL) {
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Stopping webserver...");
+ mg_stop(admin->ctx);
+ admin->ctx = NULL;
+ }
+
+ hashMap_destroy(admin->exportedServices, false, false);
+ arrayList_destroy(admin->importedServices);
+
+ logHelper_stop(admin->loghelper);
+ logHelper_destroy(&admin->loghelper);
+
+ return status;
+}
+
+/**
+ * Request: http://host:port/services/{service}/{request}
+ */
+//void *remoteServiceAdmin_callback(enum mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info) {
+
+celix_status_t importRegistration_getFactory(import_registration_pt import, service_factory_pt *factory);
+
+static int remoteServiceAdmin_callback(struct mg_connection *conn) {
+ int result = 1; // zero means: let civetweb handle it further, any non-zero value means it is handled by us...
+
+ const struct mg_request_info *request_info = mg_get_request_info(conn);
+ if (request_info->uri != NULL) {
+ remote_service_admin_pt rsa = request_info->user_data;
+
+
+ if (strncmp(request_info->uri, "/service/", 9) == 0 && strcmp("POST", request_info->request_method) == 0) {
+
+ // uri = /services/myservice/call
+ const char *uri = request_info->uri;
+ // rest = myservice/call
+
+ const char *rest = uri+9;
+ char *interfaceStart = strchr(rest, '/');
+ int pos = interfaceStart - rest;
+ char service[pos+1];
+ strncpy(service, rest, pos);
+ service[pos] = '\0';
+ unsigned long serviceId = strtoul(service,NULL,10);
+
+ celixThreadMutex_lock(&rsa->exportedServicesLock);
+
+ //find endpoint
+ export_registration_pt export = NULL;
+ hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ array_list_pt exports = hashMapEntry_getValue(entry);
+ int expIt = 0;
+ for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
+ export_registration_pt check = arrayList_get(exports, expIt);
+ export_reference_pt ref = NULL;
+ exportRegistration_getExportReference(check, &ref);
+ endpoint_description_pt checkEndpoint = NULL;
+ exportReference_getExportedEndpoint(ref, &checkEndpoint);
+ if (serviceId == checkEndpoint->serviceId) {
+ export = check;
+ free(ref);
+ break;
+ }
+ free(ref);
+ }
+ }
+ hashMapIterator_destroy(iter);
+
+ if (export != NULL) {
+
+ uint64_t datalength = request_info->content_length;
+ char* data = malloc(datalength + 1);
+ mg_read(conn, data, datalength);
+ data[datalength] = '\0';
+
+ char *response = NULL;
+ int responceLength = 0;
+ int rc = exportRegistration_call(export, data, -1, &response, &responceLength);
+ if (rc != CELIX_SUCCESS) {
+ RSA_LOG_ERROR(rsa, "Error trying to invoke remove service, got error %i\n", rc);
+ }
+
+ if (rc == CELIX_SUCCESS && response != NULL) {
+ mg_write(conn, data_response_headers, strlen(data_response_headers));
+ mg_write(conn, response, strlen(response));
+ free(response);
+ } else {
+ mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
+ }
+ result = 1;
+
+ free(data);
+ } else {
+ result = 0;
+ RSA_LOG_WARNING(rsa, "NO export registration found for service id %lu", serviceId);
+ }
+
+ celixThreadMutex_unlock(&rsa->exportedServicesLock);
+
+ }
+ }
+
+ return result;
+}
+
+celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations) {
+ celix_status_t status;
+
+ arrayList_create(registrations);
+ array_list_pt references = NULL;
+ service_reference_pt reference = NULL;
+ char filter [256];
+
+ snprintf(filter, 256, "(%s=%s)", (char *)OSGI_FRAMEWORK_SERVICE_ID, serviceId);
+
+ status = bundleContext_getServiceReferences(admin->context, NULL, filter, &references);
+
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_DEBUG, "RSA: exportService called for serviceId %s", serviceId);
+
+ int i;
+ int size = arrayList_size(references);
+ for (i = 0; i < size; i += 1) {
+ if (i == 0) {
+ reference = arrayList_get(references, i);
+ } else {
+ bundleContext_ungetServiceReference(admin->context, arrayList_get(references, i));
+ }
+ }
+ arrayList_destroy(references);
+
+ if (reference == NULL) {
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "ERROR: expected a reference for service id %s.", serviceId);
+ status = CELIX_ILLEGAL_STATE;
+ }
+
+ const char *exports = NULL;
+ const char *provided = NULL;
+ if (status == CELIX_SUCCESS) {
+ serviceReference_getProperty(reference, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exports);
+ serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_OBJECTCLASS, &provided);
+
+ if (exports == NULL || provided == NULL || strcmp(exports, provided) != 0) {
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No Services to export.");
+ status = CELIX_ILLEGAL_STATE;
+ } else {
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Export service (%s)", provided);
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ const char *interface = provided;
+ endpoint_description_pt endpoint = NULL;
+ export_registration_pt registration = NULL;
+
+ remoteServiceAdmin_createEndpointDescription(admin, reference, properties, (char*)interface, &endpoint);
+ //TODO precheck if descriptor exists
+ status = exportRegistration_create(admin->loghelper, reference, endpoint, admin->context, ®istration);
+ if (status == CELIX_SUCCESS) {
+ status = exportRegistration_start(registration);
+ if (status == CELIX_SUCCESS) {
+ arrayList_add(*registrations, registration);
+ }
+ }
+ }
+
+
+ if (status == CELIX_SUCCESS) {
+ celixThreadMutex_lock(&admin->exportedServicesLock);
+ hashMap_put(admin->exportedServices, reference, *registrations);
+ celixThreadMutex_unlock(&admin->exportedServicesLock);
+ }
+ else{
+ arrayList_destroy(*registrations);
+ *registrations = NULL;
+ }
+
+ return status;
+}
+
+celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration) {
+ celix_status_t status;
+
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_DFI: Removing exported service");
+
+ export_reference_pt ref = NULL;
+ status = exportRegistration_getExportReference(registration, &ref);
+
+ if (status == CELIX_SUCCESS && ref != NULL) {
+ service_reference_pt servRef;
+ celixThreadMutex_lock(&admin->exportedServicesLock);
+ exportReference_getExportedService(ref, &servRef);
+
+ array_list_pt exports = (array_list_pt)hashMap_remove(admin->exportedServices, servRef);
+ if(exports!=NULL){
+ arrayList_destroy(exports);
+ }
+
+ exportRegistration_close(registration);
+ exportRegistration_destroy(registration);
+
+ celixThreadMutex_unlock(&admin->exportedServicesLock);
+
+ free(ref);
+
+ } else {
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "Cannot find reference for registration");
+ }
+
+ return status;
+}
+
+static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, properties_pt props, char *interface, endpoint_description_pt *endpoint) {
+
+ celix_status_t status = CELIX_SUCCESS;
+ properties_pt endpointProperties = properties_create();
+
+
+ unsigned int size = 0;
+ char **keys;
+
+ serviceReference_getPropertyKeys(reference, &keys, &size);
+ for (int i = 0; i < size; i++) {
+ char *key = keys[i];
+ const char *value = NULL;
+
+ if (serviceReference_getProperty(reference, key, &value) == CELIX_SUCCESS
+ && strcmp(key, (char*) OSGI_RSA_SERVICE_EXPORTED_INTERFACES) != 0
+ && strcmp(key, (char*) OSGI_FRAMEWORK_OBJECTCLASS) != 0) {
+ properties_set(endpointProperties, key, value);
+ }
+ }
+
+ hash_map_entry_pt entry = hashMap_getEntry(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
+
+ char* key = hashMapEntry_getKey(entry);
+ char *serviceId = (char *) hashMap_remove(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
+ const char *uuid = NULL;
+
+ char buf[512];
+ snprintf(buf, 512, "/service/%s/%s", serviceId, interface);
+
+ char url[1024];
+ snprintf(url, 1024, "http://%s:%s%s", admin->ip, admin->port, buf);
+
+ uuid_t endpoint_uid;
+ uuid_generate(endpoint_uid);
+ char endpoint_uuid[37];
+ uuid_unparse_lower(endpoint_uid, endpoint_uuid);
+
+ bundleContext_getProperty(admin->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
+ properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
+ properties_set(endpointProperties, (char*) OSGI_FRAMEWORK_OBJECTCLASS, interface);
+ properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_SERVICE_ID, serviceId);
+ properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID, endpoint_uuid);
+ properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED, "true");
+ properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED_CONFIGS, (char*) CONFIGURATION_TYPE);
+ properties_set(endpointProperties, (char*) ENDPOINT_URL, url);
+
+ if (props != NULL) {
+ hash_map_iterator_pt propIter = hashMapIterator_create(props);
+ while (hashMapIterator_hasNext(propIter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(propIter);
+ properties_set(endpointProperties, (char*)hashMapEntry_getKey(entry), (char*)hashMapEntry_getValue(entry));
+ }
+ hashMapIterator_destroy(propIter);
+ }
+
+ *endpoint = calloc(1, sizeof(**endpoint));
+ if (!*endpoint) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*endpoint)->id = (char*)properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID);
+ const char *serviceId = NULL;
+ serviceReference_getProperty(reference, (char*) OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
+ (*endpoint)->serviceId = strtoull(serviceId, NULL, 0);
+ (*endpoint)->frameworkUUID = (char*) properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
+ (*endpoint)->service = strndup(interface, 1024*10);
+ (*endpoint)->properties = endpointProperties;
+ }
+
+ free(key);
+ free(serviceId);
+ free(keys);
+
+ return status;
+}
+
+static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip) {
+ celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+
+ struct ifaddrs *ifaddr, *ifa;
+ char host[NI_MAXHOST];
+
+ if (getifaddrs(&ifaddr) != -1)
+ {
+ for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
+ {
+ if (ifa->ifa_addr == NULL)
+ continue;
+
+ if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
+ if (interface == NULL) {
+ *ip = strdup(host);
+ status = CELIX_SUCCESS;
+ }
+ else if (strcmp(ifa->ifa_name, interface) == 0) {
+ *ip = strdup(host);
+ status = CELIX_SUCCESS;
+ }
+ }
+ }
+
+ freeifaddrs(ifaddr);
+ }
+
+ return status;
+}
+
+
+celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description)
+{
+ celix_status_t status = CELIX_SUCCESS;
+
+ properties_destroy((*description)->properties);
+ free((*description)->service);
+ free(*description);
+
+ return status;
+}
+
+
+celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpointDescription, import_registration_pt *out) {
+ celix_status_t status = CELIX_SUCCESS;
+ import_registration_pt import = NULL;
+
+ const char *objectClass = properties_get(endpointDescription->properties, "objectClass");
+ const char *serviceVersion = properties_get(endpointDescription->properties, (char*) CELIX_FRAMEWORK_SERVICE_VERSION);
+
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Import service %s", endpointDescription->service);
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "Registering service factory (proxy) for service '%s'\n", objectClass);
+
+ if (objectClass != NULL) {
+ status = importRegistration_create(admin->context, endpointDescription, objectClass, serviceVersion, &import);
+ }
+ if (status == CELIX_SUCCESS && import != NULL) {
+ importRegistration_setSendFn(import, (send_func_type) remoteServiceAdmin_send, admin);
+ }
+
+ if (status == CELIX_SUCCESS && import != NULL) {
+ status = importRegistration_start(import);
+ }
+
+ celixThreadMutex_lock(&admin->importedServicesLock);
+ arrayList_add(admin->importedServices, import);
+ celixThreadMutex_unlock(&admin->importedServicesLock);
+
+ if (status == CELIX_SUCCESS) {
+ *out = import;
+ }
+
+ return status;
+}
+
+
+celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_DFI: Removing imported service");
+
+ celixThreadMutex_lock(&admin->importedServicesLock);
+ int i;
+ int size = arrayList_size(admin->importedServices);
+ import_registration_pt current = NULL;
+ for (i = 0; i < size; i += 1) {
+ current = arrayList_get(admin->importedServices, i);
+ if (current == registration) {
+ arrayList_remove(admin->importedServices, i);
+ importRegistration_close(current);
+ importRegistration_destroy(current);
+ break;
+ }
+ }
+ celixThreadMutex_unlock(&admin->importedServicesLock);
+
+ return status;
+}
+
+
+static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus) {
+ remote_service_admin_pt rsa = handle;
+ struct post post;
+ post.readptr = request;
+ post.size = strlen(request);
+
+ struct get get;
+ get.size = 0;
+ get.writeptr = malloc(1);
+
+ char *serviceUrl = (char*)properties_get(endpointDescription->properties, (char*) ENDPOINT_URL);
+ char url[256];
+ snprintf(url, 256, "%s", serviceUrl);
+
+ // assume the default timeout
+ int timeout = DEFAULT_TIMEOUT;
+
+ const char *timeoutStr = NULL;
+ // Check if the endpoint has a timeout, if so, use it.
+ timeoutStr = (char*) properties_get(endpointDescription->properties, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT);
+ if (timeoutStr == NULL) {
+ // If not, get the global variable and use that one.
+ bundleContext_getProperty(rsa->context, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT, &timeoutStr);
+ }
+
+ // Update timeout if a property is used to set it.
+ if (timeoutStr != NULL) {
+ timeout = atoi(timeoutStr);
+ }
+
+ celix_status_t status = CELIX_SUCCESS;
+ CURL *curl;
+ CURLcode res;
+
+ curl = curl_easy_init();
+ if(!curl) {
+ status = CELIX_ILLEGAL_STATE;
+ } else {
+ curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_POST, 1L);
+ curl_easy_setopt(curl, CURLOPT_READFUNCTION, remoteServiceAdmin_readCallback);
+ curl_easy_setopt(curl, CURLOPT_READDATA, &post);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, remoteServiceAdmin_write);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&get);
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)post.size);
+ logHelper_log(rsa->loghelper, OSGI_LOGSERVICE_DEBUG, "RSA: Performing curl post\n");
+ res = curl_easy_perform(curl);
+
+ *reply = get.writeptr;
+ *replyStatus = res;
+
+ curl_easy_cleanup(curl);
+ }
+
+ return status;
+}
+
+static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp) {
+ struct post *post = userp;
+
+ if (post->size) {
+ *(char *) ptr = post->readptr[0];
+ post->readptr++;
+ post->size--;
+ return 1;
+ }
+
+ return 0;
+}
+
+static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp) {
+ size_t realsize = size * nmemb;
+ struct get *mem = (struct get *)userp;
+
+ mem->writeptr = realloc(mem->writeptr, mem->size + realsize + 1);
+ if (mem->writeptr == NULL) {
+ /* out of memory! */
+ printf("not enough memory (realloc returned NULL)");
+ exit(EXIT_FAILURE);
+ }
+
+ memcpy(&(mem->writeptr[mem->size]), contents, realsize);
+ mem->size += realsize;
+ mem->writeptr[mem->size] = 0;
+
+ return realsize;
+}
+
+
+static void remoteServiceAdmin_log(remote_service_admin_pt admin, int level, const char *file, int line, const char *msg, ...) {
+ va_list ap;
+ va_start(ap, msg);
+ int levels[5] = {0, OSGI_LOGSERVICE_ERROR, OSGI_LOGSERVICE_WARNING, OSGI_LOGSERVICE_INFO, OSGI_LOGSERVICE_DEBUG};
+
+ char buf1[256];
+ snprintf(buf1, 256, "FILE:%s, LINE:%i, MSG:", file, line);
+
+ char buf2[256];
+ vsnprintf(buf2, 256, msg, ap);
+ logHelper_log(admin->loghelper, levels[level], "%s%s", buf1, buf2);
+ va_end(ap);
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.h b/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.h
new file mode 100644
index 0000000..8b282f1
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.h
@@ -0,0 +1,57 @@
+/**
+ *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.
+ */
+/*
+ * remote_service_admin_http_impl.h
+ *
+ * \date Sep 30, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
+#define REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
+
+
+#include "bundle_context.h"
+#include "endpoint_description.h"
+
+//typedef struct remote_service_admin *remote_service_admin_pt;
+
+celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin);
+celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin);
+
+celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin);
+
+celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
+celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration);
+celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services);
+celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services);
+celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
+celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration);
+
+
+celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint);
+celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service);
+
+celix_status_t importReference_getImportedEndpoint(import_reference_pt reference);
+celix_status_t importReference_getImportedService(import_reference_pt reference);
+
+celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description);
+
+#endif /* REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/test/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/test/CMakeLists.txt b/remote_services/remote_service_admin_dfi/test/CMakeLists.txt
new file mode 100644
index 0000000..a78a6d0
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/test/CMakeLists.txt
@@ -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.
+
+find_package(CppUTest REQUIRED)
+include_directories(${CPPUTEST_INCLUDE_DIR})
+
+add_bundle(rsa_dfi_tst_bundle
+ VERSION 0.0.1
+ SOURCES
+ src/tst_activator.c
+)
+get_target_property(DESCR calculator_api INTERFACE_CALCULATOR_DESCRIPTOR)
+bundle_files(rsa_dfi_tst_bundle ${DESCR} DESTINATION .)
+target_link_libraries(rsa_dfi_tst_bundle PRIVATE ${CPPUTEST_LIBRARY} calculator_api)
+target_include_directories(rsa_dfi_tst_bundle PRIVATE src)
+
+add_executable(test_rsa_dfi
+ src/run_tests.cpp
+ src/rsa_tests.cpp
+ src/rsa_client_server_tests.cpp
+)
+target_include_directories(test_rsa_dfi PRIVATE src)
+target_link_libraries(test_rsa_dfi PRIVATE ${CURL_LIBRARIES} ${CPPUTEST_LIBRARY}
+ Celix::framework
+ Celix::remote_service_admin_api
+ Celix::remote_service_admin_common
+ calculator_api)
+
+get_property(rsa_bundle_file TARGET remote_service_admin_dfi PROPERTY BUNDLE_FILE)
+get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE_FILE)
+get_property(calculator_shell_bundle_file TARGET calculator_shell PROPERTY BUNDLE_FILE)
+get_property(discovery_configured_bundle_file TARGET discovery_configured PROPERTY BUNDLE_FILE)
+get_property(topology_manager_bundle_file TARGET topology_manager PROPERTY BUNDLE_FILE)
+get_property(tst_bundle_file TARGET rsa_dfi_tst_bundle PROPERTY BUNDLE_FILE)
+
+configure_file(config.properties.in config.properties)
+configure_file(client.properties.in client.properties)
+configure_file(server.properties.in server.properties)
+
+add_dependencies(test_rsa_dfi
+ remote_service_admin_dfi_bundle #note depend on the target creating the bundle zip not the lib target
+ calculator_bundle
+)
+
+add_test(NAME run_test_rsa_dfi COMMAND test_rsa_dfi)
+SETUP_TARGET_FOR_COVERAGE(test_rsa_dfi_cov test_rsa_dfi ${CMAKE_BINARY_DIR}/coverage/test_rsa_dfi/test_rsa_dfi)
+
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/test/client.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/test/client.properties.in b/remote_services/remote_service_admin_dfi/test/client.properties.in
new file mode 100644
index 0000000..a9a06fb
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/test/client.properties.in
@@ -0,0 +1,8 @@
+cosgi.auto.start.1=@rsa_bundle_file@ @calculator_shell_bundle_file@ @discovery_configured_bundle_file@ @topology_manager_bundle_file@ @tst_bundle_file@
+LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+RSA_PORT=50881
+DISCOVERY_CFG_SERVER_PORT=50991
+DISCOVERY_CFG_POLL_ENDPOINTS=http://127.0.0.1:50992/org.apache.celix.discovery.configured
+org.osgi.framework.storage.clean=onFirstInit
+org.osgi.framework.storage=.cacheClient
+DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/test/config.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/test/config.properties.in b/remote_services/remote_service_admin_dfi/test/config.properties.in
new file mode 100644
index 0000000..5776ad8
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/test/config.properties.in
@@ -0,0 +1,20 @@
+# 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.
+
+cosgi.auto.start.1=@rsa_bundle_file@ @calc_bundle_file@
+LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+org.osgi.framework.storage.clean=onFirstInit
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/test/server.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/test/server.properties.in b/remote_services/remote_service_admin_dfi/test/server.properties.in
new file mode 100644
index 0000000..707c7e6
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/test/server.properties.in
@@ -0,0 +1,23 @@
+# 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.
+cosgi.auto.start.1=@rsa_bundle_file@ @calc_bundle_file@ @discovery_configured_bundle_file@ @topology_manager_bundle_file@
+LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+RSA_PORT=50882
+DISCOVERY_CFG_SERVER_PORT=50992
+org.osgi.framework.storage.clean=onFirstInit
+org.osgi.framework.storage=.cacheServer
+DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/test/src/rsa_client_server_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/test/src/rsa_client_server_tests.cpp b/remote_services/remote_service_admin_dfi/test/src/rsa_client_server_tests.cpp
new file mode 100644
index 0000000..528e6b7
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/test/src/rsa_client_server_tests.cpp
@@ -0,0 +1,133 @@
+/**
+ *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.
+ */
+
+#include <CppUTest/TestHarness.h>
+#include <remote_constants.h>
+#include <constants.h>
+#include <tst_service.h>
+#include "CppUTest/CommandLineTestRunner.h"
+#include "calculator_service.h"
+
+extern "C" {
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+
+#include "celix_launcher.h"
+#include "framework.h"
+#include "remote_service_admin.h"
+#include "calculator_service.h"
+
+ static framework_pt serverFramework = NULL;
+ static bundle_context_pt serverContext = NULL;
+
+ static framework_pt clientFramework = NULL;
+ static bundle_context_pt clientContext = NULL;
+
+ static void setupFm(void) {
+ int rc = 0;
+ bundle_pt bundle = NULL;
+
+ //server
+ rc = celixLauncher_launch("server.properties", &serverFramework);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ bundle = NULL;
+ rc = framework_getFrameworkBundle(serverFramework, &bundle);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ rc = bundle_getContext(bundle, &serverContext);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+
+ //client
+ rc = celixLauncher_launch("client.properties", &clientFramework);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ bundle = NULL;
+ rc = framework_getFrameworkBundle(clientFramework, &bundle);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ rc = bundle_getContext(bundle, &clientContext);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+ }
+
+ static void teardownFm(void) {
+ celixLauncher_stop(serverFramework);
+ celixLauncher_waitForShutdown(serverFramework);
+ celixLauncher_destroy(serverFramework);
+
+ celixLauncher_stop(clientFramework);
+ celixLauncher_waitForShutdown(clientFramework);
+ celixLauncher_destroy(clientFramework);
+
+ serverContext = NULL;
+ serverFramework = NULL;
+ clientContext = NULL;
+ clientFramework = NULL;
+ }
+
+ static void test1(void) {
+ celix_status_t rc;
+ service_reference_pt ref = NULL;
+ tst_service_pt tst = NULL;
+ int retries = 4;
+
+ while (ref == NULL && retries > 0) {
+ printf("Waiting for service .. %d\n", retries);
+ rc = bundleContext_getServiceReference(clientContext, (char *) TST_SERVICE_NAME, &ref);
+ usleep(1000000);
+ --retries;
+ }
+
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+ CHECK(ref != NULL);
+
+ rc = bundleContext_getService(clientContext, ref, (void **)&tst);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+ CHECK(tst != NULL);
+
+ rc = tst->test(tst->handle);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ bool result;
+ bundleContext_ungetService(clientContext, ref, &result);
+ bundleContext_ungetServiceReference(clientContext, ref);
+ }
+
+}
+
+
+TEST_GROUP(RsaDfiClientServerTests) {
+ void setup() {
+ setupFm();
+ }
+
+ void teardown() {
+ teardownFm();
+ }
+};
+
+TEST(RsaDfiClientServerTests, Test1) {
+ test1();
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/test/src/rsa_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/test/src/rsa_tests.cpp b/remote_services/remote_service_admin_dfi/test/src/rsa_tests.cpp
new file mode 100644
index 0000000..6026ac6
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/test/src/rsa_tests.cpp
@@ -0,0 +1,234 @@
+/**
+ *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.
+ */
+
+#include <CppUTest/TestHarness.h>
+#include <remote_constants.h>
+#include <constants.h>
+#include "CppUTest/CommandLineTestRunner.h"
+#include "calculator_service.h"
+
+extern "C" {
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "celix_launcher.h"
+#include "framework.h"
+#include "remote_service_admin.h"
+#include "calculator_service.h"
+
+
+ static framework_pt framework = NULL;
+ static bundle_context_pt context = NULL;
+
+ static service_reference_pt rsaRef = NULL;
+ static remote_service_admin_service_pt rsa = NULL;
+
+ static service_reference_pt calcRef = NULL;
+ static calculator_service_pt calc = NULL;
+
+ static void setupFm(void) {
+ int rc = 0;
+
+ rc = celixLauncher_launch("config.properties", &framework);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ bundle_pt bundle = NULL;
+ rc = framework_getFrameworkBundle(framework, &bundle);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ rc = bundle_getContext(bundle, &context);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ rc = bundleContext_getServiceReference(context, (char *)OSGI_RSA_REMOTE_SERVICE_ADMIN, &rsaRef);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+ CHECK(rsaRef != NULL);
+
+ rc = bundleContext_getService(context, rsaRef, (void **)&rsa);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ rc = bundleContext_getServiceReference(context, (char *)CALCULATOR2_SERVICE, &calcRef);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+ CHECK(calcRef != NULL);
+
+ rc = bundleContext_getService(context, calcRef, (void **)&calc);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+ }
+
+ static void teardownFm(void) {
+ int rc = 0;
+ rc = bundleContext_ungetService(context, rsaRef, NULL);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ rc = bundleContext_ungetServiceReference(context, rsaRef);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ rc = bundleContext_ungetService(context, calcRef, NULL);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ rc = bundleContext_ungetServiceReference(context, calcRef);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ celixLauncher_stop(framework);
+ celixLauncher_waitForShutdown(framework);
+ celixLauncher_destroy(framework);
+
+ rsaRef = NULL;
+ rsa = NULL;
+ calcRef = NULL;
+ calc = NULL;
+ context = NULL;
+ framework = NULL;
+ }
+
+ static void testServices(void) {
+ int rc = 0;
+ array_list_pt exported = NULL;
+ array_list_pt imported = NULL;
+ arrayList_create(&exported);
+ arrayList_create(&imported);
+
+ rc = rsa->getExportedServices(rsa->admin, &exported);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+ CHECK_EQUAL(0, arrayList_size(exported));
+
+ rc = rsa->getImportedEndpoints(rsa->admin, &imported);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+ CHECK_EQUAL(0, arrayList_size(imported));
+
+ double result = 0;
+ rc = calc->add(calc->calculator, 2.0, 5.0, &result);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+ CHECK_EQUAL(7.0, result);
+
+ arrayList_destroy(imported);
+ arrayList_destroy(exported);
+ }
+
+ static void testExportService(void) {
+ int rc = 0;
+ const char *calcId = NULL;
+ array_list_pt regs = NULL;
+
+ rc = serviceReference_getProperty(calcRef, (char *)"service.id", &calcId);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ rc = rsa->exportService(rsa->admin, (char*)calcId, NULL, ®s);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ CHECK_EQUAL(1, arrayList_size(regs));
+
+ rc = rsa->exportRegistration_close(rsa->admin,(export_registration_pt)(arrayList_get(regs,0)));
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ }
+
+ static void testImportService(void) {
+ int rc = 0;
+ import_registration_pt reg = NULL;
+ endpoint_description_pt endpoint = NULL;
+
+ properties_pt props = properties_create();
+ properties_set(props, (char *)OSGI_RSA_ENDPOINT_SERVICE_ID, (char *)"42");
+ properties_set(props, (char *)OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42");
+ properties_set(props, (char *)OSGI_RSA_ENDPOINT_ID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42-42");
+ properties_set(props, (char *)OSGI_FRAMEWORK_OBJECTCLASS,(char *)"org.apache.celix.Example");
+ properties_set(props, (char *)"service.version",(char *)"1.0.0"); //TODO find out standard in osgi spec
+
+ rc = endpointDescription_create(props, &endpoint);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ rc = rsa->importService(rsa->admin, endpoint, ®);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+ CHECK(reg != NULL);
+
+ service_reference_pt ref = NULL;
+ rc = bundleContext_getServiceReference(context, (char *)"org.apache.celix.Example", &ref);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+ CHECK(ref != NULL);
+
+ rc = bundleContext_ungetServiceReference(context, ref);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ rc = endpointDescription_destroy(endpoint);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+ /* Cannot test. uses requesting bundles descriptor
+ void *service = NULL;
+ rc = bundleContext_getService(context, ref, &service);
+ CHECK_EQUAL(CELIX_SUCCESS, rc);
+ CHECK(service != NULL);
+ */
+ }
+
+ static void testBundles(void) {
+ array_list_pt bundles = NULL;
+
+ int rc = bundleContext_getBundles(context, &bundles);
+ CHECK_EQUAL(0, rc);
+ CHECK_EQUAL(3, arrayList_size(bundles)); //framework, rsa_dfi & calc
+
+ /*
+ int size = arrayList_size(bundles);
+ int i;
+ for (i = 0; i < size; i += 1) {
+ bundle_pt bundle = NULL;
+ module_pt module = NULL;
+ char *name = NULL;
+
+ bundle = (bundle_pt) arrayList_get(bundles, i);
+ bundle_getCurrentModule(bundle, &module);
+ module_getSymbolicName(module, &name);
+ printf("got bundle with symbolic name '%s'", name);
+ }*/
+
+ arrayList_destroy(bundles);
+ }
+
+}
+
+
+TEST_GROUP(RsaDfiTests) {
+ void setup() {
+ setupFm();
+ }
+
+ void teardown() {
+ teardownFm();
+ }
+};
+
+TEST(RsaDfiTests, InfoTest) {
+ testServices();
+}
+
+TEST(RsaDfiTests, ExportService) {
+ testExportService();
+}
+
+TEST(RsaDfiTests, ImportService) {
+ testImportService();
+}
+
+TEST(RsaDfiTests, TestBundles) {
+ testBundles();
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/test/src/run_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/test/src/run_tests.cpp b/remote_services/remote_service_admin_dfi/test/src/run_tests.cpp
new file mode 100644
index 0000000..b5fd502
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/test/src/run_tests.cpp
@@ -0,0 +1,25 @@
+/**
+ *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.
+ */
+
+#include <CppUTest/TestHarness.h>
+#include "CppUTest/CommandLineTestRunner.h"
+
+int main(int argc, char** argv) {
+ return RUN_ALL_TESTS(argc, argv);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/test/src/tst_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/test/src/tst_activator.c b/remote_services/remote_service_admin_dfi/test/src/tst_activator.c
new file mode 100644
index 0000000..3db38fb
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/test/src/tst_activator.c
@@ -0,0 +1,162 @@
+/**
+ *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.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <service_tracker_customizer.h>
+#include <service_tracker.h>
+
+#include "bundle_activator.h"
+#include "bundle_context.h"
+#include "service_registration.h"
+#include "service_reference.h"
+#include "celix_errno.h"
+
+#include "tst_service.h"
+#include "calculator_service.h"
+#include <unistd.h>
+
+
+struct activator {
+ bundle_context_pt context;
+ struct tst_service serv;
+ service_registration_pt reg;
+
+ service_tracker_customizer_pt cust;
+ service_tracker_pt tracker;
+ calculator_service_pt calc;
+};
+
+static celix_status_t addCalc(void * handle, service_reference_pt reference, void * service);
+static celix_status_t removeCalc(void * handle, service_reference_pt reference, void * service);
+static int test(void *handle);
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **out) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *act = calloc(1, sizeof(*act));
+ if (act != NULL) {
+ act->context = context;
+ act->serv.handle = act;
+ act->serv.test = test;
+
+ status = serviceTrackerCustomizer_create(act, NULL, addCalc, NULL, removeCalc, &act->cust);
+ status = CELIX_DO_IF(status, serviceTracker_create(context, CALCULATOR2_SERVICE, act->cust, &act->tracker));
+
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *out = act;
+ } else if (act != NULL) {
+ if (act->cust != NULL) {
+ free(act->cust);
+ act->cust = NULL;
+ }
+ if (act->tracker != NULL) {
+ serviceTracker_destroy(act->tracker);
+ act->tracker = NULL;
+ }
+ free(act);
+ }
+
+ return CELIX_SUCCESS;
+}
+
+static celix_status_t addCalc(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator * act = handle;
+ act->calc = service;
+ return status;
+}
+
+static celix_status_t removeCalc(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator * act = handle;
+ if (act->calc == service) {
+ act->calc = NULL;
+ }
+ return status;
+
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator * act = userData;
+
+ act->reg = NULL;
+ status = bundleContext_registerService(context, (char *)TST_SERVICE_NAME, &act->serv, NULL, &act->reg);
+
+ status = CELIX_DO_IF(status, serviceTracker_open(act->tracker));
+
+
+ return status;
+}
+
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator * act = userData;
+
+ status = serviceRegistration_unregister(act->reg);
+ status = CELIX_DO_IF(status, serviceTracker_close(act->tracker));
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+ struct activator *act = userData;
+ if (act != NULL) {
+ if (act->tracker != NULL) {
+ serviceTracker_destroy(act->tracker);
+ act->tracker = NULL;
+ }
+ free(act);
+ }
+ return CELIX_SUCCESS;
+}
+
+static int test(void *handle) {
+ int status = 0;
+ struct activator *act = handle;
+
+ double result = -1.0;
+
+ int retries = 40;
+
+ while (act->calc == NULL) {
+ printf("Waiting for calc service .. %d\n", retries);
+ usleep(100000);
+ --retries;
+ }
+
+ int rc = 1;
+ if (act->calc != NULL) {
+ rc = act->calc->sqrt(act->calc->calculator, 4, &result);
+ printf("calc result is %f\n", result);
+ } else {
+ printf("calc not ready\n");
+ }
+
+ if (rc != 0 || result != 2.0) {
+ status = 1;
+ }
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/test/src/tst_service.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/test/src/tst_service.h b/remote_services/remote_service_admin_dfi/test/src/tst_service.h
new file mode 100644
index 0000000..c8ca2e7
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/test/src/tst_service.h
@@ -0,0 +1,32 @@
+/**
+ *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.
+ */
+
+#ifndef CELIX_TST_SERVICE_H
+#define CELIX_TST_SERVICE_H
+
+#define TST_SERVICE_NAME "tst_service"
+
+struct tst_service {
+ void *handle;
+ int (*test)(void *handle);
+};
+
+typedef struct tst_service *tst_service_pt;
+
+#endif //CELIX_TST_SERVICE_H
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/topology_manager/src/topology_manager.h
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/src/topology_manager.h b/remote_services/topology_manager/src/topology_manager.h
index 7e5e917..b6ee064 100644
--- a/remote_services/topology_manager/src/topology_manager.h
+++ b/remote_services/topology_manager/src/topology_manager.h
@@ -35,6 +35,7 @@
#define OSGI_RSA_REMOTE_SERVICE_ADMIN "remote_service_admin"
+typedef struct topology_manager topology_manager_t;
typedef struct topology_manager *topology_manager_pt;
celix_status_t topologyManager_create(bundle_context_pt context, log_helper_pt logHelper, topology_manager_pt *manager, void **scope);
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/topology_manager/tms_tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/tms_tst/CMakeLists.txt b/remote_services/topology_manager/tms_tst/CMakeLists.txt
index 6d0713c..5e27139 100644
--- a/remote_services/topology_manager/tms_tst/CMakeLists.txt
+++ b/remote_services/topology_manager/tms_tst/CMakeLists.txt
@@ -37,9 +37,18 @@ add_executable(test_tm_scoped
run_tests.cpp
tms_tests.cpp
)
-target_link_libraries(test_tm_scoped Celix::framework ${CPPUTEST_LIBRARY} ${JANSSON_LIBRARY} Celix::log_helper remote_service_admin_common)
+target_include_directories(test_tm_scoped PRIVATE ../src ../include)
+target_link_libraries(test_tm_scoped PRIVATE
+ Celix::framework
+ ${CPPUTEST_LIBRARY}
+ ${JANSSON_LIBRARY}
+ Celix::log_helper
+ calculator_api
+ Celix::remote_service_admin_api
+ Celix::remote_service_admin_common
+)
-add_dependencies(test_tm_scoped remote_service_admin_dfi topology_manager calculator)
+add_dependencies(test_tm_scoped remote_service_admin_dfi_bundle topology_manager_bundle)
file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/config.properties"
@@ -57,13 +66,6 @@ LOGHELPER_ENABLE_STDOUT_FALLBACK=true
org.osgi.framework.storage.clean=onFirstInit
")
-
-#TODO improve copy commands, for now using configure_file as copy
-#add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scope.json" COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURE_DIR}/scope.json" "${CMAKE_CURRENT_BINARY_DIR}/scope.json")
-#add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scope2.json" COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURE_DIR}/scope2.json" "${CMAKE_CURRENT_BINARY_DIR}/scope2.json")
-#add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scope3.json" COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURE_DIR}/scope3.json" "${CMAKE_CURRENT_BINARY_DIR}/scope3.json")
-#add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scope4.json" COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURE_DIR}/scope4.json" "${CMAKE_CURRENT_BINARY_DIR}/scope4.json")
-
configure_file("scope.json" "scope.json")
configure_file("scope2.json" "scope2.json")
configure_file("scope3.json" "scope3.json")
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt b/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
index fc9d9bf..551995b 100644
--- a/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
+++ b/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
@@ -32,4 +32,4 @@ bundle_files(topology_manager_test_bundle
DESTINATION .
)
-target_link_libraries(topology_manager_test_bundle PRIVATE ${CPPUTEST_LIBRARY} remote_service_admin calculator_api)
+target_link_libraries(topology_manager_test_bundle PRIVATE ${CPPUTEST_LIBRARY} Celix::remote_service_admin_api calculator_api)
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt b/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt
index bfd7fc1..653b69c 100644
--- a/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt
+++ b/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt
@@ -20,7 +20,9 @@ add_bundle(topology_manager_disc_mock_bundle
SOURCES
disc_mock_activator.c
disc_mock_service.c
-
)
-target_include_directories(topology_manager_disc_mock_bundle PRIVATE ${CPPUTEST_INCLUDE_DIR})
-target_link_libraries(topology_manager_disc_mock_bundle PRIVATE ${CPPUTEST_LIBRARY} Celix::framework discovery_common)
+target_include_directories(topology_manager_disc_mock_bundle PRIVATE
+ ${CPPUTEST_INCLUDE_DIR}
+ $<TARGET_PROPERTY:discovery_common,INCLUDE_DIRECTORIES>
+)
+target_link_libraries(topology_manager_disc_mock_bundle PRIVATE ${CPPUTEST_LIBRARY} Celix::framework)
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/topology_manager/tms_tst/disc_mock/disc_mock_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/tms_tst/disc_mock/disc_mock_activator.c b/remote_services/topology_manager/tms_tst/disc_mock/disc_mock_activator.c
index 53fccd7..d07ce02 100644
--- a/remote_services/topology_manager/tms_tst/disc_mock/disc_mock_activator.c
+++ b/remote_services/topology_manager/tms_tst/disc_mock/disc_mock_activator.c
@@ -29,7 +29,6 @@
#include "celix_errno.h"
#include "disc_mock_service.h"
-#include "discovery.h"
#include "constants.h"
#include "remote_constants.h"
[23/54] [abbrv] celix git commit: CELIX-417: Refactors CMake usage
for the RSA bundles
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_common/src/civetweb.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/src/civetweb.c b/remote_services/discovery_common/src/civetweb.c
deleted file mode 100644
index a6093b7..0000000
--- a/remote_services/discovery_common/src/civetweb.c
+++ /dev/null
@@ -1,7907 +0,0 @@
- /* Copyright (c) 2013-2015 the Civetweb developers
- * Copyright (c) 2004-2013 Sergey Lyubka
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#if defined(_WIN32)
-#if !defined(_CRT_SECURE_NO_WARNINGS)
-#define _CRT_SECURE_NO_WARNINGS /* Disable deprecation warning in VS2005 */
-#endif
-#else
-#ifdef __linux__
-#define _XOPEN_SOURCE 600 /* For flockfile() on Linux */
-#endif
-#ifndef _LARGEFILE_SOURCE
-#define _LARGEFILE_SOURCE /* For fseeko(), ftello() */
-#endif
-#ifndef _FILE_OFFSET_BITS
-#define _FILE_OFFSET_BITS 64 /* Use 64-bit file offsets by default */
-#endif
-#ifndef __STDC_FORMAT_MACROS
-#define __STDC_FORMAT_MACROS /* <inttypes.h> wants this for C++ */
-#endif
-#ifndef __STDC_LIMIT_MACROS
-#define __STDC_LIMIT_MACROS /* C++ wants that for INT64_MAX */
-#endif
-#endif
-
-#if defined (_MSC_VER)
-/* 'type cast' : conversion from 'int' to 'HANDLE' of greater size */
-#pragma warning (disable : 4306 )
-/* conditional expression is constant: introduced by FD_SET(..) */
-#pragma warning (disable : 4127)
-/* non-constant aggregate initializer: issued due to missing C99 support */
-#pragma warning (disable : 4204)
-#endif
-
-/* Disable WIN32_LEAN_AND_MEAN.
- This makes windows.h always include winsock2.h */
-#if defined(WIN32_LEAN_AND_MEAN)
-#undef WIN32_LEAN_AND_MEAN
-#endif
-
-#if defined USE_IPV6 && defined(_WIN32)
-#include <ws2tcpip.h>
-#endif
-
-#if defined(__SYMBIAN32__)
-#define NO_SSL /* SSL is not supported */
-#define NO_CGI /* CGI is not supported */
-#define PATH_MAX FILENAME_MAX
-#endif /* __SYMBIAN32__ */
-
-#ifndef IGNORE_UNUSED_RESULT
-#define IGNORE_UNUSED_RESULT(a) (void)((a) && 1)
-#endif
-
-#ifndef _WIN32_WCE /* Some ANSI #includes are not available on Windows CE */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <signal.h>
-#include <fcntl.h>
-#endif /* !_WIN32_WCE */
-
-#include <time.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <assert.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-#include <stddef.h>
-#include <stdio.h>
-
-#ifndef MAX_WORKER_THREADS
-#define MAX_WORKER_THREADS (1024*64)
-#endif
-
-#if defined(_WIN32) && !defined(__SYMBIAN32__) /* Windows specific */
-#if defined(_MSC_VER) && _MSC_VER <= 1400
-#undef _WIN32_WINNT
-#define _WIN32_WINNT 0x0400 /* To make it link in VS2005 */
-#endif
-#include <windows.h>
-typedef const char * SOCK_OPT_TYPE;
-
-#ifndef PATH_MAX
-#define PATH_MAX MAX_PATH
-#endif
-
-#ifndef _IN_PORT_T
-#ifndef in_port_t
-#define in_port_t u_short
-#endif
-#endif
-
-#ifndef _WIN32_WCE
-#include <process.h>
-#include <direct.h>
-#include <io.h>
-#else /* _WIN32_WCE */
-#define NO_CGI /* WinCE has no pipes */
-
-typedef long off_t;
-
-#define errno GetLastError()
-#define strerror(x) _ultoa(x, (char *) _alloca(sizeof(x) *3 ), 10)
-#endif /* _WIN32_WCE */
-
-#define MAKEUQUAD(lo, hi) ((uint64_t)(((uint32_t)(lo)) | \
- ((uint64_t)((uint32_t)(hi))) << 32))
-#define RATE_DIFF 10000000 /* 100 nsecs */
-#define EPOCH_DIFF MAKEUQUAD(0xd53e8000, 0x019db1de)
-#define SYS2UNIX_TIME(lo, hi) \
- (time_t) ((MAKEUQUAD((lo), (hi)) - EPOCH_DIFF) / RATE_DIFF)
-
-/* Visual Studio 6 does not know __func__ or __FUNCTION__
- The rest of MS compilers use __FUNCTION__, not C99 __func__
- Also use _strtoui64 on modern M$ compilers */
-#if defined(_MSC_VER) && _MSC_VER < 1300
-#define STRX(x) #x
-#define STR(x) STRX(x)
-#define __func__ __FILE__ ":" STR(__LINE__)
-#define strtoull(x, y, z) (unsigned __int64) _atoi64(x)
-#define strtoll(x, y, z) _atoi64(x)
-#else
-#define __func__ __FUNCTION__
-#define strtoull(x, y, z) _strtoui64(x, y, z)
-#define strtoll(x, y, z) _strtoi64(x, y, z)
-#endif /* _MSC_VER */
-
-#define ERRNO GetLastError()
-#define NO_SOCKLEN_T
-#define SSL_LIB "ssleay32.dll"
-#define CRYPTO_LIB "libeay32.dll"
-#define O_NONBLOCK 0
-#define W_OK (2) /* http://msdn.microsoft.com/en-us/library/1w06ktdy.aspx */
-#if !defined(EWOULDBLOCK)
-#define EWOULDBLOCK WSAEWOULDBLOCK
-#endif /* !EWOULDBLOCK */
-#define _POSIX_
-#define INT64_FMT "I64d"
-
-#define WINCDECL __cdecl
-#define SHUT_WR 1
-#define snprintf _snprintf
-#define vsnprintf _vsnprintf
-#define access _access
-#define mg_sleep(x) Sleep(x)
-
-#define pipe(x) _pipe(x, MG_BUF_LEN, _O_BINARY)
-#ifndef popen
-#define popen(x, y) _popen(x, y)
-#endif
-#ifndef pclose
-#define pclose(x) _pclose(x)
-#endif
-#define close(x) _close(x)
-#define dlsym(x,y) GetProcAddress((HINSTANCE) (x), (y))
-#define RTLD_LAZY 0
-#define fseeko(x, y, z) _lseeki64(_fileno(x), (y), (z))
-#define fdopen(x, y) _fdopen((x), (y))
-#define write(x, y, z) _write((x), (y), (unsigned) z)
-#define read(x, y, z) _read((x), (y), (unsigned) z)
-#define flockfile(x) EnterCriticalSection(&global_log_file_lock)
-#define funlockfile(x) LeaveCriticalSection(&global_log_file_lock)
-#define sleep(x) Sleep((x) * 1000)
-#define rmdir(x) _rmdir(x)
-
-#if defined(USE_LUA) && defined(USE_WEBSOCKET)
-#define USE_TIMERS
-#endif
-
-#if !defined(va_copy)
-#define va_copy(x, y) x = y
-#endif /* !va_copy MINGW #defines va_copy */
-
-#if !defined(fileno)
-#define fileno(x) _fileno(x)
-#endif /* !fileno MINGW #defines fileno */
-
-typedef HANDLE pthread_mutex_t;
-typedef DWORD pthread_key_t;
-typedef HANDLE pthread_t;
-typedef struct {
- CRITICAL_SECTION threadIdSec;
- int waitingthreadcount; /* The number of threads queued. */
- pthread_t *waitingthreadhdls; /* The thread handles. */
-} pthread_cond_t;
-
-#ifndef __clockid_t_defined
-typedef DWORD clockid_t;
-#endif
-#ifndef CLOCK_MONOTONIC
-#define CLOCK_MONOTONIC (1)
-#endif
-#ifndef CLOCK_REALTIME
-#define CLOCK_REALTIME (2)
-#endif
-
-#ifndef _TIMESPEC_DEFINED
-struct timespec {
- time_t tv_sec; /* seconds */
- long tv_nsec; /* nanoseconds */
-};
-#endif
-
-#define pid_t HANDLE /* MINGW typedefs pid_t to int. Using #define here. */
-
-static int pthread_mutex_lock(pthread_mutex_t *);
-static int pthread_mutex_unlock(pthread_mutex_t *);
-static void to_unicode(const char *path, wchar_t *wbuf, size_t wbuf_len);
-struct file;
-static char *mg_fgets(char *buf, size_t size, struct file *filep, char **p);
-
-#if defined(HAVE_STDINT)
-#include <stdint.h>
-#else
-typedef unsigned int uint32_t;
-typedef unsigned short uint16_t;
-typedef unsigned __int64 uint64_t;
-typedef __int64 int64_t;
-#define INT64_MAX 9223372036854775807
-#endif /* HAVE_STDINT */
-
-/* POSIX dirent interface */
-struct dirent {
- char d_name[PATH_MAX];
-};
-
-typedef struct DIR {
- HANDLE handle;
- WIN32_FIND_DATAW info;
- struct dirent result;
-} DIR;
-
-#if !defined(USE_IPV6) && defined(_WIN32)
-#ifndef HAVE_POLL
-struct pollfd {
- SOCKET fd;
- short events;
- short revents;
-};
-#define POLLIN 1
-#endif
-#endif
-
-/* Mark required libraries */
-#ifdef _MSC_VER
-#pragma comment(lib, "Ws2_32.lib")
-#endif
-
-#else /* UNIX specific */
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <sys/poll.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/time.h>
-#include <sys/utsname.h>
-#include <stdint.h>
-#include <inttypes.h>
-#include <netdb.h>
-typedef const void * SOCK_OPT_TYPE;
-
-//#if defined(ANDROID)
-typedef unsigned short int in_port_t;
-//#endif
-
-#include <pwd.h>
-#include <unistd.h>
-#include <dirent.h>
-#if !defined(NO_SSL_DL) && !defined(NO_SSL)
-#include <dlfcn.h>
-#endif
-#include <pthread.h>
-#if defined(__MACH__)
-#define SSL_LIB "libssl.dylib"
-#define CRYPTO_LIB "libcrypto.dylib"
-#else
-#if !defined(SSL_LIB)
-#define SSL_LIB "libssl.so"
-#endif
-#if !defined(CRYPTO_LIB)
-#define CRYPTO_LIB "libcrypto.so"
-#endif
-#endif
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif /* O_BINARY */
-#define closesocket(a) close(a)
-#define mg_mkdir(x, y) mkdir(x, y)
-#define mg_remove(x) remove(x)
-#define mg_sleep(x) usleep((x) * 1000)
-#define ERRNO errno
-#define INVALID_SOCKET (-1)
-#define INT64_FMT PRId64
-typedef int SOCKET;
-#define WINCDECL
-
-#endif /* End of Windows and UNIX specific includes */
-
-#ifdef _WIN32
-static CRITICAL_SECTION global_log_file_lock;
-static DWORD pthread_self(void)
-{
- return GetCurrentThreadId();
-}
-
-int pthread_key_create(pthread_key_t *key, void (*_must_be_zero)(void*) /* destructor function not supported for windows */)
-{
- assert(_must_be_zero == NULL);
- if ((key!=0) && (_must_be_zero == NULL)) {
- *key = TlsAlloc();
- return (*key != TLS_OUT_OF_INDEXES) ? 0 : -1;
- }
- return -2;
-}
-
-int pthread_key_delete(pthread_key_t key)
-{
- return TlsFree(key) ? 0 : 1;
-}
-
-int pthread_setspecific(pthread_key_t key, void * value)
-{
- return TlsSetValue(key, value) ? 0 : 1;
-}
-
-void *pthread_getspecific(pthread_key_t key)
-{
- return TlsGetValue(key);
-}
-#endif /* _WIN32 */
-
-
-#include "civetweb.h"
-
-#define PASSWORDS_FILE_NAME ".htpasswd"
-#define CGI_ENVIRONMENT_SIZE 4096
-#define MAX_CGI_ENVIR_VARS 64
-#define MG_BUF_LEN 8192
-#ifndef MAX_REQUEST_SIZE
-#define MAX_REQUEST_SIZE 16384
-#endif
-#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
-
-#if !defined(DEBUG_TRACE)
-#if defined(CWDEBUG)
-
-static void DEBUG_TRACE_FUNC(const char *func, unsigned line, PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(3, 4);
-
-static void DEBUG_TRACE_FUNC(const char *func, unsigned line, const char *fmt, ...) {
-
- va_list args;
- flockfile(stdout);
- printf("*** %lu.%p.%s.%u: ",
- (unsigned long) time(NULL), (void *) pthread_self(),
- func, line);
- va_start(args, fmt);
- vprintf(fmt, args);
- va_end(args);
- putchar('\n');
- fflush(stdout);
- funlockfile(stdout);
-}
-
-#define DEBUG_TRACE(fmt, ...) DEBUG_TRACE_FUNC(__func__, __LINE__, fmt, __VA_ARGS__)
-
-#else
-#define DEBUG_TRACE(fmt, ...)
-#endif /* CWDEBUG */
-#endif /* DEBUG_TRACE */
-
-#if defined(MEMORY_DEBUGGING)
-static unsigned long blockCount = 0;
-static unsigned long totalMemUsed = 0;
-
-static void * mg_malloc_ex(size_t size, const char * file, unsigned line) {
-
- void * data = malloc(size + sizeof(size_t));
- void * memory = 0;
- char mallocStr[256];
-
- if (data) {
- *(size_t*)data = size;
- totalMemUsed += size;
- blockCount++;
- memory = (void *)(((char*)data)+sizeof(size_t));
- }
-
- sprintf(mallocStr, "MEM: %p %5lu alloc %7lu %4lu --- %s:%u\n", memory, (unsigned long)size, totalMemUsed, blockCount, file, line);
-#if defined(_WIN32)
- OutputDebugStringA(mallocStr);
-#else
- DEBUG_TRACE("%s", mallocStr);
-#endif
-
- return memory;
-}
-
-static void * mg_calloc_ex(size_t count, size_t size, const char * file, unsigned line) {
-
- void * data = mg_malloc_ex(size*count, file, line);
- if (data) memset(data, 0, size);
-
- return data;
-}
-
-static void mg_free_ex(void * memory, const char * file, unsigned line) {
-
- char mallocStr[256];
- void * data = (void *)(((char*)memory)-sizeof(size_t));
- size_t size;
-
- if (memory) {
- size = *(size_t*)data;
- totalMemUsed -= size;
- blockCount--;
- sprintf(mallocStr, "MEM: %p %5lu free %7lu %4lu --- %s:%u\n", memory, (unsigned long)size, totalMemUsed, blockCount, file, line);
-#if defined(_WIN32)
- OutputDebugStringA(mallocStr);
-#else
- DEBUG_TRACE("%s", mallocStr);
-#endif
-
- free(data);
- }
-}
-
-static void * mg_realloc_ex(void * memory, size_t newsize, const char * file, unsigned line) {
-
- char mallocStr[256];
- void * data;
- void * _realloc;
- size_t oldsize;
-
- if (newsize) {
- if (memory) {
- data = (void *)(((char*)memory)-sizeof(size_t));
- oldsize = *(size_t*)data;
- _realloc = realloc(data, newsize+sizeof(size_t));
- if (_realloc) {
- data = _realloc;
- totalMemUsed -= oldsize;
- sprintf(mallocStr, "MEM: %p %5lu r-free %7lu %4lu --- %s:%u\n", memory, (unsigned long)oldsize, totalMemUsed, blockCount, file, line);
-#if defined(_WIN32)
- OutputDebugStringA(mallocStr);
-#else
- DEBUG_TRACE("%s", mallocStr);
-#endif
- totalMemUsed += newsize;
- sprintf(mallocStr, "MEM: %p %5lu r-alloc %7lu %4lu --- %s:%u\n", memory, (unsigned long)newsize, totalMemUsed, blockCount, file, line);
-#if defined(_WIN32)
- OutputDebugStringA(mallocStr);
-#else
- DEBUG_TRACE("%s", mallocStr);
-#endif
- *(size_t*)data = newsize;
- data = (void *)(((char*)data)+sizeof(size_t));
- } else {
-#if defined(_WIN32)
- OutputDebugStringA("MEM: realloc failed\n");
-#else
- DEBUG_TRACE("%s", "MEM: realloc failed\n");
-#endif
- return _realloc;
- }
- } else {
- data = mg_malloc_ex(newsize, file, line);
- }
- } else {
- data = 0;
- mg_free_ex(memory, file, line);
- }
-
- return data;
-}
-
-#define mg_malloc(a) mg_malloc_ex(a, __FILE__, __LINE__)
-#define mg_calloc(a,b) mg_calloc_ex(a, b, __FILE__, __LINE__)
-#define mg_realloc(a, b) mg_realloc_ex(a, b, __FILE__, __LINE__)
-#define mg_free(a) mg_free_ex(a, __FILE__, __LINE__)
-
-#else
-static __inline void * mg_malloc(size_t a) {return malloc(a);}
-static __inline void * mg_calloc(size_t a, size_t b) {return calloc(a, b);}
-static __inline void * mg_realloc(void * a, size_t b) {return realloc(a, b);}
-static __inline void mg_free(void * a) {free(a);}
-#endif
-
-/* This following lines are just meant as a reminder to use the mg-functions for memory management */
-#ifdef malloc
- #undef malloc
-#endif
-#ifdef calloc
- #undef calloc
-#endif
-#ifdef realloc
- #undef realloc
-#endif
-#ifdef free
- #undef free
-#endif
-#define malloc DO_NOT_USE_THIS_FUNCTION__USE_mg_malloc
-#define calloc DO_NOT_USE_THIS_FUNCTION__USE_mg_calloc
-#define realloc DO_NOT_USE_THIS_FUNCTION__USE_mg_realloc
-#define free DO_NOT_USE_THIS_FUNCTION__USE_mg_free
-
-
-#define MD5_STATIC static
-#include "md5.inl"
-
-/* Darwin prior to 7.0 and Win32 do not have socklen_t */
-#ifdef NO_SOCKLEN_T
-typedef int socklen_t;
-#endif /* NO_SOCKLEN_T */
-#define _DARWIN_UNLIMITED_SELECT
-
-#define IP_ADDR_STR_LEN 50 /* IPv6 hex string is 46 chars */
-
-#if !defined(MSG_NOSIGNAL)
-#define MSG_NOSIGNAL 0
-#endif
-
-#if !defined(SOMAXCONN)
-#define SOMAXCONN 100
-#endif
-
-#if !defined(PATH_MAX)
-#define PATH_MAX 4096
-#endif
-
-/* Size of the accepted socket queue */
-#if !defined(MGSQLEN)
-#define MGSQLEN 20
-#endif
-
-#if defined(NO_SSL_DL)
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#else
-/* SSL loaded dynamically from DLL.
- I put the prototypes here to be independent from OpenSSL source
- installation. */
-
-typedef struct ssl_st SSL;
-typedef struct ssl_method_st SSL_METHOD;
-typedef struct ssl_ctx_st SSL_CTX;
-
-struct ssl_func {
- const char *name; /* SSL function name */
- void (*ptr)(void); /* Function pointer */
-};
-
-#define SSL_free (* (void (*)(SSL *)) ssl_sw[0].ptr)
-#define SSL_accept (* (int (*)(SSL *)) ssl_sw[1].ptr)
-#define SSL_connect (* (int (*)(SSL *)) ssl_sw[2].ptr)
-#define SSL_read (* (int (*)(SSL *, void *, int)) ssl_sw[3].ptr)
-#define SSL_write (* (int (*)(SSL *, const void *,int)) ssl_sw[4].ptr)
-#define SSL_get_error (* (int (*)(SSL *, int)) ssl_sw[5].ptr)
-#define SSL_set_fd (* (int (*)(SSL *, SOCKET)) ssl_sw[6].ptr)
-#define SSL_new (* (SSL * (*)(SSL_CTX *)) ssl_sw[7].ptr)
-#define SSL_CTX_new (* (SSL_CTX * (*)(SSL_METHOD *)) ssl_sw[8].ptr)
-#define SSLv23_server_method (* (SSL_METHOD * (*)(void)) ssl_sw[9].ptr)
-#define SSL_library_init (* (int (*)(void)) ssl_sw[10].ptr)
-#define SSL_CTX_use_PrivateKey_file (* (int (*)(SSL_CTX *, \
- const char *, int)) ssl_sw[11].ptr)
-#define SSL_CTX_use_certificate_file (* (int (*)(SSL_CTX *, \
- const char *, int)) ssl_sw[12].ptr)
-#define SSL_CTX_set_default_passwd_cb \
- (* (void (*)(SSL_CTX *, mg_callback_t)) ssl_sw[13].ptr)
-#define SSL_CTX_free (* (void (*)(SSL_CTX *)) ssl_sw[14].ptr)
-#define SSL_load_error_strings (* (void (*)(void)) ssl_sw[15].ptr)
-#define SSL_CTX_use_certificate_chain_file \
- (* (int (*)(SSL_CTX *, const char *)) ssl_sw[16].ptr)
-#define SSLv23_client_method (* (SSL_METHOD * (*)(void)) ssl_sw[17].ptr)
-#define SSL_pending (* (int (*)(SSL *)) ssl_sw[18].ptr)
-#define SSL_CTX_set_verify (* (void (*)(SSL_CTX *, int, int)) ssl_sw[19].ptr)
-#define SSL_shutdown (* (int (*)(SSL *)) ssl_sw[20].ptr)
-
-#define CRYPTO_num_locks (* (int (*)(void)) crypto_sw[0].ptr)
-#define CRYPTO_set_locking_callback \
- (* (void (*)(void (*)(int, int, const char *, int))) crypto_sw[1].ptr)
-#define CRYPTO_set_id_callback \
- (* (void (*)(unsigned long (*)(void))) crypto_sw[2].ptr)
-#define ERR_get_error (* (unsigned long (*)(void)) crypto_sw[3].ptr)
-#define ERR_error_string (* (char * (*)(unsigned long,char *)) crypto_sw[4].ptr)
-
-/* set_ssl_option() function updates this array.
- It loads SSL library dynamically and changes NULLs to the actual addresses
- of respective functions. The macros above (like SSL_connect()) are really
- just calling these functions indirectly via the pointer. */
-static struct ssl_func ssl_sw[] = {
- {"SSL_free", NULL},
- {"SSL_accept", NULL},
- {"SSL_connect", NULL},
- {"SSL_read", NULL},
- {"SSL_write", NULL},
- {"SSL_get_error", NULL},
- {"SSL_set_fd", NULL},
- {"SSL_new", NULL},
- {"SSL_CTX_new", NULL},
- {"SSLv23_server_method", NULL},
- {"SSL_library_init", NULL},
- {"SSL_CTX_use_PrivateKey_file", NULL},
- {"SSL_CTX_use_certificate_file",NULL},
- {"SSL_CTX_set_default_passwd_cb",NULL},
- {"SSL_CTX_free", NULL},
- {"SSL_load_error_strings", NULL},
- {"SSL_CTX_use_certificate_chain_file", NULL},
- {"SSLv23_client_method", NULL},
- {"SSL_pending", NULL},
- {"SSL_CTX_set_verify", NULL},
- {"SSL_shutdown", NULL},
- {NULL, NULL}
-};
-
-/* Similar array as ssl_sw. These functions could be located in different
- lib. */
-#if !defined(NO_SSL)
-static struct ssl_func crypto_sw[] = {
- {"CRYPTO_num_locks", NULL},
- {"CRYPTO_set_locking_callback", NULL},
- {"CRYPTO_set_id_callback", NULL},
- {"ERR_get_error", NULL},
- {"ERR_error_string", NULL},
- {NULL, NULL}
-};
-#endif /* NO_SSL */
-#endif /* NO_SSL_DL */
-
-static const char *month_names[] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-
-/* Unified socket address. For IPv6 support, add IPv6 address structure
- in the union u. */
-union usa {
- struct sockaddr sa;
- struct sockaddr_in sin;
-#if defined(USE_IPV6)
- struct sockaddr_in6 sin6;
-#endif
-};
-
-/* Describes a string (chunk of memory). */
-struct vec {
- const char *ptr;
- size_t len;
-};
-
-struct file {
- int is_directory;
- time_t modification_time;
- int64_t size;
- FILE *fp;
- const char *membuf; /* Non-NULL if file data is in memory */
- /* set to 1 if the content is gzipped
- in which case we need a content-encoding: gzip header */
- int gzipped;
-};
-#define STRUCT_FILE_INITIALIZER {0, 0, 0, NULL, NULL, 0}
-
-/* Describes listening socket, or socket which was accept()-ed by the master
- thread and queued for future handling by the worker thread. */
-struct socket {
- SOCKET sock; /* Listening socket */
- union usa lsa; /* Local socket address */
- union usa rsa; /* Remote socket address */
- unsigned is_ssl:1; /* Is port SSL-ed */
- unsigned ssl_redir:1; /* Is port supposed to redirect everything to SSL
- port */
-};
-
-/* NOTE(lsm): this enum shoulds be in sync with the config_options below. */
-enum {
- CGI_EXTENSIONS, CGI_ENVIRONMENT, PUT_DELETE_PASSWORDS_FILE, CGI_INTERPRETER,
- PROTECT_URI, AUTHENTICATION_DOMAIN, SSI_EXTENSIONS, THROTTLE,
- ACCESS_LOG_FILE, ENABLE_DIRECTORY_LISTING, ERROR_LOG_FILE,
- GLOBAL_PASSWORDS_FILE, INDEX_FILES, ENABLE_KEEP_ALIVE, ACCESS_CONTROL_LIST,
- EXTRA_MIME_TYPES, LISTENING_PORTS, DOCUMENT_ROOT, SSL_CERTIFICATE,
- NUM_THREADS, RUN_AS_USER, REWRITE, HIDE_FILES, REQUEST_TIMEOUT,
- DECODE_URL,
-
-#if defined(USE_LUA)
- LUA_PRELOAD_FILE, LUA_SCRIPT_EXTENSIONS, LUA_SERVER_PAGE_EXTENSIONS,
-#endif
-#if defined(USE_WEBSOCKET)
- WEBSOCKET_ROOT,
-#endif
-#if defined(USE_LUA) && defined(USE_WEBSOCKET)
- LUA_WEBSOCKET_EXTENSIONS,
-#endif
- ACCESS_CONTROL_ALLOW_ORIGIN, ERROR_PAGES,
-
- NUM_OPTIONS
-};
-
-/* Config option name, config types, default value */
-static struct mg_option config_options[] = {
- {"cgi_pattern", CONFIG_TYPE_EXT_PATTERN, "**.cgi$|**.pl$|**.php$"},
- {"cgi_environment", CONFIG_TYPE_STRING, NULL},
- {"put_delete_auth_file", CONFIG_TYPE_FILE, NULL},
- {"cgi_interpreter", CONFIG_TYPE_FILE, NULL},
- {"protect_uri", CONFIG_TYPE_STRING, NULL},
- {"authentication_domain", CONFIG_TYPE_STRING, "mydomain.com"},
- {"ssi_pattern", CONFIG_TYPE_EXT_PATTERN, "**.shtml$|**.shtm$"},
- {"throttle", CONFIG_TYPE_STRING, NULL},
- {"access_log_file", CONFIG_TYPE_FILE, NULL},
- {"enable_directory_listing", CONFIG_TYPE_BOOLEAN, "yes"},
- {"error_log_file", CONFIG_TYPE_FILE, NULL},
- {"global_auth_file", CONFIG_TYPE_FILE, NULL},
- {"index_files", CONFIG_TYPE_STRING,
-#ifdef USE_LUA
- "index.xhtml,index.html,index.htm,index.lp,index.lsp,index.lua,index.cgi,index.shtml,index.php"},
-#else
- "index.xhtml,index.html,index.htm,index.cgi,index.shtml,index.php"},
-#endif
- {"enable_keep_alive", CONFIG_TYPE_BOOLEAN, "no"},
- {"access_control_list", CONFIG_TYPE_STRING, NULL},
- {"extra_mime_types", CONFIG_TYPE_STRING, NULL},
- {"listening_ports", CONFIG_TYPE_STRING, "8080"},
- {"document_root", CONFIG_TYPE_DIRECTORY, NULL},
- {"ssl_certificate", CONFIG_TYPE_FILE, NULL},
- {"num_threads", CONFIG_TYPE_NUMBER, "50"},
- {"run_as_user", CONFIG_TYPE_STRING, NULL},
- {"url_rewrite_patterns", CONFIG_TYPE_STRING, NULL},
- {"hide_files_patterns", CONFIG_TYPE_EXT_PATTERN, NULL},
- {"request_timeout_ms", CONFIG_TYPE_NUMBER, "30000"},
- {"decode_url", CONFIG_TYPE_BOOLEAN, "yes"},
-
-#if defined(USE_LUA)
- {"lua_preload_file", CONFIG_TYPE_FILE, NULL},
- {"lua_script_pattern", CONFIG_TYPE_EXT_PATTERN, "**.lua$"},
- {"lua_server_page_pattern", CONFIG_TYPE_EXT_PATTERN, "**.lp$|**.lsp$"},
-#endif
-#if defined(USE_WEBSOCKET)
- {"websocket_root", CONFIG_TYPE_DIRECTORY, NULL},
-#endif
-#if defined(USE_LUA) && defined(USE_WEBSOCKET)
- {"lua_websocket_pattern", CONFIG_TYPE_EXT_PATTERN, "**.lua$"},
-#endif
- {"access_control_allow_origin", CONFIG_TYPE_STRING, "*"},
- {"error_pages", CONFIG_TYPE_DIRECTORY, NULL},
-
- {NULL, CONFIG_TYPE_UNKNOWN, NULL}
-};
-
-struct mg_request_handler_info {
- char *uri;
- size_t uri_len;
- mg_request_handler handler;
-
- void *cbdata;
- struct mg_request_handler_info *next;
-};
-
-struct mg_context {
- volatile int stop_flag; /* Should we stop event loop */
- SSL_CTX *ssl_ctx; /* SSL context */
- char *config[NUM_OPTIONS]; /* Civetweb configuration parameters */
- struct mg_callbacks callbacks; /* User-defined callback function */
- void *user_data; /* User-defined data */
- int context_type; /* 1 = server context, 2 = client context */
-
- struct socket *listening_sockets;
- in_port_t *listening_ports;
- int num_listening_sockets;
-
- volatile int num_threads; /* Number of threads */
- pthread_mutex_t thread_mutex; /* Protects (max|num)_threads */
- pthread_cond_t thread_cond; /* Condvar for tracking workers terminations */
-
- struct socket queue[MGSQLEN]; /* Accepted sockets */
- volatile int sq_head; /* Head of the socket queue */
- volatile int sq_tail; /* Tail of the socket queue */
- pthread_cond_t sq_full; /* Signaled when socket is produced */
- pthread_cond_t sq_empty; /* Signaled when socket is consumed */
- pthread_t masterthreadid; /* The master thread ID */
- int workerthreadcount; /* The amount of worker threads. */
- pthread_t *workerthreadids; /* The worker thread IDs */
-
- unsigned long start_time; /* Server start time, used for authentication */
- pthread_mutex_t nonce_mutex; /* Protects nonce_count */
- unsigned long nonce_count; /* Used nonces, used for authentication */
-
- char *systemName; /* What operating system is running */
-
- /* linked list of uri handlers */
- struct mg_request_handler_info *request_handlers;
-
-#if defined(USE_LUA) && defined(USE_WEBSOCKET)
- /* linked list of shared lua websockets */
- struct mg_shared_lua_websocket_list *shared_lua_websockets;
-#endif
-
-#ifdef USE_TIMERS
- struct ttimers * timers;
-#endif
-};
-
-struct mg_connection {
- struct mg_request_info request_info;
- struct mg_context *ctx;
- SSL *ssl; /* SSL descriptor */
- SSL_CTX *client_ssl_ctx; /* SSL context for client connections */
- struct socket client; /* Connected client */
- time_t birth_time; /* Time when request was received */
- int64_t num_bytes_sent; /* Total bytes sent to client */
- int64_t content_len; /* Content-Length header value */
- int64_t consumed_content; /* How many bytes of content have been read */
- char *buf; /* Buffer for received data */
- char *path_info; /* PATH_INFO part of the URL */
- int must_close; /* 1 if connection must be closed */
- int in_error_handler; /* 1 if in handler for user defined error pages */
- int buf_size; /* Buffer size */
- int request_len; /* Size of the request + headers in a buffer */
- int data_len; /* Total size of data in a buffer */
- int status_code; /* HTTP reply status code, e.g. 200 */
- int throttle; /* Throttling, bytes/sec. <= 0 means no throttle */
- time_t last_throttle_time; /* Last time throttled data was sent */
- int64_t last_throttle_bytes; /* Bytes sent this second */
- pthread_mutex_t mutex; /* Used by mg_lock_connection/mg_unlock_connection to ensure atomic transmissions for websockets */
-#if defined(USE_LUA) && defined(USE_WEBSOCKET)
- void * lua_websocket_state; /* Lua_State for a websocket connection */
-#endif
-};
-
-static pthread_key_t sTlsKey; /* Thread local storage index */
-static int sTlsInit = 0;
-
-struct mg_workerTLS {
- int is_master;
-#if defined(_WIN32) && !defined(__SYMBIAN32__)
- HANDLE pthread_cond_helper_mutex;
-#endif
-};
-
-/* Directory entry */
-struct de {
- struct mg_connection *conn;
- char *file_name;
- struct file file;
-};
-
-#if defined(USE_WEBSOCKET)
-static int is_websocket_protocol(const struct mg_connection *conn);
-#else
-#define is_websocket_protocol(conn) (0)
-#endif
-
-int mg_atomic_inc(volatile int * addr)
-{
- int ret;
-#if defined(_WIN32) && !defined(__SYMBIAN32__)
- ret = InterlockedIncrement((volatile unsigned int *) addr);
-#elif defined(__GNUC__)
- ret = __sync_add_and_fetch(addr, 1);
-#else
- ret = (++(*addr));
-#endif
- return ret;
-}
-
-int mg_atomic_dec(volatile int * addr)
-{
- int ret;
-#if defined(_WIN32) && !defined(__SYMBIAN32__)
- ret = InterlockedDecrement((volatile unsigned int *) addr);
-#elif defined(__GNUC__)
- ret = __sync_sub_and_fetch(addr, 1);
-#else
- ret = (--(*addr));
-#endif
- return ret;
-}
-
-#if !defined(NO_THREAD_NAME)
-#if defined(_WIN32) && defined(_MSC_VER)
-/* Set the thread name for debugging purposes in Visual Studio
- http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
-*/
-#pragma pack(push,8)
-typedef struct tagTHREADNAME_INFO
-{
- DWORD dwType; /* Must be 0x1000. */
- LPCSTR szName; /* Pointer to name (in user addr space). */
- DWORD dwThreadID; /* Thread ID (-1=caller thread). */
- DWORD dwFlags; /* Reserved for future use, must be zero. */
-} THREADNAME_INFO;
-#pragma pack(pop)
-#elif defined(__linux__)
-#include <sys/prctl.h>
-#endif
-
-void mg_set_thread_name(const char* name)
-{
- char threadName[16]; /* Max. thread length in Linux/OSX/.. */
-
- if (snprintf(threadName, sizeof(threadName), "civetweb-%s", name)<0) return;
- threadName[sizeof(threadName)-1] = 0;
-
-#if defined(_WIN32)
-#if defined(_MSC_VER)
- /* Windows and Visual Studio Compiler */
- __try
- {
- THREADNAME_INFO info;
- info.dwType = 0x1000;
- info.szName = threadName;
- info.dwThreadID = -1;
- info.dwFlags = 0;
-
- RaiseException(0x406D1388, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info);
- }
- __except(EXCEPTION_EXECUTE_HANDLER)
- {
- }
-#elif defined(__MINGW32__)
- /* No option known to set thread name for MinGW */
-#endif
-#elif defined(__linux__)
- /* Linux */
- (void)prctl(PR_SET_NAME,threadName,0,0,0);
-#elif defined(__APPLE__) || defined(__MACH__)
- /* OS X (TODO: test) */
- (void)pthread_setname_np(threadName);
-#elif defined(BSD) || defined(__FreeBSD__) || defined(__OpenBSD__)
- /* BSD (TODO: test) */
- pthread_set_name_np(pthread_self(), threadName);
-#else
- /* POSIX */
- (void)pthread_setname_np(pthread_self(), threadName);
-#endif
-}
-#else /* !defined(NO_THREAD_NAME) */
-void mg_set_thread_name(const char* threadName) {}
-#endif
-
-#if defined(MG_LEGACY_INTERFACE)
-const char **mg_get_valid_option_names(void)
-{
- static const char * data[2 * sizeof(config_options) / sizeof(config_options[0])] = {0};
- int i;
-
- for (i=0; config_options[i].name != NULL; i++) {
- data[i * 2] = config_options[i].name;
- data[i * 2 + 1] = config_options[i].default_value;
- }
-
- return data;
-}
-#endif
-
-const struct mg_option *mg_get_valid_options(void)
-{
- return config_options;
-}
-
-
-static int is_file_in_memory(struct mg_connection *conn, const char *path,
- struct file *filep)
-{
- size_t size = 0;
- if ((filep->membuf = conn->ctx->callbacks.open_file == NULL ? NULL :
- conn->ctx->callbacks.open_file(conn, path, &size)) != NULL) {
- /* NOTE: override filep->size only on success. Otherwise, it might
- break constructs like if (!mg_stat() || !mg_fopen()) ... */
- filep->size = size;
- }
- return filep->membuf != NULL;
-}
-
-static int is_file_opened(const struct file *filep)
-{
- return filep->membuf != NULL || filep->fp != NULL;
-}
-
-static int mg_fopen(struct mg_connection *conn, const char *path,
- const char *mode, struct file *filep)
-{
- if (!is_file_in_memory(conn, path, filep)) {
-#ifdef _WIN32
- wchar_t wbuf[PATH_MAX], wmode[20];
- to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
- MultiByteToWideChar(CP_UTF8, 0, mode, -1, wmode, ARRAY_SIZE(wmode));
- filep->fp = _wfopen(wbuf, wmode);
-#else
- filep->fp = fopen(path, mode);
-#endif
- }
-
- return is_file_opened(filep);
-}
-
-static void mg_fclose(struct file *filep)
-{
- if (filep != NULL && filep->fp != NULL) {
- fclose(filep->fp);
- }
-}
-
-static void mg_strlcpy(register char *dst, register const char *src, size_t n)
-{
- for (; *src != '\0' && n > 1; n--) {
- *dst++ = *src++;
- }
- *dst = '\0';
-}
-
-static int lowercase(const char *s)
-{
- return tolower(* (const unsigned char *) s);
-}
-
-int mg_strncasecmp(const char *s1, const char *s2, size_t len)
-{
- int diff = 0;
-
- if (len > 0)
- do {
- diff = lowercase(s1++) - lowercase(s2++);
- } while (diff == 0 && s1[-1] != '\0' && --len > 0);
-
- return diff;
-}
-
-static int mg_strcasecmp(const char *s1, const char *s2)
-{
- int diff;
-
- do {
- diff = lowercase(s1++) - lowercase(s2++);
- } while (diff == 0 && s1[-1] != '\0');
-
- return diff;
-}
-
-static char * mg_strndup(const char *ptr, size_t len)
-{
- char *p;
-
- if ((p = (char *) mg_malloc(len + 1)) != NULL) {
- mg_strlcpy(p, ptr, len + 1);
- }
-
- return p;
-}
-
-static char * mg_strdup(const char *str)
-{
- return mg_strndup(str, strlen(str));
-}
-
-static const char *mg_strcasestr(const char *big_str, const char *small_str)
-{
- int i, big_len = (int)strlen(big_str), small_len = (int)strlen(small_str);
-
- for (i = 0; i <= big_len - small_len; i++) {
- if (mg_strncasecmp(big_str + i, small_str, small_len) == 0) {
- return big_str + i;
- }
- }
-
- return NULL;
-}
-
-/* Like snprintf(), but never returns negative value, or a value
- that is larger than a supplied buffer.
- Thanks to Adam Zeldis to pointing snprintf()-caused vulnerability
- in his audit report. */
-static int mg_vsnprintf(struct mg_connection *conn, char *buf, size_t buflen,
- const char *fmt, va_list ap)
-{
- int n;
-
- if (buflen == 0)
- return 0;
-
- n = vsnprintf(buf, buflen, fmt, ap);
-
- if (n < 0) {
- mg_cry(conn, "vsnprintf error");
- n = 0;
- } else if (n >= (int) buflen) {
- mg_cry(conn, "truncating vsnprintf buffer: [%.*s]",
- n > 200 ? 200 : n, buf);
- n = (int) buflen - 1;
- }
- buf[n] = '\0';
-
- return n;
-}
-
-static int mg_snprintf(struct mg_connection *conn, char *buf, size_t buflen,
- PRINTF_FORMAT_STRING(const char *fmt), ...)
-PRINTF_ARGS(4, 5);
-
-static int mg_snprintf(struct mg_connection *conn, char *buf, size_t buflen,
- const char *fmt, ...)
-{
- va_list ap;
- int n;
-
- va_start(ap, fmt);
- n = mg_vsnprintf(conn, buf, buflen, fmt, ap);
- va_end(ap);
-
- return n;
-}
-
-static int get_option_index(const char *name)
-{
- int i;
-
- for (i = 0; config_options[i].name != NULL; i++) {
- if (strcmp(config_options[i].name, name) == 0) {
- return i;
- }
- }
- return -1;
-}
-
-const char *mg_get_option(const struct mg_context *ctx, const char *name)
-{
- int i;
- if ((i = get_option_index(name)) == -1) {
- return NULL;
- } else if (ctx->config[i] == NULL) {
- return "";
- } else {
- return ctx->config[i];
- }
-}
-
-struct mg_context *mg_get_context(struct mg_connection * conn)
-{
- return (conn == NULL) ? (struct mg_context *)NULL : (conn->ctx);
-}
-
-void *mg_get_user_data(struct mg_context *ctx)
-{
- return (ctx == NULL) ? NULL : ctx->user_data;
-}
-
-size_t mg_get_ports(const struct mg_context *ctx, size_t size, int* ports, int* ssl)
-{
- size_t i;
- for (i = 0; i < size && i < (size_t)ctx->num_listening_sockets; i++)
- {
- ssl[i] = ctx->listening_sockets[i].is_ssl;
- ports[i] = ctx->listening_ports[i];
- }
- return i;
-}
-
-static void sockaddr_to_string(char *buf, size_t len,
- const union usa *usa)
-{
- buf[0] = '\0';
-#if defined(USE_IPV6)
- inet_ntop(usa->sa.sa_family, usa->sa.sa_family == AF_INET ?
- (void *) &usa->sin.sin_addr :
- (void *) &usa->sin6.sin6_addr, buf, len);
-#elif defined(_WIN32)
- /* Only Windows Vista (and newer) have inet_ntop() */
- mg_strlcpy(buf, inet_ntoa(usa->sin.sin_addr), len);
-#else
- inet_ntop(usa->sa.sa_family, (void *) &usa->sin.sin_addr, buf, len);
-#endif
-}
-
-/* Convert time_t to a string. According to RFC2616, Sec 14.18, this must be included in all responses other than 100, 101, 5xx. */
-static void gmt_time_string(char *buf, size_t buf_len, time_t *t)
-{
- struct tm *tm;
-
- tm = gmtime(t);
- if (tm != NULL) {
- strftime(buf, buf_len, "%a, %d %b %Y %H:%M:%S GMT", tm);
- } else {
- mg_strlcpy(buf, "Thu, 01 Jan 1970 00:00:00 GMT", buf_len);
- buf[buf_len - 1] = '\0';
- }
-}
-
-/* Print error message to the opened error log stream. */
-void mg_cry(struct mg_connection *conn, const char *fmt, ...)
-{
- char buf[MG_BUF_LEN], src_addr[IP_ADDR_STR_LEN];
- va_list ap;
- FILE *fp;
- time_t timestamp;
-
- va_start(ap, fmt);
- IGNORE_UNUSED_RESULT(vsnprintf(buf, sizeof(buf), fmt, ap));
- va_end(ap);
-
- /* Do not lock when getting the callback value, here and below.
- I suppose this is fine, since function cannot disappear in the
- same way string option can. */
- if (conn->ctx->callbacks.log_message == NULL ||
- conn->ctx->callbacks.log_message(conn, buf) == 0) {
- fp = conn->ctx->config[ERROR_LOG_FILE] == NULL ? NULL :
- fopen(conn->ctx->config[ERROR_LOG_FILE], "a+");
-
- if (fp != NULL) {
- flockfile(fp);
- timestamp = time(NULL);
-
- sockaddr_to_string(src_addr, sizeof(src_addr), &conn->client.rsa);
- fprintf(fp, "[%010lu] [error] [client %s] ", (unsigned long) timestamp,
- src_addr);
-
- if (conn->request_info.request_method != NULL) {
- fprintf(fp, "%s %s: ", conn->request_info.request_method,
- conn->request_info.uri);
- }
-
- fprintf(fp, "%s", buf);
- fputc('\n', fp);
- funlockfile(fp);
- fclose(fp);
- }
- }
-}
-
-/* Return fake connection structure. Used for logging, if connection
- is not applicable at the moment of logging. */
-static struct mg_connection *fc(struct mg_context *ctx)
-{
- static struct mg_connection fake_connection;
- fake_connection.ctx = ctx;
- return &fake_connection;
-}
-
-const char *mg_version(void)
-{
- return CIVETWEB_VERSION;
-}
-
-struct mg_request_info *mg_get_request_info(struct mg_connection *conn)
-{
- return &conn->request_info;
-}
-
-/* Skip the characters until one of the delimiters characters found.
- 0-terminate resulting word. Skip the delimiter and following whitespaces.
- Advance pointer to buffer to the next word. Return found 0-terminated word.
- Delimiters can be quoted with quotechar. */
-static char *skip_quoted(char **buf, const char *delimiters,
- const char *whitespace, char quotechar)
-{
- char *p, *begin_word, *end_word, *end_whitespace;
-
- begin_word = *buf;
- end_word = begin_word + strcspn(begin_word, delimiters);
-
- /* Check for quotechar */
- if (end_word > begin_word) {
- p = end_word - 1;
- while (*p == quotechar) {
- /* TODO (bel): it seems this code is never reached, so quotechar is actually
- not needed - check if this code may be droped */
-
- /* If there is anything beyond end_word, copy it */
- if (*end_word == '\0') {
- *p = '\0';
- break;
- } else {
- size_t end_off = strcspn(end_word + 1, delimiters);
- memmove (p, end_word, end_off + 1);
- p += end_off; /* p must correspond to end_word - 1 */
- end_word += end_off + 1;
- }
- }
- for (p++; p < end_word; p++) {
- *p = '\0';
- }
- }
-
- if (*end_word == '\0') {
- *buf = end_word;
- } else {
- end_whitespace = end_word + 1 + strspn(end_word + 1, whitespace);
-
- for (p = end_word; p < end_whitespace; p++) {
- *p = '\0';
- }
-
- *buf = end_whitespace;
- }
-
- return begin_word;
-}
-
-/* Simplified version of skip_quoted without quote char
- and whitespace == delimiters */
-static char *skip(char **buf, const char *delimiters)
-{
- return skip_quoted(buf, delimiters, delimiters, 0);
-}
-
-
-/* Return HTTP header value, or NULL if not found. */
-static const char *get_header(const struct mg_request_info *ri,
- const char *name)
-{
- int i;
-
- for (i = 0; i < ri->num_headers; i++)
- if (!mg_strcasecmp(name, ri->http_headers[i].name))
- return ri->http_headers[i].value;
-
- return NULL;
-}
-
-const char *mg_get_header(const struct mg_connection *conn, const char *name)
-{
- return get_header(&conn->request_info, name);
-}
-
-/* A helper function for traversing a comma separated list of values.
- It returns a list pointer shifted to the next value, or NULL if the end
- of the list found.
- Value is stored in val vector. If value has form "x=y", then eq_val
- vector is initialized to point to the "y" part, and val vector length
- is adjusted to point only to "x". */
-static const char *next_option(const char *list, struct vec *val,
- struct vec *eq_val)
-{
- if (list == NULL || *list == '\0') {
- /* End of the list */
- list = NULL;
- } else {
- val->ptr = list;
- if ((list = strchr(val->ptr, ',')) != NULL) {
- /* Comma found. Store length and shift the list ptr */
- val->len = list - val->ptr;
- list++;
- } else {
- /* This value is the last one */
- list = val->ptr + strlen(val->ptr);
- val->len = list - val->ptr;
- }
-
- if (eq_val != NULL) {
- /* Value has form "x=y", adjust pointers and lengths
- so that val points to "x", and eq_val points to "y". */
- eq_val->len = 0;
- eq_val->ptr = (const char *) memchr(val->ptr, '=', val->len);
- if (eq_val->ptr != NULL) {
- eq_val->ptr++; /* Skip over '=' character */
- eq_val->len = val->ptr + val->len - eq_val->ptr;
- val->len = (eq_val->ptr - val->ptr) - 1;
- }
- }
- }
-
- return list;
-}
-
-/* Perform case-insensitive match of string against pattern */
-static int match_prefix(const char *pattern, int pattern_len, const char *str)
-{
- const char *or_str;
- int i, j, len, res;
-
- if ((or_str = (const char *) memchr(pattern, '|', pattern_len)) != NULL) {
- res = match_prefix(pattern, (int)(or_str - pattern), str);
- return res > 0 ? res :
- match_prefix(or_str + 1, (int)((pattern + pattern_len) - (or_str + 1)), str);
- }
-
- i = j = 0;
- for (; i < pattern_len; i++, j++) {
- if (pattern[i] == '?' && str[j] != '\0') {
- continue;
- } else if (pattern[i] == '$') {
- return str[j] == '\0' ? j : -1;
- } else if (pattern[i] == '*') {
- i++;
- if (pattern[i] == '*') {
- i++;
- len = (int) strlen(str + j);
- } else {
- len = (int) strcspn(str + j, "/");
- }
- if (i == pattern_len) {
- return j + len;
- }
- do {
- res = match_prefix(pattern + i, pattern_len - i, str + j + len);
- } while (res == -1 && len-- > 0);
- return res == -1 ? -1 : j + res + len;
- } else if (lowercase(&pattern[i]) != lowercase(&str[j])) {
- return -1;
- }
- }
- return j;
-}
-
-/* HTTP 1.1 assumes keep alive if "Connection:" header is not set
- This function must tolerate situations when connection info is not
- set up, for example if request parsing failed. */
-static int should_keep_alive(const struct mg_connection *conn)
-{
- const char *http_version = conn->request_info.http_version;
- const char *header = mg_get_header(conn, "Connection");
- if (conn->must_close ||
- conn->status_code == 401 ||
- mg_strcasecmp(conn->ctx->config[ENABLE_KEEP_ALIVE], "yes") != 0 ||
- (header != NULL && mg_strcasecmp(header, "keep-alive") != 0) ||
- (header == NULL && http_version && 0!=strcmp(http_version, "1.1"))) {
- return 0;
- }
- return 1;
-}
-
-static int should_decode_url(const struct mg_connection *conn)
-{
- return (mg_strcasecmp(conn->ctx->config[DECODE_URL], "yes") == 0);
-}
-
-static const char *suggest_connection_header(const struct mg_connection *conn)
-{
- return should_keep_alive(conn) ? "keep-alive" : "close";
-}
-
-static void handle_file_based_request(struct mg_connection *conn, const char *path, struct file *filep);
-static int mg_stat(struct mg_connection *conn, const char *path, struct file *filep);
-
-static const char *mg_get_response_code_text(int response_code, struct mg_connection *conn)
-{
- switch (response_code)
- {
- /* RFC2616 Section 10.1 - Informational 1xx */
- case 100: return "Continue"; /* RFC2616 Section 10.1.1 */
- case 101: return "Switching Protocols"; /* RFC2616 Section 10.1.2 */
- case 102: return "Processing"; /* RFC2518 Section 10.1 */
-
- /* RFC2616 Section 10.2 - Successful 2xx */
- case 200: return "OK"; /* RFC2616 Section 10.2.1 */
- case 201: return "Created"; /* RFC2616 Section 10.2.2 */
- case 202: return "Accepted"; /* RFC2616 Section 10.2.3 */
- case 203: return "Non-Authoritative Information"; /* RFC2616 Section 10.2.4 */
- case 204: return "No Content"; /* RFC2616 Section 10.2.5 */
- case 205: return "Reset Content"; /* RFC2616 Section 10.2.6 */
- case 206: return "Partial Content"; /* RFC2616 Section 10.2.7 */
- case 207: return "Multi-Status"; /* RFC2518 Section 10.2, RFC4918 Section 11.1 */
-
- /* RFC2616 Section 10.3 - Redirection 3xx */
- case 300: return "Multiple Choices"; /* RFC2616 Section 10.3.1 */
- case 301: return "Moved Permanently"; /* RFC2616 Section 10.3.2 */
- case 302: return "Found"; /* RFC2616 Section 10.3.3 */
- case 303: return "See Other"; /* RFC2616 Section 10.3.4 */
- case 304: return "Not Modified"; /* RFC2616 Section 10.3.5 */
- case 305: return "Use Proxy"; /* RFC2616 Section 10.3.6 */
- case 307: return "Temporary Redirect"; /* RFC2616 Section 10.3.8 */
-
- /* RFC2616 Section 10.4 - Client Error 4xx */
- case 400: return "Bad Request"; /* RFC2616 Section 10.4.1 */
- case 401: return "Unauthorized"; /* RFC2616 Section 10.4.2 */
- case 402: return "Payment Required"; /* RFC2616 Section 10.4.3 */
- case 403: return "Forbidden"; /* RFC2616 Section 10.4.4 */
- case 404: return "Not Found"; /* RFC2616 Section 10.4.5 */
- case 405: return "Method Not Allowed"; /* RFC2616 Section 10.4.6 */
- case 406: return "Not Acceptable"; /* RFC2616 Section 10.4.7 */
- case 407: return "Proxy Authentication Required"; /* RFC2616 Section 10.4.8 */
- case 408: return "Request Time-out"; /* RFC2616 Section 10.4.9 */
- case 409: return "Conflict"; /* RFC2616 Section 10.4.10 */
- case 410: return "Gone"; /* RFC2616 Section 10.4.11 */
- case 411: return "Length Required"; /* RFC2616 Section 10.4.12 */
- case 412: return "Precondition Failed"; /* RFC2616 Section 10.4.13 */
- case 413: return "Request Entity Too Large"; /* RFC2616 Section 10.4.14 */
- case 414: return "Request-URI Too Large"; /* RFC2616 Section 10.4.15 */
- case 415: return "Unsupported Media Type"; /* RFC2616 Section 10.4.16 */
- case 416: return "Requested range not satisfiable"; /* RFC2616 Section 10.4.17 */
- case 417: return "Expectation Failed"; /* RFC2616 Section 10.4.18 */
- case 422: return "Unproccessable entity"; /* RFC2518 Section 10.3, RFC4918 Section 11.2 */
- case 423: return "Locked"; /* RFC2518 Section 10.4, RFC4918 Section 11.3 */
- case 424: return "Failed Dependency"; /* RFC2518 Section 10.5, RFC4918 Section 11.4 */
- case 428: return "Precondition Required"; /* RFC 6585, Section 3 */
- case 429: return "Too Many Requests"; /* RFC 6585, Section 4 */
- case 431: return "Request Header Fields Too Large"; /* RFC 6585, Section 5 */
-
- /* RFC2616 Section 10.5 - Server Error 5xx */
- case 500: return "Internal Server Error"; /* RFC2616 Section 10.5.1 */
- case 501: return "Not Implemented"; /* RFC2616 Section 10.5.2 */
- case 502: return "Bad Gateway"; /* RFC2616 Section 10.5.3 */
- case 503: return "Service Unavailable"; /* RFC2616 Section 10.5.4 */
- case 504: return "Gateway Time-out"; /* RFC2616 Section 10.5.5 */
- case 505: return "HTTP Version not supported"; /* RFC2616 Section 10.5.6 */
- case 507: return "Insufficient Storage"; /* RFC2518 Section 10.6, , RFC4918 Section 11.5 */
- case 511: return "Network Authentication Required"; /* RFC 6585, Section 6 */
-
- /* Other RFCs */
- case 426: return "Upgrade Required"; /* RFC 2817 */
-
- /* Return codes from non normative RFCs: */
- /* Informative and experimental RFCs, "de facto" standards due to common use, ... */
- case 208: return "Already Reported"; /* RFC5842 Section 7.1 */
- case 226: return "IM used"; /* RFC3229 Section 10.4.1 */
- case 308: return "Permanent Redirect"; /* RFC7238 Section 3 */
- case 418: return "I am a teapot"; /* RFC2324 Section 2.3.2 */
- case 419: return "Authentication Timeout"; /* common use */
- case 451: return "Unavailable For Legal Reasons"; /* draft-tbray-http-legally-restricted-status-05, Section 3 */
- case 506: return "Variant Also Negotiates"; /* RFC 2295, Section 8.1 */
- case 508: return "Loop Detected"; /* RFC5842 Section 7.1 */
- case 510: return "Not Extended"; /* RFC 2774, Section 7 */
-
- default:
- /* This error code is unknown. This should not happen. */
- if (conn) {
- mg_cry(conn, "Unknown HTTP response code: %u", response_code);
- }
-
- /* Return at least a category according to RFC 2616 Section 10. */
- if (response_code>=100 && response_code<200) {
- /* Unknown informational status code */
- return "Information";
- }
- if (response_code>=200 && response_code<300) {
- /* Unknown success code */
- return "Success";
- }
- if (response_code>=300 && response_code<400) {
- /* Unknown redirection code */
- return "Redirection";
- }
- if (response_code>=400 && response_code<500) {
- /* Unknown request error code */
- return "Client Error";
- }
- if (response_code>=500 && response_code<600) {
- /* Unknown server error code */
- return "Server Error";
- }
-
- /* Response code not even within reasonable range */
- return "";
- }
-}
-
-
-static void send_http_error(struct mg_connection *, int, const char *,
- PRINTF_FORMAT_STRING(const char *fmt), ...)
-PRINTF_ARGS(4, 5);
-
-
-static void send_http_error(struct mg_connection *conn, int status,
- const char *reason, const char *fmt, ...)
-{
- char buf[MG_BUF_LEN];
- va_list ap;
- int len = 0, i, page_handler_found, scope;
- char date[64];
- time_t curtime = time(NULL);
- const char *error_handler = NULL;
- struct file error_page_file = STRUCT_FILE_INITIALIZER;
- const char *error_page_file_ext, *tstr;
-
- if (!reason) {
- reason = mg_get_response_code_text(status, conn);
- }
-
- conn->status_code = status;
- if (conn->in_error_handler ||
- conn->ctx->callbacks.http_error == NULL ||
- conn->ctx->callbacks.http_error(conn, status)) {
-
- if (!conn->in_error_handler) {
- /* Send user defined error pages, if defined */
- error_handler = conn->ctx->config[ERROR_PAGES];
- error_page_file_ext = conn->ctx->config[INDEX_FILES];
- page_handler_found = 0;
- if (error_handler != NULL) {
- for (scope=1; (scope<=3) && !page_handler_found; scope++) {
- switch (scope) {
- case 1:
- len = mg_snprintf(conn, buf, sizeof(buf)-32, "%serror%03u.", error_handler, status);
- break;
- case 2:
- len = mg_snprintf(conn, buf, sizeof(buf)-32, "%serror%01uxx.", error_handler, status/100);
- break;
- default:
- len = mg_snprintf(conn, buf, sizeof(buf)-32, "%serror.", error_handler);
- break;
- }
- tstr = strchr(error_page_file_ext, '.');
- while (tstr) {
- for (i=1; i<32 && tstr[i]!=0 && tstr[i]!=','; i++) buf[len+i-1]=tstr[i];
- buf[len+i-1]=0;
- if (mg_stat(conn, buf, &error_page_file)) {
- page_handler_found = 1;
- break;
- }
- tstr = strchr(tstr+i, '.');
- }
- }
- }
-
- if (page_handler_found) {
- conn->in_error_handler = 1;
- handle_file_based_request(conn, buf, &error_page_file);
- conn->in_error_handler = 0;
- return;
- }
- }
-
- buf[0] = '\0';
- gmt_time_string(date, sizeof(date), &curtime);
-
- /* Errors 1xx, 204 and 304 MUST NOT send a body */
- if (status > 199 && status != 204 && status != 304) {
- len = mg_snprintf(conn, buf, sizeof(buf)-1, "Error %d: %s", status, reason);
- buf[len] = '\n';
- len++;
- buf[len] = 0;
-
- va_start(ap, fmt);
- len += mg_vsnprintf(conn, buf + len, sizeof(buf) - len, fmt, ap);
- va_end(ap);
- }
- DEBUG_TRACE("[%s]", buf);
-
- mg_printf(conn, "HTTP/1.1 %d %s\r\n"
- "Content-Length: %d\r\n"
- "Date: %s\r\n"
- "Connection: %s\r\n\r\n",
- status, reason, len, date,
- suggest_connection_header(conn));
- conn->num_bytes_sent += mg_printf(conn, "%s", buf);
- }
-}
-
-#if defined(_WIN32) && !defined(__SYMBIAN32__)
-static int pthread_mutex_init(pthread_mutex_t *mutex, void *unused)
-{
- (void) unused;
- *mutex = CreateMutex(NULL, FALSE, NULL);
- return *mutex == NULL ? -1 : 0;
-}
-
-static int pthread_mutex_destroy(pthread_mutex_t *mutex)
-{
- return CloseHandle(*mutex) == 0 ? -1 : 0;
-}
-
-static int pthread_mutex_lock(pthread_mutex_t *mutex)
-{
- return WaitForSingleObject(*mutex, INFINITE) == WAIT_OBJECT_0 ? 0 : -1;
-}
-
-static int pthread_mutex_trylock(pthread_mutex_t *mutex)
-{
- switch (WaitForSingleObject(*mutex, 0)) {
- case WAIT_OBJECT_0:
- return 0;
- case WAIT_TIMEOUT:
- return -2; /* EBUSY */
- }
- return -1;
-}
-
-static int pthread_mutex_unlock(pthread_mutex_t *mutex)
-{
- return ReleaseMutex(*mutex) == 0 ? -1 : 0;
-}
-
-#ifndef WIN_PTHREADS_TIME_H
-static int clock_gettime(clockid_t clk_id, struct timespec *tp)
-{
- FILETIME ft;
- ULARGE_INTEGER li;
- BOOL ok = FALSE;
- double d;
- static double perfcnt_per_sec = 0.0;
-
- if (tp) {
- if (clk_id == CLOCK_REALTIME) {
- GetSystemTimeAsFileTime(&ft);
- li.LowPart = ft.dwLowDateTime;
- li.HighPart = ft.dwHighDateTime;
- li.QuadPart -= 116444736000000000; /* 1.1.1970 in filedate */
- tp->tv_sec = (time_t)(li.QuadPart / 10000000);
- tp->tv_nsec = (long)(li.QuadPart % 10000000) * 100;
- ok = TRUE;
- } else if (clk_id == CLOCK_MONOTONIC) {
- if (perfcnt_per_sec == 0.0) {
- QueryPerformanceFrequency((LARGE_INTEGER *) &li);
- perfcnt_per_sec = 1.0 / li.QuadPart;
- }
- if (perfcnt_per_sec != 0.0) {
- QueryPerformanceCounter((LARGE_INTEGER *) &li);
- d = li.QuadPart * perfcnt_per_sec;
- tp->tv_sec = (time_t)d;
- d -= tp->tv_sec;
- tp->tv_nsec = (long)(d*1.0E9);
- ok = TRUE;
- }
- }
- }
-
- return ok ? 0 : -1;
-}
-#endif
-
-static int pthread_cond_init(pthread_cond_t *cv, const void *unused)
-{
- (void) unused;
- InitializeCriticalSection(&cv->threadIdSec);
- cv->waitingthreadcount = 0;
- cv->waitingthreadhdls = (pthread_t *) mg_calloc(MAX_WORKER_THREADS, sizeof(pthread_t));
- return (cv->waitingthreadhdls!=NULL) ? 0 : -1;
-}
-
-static int pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t *mutex, const struct timespec * abstime)
-{
- struct mg_workerTLS * tls = (struct mg_workerTLS *)TlsGetValue(sTlsKey);
- int ok;
- struct timespec tsnow;
- int64_t nsnow, nswaitabs, nswaitrel;
- DWORD mswaitrel;
-
- EnterCriticalSection(&cv->threadIdSec);
- assert(cv->waitingthreadcount < MAX_WORKER_THREADS);
- cv->waitingthreadhdls[cv->waitingthreadcount] = tls->pthread_cond_helper_mutex;
- cv->waitingthreadcount++;
- LeaveCriticalSection(&cv->threadIdSec);
-
- if (abstime) {
- clock_gettime(CLOCK_REALTIME, &tsnow);
- nsnow = (((uint64_t)tsnow.tv_sec)*1000000000) + tsnow.tv_nsec;
- nswaitabs = (((uint64_t)abstime->tv_sec)*1000000000) + abstime->tv_nsec;
- nswaitrel = nswaitabs - nsnow;
- if (nswaitrel<0) nswaitrel=0;
- mswaitrel = (DWORD)(nswaitrel / 1000000);
- } else {
- mswaitrel = INFINITE;
- }
-
- pthread_mutex_unlock(mutex);
- ok = (WAIT_OBJECT_0 == WaitForSingleObject(tls->pthread_cond_helper_mutex, mswaitrel));
- pthread_mutex_lock(mutex);
-
- return ok ? 0 : -1;
-}
-
-static int pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex)
-{
- return pthread_cond_timedwait(cv, mutex, NULL);
-}
-
-static int pthread_cond_signal(pthread_cond_t *cv)
-{
- int i;
- HANDLE wkup = NULL;
- BOOL ok = FALSE;
-
- EnterCriticalSection(&cv->threadIdSec);
- if (cv->waitingthreadcount) {
- wkup = cv->waitingthreadhdls[0];
- ok = SetEvent(wkup);
-
- for (i=1; i<cv->waitingthreadcount; i++) {
- cv->waitingthreadhdls[i-1] = cv->waitingthreadhdls[i];
- }
- cv->waitingthreadcount--;
-
- assert(ok);
- }
- LeaveCriticalSection(&cv->threadIdSec);
-
- return ok ? 0 : 1;
-}
-
-static int pthread_cond_broadcast(pthread_cond_t *cv)
-{
- EnterCriticalSection(&cv->threadIdSec);
- while (cv->waitingthreadcount) {
- pthread_cond_signal(cv);
- }
- LeaveCriticalSection(&cv->threadIdSec);
-
- return 0;
-}
-
-static int pthread_cond_destroy(pthread_cond_t *cv)
-{
- EnterCriticalSection(&cv->threadIdSec);
- assert(cv->waitingthreadcount==0);
- mg_free(cv->waitingthreadhdls);
- cv->waitingthreadhdls = 0;
- LeaveCriticalSection(&cv->threadIdSec);
- DeleteCriticalSection(&cv->threadIdSec);
-
- return 0;
-}
-
-/* For Windows, change all slashes to backslashes in path names. */
-static void change_slashes_to_backslashes(char *path)
-{
- int i;
-
- for (i = 0; path[i] != '\0'; i++) {
- if (path[i] == '/')
- path[i] = '\\';
- /* i > 0 check is to preserve UNC paths, like \\server\file.txt */
- if (path[i] == '\\' && i > 0)
- while (path[i + 1] == '\\' || path[i + 1] == '/')
- (void) memmove(path + i + 1,
- path + i + 2, strlen(path + i + 1));
- }
-}
-
-/* Encode 'path' which is assumed UTF-8 string, into UNICODE string.
- wbuf and wbuf_len is a target buffer and its length. */
-static void to_unicode(const char *path, wchar_t *wbuf, size_t wbuf_len)
-{
- char buf[PATH_MAX], buf2[PATH_MAX];
-
- mg_strlcpy(buf, path, sizeof(buf));
- change_slashes_to_backslashes(buf);
-
- /* Convert to Unicode and back. If doubly-converted string does not
- match the original, something is fishy, reject. */
- memset(wbuf, 0, wbuf_len * sizeof(wchar_t));
- MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, (int) wbuf_len);
- WideCharToMultiByte(CP_UTF8, 0, wbuf, (int) wbuf_len, buf2, sizeof(buf2),
- NULL, NULL);
- if (strcmp(buf, buf2) != 0) {
- wbuf[0] = L'\0';
- }
-}
-
-#if defined(_WIN32_WCE)
-static time_t time(time_t *ptime)
-{
- time_t t;
- SYSTEMTIME st;
- FILETIME ft;
-
- GetSystemTime(&st);
- SystemTimeToFileTime(&st, &ft);
- t = SYS2UNIX_TIME(ft.dwLowDateTime, ft.dwHighDateTime);
-
- if (ptime != NULL) {
- *ptime = t;
- }
-
- return t;
-}
-
-static struct tm *localtime(const time_t *ptime, struct tm *ptm)
-{
- int64_t t = ((int64_t) *ptime) * RATE_DIFF + EPOCH_DIFF;
- FILETIME ft, lft;
- SYSTEMTIME st;
- TIME_ZONE_INFORMATION tzinfo;
-
- if (ptm == NULL) {
- return NULL;
- }
-
- * (int64_t *) &ft = t;
- FileTimeToLocalFileTime(&ft, &lft);
- FileTimeToSystemTime(&lft, &st);
- ptm->tm_year = st.wYear - 1900;
- ptm->tm_mon = st.wMonth - 1;
- ptm->tm_wday = st.wDayOfWeek;
- ptm->tm_mday = st.wDay;
- ptm->tm_hour = st.wHour;
- ptm->tm_min = st.wMinute;
- ptm->tm_sec = st.wSecond;
- ptm->tm_yday = 0; /* hope nobody uses this */
- ptm->tm_isdst =
- GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_DAYLIGHT ? 1 : 0;
-
- return ptm;
-}
-
-static struct tm *gmtime(const time_t *ptime, struct tm *ptm)
-{
- /* FIXME(lsm): fix this. */
- return localtime(ptime, ptm);
-}
-
-static size_t strftime(char *dst, size_t dst_size, const char *fmt,
- const struct tm *tm)
-{
- (void) snprintf(dst, dst_size, "implement strftime() for WinCE");
- return 0;
-}
-#endif
-
-/* Windows happily opens files with some garbage at the end of file name.
- For example, fopen("a.cgi ", "r") on Windows successfully opens
- "a.cgi", despite one would expect an error back.
- This function returns non-0 if path ends with some garbage. */
-static int path_cannot_disclose_cgi(const char *path)
-{
- static const char *allowed_last_characters = "_-";
- int last = path[strlen(path) - 1];
- return isalnum(last) || strchr(allowed_last_characters, last) != NULL;
-}
-
-static int mg_stat(struct mg_connection *conn, const char *path, struct file *filep)
-{
- wchar_t wbuf[PATH_MAX];
- WIN32_FILE_ATTRIBUTE_DATA info;
-
- if (!is_file_in_memory(conn, path, filep)) {
- to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
- if (GetFileAttributesExW(wbuf, GetFileExInfoStandard, &info) != 0) {
- filep->size = MAKEUQUAD(info.nFileSizeLow, info.nFileSizeHigh);
- filep->modification_time = SYS2UNIX_TIME(
- info.ftLastWriteTime.dwLowDateTime,
- info.ftLastWriteTime.dwHighDateTime);
- filep->is_directory = info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
- /* If file name is fishy, reset the file structure and return
- error.
- Note it is important to reset, not just return the error, cause
- functions like is_file_opened() check the struct. */
- if (!filep->is_directory && !path_cannot_disclose_cgi(path)) {
- memset(filep, 0, sizeof(*filep));
- }
- }
- }
-
- return filep->membuf != NULL || filep->modification_time != 0;
-}
-
-static int mg_remove(const char *path)
-{
- wchar_t wbuf[PATH_MAX];
- to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
- return DeleteFileW(wbuf) ? 0 : -1;
-}
-
-static int mg_mkdir(const char *path, int mode)
-{
- char buf[PATH_MAX];
- wchar_t wbuf[PATH_MAX];
-
- (void) mode;
- mg_strlcpy(buf, path, sizeof(buf));
- change_slashes_to_backslashes(buf);
-
- (void) MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, ARRAY_SIZE(wbuf));
-
- return CreateDirectoryW(wbuf, NULL) ? 0 : -1;
-}
-
-/* Implementation of POSIX opendir/closedir/readdir for Windows. */
-static DIR * opendir(const char *name)
-{
- DIR *dir = NULL;
- wchar_t wpath[PATH_MAX];
- DWORD attrs;
-
- if (name == NULL) {
- SetLastError(ERROR_BAD_ARGUMENTS);
- } else if ((dir = (DIR *) mg_malloc(sizeof(*dir))) == NULL) {
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- } else {
- to_unicode(name, wpath, ARRAY_SIZE(wpath));
- attrs = GetFileAttributesW(wpath);
- if (attrs != 0xFFFFFFFF &&
- ((attrs & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)) {
- (void) wcscat(wpath, L"\\*");
- dir->handle = FindFirstFileW(wpath, &dir->info);
- dir->result.d_name[0] = '\0';
- } else {
- mg_free(dir);
- dir = NULL;
- }
- }
-
- return dir;
-}
-
-static int closedir(DIR *dir)
-{
- int result = 0;
-
- if (dir != NULL) {
- if (dir->handle != INVALID_HANDLE_VALUE)
- result = FindClose(dir->handle) ? 0 : -1;
-
- mg_free(dir);
- } else {
- result = -1;
- SetLastError(ERROR_BAD_ARGUMENTS);
- }
-
- return result;
-}
-
-static struct dirent *readdir(DIR *dir)
-{
- struct dirent *result = 0;
-
- if (dir) {
- if (dir->handle != INVALID_HANDLE_VALUE) {
- result = &dir->result;
- (void) WideCharToMultiByte(CP_UTF8, 0,
- dir->info.cFileName, -1, result->d_name,
- sizeof(result->d_name), NULL, NULL);
-
- if (!FindNextFileW(dir->handle, &dir->info)) {
- (void) FindClose(dir->handle);
- dir->handle = INVALID_HANDLE_VALUE;
- }
-
- } else {
- SetLastError(ERROR_FILE_NOT_FOUND);
- }
- } else {
- SetLastError(ERROR_BAD_ARGUMENTS);
- }
-
- return result;
-}
-
-#ifndef HAVE_POLL
-static int poll(struct pollfd *pfd, int n, int milliseconds)
-{
- struct timeval tv;
- fd_set set;
- int i, result;
- SOCKET maxfd = 0;
-
- tv.tv_sec = milliseconds / 1000;
- tv.tv_usec = (milliseconds % 1000) * 1000;
- FD_ZERO(&set);
-
- for (i = 0; i < n; i++) {
- FD_SET((SOCKET) pfd[i].fd, &set);
- pfd[i].revents = 0;
-
- if (pfd[i].fd > maxfd) {
- maxfd = pfd[i].fd;
- }
- }
-
- if ((result = select((int)maxfd + 1, &set, NULL, NULL, &tv)) > 0) {
- for (i = 0; i < n; i++) {
- if (FD_ISSET(pfd[i].fd, &set)) {
- pfd[i].revents = POLLIN;
- }
- }
- }
-
- return result;
-}
-#endif /* HAVE_POLL */
-
-static void set_close_on_exec(SOCKET sock, struct mg_connection *conn /* may be null */)
-{
- (void) conn; /* Unused. */
- (void) SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0);
-}
-
-int mg_start_thread(mg_thread_func_t f, void *p)
-{
-#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
- /* Compile-time option to control stack size, e.g. -DUSE_STACK_SIZE=16384 */
- return ((_beginthread((void (__cdecl *)(void *)) f, USE_STACK_SIZE, p) == ((uintptr_t)(-1L))) ? -1 : 0);
-#else
- return ((_beginthread((void (__cdecl *)(void *)) f, 0, p) == ((uintptr_t)(-1L))) ? -1 : 0);
-#endif /* defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1) */
-}
-
-/* Start a thread storing the thread context. */
-
-static int mg_start_thread_with_id(unsigned (__stdcall *f)(void *), void *p,
- pthread_t *threadidptr)
-{
- uintptr_t uip;
- HANDLE threadhandle;
- int result = -1;
-
- uip = _beginthreadex(NULL, 0, (unsigned (__stdcall *)(void *)) f, p, 0,
- NULL);
- threadhandle = (HANDLE) uip;
- if ((uip != (uintptr_t)(-1L)) && (threadidptr != NULL)) {
- *threadidptr = threadhandle;
- result = 0;
- }
-
- return result;
-}
-
-/* Wait for a thread to finish. */
-
-static int mg_join_thread(pthread_t threadid)
-{
- int result;
- DWORD dwevent;
-
- result = -1;
- dwevent = WaitForSingleObject(threadid, INFINITE);
- if (dwevent == WAIT_FAILED) {
- int err;
-
- err = GetLastError();
- DEBUG_TRACE("WaitForSingleObject() failed, error %d", err);
- } else {
- if (dwevent == WAIT_OBJECT_0) {
- CloseHandle(threadid);
- result = 0;
- }
- }
-
- return result;
-}
-
-static HANDLE dlopen(const char *dll_name, int flags)
-{
- wchar_t wbuf[PATH_MAX];
- (void) flags;
- to_unicode(dll_name, wbuf, ARRAY_SIZE(wbuf));
- return LoadLibraryW(wbuf);
-}
-
-static int dlclose(void *handle)
-{
- int result;
-
- if (FreeLibrary((HMODULE) handle) != 0) {
- result = 0;
- } else {
- result = -1;
- }
-
- return result;
-}
-
-#if !defined(NO_CGI)
-#define SIGKILL 0
-static int kill(pid_t pid, int sig_num)
-{
- (void) TerminateProcess(pid, sig_num);
- (void) CloseHandle(pid);
- return 0;
-}
-
-static void trim_trailing_whitespaces(char *s)
-{
- char *e = s + strlen(s) - 1;
- while (e > s && isspace(* (unsigned char *) e)) {
- *e-- = '\0';
- }
-}
-
-static pid_t spawn_process(struct mg_connection *conn, const char *prog,
- char *envblk, char *envp[], int fdin,
- int fdout, const char *dir)
-{
- HANDLE me;
- char *p, *interp, full_interp[PATH_MAX], full_dir[PATH_MAX],
- cmdline[PATH_MAX], buf[PATH_MAX];
- struct file file = STRUCT_FILE_INITIALIZER;
- STARTUPINFOA si;
- PROCESS_INFORMATION pi = { 0 };
-
- (void) envp;
-
- memset(&si, 0, sizeof(si));
- si.cb = sizeof(si);
-
- /* TODO(lsm): redirect CGI errors to the error log file */
- si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
- si.wShowWindow = SW_HIDE;
-
- me = GetCurrentProcess();
- DuplicateHandle(me, (HANDLE) _get_osfhandle(fdin), me,
- &si.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS);
- DuplicateHandle(me, (HANDLE) _get_osfhandle(fdout), me,
- &si.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS);
-
- /* If CGI file is a script, try to read the interpreter line */
- interp = conn->ctx->config[CGI_INTERPRETER];
- if (interp == NULL) {
- buf[0] = buf[1] = '\0';
-
- /* Read the first line of the script into the buffer */
- snprintf(cmdline, sizeof(cmdline), "%s%c%s", dir, '/', prog);
- if (mg_fopen(conn, cmdline, "r", &file)) {
- p = (char *) file.membuf;
- mg_fgets(buf, sizeof(buf), &file, &p);
- mg_fclose(&file);
- buf[sizeof(buf) - 1] = '\0';
- }
-
- if (buf[0] == '#' && buf[1] == '!') {
- trim_trailing_whitespaces(buf + 2);
- } else {
- buf[2] = '\0';
- }
- interp = buf + 2;
- }
-
- if (interp[0] != '\0') {
- GetFullPathNameA(interp, sizeof(full_interp), full_interp, NULL);
- interp = full_interp;
- }
- GetFullPathNameA(dir, sizeof(full_dir), full_dir, NULL);
-
- mg_snprintf(conn, cmdline, sizeof(cmdline), "%s%s\"%s\\%s\"",
- interp, interp[0] == '\0' ? "" : " ", full_dir, prog);
-
- DEBUG_TRACE("Running [%s]", cmdline);
- if (CreateProcessA(NULL, cmdline, NULL, NULL, TRUE,
- CREATE_NEW_PROCESS_GROUP, envblk, NULL, &si, &pi) == 0) {
- mg_cry(conn, "%s: CreateProcess(%s): %ld",
- __func__, cmdline, ERRNO);
- pi.hProcess = (pid_t) -1;
- }
-
- (void) CloseHandle(si.hStdOutput);
- (void) CloseHandle(si.hStdInput);
- if (pi.hThread != NULL)
- (void) CloseHandle(pi.hThread);
-
- return (pid_t) pi.hProcess;
-}
-#endif /* !NO_CGI */
-
-static int set_non_blocking_mode(SOCKET sock)
-{
- unsigned long on = 1;
- return ioctlsocket(sock, FIONBIO, &on);
-}
-
-#else
-static int mg_stat(struct mg_connection *conn, const char *path,
- struct file *filep)
-{
- struct stat st;
-
- if (!is_file_in_memory(conn, path, filep) && !stat(path, &st)) {
- filep->size = st.st_size;
- filep->modification_time = st.st_mtime;
- filep->is_directory = S_ISDIR(st.st_mode);
- } else {
- filep->modification_time = (time_t) 0;
- }
-
- return filep->membuf != NULL || filep->modification_time != (time_t) 0;
-}
-
-static void set_close_on_exec(int fd, struct mg_connection *conn /* may be null */)
-{
- if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) {
- if (conn) {
- mg_cry(conn, "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s", __func__, strerror(ERRNO));
- }
- }
-}
-
-int mg_start_thread(mg_thread_func_t func, void *param)
-{
- pthread_t thread_id;
- pthread_attr_t attr;
- int result;
-
- (void) pthread_attr_init(&attr);
- (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
-#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
- /* Compile-time option to control stack size,
- e.g. -DUSE_STACK_SIZE=16384 */
- (void) pthread_attr_setstacksize(&attr, USE_STACK_SIZE);
-#endif /* defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1) */
-
- result = pthread_create(&thread_id, &attr, func, param);
- pthread_attr_destroy(&attr);
-
- return result;
-}
-
-/* Start a thread storing the thread context. */
-
-static int mg_start_thread_with_id(mg_thread_func_t func, void *param, pthread_t *threadidptr)
-{
- pthread_t thread_id;
- pthread_attr_t attr;
- int result;
-
- (void) pthread_attr_init(&attr);
-
-#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
- /* Compile-time option to control stack size,
- e.g. -DUSE_STACK_SIZE=16384 */
- (void) pthread_attr_setstacksize(&attr, USE_STACK_SIZE);
-#endif /* defined(USE_STACK_SIZE) && USE_STACK_SIZE > 1 */
-
- result = pthread_create(&thread_id, &attr, func, param);
- pthread_attr_destroy(&attr);
- if ((result == 0) && (threadidptr != NULL)) {
- *threadidptr = thread_id;
- }
- return result;
-}
-
-/* Wait for a thread to finish. */
-
-static int mg_join_thread(pthread_t threadid)
-{
- int result;
-
- result = pthread_join(threadid, NULL);
- return result;
-}
-
-#ifndef NO_CGI
-static pid_t spawn_process(struct mg_connection *conn, const char *prog,
- char *envblk, char *envp[], int fdin,
- int fdout, const char *dir)
-{
- pid_t pid;
- const char *interp;
-
- (void) envblk;
-
- if ((pid = fork()) == -1) {
- /* Parent */
- send_http_error(conn, 500, NULL,
- "Error: Creating CGI process\nfork(): %s", strerror(ERRNO));
- } else if (pid == 0) {
- /* Child */
- if (chdir(dir) != 0) {
- mg_cry(conn, "%s: chdir(%s): %s", __func__, dir, strerror(ERRNO));
- } else if (dup2(fdin, 0) == -1) {
- mg_cry(conn, "%s: dup2(%d, 0): %s", __func__, fdin, strerror(ERRNO));
- } else if (dup2(fdout, 1) == -1) {
- mg_cry(conn, "%s: dup2(%d, 1): %s", __func__, fdout, strerror(ERRNO));
- } else {
- /* Not redirecting stderr to stdout, to avoid output being littered
- with the error messages. */
- (void) close(fdin);
- (void) close(fdout);
-
- /* After exec, all signal handlers are restored to their default
- values, with one exception of SIGCHLD. According to
- POSIX.1-2001 and Linux's implementation, SIGCHLD's handler will
- leave unchanged after exec if it was set to be ignored. Restore
- it to default action. */
- signal(SIGCHLD, SIG_DFL);
-
- interp = conn->ctx->config[CGI_INTERPRETER];
- if (interp == NULL) {
- (void) execle(prog, prog, NULL, envp);
- mg_cry(conn, "%s: execle(%s): %s", __func__, prog, strerror(ERRNO));
- } else {
- (void) execle(interp, interp, prog, NULL, envp);
- mg_cry(conn, "%s: execle(%s %s): %s", __func__, interp, prog,
- strerror(ERRNO));
- }
- }
- exit(EXIT_FAILURE);
- }
-
- return pid;
-}
-#endif /* !NO_CGI */
-
-static int set_non_blocking_mode(SOCKET sock)
-{
- int flags;
-
- flags = fcntl(sock, F_GETFL, 0);
- (void) fcntl(sock, F_SETFL, flags | O_NONBLOCK);
-
- return 0;
-}
-#endif /* _WIN32 */
-
-/* Write data to the IO channel - opened file descriptor, socket or SSL
- descriptor. Return number of bytes written. */
-static int64_t push(FILE *fp, SOCKET sock, SSL *ssl, const char *buf, int64_t len)
-{
- int64_t sent;
- int n, k;
-
- (void) ssl; /* Get rid of warning */
- sent = 0;
- while (sent < len) {
-
- /* How many bytes we send in this iteration */
- k = len - sent > INT_MAX ? INT_MAX : (int) (len - sent);
-
-#ifndef NO_SSL
- if (ssl != NULL) {
- n = SSL_write(ssl, buf + sent, k);
- } else
-#endif
- if (fp != NULL) {
- n = (int) fwrite(buf + sent, 1, (size_t) k, fp);
- if (ferror(fp))
- n = -1;
- } else {
- n = send(sock, buf + sent, (size_t) k, MSG_NOSIGNAL);
- }
-
- if (n <= 0)
- break;
-
- sent += n;
- }
-
- return sent;
-}
-
-/* Read from IO channel - opened file descriptor, socket, or SSL descriptor.
- Return negative value on error, or number of bytes read on success. */
-static int pull(FILE *fp, struct mg_connection *conn, char *buf, int len)
-{
- int nread;
-
- if (fp != NULL) {
- /* Use read() instead of fread(), because if we're reading from the
- CGI pipe, fread() may block until IO buffer is filled up. We cannot
- afford to block and must pass all read bytes immediately to the
- client. */
- nread = read(fileno(fp), buf, (size_t) len);
-#ifndef NO_SSL
- } else if (conn->ssl != NULL) {
- nread = SSL_read(conn->ssl, buf, len);
-#endif
- } else {
- nread = recv(conn->client.sock, buf, (size_t) len, 0);
- }
-
- return conn->ctx->stop_flag ? -1 : nread;
-}
-
-static int pull_all(FILE *fp, struct mg_connection *conn, char *buf, int len)
-{
- int n, nread = 0;
-
- while (len > 0 && conn->ctx->stop_flag == 0) {
- n = pull(fp, conn, buf + nread, len);
- if (n < 0) {
- nread = n; /* Propagate the error */
- break;
- } else if (n == 0) {
- break; /* No more data to read */
- } else {
- conn->consumed_content += n;
- nread += n;
- len -= n;
- }
- }
-
- return nread;
-}
-
-int mg_read(struct mg_connection *conn, void *buf, size_t len)
-{
- int64_t n, buffered_len, nread;
- int64_t len64 = (int64_t)(len > INT_MAX ? INT_MAX : len); /* since the return value is int, we may not read more bytes */
- const char *body;
-
- /* If Content-Length is not set for a PUT or POST request, read until socket is closed */
- if (conn->consumed_content == 0 && conn->content_len == -1) {
- conn->content_len = INT64_MAX;
- conn->must_close = 1;
- }
-
- nread = 0;
- if (conn->consumed_content < conn->content_len) {
- /* Adjust number of bytes to read. */
- int64_t left_to_read = conn->content_len - conn->consumed_content;
- if (left_to_read < len64) {
- /* Do not reade more than the total content length of the request. */
- len64 = left_to_read;
- }
-
- /* Return buffered data */
- buffered_len = (int64_t)(conn->data_len) - (int64_t)conn->request_len - conn->consumed_content;
- if (buffered_len > 0) {
- if (len64 < buffered_len) {
- buffered_len = len64;
- }
- body = conn->buf + conn->request_len + conn->consumed_content;
- memcpy(buf, body, (size_t) buffered_len);
- len64 -= buffered_len;
- conn->consumed_content += buffered_len;
- nread += buffered_len;
- buf = (char *) buf + buffered_len;
- }
-
- /* We have returned all buffered data. Read new data from the remote
- socket. */
- if ((n = pull_all(NULL, conn, (char *) buf, (int)len64)) >= 0) {
- nread += n;
- } else {
- nread = (nread > 0 ? nread : n);
- }
- }
- return (int)nread;
-}
-
-int mg_write(struct mg_connection *conn, const void *buf, size_t len)
-{
- time_t now;
- int64_t n, total, allowed;
-
- if (conn->throttle > 0) {
- if ((now = time(NULL)) != conn->last_throttle_time) {
- conn->last_throttle_time = now;
- conn->last_throttle_bytes = 0;
- }
- allowed = conn->throttle - conn->last_throttle_bytes;
- if (allowed > (int64_t) len) {
- allowed = len;
- }
- if ((total = push(NULL, conn->client.sock, conn->ssl, (const char *) buf,
- (int64_t) allowed)) == allowed) {
- buf = (char *) buf + total;
- conn->last_throttle_bytes += total;
- while (total < (int64_t) len && conn->ctx->stop_flag == 0) {
- allowed = conn->throttle > (int64_t) len - total ?
- (int64_t) len - total : conn->throttle;
- if ((n = push(NULL, conn->client.sock, conn->ssl, (const char *) buf,
- (int64_t) allowed)) != allowed) {
- break;
- }
- sleep(1);
- conn->last_throttle_bytes = allowed;
- conn->last_throttle_time = time(NULL);
- buf = (char *) buf + n;
- total += n;
- }
- }
- } else {
- total = push(NULL, conn->client.sock, conn->ssl, (const char *) buf,
- (int64_t) len);
- }
- return (int) total;
-}
-
-/* Alternative alloc_vprintf() for non-compliant C runtimes */
-static int alloc_vprintf2(char **buf, const char *fmt, va_list ap)
-{
- va_list ap_copy;
- int size = MG_BUF_LEN;
- int len = -1;
-
- *buf = NULL;
- while (len == -1) {
- if (*buf) mg_free(*buf);
- *buf = (char *)mg_malloc(size *= 4);
- if (!*buf) break;
- va_copy(ap_copy, ap);
- len = vsnprintf(*buf, size, fmt, ap_copy);
- va_end(ap_copy);
- }
-
- return len;
-}
-
-/* Print message to buffer. If buffer is large enough to hold the message,
- return buffer. If buffer is to small, allocate large enough buffer on heap,
- and return allocated buffer. */
-static int alloc_vprintf(char **buf, size_t size, const char *fmt, va_list ap)
-{
- va_list ap_copy;
- int len;
-
- /* Windows is not standard-compliant, and vsnprintf() returns -1 if
- buffer is too small. Also, older versions of msvcrt.dll do not have
- _vscprintf(). However, if size is 0, vsnprintf() behaves correctly.
- Therefore, we make two passes: on first pass, get required message
- length.
- On second pass, actually print the message. */
- va_copy(ap_copy, ap);
- len = vsnprintf(NULL, 0, fmt, ap_copy);
- va_end(ap_copy);
-
- if (len < 0) {
- /* C runtime is not standard compliant, vsnprintf() returned -1.
- Switch to alternative code path that uses incremental allocations.
- */
- va_copy(ap_copy, ap);
- len = alloc_vprintf2(buf, fmt, ap);
- va_end(ap_copy);
- } else if (len > (int) size &&
- (size = len + 1) > 0 &&
- (*buf = (char *) mg_malloc(size)) == NULL) {
- len = -1; /* Allocation failed, mark failure */
- } else {
- va_copy(ap_copy, ap);
- IGNORE_UNUSED_RESULT(vsnprintf(*buf, size, fmt, ap_copy));
- va_end(ap_copy);
- }
-
- return len;
-}
-
-int mg_vprintf(struct mg_connection *conn, const char *fmt, va_list ap)
-{
- char mem[MG_BUF_LEN], *buf = mem;
- int len;
-
- if ((len = alloc_vprintf(&buf, sizeof(mem), fmt, ap)) > 0) {
- len = mg_write(conn, buf, (size_t) len);
- }
- if (buf != mem && buf != NULL) {
- mg_free(buf);
- }
-
- return len;
-}
-
-int mg_printf(struct mg_connection *conn, const char *fmt, ...)
-{
- va_list ap;
- int result;
-
- va_start(ap, fmt);
- result = mg_vprintf(conn, fmt, ap);
- va_end(ap);
-
- return result;
-}
-
-int mg_url_decode(const char *src, int src_len, char *dst,
- int dst_len, int is_form_url_encoded)
-{
- int i, j, a, b;
-#define HEXTOI(x) (isdigit(x) ? x - '0' : x - 'W')
-
- for (i = j = 0; i < src_len && j < dst_len - 1; i++, j++) {
- if (i < src_len - 2 && src[i] == '%' &&
- isxdigit(* (const unsigned char *) (src + i + 1)) &&
- isxdigit(* (const unsigned char *) (src + i + 2))) {
- a = tolower(* (const unsigned char *) (src + i + 1));
- b = tolower(* (const unsigned char *) (src + i + 2));
- dst[j] = (char) ((HEXTOI(a) << 4) | HEXTOI(b));
- i += 2;
- } else if (is_form_url_encoded && src[i] == '+') {
- dst[j] = ' ';
- } else {
- dst[j] = src[i];
- }
- }
-
- dst[j] = '\0'; /* Null-terminate the destination */
-
- return i >= src_len ? j : -1;
-}
-
-int mg_get_var(const char *data, size_t data_len, const char *name,
- char *dst, size_t dst_len)
-{
- return mg_get_var2(data,data_len,name,dst,dst_len,0);
-}
-
-int mg_get_var2(const char *data, size_t data_len, const char *name,
- char *dst, size_t dst_len, size_t occurrence)
-{
- const char *p, *e, *s;
- size_t name_len;
- int len;
-
- if (dst == NULL || dst_len == 0) {
- len = -2;
- } else if (data == NULL || name == NULL || data_len == 0) {
- len = -1;
- dst[0] = '\0';
- } else {
- name_len = strlen(name);
- e = data + data_len;
- len = -1;
- dst[0] = '\0';
-
- /* data is "var1=val1&var2=val2...". Find variable first */
- for (p = data; p + name_len < e; p++) {
- if ((p == data || p[-1] == '&') && p[name_len] == '=' &&
- !mg_strncasecmp(name, p, name_len) && 0 == occurrence--) {
-
- /* Point p to variable value */
- p += name_len + 1;
-
- /* Point s to the end of the value */
- s = (const char *) memchr(p, '&', (size_t)(e - p));
- if (s == NULL) {
- s = e;
- }
- assert(s >= p);
-
- /* Decode variable into destination buffer */
- len = mg_url_decode(p, (int)(s - p), dst, (int)dst_len, 1);
-
- /* Redirect error code from -1 to -2 (destination buffer too
- small). */
- if (len == -1) {
- len = -2;
- }
- break;
- }
- }
- }
-
- return len;
-}
-
-int mg_get_cookie(const char *cookie_header, const char *var_name,
- char *dst, size_t dst_size)
-{
- const char *s, *p, *end;
- int name_len, len = -1;
-
- if (dst == NULL || dst_size == 0) {
- len = -2;
- } else if (var_name == NULL || (s = cookie_header) == NULL) {
- len = -1;
- dst[0] = '\0';
- } else {
- name_len = (int) strlen(var_name);
- end = s + strlen(s);
- dst[0] = '\0';
-
- for (; (s = mg_strcasestr(s, var_name)) != NULL; s += name_len) {
-
<TRUNCATED>
[10/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_configured/private/include/discovery_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_configured/private/include/discovery_impl.h b/remote_services/discovery_configured/private/include/discovery_impl.h
deleted file mode 100644
index 0414eac..0000000
--- a/remote_services/discovery_configured/private/include/discovery_impl.h
+++ /dev/null
@@ -1,62 +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.
- */
-/*
- * discovery_impl.h
- *
- * \date Sep 29, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef DISCOVERY_IMPL_H_
-#define DISCOVERY_IMPL_H_
-
-#include "bundle_context.h"
-#include "service_reference.h"
-
-#include "endpoint_description.h"
-#include "endpoint_listener.h"
-
-#include "endpoint_discovery_poller.h"
-#include "endpoint_discovery_server.h"
-
-#include "log_helper.h"
-
-#define DEFAULT_SERVER_IP "127.0.0.1"
-#define DEFAULT_SERVER_PORT "9999"
-#define DEFAULT_SERVER_PATH "/org.apache.celix.discovery.configured"
-#define DEFAULT_POLL_ENDPOINTS "http://localhost:9999/org.apache.celix.discovery.configured"
-
-
-struct discovery {
- bundle_context_pt context;
-
- celix_thread_mutex_t listenerReferencesMutex;
- celix_thread_mutex_t discoveredServicesMutex;
-
- hash_map_pt listenerReferences; //key=serviceReference, value=nop
- hash_map_pt discoveredServices; //key=endpointId (string), value=endpoint_description_pt
-
- endpoint_discovery_poller_pt poller;
- endpoint_discovery_server_pt server;
-
- log_helper_pt loghelper;
-};
-
-#endif /* DISCOVERY_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_configured/private/src/desc.xml
----------------------------------------------------------------------
diff --git a/remote_services/discovery_configured/private/src/desc.xml b/remote_services/discovery_configured/private/src/desc.xml
deleted file mode 100644
index 5998992..0000000
--- a/remote_services/discovery_configured/private/src/desc.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- *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.
- -->
-<endpoint-descriptions xmlns="http://www.osgi.org/xmlns/rsa/v1.0.0">
- <endpoint-description>
- <property name="service.intents">
- <list>
- <value>SOAP</value>
- <value>HTTP</value>
- </list>
- </property>
- <property name="endpoint.id" value="http://ws.acme.com:9000/hello" />
- <property name="objectClass" value="com.acme.Foo" />
- <property name="endpoint.package.version.com.acme" value="4.2" />
- <property name="service.imported.configs" value="com.acme" />
- <property name="com.acme.ws.xml">
- <xml>
- <config xmlns="http://acme.com/defs">
- <port>1029</port>
- <host>www.acme.com</host>
- </config>
- </xml>
- </property>
- </endpoint-description>
-</endpoint-descriptions>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_configured/private/src/discovery_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_configured/private/src/discovery_impl.c b/remote_services/discovery_configured/private/src/discovery_impl.c
deleted file mode 100644
index 35a0c71..0000000
--- a/remote_services/discovery_configured/private/src/discovery_impl.c
+++ /dev/null
@@ -1,123 +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.
- */
-/*
- * discovery_impl.c
- *
- * \date Aug 8, 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <netdb.h>
-
-#include "celix_threads.h"
-#include "bundle_context.h"
-#include "utils.h"
-#include "log_helper.h"
-
-#include "discovery.h"
-#include "discovery_impl.h"
-
-
-celix_status_t discovery_create(bundle_context_pt context, discovery_pt *discovery) {
- celix_status_t status;
-
- *discovery = malloc(sizeof(struct discovery));
- if (!*discovery) {
- status = CELIX_ENOMEM;
- }
- else {
- (*discovery)->context = context;
- (*discovery)->poller = NULL;
- (*discovery)->server = NULL;
-
- (*discovery)->listenerReferences = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
- (*discovery)->discoveredServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
-
- status = celixThreadMutex_create(&(*discovery)->listenerReferencesMutex, NULL);
- status = celixThreadMutex_create(&(*discovery)->discoveredServicesMutex, NULL);
-
- logHelper_create(context, &(*discovery)->loghelper);
- }
-
- return status;
-}
-
-celix_status_t discovery_start(discovery_pt discovery) {
- celix_status_t status;
-
- logHelper_start(discovery->loghelper);
-
- status = endpointDiscoveryPoller_create(discovery, discovery->context, &discovery->poller);
- if (status != CELIX_SUCCESS) {
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- status = endpointDiscoveryServer_create(discovery, discovery->context, &discovery->server);
- if (status != CELIX_SUCCESS) {
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- return status;
-}
-
-celix_status_t discovery_stop(discovery_pt discovery) {
- celix_status_t status;
-
- status = endpointDiscoveryServer_destroy(discovery->server);
- status = endpointDiscoveryPoller_destroy(discovery->poller);
-
- logHelper_stop(discovery->loghelper);
-
- return status;
-}
-
-celix_status_t discovery_destroy(discovery_pt discovery) {
- celix_status_t status = CELIX_SUCCESS;
-
- discovery->context = NULL;
- discovery->poller = NULL;
- discovery->server = NULL;
-
- celixThreadMutex_lock(&discovery->discoveredServicesMutex);
-
- hashMap_destroy(discovery->discoveredServices, false, false);
- discovery->discoveredServices = NULL;
-
- celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
-
- celixThreadMutex_destroy(&discovery->discoveredServicesMutex);
-
- celixThreadMutex_lock(&discovery->listenerReferencesMutex);
-
- hashMap_destroy(discovery->listenerReferences, false, false);
- discovery->listenerReferences = NULL;
-
- celixThreadMutex_unlock(&discovery->listenerReferencesMutex);
-
- celixThreadMutex_destroy(&discovery->listenerReferencesMutex);
-
- logHelper_destroy(&discovery->loghelper);
-
- free(discovery);
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_configured/src/desc.xml
----------------------------------------------------------------------
diff --git a/remote_services/discovery_configured/src/desc.xml b/remote_services/discovery_configured/src/desc.xml
new file mode 100644
index 0000000..5998992
--- /dev/null
+++ b/remote_services/discovery_configured/src/desc.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ *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.
+ -->
+<endpoint-descriptions xmlns="http://www.osgi.org/xmlns/rsa/v1.0.0">
+ <endpoint-description>
+ <property name="service.intents">
+ <list>
+ <value>SOAP</value>
+ <value>HTTP</value>
+ </list>
+ </property>
+ <property name="endpoint.id" value="http://ws.acme.com:9000/hello" />
+ <property name="objectClass" value="com.acme.Foo" />
+ <property name="endpoint.package.version.com.acme" value="4.2" />
+ <property name="service.imported.configs" value="com.acme" />
+ <property name="com.acme.ws.xml">
+ <xml>
+ <config xmlns="http://acme.com/defs">
+ <port>1029</port>
+ <host>www.acme.com</host>
+ </config>
+ </xml>
+ </property>
+ </endpoint-description>
+</endpoint-descriptions>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_configured/src/discovery_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_configured/src/discovery_impl.c b/remote_services/discovery_configured/src/discovery_impl.c
new file mode 100644
index 0000000..35a0c71
--- /dev/null
+++ b/remote_services/discovery_configured/src/discovery_impl.c
@@ -0,0 +1,123 @@
+/**
+ * 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.
+ */
+/*
+ * discovery_impl.c
+ *
+ * \date Aug 8, 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <netdb.h>
+
+#include "celix_threads.h"
+#include "bundle_context.h"
+#include "utils.h"
+#include "log_helper.h"
+
+#include "discovery.h"
+#include "discovery_impl.h"
+
+
+celix_status_t discovery_create(bundle_context_pt context, discovery_pt *discovery) {
+ celix_status_t status;
+
+ *discovery = malloc(sizeof(struct discovery));
+ if (!*discovery) {
+ status = CELIX_ENOMEM;
+ }
+ else {
+ (*discovery)->context = context;
+ (*discovery)->poller = NULL;
+ (*discovery)->server = NULL;
+
+ (*discovery)->listenerReferences = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
+ (*discovery)->discoveredServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+
+ status = celixThreadMutex_create(&(*discovery)->listenerReferencesMutex, NULL);
+ status = celixThreadMutex_create(&(*discovery)->discoveredServicesMutex, NULL);
+
+ logHelper_create(context, &(*discovery)->loghelper);
+ }
+
+ return status;
+}
+
+celix_status_t discovery_start(discovery_pt discovery) {
+ celix_status_t status;
+
+ logHelper_start(discovery->loghelper);
+
+ status = endpointDiscoveryPoller_create(discovery, discovery->context, &discovery->poller);
+ if (status != CELIX_SUCCESS) {
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+
+ status = endpointDiscoveryServer_create(discovery, discovery->context, &discovery->server);
+ if (status != CELIX_SUCCESS) {
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+
+ return status;
+}
+
+celix_status_t discovery_stop(discovery_pt discovery) {
+ celix_status_t status;
+
+ status = endpointDiscoveryServer_destroy(discovery->server);
+ status = endpointDiscoveryPoller_destroy(discovery->poller);
+
+ logHelper_stop(discovery->loghelper);
+
+ return status;
+}
+
+celix_status_t discovery_destroy(discovery_pt discovery) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ discovery->context = NULL;
+ discovery->poller = NULL;
+ discovery->server = NULL;
+
+ celixThreadMutex_lock(&discovery->discoveredServicesMutex);
+
+ hashMap_destroy(discovery->discoveredServices, false, false);
+ discovery->discoveredServices = NULL;
+
+ celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
+
+ celixThreadMutex_destroy(&discovery->discoveredServicesMutex);
+
+ celixThreadMutex_lock(&discovery->listenerReferencesMutex);
+
+ hashMap_destroy(discovery->listenerReferences, false, false);
+ discovery->listenerReferences = NULL;
+
+ celixThreadMutex_unlock(&discovery->listenerReferencesMutex);
+
+ celixThreadMutex_destroy(&discovery->listenerReferencesMutex);
+
+ logHelper_destroy(&discovery->loghelper);
+
+ free(discovery);
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_configured/src/discovery_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_configured/src/discovery_impl.h b/remote_services/discovery_configured/src/discovery_impl.h
new file mode 100644
index 0000000..0414eac
--- /dev/null
+++ b/remote_services/discovery_configured/src/discovery_impl.h
@@ -0,0 +1,62 @@
+/**
+ *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.
+ */
+/*
+ * discovery_impl.h
+ *
+ * \date Sep 29, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef DISCOVERY_IMPL_H_
+#define DISCOVERY_IMPL_H_
+
+#include "bundle_context.h"
+#include "service_reference.h"
+
+#include "endpoint_description.h"
+#include "endpoint_listener.h"
+
+#include "endpoint_discovery_poller.h"
+#include "endpoint_discovery_server.h"
+
+#include "log_helper.h"
+
+#define DEFAULT_SERVER_IP "127.0.0.1"
+#define DEFAULT_SERVER_PORT "9999"
+#define DEFAULT_SERVER_PATH "/org.apache.celix.discovery.configured"
+#define DEFAULT_POLL_ENDPOINTS "http://localhost:9999/org.apache.celix.discovery.configured"
+
+
+struct discovery {
+ bundle_context_pt context;
+
+ celix_thread_mutex_t listenerReferencesMutex;
+ celix_thread_mutex_t discoveredServicesMutex;
+
+ hash_map_pt listenerReferences; //key=serviceReference, value=nop
+ hash_map_pt discoveredServices; //key=endpointId (string), value=endpoint_description_pt
+
+ endpoint_discovery_poller_pt poller;
+ endpoint_discovery_server_pt server;
+
+ log_helper_pt loghelper;
+};
+
+#endif /* DISCOVERY_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_etcd/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/discovery_etcd/CMakeLists.txt b/remote_services/discovery_etcd/CMakeLists.txt
index b8955de..4168281 100644
--- a/remote_services/discovery_etcd/CMakeLists.txt
+++ b/remote_services/discovery_etcd/CMakeLists.txt
@@ -20,42 +20,19 @@ if (RSA_DISCOVERY_ETCD)
find_package(CURL REQUIRED)
find_package(LibXml2 REQUIRED)
find_package(Jansson REQUIRED)
-
- include_directories("${CURL_INCLUDE_DIR}")
- include_directories("${JANSSON_INCLUDE_DIR}")
- include_directories("${LIBXML2_INCLUDE_DIR}")
- include_directories("${PROJECT_SOURCE_DIR}/etcdlib/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/discovery/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/discovery_etcd/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
- include_directories("private/include")
add_bundle(discovery_etcd
VERSION 0.9.0
SYMBOLIC_NAME "apache_celix_rsa_discovery_etcd"
NAME "Apache Celix RSA Discovery ETCD"
SOURCES
- src/discovery_impl.c
- src/etcd_watcher.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/discovery_activator.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/discovery.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_descriptor_reader.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_descriptor_writer.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_discovery_poller.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_discovery_server.c
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
- ${PROJECT_SOURCE_DIR}/remote_services/utils/private/src/civetweb.c
+ src/discovery_impl.c
+ src/etcd_watcher.c
)
target_link_libraries(discovery_etcd PRIVATE Celix::log_helper)
- target_include_directories(discovery_etcd PRIVATE src ../discovery/private/include)
+ target_include_directories(discovery_etcd PRIVATE src )
+ target_include_directories(discovery_etcd PRIVATE ${CURL_INCLUDE_DIR} ${JANSSON_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR})
+ target_link_libraries(discovery_etcd PRIVATE ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} ${JANSSON_LIBRARIES} discovery_common)
install_bundle(discovery_etcd)
-
- target_link_libraries(discovery_etcd PRIVATE Celix::etcdlib ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} ${JANSSON_LIBRARIES})
-
endif (RSA_DISCOVERY_ETCD)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_shm/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/CMakeLists.txt b/remote_services/discovery_shm/CMakeLists.txt
index 862096c..dff403d 100644
--- a/remote_services/discovery_shm/CMakeLists.txt
+++ b/remote_services/discovery_shm/CMakeLists.txt
@@ -19,40 +19,25 @@ celix_subproject(RSA_DISCOVERY_SHM "Option to enable building the Discovery (SHM
if (RSA_DISCOVERY_SHM)
find_package(CURL REQUIRED)
find_package(LibXml2 REQUIRED)
-
- include_directories("${CURL_INCLUDE_DIR}")
- include_directories("${LIBXML2_INCLUDE_DIR}")
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/discovery/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/discovery_shm/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
- include_directories("private/include")
add_bundle(discovery_shm
VERSION 0.0.1
SYMBOLIC_NAME "apache_celix_rsa_discovery_shm"
NAME "Apache Celix RSA Discovery SHM"
SOURCES
- private/src/discovery_shm
- private/src/discovery_shmWatcher
- private/src/discovery_impl
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/discovery_activator.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/discovery.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_descriptor_reader.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_descriptor_writer.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_discovery_poller.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_discovery_server.c
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
- ${PROJECT_SOURCE_DIR}/remote_services/utils/private/src/civetweb.c
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
+ src/discovery_shm.c
+ src/discovery_shmWatcher.c
+ src/discovery_impl.c
)
+ target_include_directories(discovery_shm PRIVATE
+ src
+ ${LIBXML2_INCLUDE_DIR}
+ ${CURL_INCLUDE_DIR}
+ )
+ target_link_libraries(discovery_shm PRIVATE Celix::framework ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} discovery_common)
install_bundle(discovery_shm)
- target_link_libraries(discovery_shm celix_framework ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES})
+
endif (RSA_DISCOVERY_SHM)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_shm/private/include/discovery_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/private/include/discovery_impl.h b/remote_services/discovery_shm/private/include/discovery_impl.h
deleted file mode 100644
index c7206bd..0000000
--- a/remote_services/discovery_shm/private/include/discovery_impl.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.
- */
-/*
- * discovery_impl.h
- *
- * \date Oct 01, 2014
- * \author <a href="mailto:celix-dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef DISCOVERY_IMPL_H_
-#define DISCOVERY_IMPL_H_
-
-#include "bundle_context.h"
-#include "service_reference.h"
-
-#include "endpoint_description.h"
-#include "endpoint_listener.h"
-
-#include "endpoint_discovery_poller.h"
-#include "endpoint_discovery_server.h"
-#include "discovery_shmWatcher.h"
-
-
-#define DEFAULT_SERVER_IP "127.0.0.1"
-#define DEFAULT_SERVER_PORT "9999"
-#define DEFAULT_SERVER_PATH "/org.apache.celix.discovery.shm"
-#define DEFAULT_POLL_ENDPOINTS "http://localhost:9999/org.apache.celix.discovery.shm"
-
-#define MAX_ROOTNODE_LENGTH 64
-#define MAX_LOCALNODE_LENGTH 256
-
-
-struct discovery {
- bundle_context_pt context;
-
- celix_thread_mutex_t listenerReferencesMutex;
- celix_thread_mutex_t discoveredServicesMutex;
-
- hash_map_pt listenerReferences; //key=serviceReference, value=nop
- hash_map_pt discoveredServices; //key=endpointId (string), value=endpoint_description_pt
-
- shm_watcher_pt watcher;
- endpoint_discovery_poller_pt poller;
- endpoint_discovery_server_pt server;
-
- log_helper_pt loghelper;
-};
-
-#endif /* DISCOVERY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_shm/private/include/discovery_shm.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/private/include/discovery_shm.h b/remote_services/discovery_shm/private/include/discovery_shm.h
deleted file mode 100644
index 9c4593b..0000000
--- a/remote_services/discovery_shm/private/include/discovery_shm.h
+++ /dev/null
@@ -1,56 +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.
- */
-
-/*
- * shm.h
- *
- * \date 26 Jul 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-
-
-#ifndef _DISCOVERY_SHM_H_
-#define _DISCOVERY_SHM_H_
-
-#include <celix_errno.h>
-
-#define SHM_ENTRY_MAX_KEY_LENGTH 256
-#define SHM_ENTRY_MAX_VALUE_LENGTH 256
-
-// defines the time-to-live in seconds
-#define SHM_ENTRY_DEFAULT_TTL 60
-
-// we currently support 64 separate discovery instances
-#define SHM_DATA_MAX_ENTRIES 64
-
-typedef struct shmData* shmData_pt;
-
-/* creates a new shared memory block */
-celix_status_t discoveryShm_create(shmData_pt* data);
-celix_status_t discoveryShm_attach(shmData_pt* data);
-celix_status_t discoveryShm_set(shmData_pt data, char *key, char* value);
-celix_status_t discoveryShm_get(shmData_pt data, char* key, char* value);
-celix_status_t discoveryShm_getKeys(shmData_pt data, char** keys, int* size);
-celix_status_t discoveryShm_remove(shmData_pt data, char* key);
-celix_status_t discoveryShm_detach(shmData_pt data);
-celix_status_t discoveryShm_destroy(shmData_pt data);
-
-#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_shm/private/include/discovery_shmWatcher.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/private/include/discovery_shmWatcher.h b/remote_services/discovery_shm/private/include/discovery_shmWatcher.h
deleted file mode 100644
index ff70f72..0000000
--- a/remote_services/discovery_shm/private/include/discovery_shmWatcher.h
+++ /dev/null
@@ -1,40 +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.
- */
-/*
- * shm_watcher.h
- *
- * \date 30 Sep 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef DISCOVERY_SHM_WATCHER_H_
-#define DISCOVERY_SHM_WATCHER_H_
-
-#include "celix_errno.h"
-#include "discovery.h"
-#include "endpoint_discovery_poller.h"
-
-typedef struct shm_watcher *shm_watcher_pt;
-
-celix_status_t discoveryShmWatcher_create(discovery_pt discovery);
-celix_status_t discoveryShmWatcher_destroy(discovery_pt discovery);
-
-
-#endif /* DISCOVERY_SHM_WATCHER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_shm/private/src/discovery_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/private/src/discovery_impl.c b/remote_services/discovery_shm/private/src/discovery_impl.c
deleted file mode 100644
index 2604595..0000000
--- a/remote_services/discovery_shm/private/src/discovery_impl.c
+++ /dev/null
@@ -1,163 +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.
- */
-/*
- * discovery_impl.c
- *
- * \date Aug 8, 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdbool.h>
-#include <netdb.h>
-#include <netinet/in.h>
-
-#include "constants.h"
-#include "celix_threads.h"
-#include "bundle_context.h"
-#include "array_list.h"
-#include "utils.h"
-#include "celix_errno.h"
-#include "filter.h"
-#include "service_reference.h"
-#include "service_registration.h"
-#include "remote_constants.h"
-
-
-#include "discovery.h"
-#include "discovery_impl.h"
-#include "discovery_shmWatcher.h"
-#include "endpoint_discovery_poller.h"
-#include "endpoint_discovery_server.h"
-
-
-
-celix_status_t discovery_create(bundle_context_pt context, discovery_pt *discovery) {
- celix_status_t status = CELIX_SUCCESS;
-
- *discovery = calloc(1, sizeof(struct discovery));
- if (!*discovery) {
- status = CELIX_ENOMEM;
- } else {
- (*discovery)->context = context;
- (*discovery)->poller = NULL;
- (*discovery)->server = NULL;
-
- (*discovery)->listenerReferences = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
- (*discovery)->discoveredServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
-
- celixThreadMutex_create(&(*discovery)->listenerReferencesMutex, NULL);
- celixThreadMutex_create(&(*discovery)->discoveredServicesMutex, NULL);
-
- if (logHelper_create(context, &(*discovery)->loghelper) == CELIX_SUCCESS) {
- logHelper_start((*discovery)->loghelper);
- }
- }
-
- return status;
-}
-
-
-
-celix_status_t discovery_destroy(discovery_pt discovery) {
- celix_status_t status = CELIX_SUCCESS;
-
- discovery->context = NULL;
- discovery->poller = NULL;
- discovery->server = NULL;
-
- celixThreadMutex_lock(&discovery->discoveredServicesMutex);
-
- hashMap_destroy(discovery->discoveredServices, false, false);
- discovery->discoveredServices = NULL;
-
- celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
-
- celixThreadMutex_destroy(&discovery->discoveredServicesMutex);
-
- celixThreadMutex_lock(&discovery->listenerReferencesMutex);
-
- hashMap_destroy(discovery->listenerReferences, false, false);
- discovery->listenerReferences = NULL;
-
- celixThreadMutex_unlock(&discovery->listenerReferencesMutex);
-
- celixThreadMutex_destroy(&discovery->listenerReferencesMutex);
-
-
-
-
- free(discovery);
-
- return status;
-}
-
-celix_status_t discovery_start(discovery_pt discovery) {
- celix_status_t status;
-
- status = endpointDiscoveryPoller_create(discovery, discovery->context, &discovery->poller);
- if (status == CELIX_SUCCESS) {
- status = endpointDiscoveryServer_create(discovery, discovery->context, &discovery->server);
- }
-
- if (status == CELIX_SUCCESS) {
- status = discoveryShmWatcher_create(discovery);
- }
-
- return status;
-}
-
-celix_status_t discovery_stop(discovery_pt discovery) {
- celix_status_t status;
-
- status = discoveryShmWatcher_destroy(discovery);
-
- if (status == CELIX_SUCCESS) {
- status = endpointDiscoveryServer_destroy(discovery->server);
- }
-
- endpointDiscoveryPoller_destroy(discovery->poller);
-
- if (status == CELIX_SUCCESS) {
- hash_map_iterator_pt iter;
-
- celixThreadMutex_lock(&discovery->discoveredServicesMutex);
-
- iter = hashMapIterator_create(discovery->discoveredServices);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- endpoint_description_pt endpoint = hashMapEntry_getValue(entry);
-
- discovery_informEndpointListeners(discovery, endpoint, false);
- }
- hashMapIterator_destroy(iter);
-
- celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
-
- logHelper_stop(discovery->loghelper);
- logHelper_destroy(&discovery->loghelper);
- }
-
- return status;
-}
-
-
-
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_shm/private/src/discovery_shm.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/private/src/discovery_shm.c b/remote_services/discovery_shm/private/src/discovery_shm.c
deleted file mode 100644
index 1b1170e..0000000
--- a/remote_services/discovery_shm/private/src/discovery_shm.c
+++ /dev/null
@@ -1,284 +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.
- */
-
-/*
- * discovery_shm.c
- *
- * \date 26 Jul 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-
-
-#include <stdio.h>
-#include <pthread.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-#include <sys/types.h>
-#include <sys/sem.h>
-#include <sys/shm.h>
-
-#include <celix_errno.h>
-#include <celix_threads.h>
-
-#include "discovery_shm.h"
-
-#define DISCOVERY_SHM_MEMSIZE 262144
-#define DISCOVERY_SHM_FILENAME "/dev/null"
-#define DISCOVERY_SHM_FTOK_ID 50
-#define DISCOVERY_SEM_FILENAME "/dev/null"
-#define DISCOVERY_SEM_FTOK_ID 54
-
-struct shmEntry {
- char key[SHM_ENTRY_MAX_KEY_LENGTH];
- char value[SHM_ENTRY_MAX_VALUE_LENGTH];
-
- time_t expires;
-};
-
-typedef struct shmEntry shmEntry;
-
-struct shmData {
- shmEntry entries[SHM_DATA_MAX_ENTRIES];
- int numOfEntries;
- int shmId;
-
- celix_thread_mutex_t globalLock;
-};
-
-void* shmAdress;
-
-static celix_status_t discoveryShm_removeWithIndex(shmData_pt data, int index);
-
-/* returns the ftok key to identify shared memory*/
-static key_t discoveryShm_getKey() {
- return ftok(DISCOVERY_SHM_FILENAME, DISCOVERY_SHM_FTOK_ID);
-}
-
-/* creates a new shared memory block */
-celix_status_t discoveryShm_create(shmData_pt* data) {
- celix_status_t status;
-
- shmData_pt shmData = calloc(1, sizeof(*shmData));
- key_t shmKey = discoveryShm_getKey();
-
- if (!shmData) {
- status = CELIX_ENOMEM;
- } else if ((shmData->shmId = shmget(shmKey, DISCOVERY_SHM_MEMSIZE, IPC_CREAT | 0666)) < 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else if ((shmAdress = shmat(shmData->shmId, 0, 0)) == (char*) -1) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- celix_thread_mutexattr_t threadAttr;
-
- shmData->numOfEntries = 0;
-
- status = celixThreadMutexAttr_create(&threadAttr);
-
-#ifdef LINUX
- if (status == CELIX_SUCCESS) {
- // This is Linux specific
- status = pthread_mutexattr_setrobust(&threadAttr, PTHREAD_MUTEX_ROBUST);
- }
-#endif
-
- if (status == CELIX_SUCCESS) {
- status = celixThreadMutex_create(&shmData->globalLock, &threadAttr);
- }
-
- if (status == CELIX_SUCCESS) {
- memcpy(shmAdress, shmData, sizeof(struct shmData));
- (*data) = shmAdress;
- }
- }
-
- free(shmData);
-
- return status;
-}
-
-celix_status_t discoveryShm_attach(shmData_pt* data) {
- celix_status_t status = CELIX_SUCCESS;
- key_t shmKey = ftok(DISCOVERY_SHM_FILENAME, DISCOVERY_SHM_FTOK_ID);
- int shmId = -1;
-
- if ((shmId = shmget(shmKey, DISCOVERY_SHM_MEMSIZE, 0666)) < 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- }
-
- /* shmat has a curious return value of (void*)-1 in case of error */
- void *mem=shmat(shmId, 0, 0);
- if(mem==((void*)-1)){
- status = CELIX_BUNDLE_EXCEPTION;
- }
- else{
- (*data)=mem;
- }
-
- return status;
-}
-
-static celix_status_t discoveryShm_getwithIndex(shmData_pt data, char* key, char* value, int* index) {
- celix_status_t status = CELIX_BUNDLE_EXCEPTION;
- time_t currentTime = time(NULL);
- unsigned int i;
-
- for (i = 0; i < data->numOfEntries && status != CELIX_SUCCESS; i++) {
- shmEntry entry = data->entries[i];
- // check if entry is still valid
- if (data->entries[i].expires < currentTime) {
- discoveryShm_removeWithIndex(data, i);
- } else if (strcmp(entry.key, key) == 0) {
- if (value) {
- strcpy(value, entry.value);
- }
- if (index) {
- (*index) = i;
- }
- status = CELIX_SUCCESS;
- }
- }
-
- return status;
-}
-
-celix_status_t discoveryShm_getKeys(shmData_pt data, char** keys, int* size) {
- celix_status_t status;
-
- status = celixThreadMutex_lock(&data->globalLock);
-
- if (status == CELIX_SUCCESS) {
- unsigned int i = 0;
- for (i = 0; i < data->numOfEntries; i++) {
- shmEntry entry = data->entries[i];
-
- if (strlen(entry.key)>0) {
- snprintf(keys[i], SHM_ENTRY_MAX_KEY_LENGTH, "%s", entry.key);
- }
- }
-
- (*size) = i;
-
- celixThreadMutex_unlock(&data->globalLock);
- }
-
- return status;
-}
-
-celix_status_t discoveryShm_set(shmData_pt data, char *key, char* value) {
- celix_status_t status;
- int index = -1;
-
- if (data->numOfEntries >= SHM_DATA_MAX_ENTRIES) {
- status = CELIX_ILLEGAL_STATE;
- } else {
- status = celixThreadMutex_lock(&data->globalLock);
-
- if (status == CELIX_SUCCESS) {
- // check if key already there
- status = discoveryShm_getwithIndex(data, key, NULL, &index);
- if (status != CELIX_SUCCESS) {
- index = data->numOfEntries;
-
- snprintf(data->entries[index].key, SHM_ENTRY_MAX_KEY_LENGTH, "%s", key);
- data->numOfEntries++;
-
- status = CELIX_SUCCESS;
- }
-
- snprintf(data->entries[index].value, SHM_ENTRY_MAX_VALUE_LENGTH, "%s", value);
- data->entries[index].expires = (time(NULL) + SHM_ENTRY_DEFAULT_TTL);
-
- celixThreadMutex_unlock(&data->globalLock);
- }
- }
-
- return status;
-}
-
-celix_status_t discoveryShm_get(shmData_pt data, char* key, char* value) {
- celix_status_t status;
-
- status = celixThreadMutex_lock(&data->globalLock);
-
- if (status == CELIX_SUCCESS) {
- status = discoveryShm_getwithIndex(data, key, value, NULL);
-
- celixThreadMutex_unlock(&data->globalLock);
- }
-
- return status;
-}
-
-static celix_status_t discoveryShm_removeWithIndex(shmData_pt data, int index) {
- celix_status_t status = CELIX_SUCCESS;
-
- data->numOfEntries--;
- if (index < data->numOfEntries) {
- memcpy((void*) &data->entries[index], (void*) &data->entries[index + 1], ((data->numOfEntries - index) * sizeof(struct shmEntry)));
- }
-
- return status;
-}
-
-celix_status_t discoveryShm_remove(shmData_pt data, char* key) {
- celix_status_t status;
- int index = -1;
-
- status = celixThreadMutex_lock(&data->globalLock);
-
- if (status == CELIX_SUCCESS) {
- status = discoveryShm_getwithIndex(data, key, NULL, &index);
-
- if (status == CELIX_SUCCESS) {
- status = discoveryShm_removeWithIndex(data, index);
- }
-
- celixThreadMutex_unlock(&data->globalLock);
- }
-
- return status;
-}
-
-celix_status_t discoveryShm_detach(shmData_pt data) {
- celix_status_t status = CELIX_BUNDLE_EXCEPTION;
-
- if (data->numOfEntries == 0) {
- status = discoveryShm_destroy(data);
- }
- else if (shmdt(shmAdress) == 0) {
- status = CELIX_SUCCESS;
- }
-
- return status;
-}
-
-celix_status_t discoveryShm_destroy(shmData_pt data) {
- celix_status_t status = CELIX_BUNDLE_EXCEPTION;
-
- if (shmctl(data->shmId, IPC_RMID, 0) == 0) {
- status = CELIX_SUCCESS;
- }
-
- return status;
-
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_shm/private/src/discovery_shmWatcher.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/private/src/discovery_shmWatcher.c b/remote_services/discovery_shm/private/src/discovery_shmWatcher.c
deleted file mode 100644
index 6460de8..0000000
--- a/remote_services/discovery_shm/private/src/discovery_shmWatcher.c
+++ /dev/null
@@ -1,246 +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.
- */
-/*
- * discovery_shmWatcher.c
- *
- * \date 16 Sep 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdbool.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdio.h>
-
-
-#include "celix_log.h"
-#include "constants.h"
-#include "discovery_impl.h"
-
-#include "discovery_shm.h"
-#include "discovery_shmWatcher.h"
-
-#include "endpoint_discovery_poller.h"
-
-struct shm_watcher {
- shmData_pt shmData;
- celix_thread_t watcherThread;
- celix_thread_mutex_t watcherLock;
-
- volatile bool running;
-};
-
-// note that the rootNode shouldn't have a leading slash
-static celix_status_t discoveryShmWatcher_getRootPath(char* rootNode) {
- celix_status_t status = CELIX_SUCCESS;
-
- strcpy(rootNode, "discovery");
-
- return status;
-}
-
-static celix_status_t discoveryShmWatcher_getLocalNodePath(bundle_context_pt context, char* localNodePath) {
- celix_status_t status;
- char rootPath[MAX_ROOTNODE_LENGTH];
- const char* uuid = NULL;
-
- status = discoveryShmWatcher_getRootPath(&rootPath[0]);
-
- if (status == CELIX_SUCCESS) {
- status = bundleContext_getProperty(context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
- }
-
- if (status == CELIX_SUCCESS) {
- if (rootPath[strlen(&rootPath[0]) - 1] == '/') {
- snprintf(localNodePath, MAX_LOCALNODE_LENGTH, "%s%s", &rootPath[0], uuid);
- } else {
- snprintf(localNodePath, MAX_LOCALNODE_LENGTH, "%s/%s", &rootPath[0], uuid);
- }
- }
-
- return status;
-}
-
-/* retrieves all endpoints from shm and syncs them with the ones already available */
-static celix_status_t discoveryShmWatcher_syncEndpoints(discovery_pt discovery) {
- celix_status_t status = CELIX_SUCCESS;
- shm_watcher_pt watcher = discovery->watcher;
- char** shmKeyArr = calloc(SHM_DATA_MAX_ENTRIES, sizeof(*shmKeyArr));
- array_list_pt registeredKeyArr = NULL;
-
- int i, j, shmSize;
-
- for (i = 0; i < SHM_DATA_MAX_ENTRIES; i++) {
- shmKeyArr[i] = calloc(SHM_ENTRY_MAX_KEY_LENGTH, sizeof(*shmKeyArr[i]));
- }
-
- arrayList_create(®isteredKeyArr);
-
- // get all urls available in shm
- discoveryShm_getKeys(watcher->shmData, shmKeyArr, &shmSize);
-
- // get all locally registered endpoints
- endpointDiscoveryPoller_getDiscoveryEndpoints(discovery->poller, registeredKeyArr);
-
- // add discovery points which are in shm, but not local yet
- for (i = 0; i < shmSize; i++) {
- char url[SHM_ENTRY_MAX_VALUE_LENGTH];
-
- if (discoveryShm_get(watcher->shmData, shmKeyArr[i], &url[0]) == CELIX_SUCCESS) {
- bool elementFound = false;
-
- for (j = 0; j < arrayList_size(registeredKeyArr) && elementFound == false; j++) {
-
- if (strcmp(url, (char*) arrayList_get(registeredKeyArr, j)) == 0) {
- free(arrayList_remove(registeredKeyArr, j));
- elementFound = true;
- }
- }
-
- if (elementFound == false) {
- endpointDiscoveryPoller_addDiscoveryEndpoint(discovery->poller, url);
- }
- }
- }
-
- // remove those which are not in shm
- for (i = 0; i < arrayList_size(registeredKeyArr); i++) {
- char* regUrl = arrayList_get(registeredKeyArr, i);
-
- if (regUrl != NULL) {
- endpointDiscoveryPoller_removeDiscoveryEndpoint(discovery->poller, regUrl);
- }
- }
-
- for (i = 0; i < SHM_DATA_MAX_ENTRIES; i++) {
- free(shmKeyArr[i]);
- }
-
- free(shmKeyArr);
-
- for (j = 0; j < arrayList_size(registeredKeyArr); j++) {
- free(arrayList_get(registeredKeyArr, j));
- }
-
- arrayList_destroy(registeredKeyArr);
-
- return status;
-}
-
-static void* discoveryShmWatcher_run(void* data) {
- discovery_pt discovery = (discovery_pt) data;
- shm_watcher_pt watcher = discovery->watcher;
- char localNodePath[MAX_LOCALNODE_LENGTH];
- char url[MAX_LOCALNODE_LENGTH];
-
- if (discoveryShmWatcher_getLocalNodePath(discovery->context, &localNodePath[0]) != CELIX_SUCCESS) {
- logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_WARNING, "Cannot retrieve local discovery path.");
- }
-
- if (endpointDiscoveryServer_getUrl(discovery->server, &url[0]) != CELIX_SUCCESS) {
- snprintf(url, MAX_LOCALNODE_LENGTH, "http://%s:%s/%s", DEFAULT_SERVER_IP, DEFAULT_SERVER_PORT, DEFAULT_SERVER_PATH);
- }
-
- while (watcher->running) {
- // register own framework
- if (discoveryShm_set(watcher->shmData, localNodePath, url) != CELIX_SUCCESS) {
- logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_WARNING, "Cannot set local discovery registration.");
- }
-
- discoveryShmWatcher_syncEndpoints(discovery);
- sleep(5);
- }
-
- return NULL;
-}
-
-celix_status_t discoveryShmWatcher_create(discovery_pt discovery) {
- celix_status_t status = CELIX_SUCCESS;
- shm_watcher_pt watcher = NULL;
-
- watcher = calloc(1, sizeof(*watcher));
-
- if (!watcher) {
- status = CELIX_ENOMEM;
- } else {
- status = discoveryShm_attach(&(watcher->shmData));
-
- if (status != CELIX_SUCCESS) {
- logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_DEBUG, "Attaching to Shared Memory Failed. Trying to create.");
-
- status = discoveryShm_create(&(watcher->shmData));
-
- if (status != CELIX_SUCCESS) {
- logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_ERROR, "Failed to create Shared Memory Segment.");
- }
- }
-
- if (status == CELIX_SUCCESS) {
- discovery->watcher = watcher;
- }
- else{
- discovery->watcher = NULL;
- free(watcher);
- }
-
- }
-
- if (status == CELIX_SUCCESS) {
- status += celixThreadMutex_create(&watcher->watcherLock, NULL);
- status += celixThreadMutex_lock(&watcher->watcherLock);
- watcher->running = true;
- status += celixThread_create(&watcher->watcherThread, NULL, discoveryShmWatcher_run, discovery);
- status += celixThreadMutex_unlock(&watcher->watcherLock);
- }
-
- return status;
-}
-
-celix_status_t discoveryShmWatcher_destroy(discovery_pt discovery) {
- celix_status_t status;
- shm_watcher_pt watcher = discovery->watcher;
- char localNodePath[MAX_LOCALNODE_LENGTH];
-
- celixThreadMutex_lock(&watcher->watcherLock);
- watcher->running = false;
- celixThreadMutex_unlock(&watcher->watcherLock);
-
- celixThread_join(watcher->watcherThread, NULL);
-
- // remove own framework
- status = discoveryShmWatcher_getLocalNodePath(discovery->context, &localNodePath[0]);
-
- if (status == CELIX_SUCCESS) {
- status = discoveryShm_remove(watcher->shmData, localNodePath);
- }
-
- if (status == CELIX_SUCCESS) {
- discoveryShm_detach(watcher->shmData);
- free(watcher);
- }
- else {
- logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_WARNING, "Cannot remove local discovery registration.");
- }
-
-
- return status;
-}
-
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_shm/src/discovery_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/src/discovery_impl.c b/remote_services/discovery_shm/src/discovery_impl.c
new file mode 100644
index 0000000..2604595
--- /dev/null
+++ b/remote_services/discovery_shm/src/discovery_impl.c
@@ -0,0 +1,163 @@
+/**
+ * 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.
+ */
+/*
+ * discovery_impl.c
+ *
+ * \date Aug 8, 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdbool.h>
+#include <netdb.h>
+#include <netinet/in.h>
+
+#include "constants.h"
+#include "celix_threads.h"
+#include "bundle_context.h"
+#include "array_list.h"
+#include "utils.h"
+#include "celix_errno.h"
+#include "filter.h"
+#include "service_reference.h"
+#include "service_registration.h"
+#include "remote_constants.h"
+
+
+#include "discovery.h"
+#include "discovery_impl.h"
+#include "discovery_shmWatcher.h"
+#include "endpoint_discovery_poller.h"
+#include "endpoint_discovery_server.h"
+
+
+
+celix_status_t discovery_create(bundle_context_pt context, discovery_pt *discovery) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *discovery = calloc(1, sizeof(struct discovery));
+ if (!*discovery) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*discovery)->context = context;
+ (*discovery)->poller = NULL;
+ (*discovery)->server = NULL;
+
+ (*discovery)->listenerReferences = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
+ (*discovery)->discoveredServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+
+ celixThreadMutex_create(&(*discovery)->listenerReferencesMutex, NULL);
+ celixThreadMutex_create(&(*discovery)->discoveredServicesMutex, NULL);
+
+ if (logHelper_create(context, &(*discovery)->loghelper) == CELIX_SUCCESS) {
+ logHelper_start((*discovery)->loghelper);
+ }
+ }
+
+ return status;
+}
+
+
+
+celix_status_t discovery_destroy(discovery_pt discovery) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ discovery->context = NULL;
+ discovery->poller = NULL;
+ discovery->server = NULL;
+
+ celixThreadMutex_lock(&discovery->discoveredServicesMutex);
+
+ hashMap_destroy(discovery->discoveredServices, false, false);
+ discovery->discoveredServices = NULL;
+
+ celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
+
+ celixThreadMutex_destroy(&discovery->discoveredServicesMutex);
+
+ celixThreadMutex_lock(&discovery->listenerReferencesMutex);
+
+ hashMap_destroy(discovery->listenerReferences, false, false);
+ discovery->listenerReferences = NULL;
+
+ celixThreadMutex_unlock(&discovery->listenerReferencesMutex);
+
+ celixThreadMutex_destroy(&discovery->listenerReferencesMutex);
+
+
+
+
+ free(discovery);
+
+ return status;
+}
+
+celix_status_t discovery_start(discovery_pt discovery) {
+ celix_status_t status;
+
+ status = endpointDiscoveryPoller_create(discovery, discovery->context, &discovery->poller);
+ if (status == CELIX_SUCCESS) {
+ status = endpointDiscoveryServer_create(discovery, discovery->context, &discovery->server);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = discoveryShmWatcher_create(discovery);
+ }
+
+ return status;
+}
+
+celix_status_t discovery_stop(discovery_pt discovery) {
+ celix_status_t status;
+
+ status = discoveryShmWatcher_destroy(discovery);
+
+ if (status == CELIX_SUCCESS) {
+ status = endpointDiscoveryServer_destroy(discovery->server);
+ }
+
+ endpointDiscoveryPoller_destroy(discovery->poller);
+
+ if (status == CELIX_SUCCESS) {
+ hash_map_iterator_pt iter;
+
+ celixThreadMutex_lock(&discovery->discoveredServicesMutex);
+
+ iter = hashMapIterator_create(discovery->discoveredServices);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ endpoint_description_pt endpoint = hashMapEntry_getValue(entry);
+
+ discovery_informEndpointListeners(discovery, endpoint, false);
+ }
+ hashMapIterator_destroy(iter);
+
+ celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
+
+ logHelper_stop(discovery->loghelper);
+ logHelper_destroy(&discovery->loghelper);
+ }
+
+ return status;
+}
+
+
+
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_shm/src/discovery_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/src/discovery_impl.h b/remote_services/discovery_shm/src/discovery_impl.h
new file mode 100644
index 0000000..c7206bd
--- /dev/null
+++ b/remote_services/discovery_shm/src/discovery_impl.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.
+ */
+/*
+ * discovery_impl.h
+ *
+ * \date Oct 01, 2014
+ * \author <a href="mailto:celix-dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef DISCOVERY_IMPL_H_
+#define DISCOVERY_IMPL_H_
+
+#include "bundle_context.h"
+#include "service_reference.h"
+
+#include "endpoint_description.h"
+#include "endpoint_listener.h"
+
+#include "endpoint_discovery_poller.h"
+#include "endpoint_discovery_server.h"
+#include "discovery_shmWatcher.h"
+
+
+#define DEFAULT_SERVER_IP "127.0.0.1"
+#define DEFAULT_SERVER_PORT "9999"
+#define DEFAULT_SERVER_PATH "/org.apache.celix.discovery.shm"
+#define DEFAULT_POLL_ENDPOINTS "http://localhost:9999/org.apache.celix.discovery.shm"
+
+#define MAX_ROOTNODE_LENGTH 64
+#define MAX_LOCALNODE_LENGTH 256
+
+
+struct discovery {
+ bundle_context_pt context;
+
+ celix_thread_mutex_t listenerReferencesMutex;
+ celix_thread_mutex_t discoveredServicesMutex;
+
+ hash_map_pt listenerReferences; //key=serviceReference, value=nop
+ hash_map_pt discoveredServices; //key=endpointId (string), value=endpoint_description_pt
+
+ shm_watcher_pt watcher;
+ endpoint_discovery_poller_pt poller;
+ endpoint_discovery_server_pt server;
+
+ log_helper_pt loghelper;
+};
+
+#endif /* DISCOVERY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_shm/src/discovery_shm.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/src/discovery_shm.c b/remote_services/discovery_shm/src/discovery_shm.c
new file mode 100644
index 0000000..1b1170e
--- /dev/null
+++ b/remote_services/discovery_shm/src/discovery_shm.c
@@ -0,0 +1,284 @@
+/**
+ * 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.
+ */
+
+/*
+ * discovery_shm.c
+ *
+ * \date 26 Jul 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+
+
+#include <stdio.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include <sys/types.h>
+#include <sys/sem.h>
+#include <sys/shm.h>
+
+#include <celix_errno.h>
+#include <celix_threads.h>
+
+#include "discovery_shm.h"
+
+#define DISCOVERY_SHM_MEMSIZE 262144
+#define DISCOVERY_SHM_FILENAME "/dev/null"
+#define DISCOVERY_SHM_FTOK_ID 50
+#define DISCOVERY_SEM_FILENAME "/dev/null"
+#define DISCOVERY_SEM_FTOK_ID 54
+
+struct shmEntry {
+ char key[SHM_ENTRY_MAX_KEY_LENGTH];
+ char value[SHM_ENTRY_MAX_VALUE_LENGTH];
+
+ time_t expires;
+};
+
+typedef struct shmEntry shmEntry;
+
+struct shmData {
+ shmEntry entries[SHM_DATA_MAX_ENTRIES];
+ int numOfEntries;
+ int shmId;
+
+ celix_thread_mutex_t globalLock;
+};
+
+void* shmAdress;
+
+static celix_status_t discoveryShm_removeWithIndex(shmData_pt data, int index);
+
+/* returns the ftok key to identify shared memory*/
+static key_t discoveryShm_getKey() {
+ return ftok(DISCOVERY_SHM_FILENAME, DISCOVERY_SHM_FTOK_ID);
+}
+
+/* creates a new shared memory block */
+celix_status_t discoveryShm_create(shmData_pt* data) {
+ celix_status_t status;
+
+ shmData_pt shmData = calloc(1, sizeof(*shmData));
+ key_t shmKey = discoveryShm_getKey();
+
+ if (!shmData) {
+ status = CELIX_ENOMEM;
+ } else if ((shmData->shmId = shmget(shmKey, DISCOVERY_SHM_MEMSIZE, IPC_CREAT | 0666)) < 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else if ((shmAdress = shmat(shmData->shmId, 0, 0)) == (char*) -1) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ celix_thread_mutexattr_t threadAttr;
+
+ shmData->numOfEntries = 0;
+
+ status = celixThreadMutexAttr_create(&threadAttr);
+
+#ifdef LINUX
+ if (status == CELIX_SUCCESS) {
+ // This is Linux specific
+ status = pthread_mutexattr_setrobust(&threadAttr, PTHREAD_MUTEX_ROBUST);
+ }
+#endif
+
+ if (status == CELIX_SUCCESS) {
+ status = celixThreadMutex_create(&shmData->globalLock, &threadAttr);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ memcpy(shmAdress, shmData, sizeof(struct shmData));
+ (*data) = shmAdress;
+ }
+ }
+
+ free(shmData);
+
+ return status;
+}
+
+celix_status_t discoveryShm_attach(shmData_pt* data) {
+ celix_status_t status = CELIX_SUCCESS;
+ key_t shmKey = ftok(DISCOVERY_SHM_FILENAME, DISCOVERY_SHM_FTOK_ID);
+ int shmId = -1;
+
+ if ((shmId = shmget(shmKey, DISCOVERY_SHM_MEMSIZE, 0666)) < 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+
+ /* shmat has a curious return value of (void*)-1 in case of error */
+ void *mem=shmat(shmId, 0, 0);
+ if(mem==((void*)-1)){
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+ else{
+ (*data)=mem;
+ }
+
+ return status;
+}
+
+static celix_status_t discoveryShm_getwithIndex(shmData_pt data, char* key, char* value, int* index) {
+ celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+ time_t currentTime = time(NULL);
+ unsigned int i;
+
+ for (i = 0; i < data->numOfEntries && status != CELIX_SUCCESS; i++) {
+ shmEntry entry = data->entries[i];
+ // check if entry is still valid
+ if (data->entries[i].expires < currentTime) {
+ discoveryShm_removeWithIndex(data, i);
+ } else if (strcmp(entry.key, key) == 0) {
+ if (value) {
+ strcpy(value, entry.value);
+ }
+ if (index) {
+ (*index) = i;
+ }
+ status = CELIX_SUCCESS;
+ }
+ }
+
+ return status;
+}
+
+celix_status_t discoveryShm_getKeys(shmData_pt data, char** keys, int* size) {
+ celix_status_t status;
+
+ status = celixThreadMutex_lock(&data->globalLock);
+
+ if (status == CELIX_SUCCESS) {
+ unsigned int i = 0;
+ for (i = 0; i < data->numOfEntries; i++) {
+ shmEntry entry = data->entries[i];
+
+ if (strlen(entry.key)>0) {
+ snprintf(keys[i], SHM_ENTRY_MAX_KEY_LENGTH, "%s", entry.key);
+ }
+ }
+
+ (*size) = i;
+
+ celixThreadMutex_unlock(&data->globalLock);
+ }
+
+ return status;
+}
+
+celix_status_t discoveryShm_set(shmData_pt data, char *key, char* value) {
+ celix_status_t status;
+ int index = -1;
+
+ if (data->numOfEntries >= SHM_DATA_MAX_ENTRIES) {
+ status = CELIX_ILLEGAL_STATE;
+ } else {
+ status = celixThreadMutex_lock(&data->globalLock);
+
+ if (status == CELIX_SUCCESS) {
+ // check if key already there
+ status = discoveryShm_getwithIndex(data, key, NULL, &index);
+ if (status != CELIX_SUCCESS) {
+ index = data->numOfEntries;
+
+ snprintf(data->entries[index].key, SHM_ENTRY_MAX_KEY_LENGTH, "%s", key);
+ data->numOfEntries++;
+
+ status = CELIX_SUCCESS;
+ }
+
+ snprintf(data->entries[index].value, SHM_ENTRY_MAX_VALUE_LENGTH, "%s", value);
+ data->entries[index].expires = (time(NULL) + SHM_ENTRY_DEFAULT_TTL);
+
+ celixThreadMutex_unlock(&data->globalLock);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t discoveryShm_get(shmData_pt data, char* key, char* value) {
+ celix_status_t status;
+
+ status = celixThreadMutex_lock(&data->globalLock);
+
+ if (status == CELIX_SUCCESS) {
+ status = discoveryShm_getwithIndex(data, key, value, NULL);
+
+ celixThreadMutex_unlock(&data->globalLock);
+ }
+
+ return status;
+}
+
+static celix_status_t discoveryShm_removeWithIndex(shmData_pt data, int index) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ data->numOfEntries--;
+ if (index < data->numOfEntries) {
+ memcpy((void*) &data->entries[index], (void*) &data->entries[index + 1], ((data->numOfEntries - index) * sizeof(struct shmEntry)));
+ }
+
+ return status;
+}
+
+celix_status_t discoveryShm_remove(shmData_pt data, char* key) {
+ celix_status_t status;
+ int index = -1;
+
+ status = celixThreadMutex_lock(&data->globalLock);
+
+ if (status == CELIX_SUCCESS) {
+ status = discoveryShm_getwithIndex(data, key, NULL, &index);
+
+ if (status == CELIX_SUCCESS) {
+ status = discoveryShm_removeWithIndex(data, index);
+ }
+
+ celixThreadMutex_unlock(&data->globalLock);
+ }
+
+ return status;
+}
+
+celix_status_t discoveryShm_detach(shmData_pt data) {
+ celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+
+ if (data->numOfEntries == 0) {
+ status = discoveryShm_destroy(data);
+ }
+ else if (shmdt(shmAdress) == 0) {
+ status = CELIX_SUCCESS;
+ }
+
+ return status;
+}
+
+celix_status_t discoveryShm_destroy(shmData_pt data) {
+ celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+
+ if (shmctl(data->shmId, IPC_RMID, 0) == 0) {
+ status = CELIX_SUCCESS;
+ }
+
+ return status;
+
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_shm/src/discovery_shm.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/src/discovery_shm.h b/remote_services/discovery_shm/src/discovery_shm.h
new file mode 100644
index 0000000..9c4593b
--- /dev/null
+++ b/remote_services/discovery_shm/src/discovery_shm.h
@@ -0,0 +1,56 @@
+/**
+ * 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.
+ */
+
+/*
+ * shm.h
+ *
+ * \date 26 Jul 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+
+
+#ifndef _DISCOVERY_SHM_H_
+#define _DISCOVERY_SHM_H_
+
+#include <celix_errno.h>
+
+#define SHM_ENTRY_MAX_KEY_LENGTH 256
+#define SHM_ENTRY_MAX_VALUE_LENGTH 256
+
+// defines the time-to-live in seconds
+#define SHM_ENTRY_DEFAULT_TTL 60
+
+// we currently support 64 separate discovery instances
+#define SHM_DATA_MAX_ENTRIES 64
+
+typedef struct shmData* shmData_pt;
+
+/* creates a new shared memory block */
+celix_status_t discoveryShm_create(shmData_pt* data);
+celix_status_t discoveryShm_attach(shmData_pt* data);
+celix_status_t discoveryShm_set(shmData_pt data, char *key, char* value);
+celix_status_t discoveryShm_get(shmData_pt data, char* key, char* value);
+celix_status_t discoveryShm_getKeys(shmData_pt data, char** keys, int* size);
+celix_status_t discoveryShm_remove(shmData_pt data, char* key);
+celix_status_t discoveryShm_detach(shmData_pt data);
+celix_status_t discoveryShm_destroy(shmData_pt data);
+
+#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_shm/src/discovery_shmWatcher.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/src/discovery_shmWatcher.c b/remote_services/discovery_shm/src/discovery_shmWatcher.c
new file mode 100644
index 0000000..6460de8
--- /dev/null
+++ b/remote_services/discovery_shm/src/discovery_shmWatcher.c
@@ -0,0 +1,246 @@
+/**
+ * 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.
+ */
+/*
+ * discovery_shmWatcher.c
+ *
+ * \date 16 Sep 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+
+
+#include "celix_log.h"
+#include "constants.h"
+#include "discovery_impl.h"
+
+#include "discovery_shm.h"
+#include "discovery_shmWatcher.h"
+
+#include "endpoint_discovery_poller.h"
+
+struct shm_watcher {
+ shmData_pt shmData;
+ celix_thread_t watcherThread;
+ celix_thread_mutex_t watcherLock;
+
+ volatile bool running;
+};
+
+// note that the rootNode shouldn't have a leading slash
+static celix_status_t discoveryShmWatcher_getRootPath(char* rootNode) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ strcpy(rootNode, "discovery");
+
+ return status;
+}
+
+static celix_status_t discoveryShmWatcher_getLocalNodePath(bundle_context_pt context, char* localNodePath) {
+ celix_status_t status;
+ char rootPath[MAX_ROOTNODE_LENGTH];
+ const char* uuid = NULL;
+
+ status = discoveryShmWatcher_getRootPath(&rootPath[0]);
+
+ if (status == CELIX_SUCCESS) {
+ status = bundleContext_getProperty(context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ if (rootPath[strlen(&rootPath[0]) - 1] == '/') {
+ snprintf(localNodePath, MAX_LOCALNODE_LENGTH, "%s%s", &rootPath[0], uuid);
+ } else {
+ snprintf(localNodePath, MAX_LOCALNODE_LENGTH, "%s/%s", &rootPath[0], uuid);
+ }
+ }
+
+ return status;
+}
+
+/* retrieves all endpoints from shm and syncs them with the ones already available */
+static celix_status_t discoveryShmWatcher_syncEndpoints(discovery_pt discovery) {
+ celix_status_t status = CELIX_SUCCESS;
+ shm_watcher_pt watcher = discovery->watcher;
+ char** shmKeyArr = calloc(SHM_DATA_MAX_ENTRIES, sizeof(*shmKeyArr));
+ array_list_pt registeredKeyArr = NULL;
+
+ int i, j, shmSize;
+
+ for (i = 0; i < SHM_DATA_MAX_ENTRIES; i++) {
+ shmKeyArr[i] = calloc(SHM_ENTRY_MAX_KEY_LENGTH, sizeof(*shmKeyArr[i]));
+ }
+
+ arrayList_create(®isteredKeyArr);
+
+ // get all urls available in shm
+ discoveryShm_getKeys(watcher->shmData, shmKeyArr, &shmSize);
+
+ // get all locally registered endpoints
+ endpointDiscoveryPoller_getDiscoveryEndpoints(discovery->poller, registeredKeyArr);
+
+ // add discovery points which are in shm, but not local yet
+ for (i = 0; i < shmSize; i++) {
+ char url[SHM_ENTRY_MAX_VALUE_LENGTH];
+
+ if (discoveryShm_get(watcher->shmData, shmKeyArr[i], &url[0]) == CELIX_SUCCESS) {
+ bool elementFound = false;
+
+ for (j = 0; j < arrayList_size(registeredKeyArr) && elementFound == false; j++) {
+
+ if (strcmp(url, (char*) arrayList_get(registeredKeyArr, j)) == 0) {
+ free(arrayList_remove(registeredKeyArr, j));
+ elementFound = true;
+ }
+ }
+
+ if (elementFound == false) {
+ endpointDiscoveryPoller_addDiscoveryEndpoint(discovery->poller, url);
+ }
+ }
+ }
+
+ // remove those which are not in shm
+ for (i = 0; i < arrayList_size(registeredKeyArr); i++) {
+ char* regUrl = arrayList_get(registeredKeyArr, i);
+
+ if (regUrl != NULL) {
+ endpointDiscoveryPoller_removeDiscoveryEndpoint(discovery->poller, regUrl);
+ }
+ }
+
+ for (i = 0; i < SHM_DATA_MAX_ENTRIES; i++) {
+ free(shmKeyArr[i]);
+ }
+
+ free(shmKeyArr);
+
+ for (j = 0; j < arrayList_size(registeredKeyArr); j++) {
+ free(arrayList_get(registeredKeyArr, j));
+ }
+
+ arrayList_destroy(registeredKeyArr);
+
+ return status;
+}
+
+static void* discoveryShmWatcher_run(void* data) {
+ discovery_pt discovery = (discovery_pt) data;
+ shm_watcher_pt watcher = discovery->watcher;
+ char localNodePath[MAX_LOCALNODE_LENGTH];
+ char url[MAX_LOCALNODE_LENGTH];
+
+ if (discoveryShmWatcher_getLocalNodePath(discovery->context, &localNodePath[0]) != CELIX_SUCCESS) {
+ logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_WARNING, "Cannot retrieve local discovery path.");
+ }
+
+ if (endpointDiscoveryServer_getUrl(discovery->server, &url[0]) != CELIX_SUCCESS) {
+ snprintf(url, MAX_LOCALNODE_LENGTH, "http://%s:%s/%s", DEFAULT_SERVER_IP, DEFAULT_SERVER_PORT, DEFAULT_SERVER_PATH);
+ }
+
+ while (watcher->running) {
+ // register own framework
+ if (discoveryShm_set(watcher->shmData, localNodePath, url) != CELIX_SUCCESS) {
+ logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_WARNING, "Cannot set local discovery registration.");
+ }
+
+ discoveryShmWatcher_syncEndpoints(discovery);
+ sleep(5);
+ }
+
+ return NULL;
+}
+
+celix_status_t discoveryShmWatcher_create(discovery_pt discovery) {
+ celix_status_t status = CELIX_SUCCESS;
+ shm_watcher_pt watcher = NULL;
+
+ watcher = calloc(1, sizeof(*watcher));
+
+ if (!watcher) {
+ status = CELIX_ENOMEM;
+ } else {
+ status = discoveryShm_attach(&(watcher->shmData));
+
+ if (status != CELIX_SUCCESS) {
+ logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_DEBUG, "Attaching to Shared Memory Failed. Trying to create.");
+
+ status = discoveryShm_create(&(watcher->shmData));
+
+ if (status != CELIX_SUCCESS) {
+ logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_ERROR, "Failed to create Shared Memory Segment.");
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ discovery->watcher = watcher;
+ }
+ else{
+ discovery->watcher = NULL;
+ free(watcher);
+ }
+
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status += celixThreadMutex_create(&watcher->watcherLock, NULL);
+ status += celixThreadMutex_lock(&watcher->watcherLock);
+ watcher->running = true;
+ status += celixThread_create(&watcher->watcherThread, NULL, discoveryShmWatcher_run, discovery);
+ status += celixThreadMutex_unlock(&watcher->watcherLock);
+ }
+
+ return status;
+}
+
+celix_status_t discoveryShmWatcher_destroy(discovery_pt discovery) {
+ celix_status_t status;
+ shm_watcher_pt watcher = discovery->watcher;
+ char localNodePath[MAX_LOCALNODE_LENGTH];
+
+ celixThreadMutex_lock(&watcher->watcherLock);
+ watcher->running = false;
+ celixThreadMutex_unlock(&watcher->watcherLock);
+
+ celixThread_join(watcher->watcherThread, NULL);
+
+ // remove own framework
+ status = discoveryShmWatcher_getLocalNodePath(discovery->context, &localNodePath[0]);
+
+ if (status == CELIX_SUCCESS) {
+ status = discoveryShm_remove(watcher->shmData, localNodePath);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ discoveryShm_detach(watcher->shmData);
+ free(watcher);
+ }
+ else {
+ logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_WARNING, "Cannot remove local discovery registration.");
+ }
+
+
+ return status;
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_shm/src/discovery_shmWatcher.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/src/discovery_shmWatcher.h b/remote_services/discovery_shm/src/discovery_shmWatcher.h
new file mode 100644
index 0000000..ff70f72
--- /dev/null
+++ b/remote_services/discovery_shm/src/discovery_shmWatcher.h
@@ -0,0 +1,40 @@
+/**
+ * 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.
+ */
+/*
+ * shm_watcher.h
+ *
+ * \date 30 Sep 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef DISCOVERY_SHM_WATCHER_H_
+#define DISCOVERY_SHM_WATCHER_H_
+
+#include "celix_errno.h"
+#include "discovery.h"
+#include "endpoint_discovery_poller.h"
+
+typedef struct shm_watcher *shm_watcher_pt;
+
+celix_status_t discoveryShmWatcher_create(discovery_pt discovery);
+celix_status_t discoveryShmWatcher_destroy(discovery_pt discovery);
+
+
+#endif /* DISCOVERY_SHM_WATCHER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/CMakeLists.txt b/remote_services/examples/CMakeLists.txt
index c7c5444..2b1f35f 100644
--- a/remote_services/examples/CMakeLists.txt
+++ b/remote_services/examples/CMakeLists.txt
@@ -17,6 +17,7 @@
celix_subproject(RSA_EXAMPLES "Option to enable building the RSA examples" ON DEPS LAUNCHER shell_tui log_writer RSA_TOPOLOGY_MANAGER)
if (RSA_EXAMPLES)
+ add_subdirectory(calculator_api)
add_subdirectory(calculator_service)
add_subdirectory(calculator_shell)
@@ -47,13 +48,13 @@ if (RSA_EXAMPLES)
add_deploy(remote-services-dfi
NAME "server"
GROUP "remote-services/remote-services-dfi"
- BUNDLES discovery_etcd topology_manager remote_service_admin_dfi calculator Celix::shell Celix::shell_tui log_service log_writer
+ BUNDLES discovery_etcd topology_manager remote_service_admin_dfi calculator Celix::shell Celix::shell_tui Celix::log_service Celix::log_writer_stdout
)
add_deploy("remote-services-dfi-client"
NAME "client"
GROUP "remote-services/remote-services-dfi"
- BUNDLES topology_manager remote_service_admin_dfi Celix::shell Celix::shell_tui log_service log_writer calculator_shell discovery_etcd
+ BUNDLES topology_manager remote_service_admin_dfi Celix::shell Celix::shell_tui Celix::log_service Celix::log_writer_stdout calculator_shell discovery_etcd
)
endif ()
endif (RSA_EXAMPLES)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_api/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_api/CMakeLists.txt b/remote_services/examples/calculator_api/CMakeLists.txt
new file mode 100644
index 0000000..76acfa7
--- /dev/null
+++ b/remote_services/examples/calculator_api/CMakeLists.txt
@@ -0,0 +1,22 @@
+# 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.
+
+add_library(calculator_api INTERFACE)
+target_include_directories(calculator_api INTERFACE include)
+set_target_properties(calculator_api PROPERTIES
+ "INTERFACE_CALCULATOR_DESCRIPTOR"
+ "${CMAKE_CURRENT_LIST_DIR}/include/org.apache.celix.calc.api.Calculator2.descriptor")
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_api/include/calculator_service.h
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_api/include/calculator_service.h b/remote_services/examples/calculator_api/include/calculator_service.h
new file mode 100644
index 0000000..8e2f0dc
--- /dev/null
+++ b/remote_services/examples/calculator_api/include/calculator_service.h
@@ -0,0 +1,56 @@
+/**
+ *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.
+ */
+/*
+ * calculator_service.h
+ *
+ * \date Oct 5, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef CALCULATOR_SERVICE_H_
+#define CALCULATOR_SERVICE_H_
+
+#define CALCULATOR_SERVICE "org.apache.celix.calc.api.Calculator"
+#define CALCULATOR2_SERVICE "org.apache.celix.calc.api.Calculator2"
+
+
+typedef struct calculator *calculator_pt;
+
+typedef struct calculator_service *calculator_service_pt;
+
+/*
+ * The calculator service definition corresponds to the following Java interface:
+ *
+ * interface Calculator {
+ * double add(double a, double b);
+ * double sub(double a, double b);
+ * double sqrt(double a);
+ * }
+ */
+struct calculator_service {
+ calculator_pt calculator;
+ int (*add)(calculator_pt calculator, double a, double b, double *result);
+ int (*sub)(calculator_pt calculator, double a, double b, double *result);
+ int (*sqrt)(calculator_pt calculator, double a, double *result);
+};
+
+
+
+#endif /* CALCULATOR_SERVICE_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_api/include/org.apache.celix.calc.api.Calculator2.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_api/include/org.apache.celix.calc.api.Calculator2.descriptor b/remote_services/examples/calculator_api/include/org.apache.celix.calc.api.Calculator2.descriptor
new file mode 100644
index 0000000..b784838
--- /dev/null
+++ b/remote_services/examples/calculator_api/include/org.apache.celix.calc.api.Calculator2.descriptor
@@ -0,0 +1,11 @@
+:header
+type=interface
+name=calculator
+version=1.3.0
+:annotations
+classname=org.example.Calculator
+:types
+:methods
+add(DD)D=add(#am=handle;PDD#am=pre;*D)N
+sub(DD)D=sub(#am=handle;PDD#am=pre;*D)N
+sqrt(D)D=sqrt(#am=handle;PD#am=pre;*D)N
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_service/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/CMakeLists.txt b/remote_services/examples/calculator_service/CMakeLists.txt
index 5e8040c..ff4d2d7 100644
--- a/remote_services/examples/calculator_service/CMakeLists.txt
+++ b/remote_services/examples/calculator_service/CMakeLists.txt
@@ -15,21 +15,15 @@
# specific language governing permissions and limitations
# under the License.
-include_directories("../../../utils/public/include")
-include_directories("../../utils/public/include")
-include_directories("../../remote_service_admin/public/include")
-include_directories("private/include")
-include_directories("public/include")
-
-add_bundle(calculator SOURCES
- private/src/calculator_impl
- private/src/calculator_activator
-
- private/include/calculator_impl.h
-
+add_bundle(calculator
+ SOURCES
+ src/calculator_impl
+ src/calculator_activator
SYMBOLIC_NAME "apache_celix_remoting_calculator_impl"
VERSION 0.0.1
)
+target_include_directories(calculator PRIVATE src)
+target_link_libraries(calculator PRIVATE Celix::remote_service_admin_api calculator_api)
-bundle_files(calculator public/include/org.apache.celix.calc.api.Calculator2.descriptor
- DESTINATION .)
+get_target_property(DESCR calculator_api INTERFACE_CALCULATOR_DESCRIPTOR)
+bundle_files(calculator ${DESCR} DESTINATION .)
[09/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_service/private/include/calculator_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/private/include/calculator_impl.h b/remote_services/examples/calculator_service/private/include/calculator_impl.h
deleted file mode 100644
index 5e075e4..0000000
--- a/remote_services/examples/calculator_service/private/include/calculator_impl.h
+++ /dev/null
@@ -1,43 +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.
- */
-/*
- * calculator_impl.h
- *
- * \date Oct 5, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef CALCULATOR_IMPL_H_
-#define CALCULATOR_IMPL_H_
-
-#include "celix_errno.h"
-
-#include "calculator_service.h"
-
-struct calculator {
-};
-
-celix_status_t calculator_create(calculator_pt *calcuator);
-celix_status_t calculator_destroy(calculator_pt *calcuator);
-celix_status_t calculator_add(calculator_pt calcuator, double a, double b, double *result);
-celix_status_t calculator_sub(calculator_pt calcuator, double a, double b, double *result);
-celix_status_t calculator_sqrt(calculator_pt calcuator, double a, double *result);
-
-#endif /* CALCULATOR_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_service/private/src/calculator_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/private/src/calculator_activator.c b/remote_services/examples/calculator_service/private/src/calculator_activator.c
deleted file mode 100644
index 688a7b0..0000000
--- a/remote_services/examples/calculator_service/private/src/calculator_activator.c
+++ /dev/null
@@ -1,110 +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.
- */
-/*
- * calculator_activator.c
- *
- * \date Oct 5, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-
-#include "bundle_activator.h"
-#include "bundle_context.h"
-#include "service_registration.h"
-
-#include "calculator_impl.h"
-#include "remote_constants.h"
-
-struct activator {
- calculator_pt calculator;
- calculator_service_pt service;
-
- service_registration_pt calculatorReg;
- service_registration_pt calculatorReg2;
-};
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator;
-
- activator = calloc(1, sizeof(*activator));
- if (!activator) {
- status = CELIX_ENOMEM;
- } else {
- activator->calculatorReg = NULL;
- activator->calculatorReg2 = NULL;
-
- *userData = activator;
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
- properties_pt properties = NULL;
-
- status = calculator_create(&activator->calculator);
- if (status == CELIX_SUCCESS) {
- activator->service = calloc(1, sizeof(*activator->service));
- if (!activator->service) {
- status = CELIX_ENOMEM;
- } else {
- activator->service->calculator = activator->calculator;
- activator->service->add = calculator_add;
- activator->service->sub = calculator_sub;
- activator->service->sqrt = calculator_sqrt;
-
- properties = properties_create();
- properties_set(properties, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, (char *) CALCULATOR_SERVICE);
-
- bundleContext_registerService(context, (char *) CALCULATOR_SERVICE, activator->service, properties, &activator->calculatorReg);
-
- properties_pt properties2 = properties_create();
- properties_set(properties2, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, (char *) CALCULATOR2_SERVICE);
- bundleContext_registerService(context, CALCULATOR2_SERVICE, activator->service, properties2, &activator->calculatorReg2);
- }
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- serviceRegistration_unregister(activator->calculatorReg);
- serviceRegistration_unregister(activator->calculatorReg2);
-
- free(activator->service);
-
- calculator_destroy(&activator->calculator);
-
- return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
-
- free(userData);
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_service/private/src/calculator_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/private/src/calculator_impl.c b/remote_services/examples/calculator_service/private/src/calculator_impl.c
deleted file mode 100644
index adccb52..0000000
--- a/remote_services/examples/calculator_service/private/src/calculator_impl.c
+++ /dev/null
@@ -1,79 +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.
- */
-/*
- * calculator_impl.c
- *
- * \date Oct 5, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <math.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "calculator_impl.h"
-
-celix_status_t calculator_create(calculator_pt *calculator) {
- celix_status_t status = CELIX_SUCCESS;
-
- *calculator = calloc(1, sizeof(**calculator));
- if (!*calculator) {
- status = CELIX_ENOMEM;
- }
-
- return status;
-}
-
-celix_status_t calculator_destroy(calculator_pt *calculator) {
- free(*calculator);
- return CELIX_SUCCESS;
-}
-
-celix_status_t calculator_add(calculator_pt calculator, double a, double b, double *result) {
- celix_status_t status = CELIX_SUCCESS;
-
- *result = a + b;
- printf("CALCULATOR: Add: %f + %f = %f\n", a, b, *result);
-
- return status;
-}
-
-celix_status_t calculator_sub(calculator_pt calculator, double a, double b, double *result) {
- celix_status_t status = CELIX_SUCCESS;
-
- *result = a - b;
- printf("CALCULATOR: Sub: %f + %f = %f\n", a, b, *result);
-
- return status;
-}
-
-celix_status_t calculator_sqrt(calculator_pt calculator, double a, double *result) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (a > 0) {
- *result = sqrt(a);
- printf("CALCULATOR: Sqrt: %f = %f\n", a, *result);
- } else {
- printf("CALCULATOR: Sqrt: %f = ERR\n", a);
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_service/public/include/calculator_service.h
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/public/include/calculator_service.h b/remote_services/examples/calculator_service/public/include/calculator_service.h
deleted file mode 100644
index 8e2f0dc..0000000
--- a/remote_services/examples/calculator_service/public/include/calculator_service.h
+++ /dev/null
@@ -1,56 +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.
- */
-/*
- * calculator_service.h
- *
- * \date Oct 5, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef CALCULATOR_SERVICE_H_
-#define CALCULATOR_SERVICE_H_
-
-#define CALCULATOR_SERVICE "org.apache.celix.calc.api.Calculator"
-#define CALCULATOR2_SERVICE "org.apache.celix.calc.api.Calculator2"
-
-
-typedef struct calculator *calculator_pt;
-
-typedef struct calculator_service *calculator_service_pt;
-
-/*
- * The calculator service definition corresponds to the following Java interface:
- *
- * interface Calculator {
- * double add(double a, double b);
- * double sub(double a, double b);
- * double sqrt(double a);
- * }
- */
-struct calculator_service {
- calculator_pt calculator;
- int (*add)(calculator_pt calculator, double a, double b, double *result);
- int (*sub)(calculator_pt calculator, double a, double b, double *result);
- int (*sqrt)(calculator_pt calculator, double a, double *result);
-};
-
-
-
-#endif /* CALCULATOR_SERVICE_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor b/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
deleted file mode 100644
index b784838..0000000
--- a/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
+++ /dev/null
@@ -1,11 +0,0 @@
-:header
-type=interface
-name=calculator
-version=1.3.0
-:annotations
-classname=org.example.Calculator
-:types
-:methods
-add(DD)D=add(#am=handle;PDD#am=pre;*D)N
-sub(DD)D=sub(#am=handle;PDD#am=pre;*D)N
-sqrt(D)D=sqrt(#am=handle;PD#am=pre;*D)N
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_service/src/calculator_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/src/calculator_activator.c b/remote_services/examples/calculator_service/src/calculator_activator.c
new file mode 100644
index 0000000..688a7b0
--- /dev/null
+++ b/remote_services/examples/calculator_service/src/calculator_activator.c
@@ -0,0 +1,110 @@
+/**
+ *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.
+ */
+/*
+ * calculator_activator.c
+ *
+ * \date Oct 5, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+
+#include "bundle_activator.h"
+#include "bundle_context.h"
+#include "service_registration.h"
+
+#include "calculator_impl.h"
+#include "remote_constants.h"
+
+struct activator {
+ calculator_pt calculator;
+ calculator_service_pt service;
+
+ service_registration_pt calculatorReg;
+ service_registration_pt calculatorReg2;
+};
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator;
+
+ activator = calloc(1, sizeof(*activator));
+ if (!activator) {
+ status = CELIX_ENOMEM;
+ } else {
+ activator->calculatorReg = NULL;
+ activator->calculatorReg2 = NULL;
+
+ *userData = activator;
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+ properties_pt properties = NULL;
+
+ status = calculator_create(&activator->calculator);
+ if (status == CELIX_SUCCESS) {
+ activator->service = calloc(1, sizeof(*activator->service));
+ if (!activator->service) {
+ status = CELIX_ENOMEM;
+ } else {
+ activator->service->calculator = activator->calculator;
+ activator->service->add = calculator_add;
+ activator->service->sub = calculator_sub;
+ activator->service->sqrt = calculator_sqrt;
+
+ properties = properties_create();
+ properties_set(properties, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, (char *) CALCULATOR_SERVICE);
+
+ bundleContext_registerService(context, (char *) CALCULATOR_SERVICE, activator->service, properties, &activator->calculatorReg);
+
+ properties_pt properties2 = properties_create();
+ properties_set(properties2, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, (char *) CALCULATOR2_SERVICE);
+ bundleContext_registerService(context, CALCULATOR2_SERVICE, activator->service, properties2, &activator->calculatorReg2);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ serviceRegistration_unregister(activator->calculatorReg);
+ serviceRegistration_unregister(activator->calculatorReg2);
+
+ free(activator->service);
+
+ calculator_destroy(&activator->calculator);
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ free(userData);
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_service/src/calculator_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/src/calculator_impl.c b/remote_services/examples/calculator_service/src/calculator_impl.c
new file mode 100644
index 0000000..adccb52
--- /dev/null
+++ b/remote_services/examples/calculator_service/src/calculator_impl.c
@@ -0,0 +1,79 @@
+/**
+ *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.
+ */
+/*
+ * calculator_impl.c
+ *
+ * \date Oct 5, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <math.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "calculator_impl.h"
+
+celix_status_t calculator_create(calculator_pt *calculator) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *calculator = calloc(1, sizeof(**calculator));
+ if (!*calculator) {
+ status = CELIX_ENOMEM;
+ }
+
+ return status;
+}
+
+celix_status_t calculator_destroy(calculator_pt *calculator) {
+ free(*calculator);
+ return CELIX_SUCCESS;
+}
+
+celix_status_t calculator_add(calculator_pt calculator, double a, double b, double *result) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *result = a + b;
+ printf("CALCULATOR: Add: %f + %f = %f\n", a, b, *result);
+
+ return status;
+}
+
+celix_status_t calculator_sub(calculator_pt calculator, double a, double b, double *result) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *result = a - b;
+ printf("CALCULATOR: Sub: %f + %f = %f\n", a, b, *result);
+
+ return status;
+}
+
+celix_status_t calculator_sqrt(calculator_pt calculator, double a, double *result) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (a > 0) {
+ *result = sqrt(a);
+ printf("CALCULATOR: Sqrt: %f = %f\n", a, *result);
+ } else {
+ printf("CALCULATOR: Sqrt: %f = ERR\n", a);
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_service/src/calculator_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/src/calculator_impl.h b/remote_services/examples/calculator_service/src/calculator_impl.h
new file mode 100644
index 0000000..5e075e4
--- /dev/null
+++ b/remote_services/examples/calculator_service/src/calculator_impl.h
@@ -0,0 +1,43 @@
+/**
+ *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.
+ */
+/*
+ * calculator_impl.h
+ *
+ * \date Oct 5, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef CALCULATOR_IMPL_H_
+#define CALCULATOR_IMPL_H_
+
+#include "celix_errno.h"
+
+#include "calculator_service.h"
+
+struct calculator {
+};
+
+celix_status_t calculator_create(calculator_pt *calcuator);
+celix_status_t calculator_destroy(calculator_pt *calcuator);
+celix_status_t calculator_add(calculator_pt calcuator, double a, double b, double *result);
+celix_status_t calculator_sub(calculator_pt calcuator, double a, double b, double *result);
+celix_status_t calculator_sqrt(calculator_pt calcuator, double a, double *result);
+
+#endif /* CALCULATOR_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/CMakeLists.txt b/remote_services/examples/calculator_shell/CMakeLists.txt
index 980fa1a..78c0737 100644
--- a/remote_services/examples/calculator_shell/CMakeLists.txt
+++ b/remote_services/examples/calculator_shell/CMakeLists.txt
@@ -15,28 +15,22 @@
# specific language governing permissions and limitations
# under the License.
-include_directories("private/include")
-include_directories("../../../utils/public/include")
-include_directories("../calculator_service/public/include")
-
-add_bundle(calculator_shell SOURCES
- private/src/add_command
- private/src/sub_command
- private/src/sqrt_command
- private/src/calculator_shell_activator
-
- private/include/add_command.h
- private/include/sqrt_command.h
- private/include/sub_command.h
-
+add_bundle(calculator_shell
+ SOURCES
+ src/add_command
+ src/sub_command
+ src/sqrt_command
+ src/calculator_shell_activator
VERSION 0.0.1
SYMBOLIC_NAME "apache_celix_remoting_calculator_shell"
)
+target_include_directories(calculator_shell PRIVATE src)
+target_link_libraries(calculator_shell PRIVATE Celix::shell_api calculator_api)
bundle_files(calculator_shell
- ../calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
- #private/include/org.apache.celix.calc.api.Calculator2.descriptor ##Use this descriptor in case you want to try out versioning!
+ ../calculator_api/include/org.apache.celix.calc.api.Calculator2.descriptor
+ #src/org.apache.celix.calc.api.Calculator2.descriptor ##Use this descriptor in case you want to try out versioning!
DESTINATION .
)
-target_link_libraries(calculator_shell PRIVATE Celix::shell_api)
+
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/private/include/add_command.h
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/private/include/add_command.h b/remote_services/examples/calculator_shell/private/include/add_command.h
deleted file mode 100644
index 58a7bda..0000000
--- a/remote_services/examples/calculator_shell/private/include/add_command.h
+++ /dev/null
@@ -1,32 +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.
- */
-/*
- * add_command.h
- *
- * \date Oct 13, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef ADD_COMMAND_H_
-#define ADD_COMMAND_H_
-
-void addCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err);
-
-#endif /* ADD_COMMAND_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/private/include/org.apache.celix.calc.api.Calculator2.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/private/include/org.apache.celix.calc.api.Calculator2.descriptor b/remote_services/examples/calculator_shell/private/include/org.apache.celix.calc.api.Calculator2.descriptor
deleted file mode 100644
index 789af9a..0000000
--- a/remote_services/examples/calculator_shell/private/include/org.apache.celix.calc.api.Calculator2.descriptor
+++ /dev/null
@@ -1,11 +0,0 @@
-+:header
-+type=interface
-+name=calculator
-+version=1.2.3
-+:annotations
-+classname=org.example.Calculator
-+:types
-+:methods
-+add(DD)D=add(#am=handle;PDD#am=pre;*D)N
-+sub(DD)D=sub(#am=handle;PDD#am=pre;*D)N
-+sqrt(D)D=sqrt(#am=handle;PD#am=pre;*D)N
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/private/include/sqrt_command.h
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/private/include/sqrt_command.h b/remote_services/examples/calculator_shell/private/include/sqrt_command.h
deleted file mode 100644
index c9d07d2..0000000
--- a/remote_services/examples/calculator_shell/private/include/sqrt_command.h
+++ /dev/null
@@ -1,32 +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.
- */
-/*
- * sqrt_command.h
- *
- * \date Oct 13, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef SQRT_COMMAND_H_
-#define SQRT_COMMAND_H_
-
-void sqrtCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err);
-
-#endif /* SQRT_COMMAND_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/private/include/sub_command.h
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/private/include/sub_command.h b/remote_services/examples/calculator_shell/private/include/sub_command.h
deleted file mode 100644
index cf13616..0000000
--- a/remote_services/examples/calculator_shell/private/include/sub_command.h
+++ /dev/null
@@ -1,32 +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.
- */
-/*
- * sub_command.h
- *
- * \date Oct 13, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef SUB_COMMAND_H_
-#define SUB_COMMAND_H_
-
-void subCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err);
-
-#endif /* SUB_COMMAND_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/private/src/add_command.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/private/src/add_command.c b/remote_services/examples/calculator_shell/private/src/add_command.c
deleted file mode 100644
index b2520ae..0000000
--- a/remote_services/examples/calculator_shell/private/src/add_command.c
+++ /dev/null
@@ -1,101 +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.
- */
-/*
- * add_command.c
- *
- * \date Oct 13, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-#include <command.h>
-
-#include "array_list.h"
-#include "bundle_context.h"
-#include "add_command.h"
-#include "calculator_service.h"
-
-
-static celix_status_t addCommand_isNumeric(char *number, bool *ret);
-
-void addCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err) {
- celix_status_t status = CELIX_SUCCESS;
- service_reference_pt calculatorService = NULL;
-
- status = bundleContext_getServiceReference(context, (char *) CALCULATOR_SERVICE, &calculatorService);
- if (calculatorService == NULL) {
- fprintf(err, "ADD: Cannot get reference for %s. Trying to get one for %s\n", CALCULATOR_SERVICE, CALCULATOR2_SERVICE);
- status = bundleContext_getServiceReference(context, (char *) CALCULATOR2_SERVICE, &calculatorService);
- if (calculatorService == NULL) {
- fprintf(err, "ADD: Cannot get reference even for %s.\n", CALCULATOR2_SERVICE);
- }
- }
- if (status == CELIX_SUCCESS) {
- char *token = line;
- strtok_r(line, " ", &token);
- char *aStr = strtok_r(NULL, " ", &token);
- char *bStr = strtok_r(NULL, " ", &token);
- bool aNumeric, bNumeric;
- if (aStr != NULL && bStr != NULL) {
- addCommand_isNumeric(aStr, &aNumeric);
- addCommand_isNumeric(bStr, &bNumeric);
- if(aNumeric && bNumeric){
- calculator_service_pt calculator = NULL;
- status = bundleContext_getService(context, calculatorService, (void *) &calculator);
- if (status == CELIX_SUCCESS && calculator != NULL) {
- double a = atof(aStr);
- double b = atof(bStr);
- double result = 0;
- status = calculator->add(calculator->calculator, a, b, &result);
- if (status == CELIX_SUCCESS) {
- fprintf(out, "CALCULATOR_SHELL: Add: %f + %f = %f\n", a, b, result);
- } else {
- fprintf(err, "ADD: Unexpected exception in Calc service\n");
- }
- } else {
- fprintf(err, "No calc service available\n");
- }
- } else {
- fprintf(err, "ADD: Requires 2 numerical parameter\n");
- }
- } else {
- fprintf(err, "ADD: Requires 2 numerical parameter\n");
- }
- } else {
- fprintf(err, "No calc service available\n");
- }
-
- //return status;
-}
-
-static celix_status_t addCommand_isNumeric(char *number, bool *ret) {
- celix_status_t status = CELIX_SUCCESS;
- *ret = true;
- while(*number) {
- if(!isdigit(*number) && *number != '.') {
- *ret = false;
- break;
- }
- number++;
- }
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/private/src/calculator_shell_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/private/src/calculator_shell_activator.c b/remote_services/examples/calculator_shell/private/src/calculator_shell_activator.c
deleted file mode 100644
index d6b561b..0000000
--- a/remote_services/examples/calculator_shell/private/src/calculator_shell_activator.c
+++ /dev/null
@@ -1,125 +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.
- */
-/*
- * calculator_shell_activator.c
- *
- * \date Oct 13, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <string.h>
-#include <command.h>
-
-#include "bundle_activator.h"
-#include "bundle_context.h"
-#include "service_registration.h"
-
-#include "add_command.h"
-#include "sub_command.h"
-#include "sqrt_command.h"
-
-struct activator {
- service_registration_pt addCommand;
- command_service_pt addCmd;
- command_service_pt addCmdSrv;
-
- service_registration_pt subCommand;
- command_service_pt subCmd;
- command_service_pt subCmdSrv;
-
- service_registration_pt sqrtCommand;
- command_service_pt sqrtCmd;
- command_service_pt sqrtCmdSrv;
-};
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status = CELIX_SUCCESS;
- if (status == CELIX_SUCCESS) {
- *userData = calloc(1, sizeof(struct activator));
- if (!*userData) {
- status = CELIX_ENOMEM;
- } else {
- ((struct activator *) (*userData))->addCommand = NULL;
- ((struct activator *) (*userData))->subCommand = NULL;
- ((struct activator *) (*userData))->sqrtCommand = NULL;
-
- ((struct activator *) (*userData))->addCmd = NULL;
- ((struct activator *) (*userData))->subCmd = NULL;
- ((struct activator *) (*userData))->sqrtCmd = NULL;
-
- ((struct activator *) (*userData))->addCmdSrv = NULL;
- ((struct activator *) (*userData))->subCmdSrv = NULL;
- ((struct activator *) (*userData))->sqrtCmdSrv = NULL;
- }
- }
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
-
- struct activator * activator = (struct activator *) userData;
-
- activator->addCmdSrv = calloc(1, sizeof(*activator->addCmdSrv));
- activator->addCmdSrv->handle = context;
- activator->addCmdSrv->executeCommand = (void *)addCommand_execute;
- properties_pt props = properties_create();
- properties_set(props, OSGI_SHELL_COMMAND_NAME, "add");
- bundleContext_registerService(context, (char *)OSGI_SHELL_COMMAND_SERVICE_NAME, activator->addCmdSrv, props, &activator->addCommand);
-
-
- activator->sqrtCmdSrv = calloc(1, sizeof(*activator->sqrtCmdSrv));
- activator->sqrtCmdSrv->handle = context;
- activator->sqrtCmdSrv->executeCommand = (void *)sqrtCommand_execute;
- props = properties_create();
- properties_set(props, OSGI_SHELL_COMMAND_NAME, "sqrt");
- bundleContext_registerService(context, (char *)OSGI_SHELL_COMMAND_SERVICE_NAME, activator->sqrtCmdSrv, props, &activator->sqrtCommand);
-
- activator->subCmdSrv = calloc(1, sizeof(*activator->subCmdSrv));
- activator->subCmdSrv->handle = context;
- activator->subCmdSrv->executeCommand = (void *)subCommand_execute;
- props = properties_create();
- properties_set(props, OSGI_SHELL_COMMAND_NAME, "sub");
- bundleContext_registerService(context, (char *)OSGI_SHELL_COMMAND_SERVICE_NAME, activator->subCmdSrv, props, &activator->subCommand);
-
- return status;
-}
-
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator * activator = (struct activator *) userData;
- serviceRegistration_unregister(activator->addCommand);
- serviceRegistration_unregister(activator->subCommand);
- serviceRegistration_unregister(activator->sqrtCommand);
-
- free(activator->addCmdSrv);
- free(activator->subCmdSrv);
- free(activator->sqrtCmdSrv);
-
- return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- free(userData);
- return CELIX_SUCCESS;
-}
-
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/private/src/sqrt_command.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/private/src/sqrt_command.c b/remote_services/examples/calculator_shell/private/src/sqrt_command.c
deleted file mode 100644
index 2e7238c..0000000
--- a/remote_services/examples/calculator_shell/private/src/sqrt_command.c
+++ /dev/null
@@ -1,96 +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.
- */
-/*
- * sqrt_command.c
- *
- * \date Oct 13, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-
-#include "array_list.h"
-#include "bundle_context.h"
-#include "sqrt_command.h"
-#include "calculator_service.h"
-
-static celix_status_t sqrtCommand_isNumeric(char *number, bool *ret);
-
-void sqrtCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err) {
- celix_status_t status = CELIX_SUCCESS;
- service_reference_pt calculatorService = NULL;
-
- status = bundleContext_getServiceReference(context, (char *) CALCULATOR_SERVICE, &calculatorService);
- if (calculatorService == NULL) {
- fprintf(err, "SQRT: Cannot get reference for %s. Trying to get one for %s\n", CALCULATOR_SERVICE, CALCULATOR2_SERVICE);
- status = bundleContext_getServiceReference(context, (char *) CALCULATOR2_SERVICE, &calculatorService);
- if (calculatorService == NULL) {
- fprintf(err, "SQRT: Cannot get reference even for %s.\n", CALCULATOR2_SERVICE);
- }
- }
- if (status == CELIX_SUCCESS) {
- char *token = line;
- strtok_r(line, " ", &token);
- char *aStr = strtok_r(NULL, " ", &token);
- if(aStr != NULL){
- bool numeric;
- sqrtCommand_isNumeric(aStr, &numeric);
- if (numeric) {
- calculator_service_pt calculator = NULL;
- status = bundleContext_getService(context, calculatorService, (void *) &calculator);
- if (status == CELIX_SUCCESS && calculator != NULL) {
- double a = atof(aStr);
- double result = 0;
- status = calculator->sqrt(calculator->calculator, a, &result);
- if (status == CELIX_SUCCESS) {
- fprintf(out, "CALCULATOR_SHELL: Sqrt: %f = %f\n", a, result);
- } else {
- fprintf(err, "SQRT: Unexpected exception in Calc service\n");
- }
- } else {
- fprintf(err, "No calc service available\n");
- }
- } else {
- fprintf(err, "SQRT: Requires 1 numerical parameter\n");
- }
- } else {
- fprintf(err, "SQRT: Requires 1 numerical parameter\n");
- }
- } else {
- fprintf(err, "No calc service available\n");
- }
-
- //return status;
-}
-
-static celix_status_t sqrtCommand_isNumeric(char *number, bool *ret) {
- celix_status_t status = CELIX_SUCCESS;
- *ret = true;
- while(*number) {
- if(!isdigit(*number) && *number != '.') {
- *ret = false;
- break;
- }
- number++;
- }
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/private/src/sub_command.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/private/src/sub_command.c b/remote_services/examples/calculator_shell/private/src/sub_command.c
deleted file mode 100644
index 672ea4c..0000000
--- a/remote_services/examples/calculator_shell/private/src/sub_command.c
+++ /dev/null
@@ -1,99 +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.
- */
-/*
- * sub_command.c
- *
- * \date Oct 13, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-
-#include "array_list.h"
-#include "bundle_context.h"
-#include "sub_command.h"
-#include "calculator_service.h"
-
-static celix_status_t subCommand_isNumeric(char *number, bool *ret);
-
-void subCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err) {
- celix_status_t status = CELIX_SUCCESS;
- service_reference_pt calculatorService = NULL;
-
- status = bundleContext_getServiceReference(context, (char *) CALCULATOR_SERVICE, &calculatorService);
- if (calculatorService == NULL) {
- fprintf(err, "SUB: Cannot get reference for %s. Trying to get one for %s\n", CALCULATOR_SERVICE, CALCULATOR2_SERVICE);
- status = bundleContext_getServiceReference(context, (char *) CALCULATOR2_SERVICE, &calculatorService);
- if (calculatorService == NULL) {
- fprintf(err, "SUB: Cannot get reference even for %s.\n", CALCULATOR2_SERVICE);
- }
- }
- if (status == CELIX_SUCCESS) {
- char *token = line;
- strtok_r(line, " ", &token);
- char *aStr = strtok_r(NULL, " ", &token);
- char *bStr = strtok_r(NULL, " ", &token);
- if(aStr != NULL && bStr != NULL ){
- bool aNumeric, bNumeric;
- subCommand_isNumeric(aStr, &aNumeric);
- subCommand_isNumeric(bStr, &bNumeric);
- if (aNumeric && bNumeric) {
- calculator_service_pt calculator = NULL;
- status = bundleContext_getService(context, calculatorService, (void *) &calculator);
- if (status == CELIX_SUCCESS && calculator != NULL) {
- double a = atof(aStr);
- double b = atof(bStr);
- double result = 0;
- status = calculator->sub(calculator->calculator, a, b, &result);
- if (status == CELIX_SUCCESS) {
- fprintf(out, "CALCULATOR_SHELL: Sub: %f - %f = %f\n", a, b, result);
- } else {
- fprintf(err, "SUB: Unexpected exception in Calc service\n");
- }
- } else {
- fprintf(err, "No calc service available\n");
- }
- } else {
- fprintf(err, "SUB: Requires 2 numerical parameter\n");
- }
- } else {
- fprintf(err, "SUB: Requires 2 numerical parameter\n");
- }
- } else {
- fprintf(err, "No calc service available\n");
- }
-
- //return status;
-}
-
-static celix_status_t subCommand_isNumeric(char *number, bool *ret) {
- celix_status_t status = CELIX_SUCCESS;
- *ret = true;
- while(*number) {
- if(!isdigit(*number) && *number != '.') {
- *ret = false;
- break;
- }
- number++;
- }
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/src/add_command.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/src/add_command.c b/remote_services/examples/calculator_shell/src/add_command.c
new file mode 100644
index 0000000..b2520ae
--- /dev/null
+++ b/remote_services/examples/calculator_shell/src/add_command.c
@@ -0,0 +1,101 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+/*
+ * add_command.c
+ *
+ * \date Oct 13, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <command.h>
+
+#include "array_list.h"
+#include "bundle_context.h"
+#include "add_command.h"
+#include "calculator_service.h"
+
+
+static celix_status_t addCommand_isNumeric(char *number, bool *ret);
+
+void addCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err) {
+ celix_status_t status = CELIX_SUCCESS;
+ service_reference_pt calculatorService = NULL;
+
+ status = bundleContext_getServiceReference(context, (char *) CALCULATOR_SERVICE, &calculatorService);
+ if (calculatorService == NULL) {
+ fprintf(err, "ADD: Cannot get reference for %s. Trying to get one for %s\n", CALCULATOR_SERVICE, CALCULATOR2_SERVICE);
+ status = bundleContext_getServiceReference(context, (char *) CALCULATOR2_SERVICE, &calculatorService);
+ if (calculatorService == NULL) {
+ fprintf(err, "ADD: Cannot get reference even for %s.\n", CALCULATOR2_SERVICE);
+ }
+ }
+ if (status == CELIX_SUCCESS) {
+ char *token = line;
+ strtok_r(line, " ", &token);
+ char *aStr = strtok_r(NULL, " ", &token);
+ char *bStr = strtok_r(NULL, " ", &token);
+ bool aNumeric, bNumeric;
+ if (aStr != NULL && bStr != NULL) {
+ addCommand_isNumeric(aStr, &aNumeric);
+ addCommand_isNumeric(bStr, &bNumeric);
+ if(aNumeric && bNumeric){
+ calculator_service_pt calculator = NULL;
+ status = bundleContext_getService(context, calculatorService, (void *) &calculator);
+ if (status == CELIX_SUCCESS && calculator != NULL) {
+ double a = atof(aStr);
+ double b = atof(bStr);
+ double result = 0;
+ status = calculator->add(calculator->calculator, a, b, &result);
+ if (status == CELIX_SUCCESS) {
+ fprintf(out, "CALCULATOR_SHELL: Add: %f + %f = %f\n", a, b, result);
+ } else {
+ fprintf(err, "ADD: Unexpected exception in Calc service\n");
+ }
+ } else {
+ fprintf(err, "No calc service available\n");
+ }
+ } else {
+ fprintf(err, "ADD: Requires 2 numerical parameter\n");
+ }
+ } else {
+ fprintf(err, "ADD: Requires 2 numerical parameter\n");
+ }
+ } else {
+ fprintf(err, "No calc service available\n");
+ }
+
+ //return status;
+}
+
+static celix_status_t addCommand_isNumeric(char *number, bool *ret) {
+ celix_status_t status = CELIX_SUCCESS;
+ *ret = true;
+ while(*number) {
+ if(!isdigit(*number) && *number != '.') {
+ *ret = false;
+ break;
+ }
+ number++;
+ }
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/src/add_command.h
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/src/add_command.h b/remote_services/examples/calculator_shell/src/add_command.h
new file mode 100644
index 0000000..58a7bda
--- /dev/null
+++ b/remote_services/examples/calculator_shell/src/add_command.h
@@ -0,0 +1,32 @@
+/**
+ *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.
+ */
+/*
+ * add_command.h
+ *
+ * \date Oct 13, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef ADD_COMMAND_H_
+#define ADD_COMMAND_H_
+
+void addCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err);
+
+#endif /* ADD_COMMAND_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/src/calculator_shell_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/src/calculator_shell_activator.c b/remote_services/examples/calculator_shell/src/calculator_shell_activator.c
new file mode 100644
index 0000000..d6b561b
--- /dev/null
+++ b/remote_services/examples/calculator_shell/src/calculator_shell_activator.c
@@ -0,0 +1,125 @@
+/**
+ *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.
+ */
+/*
+ * calculator_shell_activator.c
+ *
+ * \date Oct 13, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <string.h>
+#include <command.h>
+
+#include "bundle_activator.h"
+#include "bundle_context.h"
+#include "service_registration.h"
+
+#include "add_command.h"
+#include "sub_command.h"
+#include "sqrt_command.h"
+
+struct activator {
+ service_registration_pt addCommand;
+ command_service_pt addCmd;
+ command_service_pt addCmdSrv;
+
+ service_registration_pt subCommand;
+ command_service_pt subCmd;
+ command_service_pt subCmdSrv;
+
+ service_registration_pt sqrtCommand;
+ command_service_pt sqrtCmd;
+ command_service_pt sqrtCmdSrv;
+};
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+ celix_status_t status = CELIX_SUCCESS;
+ if (status == CELIX_SUCCESS) {
+ *userData = calloc(1, sizeof(struct activator));
+ if (!*userData) {
+ status = CELIX_ENOMEM;
+ } else {
+ ((struct activator *) (*userData))->addCommand = NULL;
+ ((struct activator *) (*userData))->subCommand = NULL;
+ ((struct activator *) (*userData))->sqrtCommand = NULL;
+
+ ((struct activator *) (*userData))->addCmd = NULL;
+ ((struct activator *) (*userData))->subCmd = NULL;
+ ((struct activator *) (*userData))->sqrtCmd = NULL;
+
+ ((struct activator *) (*userData))->addCmdSrv = NULL;
+ ((struct activator *) (*userData))->subCmdSrv = NULL;
+ ((struct activator *) (*userData))->sqrtCmdSrv = NULL;
+ }
+ }
+
+ return CELIX_SUCCESS;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ struct activator * activator = (struct activator *) userData;
+
+ activator->addCmdSrv = calloc(1, sizeof(*activator->addCmdSrv));
+ activator->addCmdSrv->handle = context;
+ activator->addCmdSrv->executeCommand = (void *)addCommand_execute;
+ properties_pt props = properties_create();
+ properties_set(props, OSGI_SHELL_COMMAND_NAME, "add");
+ bundleContext_registerService(context, (char *)OSGI_SHELL_COMMAND_SERVICE_NAME, activator->addCmdSrv, props, &activator->addCommand);
+
+
+ activator->sqrtCmdSrv = calloc(1, sizeof(*activator->sqrtCmdSrv));
+ activator->sqrtCmdSrv->handle = context;
+ activator->sqrtCmdSrv->executeCommand = (void *)sqrtCommand_execute;
+ props = properties_create();
+ properties_set(props, OSGI_SHELL_COMMAND_NAME, "sqrt");
+ bundleContext_registerService(context, (char *)OSGI_SHELL_COMMAND_SERVICE_NAME, activator->sqrtCmdSrv, props, &activator->sqrtCommand);
+
+ activator->subCmdSrv = calloc(1, sizeof(*activator->subCmdSrv));
+ activator->subCmdSrv->handle = context;
+ activator->subCmdSrv->executeCommand = (void *)subCommand_execute;
+ props = properties_create();
+ properties_set(props, OSGI_SHELL_COMMAND_NAME, "sub");
+ bundleContext_registerService(context, (char *)OSGI_SHELL_COMMAND_SERVICE_NAME, activator->subCmdSrv, props, &activator->subCommand);
+
+ return status;
+}
+
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator * activator = (struct activator *) userData;
+ serviceRegistration_unregister(activator->addCommand);
+ serviceRegistration_unregister(activator->subCommand);
+ serviceRegistration_unregister(activator->sqrtCommand);
+
+ free(activator->addCmdSrv);
+ free(activator->subCmdSrv);
+ free(activator->sqrtCmdSrv);
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+ free(userData);
+ return CELIX_SUCCESS;
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/src/org.apache.celix.calc.api.Calculator2.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/src/org.apache.celix.calc.api.Calculator2.descriptor b/remote_services/examples/calculator_shell/src/org.apache.celix.calc.api.Calculator2.descriptor
new file mode 100644
index 0000000..789af9a
--- /dev/null
+++ b/remote_services/examples/calculator_shell/src/org.apache.celix.calc.api.Calculator2.descriptor
@@ -0,0 +1,11 @@
++:header
++type=interface
++name=calculator
++version=1.2.3
++:annotations
++classname=org.example.Calculator
++:types
++:methods
++add(DD)D=add(#am=handle;PDD#am=pre;*D)N
++sub(DD)D=sub(#am=handle;PDD#am=pre;*D)N
++sqrt(D)D=sqrt(#am=handle;PD#am=pre;*D)N
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/src/sqrt_command.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/src/sqrt_command.c b/remote_services/examples/calculator_shell/src/sqrt_command.c
new file mode 100644
index 0000000..2e7238c
--- /dev/null
+++ b/remote_services/examples/calculator_shell/src/sqrt_command.c
@@ -0,0 +1,96 @@
+/**
+ *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.
+ */
+/*
+ * sqrt_command.c
+ *
+ * \date Oct 13, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+
+#include "array_list.h"
+#include "bundle_context.h"
+#include "sqrt_command.h"
+#include "calculator_service.h"
+
+static celix_status_t sqrtCommand_isNumeric(char *number, bool *ret);
+
+void sqrtCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err) {
+ celix_status_t status = CELIX_SUCCESS;
+ service_reference_pt calculatorService = NULL;
+
+ status = bundleContext_getServiceReference(context, (char *) CALCULATOR_SERVICE, &calculatorService);
+ if (calculatorService == NULL) {
+ fprintf(err, "SQRT: Cannot get reference for %s. Trying to get one for %s\n", CALCULATOR_SERVICE, CALCULATOR2_SERVICE);
+ status = bundleContext_getServiceReference(context, (char *) CALCULATOR2_SERVICE, &calculatorService);
+ if (calculatorService == NULL) {
+ fprintf(err, "SQRT: Cannot get reference even for %s.\n", CALCULATOR2_SERVICE);
+ }
+ }
+ if (status == CELIX_SUCCESS) {
+ char *token = line;
+ strtok_r(line, " ", &token);
+ char *aStr = strtok_r(NULL, " ", &token);
+ if(aStr != NULL){
+ bool numeric;
+ sqrtCommand_isNumeric(aStr, &numeric);
+ if (numeric) {
+ calculator_service_pt calculator = NULL;
+ status = bundleContext_getService(context, calculatorService, (void *) &calculator);
+ if (status == CELIX_SUCCESS && calculator != NULL) {
+ double a = atof(aStr);
+ double result = 0;
+ status = calculator->sqrt(calculator->calculator, a, &result);
+ if (status == CELIX_SUCCESS) {
+ fprintf(out, "CALCULATOR_SHELL: Sqrt: %f = %f\n", a, result);
+ } else {
+ fprintf(err, "SQRT: Unexpected exception in Calc service\n");
+ }
+ } else {
+ fprintf(err, "No calc service available\n");
+ }
+ } else {
+ fprintf(err, "SQRT: Requires 1 numerical parameter\n");
+ }
+ } else {
+ fprintf(err, "SQRT: Requires 1 numerical parameter\n");
+ }
+ } else {
+ fprintf(err, "No calc service available\n");
+ }
+
+ //return status;
+}
+
+static celix_status_t sqrtCommand_isNumeric(char *number, bool *ret) {
+ celix_status_t status = CELIX_SUCCESS;
+ *ret = true;
+ while(*number) {
+ if(!isdigit(*number) && *number != '.') {
+ *ret = false;
+ break;
+ }
+ number++;
+ }
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/src/sqrt_command.h
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/src/sqrt_command.h b/remote_services/examples/calculator_shell/src/sqrt_command.h
new file mode 100644
index 0000000..c9d07d2
--- /dev/null
+++ b/remote_services/examples/calculator_shell/src/sqrt_command.h
@@ -0,0 +1,32 @@
+/**
+ *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.
+ */
+/*
+ * sqrt_command.h
+ *
+ * \date Oct 13, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef SQRT_COMMAND_H_
+#define SQRT_COMMAND_H_
+
+void sqrtCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err);
+
+#endif /* SQRT_COMMAND_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/src/sub_command.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/src/sub_command.c b/remote_services/examples/calculator_shell/src/sub_command.c
new file mode 100644
index 0000000..672ea4c
--- /dev/null
+++ b/remote_services/examples/calculator_shell/src/sub_command.c
@@ -0,0 +1,99 @@
+/**
+ *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.
+ */
+/*
+ * sub_command.c
+ *
+ * \date Oct 13, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+
+#include "array_list.h"
+#include "bundle_context.h"
+#include "sub_command.h"
+#include "calculator_service.h"
+
+static celix_status_t subCommand_isNumeric(char *number, bool *ret);
+
+void subCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err) {
+ celix_status_t status = CELIX_SUCCESS;
+ service_reference_pt calculatorService = NULL;
+
+ status = bundleContext_getServiceReference(context, (char *) CALCULATOR_SERVICE, &calculatorService);
+ if (calculatorService == NULL) {
+ fprintf(err, "SUB: Cannot get reference for %s. Trying to get one for %s\n", CALCULATOR_SERVICE, CALCULATOR2_SERVICE);
+ status = bundleContext_getServiceReference(context, (char *) CALCULATOR2_SERVICE, &calculatorService);
+ if (calculatorService == NULL) {
+ fprintf(err, "SUB: Cannot get reference even for %s.\n", CALCULATOR2_SERVICE);
+ }
+ }
+ if (status == CELIX_SUCCESS) {
+ char *token = line;
+ strtok_r(line, " ", &token);
+ char *aStr = strtok_r(NULL, " ", &token);
+ char *bStr = strtok_r(NULL, " ", &token);
+ if(aStr != NULL && bStr != NULL ){
+ bool aNumeric, bNumeric;
+ subCommand_isNumeric(aStr, &aNumeric);
+ subCommand_isNumeric(bStr, &bNumeric);
+ if (aNumeric && bNumeric) {
+ calculator_service_pt calculator = NULL;
+ status = bundleContext_getService(context, calculatorService, (void *) &calculator);
+ if (status == CELIX_SUCCESS && calculator != NULL) {
+ double a = atof(aStr);
+ double b = atof(bStr);
+ double result = 0;
+ status = calculator->sub(calculator->calculator, a, b, &result);
+ if (status == CELIX_SUCCESS) {
+ fprintf(out, "CALCULATOR_SHELL: Sub: %f - %f = %f\n", a, b, result);
+ } else {
+ fprintf(err, "SUB: Unexpected exception in Calc service\n");
+ }
+ } else {
+ fprintf(err, "No calc service available\n");
+ }
+ } else {
+ fprintf(err, "SUB: Requires 2 numerical parameter\n");
+ }
+ } else {
+ fprintf(err, "SUB: Requires 2 numerical parameter\n");
+ }
+ } else {
+ fprintf(err, "No calc service available\n");
+ }
+
+ //return status;
+}
+
+static celix_status_t subCommand_isNumeric(char *number, bool *ret) {
+ celix_status_t status = CELIX_SUCCESS;
+ *ret = true;
+ while(*number) {
+ if(!isdigit(*number) && *number != '.') {
+ *ret = false;
+ break;
+ }
+ number++;
+ }
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/examples/calculator_shell/src/sub_command.h
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/src/sub_command.h b/remote_services/examples/calculator_shell/src/sub_command.h
new file mode 100644
index 0000000..cf13616
--- /dev/null
+++ b/remote_services/examples/calculator_shell/src/sub_command.h
@@ -0,0 +1,32 @@
+/**
+ *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.
+ */
+/*
+ * sub_command.h
+ *
+ * \date Oct 13, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef SUB_COMMAND_H_
+#define SUB_COMMAND_H_
+
+void subCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err);
+
+#endif /* SUB_COMMAND_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/CMakeLists.txt b/remote_services/remote_service_admin/CMakeLists.txt
deleted file mode 100644
index ac703e2..0000000
--- a/remote_services/remote_service_admin/CMakeLists.txt
+++ /dev/null
@@ -1,46 +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.
-
-install (FILES
- public/include/remote_endpoint_impl.h
- public/include/remote_endpoint.h
- public/include/remote_proxy.h
- public/include/remote_service_admin.h
- public/include/export_registration.h
- public/include/import_registration.h
- public/include/endpoint_description.h
- public/include/endpoint_listener.h
- public/include/remote_constants.h
- DESTINATION
- include/celix/remote_service_admin
- COMPONENT
- remote_service_admin
-)
-install (FILES
- private/src/remote_proxy_factory_impl.c
- DESTINATION
- share/celix/remote_service_admin
- COMPONENT
- remote_service_admin
-)
-install (FILES
- public/include/endpoint_listener.h
- DESTINATION
- include/celix/endpoint_listener
- COMPONENT
- remote_service_admin
-)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/README.md
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/README.md b/remote_services/remote_service_admin/README.md
deleted file mode 100644
index c4bdebd..0000000
--- a/remote_services/remote_service_admin/README.md
+++ /dev/null
@@ -1,11 +0,0 @@
-## Remote Service Admin
-
-The Remote Service Admin (RSA) provides the mechanisms to import and export services when instructed to do so by the Topology Manager.
-
-To delegate method calls to the actual service implementation, the RSA_SHM and the RSA_HTTP are using "endpoint/proxy" bundles, which has all the knowledge about the marshalling and unmarshalling of data for the service. The RSA_DFI implementation combines a [foreign function interface](https://en.wikipedia.org/wiki/Foreign_function_interface) technique together with manualy created descriptors.
-
-Note that this folder contains code commonly used by the RSA implementations and therefore does not include any CMAKE configuration.
-
-###### Properties
- ENDPOINTS defines the relative directory where endpoints and proxys can be found (default: endpoints)
- CELIX_FRAMEWORK_EXTENDER_PATH Used in RSA_DFI only. Can be used to define a path to use as an extender path point for the framework bundle. For normal bundles the bundle cache is used.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/private/include/export_registration_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/private/include/export_registration_impl.h b/remote_services/remote_service_admin/private/include/export_registration_impl.h
deleted file mode 100644
index bb276f9..0000000
--- a/remote_services/remote_service_admin/private/include/export_registration_impl.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.
- */
-/*
- * export_registration_impl.h
- *
- * \date Oct 6, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef EXPORT_REGISTRATION_IMPL_H_
-#define EXPORT_REGISTRATION_IMPL_H_
-
-#include "remote_service_admin.h"
-#include "remote_endpoint.h"
-#include "service_tracker.h"
-#include "log_helper.h"
-
-struct export_registration {
- bundle_context_pt context;
- remote_service_admin_pt rsa;
- endpoint_description_pt endpointDescription;
- service_reference_pt reference;
- log_helper_pt loghelper;
-
- service_tracker_pt tracker;
- service_tracker_pt endpointTracker;
-
- remote_endpoint_service_pt endpoint;
-
- export_reference_pt exportReference;
- bundle_pt bundle;
-
- bool closed;
-};
-
-celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, remote_service_admin_pt rsa, bundle_context_pt context, export_registration_pt *registration);
-celix_status_t exportRegistration_destroy(export_registration_pt *registration);
-celix_status_t exportRegistration_open(export_registration_pt registration);
-
-celix_status_t exportRegistration_setEndpointDescription(export_registration_pt registration, endpoint_description_pt endpointDescription);
-celix_status_t exportRegistration_startTracking(export_registration_pt registration);
-celix_status_t exportRegistration_stopTracking(export_registration_pt registration);
-
-#endif /* EXPORT_REGISTRATION_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/private/include/import_registration_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/private/include/import_registration_impl.h b/remote_services/remote_service_admin/private/include/import_registration_impl.h
deleted file mode 100644
index 7aa397f..0000000
--- a/remote_services/remote_service_admin/private/include/import_registration_impl.h
+++ /dev/null
@@ -1,81 +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.
- */
-/*
- * import_registration_impl.h
- *
- * \date Oct 14, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef IMPORT_REGISTRATION_IMPL_H_
-#define IMPORT_REGISTRATION_IMPL_H_
-
-#include "remote_service_admin.h"
-#include "remote_proxy.h"
-#include "service_tracker.h"
-#include "log_helper.h"
-
-struct import_registration {
- bundle_context_pt context;
- endpoint_description_pt endpointDescription;
-
- service_reference_pt reference;
- import_reference_pt importReference;
-
- remote_service_admin_pt rsa;
- sendToHandle sendToCallback;
-
- bool closed;
-};
-
-
-
-struct import_registration_factory
-{
- char* serviceName;
- log_helper_pt loghelper;
- remote_proxy_factory_service_pt trackedFactory;
- service_tracker_pt proxyFactoryTracker;
- bundle_context_pt context;
- array_list_pt registrations;
- bundle_pt bundle;
-};
-
-
-celix_status_t importRegistration_create(endpoint_description_pt endpoint, remote_service_admin_pt rsa, sendToHandle callback, bundle_context_pt context, import_registration_pt *registration);
-celix_status_t importRegistration_destroy(import_registration_pt registration);
-
-celix_status_t importRegistration_setEndpointDescription(import_registration_pt registration, endpoint_description_pt endpointDescription);
-celix_status_t importRegistration_setHandler(import_registration_pt registration, void * handler);
-celix_status_t importRegistration_setCallback(import_registration_pt registration, sendToHandle callback);
-
-celix_status_t importRegistration_getException(import_registration_pt registration);
-celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference);
-
-celix_status_t importRegistration_createProxyFactoryTracker(import_registration_factory_pt registration_factory, service_tracker_pt *tracker);
-
-celix_status_t importRegistrationFactory_destroy(import_registration_factory_pt* registration_factory);
-//celix_status_t importRegistrationFactory_open(import_registration_factory_pt registration_factory);
-celix_status_t importRegistrationFactory_close(import_registration_factory_pt registration_factory);
-celix_status_t importRegistrationFactory_install(log_helper_pt helper, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory);
-
-
-
-#endif /* IMPORT_REGISTRATION_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h b/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
deleted file mode 100644
index e8a5e1f..0000000
--- a/remote_services/remote_service_admin/private/include/remote_service_admin_impl.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.
- */
-/*
- * remote_service_admin_impl.h
- *
- * \date Dec 5, 2013
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_SERVICE_ADMIN_IMPL_H_
-#define REMOTE_SERVICE_ADMIN_IMPL_H_
-
-#include "remote_service_admin.h"
-
-#define BUNDLE_STORE_PROPERTY_NAME "ENDPOINTS"
-#define DEFAULT_BUNDLE_STORE "endpoints"
-
-celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin);
-celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin);
-
-celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *methodSignature, char **reply, int* replyStatus);
-
-celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
-celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration);
-celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services);
-celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services);
-celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
-celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration);
-
-celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description);
-
-#endif /* REMOTE_SERVICE_ADMIN_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin/private/src/endpoint_description.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/private/src/endpoint_description.c b/remote_services/remote_service_admin/private/src/endpoint_description.c
deleted file mode 100644
index 0d8b684..0000000
--- a/remote_services/remote_service_admin/private/src/endpoint_description.c
+++ /dev/null
@@ -1,89 +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.
- */
-/*
- * endpoint_description.c
- *
- * \date 25 Jul 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <string.h>
-
-#include "celix_errno.h"
-#include "celix_log.h"
-
-#include "endpoint_description.h"
-#include "remote_constants.h"
-#include "constants.h"
-
-static celix_status_t endpointDescription_verifyLongProperty(properties_pt properties, char *propertyName, unsigned long *longProperty);
-
-celix_status_t endpointDescription_create(properties_pt properties, endpoint_description_pt *endpointDescription) {
- celix_status_t status = CELIX_SUCCESS;
-
- unsigned long serviceId = 0UL;
- status = endpointDescription_verifyLongProperty(properties, (char *) OSGI_RSA_ENDPOINT_SERVICE_ID, &serviceId);
- if (status != CELIX_SUCCESS) {
- return status;
- }
-
- endpoint_description_pt ep = calloc(1,sizeof(*ep));
-
- ep->properties = properties;
- ep->frameworkUUID = (char*)properties_get(properties, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
- ep->id = (char*)properties_get(properties, OSGI_RSA_ENDPOINT_ID);
- ep->service = strndup(properties_get(properties, OSGI_FRAMEWORK_OBJECTCLASS), 1024*10);
- ep->serviceId = serviceId;
-
- if (!(ep->frameworkUUID) || !(ep->id) || !(ep->service) ) {
- fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "ENDPOINT_DESCRIPTION: incomplete description!.");
- status = CELIX_BUNDLE_EXCEPTION;
- }
-
- if(status == CELIX_SUCCESS){
- *endpointDescription = ep;
- }
- else{
- *endpointDescription = NULL;
- free(ep);
- }
-
- return status;
-}
-
-celix_status_t endpointDescription_destroy(endpoint_description_pt description) {
- properties_destroy(description->properties);
- free(description->service);
- free(description);
- return CELIX_SUCCESS;
-}
-
-static celix_status_t endpointDescription_verifyLongProperty(properties_pt properties, char *propertyName, unsigned long *longProperty) {
- celix_status_t status = CELIX_SUCCESS;
-
- const char *value = properties_get(properties, propertyName);
- if (value == NULL) {
- *longProperty = 0UL;
- } else {
- *longProperty = strtoul(value,NULL,10);
- }
-
- return status;
-}
[28/54] [abbrv] celix git commit: CELIX-417: Refactors CMake usage
for example embedded, dm and dm_cxx
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase3/src/phase3_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/src/phase3_cmp.h b/examples/dm_example/phase3/src/phase3_cmp.h
new file mode 100644
index 0000000..9c63845
--- /dev/null
+++ b/examples/dm_example/phase3/src/phase3_cmp.h
@@ -0,0 +1,45 @@
+/**
+ *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.
+ */
+/*
+ * publisher.h
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PHASE3_CMP_H
+#define PHASE3_CMP_H
+
+#include "phase2.h"
+
+typedef struct phase3_cmp_struct phase3_cmp_t;
+
+phase3_cmp_t *phase3_create();
+int phase3_init(phase3_cmp_t *cmp);
+int phase3_start(phase3_cmp_t *cmp);
+int phase3_stop(phase3_cmp_t *cmp);
+int phase3_deinit(phase3_cmp_t *cmp);
+void phase3_destroy(phase3_cmp_t *cmp);
+
+int phase3_addPhase2(phase3_cmp_t *cmp, const phase2_t* phase2);
+int phase3_removePhase2(phase3_cmp_t *cmp, const phase2_t* phase2);
+
+
+#endif //PHASE3_CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/services/phase1.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/services/phase1.h b/examples/dm_example/services/phase1.h
deleted file mode 100644
index 04e9da7..0000000
--- a/examples/dm_example/services/phase1.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.
- */
-/*
- * publisher.h
- *
- * \date Aug 23, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PHASE1_H_
-#define PHASE1_H_
-
-#define PHASE1_NAME "PHASE1"
-#define PHASE1_VERSION "1.2.2.0"
-#define PHASE1_RANGE_ALL "[1.2.2.0,4.5.6.x)"
-#define PHASE1_RANGE_EXACT "[1.2.2.0,1.2.2.0]"
-
-
-
-struct phase1_struct {
- void *handle;
- int (*getData)(void *handle, unsigned int *data);
-};
-
-typedef struct phase1_struct phase1_t;
-
-#endif /* PHASE1_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/services/phase2.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/services/phase2.h b/examples/dm_example/services/phase2.h
deleted file mode 100644
index 2f4df86..0000000
--- a/examples/dm_example/services/phase2.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.
- */
-/*
- * publisher.h
- *
- * \date Aug 23, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PHASE2_H
-#define PHASE2_H
-
-#define PHASE2_NAME "PHASE2"
-#define PHASE2_VERSION "1.0.0.0"
-
-struct phase2_struct {
- void *handle;
- void (*getData)(void *handle, double *data);
-};
-
-typedef struct phase2_struct phase2_t;
-
-
-#endif /* PHASE2_H */
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/CMakeLists.txt b/examples/dm_example_cxx/CMakeLists.txt
index 012f706..9ef4c1e 100644
--- a/examples/dm_example_cxx/CMakeLists.txt
+++ b/examples/dm_example_cxx/CMakeLists.txt
@@ -15,17 +15,11 @@
# specific language governing permissions and limitations
# under the License.
if (BUILD_DEPENDENCY_MANAGER_CXX)
- include_directories(
- ${PROJECT_SOURCE_DIR}/dependency_manager/public/include
- ${PROJECT_SOURCE_DIR}/dependency_manager_cxx/include
- ${PROJECT_SOURCE_DIR}/utils/public/include
- ${PROJECT_SOURCE_DIR}/log_service/public/include
- api
- )
+
+ add_subdirectory(api)
add_subdirectory(phase1)
- add_subdirectory(phase2a)
- add_subdirectory(phase2b)
+ add_subdirectory(phase2)
add_subdirectory(phase3)
add_subdirectory(phase3_locking)
@@ -40,11 +34,11 @@ if (BUILD_DEPENDENCY_MANAGER_CXX)
Celix::log_service
Celix::log_writer_stdout
- phase1_cxx
- phase2a_cxx
- phase2b_cxx
- phase3_cxx
- phase3_locking_cxx
+ dm_example_cxx_phase1
+ dm_example_cxx_phase2a
+ dm_example_cxx_phase2b
+ dm_example_cxx_phase3
+ dm_example_cxx_phase3_locking
PROPERTIES
LOGHELPER_ENABLE_STDOUT_FALLBACK=true
)
@@ -61,11 +55,11 @@ if (BUILD_DEPENDENCY_MANAGER_CXX)
Celix::log_service
Celix::log_writer_stdout
- phase1_cxx
- phase2a_cxx
- phase2b_cxx
- phase3_cxx
- phase3_locking_cxx
+ dm_example_cxx_phase1
+ dm_example_cxx_phase2a
+ dm_example_cxx_phase2b
+ dm_example_cxx_phase3
+ dm_example_cxx_phase3_locking
PROPERTIES
LOGHELPER_ENABLE_STDOUT_FALLBACK=true
)
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/api/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/api/CMakeLists.txt b/examples/dm_example_cxx/api/CMakeLists.txt
new file mode 100644
index 0000000..d1d07d5
--- /dev/null
+++ b/examples/dm_example_cxx/api/CMakeLists.txt
@@ -0,0 +1,19 @@
+# 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.
+
+add_library(dm_example_cxx_api INTERFACE)
+target_include_directories(dm_example_cxx_api INTERFACE include)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/api/IName.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/api/IName.h b/examples/dm_example_cxx/api/IName.h
deleted file mode 100644
index 89edb19..0000000
--- a/examples/dm_example_cxx/api/IName.h
+++ /dev/null
@@ -1,39 +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.
- */
-
-#ifndef CELIX_INAME_H
-#define CELIX_INAME_H
-
-#define INAME_VERSION "1.0.0"
-
-#include <string>
-
-namespace srv {
- namespace info {
- class IName {
- protected:
- IName() = default;
- ~IName() = default;
- public:
- virtual std::string getName() = 0;
- };
- }
-}
-
-#endif //CELIX_INAME_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/api/IPhase1.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/api/IPhase1.h b/examples/dm_example_cxx/api/IPhase1.h
deleted file mode 100644
index d75b3e1..0000000
--- a/examples/dm_example_cxx/api/IPhase1.h
+++ /dev/null
@@ -1,33 +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.
- */
-
-#ifndef CELIX_PHASE1_H
-#define CELIX_PHASE1_H
-
-#define IPHASE1_VERSION "1.0.0"
-
-class IPhase1 {
-protected:
- IPhase1() = default;
- ~IPhase1() = default;
-public:
- virtual int getData() = 0;
-};
-
-#endif //CELIX_PHASE1_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/api/IPhase2.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/api/IPhase2.h b/examples/dm_example_cxx/api/IPhase2.h
deleted file mode 100644
index 20e3774..0000000
--- a/examples/dm_example_cxx/api/IPhase2.h
+++ /dev/null
@@ -1,33 +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.
- */
-
-#ifndef CELIX_PHASE2_H
-#define CELIX_PHASE2_H
-
-#define IPHASE2_VERSION "1.0.0"
-
-class IPhase2 {
-protected:
- IPhase2() = default;
- ~IPhase2() = default;
-public:
- virtual double getData() = 0;
-};
-
-#endif //CELIX_PHASE2_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/api/include/IName.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/api/include/IName.h b/examples/dm_example_cxx/api/include/IName.h
new file mode 100644
index 0000000..89edb19
--- /dev/null
+++ b/examples/dm_example_cxx/api/include/IName.h
@@ -0,0 +1,39 @@
+/**
+ * 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.
+ */
+
+#ifndef CELIX_INAME_H
+#define CELIX_INAME_H
+
+#define INAME_VERSION "1.0.0"
+
+#include <string>
+
+namespace srv {
+ namespace info {
+ class IName {
+ protected:
+ IName() = default;
+ ~IName() = default;
+ public:
+ virtual std::string getName() = 0;
+ };
+ }
+}
+
+#endif //CELIX_INAME_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/api/include/IPhase1.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/api/include/IPhase1.h b/examples/dm_example_cxx/api/include/IPhase1.h
new file mode 100644
index 0000000..d75b3e1
--- /dev/null
+++ b/examples/dm_example_cxx/api/include/IPhase1.h
@@ -0,0 +1,33 @@
+/**
+ * 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.
+ */
+
+#ifndef CELIX_PHASE1_H
+#define CELIX_PHASE1_H
+
+#define IPHASE1_VERSION "1.0.0"
+
+class IPhase1 {
+protected:
+ IPhase1() = default;
+ ~IPhase1() = default;
+public:
+ virtual int getData() = 0;
+};
+
+#endif //CELIX_PHASE1_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/api/include/IPhase2.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/api/include/IPhase2.h b/examples/dm_example_cxx/api/include/IPhase2.h
new file mode 100644
index 0000000..20e3774
--- /dev/null
+++ b/examples/dm_example_cxx/api/include/IPhase2.h
@@ -0,0 +1,33 @@
+/**
+ * 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.
+ */
+
+#ifndef CELIX_PHASE2_H
+#define CELIX_PHASE2_H
+
+#define IPHASE2_VERSION "1.0.0"
+
+class IPhase2 {
+protected:
+ IPhase2() = default;
+ ~IPhase2() = default;
+public:
+ virtual double getData() = 0;
+};
+
+#endif //CELIX_PHASE2_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase1/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase1/CMakeLists.txt b/examples/dm_example_cxx/phase1/CMakeLists.txt
index 62b1658..0832816 100644
--- a/examples/dm_example_cxx/phase1/CMakeLists.txt
+++ b/examples/dm_example_cxx/phase1/CMakeLists.txt
@@ -15,28 +15,23 @@
# specific language governing permissions and limitations
# under the License.
-include_directories(
- include
- ../api
-)
-
-add_bundle(phase1_cxx
+add_bundle(dm_example_cxx_phase1
SYMBOLIC_NAME phase1_cxx
VERSION 0.0.1
SOURCES
src/Phase1Activator.cc
src/Phase1Cmp.cc
)
-
-target_compile_options(phase1_cxx PUBLIC -Wall -Wextra -Weffc++ -Werror)
+target_include_directories(dm_example_cxx_phase1 PRIVATE src)
+target_link_libraries(dm_example_cxx_phase1 PRIVATE dm_example_cxx_api Celix::shell_api)
IF(APPLE)
- target_link_libraries(phase1_cxx PRIVATE -Wl,-all_load dependency_manager_cxx_static Celix::shell_api)
+ target_link_libraries(dm_example_cxx_phase1 PRIVATE -Wl,-all_load Celix::dependency_manager_cxx_static)
else()
if(ENABLE_ADDRESS_SANITIZER)
#With asan there can be undefined symbols
- target_link_libraries(phase1_cxx PRIVATE -Wl,--whole-archive dependency_manager_cxx_static -Wl,--no-whole-archive Celix::shell_api)
+ target_link_libraries(dm_example_cxx_phase1 PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
else()
- target_link_libraries(phase1_cxx PRIVATE -Wl,--no-undefined -Wl,--whole-archive dependency_manager_cxx_static -Wl,--no-whole-archive Celix::shell_api)
+ target_link_libraries(dm_example_cxx_phase1 PRIVATE -Wl,--no-undefined -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
endif()
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase1/include/Phase1Activator.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase1/include/Phase1Activator.h b/examples/dm_example_cxx/phase1/include/Phase1Activator.h
deleted file mode 100644
index 37b25e3..0000000
--- a/examples/dm_example_cxx/phase1/include/Phase1Activator.h
+++ /dev/null
@@ -1,36 +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.
- */
-
-#ifndef CELIX_PHASE1ACTIVATOR_H
-#define CELIX_PHASE1ACTIVATOR_H
-
-#include "celix/dm/DmActivator.h"
-#include "command.h"
-
-using namespace celix::dm;
-
-class Phase1Activator : public DmActivator {
- command_service_t cmd {nullptr, nullptr};
-public:
- Phase1Activator(DependencyManager& mng) : DmActivator(mng) {}
- virtual void init();
- virtual void deinit();
-};
-
-#endif //CELIX_PHASE1ACTIVATOR_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase1/include/Phase1Cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase1/include/Phase1Cmp.h b/examples/dm_example_cxx/phase1/include/Phase1Cmp.h
deleted file mode 100644
index f475c41..0000000
--- a/examples/dm_example_cxx/phase1/include/Phase1Cmp.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.
- */
-
-#ifndef CELIX_PHASE1CMP_H
-#define CELIX_PHASE1CMP_H
-
-#include "IPhase1.h"
-#include "IName.h"
-#include <stdint.h>
-#include <stdio.h>
-
-class Phase1Cmp : public srv::info::IName, public IPhase1 {
- uint32_t counter = 0;
-public:
- Phase1Cmp() = default;
- virtual ~Phase1Cmp() = default;
-
- void init();
- void start();
- void stop();
- void deinit();
-
- int getData() override; //implements IPhase1
- int infoCmd(char* line, FILE *out, FILE* err); //implements cmd service
- std::string getName() override;
-};
-
-#endif //CELIX_PHASE1CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase1/src/Phase1Activator.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase1/src/Phase1Activator.h b/examples/dm_example_cxx/phase1/src/Phase1Activator.h
new file mode 100644
index 0000000..37b25e3
--- /dev/null
+++ b/examples/dm_example_cxx/phase1/src/Phase1Activator.h
@@ -0,0 +1,36 @@
+/**
+ * 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.
+ */
+
+#ifndef CELIX_PHASE1ACTIVATOR_H
+#define CELIX_PHASE1ACTIVATOR_H
+
+#include "celix/dm/DmActivator.h"
+#include "command.h"
+
+using namespace celix::dm;
+
+class Phase1Activator : public DmActivator {
+ command_service_t cmd {nullptr, nullptr};
+public:
+ Phase1Activator(DependencyManager& mng) : DmActivator(mng) {}
+ virtual void init();
+ virtual void deinit();
+};
+
+#endif //CELIX_PHASE1ACTIVATOR_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase1/src/Phase1Cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase1/src/Phase1Cmp.h b/examples/dm_example_cxx/phase1/src/Phase1Cmp.h
new file mode 100644
index 0000000..f475c41
--- /dev/null
+++ b/examples/dm_example_cxx/phase1/src/Phase1Cmp.h
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+
+#ifndef CELIX_PHASE1CMP_H
+#define CELIX_PHASE1CMP_H
+
+#include "IPhase1.h"
+#include "IName.h"
+#include <stdint.h>
+#include <stdio.h>
+
+class Phase1Cmp : public srv::info::IName, public IPhase1 {
+ uint32_t counter = 0;
+public:
+ Phase1Cmp() = default;
+ virtual ~Phase1Cmp() = default;
+
+ void init();
+ void start();
+ void stop();
+ void deinit();
+
+ int getData() override; //implements IPhase1
+ int infoCmd(char* line, FILE *out, FILE* err); //implements cmd service
+ std::string getName() override;
+};
+
+#endif //CELIX_PHASE1CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase2/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2/CMakeLists.txt b/examples/dm_example_cxx/phase2/CMakeLists.txt
new file mode 100644
index 0000000..66f4ddd
--- /dev/null
+++ b/examples/dm_example_cxx/phase2/CMakeLists.txt
@@ -0,0 +1,51 @@
+# 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.
+
+add_bundle(dm_example_cxx_phase2a
+ SYMBOLIC_NAME phase2a_cxx
+ VERSION 0.0.1
+ SOURCES
+ src/Phase2aActivator.cc
+ src/Phase2aCmp.cc
+)
+target_include_directories(dm_example_cxx_phase2a PRIVATE src)
+target_link_libraries(dm_example_cxx_phase2a PRIVATE Celix::log_service_api dm_example_cxx_api)
+
+add_bundle(dm_example_cxx_phase2b
+ SYMBOLIC_NAME phase2b_cxx
+ VERSION 0.0.1
+ SOURCES
+ src/Phase2bActivator.cc
+ src/Phase2bCmp.cc
+ )
+target_include_directories(dm_example_cxx_phase2b PRIVATE src)
+target_link_libraries(dm_example_cxx_phase2b PRIVATE Celix::log_service_api dm_example_cxx_api)
+
+IF(APPLE)
+ target_link_libraries(dm_example_cxx_phase2a PRIVATE -Wl,-all_load Celix::dependency_manager_cxx_static)
+ target_link_libraries(dm_example_cxx_phase2b PRIVATE -Wl,-all_load Celix::dependency_manager_cxx_static)
+else()
+ if(ENABLE_ADDRESS_SANITIZER)
+ #With asan there can be undefined symbols
+ target_link_libraries(dm_example_cxx_phase2a PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
+ target_link_libraries(dm_example_cxx_phase2b PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
+ else()
+ target_link_libraries(dm_example_cxx_phase2a PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
+ target_link_libraries(dm_example_cxx_phase2b PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
+
+ endif()
+endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase2/include/Phase2Activator.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2/include/Phase2Activator.h b/examples/dm_example_cxx/phase2/include/Phase2Activator.h
deleted file mode 100644
index 069b2ae..0000000
--- a/examples/dm_example_cxx/phase2/include/Phase2Activator.h
+++ /dev/null
@@ -1,34 +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.
- */
-
-#ifndef CELIX_PHASE2AACTIVATOR_H
-#define CELIX_PHASE2AACTIVATOR_H
-
-#include "celix/dm/DmActivator.h"
-
-using namespace celix::dm;
-
-class Phase2Activator : public DmActivator {
-public:
- Phase2Activator(DependencyManager& mng) : DmActivator(mng) {}
- virtual void init();
- virtual void deinit();
-};
-
-#endif //CELIX_PHASE2AACTIVATOR_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase2/include/Phase2Cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2/include/Phase2Cmp.h b/examples/dm_example_cxx/phase2/include/Phase2Cmp.h
deleted file mode 100644
index 87b6e8e..0000000
--- a/examples/dm_example_cxx/phase2/include/Phase2Cmp.h
+++ /dev/null
@@ -1,56 +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.
- */
-
-#ifndef CELIX_PHASE2CMP_H
-#define CELIX_PHASE2CMP_H
-
-#include "IName.h"
-#include "IPhase1.h"
-#include "IPhase2.h"
-#include <stdint.h>
-#include <stdio.h>
-#include <thread>
-#include <iostream>
-
-extern "C" {
-#include "log_service.h"
-};
-
-class Phase2Cmp : public IPhase2 {
-public:
- Phase2Cmp() = default;
- virtual ~Phase2Cmp() { std::cout << "Destroying Phase2\n"; };
-
- Phase2Cmp(Phase2Cmp&& other) noexcept;
- Phase2Cmp& operator=(Phase2Cmp&&) = default;
-
- Phase2Cmp(const Phase2Cmp& other) = delete;
- Phase2Cmp operator=(const Phase2Cmp&) = delete;
-
- void setPhase1(IPhase1* phase); //injector used by dependency manager
- void setName(srv::info::IName* name) { std::cout << "Setting IName with name: " << (name != nullptr ? name->getName() : "null") << std::endl; }
- void setLogService(const log_service_t* logSrv);
-
- double getData() override; //implements IPhase2
-private:
- IPhase1* phase1 {nullptr};
- const log_service_t* logSrv {nullptr};
-};
-
-#endif //CELIX_PHASE2CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase2/src/Phase2Activator.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2/src/Phase2Activator.h b/examples/dm_example_cxx/phase2/src/Phase2Activator.h
new file mode 100644
index 0000000..069b2ae
--- /dev/null
+++ b/examples/dm_example_cxx/phase2/src/Phase2Activator.h
@@ -0,0 +1,34 @@
+/**
+ * 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.
+ */
+
+#ifndef CELIX_PHASE2AACTIVATOR_H
+#define CELIX_PHASE2AACTIVATOR_H
+
+#include "celix/dm/DmActivator.h"
+
+using namespace celix::dm;
+
+class Phase2Activator : public DmActivator {
+public:
+ Phase2Activator(DependencyManager& mng) : DmActivator(mng) {}
+ virtual void init();
+ virtual void deinit();
+};
+
+#endif //CELIX_PHASE2AACTIVATOR_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase2/src/Phase2Cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2/src/Phase2Cmp.h b/examples/dm_example_cxx/phase2/src/Phase2Cmp.h
new file mode 100644
index 0000000..87b6e8e
--- /dev/null
+++ b/examples/dm_example_cxx/phase2/src/Phase2Cmp.h
@@ -0,0 +1,56 @@
+/**
+ * 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.
+ */
+
+#ifndef CELIX_PHASE2CMP_H
+#define CELIX_PHASE2CMP_H
+
+#include "IName.h"
+#include "IPhase1.h"
+#include "IPhase2.h"
+#include <stdint.h>
+#include <stdio.h>
+#include <thread>
+#include <iostream>
+
+extern "C" {
+#include "log_service.h"
+};
+
+class Phase2Cmp : public IPhase2 {
+public:
+ Phase2Cmp() = default;
+ virtual ~Phase2Cmp() { std::cout << "Destroying Phase2\n"; };
+
+ Phase2Cmp(Phase2Cmp&& other) noexcept;
+ Phase2Cmp& operator=(Phase2Cmp&&) = default;
+
+ Phase2Cmp(const Phase2Cmp& other) = delete;
+ Phase2Cmp operator=(const Phase2Cmp&) = delete;
+
+ void setPhase1(IPhase1* phase); //injector used by dependency manager
+ void setName(srv::info::IName* name) { std::cout << "Setting IName with name: " << (name != nullptr ? name->getName() : "null") << std::endl; }
+ void setLogService(const log_service_t* logSrv);
+
+ double getData() override; //implements IPhase2
+private:
+ IPhase1* phase1 {nullptr};
+ const log_service_t* logSrv {nullptr};
+};
+
+#endif //CELIX_PHASE2CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase2/src/Phase2aActivator.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2/src/Phase2aActivator.cc b/examples/dm_example_cxx/phase2/src/Phase2aActivator.cc
new file mode 100644
index 0000000..e33ae0e
--- /dev/null
+++ b/examples/dm_example_cxx/phase2/src/Phase2aActivator.cc
@@ -0,0 +1,57 @@
+/**
+ * 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.
+ */
+
+#include <IName.h>
+#include "Phase2Cmp.h"
+#include "Phase2Activator.h"
+#include "log_service.h"
+
+using namespace celix::dm;
+
+
+DmActivator* DmActivator::create(DependencyManager& mng) {
+ return new Phase2Activator(mng);
+}
+
+
+void Phase2Activator::init() {
+
+ Properties props {};
+ props["name"] = "phase2a";
+
+ Component<Phase2Cmp>& cmp = mng.createComponent<Phase2Cmp>()
+ .setInstance(Phase2Cmp())
+ .addInterface<IPhase2>(IPHASE2_VERSION, props);
+
+ cmp.createServiceDependency<IPhase1>()
+ .setRequired(true)
+ .setCallbacks(&Phase2Cmp::setPhase1);
+
+ cmp.createServiceDependency<srv::info::IName>()
+ .setVersionRange("[1.0.0,2)")
+ .setCallbacks(&Phase2Cmp::setName);
+
+ cmp.createCServiceDependency<log_service_t>(OSGI_LOGSERVICE_NAME)
+ .setRequired(false)
+ .setCallbacks(&Phase2Cmp::setLogService);
+}
+
+void Phase2Activator::deinit() {
+
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase2/src/Phase2aCmp.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2/src/Phase2aCmp.cc b/examples/dm_example_cxx/phase2/src/Phase2aCmp.cc
new file mode 100644
index 0000000..4f68679
--- /dev/null
+++ b/examples/dm_example_cxx/phase2/src/Phase2aCmp.cc
@@ -0,0 +1,45 @@
+/**
+ * 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.
+ */
+
+#include "Phase2Cmp.h"
+#include <iostream>
+#include <stdlib.h>
+#include <stdio.h>
+
+Phase2Cmp::Phase2Cmp(Phase2Cmp&& other) noexcept : phase1(other.phase1), logSrv{other.logSrv} {
+ std::cout << "Move constructor Phase2aCmp called\n";
+ other.phase1 = nullptr;
+ other.logSrv = nullptr;
+}
+
+void Phase2Cmp::setPhase1(IPhase1* phase1) {
+ std::cout << "setting phase1 for phase2\n";
+ this->phase1 = phase1;
+}
+
+void Phase2Cmp::setLogService(const log_service_t* logSrv) {
+ this->logSrv = logSrv;
+}
+
+double Phase2Cmp::getData() {
+ if (this->logSrv != NULL) {
+ this->logSrv->log(this->logSrv->logger, OSGI_LOGSERVICE_DEBUG, (char *) "getting data from phase2cmp A\n");
+ }
+ return phase1->getData() * 42.0;
+};
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase2/src/Phase2bActivator.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2/src/Phase2bActivator.cc b/examples/dm_example_cxx/phase2/src/Phase2bActivator.cc
new file mode 100644
index 0000000..4fba8c0
--- /dev/null
+++ b/examples/dm_example_cxx/phase2/src/Phase2bActivator.cc
@@ -0,0 +1,50 @@
+/**
+ * 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.
+ */
+
+#include "Phase2Cmp.h"
+#include "Phase2Activator.h"
+#include "log_service.h"
+
+using namespace celix::dm;
+
+
+DmActivator* DmActivator::create(DependencyManager& mng) {
+ return new Phase2Activator(mng);
+}
+
+void Phase2Activator::init() {
+
+ Properties props {};
+ props["name"] = "phase2b";
+
+ Component<Phase2Cmp>& cmp = mng.createComponent<Phase2Cmp>()
+ .addInterface<IPhase2>(IPHASE2_VERSION, props);
+
+ cmp.createServiceDependency<IPhase1>()
+ .setRequired(true)
+ .setCallbacks(&Phase2Cmp::setPhase1);
+
+ cmp.createCServiceDependency<log_service_t>(OSGI_LOGSERVICE_NAME)
+ .setRequired(false)
+ .setCallbacks(&Phase2Cmp::setLogService);
+}
+
+void Phase2Activator::deinit() {
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase2/src/Phase2bCmp.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2/src/Phase2bCmp.cc b/examples/dm_example_cxx/phase2/src/Phase2bCmp.cc
new file mode 100644
index 0000000..2f420a0
--- /dev/null
+++ b/examples/dm_example_cxx/phase2/src/Phase2bCmp.cc
@@ -0,0 +1,45 @@
+/**
+ * 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.
+ */
+
+#include "Phase2Cmp.h"
+#include <iostream>
+#include <stdlib.h>
+#include <stdio.h>
+
+Phase2Cmp::Phase2Cmp(Phase2Cmp&& other) noexcept : phase1(other.phase1), logSrv{other.logSrv} {
+ std::cout << "Move constructor Phase2bCmp called\n";
+ other.phase1 = nullptr;
+ other.logSrv = nullptr;
+}
+
+void Phase2Cmp::setPhase1(IPhase1* phase1) {
+ std::cout << "setting phase1 for phase2\n";
+ this->phase1 = phase1;
+}
+
+void Phase2Cmp::setLogService(const log_service_t* logSrv) {
+ this->logSrv = logSrv;
+}
+
+double Phase2Cmp::getData() {
+ if (this->logSrv != NULL) {
+ this->logSrv->log(this->logSrv->logger, OSGI_LOGSERVICE_DEBUG, (char *) "getting data from phase2cmp B\n");
+ }
+ return phase1->getData() * 24.0;
+};
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase2a/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2a/CMakeLists.txt b/examples/dm_example_cxx/phase2a/CMakeLists.txt
deleted file mode 100644
index 4e2e673..0000000
--- a/examples/dm_example_cxx/phase2a/CMakeLists.txt
+++ /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.
-add_bundle(phase2a_cxx
- SYMBOLIC_NAME phase2a_cxx
- VERSION 0.0.1
- SOURCES
- src/Phase2aActivator.cc
- src/Phase2aCmp.cc
-)
-
-target_include_directories(phase2a_cxx PRIVATE
- ../phase2/include
- ../api
-)
-
-target_link_libraries(phase2a_cxx PRIVATE Celix::log_service_api)
-
-IF(APPLE)
- target_link_libraries(phase2a_cxx PRIVATE -Wl,-all_load Celix::dependency_manager_cxx_static)
-else()
- if(ENABLE_ADDRESS_SANITIZER)
- #With asan there can be undefined symbols
- target_link_libraries(phase2a_cxx PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
- else()
- target_link_libraries(phase2a_cxx PRIVATE -Wl,--no-undefined -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
- endif()
-endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase2a/src/Phase2aActivator.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2a/src/Phase2aActivator.cc b/examples/dm_example_cxx/phase2a/src/Phase2aActivator.cc
deleted file mode 100644
index e33ae0e..0000000
--- a/examples/dm_example_cxx/phase2a/src/Phase2aActivator.cc
+++ /dev/null
@@ -1,57 +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.
- */
-
-#include <IName.h>
-#include "Phase2Cmp.h"
-#include "Phase2Activator.h"
-#include "log_service.h"
-
-using namespace celix::dm;
-
-
-DmActivator* DmActivator::create(DependencyManager& mng) {
- return new Phase2Activator(mng);
-}
-
-
-void Phase2Activator::init() {
-
- Properties props {};
- props["name"] = "phase2a";
-
- Component<Phase2Cmp>& cmp = mng.createComponent<Phase2Cmp>()
- .setInstance(Phase2Cmp())
- .addInterface<IPhase2>(IPHASE2_VERSION, props);
-
- cmp.createServiceDependency<IPhase1>()
- .setRequired(true)
- .setCallbacks(&Phase2Cmp::setPhase1);
-
- cmp.createServiceDependency<srv::info::IName>()
- .setVersionRange("[1.0.0,2)")
- .setCallbacks(&Phase2Cmp::setName);
-
- cmp.createCServiceDependency<log_service_t>(OSGI_LOGSERVICE_NAME)
- .setRequired(false)
- .setCallbacks(&Phase2Cmp::setLogService);
-}
-
-void Phase2Activator::deinit() {
-
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase2a/src/Phase2aCmp.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2a/src/Phase2aCmp.cc b/examples/dm_example_cxx/phase2a/src/Phase2aCmp.cc
deleted file mode 100644
index 4f68679..0000000
--- a/examples/dm_example_cxx/phase2a/src/Phase2aCmp.cc
+++ /dev/null
@@ -1,45 +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.
- */
-
-#include "Phase2Cmp.h"
-#include <iostream>
-#include <stdlib.h>
-#include <stdio.h>
-
-Phase2Cmp::Phase2Cmp(Phase2Cmp&& other) noexcept : phase1(other.phase1), logSrv{other.logSrv} {
- std::cout << "Move constructor Phase2aCmp called\n";
- other.phase1 = nullptr;
- other.logSrv = nullptr;
-}
-
-void Phase2Cmp::setPhase1(IPhase1* phase1) {
- std::cout << "setting phase1 for phase2\n";
- this->phase1 = phase1;
-}
-
-void Phase2Cmp::setLogService(const log_service_t* logSrv) {
- this->logSrv = logSrv;
-}
-
-double Phase2Cmp::getData() {
- if (this->logSrv != NULL) {
- this->logSrv->log(this->logSrv->logger, OSGI_LOGSERVICE_DEBUG, (char *) "getting data from phase2cmp A\n");
- }
- return phase1->getData() * 42.0;
-};
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase2b/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2b/CMakeLists.txt b/examples/dm_example_cxx/phase2b/CMakeLists.txt
deleted file mode 100644
index cfbda7c..0000000
--- a/examples/dm_example_cxx/phase2b/CMakeLists.txt
+++ /dev/null
@@ -1,39 +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.
-
-add_bundle(phase2b_cxx
- SYMBOLIC_NAME phase2b_cxx
- VERSION 0.0.1
- SOURCES
- src/Phase2bActivator.cc
- src/Phase2bCmp.cc
-)
-target_link_libraries(phase2b_cxx PRIVATE Celix::log_service_api)
-target_include_directories(phase2b_cxx PRIVATE ../api ../phase2/include)
-
-
-
-IF(APPLE)
- target_link_libraries(phase2b_cxx PRIVATE -Wl,-all_load Celix::dependency_manager_cxx_static)
-else()
- if(ENABLE_ADDRESS_SANITIZER)
- #With asan there can be undefined symbols
- target_link_libraries(phase2b_cxx PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
- else()
- target_link_libraries(phase2b_cxx PRIVATE -Wl,--no-undefined -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
- endif()
-endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase2b/src/Phase2bActivator.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2b/src/Phase2bActivator.cc b/examples/dm_example_cxx/phase2b/src/Phase2bActivator.cc
deleted file mode 100644
index 4fba8c0..0000000
--- a/examples/dm_example_cxx/phase2b/src/Phase2bActivator.cc
+++ /dev/null
@@ -1,50 +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.
- */
-
-#include "Phase2Cmp.h"
-#include "Phase2Activator.h"
-#include "log_service.h"
-
-using namespace celix::dm;
-
-
-DmActivator* DmActivator::create(DependencyManager& mng) {
- return new Phase2Activator(mng);
-}
-
-void Phase2Activator::init() {
-
- Properties props {};
- props["name"] = "phase2b";
-
- Component<Phase2Cmp>& cmp = mng.createComponent<Phase2Cmp>()
- .addInterface<IPhase2>(IPHASE2_VERSION, props);
-
- cmp.createServiceDependency<IPhase1>()
- .setRequired(true)
- .setCallbacks(&Phase2Cmp::setPhase1);
-
- cmp.createCServiceDependency<log_service_t>(OSGI_LOGSERVICE_NAME)
- .setRequired(false)
- .setCallbacks(&Phase2Cmp::setLogService);
-}
-
-void Phase2Activator::deinit() {
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase2b/src/Phase2bCmp.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2b/src/Phase2bCmp.cc b/examples/dm_example_cxx/phase2b/src/Phase2bCmp.cc
deleted file mode 100644
index 2f420a0..0000000
--- a/examples/dm_example_cxx/phase2b/src/Phase2bCmp.cc
+++ /dev/null
@@ -1,45 +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.
- */
-
-#include "Phase2Cmp.h"
-#include <iostream>
-#include <stdlib.h>
-#include <stdio.h>
-
-Phase2Cmp::Phase2Cmp(Phase2Cmp&& other) noexcept : phase1(other.phase1), logSrv{other.logSrv} {
- std::cout << "Move constructor Phase2bCmp called\n";
- other.phase1 = nullptr;
- other.logSrv = nullptr;
-}
-
-void Phase2Cmp::setPhase1(IPhase1* phase1) {
- std::cout << "setting phase1 for phase2\n";
- this->phase1 = phase1;
-}
-
-void Phase2Cmp::setLogService(const log_service_t* logSrv) {
- this->logSrv = logSrv;
-}
-
-double Phase2Cmp::getData() {
- if (this->logSrv != NULL) {
- this->logSrv->log(this->logSrv->logger, OSGI_LOGSERVICE_DEBUG, (char *) "getting data from phase2cmp B\n");
- }
- return phase1->getData() * 24.0;
-};
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase3/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3/CMakeLists.txt b/examples/dm_example_cxx/phase3/CMakeLists.txt
index a0f6973..2a62cbb 100644
--- a/examples/dm_example_cxx/phase3/CMakeLists.txt
+++ b/examples/dm_example_cxx/phase3/CMakeLists.txt
@@ -15,12 +15,7 @@
# specific language governing permissions and limitations
# under the License.
-include_directories(
- include
- ../api
-)
-
-add_bundle(phase3_cxx
+add_bundle(dm_example_cxx_phase3
SYMBOLIC_NAME phase3_cxx
VERSION 0.0.1
SOURCES
@@ -28,16 +23,16 @@ add_bundle(phase3_cxx
src/Phase3BaseActivator.cc
src/Phase3Cmp.cc
)
-
-target_compile_options(phase3_cxx PUBLIC -Wall -Wextra -Weffc++ -Werror)
+target_include_directories(dm_example_cxx_phase3 PRIVATE src)
+target_link_libraries(dm_example_cxx_phase3 PRIVATE dm_example_cxx_api)
IF(APPLE)
- target_link_libraries(phase3_cxx PRIVATE -Wl,-all_load dependency_manager_cxx_static)
+ target_link_libraries(dm_example_cxx_phase3 PRIVATE -Wl,-all_load Celix::dependency_manager_cxx_static)
else()
if(ENABLE_ADDRESS_SANITIZER)
#With asan there can be undefined symbols
- target_link_libraries(phase3_cxx PRIVATE -Wl,--whole-archive dependency_manager_cxx_static -Wl,--no-whole-archive)
+ target_link_libraries(dm_example_cxx_phase3 PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
else()
- target_link_libraries(phase3_cxx PRIVATE -Wl,--no-undefined -Wl,--whole-archive dependency_manager_cxx_static -Wl,--no-whole-archive)
+ target_link_libraries(dm_example_cxx_phase3 PRIVATE -Wl,--no-undefined -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
endif()
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase3/include/Phase3Activator.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3/include/Phase3Activator.h b/examples/dm_example_cxx/phase3/include/Phase3Activator.h
deleted file mode 100644
index e02cd61..0000000
--- a/examples/dm_example_cxx/phase3/include/Phase3Activator.h
+++ /dev/null
@@ -1,33 +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.
- */
-
-#ifndef CELIX_PHASE3ACTIVATOR_H
-#define CELIX_PHASE3ACTIVATOR_H
-
-#include "Phase3BaseActivator.h"
-
-using namespace celix::dm;
-
-class Phase3Activator : public Phase3BaseActivator {
-public:
- Phase3Activator(DependencyManager& mng) : Phase3BaseActivator(mng) {}
- virtual void init();
-};
-
-#endif //CELIX_PHASE2AACTIVATOR_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase3/include/Phase3BaseActivator.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3/include/Phase3BaseActivator.h b/examples/dm_example_cxx/phase3/include/Phase3BaseActivator.h
deleted file mode 100644
index 0f3d813..0000000
--- a/examples/dm_example_cxx/phase3/include/Phase3BaseActivator.h
+++ /dev/null
@@ -1,35 +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.
- */
-
-#ifndef CELIX_PHASE3BASEACTIVATOR_H
-#define CELIX_PHASE3BASEACTIVATOR_H
-
-#include "celix/dm/DmActivator.h"
-
-using namespace celix::dm;
-
-class Phase3BaseActivator : public DmActivator {
-public:
- Phase3BaseActivator(DependencyManager& mng) : DmActivator(mng), cmp(mng.createComponent<Phase3Cmp>()) {}
- void init();
-protected:
- celix::dm::Component<Phase3Cmp>& cmp;
-};
-
-#endif //CELIX_PHASE3BASEACTIVATOR_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase3/include/Phase3Cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3/include/Phase3Cmp.h b/examples/dm_example_cxx/phase3/include/Phase3Cmp.h
deleted file mode 100644
index 8b7e974..0000000
--- a/examples/dm_example_cxx/phase3/include/Phase3Cmp.h
+++ /dev/null
@@ -1,50 +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.
- */
-
-#ifndef CELIX_PHASE3CMP_H
-#define CELIX_PHASE3CMP_H
-
-#include "IPhase1.h"
-#include "IPhase2.h"
-#include <stdint.h>
-#include <stdio.h>
-#include <thread>
-#include <iostream>
-#include <list>
-#include "celix/dm/Properties.h"
-
-class Phase3Cmp {
- std::map<IPhase2*,celix::dm::Properties> phases {};
- bool running {false};
- std::thread pollThread {};
-public:
- Phase3Cmp() { std::cout << "Constructing Phase3Cmp\n"; }
- virtual ~Phase3Cmp() = default;
-
- void start();
- void stop();
-
- void poll();
-
- void addPhase2(IPhase2* phase, celix::dm::Properties&& props); //injector used by dependency manager
- void removePhase2(IPhase2* phase, celix::dm::Properties&& props); //injector used by dependency manager
- void setPhase2a(IPhase2* phase);
-};
-
-#endif //CELIX_PHASE3CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase3/src/Phase3Activator.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3/src/Phase3Activator.h b/examples/dm_example_cxx/phase3/src/Phase3Activator.h
new file mode 100644
index 0000000..e02cd61
--- /dev/null
+++ b/examples/dm_example_cxx/phase3/src/Phase3Activator.h
@@ -0,0 +1,33 @@
+/**
+ * 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.
+ */
+
+#ifndef CELIX_PHASE3ACTIVATOR_H
+#define CELIX_PHASE3ACTIVATOR_H
+
+#include "Phase3BaseActivator.h"
+
+using namespace celix::dm;
+
+class Phase3Activator : public Phase3BaseActivator {
+public:
+ Phase3Activator(DependencyManager& mng) : Phase3BaseActivator(mng) {}
+ virtual void init();
+};
+
+#endif //CELIX_PHASE2AACTIVATOR_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase3/src/Phase3BaseActivator.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3/src/Phase3BaseActivator.h b/examples/dm_example_cxx/phase3/src/Phase3BaseActivator.h
new file mode 100644
index 0000000..0f3d813
--- /dev/null
+++ b/examples/dm_example_cxx/phase3/src/Phase3BaseActivator.h
@@ -0,0 +1,35 @@
+/**
+ * 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.
+ */
+
+#ifndef CELIX_PHASE3BASEACTIVATOR_H
+#define CELIX_PHASE3BASEACTIVATOR_H
+
+#include "celix/dm/DmActivator.h"
+
+using namespace celix::dm;
+
+class Phase3BaseActivator : public DmActivator {
+public:
+ Phase3BaseActivator(DependencyManager& mng) : DmActivator(mng), cmp(mng.createComponent<Phase3Cmp>()) {}
+ void init();
+protected:
+ celix::dm::Component<Phase3Cmp>& cmp;
+};
+
+#endif //CELIX_PHASE3BASEACTIVATOR_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase3/src/Phase3Cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3/src/Phase3Cmp.h b/examples/dm_example_cxx/phase3/src/Phase3Cmp.h
new file mode 100644
index 0000000..8b7e974
--- /dev/null
+++ b/examples/dm_example_cxx/phase3/src/Phase3Cmp.h
@@ -0,0 +1,50 @@
+/**
+ * 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.
+ */
+
+#ifndef CELIX_PHASE3CMP_H
+#define CELIX_PHASE3CMP_H
+
+#include "IPhase1.h"
+#include "IPhase2.h"
+#include <stdint.h>
+#include <stdio.h>
+#include <thread>
+#include <iostream>
+#include <list>
+#include "celix/dm/Properties.h"
+
+class Phase3Cmp {
+ std::map<IPhase2*,celix::dm::Properties> phases {};
+ bool running {false};
+ std::thread pollThread {};
+public:
+ Phase3Cmp() { std::cout << "Constructing Phase3Cmp\n"; }
+ virtual ~Phase3Cmp() = default;
+
+ void start();
+ void stop();
+
+ void poll();
+
+ void addPhase2(IPhase2* phase, celix::dm::Properties&& props); //injector used by dependency manager
+ void removePhase2(IPhase2* phase, celix::dm::Properties&& props); //injector used by dependency manager
+ void setPhase2a(IPhase2* phase);
+};
+
+#endif //CELIX_PHASE3CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase3_locking/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3_locking/CMakeLists.txt b/examples/dm_example_cxx/phase3_locking/CMakeLists.txt
index 956f6e1..2ea1eb4 100644
--- a/examples/dm_example_cxx/phase3_locking/CMakeLists.txt
+++ b/examples/dm_example_cxx/phase3_locking/CMakeLists.txt
@@ -15,28 +15,24 @@
# specific language governing permissions and limitations
# under the License.
-include_directories(
- include
- ../api
-)
-add_bundle(phase3_locking_cxx
+add_bundle(dm_example_cxx_phase3_locking
SYMBOLIC_NAME phase3_locking_cxx
VERSION 0.0.1
SOURCES
src/Phase3LockingActivator.cc
src/Phase3LockingCmp.cc
)
-
-target_compile_options(phase3_locking_cxx PUBLIC -Wall -Wextra -Weffc++ -Werror)
+target_include_directories(dm_example_cxx_phase3_locking PRIVATE src)
+target_link_libraries(dm_example_cxx_phase3_locking PRIVATE dm_example_cxx_api)
IF(APPLE)
- target_link_libraries(phase3_locking_cxx PRIVATE -Wl,-all_load dependency_manager_cxx_static)
+ target_link_libraries(dm_example_cxx_phase3_locking PRIVATE -Wl,-all_load Celix::dependency_manager_cxx_static)
else()
if(ENABLE_ADDRESS_SANITIZER)
#With asan there can be undefined symbols
- target_link_libraries(phase3_locking_cxx PRIVATE -Wl,--whole-archive dependency_manager_cxx_static -Wl,--no-whole-archive)
+ target_link_libraries(dm_example_cxx_phase3_locking PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
else()
- target_link_libraries(phase3_locking_cxx PRIVATE -Wl,--no-undefined -Wl,--whole-archive dependency_manager_cxx_static -Wl,--no-whole-archive)
+ target_link_libraries(dm_example_cxx_phase3_locking PRIVATE -Wl,--no-undefined -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive)
endif()
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase3_locking/include/Phase3LockingActivator.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3_locking/include/Phase3LockingActivator.h b/examples/dm_example_cxx/phase3_locking/include/Phase3LockingActivator.h
deleted file mode 100644
index 78d1748..0000000
--- a/examples/dm_example_cxx/phase3_locking/include/Phase3LockingActivator.h
+++ /dev/null
@@ -1,33 +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.
- */
-
-#ifndef CELIX_PHASE3LOCKINGACTIVATOR_H
-#define CELIX_PHASE3LOCKINGACTIVATOR_H
-
-#include "celix/dm/DmActivator.h"
-
-using namespace celix::dm;
-
-class Phase3LockingActivator : public DmActivator {
-public:
- Phase3LockingActivator(DependencyManager& mng) : DmActivator(mng) {}
- virtual void init();
-};
-
-#endif //CELIX_PHASE3LOCKINGAACTIVATOR_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase3_locking/include/Phase3LockingCmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3_locking/include/Phase3LockingCmp.h b/examples/dm_example_cxx/phase3_locking/include/Phase3LockingCmp.h
deleted file mode 100644
index 678fa80..0000000
--- a/examples/dm_example_cxx/phase3_locking/include/Phase3LockingCmp.h
+++ /dev/null
@@ -1,50 +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.
- */
-
-#ifndef CELIX_PHASE3LOCKINGCMP_H
-#define CELIX_PHASE3LOCKINGCMP_H
-
-#include "IPhase2.h"
-#include <stdint.h>
-#include <stdio.h>
-#include <thread>
-#include <iostream>
-#include <mutex>
-#include <map>
-#include "celix/dm/Properties.h"
-
-class Phase3LockingCmp {
- std::map<IPhase2*,celix::dm::Properties> phases {};
- bool running {false};
- std::thread pollThread {};
- std::mutex mutex {};
-public:
- Phase3LockingCmp() = default;
- virtual ~Phase3LockingCmp() = default;
-
- void start();
- void stop();
-
- void poll();
-
- void addPhase2(IPhase2* phase, celix::dm::Properties&& props); //injector used by dependency manager
- void removePhase2(IPhase2* phase, celix::dm::Properties&& props); //injector used by dependency manager
-};
-
-#endif //CELIX_PHASE3LOCKINGCMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.h b/examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.h
new file mode 100644
index 0000000..78d1748
--- /dev/null
+++ b/examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.h
@@ -0,0 +1,33 @@
+/**
+ * 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.
+ */
+
+#ifndef CELIX_PHASE3LOCKINGACTIVATOR_H
+#define CELIX_PHASE3LOCKINGACTIVATOR_H
+
+#include "celix/dm/DmActivator.h"
+
+using namespace celix::dm;
+
+class Phase3LockingActivator : public DmActivator {
+public:
+ Phase3LockingActivator(DependencyManager& mng) : DmActivator(mng) {}
+ virtual void init();
+};
+
+#endif //CELIX_PHASE3LOCKINGAACTIVATOR_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example_cxx/phase3_locking/src/Phase3LockingCmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3_locking/src/Phase3LockingCmp.h b/examples/dm_example_cxx/phase3_locking/src/Phase3LockingCmp.h
new file mode 100644
index 0000000..678fa80
--- /dev/null
+++ b/examples/dm_example_cxx/phase3_locking/src/Phase3LockingCmp.h
@@ -0,0 +1,50 @@
+/**
+ * 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.
+ */
+
+#ifndef CELIX_PHASE3LOCKINGCMP_H
+#define CELIX_PHASE3LOCKINGCMP_H
+
+#include "IPhase2.h"
+#include <stdint.h>
+#include <stdio.h>
+#include <thread>
+#include <iostream>
+#include <mutex>
+#include <map>
+#include "celix/dm/Properties.h"
+
+class Phase3LockingCmp {
+ std::map<IPhase2*,celix::dm::Properties> phases {};
+ bool running {false};
+ std::thread pollThread {};
+ std::mutex mutex {};
+public:
+ Phase3LockingCmp() = default;
+ virtual ~Phase3LockingCmp() = default;
+
+ void start();
+ void stop();
+
+ void poll();
+
+ void addPhase2(IPhase2* phase, celix::dm::Properties&& props); //injector used by dependency manager
+ void removePhase2(IPhase2* phase, celix::dm::Properties&& props); //injector used by dependency manager
+};
+
+#endif //CELIX_PHASE3LOCKINGCMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/embedding/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/embedding/CMakeLists.txt b/examples/embedding/CMakeLists.txt
index e39433a..9c96948 100644
--- a/examples/embedding/CMakeLists.txt
+++ b/examples/embedding/CMakeLists.txt
@@ -17,5 +17,4 @@
add_executable(embedding private/src/main)
-include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
target_link_libraries(embedding Celix::framework )
\ No newline at end of file
[03/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/topology_manager/src/topology_manager.c
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/src/topology_manager.c b/remote_services/topology_manager/src/topology_manager.c
new file mode 100644
index 0000000..6472b01
--- /dev/null
+++ b/remote_services/topology_manager/src/topology_manager.c
@@ -0,0 +1,985 @@
+/**
+ *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.
+ */
+/*
+ * topology_manager.c
+ *
+ * \date Sep 29, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "celixbool.h"
+#include "topology_manager.h"
+#include "bundle_context.h"
+#include "constants.h"
+#include "bundle.h"
+#include "remote_service_admin.h"
+#include "remote_constants.h"
+#include "filter.h"
+#include "listener_hook_service.h"
+#include "utils.h"
+#include "service_reference.h"
+#include "service_registration.h"
+#include "log_service.h"
+#include "log_helper.h"
+#include "topology_manager.h"
+#include "scope.h"
+#include "hash_map.h"
+
+struct topology_manager {
+ bundle_context_pt context;
+
+ celix_thread_mutex_t rsaListLock;
+ celix_thread_mutexattr_t rsaListLockAttr;
+ array_list_pt rsaList;
+
+ celix_thread_mutex_t listenerListLock;
+ hash_map_pt listenerList;
+
+ celix_thread_mutex_t exportedServicesLock;
+ hash_map_pt exportedServices;
+
+ celix_thread_mutex_t importedServicesLock;
+ celix_thread_mutexattr_t importedServicesLockAttr;
+ hash_map_pt importedServices;
+
+ scope_pt scope;
+
+ log_helper_pt loghelper;
+};
+
+celix_status_t topologyManager_exportScopeChanged(void *handle, char *service_name);
+celix_status_t topologyManager_importScopeChanged(void *handle, char *service_name);
+celix_status_t topologyManager_notifyListenersEndpointAdded(topology_manager_pt manager, remote_service_admin_service_pt rsa, array_list_pt registrations);
+celix_status_t topologyManager_notifyListenersEndpointRemoved(topology_manager_pt manager, remote_service_admin_service_pt rsa, export_registration_pt export);
+
+celix_status_t topologyManager_create(bundle_context_pt context, log_helper_pt logHelper, topology_manager_pt *manager, void **scope) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *manager = calloc(1, sizeof(**manager));
+
+ if (!*manager) {
+ return CELIX_ENOMEM;
+ }
+
+ (*manager)->context = context;
+ (*manager)->rsaList = NULL;
+
+ arrayList_create(&(*manager)->rsaList);
+
+
+ celixThreadMutexAttr_create(&(*manager)->rsaListLockAttr);
+ celixThreadMutexAttr_settype(&(*manager)->rsaListLockAttr, CELIX_THREAD_MUTEX_RECURSIVE);
+ celixThreadMutex_create(&(*manager)->rsaListLock, &(*manager)->rsaListLockAttr);
+
+ celixThreadMutexAttr_create(&(*manager)->importedServicesLockAttr);
+ celixThreadMutexAttr_settype(&(*manager)->importedServicesLockAttr, CELIX_THREAD_MUTEX_RECURSIVE);
+ celixThreadMutex_create(&(*manager)->importedServicesLock, &(*manager)->importedServicesLockAttr);
+
+ celixThreadMutex_create(&(*manager)->exportedServicesLock, NULL);
+ celixThreadMutex_create(&(*manager)->listenerListLock, NULL);
+
+ (*manager)->listenerList = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
+ (*manager)->exportedServices = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
+ (*manager)->importedServices = hashMap_create(NULL, NULL, NULL, NULL);
+
+ status = scope_scopeCreate(*manager, &(*manager)->scope);
+ scope_setExportScopeChangedCallback((*manager)->scope, topologyManager_exportScopeChanged);
+ scope_setImportScopeChangedCallback((*manager)->scope, topologyManager_importScopeChanged);
+ *scope = (*manager)->scope;
+
+ (*manager)->loghelper = logHelper;
+
+
+ return status;
+}
+
+celix_status_t topologyManager_destroy(topology_manager_pt manager) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&manager->listenerListLock);
+ hashMap_destroy(manager->listenerList, false, false);
+
+ celixThreadMutex_unlock(&manager->listenerListLock);
+ celixThreadMutex_destroy(&manager->listenerListLock);
+
+ celixThreadMutex_lock(&manager->rsaListLock);
+
+ arrayList_destroy(manager->rsaList);
+
+ celixThreadMutex_unlock(&manager->rsaListLock);
+ celixThreadMutex_destroy(&manager->rsaListLock);
+ celixThreadMutexAttr_destroy(&manager->rsaListLockAttr);
+
+ celixThreadMutex_lock(&manager->exportedServicesLock);
+
+ hashMap_destroy(manager->exportedServices, false, false);
+
+ celixThreadMutex_unlock(&manager->exportedServicesLock);
+ celixThreadMutex_destroy(&manager->exportedServicesLock);
+
+ celixThreadMutex_lock(&manager->importedServicesLock);
+
+ hashMap_destroy(manager->importedServices, false, false);
+
+ celixThreadMutex_unlock(&manager->importedServicesLock);
+ celixThreadMutex_destroy(&manager->importedServicesLock);
+ celixThreadMutexAttr_destroy(&manager->importedServicesLockAttr);
+
+ scope_scopeDestroy(manager->scope);
+ free(manager);
+
+ return status;
+}
+
+celix_status_t topologyManager_closeImports(topology_manager_pt manager) {
+ celix_status_t status;
+
+ status = celixThreadMutex_lock(&manager->importedServicesLock);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(manager->importedServices);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ endpoint_description_pt ep = hashMapEntry_getKey(entry);
+ hash_map_pt imports = hashMapEntry_getValue(entry);
+
+ if (imports != NULL) {
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Remove imported service (%s; %s).", ep->service, ep->id);
+ hash_map_iterator_pt importsIter = hashMapIterator_create(imports);
+
+ while (hashMapIterator_hasNext(importsIter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(importsIter);
+
+ remote_service_admin_service_pt rsa = hashMapEntry_getKey(entry);
+ import_registration_pt import = hashMapEntry_getValue(entry);
+
+ status = rsa->importRegistration_close(rsa->admin, import);
+ if (status == CELIX_SUCCESS) {
+ hashMapIterator_remove(importsIter);
+ }
+ }
+ hashMapIterator_destroy(importsIter);
+
+ hashMapIterator_remove(iter);
+
+ hashMap_destroy(imports, false, false);
+ }
+ }
+ hashMapIterator_destroy(iter);
+
+ status = celixThreadMutex_unlock(&manager->importedServicesLock);
+
+ return status;
+}
+
+celix_status_t topologyManager_rsaAdding(void * handle, service_reference_pt reference, void **service) {
+ celix_status_t status;
+ topology_manager_pt manager = (topology_manager_pt) handle;
+
+ status = bundleContext_getService(manager->context, reference, service);
+
+ return status;
+}
+
+celix_status_t topologyManager_rsaAdded(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status;
+ topology_manager_pt manager = (topology_manager_pt) handle;
+ properties_pt serviceProperties = NULL;
+ remote_service_admin_service_pt rsa = (remote_service_admin_service_pt) service;
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Added RSA");
+
+ status = celixThreadMutex_lock(&manager->rsaListLock);
+
+ if (status == CELIX_SUCCESS) {
+ arrayList_add(manager->rsaList, rsa);
+ status = celixThreadMutex_unlock(&manager->rsaListLock);
+ }
+
+ // add already imported services to new rsa
+ if (status == CELIX_SUCCESS) {
+ status = celixThreadMutex_lock(&manager->importedServicesLock);
+
+ if (status == CELIX_SUCCESS) {
+ hash_map_iterator_pt importedServicesIterator = hashMapIterator_create(manager->importedServices);
+
+ while (hashMapIterator_hasNext(importedServicesIterator)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(importedServicesIterator);
+ endpoint_description_pt endpoint = hashMapEntry_getKey(entry);
+ if (scope_allowImport(manager->scope, endpoint)) {
+ import_registration_pt import = NULL;
+ status = rsa->importService(rsa->admin, endpoint, &import);
+
+ if (status == CELIX_SUCCESS) {
+ hash_map_pt imports = hashMapEntry_getValue(entry);
+
+ if (imports == NULL) {
+ imports = hashMap_create(NULL, NULL, NULL, NULL);
+ hashMap_put(manager->importedServices,endpoint,imports);
+ }
+
+ hashMap_put(imports, service, import);
+ }
+ }
+ }
+
+ hashMapIterator_destroy(importedServicesIterator);
+
+ celixThreadMutex_unlock(&manager->importedServicesLock);
+ }
+ }
+
+ // add already exported services to new rsa
+ if (status == CELIX_SUCCESS) {
+ status = celixThreadMutex_lock(&manager->exportedServicesLock);
+
+ if (status == CELIX_SUCCESS) {
+ hash_map_iterator_pt exportedServicesIterator = hashMapIterator_create(manager->exportedServices);
+
+ while (hashMapIterator_hasNext(exportedServicesIterator)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(exportedServicesIterator);
+ service_reference_pt reference = hashMapEntry_getKey(entry);
+ const char* serviceId = NULL;
+
+ serviceReference_getProperty(reference, OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
+
+ scope_getExportProperties(manager->scope, reference, &serviceProperties);
+
+ array_list_pt endpoints = NULL;
+ status = rsa->exportService(rsa->admin, (char*)serviceId, serviceProperties, &endpoints);
+
+ if (status == CELIX_SUCCESS) {
+ hash_map_pt exports = hashMapEntry_getValue(entry);
+
+ if (exports == NULL) {
+ exports = hashMap_create(NULL, NULL, NULL, NULL);
+ hashMap_put(manager->exportedServices,reference,exports);
+ }
+
+ hashMap_put(exports, rsa, endpoints);
+ status = topologyManager_notifyListenersEndpointAdded(manager, rsa, endpoints);
+ }
+ }
+
+ hashMapIterator_destroy(exportedServicesIterator);
+
+ celixThreadMutex_unlock(&manager->exportedServicesLock);
+ }
+ }
+ return status;
+}
+
+celix_status_t topologyManager_rsaModified(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ // Nop...
+
+ return status;
+}
+
+celix_status_t topologyManager_rsaRemoved(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+ topology_manager_pt manager = (topology_manager_pt) handle;
+ remote_service_admin_service_pt rsa = (remote_service_admin_service_pt) service;
+
+ if (celixThreadMutex_lock(&manager->exportedServicesLock) == CELIX_SUCCESS) {
+ hash_map_iterator_pt iter = hashMapIterator_create(manager->exportedServices);
+
+ while (hashMapIterator_hasNext(iter)) {
+
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ service_reference_pt key = hashMapEntry_getKey(entry);
+ hash_map_pt exports = hashMapEntry_getValue(entry);
+
+ /*
+ * the problem here is that also the rsa has a a list of
+ * endpoints which is destroyed when closing the exportRegistration
+ */
+ array_list_pt exports_list = hashMap_get(exports, rsa);
+
+ if (exports_list != NULL) {
+ int exportsIter = 0;
+ int exportListSize = arrayList_size(exports_list);
+ for (exportsIter = 0; exports_list != NULL && exportsIter < exportListSize; exportsIter++) {
+ export_registration_pt export = arrayList_get(exports_list, exportsIter);
+ topologyManager_notifyListenersEndpointRemoved(manager, rsa, export);
+ rsa->exportRegistration_close(rsa->admin, export);
+ }
+ }
+
+ hashMap_remove(exports, rsa);
+ /*if(exports_list!=NULL){
+ arrayList_destroy(exports_list);
+ }*/
+
+ if (hashMap_size(exports) == 0) {
+ hashMap_remove(manager->exportedServices, key);
+ hashMap_destroy(exports, false, false);
+
+ hashMapIterator_destroy(iter);
+ iter = hashMapIterator_create(manager->exportedServices);
+ }
+ }
+ hashMapIterator_destroy(iter);
+ celixThreadMutex_unlock(&manager->exportedServicesLock);
+ }
+
+ if (celixThreadMutex_lock(&manager->importedServicesLock) == CELIX_SUCCESS) {
+ hash_map_iterator_pt iter = hashMapIterator_create(manager->importedServices);
+
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ hash_map_pt imports = hashMapEntry_getValue(entry);
+
+ import_registration_pt import = hashMap_get(imports, rsa);
+
+ if (import != NULL) {
+ celix_status_t subStatus = rsa->importRegistration_close(rsa->admin, import);
+
+ if (subStatus == CELIX_SUCCESS) {
+ hashMap_remove(imports, rsa);
+ } else {
+ status = subStatus;
+ }
+ }
+ }
+ hashMapIterator_destroy(iter);
+ celixThreadMutex_unlock(&manager->importedServicesLock);
+ }
+
+ if (celixThreadMutex_lock(&manager->rsaListLock) == CELIX_SUCCESS) {
+ arrayList_removeElement(manager->rsaList, rsa);
+ celixThreadMutex_unlock(&manager->rsaListLock);
+ }
+
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Removed RSA");
+
+ return status;
+}
+
+
+celix_status_t topologyManager_serviceChanged(void *listener, service_event_pt event) {
+ celix_status_t status = CELIX_SUCCESS;
+ service_listener_pt listen = listener;
+ topology_manager_pt manager = listen->handle;
+
+ const char* export = NULL;
+ const char* serviceId = NULL;
+ serviceReference_getProperty(event->reference, OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &export);
+ serviceReference_getProperty(event->reference, OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
+
+ if (!export) {
+ // Nothing needs to be done: we're not interested...
+ return status;
+ }
+
+ switch (event->type) {
+ case OSGI_FRAMEWORK_SERVICE_EVENT_REGISTERED:
+ status = topologyManager_addExportedService(manager, event->reference, (char*)serviceId);
+ break;
+ case OSGI_FRAMEWORK_SERVICE_EVENT_MODIFIED:
+ status = topologyManager_removeExportedService(manager, event->reference, (char*)serviceId);
+
+ if (status == CELIX_SUCCESS) {
+ status = topologyManager_addExportedService(manager, event->reference, (char*)serviceId);
+ }
+ break;
+ case OSGI_FRAMEWORK_SERVICE_EVENT_UNREGISTERING:
+ status = topologyManager_removeExportedService(manager, event->reference, (char*)serviceId);
+ break;
+ case OSGI_FRAMEWORK_SERVICE_EVENT_MODIFIED_ENDMATCH:
+ break;
+ }
+
+ return status;
+}
+
+celix_status_t topologyManager_exportScopeChanged(void *handle, char *filterStr) {
+ celix_status_t status = CELIX_SUCCESS;
+ topology_manager_pt manager = (topology_manager_pt) handle;
+ service_registration_pt reg = NULL;
+ const char* serviceId = NULL;
+ bool found;
+ properties_pt props;
+ filter_pt filter = filter_create(filterStr);
+
+ if (filter == NULL) {
+ printf("filter creating failed\n");
+ return CELIX_ENOMEM;
+ }
+
+ // add already exported services to new rsa
+ if (celixThreadMutex_lock(&manager->exportedServicesLock) == CELIX_SUCCESS) {
+ hash_map_iterator_pt exportedServicesIterator = hashMapIterator_create(manager->exportedServices);
+ int size = hashMap_size(manager->exportedServices);
+ service_reference_pt *srvRefs = (service_reference_pt *) calloc(size, sizeof(service_reference_pt));
+ char **srvIds = (char **) calloc(size, sizeof(char*));
+ int nrFound = 0;
+
+ found = false;
+
+ while (hashMapIterator_hasNext(exportedServicesIterator)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(exportedServicesIterator);
+ service_reference_pt reference = hashMapEntry_getKey(entry);
+ reg = NULL;
+ serviceReference_getServiceRegistration(reference, ®);
+ if (reg != NULL) {
+ props = NULL;
+ serviceRegistration_getProperties(reg, &props);
+ status = filter_match(filter, props, &found);
+ if (found) {
+ srvRefs[nrFound] = reference;
+ serviceReference_getProperty(reference, OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
+ srvIds[nrFound++] = (char*)serviceId;
+ }
+ }
+ }
+
+ hashMapIterator_destroy(exportedServicesIterator);
+ celixThreadMutex_unlock(&manager->exportedServicesLock);
+
+ if (nrFound > 0) {
+ for (int i = 0; i < nrFound; i++) {
+ // Question: can srvRefs become invalid meanwhile??
+ const char* export = NULL;
+ serviceReference_getProperty(srvRefs[i], (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &export);
+
+ if (export) {
+ celix_status_t substatus = topologyManager_removeExportedService(manager, srvRefs[i], srvIds[i]);
+
+ if (substatus != CELIX_SUCCESS) {
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_ERROR, "TOPOLOGY_MANAGER: Removal of exported service (%s) failed.", srvIds[i]);
+ } else {
+ substatus = topologyManager_addExportedService(manager, srvRefs[i], srvIds[i]);
+ }
+
+ if (substatus != CELIX_SUCCESS) {
+ status = substatus;
+ }
+ }
+ }
+ }
+
+ free(srvRefs);
+ free(srvIds);
+ }
+
+ filter_destroy(filter);
+
+ return status;
+}
+
+celix_status_t topologyManager_importScopeChanged(void *handle, char *service_name) {
+ celix_status_t status = CELIX_SUCCESS;
+ endpoint_description_pt endpoint;
+ topology_manager_pt manager = (topology_manager_pt) handle;
+ bool found = false;
+
+ // add already exported services to new rsa
+ if (celixThreadMutex_lock(&manager->importedServicesLock) == CELIX_SUCCESS) {
+ hash_map_iterator_pt importedServicesIterator = hashMapIterator_create(manager->importedServices);
+ while (!found && hashMapIterator_hasNext(importedServicesIterator)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(importedServicesIterator);
+ endpoint = hashMapEntry_getKey(entry);
+
+ entry = hashMap_getEntry(endpoint->properties, (void *) OSGI_FRAMEWORK_OBJECTCLASS);
+ char* name = (char *) hashMapEntry_getValue(entry);
+ // Test if a service with the same name is imported
+ if (strcmp(name, service_name) == 0) {
+ found = true;
+ }
+ }
+ hashMapIterator_destroy(importedServicesIterator);
+ celixThreadMutex_unlock(&manager->importedServicesLock);
+ }
+
+ if (found) {
+ status = topologyManager_removeImportedService(manager, endpoint, NULL);
+
+ if (status != CELIX_SUCCESS) {
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_ERROR, "TOPOLOGY_MANAGER: Removal of imported service (%s; %s) failed.", endpoint->service, endpoint->id);
+ } else {
+ status = topologyManager_addImportedService(manager, endpoint, NULL);
+ }
+ }
+ return status;
+}
+
+celix_status_t topologyManager_addImportedService(void *handle, endpoint_description_pt endpoint, char *matchedFilter) {
+ celix_status_t status = CELIX_SUCCESS;
+ topology_manager_pt manager = handle;
+
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Add imported service (%s; %s).", endpoint->service, endpoint->id);
+
+ if (celixThreadMutex_lock(&manager->importedServicesLock) == CELIX_SUCCESS) {
+
+ hash_map_pt imports = hashMap_create(NULL, NULL, NULL, NULL);
+ hashMap_put(manager->importedServices, endpoint, imports);
+
+ if (scope_allowImport(manager->scope, endpoint)) {
+ if (celixThreadMutex_lock(&manager->rsaListLock) == CELIX_SUCCESS) {
+ int size = arrayList_size(manager->rsaList);
+
+ for (int iter = 0; iter < size; iter++) {
+ import_registration_pt import = NULL;
+ remote_service_admin_service_pt rsa = arrayList_get(manager->rsaList, iter);
+ celix_status_t substatus = rsa->importService(rsa->admin, endpoint, &import);
+ if (substatus == CELIX_SUCCESS) {
+ hashMap_put(imports, rsa, import);
+ } else {
+ status = substatus;
+ }
+ }
+ celixThreadMutex_unlock(&manager->rsaListLock);
+ }
+
+ }
+
+ celixThreadMutex_unlock(&manager->importedServicesLock);
+ }
+
+
+ return status;
+}
+
+celix_status_t topologyManager_removeImportedService(void *handle, endpoint_description_pt endpoint, char *matchedFilter) {
+ celix_status_t status = CELIX_SUCCESS;
+ topology_manager_pt manager = handle;
+
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Remove imported service (%s; %s).", endpoint->service, endpoint->id);
+
+ if (celixThreadMutex_lock(&manager->importedServicesLock) == CELIX_SUCCESS) {
+
+ hash_map_iterator_pt iter = hashMapIterator_create(manager->importedServices);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ endpoint_description_pt ep = hashMapEntry_getKey(entry);
+ hash_map_pt imports = hashMapEntry_getValue(entry);
+
+ if (imports != NULL && strcmp(endpoint->id, ep->id) == 0) {
+ hash_map_iterator_pt importsIter = hashMapIterator_create(imports);
+
+ while (hashMapIterator_hasNext(importsIter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(importsIter);
+ remote_service_admin_service_pt rsa = hashMapEntry_getKey(entry);
+ import_registration_pt import = hashMapEntry_getValue(entry);
+ celix_status_t substatus = rsa->importRegistration_close(rsa->admin, import);
+ if (substatus == CELIX_SUCCESS) {
+ hashMapIterator_remove(importsIter);
+ } else {
+ status = substatus;
+ }
+ }
+ hashMapIterator_destroy(importsIter);
+ hashMapIterator_remove(iter);
+
+ hashMap_destroy(imports, false, false);
+ }
+ }
+ hashMapIterator_destroy(iter);
+ celixThreadMutex_unlock(&manager->importedServicesLock);
+ }
+
+ return status;
+}
+
+celix_status_t topologyManager_addExportedService(topology_manager_pt manager, service_reference_pt reference, char *serviceId) {
+ celix_status_t status = CELIX_SUCCESS;
+ properties_pt serviceProperties = NULL;
+
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Add exported service (%s).", serviceId);
+
+ if (celixThreadMutex_lock(&manager->exportedServicesLock) == CELIX_SUCCESS) {
+ scope_getExportProperties(manager->scope, reference, &serviceProperties);
+ hash_map_pt exports = hashMap_create(NULL, NULL, NULL, NULL);
+ hashMap_put(manager->exportedServices, reference, exports);
+
+ if (celixThreadMutex_lock(&manager->rsaListLock) == CELIX_SUCCESS) {
+ int size = arrayList_size(manager->rsaList);
+
+ if (size == 0) {
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_WARNING, "TOPOLOGY_MANAGER: No RSA available yet.");
+ }
+
+ for (int iter = 0; iter < size; iter++) {
+ remote_service_admin_service_pt rsa = arrayList_get(manager->rsaList, iter);
+
+ array_list_pt endpoints = NULL;
+ celix_status_t substatus = rsa->exportService(rsa->admin, serviceId, serviceProperties, &endpoints);
+
+ if (substatus == CELIX_SUCCESS) {
+ hashMap_put(exports, rsa, endpoints);
+ topologyManager_notifyListenersEndpointAdded(manager, rsa, endpoints);
+ } else {
+ status = substatus;
+ }
+ }
+ celixThreadMutex_unlock(&manager->rsaListLock);
+ }
+ celixThreadMutex_unlock(&manager->exportedServicesLock);
+ }
+
+ return status;
+}
+
+celix_status_t topologyManager_removeExportedService(topology_manager_pt manager, service_reference_pt reference, char *serviceId) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Remove exported service (%s).", serviceId);
+
+ if (celixThreadMutex_lock(&manager->exportedServicesLock) == CELIX_SUCCESS) {
+ hash_map_pt exports = hashMap_get(manager->exportedServices, reference);
+ if (exports) {
+ hash_map_iterator_pt iter = hashMapIterator_create(exports);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ remote_service_admin_service_pt rsa = hashMapEntry_getKey(entry);
+ array_list_pt exportRegistrations = hashMapEntry_getValue(entry);
+
+ int size = arrayList_size(exportRegistrations);
+
+ for (int exportsIter = 0; exportsIter < size; exportsIter++) {
+ export_registration_pt export = arrayList_get(exportRegistrations, exportsIter);
+ topologyManager_notifyListenersEndpointRemoved(manager, rsa, export);
+ rsa->exportRegistration_close(rsa->admin, export);
+ }
+
+ hashMap_remove(exports, rsa);
+ //arrayList_destroy(exportRegistrations);
+ hashMapIterator_destroy(iter);
+ iter = hashMapIterator_create(exports);
+
+ }
+ hashMapIterator_destroy(iter);
+ }
+ exports = hashMap_remove(manager->exportedServices, reference);
+
+ if (exports != NULL) {
+ hashMap_destroy(exports, false, false);
+ }
+
+ celixThreadMutex_unlock(&manager->exportedServicesLock);
+ }
+
+ return status;
+}
+
+celix_status_t topologyManager_getEndpointDescriptionForExportRegistration(remote_service_admin_service_pt rsa, export_registration_pt export, endpoint_description_pt *endpoint) {
+ celix_status_t status;
+
+ export_reference_pt reference = NULL;
+ status = rsa->exportRegistration_getExportReference(export, &reference);
+
+ if (status == CELIX_SUCCESS) {
+ status = rsa->exportReference_getExportedEndpoint(reference, endpoint);
+ }
+
+ free(reference);
+
+ return status;
+}
+
+celix_status_t topologyManager_endpointListenerAdding(void* handle, service_reference_pt reference, void** service) {
+ celix_status_t status = CELIX_SUCCESS;
+ topology_manager_pt manager = (topology_manager_pt) handle;
+
+ bundleContext_getService(manager->context, reference, service);
+
+ return status;
+}
+
+celix_status_t topologyManager_endpointListenerAdded(void* handle, service_reference_pt reference, void* service) {
+ celix_status_t status = CELIX_SUCCESS;
+ topology_manager_pt manager = handle;
+ const char* scope = NULL;
+
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Added ENDPOINT_LISTENER");
+
+ if (celixThreadMutex_lock(&manager->listenerListLock) == CELIX_SUCCESS) {
+ hashMap_put(manager->listenerList, reference, NULL);
+ celixThreadMutex_unlock(&manager->listenerListLock);
+
+ serviceReference_getProperty(reference, OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
+
+ filter_pt filter = filter_create(scope);
+ hash_map_iterator_pt refIter = hashMapIterator_create(manager->exportedServices);
+
+ while (hashMapIterator_hasNext(refIter)) {
+ hash_map_pt rsaExports = hashMapIterator_nextValue(refIter);
+ hash_map_iterator_pt rsaIter = hashMapIterator_create(rsaExports);
+
+ while (hashMapIterator_hasNext(rsaIter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(rsaIter);
+ remote_service_admin_service_pt rsa = hashMapEntry_getKey(entry);
+ array_list_pt registrations = hashMapEntry_getValue(entry);
+
+ int arrayListSize = arrayList_size(registrations);
+ int cnt = 0;
+
+ for (; cnt < arrayListSize; cnt++) {
+ export_registration_pt export = arrayList_get(registrations, cnt);
+ endpoint_description_pt endpoint = NULL;
+
+ status = topologyManager_getEndpointDescriptionForExportRegistration(rsa, export, &endpoint);
+ if (status == CELIX_SUCCESS) {
+ bool matchResult = false;
+ filter_match(filter, endpoint->properties, &matchResult);
+ if (matchResult) {
+ endpoint_listener_pt listener = (endpoint_listener_pt) service;
+ status = listener->endpointAdded(listener->handle, endpoint, (char*)scope);
+ }
+ }
+ }
+ }
+ hashMapIterator_destroy(rsaIter);
+ }
+ hashMapIterator_destroy(refIter);
+
+ filter_destroy(filter);
+ }
+
+ return status;
+}
+
+celix_status_t topologyManager_endpointListenerModified(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status;
+
+ status = topologyManager_endpointListenerRemoved(handle, reference, service);
+
+ if (status == CELIX_SUCCESS) {
+ status = topologyManager_endpointListenerAdded(handle, reference, service);
+ }
+
+ return status;
+}
+
+celix_status_t topologyManager_endpointListenerRemoved(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+ topology_manager_pt manager = handle;
+
+ if (celixThreadMutex_lock(&manager->listenerListLock) == CELIX_SUCCESS) {
+
+ if (hashMap_remove(manager->listenerList, reference)) {
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "EndpointListener Removed");
+ }
+
+ celixThreadMutex_unlock(&manager->listenerListLock);
+ }
+
+ return status;
+}
+
+celix_status_t topologyManager_notifyListenersEndpointAdded(topology_manager_pt manager, remote_service_admin_service_pt rsa, array_list_pt registrations) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (celixThreadMutex_lock(&manager->listenerListLock) == CELIX_SUCCESS) {
+
+ hash_map_iterator_pt iter = hashMapIterator_create(manager->listenerList);
+ while (hashMapIterator_hasNext(iter)) {
+ const char* scope = NULL;
+ endpoint_listener_pt epl = NULL;
+ service_reference_pt reference = hashMapIterator_nextKey(iter);
+
+ serviceReference_getProperty(reference, OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
+
+ status = bundleContext_getService(manager->context, reference, (void **) &epl);
+ if (status == CELIX_SUCCESS) {
+ filter_pt filter = filter_create(scope);
+
+ int regSize = arrayList_size(registrations);
+ for (int regIt = 0; regIt < regSize; regIt++) {
+ export_registration_pt export = arrayList_get(registrations, regIt);
+ endpoint_description_pt endpoint = NULL;
+ celix_status_t substatus = topologyManager_getEndpointDescriptionForExportRegistration(rsa, export, &endpoint);
+ if (substatus == CELIX_SUCCESS) {
+ bool matchResult = false;
+ filter_match(filter, endpoint->properties, &matchResult);
+ if (matchResult) {
+ status = epl->endpointAdded(epl->handle, endpoint, (char*)scope);
+ }
+ } else {
+ status = substatus;
+ }
+ }
+ filter_destroy(filter);
+ }
+ }
+ hashMapIterator_destroy(iter);
+ celixThreadMutex_unlock(&manager->listenerListLock);
+ }
+
+ return status;
+}
+
+celix_status_t topologyManager_notifyListenersEndpointRemoved(topology_manager_pt manager, remote_service_admin_service_pt rsa, export_registration_pt export) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (celixThreadMutex_lock(&manager->listenerListLock) == CELIX_SUCCESS) {
+ hash_map_iterator_pt iter = hashMapIterator_create(manager->listenerList);
+ while (hashMapIterator_hasNext(iter)) {
+ endpoint_description_pt endpoint = NULL;
+ endpoint_listener_pt epl = NULL;
+ celix_status_t substatus;
+ const char* scope = NULL;
+
+ service_reference_pt reference = hashMapIterator_nextKey(iter);
+ serviceReference_getProperty(reference, OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
+
+ substatus = bundleContext_getService(manager->context, reference, (void **) &epl);
+
+ if (substatus == CELIX_SUCCESS) {
+ substatus = topologyManager_getEndpointDescriptionForExportRegistration(rsa, export, &endpoint);
+ }
+
+ if (substatus == CELIX_SUCCESS) {
+ substatus = epl->endpointRemoved(epl->handle, endpoint, NULL);
+ }
+
+ /* if (substatus != CELIX_SUCCESS) {
+ status = substatus;
+
+ }
+ */
+ }
+ hashMapIterator_destroy(iter);
+ celixThreadMutex_unlock(&manager->listenerListLock);
+ }
+
+ return status;
+}
+
+celix_status_t topologyManager_extendFilter(topology_manager_pt manager, char *filter, char **updatedFilter) {
+ celix_status_t status;
+ bundle_context_pt context = manager->context;
+ const char* uuid = NULL;
+
+ status = bundleContext_getProperty(context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
+
+ if (!uuid) {
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_ERROR, "TOPOLOGY_MANAGER: no framework UUID defined?!");
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+
+ int len = 10 + strlen(filter) + strlen(OSGI_RSA_ENDPOINT_FRAMEWORK_UUID) + strlen(uuid);
+ *updatedFilter = malloc(len);
+ if (!*updatedFilter) {
+ return CELIX_ENOMEM;
+ }
+
+ snprintf(*updatedFilter, len, "(&%s(!(%s=%s)))", filter, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
+
+ return status;
+}
+
+celix_status_t topologyManager_listenerAdded(void *handle, array_list_pt listeners) {
+ celix_status_t status = CELIX_SUCCESS;
+ topology_manager_pt manager = handle;
+
+ for (int i = 0; i < arrayList_size(listeners); i++) {
+ listener_hook_info_pt info = arrayList_get(listeners, i);
+ bundle_pt bundle = NULL, self = NULL;
+ bundleContext_getBundle(info->context, &bundle);
+ bundleContext_getBundle(manager->context, &self);
+ if (bundle == self) {
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "TOPOLOGY_MANAGER: Ignore myself.");
+ continue;
+ }
+
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: listener with filter \"%s\" added", info->filter);
+
+ char *filter = NULL;
+ bool free_filter = true;
+ status = topologyManager_extendFilter(manager, info->filter, &filter);
+#if 0
+ if(filter != NULL){
+ // TODO: add status handling
+ status = celixThreadMutex_lock(&manager->importScopesLock);
+
+ struct scope *interest = hashMap_get(manager->importScopes, filter);
+ if (interest) {
+ interest->refs++;
+ free(filter);
+ filter = NULL;
+ } else {
+ interest = malloc(sizeof(*interest));
+ interest->filter = filter;
+ interest->refs = 1;
+ hashMap_put(manager->importScopes, filter, interest);
+ free_filter = false;
+ }
+
+ status = celixThreadMutex_unlock(&manager->importScopesLock);
+ }
+#endif
+
+ if (filter != NULL && free_filter) {
+ free(filter);
+ }
+
+ }
+
+ return status;
+}
+
+celix_status_t topologyManager_listenerRemoved(void *handle, array_list_pt listeners) {
+ celix_status_t status = CELIX_SUCCESS;
+ topology_manager_pt manager = handle;
+
+ for (int i = 0; i < arrayList_size(listeners); i++) {
+ listener_hook_info_pt info = arrayList_get(listeners, i);
+
+ bundle_pt bundle = NULL, self = NULL;
+ bundleContext_getBundle(info->context, &bundle);
+ bundleContext_getBundle(manager->context, &self);
+ if (bundle == self) {
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "TOPOLOGY_MANAGER: Ignore myself.");
+ continue;
+ }
+
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: listener with filter \"%s\" removed.", info->filter);
+
+ char *filter = NULL;
+ topologyManager_extendFilter(manager, info->filter, &filter);
+#if 0
+ status = celixThreadMutex_lock(&manager->importScopesLock);
+
+ struct scope *interest = hashMap_get(manager->importScopes, filter);
+ if (interest != NULL && --interest->refs <= 0) {
+ // last reference, remove from scope
+ hash_map_entry_pt entry = hashMap_getEntry(manager->importScopes, filter);
+ char* key = (char*) hashMapEntry_getKey(entry);
+ interest = hashMap_remove(manager->importScopes, filter);
+ free(key);
+ free(interest);
+ }
+#endif
+
+ if (filter != NULL) {
+ free(filter);
+ }
+#if 0
+ status = celixThreadMutex_unlock(&manager->importScopesLock);
+#endif
+ }
+
+ return status;
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/topology_manager/src/topology_manager.h
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/src/topology_manager.h b/remote_services/topology_manager/src/topology_manager.h
new file mode 100644
index 0000000..7e5e917
--- /dev/null
+++ b/remote_services/topology_manager/src/topology_manager.h
@@ -0,0 +1,65 @@
+/**
+ *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.
+ */
+/*
+ * topology_manager.h
+ *
+ * \date Sep 29, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef TOPOLOGY_MANAGER_H_
+#define TOPOLOGY_MANAGER_H_
+
+#include "endpoint_listener.h"
+#include "service_reference.h"
+#include "bundle_context.h"
+#include "log_helper.h"
+#include "scope.h"
+
+#define OSGI_RSA_REMOTE_SERVICE_ADMIN "remote_service_admin"
+
+typedef struct topology_manager *topology_manager_pt;
+
+celix_status_t topologyManager_create(bundle_context_pt context, log_helper_pt logHelper, topology_manager_pt *manager, void **scope);
+celix_status_t topologyManager_destroy(topology_manager_pt manager);
+celix_status_t topologyManager_closeImports(topology_manager_pt manager);
+
+celix_status_t topologyManager_rsaAdding(void *handle, service_reference_pt reference, void **service);
+celix_status_t topologyManager_rsaAdded(void *handle, service_reference_pt reference, void *service);
+celix_status_t topologyManager_rsaModified(void *handle, service_reference_pt reference, void *service);
+celix_status_t topologyManager_rsaRemoved(void *handle, service_reference_pt reference, void *service);
+
+celix_status_t topologyManager_endpointListenerAdding(void* handle, service_reference_pt reference, void** service);
+celix_status_t topologyManager_endpointListenerAdded(void* handle, service_reference_pt reference, void* service);
+celix_status_t topologyManager_endpointListenerModified(void * handle, service_reference_pt reference, void* service);
+celix_status_t topologyManager_endpointListenerRemoved(void * handle, service_reference_pt reference, void* service);
+
+celix_status_t topologyManager_serviceChanged(void *listener, service_event_pt event);
+
+celix_status_t topologyManager_addImportedService(void *handle, endpoint_description_pt endpoint, char *matchedFilter);
+celix_status_t topologyManager_removeImportedService(void *handle, endpoint_description_pt endpoint, char *matchedFilter);
+
+celix_status_t topologyManager_addExportedService(topology_manager_pt manager, service_reference_pt reference, char *serviceId);
+celix_status_t topologyManager_removeExportedService(topology_manager_pt manager, service_reference_pt reference, char *serviceId);
+
+celix_status_t topologyManager_listenerAdded(void *handle, array_list_pt listeners);
+celix_status_t topologyManager_listenerRemoved(void *handle, array_list_pt listeners);
+
+#endif /* TOPOLOGY_MANAGER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/topology_manager/tms_tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/tms_tst/CMakeLists.txt b/remote_services/topology_manager/tms_tst/CMakeLists.txt
index dc671e4..6d0713c 100644
--- a/remote_services/topology_manager/tms_tst/CMakeLists.txt
+++ b/remote_services/topology_manager/tms_tst/CMakeLists.txt
@@ -36,10 +36,8 @@ SET(CMAKE_INSTALL_RPATH "${PROJECT_BINARY_DIR}/framework" "${PROJECT_BINARY_DIR}
add_executable(test_tm_scoped
run_tests.cpp
tms_tests.cpp
-
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
)
-target_link_libraries(test_tm_scoped Celix::framework ${CPPUTEST_LIBRARY} ${JANSSON_LIBRARY} Celix::log_helper)
+target_link_libraries(test_tm_scoped Celix::framework ${CPPUTEST_LIBRARY} ${JANSSON_LIBRARY} Celix::log_helper remote_service_admin_common)
add_dependencies(test_tm_scoped remote_service_admin_dfi topology_manager calculator)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt b/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
index 9e36e4c..fc9d9bf 100644
--- a/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
+++ b/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
@@ -32,4 +32,4 @@ bundle_files(topology_manager_test_bundle
DESTINATION .
)
-target_link_libraries(topology_manager_test_bundle PRIVATE ${CPPUTEST_LIBRARY})
+target_link_libraries(topology_manager_test_bundle PRIVATE ${CPPUTEST_LIBRARY} remote_service_admin calculator_api)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt b/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt
index b961de7..bfd7fc1 100644
--- a/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt
+++ b/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt
@@ -15,14 +15,6 @@
# specific language governing permissions and limitations
# under the License.
-include_directories(
- ${CPPUTEST_INCLUDE_DIR}
- ${PROJECT_SOURCE_DIR}/framework/public/include
- ${PROJECT_SOURCE_DIR}/utils/public/include
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/include
-)
-
-
add_bundle(topology_manager_disc_mock_bundle
VERSION 0.0.1
SOURCES
@@ -30,4 +22,5 @@ add_bundle(topology_manager_disc_mock_bundle
disc_mock_service.c
)
-target_link_libraries(topology_manager_disc_mock_bundle PRIVATE ${CPPUTEST_LIBRARY} Celix::framework)
+target_include_directories(topology_manager_disc_mock_bundle PRIVATE ${CPPUTEST_INCLUDE_DIR})
+target_link_libraries(topology_manager_disc_mock_bundle PRIVATE ${CPPUTEST_LIBRARY} Celix::framework discovery_common)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/utils/private/include/civetweb.h
----------------------------------------------------------------------
diff --git a/remote_services/utils/private/include/civetweb.h b/remote_services/utils/private/include/civetweb.h
deleted file mode 100644
index 61a8e98..0000000
--- a/remote_services/utils/private/include/civetweb.h
+++ /dev/null
@@ -1,657 +0,0 @@
-/* Copyright (c) 2013-2014 the Civetweb developers
- * Copyright (c) 2004-2013 Sergey Lyubka
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef CIVETWEB_HEADER_INCLUDED
-#define CIVETWEB_HEADER_INCLUDED
-
-#ifndef CIVETWEB_VERSION
-#define CIVETWEB_VERSION "1.7"
-#endif
-
-#ifndef CIVETWEB_API
- #if defined(_WIN32)
- #if defined(CIVETWEB_DLL_EXPORTS)
- #define CIVETWEB_API __declspec(dllexport)
- #elif defined(CIVETWEB_DLL_IMPORTS)
- #define CIVETWEB_API __declspec(dllimport)
- #else
- #define CIVETWEB_API
- #endif
- #else
- #define CIVETWEB_API
- #endif
-#endif
-
-#include <stdio.h>
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-struct mg_context; /* Handle for the HTTP service itself */
-struct mg_connection; /* Handle for the individual connection */
-
-
-/* This structure contains information about the HTTP request. */
-struct mg_request_info {
- const char *request_method; /* "GET", "POST", etc */
- const char *uri; /* URL-decoded URI */
- const char *http_version; /* E.g. "1.0", "1.1" */
- const char *query_string; /* URL part after '?', not including '?', or
- NULL */
- const char *remote_user; /* Authenticated user, or NULL if no auth
- used */
- char remote_addr[48]; /* Client's IP address as a string. */
- long remote_ip; /* Client's IP address. Deprecated: use remote_addr instead */
-
- long long content_length; /* Length (in bytes) of the request body,
- can be -1 if no length was given. */
- int remote_port; /* Client's port */
- int is_ssl; /* 1 if SSL-ed, 0 if not */
- void *user_data; /* User data pointer passed to mg_start() */
- void *conn_data; /* Connection-specific user data */
-
- int num_headers; /* Number of HTTP headers */
- struct mg_header {
- const char *name; /* HTTP header name */
- const char *value; /* HTTP header value */
- } http_headers[64]; /* Maximum 64 headers */
-};
-
-
-/* This structure needs to be passed to mg_start(), to let civetweb know
- which callbacks to invoke. For a detailed description, see
- https://github.com/bel2125/civetweb/blob/master/docs/UserManual.md */
-struct mg_callbacks {
- /* Called when civetweb has received new HTTP request.
- If the callback returns one, it must process the request
- by sending valid HTTP headers and a body. Civetweb will not do
- any further processing. Otherwise it must return zero.
- Note that since V1.7 the "begin_request" function is called
- before an authorization check. If an authorization check is
- required, use a request_handler instead.
- Return value:
- 0: civetweb will process the request itself. In this case,
- the callback must not send any data to the client.
- 1: callback already processed the request. Civetweb will
- not send any data after the callback returned. */
- int (*begin_request)(struct mg_connection *);
-
- /* Called when civetweb has finished processing request. */
- void (*end_request)(const struct mg_connection *, int reply_status_code);
-
- /* Called when civetweb is about to log a message. If callback returns
- non-zero, civetweb does not log anything. */
- int (*log_message)(const struct mg_connection *, const char *message);
-
- /* Called when civetweb initializes SSL library.
- Parameters:
- user_data: parameter user_data passed when starting the server.
- Return value:
- 0: civetweb will set up the SSL certificate.
- 1: civetweb assumes the callback already set up the certificate.
- -1: initializing ssl fails. */
- int (*init_ssl)(void *ssl_context, void *user_data);
-
- /* Called when websocket request is received, before websocket handshake.
- Return value:
- 0: civetweb proceeds with websocket handshake.
- 1: connection is closed immediately. */
- int (*websocket_connect)(const struct mg_connection *);
-
- /* Called when websocket handshake is successfully completed, and
- connection is ready for data exchange. */
- void (*websocket_ready)(struct mg_connection *);
-
- /* Called when data frame has been received from the client.
- Parameters:
- bits: first byte of the websocket frame, see websocket RFC at
- http://tools.ietf.org/html/rfc6455, section 5.2
- data, data_len: payload, with mask (if any) already applied.
- Return value:
- 1: keep this websocket connection open.
- 0: close this websocket connection. */
- int (*websocket_data)(struct mg_connection *, int bits,
- char *data, size_t data_len);
-
- /* Called when civetweb is closing a connection. The per-context mutex is
- locked when this is invoked. This is primarily useful for noting when
- a websocket is closing and removing it from any application-maintained
- list of clients. */
- void (*connection_close)(struct mg_connection *);
-
- /* Called when civetweb tries to open a file. Used to intercept file open
- calls, and serve file data from memory instead.
- Parameters:
- path: Full path to the file to open.
- data_len: Placeholder for the file size, if file is served from
- memory.
- Return value:
- NULL: do not serve file from memory, proceed with normal file open.
- non-NULL: pointer to the file contents in memory. data_len must be
- initilized with the size of the memory block. */
- const char * (*open_file)(const struct mg_connection *,
- const char *path, size_t *data_len);
-
- /* Called when civetweb is about to serve Lua server page, if
- Lua support is enabled.
- Parameters:
- lua_context: "lua_State *" pointer. */
- void (*init_lua)(struct mg_connection *, void *lua_context);
-
- /* Called when civetweb has uploaded a file to a temporary directory as a
- result of mg_upload() call.
- Parameters:
- file_name: full path name to the uploaded file. */
- void (*upload)(struct mg_connection *, const char *file_name);
-
- /* Called when civetweb is about to send HTTP error to the client.
- Implementing this callback allows to create custom error pages.
- Parameters:
- status: HTTP error status code.
- Return value:
- 1: run civetweb error handler.
- 0: callback already handled the error. */
- int (*http_error)(struct mg_connection *, int status);
-
- /* Called after civetweb context has been created, before requests
- are processed.
- Parameters:
- ctx: context handle */
- void (*init_context)(struct mg_context * ctx);
-
- /* Called when civetweb context is deleted.
- Parameters:
- ctx: context handle */
- void (*exit_context)(struct mg_context * ctx);
-};
-
-
-/* Start web server.
-
- Parameters:
- callbacks: mg_callbacks structure with user-defined callbacks.
- options: NULL terminated list of option_name, option_value pairs that
- specify Civetweb configuration parameters.
-
- Side-effects: on UNIX, ignores SIGCHLD and SIGPIPE signals. If custom
- processing is required for these, signal handlers must be set up
- after calling mg_start().
-
-
- Example:
- const char *options[] = {
- "document_root", "/var/www",
- "listening_ports", "80,443s",
- NULL
- };
- struct mg_context *ctx = mg_start(&my_func, NULL, options);
-
- Refer to https://github.com/bel2125/civetweb/blob/master/docs/UserManual.md
- for the list of valid option and their possible values.
-
- Return:
- web server context, or NULL on error. */
-CIVETWEB_API struct mg_context *mg_start(const struct mg_callbacks *callbacks,
- void *user_data,
- const char **configuration_options);
-
-
-/* Stop the web server.
-
- Must be called last, when an application wants to stop the web server and
- release all associated resources. This function blocks until all Civetweb
- threads are stopped. Context pointer becomes invalid. */
-CIVETWEB_API void mg_stop(struct mg_context *);
-
-
-/* mg_request_handler
-
- Called when a new request comes in. This callback is URI based
- and configured with mg_set_request_handler().
-
- Parameters:
- conn: current connection information.
- cbdata: the callback data configured with mg_set_request_handler().
- Returns:
- 0: the handler could not handle the request, so fall through.
- 1: the handler processed the request. */
-typedef int (* mg_request_handler)(struct mg_connection *conn, void *cbdata);
-
-
-/* mg_set_request_handler
-
- Sets or removes a URI mapping for a request handler.
-
- URI's are ordered and prefixed URI's are supported. For example,
- consider two URIs: /a/b and /a
- /a matches /a
- /a/b matches /a/b
- /a/c matches /a
-
- Parameters:
- ctx: server context
- uri: the URI to configure
- handler: the callback handler to use when the URI is requested.
- If NULL, the URI will be removed.
- cbdata: the callback data to give to the handler when it s requested. */
-CIVETWEB_API void mg_set_request_handler(struct mg_context *ctx, const char *uri, mg_request_handler handler, void *cbdata);
-
-
-/* Get the value of particular configuration parameter.
- The value returned is read-only. Civetweb does not allow changing
- configuration at run time.
- If given parameter name is not valid, NULL is returned. For valid
- names, return value is guaranteed to be non-NULL. If parameter is not
- set, zero-length string is returned. */
-CIVETWEB_API const char *mg_get_option(const struct mg_context *ctx, const char *name);
-
-
-/* Get context from connection. */
-CIVETWEB_API struct mg_context *mg_get_context(struct mg_connection *conn);
-
-
-/* Get user data passed to mg_start from context. */
-CIVETWEB_API void *mg_get_user_data(struct mg_context *ctx);
-
-
-#if defined(MG_LEGACY_INTERFACE)
-/* Return array of strings that represent valid configuration options.
- For each option, option name and default value is returned, i.e. the
- number of entries in the array equals to number_of_options x 2.
- Array is NULL terminated. */
-/* Deprecated: Use mg_get_valid_options instead. */
-CIVETWEB_API const char **mg_get_valid_option_names(void);
-#endif
-
-
-struct mg_option {
- const char * name;
- int type;
- const char * default_value;
-};
-
-enum {
- CONFIG_TYPE_UNKNOWN = 0x0,
- CONFIG_TYPE_NUMBER = 0x1,
- CONFIG_TYPE_STRING = 0x2,
- CONFIG_TYPE_FILE = 0x3,
- CONFIG_TYPE_DIRECTORY = 0x4,
- CONFIG_TYPE_BOOLEAN = 0x5,
- CONFIG_TYPE_EXT_PATTERN = 0x6
-};
-
-
-/* Return array of struct mg_option, representing all valid configuration
- options of civetweb.c.
- The array is terminated by a NULL name option. */
-CIVETWEB_API const struct mg_option *mg_get_valid_options(void);
-
-
-/* Get the list of ports that civetweb is listening on.
- size is the size of the ports int array and ssl int array to fill.
- It is the caller's responsibility to make sure ports and ssl each
- contain at least size int elements worth of memory to write into.
- Return value is the number of ports and ssl information filled in.
- The value returned is read-only. Civetweb does not allow changing
- configuration at run time. */
-CIVETWEB_API size_t mg_get_ports(const struct mg_context *ctx, size_t size, int* ports, int* ssl);
-
-
-/* Add, edit or delete the entry in the passwords file.
-
- This function allows an application to manipulate .htpasswd files on the
- fly by adding, deleting and changing user records. This is one of the
- several ways of implementing authentication on the server side. For another,
- cookie-based way please refer to the examples/chat in the source tree.
-
- If password is not NULL, entry is added (or modified if already exists).
- If password is NULL, entry is deleted.
-
- Return:
- 1 on success, 0 on error. */
-CIVETWEB_API int mg_modify_passwords_file(const char *passwords_file_name,
- const char *domain,
- const char *user,
- const char *password);
-
-
-/* Return information associated with the request. */
-CIVETWEB_API struct mg_request_info *mg_get_request_info(struct mg_connection *);
-
-
-/* Send data to the client.
- Return:
- 0 when the connection has been closed
- -1 on error
- >0 number of bytes written on success */
-CIVETWEB_API int mg_write(struct mg_connection *, const void *buf, size_t len);
-
-
-/* Send data to a websocket client wrapped in a websocket frame. Uses mg_lock
- to ensure that the transmission is not interrupted, i.e., when the
- application is proactively communicating and responding to a request
- simultaneously.
-
- Send data to a websocket client wrapped in a websocket frame.
- This function is available when civetweb is compiled with -DUSE_WEBSOCKET
-
- Return:
- 0 when the connection has been closed
- -1 on error
- >0 number of bytes written on success */
-CIVETWEB_API int mg_websocket_write(struct mg_connection* conn, int opcode,
- const char *data, size_t data_len);
-
-
-/* Blocks until unique access is obtained to this connection. Intended for use
- with websockets only.
- Invoke this before mg_write or mg_printf when communicating with a
- websocket if your code has server-initiated communication as well as
- communication in direct response to a message. */
-CIVETWEB_API void mg_lock_connection(struct mg_connection* conn);
-CIVETWEB_API void mg_unlock_connection(struct mg_connection* conn);
-
-#if defined(MG_LEGACY_INTERFACE)
-#define mg_lock mg_lock_connection
-#define mg_unlock mg_unlock_connection
-#endif
-
-/* Lock server context. This lock may be used to protect ressources
- that are shared between different connection/worker threads. */
-CIVETWEB_API void mg_lock_context(struct mg_context* ctx);
-CIVETWEB_API void mg_unlock_context(struct mg_context* ctx);
-
-
-/* Opcodes, from http://tools.ietf.org/html/rfc6455 */
-enum {
- WEBSOCKET_OPCODE_CONTINUATION = 0x0,
- WEBSOCKET_OPCODE_TEXT = 0x1,
- WEBSOCKET_OPCODE_BINARY = 0x2,
- WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
- WEBSOCKET_OPCODE_PING = 0x9,
- WEBSOCKET_OPCODE_PONG = 0xa
-};
-
-
-/* Macros for enabling compiler-specific checks forprintf-like arguments. */
-#undef PRINTF_FORMAT_STRING
-#if defined(_MSC_VER) && _MSC_VER >= 1400
-#include <sal.h>
-#if defined(_MSC_VER) && _MSC_VER > 1400
-#define PRINTF_FORMAT_STRING(s) _Printf_format_string_ s
-#else
-#define PRINTF_FORMAT_STRING(s) __format_string s
-#endif
-#else
-#define PRINTF_FORMAT_STRING(s) s
-#endif
-
-#ifdef __GNUC__
-#define PRINTF_ARGS(x, y) __attribute__((format(printf, x, y)))
-#else
-#define PRINTF_ARGS(x, y)
-#endif
-
-/* Send data to the client usingprintf() semantics.
- Works exactly like mg_write(), but allows to do message formatting. */
-CIVETWEB_API int mg_printf(struct mg_connection *,
- PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(2, 3);
-
-
-/* Send contents of the entire file together with HTTP headers. */
-CIVETWEB_API void mg_send_file(struct mg_connection *conn, const char *path);
-
-
-/* Read data from the remote end, return number of bytes read.
- Return:
- 0 connection has been closed by peer. No more data could be read.
- < 0 read error. No more data could be read from the connection.
- > 0 number of bytes read into the buffer. */
-CIVETWEB_API int mg_read(struct mg_connection *, void *buf, size_t len);
-
-
-/* Get the value of particular HTTP header.
-
- This is a helper function. It traverses request_info->http_headers array,
- and if the header is present in the array, returns its value. If it is
- not present, NULL is returned. */
-CIVETWEB_API const char *mg_get_header(const struct mg_connection *, const char *name);
-
-
-/* Get a value of particular form variable.
-
- Parameters:
- data: pointer to form-uri-encoded buffer. This could be either POST data,
- or request_info.query_string.
- data_len: length of the encoded data.
- var_name: variable name to decode from the buffer
- dst: destination buffer for the decoded variable
- dst_len: length of the destination buffer
-
- Return:
- On success, length of the decoded variable.
- On error:
- -1 (variable not found).
- -2 (destination buffer is NULL, zero length or too small to hold the
- decoded variable).
-
- Destination buffer is guaranteed to be '\0' - terminated if it is not
- NULL or zero length. */
-CIVETWEB_API int mg_get_var(const char *data, size_t data_len,
- const char *var_name, char *dst, size_t dst_len);
-
-
-/* Get a value of particular form variable.
-
- Parameters:
- data: pointer to form-uri-encoded buffer. This could be either POST data,
- or request_info.query_string.
- data_len: length of the encoded data.
- var_name: variable name to decode from the buffer
- dst: destination buffer for the decoded variable
- dst_len: length of the destination buffer
- occurrence: which occurrence of the variable, 0 is the first, 1 the
- second...
- this makes it possible to parse a query like
- b=x&a=y&a=z which will have occurrence values b:0, a:0 and a:1
-
- Return:
- On success, length of the decoded variable.
- On error:
- -1 (variable not found).
- -2 (destination buffer is NULL, zero length or too small to hold the
- decoded variable).
-
- Destination buffer is guaranteed to be '\0' - terminated if it is not
- NULL or zero length. */
-CIVETWEB_API int mg_get_var2(const char *data, size_t data_len,
- const char *var_name, char *dst, size_t dst_len, size_t occurrence);
-
-
-/* Fetch value of certain cookie variable into the destination buffer.
-
- Destination buffer is guaranteed to be '\0' - terminated. In case of
- failure, dst[0] == '\0'. Note that RFC allows many occurrences of the same
- parameter. This function returns only first occurrence.
-
- Return:
- On success, value length.
- On error:
- -1 (either "Cookie:" header is not present at all or the requested
- parameter is not found).
- -2 (destination buffer is NULL, zero length or too small to hold the
- value). */
-CIVETWEB_API int mg_get_cookie(const char *cookie, const char *var_name,
- char *buf, size_t buf_len);
-
-
-/* Download data from the remote web server.
- host: host name to connect to, e.g. "foo.com", or "10.12.40.1".
- port: port number, e.g. 80.
- use_ssl: wether to use SSL connection.
- error_buffer, error_buffer_size: error message placeholder.
- request_fmt,...: HTTP request.
- Return:
- On success, valid pointer to the new connection, suitable for mg_read().
- On error, NULL. error_buffer contains error message.
- Example:
- char ebuf[100];
- struct mg_connection *conn;
- conn = mg_download("google.com", 80, 0, ebuf, sizeof(ebuf),
- "%s", "GET / HTTP/1.0\r\nHost: google.com\r\n\r\n");
- */
-CIVETWEB_API struct mg_connection *mg_download(const char *host, int port, int use_ssl,
- char *error_buffer, size_t error_buffer_size,
- PRINTF_FORMAT_STRING(const char *request_fmt),
- ...) PRINTF_ARGS(6, 7);
-
-
-/* Close the connection opened by mg_download(). */
-CIVETWEB_API void mg_close_connection(struct mg_connection *conn);
-
-
-/* File upload functionality. Each uploaded file gets saved into a temporary
- file and MG_UPLOAD event is sent.
- Return number of uploaded files. */
-CIVETWEB_API int mg_upload(struct mg_connection *conn, const char *destination_dir);
-
-
-/* Convenience function -- create detached thread.
- Return: 0 on success, non-0 on error. */
-typedef void * (*mg_thread_func_t)(void *);
-CIVETWEB_API int mg_start_thread(mg_thread_func_t f, void *p);
-
-
-/* Return builtin mime type for the given file name.
- For unrecognized extensions, "text/plain" is returned. */
-CIVETWEB_API const char *mg_get_builtin_mime_type(const char *file_name);
-
-
-/* Return Civetweb version. */
-CIVETWEB_API const char *mg_version(void);
-
-
-/* URL-decode input buffer into destination buffer.
- 0-terminate the destination buffer.
- form-url-encoded data differs from URI encoding in a way that it
- uses '+' as character for space, see RFC 1866 section 8.2.1
- http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
- Return: length of the decoded data, or -1 if dst buffer is too small. */
-CIVETWEB_API int mg_url_decode(const char *src, int src_len, char *dst,
- int dst_len, int is_form_url_encoded);
-
-
-/* URL-encode input buffer into destination buffer.
- returns the length of the resulting buffer or -1
- is the buffer is too small. */
-CIVETWEB_API int mg_url_encode(const char *src, char *dst, size_t dst_len);
-
-
-/* MD5 hash given strings.
- Buffer 'buf' must be 33 bytes long. Varargs is a NULL terminated list of
- ASCIIz strings. When function returns, buf will contain human-readable
- MD5 hash. Example:
- char buf[33];
- mg_md5(buf, "aa", "bb", NULL); */
-CIVETWEB_API char *mg_md5(char buf[33], ...);
-
-
-/* Print error message to the opened error log stream.
- This utilizes the provided logging configuration.
- conn: connection
- fmt: format string without the line return
- ...: variable argument list
- Example:
- mg_cry(conn,"i like %s", "logging"); */
-CIVETWEB_API void mg_cry(struct mg_connection *conn,
- PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(2, 3);
-
-
-/* utility method to compare two buffers, case incensitive. */
-CIVETWEB_API int mg_strncasecmp(const char *s1, const char *s2, size_t len);
-
-/* Connect to a websocket as a client
- Parameters:
- host: host to connect to, i.e. "echo.websocket.org" or "192.168.1.1" or "localhost"
- port: server port
- use_ssl: make a secure connection to server
- error_buffer, error_buffer_size: buffer for an error message
- path: server path you are trying to connect to, i.e. if connection to localhost/app, path should be "/app"
- origin: value of the Origin HTTP header
- data_func: callback that should be used when data is received from the server
- user_data: user supplied argument
-
- Return:
- On success, valid mg_connection object.
- On error, NULL. Se error_buffer for details.
-*/
-
-typedef int (*websocket_data_func)(struct mg_connection *, int bits,
- char *data, size_t data_len);
-
-typedef void (*websocket_close_func)(struct mg_connection *);
-
-CIVETWEB_API struct mg_connection *mg_connect_websocket_client(const char *host, int port, int use_ssl,
- char *error_buffer, size_t error_buffer_size,
- const char *path, const char *origin,
- websocket_data_func data_func, websocket_close_func close_func,
- void * user_data);
-
-/* Connect to a TCP server as a client (can be used to connect to a HTTP server)
- Parameters:
- host: host to connect to, i.e. "www.wikipedia.org" or "192.168.1.1" or "localhost"
- port: server port
- use_ssl: make a secure connection to server
- error_buffer, error_buffer_size: buffer for an error message
-
- Return:
- On success, valid mg_connection object.
- On error, NULL. Se error_buffer for details.
-*/
-CIVETWEB_API struct mg_connection *mg_connect_client(const char *host, int port, int use_ssl,
- char *error_buffer, size_t error_buffer_size);
-
-
-enum {
- TIMEOUT_INFINITE = -1
-};
-
-/* Wait for a response from the server
- Parameters:
- conn: connection
- ebuf, ebuf_len: error message placeholder.
- timeout: time to wait for a response in milliseconds (if < 0 then wait forever)
-
- Return:
- On success, >= 0
- On error/timeout, < 0
-*/
-CIVETWEB_API int mg_get_response(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int timeout);
-
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* CIVETWEB_HEADER_INCLUDED */
[38/54] [abbrv] celix git commit: CELIX-417: Refactors cmake usage of
pubsub and rsa. Started with installing exported targets
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/src/topic_subscription.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/src/topic_subscription.c b/pubsub/pubsub_admin_zmq/src/topic_subscription.c
new file mode 100644
index 0000000..0e7a794
--- /dev/null
+++ b/pubsub/pubsub_admin_zmq/src/topic_subscription.c
@@ -0,0 +1,732 @@
+/**
+ *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.
+ */
+/*
+ * topic_subscription.c
+ *
+ * \date Oct 2, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include "topic_subscription.h"
+#include <czmq.h>
+/* The following undefs prevent the collision between:
+ * - sys/syslog.h (which is included within czmq)
+ * - celix/dfi/dfi_log_util.h
+ */
+#undef LOG_DEBUG
+#undef LOG_WARNING
+#undef LOG_INFO
+#undef LOG_WARNING
+
+#include <string.h>
+#include <stdlib.h>
+#include <signal.h>
+
+#include "utils.h"
+#include "celix_errno.h"
+#include "constants.h"
+#include "version.h"
+
+#include "subscriber.h"
+#include "publisher.h"
+#include "pubsub_utils.h"
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+#include "zmq_crypto.h"
+
+#define MAX_CERT_PATH_LENGTH 512
+#endif
+
+#define POLL_TIMEOUT 250
+#define ZMQ_POLL_TIMEOUT_MS_ENV "ZMQ_POLL_TIMEOUT_MS"
+
+struct topic_subscription{
+
+ zsock_t* zmq_socket;
+ zcert_t * zmq_cert;
+ zcert_t * zmq_pub_cert;
+ pthread_mutex_t socket_lock;
+ service_tracker_pt tracker;
+ array_list_pt sub_ep_list;
+ celix_thread_t recv_thread;
+ bool running;
+ celix_thread_mutex_t ts_lock;
+ bundle_context_pt context;
+
+ pubsub_serializer_service_t *serializer;
+
+ hash_map_pt servicesMap; // key = service, value = msg types map
+
+ celix_thread_mutex_t pendingConnections_lock;
+ array_list_pt pendingConnections;
+
+ array_list_pt pendingDisconnections;
+ celix_thread_mutex_t pendingDisconnections_lock;
+
+ unsigned int nrSubscribers;
+};
+
+typedef struct complete_zmq_msg{
+ zframe_t* header;
+ zframe_t* payload;
+}* complete_zmq_msg_pt;
+
+typedef struct mp_handle{
+ hash_map_pt svc_msg_db;
+ hash_map_pt rcv_msg_map;
+}* mp_handle_pt;
+
+typedef struct msg_map_entry{
+ bool retain;
+ void* msgInst;
+}* msg_map_entry_pt;
+
+static celix_status_t topicsub_subscriberTracked(void * handle, service_reference_pt reference, void * service);
+static celix_status_t topicsub_subscriberUntracked(void * handle, service_reference_pt reference, void * service);
+static void* zmq_recv_thread_func(void* arg);
+static bool checkVersion(version_pt msgVersion,pubsub_msg_header_pt hdr);
+static void sigusr1_sighandler(int signo);
+static int pubsub_localMsgTypeIdForMsgType(void* handle, const char* msgType, unsigned int* msgTypeId);
+static int pubsub_getMultipart(void *handle, unsigned int msgTypeId, bool retain, void **part);
+static mp_handle_pt create_mp_handle(hash_map_pt svc_msg_db,array_list_pt rcv_msg_list);
+static void destroy_mp_handle(mp_handle_pt mp_handle);
+static void connectPendingPublishers(topic_subscription_pt sub);
+static void disconnectPendingPublishers(topic_subscription_pt sub);
+
+celix_status_t pubsub_topicSubscriptionCreate(bundle_context_pt bundle_context, char* scope, char* topic, pubsub_serializer_service_t *best_serializer, topic_subscription_pt* out){
+ celix_status_t status = CELIX_SUCCESS;
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ char* keys_bundle_dir = pubsub_getKeysBundleDir(bundle_context);
+ if (keys_bundle_dir == NULL){
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+ const char* keys_file_path = NULL;
+ const char* keys_file_name = NULL;
+ bundleContext_getProperty(bundle_context, PROPERTY_KEYS_FILE_PATH, &keys_file_path);
+ bundleContext_getProperty(bundle_context, PROPERTY_KEYS_FILE_NAME, &keys_file_name);
+
+ char sub_cert_path[MAX_CERT_PATH_LENGTH];
+ char pub_cert_path[MAX_CERT_PATH_LENGTH];
+
+ //certificate path ".cache/bundle{id}/version0.0/./META-INF/keys/subscriber/private/sub_{topic}.key.enc"
+ snprintf(sub_cert_path, MAX_CERT_PATH_LENGTH, "%s/META-INF/keys/subscriber/private/sub_%s.key.enc", keys_bundle_dir, topic);
+ snprintf(pub_cert_path, MAX_CERT_PATH_LENGTH, "%s/META-INF/keys/publisher/public/pub_%s.pub", keys_bundle_dir, topic);
+ free(keys_bundle_dir);
+
+ printf("PSA_ZMQ_PSA_ZMQ_TS: Loading subscriber key '%s'\n", sub_cert_path);
+ printf("PSA_ZMQ_PSA_ZMQ_TS: Loading publisher key '%s'\n", pub_cert_path);
+
+ zcert_t* sub_cert = get_zcert_from_encoded_file((char *) keys_file_path, (char *) keys_file_name, sub_cert_path);
+ if (sub_cert == NULL){
+ printf("PSA_ZMQ_PSA_ZMQ_TS: Cannot load key '%s'\n", sub_cert_path);
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+ zcert_t* pub_cert = zcert_load(pub_cert_path);
+ if (pub_cert == NULL){
+ zcert_destroy(&sub_cert);
+ printf("PSA_ZMQ_PSA_ZMQ_TS: Cannot load key '%s'\n", pub_cert_path);
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+ const char* pub_key = zcert_public_txt(pub_cert);
+#endif
+
+ zsock_t* zmq_s = zsock_new (ZMQ_SUB);
+ if(zmq_s==NULL){
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ zcert_destroy(&sub_cert);
+ zcert_destroy(&pub_cert);
+#endif
+
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ zcert_apply (sub_cert, zmq_s);
+ zsock_set_curve_serverkey (zmq_s, pub_key); //apply key of publisher to socket of subscriber
+#endif
+
+ if(strcmp(topic,PUBSUB_ANY_SUB_TOPIC)==0){
+ zsock_set_subscribe (zmq_s, "");
+ }
+ else{
+ zsock_set_subscribe (zmq_s, topic);
+ }
+
+ topic_subscription_pt ts = (topic_subscription_pt) calloc(1,sizeof(*ts));
+ ts->context = bundle_context;
+ ts->zmq_socket = zmq_s;
+ ts->running = false;
+ ts->nrSubscribers = 0;
+ ts->serializer = best_serializer;
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ ts->zmq_cert = sub_cert;
+ ts->zmq_pub_cert = pub_cert;
+#endif
+
+ celixThreadMutex_create(&ts->socket_lock, NULL);
+ celixThreadMutex_create(&ts->ts_lock,NULL);
+ arrayList_create(&ts->sub_ep_list);
+ ts->servicesMap = hashMap_create(NULL, NULL, NULL, NULL);
+
+ arrayList_create(&ts->pendingConnections);
+ arrayList_create(&ts->pendingDisconnections);
+ celixThreadMutex_create(&ts->pendingConnections_lock, NULL);
+ celixThreadMutex_create(&ts->pendingDisconnections_lock, NULL);
+
+ char filter[128];
+ memset(filter,0,128);
+ if(strncmp(PUBSUB_SUBSCRIBER_SCOPE_DEFAULT,scope,strlen(PUBSUB_SUBSCRIBER_SCOPE_DEFAULT)) == 0) {
+ // default scope, means that subscriber has not defined a scope property
+ snprintf(filter, 128, "(&(%s=%s)(%s=%s))",
+ (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_SUBSCRIBER_SERVICE_NAME,
+ PUBSUB_SUBSCRIBER_TOPIC,topic);
+
+ } else {
+ snprintf(filter, 128, "(&(%s=%s)(%s=%s)(%s=%s))",
+ (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_SUBSCRIBER_SERVICE_NAME,
+ PUBSUB_SUBSCRIBER_TOPIC,topic,
+ PUBSUB_SUBSCRIBER_SCOPE,scope);
+ }
+ service_tracker_customizer_pt customizer = NULL;
+ status += serviceTrackerCustomizer_create(ts,NULL,topicsub_subscriberTracked,NULL,topicsub_subscriberUntracked,&customizer);
+ status += serviceTracker_createWithFilter(bundle_context, filter, customizer, &ts->tracker);
+
+ struct sigaction actions;
+ memset(&actions, 0, sizeof(actions));
+ sigemptyset(&actions.sa_mask);
+ actions.sa_flags = 0;
+ actions.sa_handler = sigusr1_sighandler;
+
+ sigaction(SIGUSR1,&actions,NULL);
+
+ *out=ts;
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionDestroy(topic_subscription_pt ts){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+
+ ts->running = false;
+ serviceTracker_destroy(ts->tracker);
+ arrayList_clear(ts->sub_ep_list);
+ arrayList_destroy(ts->sub_ep_list);
+ /* TODO: Destroy all the serializer maps? */
+ hashMap_destroy(ts->servicesMap,false,false);
+
+ celixThreadMutex_lock(&ts->pendingConnections_lock);
+ arrayList_destroy(ts->pendingConnections);
+ celixThreadMutex_unlock(&ts->pendingConnections_lock);
+ celixThreadMutex_destroy(&ts->pendingConnections_lock);
+
+ celixThreadMutex_lock(&ts->pendingDisconnections_lock);
+ arrayList_destroy(ts->pendingDisconnections);
+ celixThreadMutex_unlock(&ts->pendingDisconnections_lock);
+ celixThreadMutex_destroy(&ts->pendingDisconnections_lock);
+
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ celixThreadMutex_lock(&ts->socket_lock);
+ zsock_destroy(&(ts->zmq_socket));
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ zcert_destroy(&(ts->zmq_cert));
+ zcert_destroy(&(ts->zmq_pub_cert));
+#endif
+ celixThreadMutex_unlock(&ts->socket_lock);
+ celixThreadMutex_destroy(&ts->socket_lock);
+
+ celixThreadMutex_destroy(&ts->ts_lock);
+
+ free(ts);
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionStart(topic_subscription_pt ts){
+ celix_status_t status = CELIX_SUCCESS;
+
+ status = serviceTracker_open(ts->tracker);
+
+ ts->running = true;
+
+ if(status==CELIX_SUCCESS){
+ status=celixThread_create(&ts->recv_thread,NULL,zmq_recv_thread_func,ts);
+ }
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionStop(topic_subscription_pt ts){
+ celix_status_t status = CELIX_SUCCESS;
+
+ ts->running = false;
+
+ pthread_kill(ts->recv_thread.thread,SIGUSR1);
+
+ celixThread_join(ts->recv_thread,NULL);
+
+ status = serviceTracker_close(ts->tracker);
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionConnectPublisher(topic_subscription_pt ts, char* pubURL){
+ celix_status_t status = CELIX_SUCCESS;
+ celixThreadMutex_lock(&ts->socket_lock);
+ if(!zsock_is(ts->zmq_socket) || zsock_connect(ts->zmq_socket,"%s",pubURL) != 0){
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ celixThreadMutex_unlock(&ts->socket_lock);
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionAddConnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL) {
+ celix_status_t status = CELIX_SUCCESS;
+ char *url = strdup(pubURL);
+ celixThreadMutex_lock(&ts->pendingConnections_lock);
+ arrayList_add(ts->pendingConnections, url);
+ celixThreadMutex_unlock(&ts->pendingConnections_lock);
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL) {
+ celix_status_t status = CELIX_SUCCESS;
+ char *url = strdup(pubURL);
+ celixThreadMutex_lock(&ts->pendingDisconnections_lock);
+ arrayList_add(ts->pendingDisconnections, url);
+ celixThreadMutex_unlock(&ts->pendingDisconnections_lock);
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionDisconnectPublisher(topic_subscription_pt ts, char* pubURL){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->socket_lock);
+ if(!zsock_is(ts->zmq_socket) || zsock_disconnect(ts->zmq_socket,"%s",pubURL) != 0){
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ celixThreadMutex_unlock(&ts->socket_lock);
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionAddSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ arrayList_add(ts->sub_ep_list,subEP);
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+
+}
+
+celix_status_t pubsub_topicIncreaseNrSubscribers(topic_subscription_pt ts) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ ts->nrSubscribers++;
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionRemoveSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ arrayList_removeElement(ts->sub_ep_list,subEP);
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+}
+
+celix_status_t pubsub_topicDecreaseNrSubscribers(topic_subscription_pt ts) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ ts->nrSubscribers--;
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+}
+
+unsigned int pubsub_topicGetNrSubscribers(topic_subscription_pt ts) {
+ return ts->nrSubscribers;
+}
+
+array_list_pt pubsub_topicSubscriptionGetSubscribersList(topic_subscription_pt sub){
+ return sub->sub_ep_list;
+}
+
+static celix_status_t topicsub_subscriberTracked(void * handle, service_reference_pt reference, void * service){
+ celix_status_t status = CELIX_SUCCESS;
+ topic_subscription_pt ts = handle;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ if (!hashMap_containsKey(ts->servicesMap, service)) {
+ bundle_pt bundle = NULL;
+ hash_map_pt msgTypes = NULL;
+
+ serviceReference_getBundle(reference, &bundle);
+
+ if(ts->serializer != NULL && bundle!=NULL){
+ ts->serializer->createSerializerMap(ts->serializer->handle,bundle,&msgTypes);
+ if(msgTypes != NULL){
+ hashMap_put(ts->servicesMap, service, msgTypes);
+ printf("PSA_ZMQ_TS: New subscriber registered.\n");
+ }
+ }
+ else{
+ printf("PSA_ZMQ_TS: Cannot register new subscriber.\n");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ }
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+}
+
+static celix_status_t topicsub_subscriberUntracked(void * handle, service_reference_pt reference, void * service){
+ celix_status_t status = CELIX_SUCCESS;
+ topic_subscription_pt ts = handle;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ if (hashMap_containsKey(ts->servicesMap, service)) {
+ hash_map_pt msgTypes = hashMap_remove(ts->servicesMap, service);
+ if(msgTypes!=NULL && ts->serializer!=NULL){
+ ts->serializer->destroySerializerMap(ts->serializer->handle,msgTypes);
+ printf("PSA_ZMQ_TS: Subscriber unregistered.\n");
+ }
+ else{
+ printf("PSA_ZMQ_TS: Cannot unregister subscriber.\n");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ }
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+}
+
+
+static void process_msg(topic_subscription_pt sub,array_list_pt msg_list){
+
+ pubsub_msg_header_pt first_msg_hdr = (pubsub_msg_header_pt)zframe_data(((complete_zmq_msg_pt)arrayList_get(msg_list,0))->header);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(sub->servicesMap);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ pubsub_subscriber_pt subsvc = hashMapEntry_getKey(entry);
+ hash_map_pt msgTypes = hashMapEntry_getValue(entry);
+
+ pubsub_msg_serializer_t *msgSer = hashMap_get(msgTypes,(void*)(uintptr_t )first_msg_hdr->type);
+ if (msgSer == NULL) {
+ printf("PSA_ZMQ_TS: Primary message %d not supported. NOT sending any part of the whole message.\n",first_msg_hdr->type);
+ }
+ else{
+ void *msgInst = NULL;
+ bool validVersion = checkVersion(msgSer->msgVersion,first_msg_hdr);
+
+ if(validVersion){
+
+ celix_status_t status = msgSer->deserialize(msgSer, (const void *) zframe_data(((complete_zmq_msg_pt)arrayList_get(msg_list,0))->payload), 0, &msgInst);
+
+ if (status == CELIX_SUCCESS) {
+ bool release = true;
+ mp_handle_pt mp_handle = create_mp_handle(msgTypes,msg_list);
+ pubsub_multipart_callbacks_t mp_callbacks;
+ mp_callbacks.handle = mp_handle;
+ mp_callbacks.localMsgTypeIdForMsgType = pubsub_localMsgTypeIdForMsgType;
+ mp_callbacks.getMultipart = pubsub_getMultipart;
+ subsvc->receive(subsvc->handle, msgSer->msgName, first_msg_hdr->type, msgInst, &mp_callbacks, &release);
+
+ if(release){
+ msgSer->freeMsg(msgSer,msgInst); // pubsubSerializer_freeMsg(msgType, msgInst);
+ }
+ if(mp_handle!=NULL){
+ destroy_mp_handle(mp_handle);
+ }
+ }
+ else{
+ printf("PSA_ZMQ_TS: Cannot deserialize msgType %s.\n",msgSer->msgName);
+ }
+
+ }
+ else{
+ int major=0,minor=0;
+ version_getMajor(msgSer->msgVersion,&major);
+ version_getMinor(msgSer->msgVersion,&minor);
+ printf("PSA_ZMQ_TS: Version mismatch for primary message '%s' (have %d.%d, received %u.%u). NOT sending any part of the whole message.\n",
+ msgSer->msgName,major,minor,first_msg_hdr->major,first_msg_hdr->minor);
+ }
+
+ }
+ }
+ hashMapIterator_destroy(iter);
+
+ int i = 0;
+ for(;i<arrayList_size(msg_list);i++){
+ complete_zmq_msg_pt c_msg = arrayList_get(msg_list,i);
+ zframe_destroy(&(c_msg->header));
+ zframe_destroy(&(c_msg->payload));
+ free(c_msg);
+ }
+
+ arrayList_destroy(msg_list);
+
+}
+
+static void* zmq_recv_thread_func(void * arg) {
+ topic_subscription_pt sub = (topic_subscription_pt) arg;
+
+ while (sub->running) {
+
+ celixThreadMutex_lock(&sub->socket_lock);
+
+ zframe_t* headerMsg = zframe_recv(sub->zmq_socket);
+ if (headerMsg == NULL) {
+ if (errno == EINTR) {
+ //It means we got a signal and we have to exit...
+ printf("PSA_ZMQ_TS: header_recv thread for topic got a signal and will exit.\n");
+ } else {
+ perror("PSA_ZMQ_TS: header_recv thread");
+ }
+ }
+ else {
+
+ pubsub_msg_header_pt hdr = (pubsub_msg_header_pt) zframe_data(headerMsg);
+
+ if (zframe_more(headerMsg)) {
+
+ zframe_t* payloadMsg = zframe_recv(sub->zmq_socket);
+ if (payloadMsg == NULL) {
+ if (errno == EINTR) {
+ //It means we got a signal and we have to exit...
+ printf("PSA_ZMQ_TS: payload_recv thread for topic got a signal and will exit.\n");
+ } else {
+ perror("PSA_ZMQ_TS: payload_recv");
+ }
+ zframe_destroy(&headerMsg);
+ } else {
+
+ //Let's fetch all the messages from the socket
+ array_list_pt msg_list = NULL;
+ arrayList_create(&msg_list);
+ complete_zmq_msg_pt firstMsg = calloc(1, sizeof(struct complete_zmq_msg));
+ firstMsg->header = headerMsg;
+ firstMsg->payload = payloadMsg;
+ arrayList_add(msg_list, firstMsg);
+
+ bool more = zframe_more(payloadMsg);
+ while (more) {
+
+ zframe_t* h_msg = zframe_recv(sub->zmq_socket);
+ if (h_msg == NULL) {
+ if (errno == EINTR) {
+ //It means we got a signal and we have to exit...
+ printf("PSA_ZMQ_TS: h_recv thread for topic got a signal and will exit.\n");
+ } else {
+ perror("PSA_ZMQ_TS: h_recv");
+ }
+ break;
+ }
+
+ zframe_t* p_msg = zframe_recv(sub->zmq_socket);
+ if (p_msg == NULL) {
+ if (errno == EINTR) {
+ //It means we got a signal and we have to exit...
+ printf("PSA_ZMQ_TS: p_recv thread for topic got a signal and will exit.\n");
+ } else {
+ perror("PSA_ZMQ_TS: p_recv");
+ }
+ zframe_destroy(&h_msg);
+ break;
+ }
+
+ complete_zmq_msg_pt c_msg = calloc(1, sizeof(struct complete_zmq_msg));
+ c_msg->header = h_msg;
+ c_msg->payload = p_msg;
+ arrayList_add(msg_list, c_msg);
+
+ if (!zframe_more(p_msg)) {
+ more = false;
+ }
+ }
+
+ celixThreadMutex_lock(&sub->ts_lock);
+ process_msg(sub, msg_list);
+ celixThreadMutex_unlock(&sub->ts_lock);
+
+ }
+
+ } //zframe_more(headerMsg)
+ else {
+ free(headerMsg);
+ printf("PSA_ZMQ_TS: received message %u for topic %s without payload!\n", hdr->type, hdr->topic);
+ }
+
+ } // headerMsg != NULL
+ celixThreadMutex_unlock(&sub->socket_lock);
+ connectPendingPublishers(sub);
+ disconnectPendingPublishers(sub);
+ } // while
+
+ return NULL;
+}
+
+static void connectPendingPublishers(topic_subscription_pt sub) {
+ celixThreadMutex_lock(&sub->pendingConnections_lock);
+ while(!arrayList_isEmpty(sub->pendingConnections)) {
+ char * pubEP = arrayList_remove(sub->pendingConnections, 0);
+ pubsub_topicSubscriptionConnectPublisher(sub, pubEP);
+ free(pubEP);
+ }
+ celixThreadMutex_unlock(&sub->pendingConnections_lock);
+}
+
+static void disconnectPendingPublishers(topic_subscription_pt sub) {
+ celixThreadMutex_lock(&sub->pendingDisconnections_lock);
+ while(!arrayList_isEmpty(sub->pendingDisconnections)) {
+ char * pubEP = arrayList_remove(sub->pendingDisconnections, 0);
+ pubsub_topicSubscriptionDisconnectPublisher(sub, pubEP);
+ free(pubEP);
+ }
+ celixThreadMutex_unlock(&sub->pendingDisconnections_lock);
+}
+
+static void sigusr1_sighandler(int signo){
+ printf("PSA_ZMQ_TS: Topic subscription being shut down...\n");
+ return;
+}
+
+static bool checkVersion(version_pt msgVersion,pubsub_msg_header_pt hdr){
+ bool check=false;
+ int major=0,minor=0;
+
+ if(msgVersion!=NULL){
+ version_getMajor(msgVersion,&major);
+ version_getMinor(msgVersion,&minor);
+ if(hdr->major==((unsigned char)major)){ /* Different major means incompatible */
+ check = (hdr->minor>=((unsigned char)minor)); /* Compatible only if the provider has a minor equals or greater (means compatible update) */
+ }
+ }
+
+ return check;
+}
+
+static int pubsub_localMsgTypeIdForMsgType(void* handle, const char* msgType, unsigned int* msgTypeId){
+ *msgTypeId = utils_stringHash(msgType);
+ return 0;
+}
+
+static int pubsub_getMultipart(void *handle, unsigned int msgTypeId, bool retain, void **part){
+
+ if(handle==NULL){
+ *part = NULL;
+ return -1;
+ }
+
+ mp_handle_pt mp_handle = (mp_handle_pt)handle;
+ msg_map_entry_pt entry = hashMap_get(mp_handle->rcv_msg_map, (void*)(uintptr_t) msgTypeId);
+ if(entry!=NULL){
+ entry->retain = retain;
+ *part = entry->msgInst;
+ }
+ else{
+ printf("TP: getMultipart cannot find msg '%u'\n",msgTypeId);
+ *part=NULL;
+ return -2;
+ }
+
+ return 0;
+
+}
+
+static mp_handle_pt create_mp_handle(hash_map_pt svc_msg_db,array_list_pt rcv_msg_list){
+
+ if(arrayList_size(rcv_msg_list)==1){ //Means it's not a multipart message
+ return NULL;
+ }
+
+ mp_handle_pt mp_handle = calloc(1,sizeof(struct mp_handle));
+ mp_handle->svc_msg_db = svc_msg_db;
+ mp_handle->rcv_msg_map = hashMap_create(NULL, NULL, NULL, NULL);
+
+ int i=1; //We skip the first message, it will be handle differently
+ for(;i<arrayList_size(rcv_msg_list);i++){
+ complete_zmq_msg_pt c_msg = (complete_zmq_msg_pt)arrayList_get(rcv_msg_list,i);
+ pubsub_msg_header_pt header = (pubsub_msg_header_pt)zframe_data(c_msg->header);
+
+ pubsub_msg_serializer_t* msgSer = hashMap_get(svc_msg_db, (void*)(uintptr_t)(header->type));
+
+ if (msgSer!= NULL) {
+ void *msgInst = NULL;
+
+ bool validVersion = checkVersion(msgSer->msgVersion,header);
+
+ if(validVersion){
+ celix_status_t status = msgSer->deserialize(msgSer, (const void*)zframe_data(c_msg->payload), 0, &msgInst);
+
+ if(status == CELIX_SUCCESS){
+ msg_map_entry_pt entry = calloc(1,sizeof(struct msg_map_entry));
+ entry->msgInst = msgInst;
+ hashMap_put(mp_handle->rcv_msg_map, (void*)(uintptr_t)header->type,entry);
+ }
+ }
+ }
+ }
+
+ return mp_handle;
+
+}
+
+static void destroy_mp_handle(mp_handle_pt mp_handle){
+
+ hash_map_iterator_pt iter = hashMapIterator_create(mp_handle->rcv_msg_map);
+ while(hashMapIterator_hasNext(iter)){
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ unsigned int msgId = (unsigned int)(uintptr_t)hashMapEntry_getKey(entry);
+ msg_map_entry_pt msgEntry = hashMapEntry_getValue(entry);
+ pubsub_msg_serializer_t* msgSer = hashMap_get(mp_handle->svc_msg_db, (void*)(uintptr_t)msgId);
+
+ if(msgSer!=NULL){
+ if(!msgEntry->retain){
+ msgSer->freeMsg(msgSer->handle,msgEntry->msgInst);
+ }
+ }
+ else{
+ printf("PSA_ZMQ_TS: ERROR: Cannot find messageSerializer for msg %u, so cannot destroy it!\n",msgId);
+ }
+
+ free(msgEntry);
+ }
+ hashMapIterator_destroy(iter);
+
+ hashMap_destroy(mp_handle->rcv_msg_map,false,false);
+ free(mp_handle);
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/src/topic_subscription.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/src/topic_subscription.h b/pubsub/pubsub_admin_zmq/src/topic_subscription.h
new file mode 100644
index 0000000..7267103
--- /dev/null
+++ b/pubsub/pubsub_admin_zmq/src/topic_subscription.h
@@ -0,0 +1,60 @@
+/**
+ *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.
+ */
+/*
+ * topic_subscription.h
+ *
+ * \date Sep 22, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef TOPIC_SUBSCRIPTION_H_
+#define TOPIC_SUBSCRIPTION_H_
+
+#include "celix_threads.h"
+#include "array_list.h"
+#include "celixbool.h"
+#include "service_tracker.h"
+
+#include "pubsub_endpoint.h"
+#include "pubsub_common.h"
+#include "pubsub_serializer.h"
+
+typedef struct topic_subscription* topic_subscription_pt;
+
+celix_status_t pubsub_topicSubscriptionCreate(bundle_context_pt bundle_context,char* scope, char* topic, pubsub_serializer_service_t *best_serializer, topic_subscription_pt* out);
+celix_status_t pubsub_topicSubscriptionDestroy(topic_subscription_pt ts);
+celix_status_t pubsub_topicSubscriptionStart(topic_subscription_pt ts);
+celix_status_t pubsub_topicSubscriptionStop(topic_subscription_pt ts);
+
+celix_status_t pubsub_topicSubscriptionAddConnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL);
+celix_status_t pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL);
+
+celix_status_t pubsub_topicSubscriptionConnectPublisher(topic_subscription_pt ts, char* pubURL);
+celix_status_t pubsub_topicSubscriptionDisconnectPublisher(topic_subscription_pt ts, char* pubURL);
+
+celix_status_t pubsub_topicSubscriptionAddSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP);
+celix_status_t pubsub_topicSubscriptionRemoveSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP);
+
+array_list_pt pubsub_topicSubscriptionGetSubscribersList(topic_subscription_pt sub);
+celix_status_t pubsub_topicIncreaseNrSubscribers(topic_subscription_pt subscription);
+celix_status_t pubsub_topicDecreaseNrSubscribers(topic_subscription_pt subscription);
+unsigned int pubsub_topicGetNrSubscribers(topic_subscription_pt subscription);
+
+#endif /*TOPIC_SUBSCRIPTION_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/src/zmq_crypto.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/src/zmq_crypto.c b/pubsub/pubsub_admin_zmq/src/zmq_crypto.c
new file mode 100644
index 0000000..fe444bd
--- /dev/null
+++ b/pubsub/pubsub_admin_zmq/src/zmq_crypto.c
@@ -0,0 +1,281 @@
+/**
+ *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.
+ */
+/*
+ * zmq_crypto.c
+ *
+ * \date Dec 2, 2016
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include "zmq_crypto.h"
+
+#include <zmq.h>
+#include <openssl/conf.h>
+#include <openssl/evp.h>
+#include <openssl/err.h>
+
+#include <string.h>
+
+#define MAX_FILE_PATH_LENGTH 512
+#define ZMQ_KEY_LENGTH 40
+#define AES_KEY_LENGTH 32
+#define AES_IV_LENGTH 16
+
+#define KEY_TO_GET "aes_key"
+#define IV_TO_GET "aes_iv"
+
+static char* read_file_content(char* filePath, char* fileName);
+static void parse_key_lines(char *keysBuffer, char **key, char **iv);
+static void parse_key_line(char *line, char **key, char **iv);
+static void extract_keys_from_buffer(unsigned char *input, int inputlen, char **publicKey, char **secretKey);
+
+/**
+ * Return a valid zcert_t from an encoded file
+ * Caller is responsible for freeing by calling zcert_destroy(zcert** cert);
+ */
+zcert_t* get_zcert_from_encoded_file(char* keysFilePath, char* keysFileName, char* file_path)
+{
+
+ if (keysFilePath == NULL){
+ keysFilePath = DEFAULT_KEYS_FILE_PATH;
+ }
+
+ if (keysFileName == NULL){
+ keysFileName = DEFAULT_KEYS_FILE_NAME;
+ }
+
+ char* keys_data = read_file_content(keysFilePath, keysFileName);
+ if (keys_data == NULL){
+ return NULL;
+ }
+
+ char *key = NULL;
+ char *iv = NULL;
+ parse_key_lines(keys_data, &key, &iv);
+ free(keys_data);
+
+ if (key == NULL || iv == NULL){
+ free(key);
+ free(iv);
+
+ printf("CRYPTO: Loading AES key and/or AES iv failed!\n");
+ return NULL;
+ }
+
+ //At this point, we know an aes key and iv are stored and loaded
+
+ // generate sha256 hashes
+ unsigned char key_digest[EVP_MAX_MD_SIZE];
+ unsigned char iv_digest[EVP_MAX_MD_SIZE];
+ generate_sha256_hash((char*) key, key_digest);
+ generate_sha256_hash((char*) iv, iv_digest);
+
+ zchunk_t* encoded_secret = zchunk_slurp (file_path, 0);
+ if (encoded_secret == NULL){
+ free(key);
+ free(iv);
+
+ return NULL;
+ }
+
+ int encoded_secret_size = (int) zchunk_size (encoded_secret);
+ char* encoded_secret_data = zchunk_strdup(encoded_secret);
+ zchunk_destroy (&encoded_secret);
+
+ // Decryption of data
+ int decryptedtext_len;
+ unsigned char decryptedtext[encoded_secret_size];
+ decryptedtext_len = decrypt((unsigned char *) encoded_secret_data, encoded_secret_size, key_digest, iv_digest, decryptedtext);
+ decryptedtext[decryptedtext_len] = '\0';
+
+ EVP_cleanup();
+
+ free(encoded_secret_data);
+ free(key);
+ free(iv);
+
+ // The public and private keys are retrieved
+ char* public_text = NULL;
+ char* secret_text = NULL;
+
+ extract_keys_from_buffer(decryptedtext, decryptedtext_len, &public_text, &secret_text);
+
+ byte public_key [32] = { 0 };
+ byte secret_key [32] = { 0 };
+
+ zmq_z85_decode (public_key, public_text);
+ zmq_z85_decode (secret_key, secret_text);
+
+ zcert_t* cert_loaded = zcert_new_from(public_key, secret_key);
+
+ free(public_text);
+ free(secret_text);
+
+ return cert_loaded;
+}
+
+int generate_sha256_hash(char* text, unsigned char* digest)
+{
+ unsigned int digest_len;
+
+ EVP_MD_CTX * mdctx = EVP_MD_CTX_new();
+ EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL);
+ EVP_DigestUpdate(mdctx, text, strlen(text));
+ EVP_DigestFinal_ex(mdctx, digest, &digest_len);
+ EVP_MD_CTX_free(mdctx);
+
+ return digest_len;
+}
+
+int decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, unsigned char *iv, unsigned char *plaintext)
+{
+ int len;
+ int plaintext_len;
+
+ EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
+
+ EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv);
+ EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len);
+ plaintext_len = len;
+ EVP_DecryptFinal_ex(ctx, plaintext + len, &len);
+ plaintext_len += len;
+
+ EVP_CIPHER_CTX_free(ctx);
+
+ return plaintext_len;
+}
+
+/**
+ * Caller is responsible for freeing the returned value
+ */
+static char* read_file_content(char* filePath, char* fileName){
+
+ char fileNameWithPath[MAX_FILE_PATH_LENGTH];
+ snprintf(fileNameWithPath, MAX_FILE_PATH_LENGTH, "%s/%s", filePath, fileName);
+ int rc = 0;
+
+ if (!zsys_file_exists(fileNameWithPath)){
+ printf("CRYPTO: Keys file '%s' doesn't exist!\n", fileNameWithPath);
+ return NULL;
+ }
+
+ zfile_t* keys_file = zfile_new (filePath, fileName);
+ rc = zfile_input (keys_file);
+ if (rc != 0){
+ zfile_destroy(&keys_file);
+ printf("CRYPTO: Keys file '%s' not readable!\n", fileNameWithPath);
+ return NULL;
+ }
+
+ ssize_t keys_file_size = zsys_file_size (fileNameWithPath);
+ zchunk_t* keys_chunk = zfile_read (keys_file, keys_file_size, 0);
+ if (keys_chunk == NULL){
+ zfile_close(keys_file);
+ zfile_destroy(&keys_file);
+ printf("CRYPTO: Can't read file '%s'!\n", fileNameWithPath);
+ return NULL;
+ }
+
+ char* keys_data = zchunk_strdup(keys_chunk);
+ zchunk_destroy(&keys_chunk);
+ zfile_close(keys_file);
+ zfile_destroy (&keys_file);
+
+ return keys_data;
+}
+
+static void parse_key_lines(char *keysBuffer, char **key, char **iv){
+ char *line = NULL, *saveLinePointer = NULL;
+
+ bool firstTime = true;
+ do {
+ if (firstTime){
+ line = strtok_r(keysBuffer, "\n", &saveLinePointer);
+ firstTime = false;
+ }else {
+ line = strtok_r(NULL, "\n", &saveLinePointer);
+ }
+
+ if (line == NULL){
+ break;
+ }
+
+ parse_key_line(line, key, iv);
+
+ } while((*key == NULL || *iv == NULL) && line != NULL);
+
+}
+
+static void parse_key_line(char *line, char **key, char **iv){
+ char *detectedKey = NULL, *detectedValue= NULL;
+
+ char* sep_at = strchr(line, ':');
+ if (sep_at == NULL){
+ return;
+ }
+
+ *sep_at = '\0'; // overwrite first separator, creating two strings.
+ detectedKey = line;
+ detectedValue = sep_at + 1;
+
+ if (detectedKey == NULL || detectedValue == NULL){
+ return;
+ }
+ if (detectedKey[0] == '\0' || detectedValue[0] == '\0'){
+ return;
+ }
+
+ if (*key == NULL && strcmp(detectedKey, KEY_TO_GET) == 0){
+ *key = strndup(detectedValue, AES_KEY_LENGTH);
+ } else if (*iv == NULL && strcmp(detectedKey, IV_TO_GET) == 0){
+ *iv = strndup(detectedValue, AES_IV_LENGTH);
+ }
+}
+
+static void extract_keys_from_buffer(unsigned char *input, int inputlen, char **publicKey, char **secretKey) {
+ // Load decrypted text buffer
+ zchunk_t* secret_decrypted = zchunk_new(input, inputlen);
+ if (secret_decrypted == NULL){
+ printf("CRYPTO: Failed to create zchunk\n");
+ return;
+ }
+
+ zconfig_t* secret_config = zconfig_chunk_load (secret_decrypted);
+ zchunk_destroy (&secret_decrypted);
+ if (secret_config == NULL){
+ printf("CRYPTO: Failed to create zconfig\n");
+ return;
+ }
+
+ // Extract public and secret key from text buffer
+ char* public_text = zconfig_get (secret_config, "/curve/public-key", NULL);
+ char* secret_text = zconfig_get (secret_config, "/curve/secret-key", NULL);
+
+ if (public_text == NULL || secret_text == NULL){
+ zconfig_destroy(&secret_config);
+ printf("CRYPTO: Loading public / secret key from text-buffer failed!\n");
+ return;
+ }
+
+ *publicKey = strndup(public_text, ZMQ_KEY_LENGTH + 1);
+ *secretKey = strndup(secret_text, ZMQ_KEY_LENGTH + 1);
+
+ zconfig_destroy(&secret_config);
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_admin_zmq/src/zmq_crypto.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/src/zmq_crypto.h b/pubsub/pubsub_admin_zmq/src/zmq_crypto.h
new file mode 100644
index 0000000..f1a990f
--- /dev/null
+++ b/pubsub/pubsub_admin_zmq/src/zmq_crypto.h
@@ -0,0 +1,41 @@
+/**
+ *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.
+ */
+/*
+ * zmq_crypto.h
+ *
+ * \date Dec 2, 2016
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef ZMQ_CRYPTO_H_
+#define ZMQ_CRYPTO_H_
+
+#include <czmq.h>
+
+#define PROPERTY_KEYS_FILE_PATH "keys.file.path"
+#define PROPERTY_KEYS_FILE_NAME "keys.file.name"
+#define DEFAULT_KEYS_FILE_PATH "/etc/"
+#define DEFAULT_KEYS_FILE_NAME "pubsub.keys"
+
+zcert_t* get_zcert_from_encoded_file(char* keysFilePath, char* keysFileName, char* file_path);
+int generate_sha256_hash(char* text, unsigned char* digest);
+int decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, unsigned char *iv, unsigned char *plaintext);
+
+#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_api/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_api/CMakeLists.txt b/pubsub/pubsub_api/CMakeLists.txt
new file mode 100644
index 0000000..5ceb291
--- /dev/null
+++ b/pubsub/pubsub_api/CMakeLists.txt
@@ -0,0 +1,32 @@
+# 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.
+
+#api target
+add_library(pubsub_api INTERFACE)
+
+target_include_directories(framework INTERFACE
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
+ $<INSTALL_INTERFACE:include/celix/pubsub>
+)
+
+#install api
+install(TARGETS pubsub_api EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT pubsub)
+install(DIRECTORY include/ DESTINATION include/celix/pubsub COMPONENT pubsub)
+
+#Setup target aliases to match external usage
+add_library(Celix::pubsub_api ALIAS pubsub_api)
+
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_api/include/pubsub/publisher.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_api/include/pubsub/publisher.h b/pubsub/pubsub_api/include/pubsub/publisher.h
new file mode 100644
index 0000000..3eec149
--- /dev/null
+++ b/pubsub/pubsub_api/include/pubsub/publisher.h
@@ -0,0 +1,88 @@
+/**
+ *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.
+ */
+/*
+ * publisher.h
+ *
+ * \date Jan 7, 2016
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef __PUBSUB_PUBLISHER_H_
+#define __PUBSUB_PUBLISHER_H_
+
+#include <stdlib.h>
+
+#define PUBSUB_PUBLISHER_SERVICE_NAME "pubsub.publisher"
+#define PUBSUB_PUBLISHER_SERVICE_VERSION "2.0.0"
+
+//properties
+#define PUBSUB_PUBLISHER_TOPIC "pubsub.topic"
+#define PUBSUB_PUBLISHER_SCOPE "pubsub.scope"
+#define PUBSUB_PUBLISHER_STRATEGY "pubsub.strategy"
+#define PUBSUB_PUBLISHER_CONFIG "pubsub.config"
+
+#define PUBSUB_PUBLISHER_SCOPE_DEFAULT "default"
+//flags
+#define PUBSUB_PUBLISHER_FIRST_MSG 01
+#define PUBSUB_PUBLISHER_PART_MSG 02
+#define PUBSUB_PUBLISHER_LAST_MSG 04
+
+struct pubsub_release_callback_struct {
+ void *handle;
+ void (*release)(char *buf, void *handle);
+};
+typedef struct pubsub_release_callback_struct pubsub_release_callback_t;
+typedef struct pubsub_release_callback_struct* pubsub_release_callback_pt;
+
+
+struct pubsub_publisher {
+ void *handle;
+
+ /**
+ * Every msg is identifiable by msg type string. Because masg type string are performance wise not preferable (string compares),
+ * a "local" (int / platform dependent) unique id will be generated runtime
+ * with use of a distributed key/value store or communication between participation parties.
+ * this is called the local message type id. This local message type id can be requested with the localMsgIdForMsgType method.
+ * When return is successful the msgTypeId is always greater than 0. (Note this can be used to specify/detect uninitialized msg type ids in the consumer code).
+ *
+ * Returns 0 on success.
+ */
+ int (*localMsgTypeIdForMsgType)(void *handle, const char *msgType, unsigned int *msgTypeId);
+
+ /**
+ * send is a async function, but the msg can be safely deleted after send returns.
+ * Returns 0 on success.
+ */
+ int (*send)(void *handle, unsigned int msgTypeId, const void *msg);
+
+
+ /**
+ * sendMultipart is a async function, but the msg can be safely deleted after send returns.
+ * The first (primary) message of a multipart message must have the flag PUBLISHER_PRIMARY_MSG
+ * The last message of a multipart message must have the flag PUBLISHER_LAST_MSG
+ * Returns 0 on success.
+ */
+ int (*sendMultipart)(void *handle, unsigned int msgTypeId, const void *msg, int flags);
+
+};
+typedef struct pubsub_publisher pubsub_publisher_t;
+typedef struct pubsub_publisher* pubsub_publisher_pt;
+
+#endif // __PUBSUB_PUBLISHER_H_
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_api/include/pubsub/subscriber.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_api/include/pubsub/subscriber.h b/pubsub/pubsub_api/include/pubsub/subscriber.h
new file mode 100644
index 0000000..5d87b8a
--- /dev/null
+++ b/pubsub/pubsub_api/include/pubsub/subscriber.h
@@ -0,0 +1,75 @@
+/**
+ *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.
+ */
+/*
+ * subscriber.h
+ *
+ * \date Jan 7, 2016
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef __PUBSUB_SUBSCRIBER_H_
+#define __PUBSUB_SUBSCRIBER_H_
+
+#include <stdbool.h>
+
+#define PUBSUB_SUBSCRIBER_SERVICE_NAME "pubsub.subscriber"
+#define PUBSUB_SUBSCRIBER_SERVICE_VERSION "2.0.0"
+
+//properties
+#define PUBSUB_SUBSCRIBER_TOPIC "pubsub.topic"
+#define PUBSUB_SUBSCRIBER_SCOPE "pubsub.scope"
+#define PUBSUB_SUBSCRIBER_STRATEGY "pubsub.strategy"
+#define PUBSUB_SUBSCRIBER_CONFIG "pubsub.config"
+
+#define PUBSUB_SUBSCRIBER_SCOPE_DEFAULT "default"
+
+struct pubsub_multipart_callbacks_struct {
+ void *handle;
+ int (*localMsgTypeIdForMsgType)(void *handle, const char *msgType, unsigned int *msgId);
+ int (*getMultipart)(void *handle, unsigned int msgTypeId, bool retain, void **part);
+};
+typedef struct pubsub_multipart_callbacks_struct pubsub_multipart_callbacks_t;
+typedef struct pubsub_multipart_callbacks_struct* pubsub_multipart_callbacks_pt;
+
+struct pubsub_subscriber_struct {
+ void *handle;
+
+ /**
+ * When a new message for a topic is available the receive will be called.
+ *
+ * msgType contains fully qualified name of the type and msgTypeId is a local id which presents the type for performance reasons.
+ * Release can be used to instruct the pubsubadmin to release (free) the message when receive function returns. Set it to false to take
+ * over ownership of the msg (e.g. take the responsibility to free it).
+ *
+ * The callbacks argument is only valid inside the receive function, use the getMultipart callback, with retain=true, to keep multipart messages in memory.
+ * results of the localMsgTypeIdForMsgType callback are valid during the complete lifecycle of the component, not just a single receive call.
+ *
+ * Return 0 implies a successful handling. If return is not 0, the msg will always be released by the pubsubadmin.
+ *
+ * this method can be NULL.
+ */
+ int (*receive)(void *handle, const char *msgType, unsigned int msgTypeId, void *msg, pubsub_multipart_callbacks_t *callbacks, bool *release);
+
+};
+typedef struct pubsub_subscriber_struct pubsub_subscriber_t;
+typedef struct pubsub_subscriber_struct* pubsub_subscriber_pt;
+
+
+#endif // __PUBSUB_SUBSCRIBER_H_
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_common/public/include/publisher_endpoint_announce.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_common/public/include/publisher_endpoint_announce.h b/pubsub/pubsub_common/public/include/publisher_endpoint_announce.h
deleted file mode 100644
index bd39fc0..0000000
--- a/pubsub/pubsub_common/public/include/publisher_endpoint_announce.h
+++ /dev/null
@@ -1,36 +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.
- */
-
-#ifndef PUBLISHER_ENDPOINT_ANNOUNCE_H_
-#define PUBLISHER_ENDPOINT_ANNOUNCE_H_
-
-#include "pubsub_endpoint.h"
-
-struct publisher_endpoint_announce {
- void *handle;
- celix_status_t (*announcePublisher)(void *handle, pubsub_endpoint_pt pubEP);
- celix_status_t (*removePublisher)(void *handle, pubsub_endpoint_pt pubEP);
- celix_status_t (*interestedInTopic)(void* handle, const char *scope, const char *topic);
- celix_status_t (*uninterestedInTopic)(void* handle, const char *scope, const char *topic);
-};
-
-typedef struct publisher_endpoint_announce *publisher_endpoint_announce_pt;
-
-
-#endif /* PUBLISHER_ENDPOINT_ANNOUNCE_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_common/public/include/pubsub_admin.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_common/public/include/pubsub_admin.h b/pubsub/pubsub_common/public/include/pubsub_admin.h
deleted file mode 100644
index f24d825..0000000
--- a/pubsub/pubsub_common/public/include/pubsub_admin.h
+++ /dev/null
@@ -1,72 +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.
- */
-/*
- * pubsub_admin.h
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PUBSUB_ADMIN_H_
-#define PUBSUB_ADMIN_H_
-
-#include "service_reference.h"
-
-#include "pubsub_common.h"
-#include "pubsub_endpoint.h"
-
-#define PSA_IP "PSA_IP"
-#define PSA_ITF "PSA_INTERFACE"
-#define PSA_MULTICAST_IP_PREFIX "PSA_MC_PREFIX"
-
-#define PUBSUB_ADMIN_TYPE_KEY "pubsub_admin.type"
-
-typedef struct pubsub_admin *pubsub_admin_pt;
-
-struct pubsub_admin_service {
- pubsub_admin_pt admin;
-
- celix_status_t (*addSubscription)(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
- celix_status_t (*removeSubscription)(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
-
- celix_status_t (*addPublication)(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
- celix_status_t (*removePublication)(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
-
- celix_status_t (*closeAllPublications)(pubsub_admin_pt admin,char* scope, char* topic);
- celix_status_t (*closeAllSubscriptions)(pubsub_admin_pt admin,char* scope, char* topic);
-
- /* Match principle:
- * - A full matching pubsub_admin gives 200 points
- * - A full matching serializer gives 100 points
- * - If QoS = sample
- * - fallback pubsub_admin order of selection is: udp_mc, zmq. Points allocation is 100,75.
- * - fallback serializers order of selection is: json, void. Points allocation is 30,20.
- * - If QoS = control
- * - fallback pubsub_admin order of selection is: zmq,udp_mc. Points allocation is 100,75.
- * - fallback serializers order of selection is: json, void. Points allocation is 30,20.
- * - If nothing is specified, QoS = sample is assumed, so the same score applies, just divided by two.
- *
- */
- celix_status_t (*matchEndpoint)(pubsub_admin_pt admin, pubsub_endpoint_pt endpoint, double* score);
-};
-
-typedef struct pubsub_admin_service *pubsub_admin_service_pt;
-
-#endif /* PUBSUB_ADMIN_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_common/public/include/pubsub_admin_match.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_common/public/include/pubsub_admin_match.h b/pubsub/pubsub_common/public/include/pubsub_admin_match.h
deleted file mode 100644
index e95ca7d..0000000
--- a/pubsub/pubsub_common/public/include/pubsub_admin_match.h
+++ /dev/null
@@ -1,40 +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.
- */
-
-
-#ifndef PUBSUB_ADMIN_MATCH_H_
-#define PUBSUB_ADMIN_MATCH_H_
-
-#include "celix_errno.h"
-#include "properties.h"
-#include "array_list.h"
-
-#include "pubsub_serializer.h"
-
-#define QOS_ATTRIBUTE_KEY "attribute.qos"
-#define QOS_TYPE_SAMPLE "sample" /* A.k.a. unreliable connection */
-#define QOS_TYPE_CONTROL "control" /* A.k.a. reliable connection */
-
-#define PUBSUB_ADMIN_FULL_MATCH_SCORE 200.0F
-#define SERIALIZER_FULL_MATCH_SCORE 100.0F
-
-celix_status_t pubsub_admin_match(properties_pt endpoint_props, const char *pubsub_admin_type, array_list_pt serializerList, double *score);
-celix_status_t pubsub_admin_get_best_serializer(properties_pt endpoint_props, array_list_pt serializerList, pubsub_serializer_service_t **serSvc);
-
-#endif /* PUBSUB_ADMIN_MATCH_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_common/public/include/pubsub_common.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_common/public/include/pubsub_common.h b/pubsub/pubsub_common/public/include/pubsub_common.h
deleted file mode 100644
index 5dfd8fd..0000000
--- a/pubsub/pubsub_common/public/include/pubsub_common.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.
- */
-/*
- * pubsub_common.h
- *
- * \date Sep 17, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PUBSUB_COMMON_H_
-#define PUBSUB_COMMON_H_
-
-#define PUBSUB_SERIALIZER_SERVICE "pubsub_serializer"
-#define PUBSUB_ADMIN_SERVICE "pubsub_admin"
-#define PUBSUB_DISCOVERY_SERVICE "pubsub_discovery"
-#define PUBSUB_TM_ANNOUNCE_PUBLISHER_SERVICE "pubsub_tm_announce_publisher"
-
-#define PUBSUB_ANY_SUB_TOPIC "any"
-
-#define PUBSUB_BUNDLE_ID "bundle.id"
-
-#define MAX_SCOPE_LEN 1024
-#define MAX_TOPIC_LEN 1024
-
-struct pubsub_msg_header{
- char topic[MAX_TOPIC_LEN];
- unsigned int type;
- unsigned char major;
- unsigned char minor;
-};
-
-typedef struct pubsub_msg_header* pubsub_msg_header_pt;
-
-
-#endif /* PUBSUB_COMMON_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_common/public/include/pubsub_endpoint.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_common/public/include/pubsub_endpoint.h b/pubsub/pubsub_common/public/include/pubsub_endpoint.h
deleted file mode 100644
index 8a979eb..0000000
--- a/pubsub/pubsub_common/public/include/pubsub_endpoint.h
+++ /dev/null
@@ -1,58 +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.
- */
-/*
- * pubsub_endpoint.h
- *
- * \date Sep 21, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PUBSUB_ENDPOINT_H_
-#define PUBSUB_ENDPOINT_H_
-
-#include "service_reference.h"
-#include "listener_hook_service.h"
-#include "properties.h"
-
-#include "publisher.h"
-#include "subscriber.h"
-
-struct pubsub_endpoint {
- char *frameworkUUID;
- char *scope;
- char *topic;
- long serviceID;
- char* endpoint;
- bool is_secure;
- properties_pt topic_props;
-};
-
-typedef struct pubsub_endpoint *pubsub_endpoint_pt;
-
-celix_status_t pubsubEndpoint_create(const char* fwUUID, const char* scope, const char* topic, long serviceId,const char* endpoint,properties_pt topic_props,pubsub_endpoint_pt* psEp);
-celix_status_t pubsubEndpoint_createFromServiceReference(service_reference_pt reference,pubsub_endpoint_pt* psEp, bool isPublisher);
-celix_status_t pubsubEndpoint_createFromListenerHookInfo(listener_hook_info_pt info,pubsub_endpoint_pt* psEp, bool isPublisher);
-celix_status_t pubsubEndpoint_clone(pubsub_endpoint_pt in, pubsub_endpoint_pt *out);
-celix_status_t pubsubEndpoint_destroy(pubsub_endpoint_pt psEp);
-bool pubsubEndpoint_equals(pubsub_endpoint_pt psEp1,pubsub_endpoint_pt psEp2);
-
-char *createScopeTopicKey(const char* scope, const char* topic);
-
-#endif /* PUBSUB_ENDPOINT_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_common/public/include/pubsub_serializer.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_common/public/include/pubsub_serializer.h b/pubsub/pubsub_common/public/include/pubsub_serializer.h
deleted file mode 100644
index 4489fa4..0000000
--- a/pubsub/pubsub_common/public/include/pubsub_serializer.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.
- */
-/*
- * pubsub_serializer.h
- *
- * \date Mar 24, 2017
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PUBSUB_SERIALIZER_SERVICE_H_
-#define PUBSUB_SERIALIZER_SERVICE_H_
-
-#include "service_reference.h"
-#include "hash_map.h"
-
-#include "pubsub_common.h"
-
-#define PUBSUB_SERIALIZER_TYPE_KEY "pubsub_serializer.type"
-
-/**
- * There should be a pubsub_serializer_t
- * per msg type (msg id) per bundle
- *
- * The pubsub_serializer_service can create
- * a serializer_map per bundle. Potentially using
- * the extender pattern.
- */
-
-typedef struct pubsub_msg_serializer {
- void* handle;
- unsigned int msgId;
- const char* msgName;
- version_pt msgVersion;
-
- celix_status_t (*serialize)(void* handle, const void* input, void** out, size_t* outLen);
- celix_status_t (*deserialize)(void* handle, const void* input, size_t inputLen, void** out); //note inputLen can be 0 if predefined size is not needed
- void (*freeMsg)(void* handle, void* msg);
-
-} pubsub_msg_serializer_t;
-
-typedef struct pubsub_serializer_service {
- void* handle;
-
- celix_status_t (*createSerializerMap)(void* handle, bundle_pt bundle, hash_map_pt* serializerMap);
- celix_status_t (*destroySerializerMap)(void* handle, hash_map_pt serializerMap);
-
-} pubsub_serializer_service_t;
-
-#endif /* PUBSUB_SERIALIZER_SERVICE_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_common/public/include/pubsub_topic_info.descriptor
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_common/public/include/pubsub_topic_info.descriptor b/pubsub/pubsub_common/public/include/pubsub_topic_info.descriptor
deleted file mode 100644
index c01a2fd..0000000
--- a/pubsub/pubsub_common/public/include/pubsub_topic_info.descriptor
+++ /dev/null
@@ -1,10 +0,0 @@
-:header
-type=interface
-name=pubsub_topic_info
-version=1.0.0
-:annotations
-:types
-:methods
-getParticipantsNumber(t)i=getParticipantsNumber(#am=handle;Pt#am=pre;*i)N
-getSubscribersNumber(t)i=getSubscribersNumber(#am=handle;Pt#am=pre;*i)N
-getPublishersNumber(t)i=getPublishersNumber(#am=handle;Pt#am=pre;*i)N
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_common/public/include/pubsub_utils.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_common/public/include/pubsub_utils.h b/pubsub/pubsub_common/public/include/pubsub_utils.h
deleted file mode 100644
index aff5c72..0000000
--- a/pubsub/pubsub_common/public/include/pubsub_utils.h
+++ /dev/null
@@ -1,39 +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.
- */
-/*
- * pubsub_utils.h
- *
- * \date Sep 24, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PUBSUB_UTILS_H_
-#define PUBSUB_UTILS_H_
-
-#include "bundle_context.h"
-#include "array_list.h"
-
-char* pubsub_getScopeFromFilter(char* bundle_filter);
-char* pubsub_getTopicFromFilter(char* bundle_filter);
-char* pubsub_getKeysBundleDir(bundle_context_pt ctx);
-array_list_pt pubsub_getTopicsFromString(char* string);
-
-
-#endif /* PUBSUB_UTILS_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_common/public/src/pubsub_admin_match.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_common/public/src/pubsub_admin_match.c b/pubsub/pubsub_common/public/src/pubsub_admin_match.c
deleted file mode 100644
index 2a695c1..0000000
--- a/pubsub/pubsub_common/public/src/pubsub_admin_match.c
+++ /dev/null
@@ -1,320 +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.
- */
-
-
-#include <string.h>
-#include "service_reference.h"
-
-#include "pubsub_admin.h"
-
-#include "pubsub_admin_match.h"
-
-#define KNOWN_PUBSUB_ADMIN_NUM 2
-#define KNOWN_SERIALIZER_NUM 2
-
-static char* qos_sample_pubsub_admin_prio_list[KNOWN_PUBSUB_ADMIN_NUM] = {"udp_mc","zmq"};
-static char* qos_sample_serializer_prio_list[KNOWN_SERIALIZER_NUM] = {"json","void"};
-
-static char* qos_control_pubsub_admin_prio_list[KNOWN_PUBSUB_ADMIN_NUM] = {"zmq","udp_mc"};
-static char* qos_control_serializer_prio_list[KNOWN_SERIALIZER_NUM] = {"json","void"};
-
-static double qos_pubsub_admin_score[KNOWN_PUBSUB_ADMIN_NUM] = {100.0F,75.0F};
-static double qos_serializer_score[KNOWN_SERIALIZER_NUM] = {30.0F,20.0F};
-
-static void get_serializer_type(service_reference_pt svcRef, char **serializerType);
-static void manage_service_from_reference(service_reference_pt svcRef, void **svc, bool getService);
-
-celix_status_t pubsub_admin_match(properties_pt endpoint_props, const char *pubsub_admin_type, array_list_pt serializerList, double *score){
-
- celix_status_t status = CELIX_SUCCESS;
- double final_score = 0;
- int i = 0, j = 0;
-
- const char *requested_admin_type = NULL;
- const char *requested_serializer_type = NULL;
- const char *requested_qos_type = NULL;
-
- if(endpoint_props!=NULL){
- requested_admin_type = properties_get(endpoint_props,PUBSUB_ADMIN_TYPE_KEY);
- requested_serializer_type = properties_get(endpoint_props,PUBSUB_SERIALIZER_TYPE_KEY);
- requested_qos_type = properties_get(endpoint_props,QOS_ATTRIBUTE_KEY);
- }
-
- /* Analyze the pubsub_admin */
- if(requested_admin_type != NULL){ /* We got precise specification on the pubsub_admin we want */
- if(strncmp(requested_admin_type,pubsub_admin_type,strlen(pubsub_admin_type))==0){ //Full match
- final_score += PUBSUB_ADMIN_FULL_MATCH_SCORE;
- }
- }
- else if(requested_qos_type != NULL){ /* We got QoS specification that will determine the selected PSA */
- if(strncmp(requested_qos_type,QOS_TYPE_SAMPLE,strlen(QOS_TYPE_SAMPLE))==0){
- for(i=0;i<KNOWN_PUBSUB_ADMIN_NUM;i++){
- if(strncmp(qos_sample_pubsub_admin_prio_list[i],pubsub_admin_type,strlen(pubsub_admin_type))==0){
- final_score += qos_pubsub_admin_score[i];
- break;
- }
- }
- }
- else if(strncmp(requested_qos_type,QOS_TYPE_CONTROL,strlen(QOS_TYPE_CONTROL))==0){
- for(i=0;i<KNOWN_PUBSUB_ADMIN_NUM;i++){
- if(strncmp(qos_control_pubsub_admin_prio_list[i],pubsub_admin_type,strlen(pubsub_admin_type))==0){
- final_score += qos_pubsub_admin_score[i];
- break;
- }
- }
- }
- else{
- printf("Unknown QoS type '%s'\n",requested_qos_type);
- status = CELIX_ILLEGAL_ARGUMENT;
- }
- }
- else{ /* We got no specification: fallback to Qos=Sample, but count half the score */
- for(i=0;i<KNOWN_PUBSUB_ADMIN_NUM;i++){
- if(strncmp(qos_sample_pubsub_admin_prio_list[i],pubsub_admin_type,strlen(pubsub_admin_type))==0){
- final_score += (qos_pubsub_admin_score[i]/2);
- break;
- }
- }
- }
-
- char *serializer_type = NULL;
- /* Analyze the serializers */
- if(requested_serializer_type != NULL){ /* We got precise specification on the serializer we want */
- for(i=0;i<arrayList_size(serializerList);i++){
- service_reference_pt svcRef = (service_reference_pt)arrayList_get(serializerList,i);
- get_serializer_type(svcRef, &serializer_type);
- if(serializer_type != NULL){
- if(strncmp(requested_serializer_type,serializer_type,strlen(serializer_type))==0){
- final_score += SERIALIZER_FULL_MATCH_SCORE;
- break;
- }
- }
- }
- }
- else if(requested_qos_type != NULL){ /* We got QoS specification that will determine the selected serializer */
- if(strncmp(requested_qos_type,QOS_TYPE_SAMPLE,strlen(QOS_TYPE_SAMPLE))==0){
- bool ser_found = false;
- for(i=0;i<KNOWN_SERIALIZER_NUM && !ser_found;i++){
- for(j=0;j<arrayList_size(serializerList) && !ser_found;j++){
- service_reference_pt svcRef = (service_reference_pt)arrayList_get(serializerList,j);
- get_serializer_type(svcRef, &serializer_type);
- if(serializer_type != NULL){
- if(strncmp(qos_sample_serializer_prio_list[i],serializer_type,strlen(serializer_type))==0){
- ser_found = true;
- }
- }
- }
- if(ser_found){
- final_score += qos_serializer_score[i];
- }
- }
- }
- else if(strncmp(requested_qos_type,QOS_TYPE_CONTROL,strlen(QOS_TYPE_CONTROL))==0){
- bool ser_found = false;
- for(i=0;i<KNOWN_SERIALIZER_NUM && !ser_found;i++){
- for(j=0;j<arrayList_size(serializerList) && !ser_found;j++){
- service_reference_pt svcRef = (service_reference_pt)arrayList_get(serializerList,j);
- get_serializer_type(svcRef, &serializer_type);
- if(serializer_type != NULL){
- if(strncmp(qos_control_serializer_prio_list[i],serializer_type,strlen(serializer_type))==0){
- ser_found = true;
- }
- }
- }
- if(ser_found){
- final_score += qos_serializer_score[i];
- }
- }
- }
- else{
- printf("Unknown QoS type '%s'\n",requested_qos_type);
- status = CELIX_ILLEGAL_ARGUMENT;
- }
- }
- else{ /* We got no specification: fallback to Qos=Sample, but count half the score */
- bool ser_found = false;
- for(i=0;i<KNOWN_SERIALIZER_NUM && !ser_found;i++){
- for(j=0;j<arrayList_size(serializerList) && !ser_found;j++){
- service_reference_pt svcRef = (service_reference_pt)arrayList_get(serializerList,j);
- get_serializer_type(svcRef, &serializer_type);
- if(serializer_type != NULL){
- if(strncmp(qos_sample_serializer_prio_list[i],serializer_type,strlen(serializer_type))==0){
- ser_found = true;
- }
- }
- }
- if(ser_found){
- final_score += (qos_serializer_score[i]/2);
- }
- }
- }
-
- *score = final_score;
-
- printf("Score for pair <%s,%s> = %f\n",pubsub_admin_type,serializer_type,final_score);
-
- return status;
-}
-
-celix_status_t pubsub_admin_get_best_serializer(properties_pt endpoint_props, array_list_pt serializerList, pubsub_serializer_service_t **serSvc){
- celix_status_t status = CELIX_SUCCESS;
-
- int i = 0, j = 0;
-
- const char *requested_serializer_type = NULL;
- const char *requested_qos_type = NULL;
-
- if (endpoint_props != NULL){
- requested_serializer_type = properties_get(endpoint_props,PUBSUB_SERIALIZER_TYPE_KEY);
- requested_qos_type = properties_get(endpoint_props,QOS_ATTRIBUTE_KEY);
- }
-
- service_reference_pt svcRef = NULL;
- void *svc = NULL;
-
- /* Analyze the serializers */
- if(requested_serializer_type != NULL){ /* We got precise specification on the serializer we want */
- for(i=0;i<arrayList_size(serializerList);i++){
- svcRef = (service_reference_pt)arrayList_get(serializerList,i);
- char *serializer_type = NULL;
- get_serializer_type(svcRef, &serializer_type);
- if(serializer_type != NULL){
- if(strncmp(requested_serializer_type,serializer_type,strlen(serializer_type))==0){
- manage_service_from_reference(svcRef, &svc,true);
- if(svc==NULL){
- printf("Cannot get pubsub_serializer_service from serviceReference %p\n",svcRef);
- status = CELIX_SERVICE_EXCEPTION;
- }
- *serSvc = svc;
- break;
- }
- }
- }
- }
- else if(requested_qos_type != NULL){ /* We got QoS specification that will determine the selected serializer */
- if(strncmp(requested_qos_type,QOS_TYPE_SAMPLE,strlen(QOS_TYPE_SAMPLE))==0){
- bool ser_found = false;
- for(i=0;i<KNOWN_SERIALIZER_NUM && !ser_found;i++){
- for(j=0;j<arrayList_size(serializerList) && !ser_found;j++){
- svcRef = (service_reference_pt)arrayList_get(serializerList,j);
- char *serializer_type = NULL;
- get_serializer_type(svcRef, &serializer_type);
- if(serializer_type != NULL){
- if(strncmp(qos_sample_serializer_prio_list[i],serializer_type,strlen(serializer_type))==0){
- manage_service_from_reference(svcRef, &svc,true);
- if(svc==NULL){
- printf("Cannot get pubsub_serializer_service from serviceReference %p\n",svcRef);
- status = CELIX_SERVICE_EXCEPTION;
- }
- else{
- *serSvc = svc;
- ser_found = true;
- printf("Selected %s serializer as best for QoS=%s\n",qos_sample_serializer_prio_list[i],QOS_TYPE_SAMPLE);
- }
- }
- }
- }
- }
- }
- else if(strncmp(requested_qos_type,QOS_TYPE_CONTROL,strlen(QOS_TYPE_CONTROL))==0){
- bool ser_found = false;
- for(i=0;i<KNOWN_SERIALIZER_NUM && !ser_found;i++){
- for(j=0;j<arrayList_size(serializerList) && !ser_found;j++){
- svcRef = (service_reference_pt)arrayList_get(serializerList,j);
- char *serializer_type = NULL;
- get_serializer_type(svcRef, &serializer_type);
- if(serializer_type != NULL){
- if(strncmp(qos_control_serializer_prio_list[i],serializer_type,strlen(serializer_type))==0){
- manage_service_from_reference(svcRef, &svc,true);
- if(svc==NULL){
- printf("Cannot get pubsub_serializer_service from serviceReference %p\n",svcRef);
- status = CELIX_SERVICE_EXCEPTION;
- }
- else{
- *serSvc = svc;
- ser_found = true;
- printf("Selected %s serializer as best for QoS=%s\n",qos_control_serializer_prio_list[i],QOS_TYPE_CONTROL);
- }
- }
- }
- }
- }
- }
- else{
- printf("Unknown QoS type '%s'\n",requested_qos_type);
- status = CELIX_ILLEGAL_ARGUMENT;
- }
- }
- else{ /* We got no specification: fallback to Qos=Sample, but count half the score */
- bool ser_found = false;
- for(i=0;i<KNOWN_SERIALIZER_NUM && !ser_found;i++){
- for(j=0;j<arrayList_size(serializerList) && !ser_found;j++){
- svcRef = (service_reference_pt)arrayList_get(serializerList,j);
- char *serializer_type = NULL;
- get_serializer_type(svcRef, &serializer_type);
- if(serializer_type != NULL){
- if(strncmp(qos_sample_serializer_prio_list[i],serializer_type,strlen(serializer_type))==0){
- manage_service_from_reference(svcRef, &svc,true);
- if(svc==NULL){
- printf("Cannot get pubsub_serializer_service from serviceReference %p\n",svcRef);
- status = CELIX_SERVICE_EXCEPTION;
- }
- else{
- *serSvc = svc;
- ser_found = true;
- printf("Selected %s serializer as best without any specification\n",qos_sample_serializer_prio_list[i]);
- }
- }
- }
- }
- }
- }
-
- if(svc!=NULL && svcRef!=NULL){
- manage_service_from_reference(svcRef, svc, false);
- }
-
- return status;
-}
-
-static void get_serializer_type(service_reference_pt svcRef, char **serializerType){
-
- const char *serType = NULL;
- serviceReference_getProperty(svcRef, PUBSUB_SERIALIZER_TYPE_KEY,&serType);
- if(serType != NULL){
- *serializerType = (char*)serType;
- }
- else{
- printf("Serializer serviceReference %p has no pubsub_serializer.type property specified\n",svcRef);
- *serializerType = NULL;
- }
-}
-
-static void manage_service_from_reference(service_reference_pt svcRef, void **svc, bool getService){
- bundle_context_pt context = NULL;
- bundle_pt bundle = NULL;
- serviceReference_getBundle(svcRef, &bundle);
- bundle_getContext(bundle, &context);
- if(getService){
- bundleContext_getService(context, svcRef, svc);
- }
- else{
- bundleContext_ungetService(context, svcRef, NULL);
- }
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_common/public/src/pubsub_endpoint.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_common/public/src/pubsub_endpoint.c b/pubsub/pubsub_common/public/src/pubsub_endpoint.c
deleted file mode 100644
index c3fd293..0000000
--- a/pubsub/pubsub_common/public/src/pubsub_endpoint.c
+++ /dev/null
@@ -1,254 +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.
- */
-/*
- * endpoint_description.c
- *
- * \date 25 Jul 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <string.h>
-#include <stdlib.h>
-
-#include "celix_errno.h"
-#include "celix_log.h"
-
-#include "pubsub_common.h"
-#include "pubsub_endpoint.h"
-#include "constants.h"
-
-#include "pubsub_utils.h"
-
-
-static void pubsubEndpoint_setFields(pubsub_endpoint_pt psEp, const char* fwUUID, const char* scope, const char* topic, long serviceId,const char* endpoint,properties_pt topic_props, bool cloneProps);
-static properties_pt pubsubEndpoint_getTopicProperties(bundle_pt bundle, const char *topic, bool isPublisher);
-
-static void pubsubEndpoint_setFields(pubsub_endpoint_pt psEp, const char* fwUUID, const char* scope, const char* topic, long serviceId,const char* endpoint,properties_pt topic_props, bool cloneProps){
-
- if (fwUUID != NULL) {
- psEp->frameworkUUID = strdup(fwUUID);
- }
-
- if (scope != NULL) {
- psEp->scope = strdup(scope);
- }
-
- if (topic != NULL) {
- psEp->topic = strdup(topic);
- }
-
- psEp->serviceID = serviceId;
-
- if(endpoint != NULL) {
- psEp->endpoint = strdup(endpoint);
- }
-
- if(topic_props != NULL){
- if(cloneProps){
- properties_copy(topic_props, &(psEp->topic_props));
- }
- else{
- psEp->topic_props = topic_props;
- }
- }
-}
-
-static properties_pt pubsubEndpoint_getTopicProperties(bundle_pt bundle, const char *topic, bool isPublisher){
-
- properties_pt topic_props = NULL;
-
- bool isSystemBundle = false;
- bundle_isSystemBundle(bundle, &isSystemBundle);
- long bundleId = -1;
- bundle_isSystemBundle(bundle, &isSystemBundle);
- bundle_getBundleId(bundle,&bundleId);
-
- if(isSystemBundle == false) {
-
- char *bundleRoot = NULL;
- char* topicPropertiesPath = NULL;
- bundle_getEntry(bundle, ".", &bundleRoot);
-
- if(bundleRoot != NULL){
-
- asprintf(&topicPropertiesPath, "%s/META-INF/topics/%s/%s.properties", bundleRoot, isPublisher?"pub":"sub", topic);
- topic_props = properties_load(topicPropertiesPath);
- if(topic_props==NULL){
- printf("PSEP: Could not load properties for %s on topic %s, bundleId=%ld\n", isPublisher?"publication":"subscription", topic,bundleId);
- }
-
- free(topicPropertiesPath);
- free(bundleRoot);
- }
- }
-
- return topic_props;
-}
-
-celix_status_t pubsubEndpoint_create(const char* fwUUID, const char* scope, const char* topic, long serviceId,const char* endpoint,properties_pt topic_props,pubsub_endpoint_pt* psEp){
- celix_status_t status = CELIX_SUCCESS;
-
- *psEp = calloc(1, sizeof(**psEp));
-
- pubsubEndpoint_setFields(*psEp, fwUUID, scope, topic, serviceId, endpoint, topic_props, true);
-
- return status;
-
-}
-
-celix_status_t pubsubEndpoint_clone(pubsub_endpoint_pt in, pubsub_endpoint_pt *out){
- celix_status_t status = CELIX_SUCCESS;
-
- *out = calloc(1,sizeof(**out));
-
- pubsubEndpoint_setFields(*out, in->frameworkUUID, in->scope, in->topic, in->serviceID, in->endpoint, in->topic_props, true);
-
- return status;
-
-}
-
-celix_status_t pubsubEndpoint_createFromServiceReference(service_reference_pt reference, pubsub_endpoint_pt* psEp, bool isPublisher){
- celix_status_t status = CELIX_SUCCESS;
-
- pubsub_endpoint_pt ep = calloc(1,sizeof(*ep));
-
- bundle_pt bundle = NULL;
- bundle_context_pt ctxt = NULL;
- const char* fwUUID = NULL;
- serviceReference_getBundle(reference,&bundle);
- bundle_getContext(bundle,&ctxt);
- bundleContext_getProperty(ctxt,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
-
- const char* scope = NULL;
- serviceReference_getProperty(reference, PUBSUB_SUBSCRIBER_SCOPE,&scope);
-
- const char* topic = NULL;
- serviceReference_getProperty(reference, PUBSUB_SUBSCRIBER_TOPIC,&topic);
-
- const char* serviceId = NULL;
- serviceReference_getProperty(reference,(char*)OSGI_FRAMEWORK_SERVICE_ID,&serviceId);
-
- /* TODO: is topic_props==NULL a fatal error such that EP cannot be created? */
- properties_pt topic_props = pubsubEndpoint_getTopicProperties(bundle, topic, isPublisher);
-
- pubsubEndpoint_setFields(ep, fwUUID, scope!=NULL?scope:PUBSUB_SUBSCRIBER_SCOPE_DEFAULT, topic, strtol(serviceId,NULL,10), NULL, topic_props, false);
-
- if (!ep->frameworkUUID || !ep->serviceID || !ep->scope || !ep->topic) {
- fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "PUBSUB_ENDPOINT: incomplete description!.");
- status = CELIX_BUNDLE_EXCEPTION;
- pubsubEndpoint_destroy(ep);
- *psEp = NULL;
- }
- else{
- *psEp = ep;
- }
-
- return status;
-
-}
-
-celix_status_t pubsubEndpoint_createFromListenerHookInfo(listener_hook_info_pt info,pubsub_endpoint_pt* psEp, bool isPublisher){
- celix_status_t status = CELIX_SUCCESS;
-
- const char* fwUUID=NULL;
- bundleContext_getProperty(info->context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
-
- if(fwUUID==NULL){
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- char* topic = pubsub_getTopicFromFilter(info->filter);
- if(topic==NULL){
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- *psEp = calloc(1, sizeof(**psEp));
-
- char* scope = pubsub_getScopeFromFilter(info->filter);
- if(scope == NULL) {
- scope = strdup(PUBSUB_PUBLISHER_SCOPE_DEFAULT);
- }
-
- bundle_pt bundle = NULL;
- long bundleId = -1;
- bundleContext_getBundle(info->context,&bundle);
-
- bundle_getBundleId(bundle,&bundleId);
-
- properties_pt topic_props = pubsubEndpoint_getTopicProperties(bundle, topic, isPublisher);
-
- /* TODO: is topic_props==NULL a fatal error such that EP cannot be created? */
- pubsubEndpoint_setFields(*psEp, fwUUID, scope!=NULL?scope:PUBSUB_SUBSCRIBER_SCOPE_DEFAULT, topic, bundleId, NULL, topic_props, false);
-
- free(topic);
- free(scope);
-
-
- return status;
-}
-
-celix_status_t pubsubEndpoint_destroy(pubsub_endpoint_pt psEp){
-
- if(psEp->frameworkUUID!=NULL){
- free(psEp->frameworkUUID);
- psEp->frameworkUUID = NULL;
- }
-
- if(psEp->scope!=NULL){
- free(psEp->scope);
- psEp->scope = NULL;
- }
-
- if(psEp->topic!=NULL){
- free(psEp->topic);
- psEp->topic = NULL;
- }
-
- if(psEp->endpoint!=NULL){
- free(psEp->endpoint);
- psEp->endpoint = NULL;
- }
-
- if(psEp->topic_props != NULL){
- properties_destroy(psEp->topic_props);
- }
-
- free(psEp);
-
- return CELIX_SUCCESS;
-
-}
-
-bool pubsubEndpoint_equals(pubsub_endpoint_pt psEp1,pubsub_endpoint_pt psEp2){
-
- return ((strcmp(psEp1->frameworkUUID,psEp2->frameworkUUID)==0) &&
- (strcmp(psEp1->scope,psEp2->scope)==0) &&
- (strcmp(psEp1->topic,psEp2->topic)==0) &&
- (psEp1->serviceID == psEp2->serviceID) /*&&
- ((psEp1->endpoint==NULL && psEp2->endpoint==NULL)||(strcmp(psEp1->endpoint,psEp2->endpoint)==0))*/
- );
-}
-
-char *createScopeTopicKey(const char* scope, const char* topic) {
- char *result = NULL;
- asprintf(&result, "%s:%s", scope, topic);
-
- return result;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_common/public/src/pubsub_utils.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_common/public/src/pubsub_utils.c b/pubsub/pubsub_common/public/src/pubsub_utils.c
deleted file mode 100644
index abc5ae6..0000000
--- a/pubsub/pubsub_common/public/src/pubsub_utils.c
+++ /dev/null
@@ -1,170 +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.
- */
-/*
- * pubsub_utils.c
- *
- * \date Sep 24, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <string.h>
-#include <stdlib.h>
-
-#include "constants.h"
-
-#include "pubsub_common.h"
-#include "publisher.h"
-#include "pubsub_utils.h"
-
-#include "array_list.h"
-#include "bundle.h"
-
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#define MAX_KEYBUNDLE_LENGTH 256
-
-char* pubsub_getScopeFromFilter(char* bundle_filter){
-
- char* scope = NULL;
-
- char* filter = strdup(bundle_filter);
-
- char* oc = strstr(filter,OSGI_FRAMEWORK_OBJECTCLASS);
- if(oc!=NULL){
- oc+=strlen(OSGI_FRAMEWORK_OBJECTCLASS)+1;
- if(strncmp(oc,PUBSUB_PUBLISHER_SERVICE_NAME,strlen(PUBSUB_PUBLISHER_SERVICE_NAME))==0){
-
- char* scopes = strstr(filter,PUBSUB_PUBLISHER_SCOPE);
- if(scopes!=NULL){
-
- scopes+=strlen(PUBSUB_PUBLISHER_SCOPE)+1;
- char* bottom=strchr(scopes,')');
- *bottom='\0';
-
- scope=strdup(scopes);
- } else {
- scope=strdup(PUBSUB_PUBLISHER_SCOPE_DEFAULT);
- }
- }
- }
-
- free(filter);
-
- return scope;
-}
-
-char* pubsub_getTopicFromFilter(char* bundle_filter){
-
- char* topic = NULL;
-
- char* filter = strdup(bundle_filter);
-
- char* oc = strstr(filter,OSGI_FRAMEWORK_OBJECTCLASS);
- if(oc!=NULL){
- oc+=strlen(OSGI_FRAMEWORK_OBJECTCLASS)+1;
- if(strncmp(oc,PUBSUB_PUBLISHER_SERVICE_NAME,strlen(PUBSUB_PUBLISHER_SERVICE_NAME))==0){
-
- char* topics = strstr(filter,PUBSUB_PUBLISHER_TOPIC);
- if(topics!=NULL){
-
- topics+=strlen(PUBSUB_PUBLISHER_TOPIC)+1;
- char* bottom=strchr(topics,')');
- *bottom='\0';
-
- topic=strdup(topics);
-
- }
- }
- }
-
- free(filter);
-
- return topic;
-
-}
-
-array_list_pt pubsub_getTopicsFromString(char* string){
-
- array_list_pt topic_list = NULL;
- arrayList_create(&topic_list);
-
- char* topics = strdup(string);
-
- char* topic = strtok(topics,",;|# ");
- arrayList_add(topic_list,strdup(topic));
-
- while( (topic = strtok(NULL,",;|# ")) !=NULL){
- arrayList_add(topic_list,strdup(topic));
- }
-
- free(topics);
-
- return topic_list;
-
-}
-
-/**
- * Loop through all bundles and look for the bundle with the keys inside.
- * If no key bundle found, return NULL
- *
- * Caller is responsible for freeing the object
- */
-char* pubsub_getKeysBundleDir(bundle_context_pt ctx)
-{
- array_list_pt bundles = NULL;
- bundleContext_getBundles(ctx, &bundles);
- int nrOfBundles = arrayList_size(bundles);
- long bundle_id = -1;
- char* result = NULL;
-
- for (int i = 0; i < nrOfBundles; i++){
- bundle_pt b = arrayList_get(bundles, i);
-
- /* Skip bundle 0 (framework bundle) since it has no path nor revisions */
- bundle_getBundleId(b, &bundle_id);
- if(bundle_id==0){
- continue;
- }
-
- char* dir = NULL;
- bundle_getEntry(b, ".", &dir);
-
- char cert_dir[MAX_KEYBUNDLE_LENGTH];
- snprintf(cert_dir, MAX_KEYBUNDLE_LENGTH, "%s/META-INF/keys", dir);
-
- struct stat s;
- int err = stat(cert_dir, &s);
- if (err != -1){
- if (S_ISDIR(s.st_mode)){
- result = dir;
- break;
- }
- }
-
- free(dir);
- }
-
- arrayList_destroy(bundles);
-
- return result;
-}
-
[45/54] [abbrv] celix git commit: CELIX-417: Fixes issues with the
order of Cmake add_subdirectory for remote services
Posted by pn...@apache.org.
CELIX-417: Fixes issues with the order of Cmake add_subdirectory for remote services
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/0c64ca6a
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/0c64ca6a
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/0c64ca6a
Branch: refs/heads/develop
Commit: 0c64ca6a1a97b6f997d1d7773d1c53c79c102bbd
Parents: 0ea8de6
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Sat Jan 27 13:47:27 2018 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Sat Jan 27 13:47:27 2018 +0100
----------------------------------------------------------------------
remote_services/CMakeLists.txt | 5 ++---
remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt | 2 +-
2 files changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0c64ca6a/remote_services/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/CMakeLists.txt b/remote_services/CMakeLists.txt
index ae27849..991d94a 100644
--- a/remote_services/CMakeLists.txt
+++ b/remote_services/CMakeLists.txt
@@ -17,11 +17,11 @@
celix_subproject(REMOTE_SERVICE_ADMIN "Option to enable building the Remote Service Admin Service bundles" OFF)
if (REMOTE_SERVICE_ADMIN)
-
add_subdirectory(remote_services_api)
+ add_subdirectory(examples)
+
add_subdirectory(rsa_spi)
add_subdirectory(rsa_common)
-
add_subdirectory(civetweb)
add_subdirectory(topology_manager)
@@ -35,7 +35,6 @@ if (REMOTE_SERVICE_ADMIN)
#add_subdirectory(remote_service_admin_shm)
add_subdirectory(remote_service_admin_dfi)
- add_subdirectory(examples)
endif (REMOTE_SERVICE_ADMIN)
http://git-wip-us.apache.org/repos/asf/celix/blob/0c64ca6a/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt b/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
index c9a9d62..15536e0 100644
--- a/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
+++ b/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
@@ -27,7 +27,7 @@ add_celix_bundle(topology_manager_test_bundle
SOURCES
tst_activator.c
)
-celix_celix_bundle_files(topology_manager_test_bundle
+celix_bundle_files(topology_manager_test_bundle
org.apache.celix.test.MyBundle.descriptor
DESTINATION .
)
[35/54] [abbrv] celix git commit: CELIX-417: Refactors cmake usage of
pubsub and rsa. Started with installing exported targets
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_common/src/import_registration_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/import_registration_impl.c b/remote_services/remote_service_admin_common/src/import_registration_impl.c
deleted file mode 100644
index 9a84327..0000000
--- a/remote_services/remote_service_admin_common/src/import_registration_impl.c
+++ /dev/null
@@ -1,274 +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.
- */
-/*
- * import_registration_impl.c
- *
- * \date Oct 14, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include <constants.h>
-
-#include "celix_errno.h"
-
-#include "import_registration_impl.h"
-#include "remote_service_admin_impl.h"
-
-struct import_reference {
- endpoint_description_pt endpoint;
- service_reference_pt reference;
-};
-
-
-
-celix_status_t importRegistration_proxyFactoryAdding(void * handle, service_reference_pt reference, void **service);
-celix_status_t importRegistration_proxyFactoryAdded(void * handle, service_reference_pt reference, void *service);
-celix_status_t importRegistration_proxyFactoryModified(void * handle, service_reference_pt reference, void *service);
-celix_status_t importRegistration_proxyFactoryRemoved(void * handle, service_reference_pt reference, void *service);
-
-celix_status_t importRegistration_create(endpoint_description_pt endpoint, remote_service_admin_pt rsa, sendToHandle sendToCallback, bundle_context_pt context, import_registration_pt *registration) {
- celix_status_t status = CELIX_SUCCESS;
-
- *registration = calloc(1, sizeof(**registration));
- if (!*registration) {
- status = CELIX_ENOMEM;
- } else {
- (*registration)->context = context;
- (*registration)->closed = false;
- (*registration)->endpointDescription = endpoint;
- (*registration)->rsa = rsa;
- (*registration)->sendToCallback = sendToCallback;
- (*registration)->reference = NULL;
- (*registration)->importReference = NULL;
- }
-
- return status;
-}
-
-celix_status_t importRegistration_destroy(import_registration_pt registration)
-{
- free(registration);
-
- return CELIX_SUCCESS;
-}
-
-
-celix_status_t importRegistrationFactory_create(log_helper_pt helper, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory) {
- celix_status_t status = CELIX_SUCCESS;
-
- *registration_factory = calloc(1, sizeof(**registration_factory));
- if (!*registration_factory) {
- status = CELIX_ENOMEM;
- } else {
- (*registration_factory)->serviceName = strdup(serviceName);
- (*registration_factory)->context = context;
- (*registration_factory)->bundle = NULL;
- (*registration_factory)->loghelper = helper;
-
- arrayList_create(&(*registration_factory)->registrations);
- }
-
- return status;
-}
-
-
-
-celix_status_t importRegistrationFactory_destroy(import_registration_factory_pt* registration_factory) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (*registration_factory != NULL)
- {
- free((*registration_factory)->serviceName);
- arrayList_destroy((*registration_factory)->registrations);
-
- serviceTracker_destroy((*registration_factory)->proxyFactoryTracker);
- free(*registration_factory);
-
- *registration_factory = NULL;
- }
-
-
- return status;
-}
-
-
-celix_status_t importRegistrationFactory_open(import_registration_factory_pt registration_factory)
-{
- celix_status_t status;
-
- const char *bundleStore = NULL;
- bundleContext_getProperty(registration_factory->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore);
-
- if (bundleStore == NULL) {
- bundleStore = DEFAULT_BUNDLE_STORE;
- }
-
- char name[256];
- snprintf(name, 256, "%s/%s_proxy.zip", bundleStore, registration_factory->serviceName);
-
- status = bundleContext_installBundle(registration_factory->context, name, ®istration_factory->bundle);
-
- if (status == CELIX_SUCCESS) {
- status = bundle_start(registration_factory->bundle);
- if (status == CELIX_SUCCESS) {
- logHelper_log(registration_factory->loghelper, OSGI_LOGSERVICE_INFO, "%s successfully started.", name);
- }
- }
- else {
- logHelper_log(registration_factory->loghelper, OSGI_LOGSERVICE_ERROR, "%s could not be installed.", name);
- }
-
- return status;
-}
-
-celix_status_t importRegistrationFactory_close(import_registration_factory_pt registration_factory)
-{
- celix_status_t status = CELIX_SUCCESS;
-
-
- if (registration_factory->proxyFactoryTracker != NULL) {
- serviceTracker_close(registration_factory->proxyFactoryTracker);
- }
-
- if (registration_factory->bundle != NULL) {
- bundle_uninstall(registration_factory->bundle);
- }
-
- return status;
-}
-
-
-celix_status_t importRegistration_createProxyFactoryTracker(import_registration_factory_pt registration_factory, service_tracker_pt *tracker) {
- celix_status_t status;
- service_tracker_customizer_pt customizer = NULL;
-
- status = serviceTrackerCustomizer_create(registration_factory, importRegistration_proxyFactoryAdding, importRegistration_proxyFactoryAdded, importRegistration_proxyFactoryModified, importRegistration_proxyFactoryRemoved, &customizer);
-
- if (status == CELIX_SUCCESS) {
- char filter[512];
-
- snprintf(filter, 512, "(&(%s=%s)(proxy.interface=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, (char*) OSGI_RSA_REMOTE_PROXY_FACTORY, registration_factory->serviceName);
- status = serviceTracker_createWithFilter(registration_factory->context, filter, customizer, tracker);
-
- if (status == CELIX_SUCCESS)
- {
- serviceTracker_open(*tracker);
- }
- }
-
- return status;
-}
-
-celix_status_t importRegistration_proxyFactoryAdding(void * handle, service_reference_pt reference, void **service) {
- celix_status_t status = CELIX_SUCCESS;
- import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
-
- bundleContext_getService(registration_factory->context, reference, service);
-
- return status;
-}
-
-celix_status_t importRegistration_proxyFactoryAdded(void * handle, service_reference_pt reference, void *service) {
- celix_status_t status = CELIX_SUCCESS;
-
- import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
- registration_factory->trackedFactory = (remote_proxy_factory_service_pt) service;
-
- return status;
-}
-
-celix_status_t importRegistration_proxyFactoryModified(void * handle, service_reference_pt reference, void *service) {
- celix_status_t status = CELIX_SUCCESS;
-
- return status;
-}
-
-celix_status_t importRegistration_proxyFactoryRemoved(void * handle, service_reference_pt reference, void *service) {
- celix_status_t status = CELIX_SUCCESS;
-
- import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
- registration_factory->trackedFactory = NULL;
-
- return status;
-}
-
-
-
-celix_status_t importRegistrationFactory_install(log_helper_pt helper, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory)
-{
- celix_status_t status;
-
- if ( (status = importRegistrationFactory_create(helper, serviceName, context, registration_factory)) == CELIX_SUCCESS) {
- // starting the proxy tracker first allows us to pick up already available proxy factories
- importRegistration_createProxyFactoryTracker(*registration_factory, &((*registration_factory)->proxyFactoryTracker));
- logHelper_log((*registration_factory)->loghelper, OSGI_LOGSERVICE_INFO, "remoteServiceAdmin_importService: new registration_factory added for %s at %p", serviceName, (*registration_factory)->proxyFactoryTracker);
-
- // check whether factory is available
- if (((*registration_factory)->trackedFactory == NULL) && ((status = importRegistrationFactory_open(*registration_factory)) != CELIX_SUCCESS)) {
- logHelper_log((*registration_factory)->loghelper, OSGI_LOGSERVICE_ERROR, "remoteServiceAdmin_importService: cannot open registration_factory for %s.", serviceName);
-
- importRegistrationFactory_close(*registration_factory);
- importRegistrationFactory_destroy(registration_factory);
- }
- }
-
- return status;
-}
-
-
-
-
-celix_status_t importRegistration_getException(import_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-
-celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (registration->importReference == NULL) {
- registration->importReference = calloc(1, sizeof(*registration->importReference));
- if (registration->importReference == NULL) {
- status = CELIX_ENOMEM;
- } else {
- registration->importReference->endpoint = registration->endpointDescription;
- registration->importReference->reference = registration->reference;
- }
- }
-
- *reference = registration->importReference;
-
- return status;
-}
-
-
-celix_status_t importReference_getImportedEndpoint(import_reference_pt reference) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-celix_status_t importReference_getImportedService(import_reference_pt reference) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_common/src/import_registration_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/import_registration_impl.h b/remote_services/remote_service_admin_common/src/import_registration_impl.h
deleted file mode 100644
index 7aa397f..0000000
--- a/remote_services/remote_service_admin_common/src/import_registration_impl.h
+++ /dev/null
@@ -1,81 +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.
- */
-/*
- * import_registration_impl.h
- *
- * \date Oct 14, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef IMPORT_REGISTRATION_IMPL_H_
-#define IMPORT_REGISTRATION_IMPL_H_
-
-#include "remote_service_admin.h"
-#include "remote_proxy.h"
-#include "service_tracker.h"
-#include "log_helper.h"
-
-struct import_registration {
- bundle_context_pt context;
- endpoint_description_pt endpointDescription;
-
- service_reference_pt reference;
- import_reference_pt importReference;
-
- remote_service_admin_pt rsa;
- sendToHandle sendToCallback;
-
- bool closed;
-};
-
-
-
-struct import_registration_factory
-{
- char* serviceName;
- log_helper_pt loghelper;
- remote_proxy_factory_service_pt trackedFactory;
- service_tracker_pt proxyFactoryTracker;
- bundle_context_pt context;
- array_list_pt registrations;
- bundle_pt bundle;
-};
-
-
-celix_status_t importRegistration_create(endpoint_description_pt endpoint, remote_service_admin_pt rsa, sendToHandle callback, bundle_context_pt context, import_registration_pt *registration);
-celix_status_t importRegistration_destroy(import_registration_pt registration);
-
-celix_status_t importRegistration_setEndpointDescription(import_registration_pt registration, endpoint_description_pt endpointDescription);
-celix_status_t importRegistration_setHandler(import_registration_pt registration, void * handler);
-celix_status_t importRegistration_setCallback(import_registration_pt registration, sendToHandle callback);
-
-celix_status_t importRegistration_getException(import_registration_pt registration);
-celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference);
-
-celix_status_t importRegistration_createProxyFactoryTracker(import_registration_factory_pt registration_factory, service_tracker_pt *tracker);
-
-celix_status_t importRegistrationFactory_destroy(import_registration_factory_pt* registration_factory);
-//celix_status_t importRegistrationFactory_open(import_registration_factory_pt registration_factory);
-celix_status_t importRegistrationFactory_close(import_registration_factory_pt registration_factory);
-celix_status_t importRegistrationFactory_install(log_helper_pt helper, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory);
-
-
-
-#endif /* IMPORT_REGISTRATION_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_common/src/remote_proxy_factory_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/remote_proxy_factory_impl.c b/remote_services/remote_service_admin_common/src/remote_proxy_factory_impl.c
deleted file mode 100644
index 9f996d6..0000000
--- a/remote_services/remote_service_admin_common/src/remote_proxy_factory_impl.c
+++ /dev/null
@@ -1,252 +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.
- */
-
-/*
- * remote_proxy_factory_impl.c
- *
- * \date 22 Dec 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "remote_proxy.h"
-
-typedef struct proxy_instance {
- service_registration_pt registration_ptr;
- void *service;
- properties_pt properties;
-} *proxy_instance_pt;
-
-static celix_status_t remoteProxyFactory_registerProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback);
-static celix_status_t remoteProxyFactory_unregisterProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription);
-
-celix_status_t remoteProxyFactory_create(bundle_context_pt context, char *service, void *handle,
- createProxyService create, destroyProxyService destroy,
- remote_proxy_factory_pt *remote_proxy_factory_ptr) {
- celix_status_t status = CELIX_SUCCESS;
-
- *remote_proxy_factory_ptr = calloc(1, sizeof(**remote_proxy_factory_ptr));
- if (!*remote_proxy_factory_ptr) {
- status = CELIX_ENOMEM;
- }
-
- if (status == CELIX_SUCCESS) {
- (*remote_proxy_factory_ptr)->context_ptr = context;
- (*remote_proxy_factory_ptr)->service = strdup(service);
-
- (*remote_proxy_factory_ptr)->remote_proxy_factory_service_ptr = NULL;
- (*remote_proxy_factory_ptr)->properties = NULL;
- (*remote_proxy_factory_ptr)->registration = NULL;
-
- (*remote_proxy_factory_ptr)->proxy_instances = hashMap_create(NULL, NULL, NULL, NULL);
-
- (*remote_proxy_factory_ptr)->handle = handle;
-
- (*remote_proxy_factory_ptr)->create_proxy_service_ptr = create;
- (*remote_proxy_factory_ptr)->destroy_proxy_service_ptr = destroy;
- }
-
- return status;
-}
-
-celix_status_t remoteProxyFactory_destroy(remote_proxy_factory_pt *remote_proxy_factory_ptr) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!*remote_proxy_factory_ptr) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- if ((*remote_proxy_factory_ptr)->proxy_instances) {
- hashMap_destroy((*remote_proxy_factory_ptr)->proxy_instances, false, false);
- (*remote_proxy_factory_ptr)->proxy_instances = NULL;
- }
- if ((*remote_proxy_factory_ptr)->service) {
- free((*remote_proxy_factory_ptr)->service);
- (*remote_proxy_factory_ptr)->service = NULL;
- }
- free(*remote_proxy_factory_ptr);
- *remote_proxy_factory_ptr = NULL;
- }
-
- return status;
-}
-
-celix_status_t remoteProxyFactory_register(remote_proxy_factory_pt remote_proxy_factory_ptr) {
- celix_status_t status = CELIX_SUCCESS;
-
- remote_proxy_factory_ptr->remote_proxy_factory_service_ptr = calloc(1, sizeof(*remote_proxy_factory_ptr->remote_proxy_factory_service_ptr));
- if (!remote_proxy_factory_ptr->remote_proxy_factory_service_ptr) {
- status = CELIX_ENOMEM;
- }
-
- if (status == CELIX_SUCCESS) {
- remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->factory = remote_proxy_factory_ptr;
- remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->registerProxyService = remoteProxyFactory_registerProxyService;
- remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->unregisterProxyService = remoteProxyFactory_unregisterProxyService;
-
- remote_proxy_factory_ptr->properties = properties_create();
- if (!remote_proxy_factory_ptr->properties) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- properties_set(remote_proxy_factory_ptr->properties, "proxy.interface", remote_proxy_factory_ptr->service);
- }
- }
-
- if (status == CELIX_SUCCESS) {
- status = bundleContext_registerService(remote_proxy_factory_ptr->context_ptr, OSGI_RSA_REMOTE_PROXY_FACTORY,
- remote_proxy_factory_ptr->remote_proxy_factory_service_ptr, remote_proxy_factory_ptr->properties, &remote_proxy_factory_ptr->registration);
- }
-
- return status;
-}
-
-celix_status_t remoteProxyFactory_unregister(remote_proxy_factory_pt remote_proxy_factory_ptr) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!remote_proxy_factory_ptr) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- // #TODO Remove proxy registrations
- if (status == CELIX_SUCCESS) {
-
- hash_map_iterator_pt iter = hashMapIterator_create(remote_proxy_factory_ptr->proxy_instances);
- while(hashMapIterator_hasNext(iter)){
- proxy_instance_pt proxy_instance_ptr = (proxy_instance_pt)hashMapIterator_nextValue(iter);
-
- if (proxy_instance_ptr->service) {
- remote_proxy_factory_ptr->destroy_proxy_service_ptr(remote_proxy_factory_ptr->handle, proxy_instance_ptr->service);
- }
- free(proxy_instance_ptr);
- }
- hashMapIterator_destroy(iter);
-
- if (remote_proxy_factory_ptr->registration) {
- status = serviceRegistration_unregister(remote_proxy_factory_ptr->registration);
- remote_proxy_factory_ptr->properties = NULL;
- }
- if (remote_proxy_factory_ptr->properties) {
- properties_destroy(remote_proxy_factory_ptr->properties);
- }
- if (remote_proxy_factory_ptr->remote_proxy_factory_service_ptr) {
- free(remote_proxy_factory_ptr->remote_proxy_factory_service_ptr);
- }
- }
-
- return status;
-}
-
-
-static celix_status_t remoteProxyFactory_registerProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback) {
- celix_status_t status = CELIX_SUCCESS;
- proxy_instance_pt proxy_instance_ptr = NULL;
-
- if (!remote_proxy_factory_ptr || !remote_proxy_factory_ptr->create_proxy_service_ptr) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- proxy_instance_ptr = calloc(1, sizeof(*proxy_instance_ptr));
- if (!proxy_instance_ptr) {
- status = CELIX_ENOMEM;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- proxy_instance_ptr->properties = properties_create();
- if (!proxy_instance_ptr->properties) {
- status = CELIX_ENOMEM;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- status = remote_proxy_factory_ptr->create_proxy_service_ptr(remote_proxy_factory_ptr->handle, endpointDescription, rsa, sendToCallback, proxy_instance_ptr->properties, &proxy_instance_ptr->service);
- }
-
- if (status == CELIX_SUCCESS) {
- properties_set(proxy_instance_ptr->properties, "proxy.interface", remote_proxy_factory_ptr->service);
-
- hash_map_iterator_pt iter = hashMapIterator_create(endpointDescription->properties);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- char *key = hashMapEntry_getKey(entry);
- char *value = hashMapEntry_getValue(entry);
-
- properties_set(proxy_instance_ptr->properties, key, value);
- }
- hashMapIterator_destroy(iter);
- }
-
- if (status == CELIX_SUCCESS) {
- status = bundleContext_registerService(remote_proxy_factory_ptr->context_ptr, remote_proxy_factory_ptr->service, proxy_instance_ptr->service, proxy_instance_ptr->properties, &proxy_instance_ptr->registration_ptr);
- }
-
- if (status == CELIX_SUCCESS) {
- hashMap_put(remote_proxy_factory_ptr->proxy_instances, endpointDescription, proxy_instance_ptr);
- }
-
- if(status!=CELIX_SUCCESS){
- if(proxy_instance_ptr != NULL){
- if(proxy_instance_ptr->properties != NULL){
- properties_destroy(proxy_instance_ptr->properties);
- }
- free(proxy_instance_ptr);
- }
- }
-
- return status;
-}
-
-static celix_status_t remoteProxyFactory_unregisterProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription) {
- celix_status_t status = CELIX_SUCCESS;
- proxy_instance_pt proxy_instance_ptr = NULL;
-
- if (!remote_proxy_factory_ptr || !endpointDescription || !remote_proxy_factory_ptr->proxy_instances || !remote_proxy_factory_ptr->handle) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- proxy_instance_ptr = hashMap_remove(remote_proxy_factory_ptr->proxy_instances, endpointDescription);
- if (proxy_instance_ptr == NULL) {
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- if (proxy_instance_ptr->registration_ptr) {
- status = serviceRegistration_unregister(proxy_instance_ptr->registration_ptr);
- proxy_instance_ptr->properties = NULL;
- }
- if (proxy_instance_ptr->service) {
- status = remote_proxy_factory_ptr->destroy_proxy_service_ptr(remote_proxy_factory_ptr->handle, proxy_instance_ptr->service);
- }
- if (proxy_instance_ptr->properties) {
- properties_destroy(proxy_instance_ptr->properties);
- }
- free(proxy_instance_ptr);
- }
-
- return status;
-}
-
-
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_common/src/remote_service_admin_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/remote_service_admin_impl.h b/remote_services/remote_service_admin_common/src/remote_service_admin_impl.h
deleted file mode 100644
index e8a5e1f..0000000
--- a/remote_services/remote_service_admin_common/src/remote_service_admin_impl.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.
- */
-/*
- * remote_service_admin_impl.h
- *
- * \date Dec 5, 2013
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_SERVICE_ADMIN_IMPL_H_
-#define REMOTE_SERVICE_ADMIN_IMPL_H_
-
-#include "remote_service_admin.h"
-
-#define BUNDLE_STORE_PROPERTY_NAME "ENDPOINTS"
-#define DEFAULT_BUNDLE_STORE "endpoints"
-
-celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin);
-celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin);
-
-celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *methodSignature, char **reply, int* replyStatus);
-
-celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
-celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration);
-celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services);
-celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services);
-celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
-celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration);
-
-celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description);
-
-#endif /* REMOTE_SERVICE_ADMIN_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_services_api/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_services_api/CMakeLists.txt b/remote_services/remote_services_api/CMakeLists.txt
new file mode 100644
index 0000000..67656d3
--- /dev/null
+++ b/remote_services/remote_services_api/CMakeLists.txt
@@ -0,0 +1,28 @@
+# 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.
+
+add_library(celix_remote_services_api INTERFACE)
+target_include_directories(celix_remote_services_api INTERFACE
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
+ $<INSTALL_INTERFACE:include/celix/remote_services>
+)
+
+install(TARGETS celix_remote_services_api EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT rsa)
+install(DIRECTORY include/ DESTINATION include/celix/remote_services COMPONENT rsa)
+
+#Setup target aliases to match external usage
+add_library(Celix::remote_services_api ALIAS celix_remote_services_api)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_services_api/README.md
----------------------------------------------------------------------
diff --git a/remote_services/remote_services_api/README.md b/remote_services/remote_services_api/README.md
new file mode 100644
index 0000000..2e3d268
--- /dev/null
+++ b/remote_services/remote_services_api/README.md
@@ -0,0 +1,11 @@
+# Remote Service Admin
+
+The Remote Service Admin (RSA) provides the mechanisms to import and export services when instructed to do so by the Topology Manager.
+
+To delegate method calls to the actual service implementation, the RSA_SHM and the RSA_HTTP are using "endpoint/proxy" bundles, which has all the knowledge about the marshalling and unmarshalling of data for the service. The RSA_DFI implementation combines a [foreign function interface](https://en.wikipedia.org/wiki/Foreign_function_interface) technique together with manualy created descriptors.
+
+Note that this folder contains code commonly used by the RSA implementations and therefore does not include any CMAKE configuration.
+
+## Properties
+ ENDPOINTS defines the relative directory where endpoints and proxys can be found (default: endpoints)
+ CELIX_FRAMEWORK_EXTENDER_PATH Used in RSA_DFI only. Can be used to define a path to use as an extender path point for the framework bundle. For normal bundles the bundle cache is used.
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_services_api/include/remote_constants.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_services_api/include/remote_constants.h b/remote_services/remote_services_api/include/remote_constants.h
new file mode 100644
index 0000000..277f837
--- /dev/null
+++ b/remote_services/remote_services_api/include/remote_constants.h
@@ -0,0 +1,31 @@
+/**
+ *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.
+ */
+
+#ifndef REMOTE_CONSTANTS_H_
+#define REMOTE_CONSTANTS_H_
+
+static const char * const OSGI_RSA_SERVICE_EXPORTED_INTERFACES = "service.exported.interfaces";
+static const char * const OSGI_RSA_ENDPOINT_FRAMEWORK_UUID = "endpoint.framework.uuid";
+static const char * const OSGI_RSA_ENDPOINT_SERVICE_ID = "endpoint.service.id";
+static const char * const OSGI_RSA_ENDPOINT_ID = "endpoint.id";
+static const char * const OSGI_RSA_SERVICE_IMPORTED = "service.imported";
+static const char * const OSGI_RSA_SERVICE_IMPORTED_CONFIGS = "service.imported.configs";
+static const char * const OSGI_RSA_SERVICE_LOCATION = "service.location";
+
+#endif /* REMOTE_CONSTANTS_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_common/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/rsa_common/CMakeLists.txt b/remote_services/rsa_common/CMakeLists.txt
new file mode 100644
index 0000000..27c2dba
--- /dev/null
+++ b/remote_services/rsa_common/CMakeLists.txt
@@ -0,0 +1,29 @@
+# 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.
+
+add_library(celix_rsa_common STATIC
+ src/endpoint_description.c
+ src/export_registration_impl.c
+ src/import_registration_impl.c
+)
+target_include_directories(celix_rsa_common PRIVATE src)
+target_link_libraries(celix_rsa_common PUBLIC Celix::framework Celix::rsa_spi Celix::log_helper)
+
+install(TARGETS celix_rsa_common EXPORT celix COMPONENT rsa DESTINATION ${CMAKE_INSTALL_LIBDIR})
+
+#Setup target aliases to match external usage
+add_library(Celix::rsa_common ALIAS celix_rsa_common)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_common/src/endpoint_description.c
----------------------------------------------------------------------
diff --git a/remote_services/rsa_common/src/endpoint_description.c b/remote_services/rsa_common/src/endpoint_description.c
new file mode 100644
index 0000000..0d8b684
--- /dev/null
+++ b/remote_services/rsa_common/src/endpoint_description.c
@@ -0,0 +1,89 @@
+/**
+ *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.
+ */
+/*
+ * endpoint_description.c
+ *
+ * \date 25 Jul 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <string.h>
+
+#include "celix_errno.h"
+#include "celix_log.h"
+
+#include "endpoint_description.h"
+#include "remote_constants.h"
+#include "constants.h"
+
+static celix_status_t endpointDescription_verifyLongProperty(properties_pt properties, char *propertyName, unsigned long *longProperty);
+
+celix_status_t endpointDescription_create(properties_pt properties, endpoint_description_pt *endpointDescription) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ unsigned long serviceId = 0UL;
+ status = endpointDescription_verifyLongProperty(properties, (char *) OSGI_RSA_ENDPOINT_SERVICE_ID, &serviceId);
+ if (status != CELIX_SUCCESS) {
+ return status;
+ }
+
+ endpoint_description_pt ep = calloc(1,sizeof(*ep));
+
+ ep->properties = properties;
+ ep->frameworkUUID = (char*)properties_get(properties, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
+ ep->id = (char*)properties_get(properties, OSGI_RSA_ENDPOINT_ID);
+ ep->service = strndup(properties_get(properties, OSGI_FRAMEWORK_OBJECTCLASS), 1024*10);
+ ep->serviceId = serviceId;
+
+ if (!(ep->frameworkUUID) || !(ep->id) || !(ep->service) ) {
+ fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "ENDPOINT_DESCRIPTION: incomplete description!.");
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+
+ if(status == CELIX_SUCCESS){
+ *endpointDescription = ep;
+ }
+ else{
+ *endpointDescription = NULL;
+ free(ep);
+ }
+
+ return status;
+}
+
+celix_status_t endpointDescription_destroy(endpoint_description_pt description) {
+ properties_destroy(description->properties);
+ free(description->service);
+ free(description);
+ return CELIX_SUCCESS;
+}
+
+static celix_status_t endpointDescription_verifyLongProperty(properties_pt properties, char *propertyName, unsigned long *longProperty) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ const char *value = properties_get(properties, propertyName);
+ if (value == NULL) {
+ *longProperty = 0UL;
+ } else {
+ *longProperty = strtoul(value,NULL,10);
+ }
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_common/src/export_registration_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/rsa_common/src/export_registration_impl.c b/remote_services/rsa_common/src/export_registration_impl.c
new file mode 100644
index 0000000..1c684e7
--- /dev/null
+++ b/remote_services/rsa_common/src/export_registration_impl.c
@@ -0,0 +1,257 @@
+/**
+ *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.
+ */
+/*
+ * export_registration_impl.c
+ *
+ * \date Oct 6, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+
+#include "constants.h"
+
+#include "celix_errno.h"
+
+#include "export_registration_impl.h"
+#include "remote_service_admin_impl.h"
+
+
+struct export_reference {
+ endpoint_description_pt endpoint;
+ service_reference_pt reference;
+};
+
+celix_status_t exportRegistration_endpointAdding(void * handle, service_reference_pt reference, void **service);
+celix_status_t exportRegistration_endpointAdded(void * handle, service_reference_pt reference, void *service);
+celix_status_t exportRegistration_endpointModified(void * handle, service_reference_pt reference, void *service);
+celix_status_t exportRegistration_endpointRemoved(void * handle, service_reference_pt reference, void *service);
+
+celix_status_t exportRegistration_createEndpointTracker(export_registration_pt registration, service_tracker_pt *tracker);
+
+celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, remote_service_admin_pt rsa, bundle_context_pt context, export_registration_pt *registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *registration = calloc(1, sizeof(**registration));
+ if (!*registration) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*registration)->context = context;
+ (*registration)->closed = false;
+ (*registration)->endpointDescription = endpoint;
+ (*registration)->reference = reference;
+ (*registration)->rsa = rsa;
+ (*registration)->tracker = NULL;
+ (*registration)->endpoint = NULL;
+ (*registration)->endpointTracker = NULL;
+ (*registration)->exportReference = NULL;
+ (*registration)->bundle = NULL;
+ (*registration)->loghelper = helper;
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_destroy(export_registration_pt *registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ remoteServiceAdmin_destroyEndpointDescription(&(*registration)->endpointDescription);
+ free(*registration);
+
+ return status;
+}
+
+celix_status_t exportRegistration_startTracking(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (registration->endpointTracker == NULL) {
+ status = exportRegistration_createEndpointTracker(registration, ®istration->endpointTracker);
+ if (status == CELIX_SUCCESS) {
+ status = serviceTracker_open(registration->endpointTracker);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_stopTracking(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (registration->endpointTracker != NULL) {
+ status = serviceTracker_close(registration->endpointTracker);
+ if (status != CELIX_SUCCESS) {
+ logHelper_log(registration->loghelper, OSGI_LOGSERVICE_ERROR, "EXPORT_REGISTRATION: Could not close endpoint tracker");
+ }
+ else {
+ status = serviceTracker_destroy(registration->endpointTracker);
+ }
+ }
+ if (registration->tracker != NULL) {
+ status = serviceTracker_close(registration->tracker);
+ if (status != CELIX_SUCCESS) {
+ logHelper_log(registration->loghelper, OSGI_LOGSERVICE_ERROR, "EXPORT_REGISTRATION: Could not close service tracker");
+ }
+ else {
+ status = serviceTracker_destroy(registration->tracker);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_createEndpointTracker(export_registration_pt registration, service_tracker_pt *tracker) {
+ celix_status_t status;
+
+ service_tracker_customizer_pt customizer = NULL;
+
+ status = serviceTrackerCustomizer_create(registration, exportRegistration_endpointAdding,
+ exportRegistration_endpointAdded, exportRegistration_endpointModified, exportRegistration_endpointRemoved, &customizer);
+
+ if (status == CELIX_SUCCESS) {
+ char filter[512];
+
+ snprintf(filter, 512, "(&(%s=%s)(remote.interface=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, (char*) OSGI_RSA_REMOTE_ENDPOINT, registration->endpointDescription->service);
+ status = serviceTracker_createWithFilter(registration->context, filter, customizer, tracker);
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_endpointAdding(void * handle, service_reference_pt reference, void **service) {
+ celix_status_t status;
+ export_registration_pt registration = handle;
+
+ status = bundleContext_getService(registration->context, reference, service);
+
+ return status;
+}
+
+celix_status_t exportRegistration_endpointAdded(void * handle, service_reference_pt reference, void *endpoint_service) {
+ celix_status_t status = CELIX_SUCCESS;
+ export_registration_pt registration = handle;
+
+ remote_endpoint_service_pt endpoint = endpoint_service;
+ if (registration->endpoint == NULL) {
+ registration->endpoint = endpoint;
+ void *service = NULL;
+ status = bundleContext_getService(registration->context, registration->reference, &service);
+ if (status == CELIX_SUCCESS) {
+ endpoint->setService(endpoint->endpoint, service);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_endpointModified(void * handle, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ return status;
+}
+
+celix_status_t exportRegistration_endpointRemoved(void * handle, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+ export_registration_pt registration = handle;
+
+ remote_endpoint_service_pt endpoint = service;
+ if (registration->endpoint != NULL) {
+ endpoint->setService(endpoint->endpoint, NULL);
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_open(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ const char *bundleStore = NULL;
+
+ bundleContext_getProperty(registration->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore);
+
+ if (bundleStore == NULL) {
+ bundleStore = DEFAULT_BUNDLE_STORE;
+ }
+ char name[256];
+
+ snprintf(name, 256, "%s/%s_endpoint.zip", bundleStore, registration->endpointDescription->service);
+
+ status = bundleContext_installBundle(registration->context, name, ®istration->bundle);
+ if (status == CELIX_SUCCESS) {
+ status = bundle_start(registration->bundle);
+ if (status == CELIX_SUCCESS) {
+ }
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_close(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ exportRegistration_stopTracking(registration);
+
+ bundle_uninstall(registration->bundle);
+
+
+ return status;
+}
+
+celix_status_t exportRegistration_getException(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *reference) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ registration->exportReference = calloc(1, sizeof(*registration->exportReference));
+
+ if (registration->exportReference == NULL) {
+ status = CELIX_ENOMEM;
+ } else {
+ registration->exportReference->endpoint = registration->endpointDescription;
+ registration->exportReference->reference = registration->reference;
+ }
+
+ *reference = registration->exportReference;
+
+ return status;
+}
+
+celix_status_t exportRegistration_setEndpointDescription(export_registration_pt registration, endpoint_description_pt endpointDescription) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ registration->endpointDescription = endpointDescription;
+
+ return status;
+}
+
+celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *endpoint = reference->endpoint;
+
+ return status;
+}
+
+celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service) {
+ celix_status_t status = CELIX_SUCCESS;
+ *service = reference->reference;
+ return status;
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_common/src/export_registration_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/rsa_common/src/export_registration_impl.h b/remote_services/rsa_common/src/export_registration_impl.h
new file mode 100644
index 0000000..bb276f9
--- /dev/null
+++ b/remote_services/rsa_common/src/export_registration_impl.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.
+ */
+/*
+ * export_registration_impl.h
+ *
+ * \date Oct 6, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef EXPORT_REGISTRATION_IMPL_H_
+#define EXPORT_REGISTRATION_IMPL_H_
+
+#include "remote_service_admin.h"
+#include "remote_endpoint.h"
+#include "service_tracker.h"
+#include "log_helper.h"
+
+struct export_registration {
+ bundle_context_pt context;
+ remote_service_admin_pt rsa;
+ endpoint_description_pt endpointDescription;
+ service_reference_pt reference;
+ log_helper_pt loghelper;
+
+ service_tracker_pt tracker;
+ service_tracker_pt endpointTracker;
+
+ remote_endpoint_service_pt endpoint;
+
+ export_reference_pt exportReference;
+ bundle_pt bundle;
+
+ bool closed;
+};
+
+celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, remote_service_admin_pt rsa, bundle_context_pt context, export_registration_pt *registration);
+celix_status_t exportRegistration_destroy(export_registration_pt *registration);
+celix_status_t exportRegistration_open(export_registration_pt registration);
+
+celix_status_t exportRegistration_setEndpointDescription(export_registration_pt registration, endpoint_description_pt endpointDescription);
+celix_status_t exportRegistration_startTracking(export_registration_pt registration);
+celix_status_t exportRegistration_stopTracking(export_registration_pt registration);
+
+#endif /* EXPORT_REGISTRATION_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_common/src/import_registration_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/rsa_common/src/import_registration_impl.c b/remote_services/rsa_common/src/import_registration_impl.c
new file mode 100644
index 0000000..9a84327
--- /dev/null
+++ b/remote_services/rsa_common/src/import_registration_impl.c
@@ -0,0 +1,274 @@
+/**
+ *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.
+ */
+/*
+ * import_registration_impl.c
+ *
+ * \date Oct 14, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <constants.h>
+
+#include "celix_errno.h"
+
+#include "import_registration_impl.h"
+#include "remote_service_admin_impl.h"
+
+struct import_reference {
+ endpoint_description_pt endpoint;
+ service_reference_pt reference;
+};
+
+
+
+celix_status_t importRegistration_proxyFactoryAdding(void * handle, service_reference_pt reference, void **service);
+celix_status_t importRegistration_proxyFactoryAdded(void * handle, service_reference_pt reference, void *service);
+celix_status_t importRegistration_proxyFactoryModified(void * handle, service_reference_pt reference, void *service);
+celix_status_t importRegistration_proxyFactoryRemoved(void * handle, service_reference_pt reference, void *service);
+
+celix_status_t importRegistration_create(endpoint_description_pt endpoint, remote_service_admin_pt rsa, sendToHandle sendToCallback, bundle_context_pt context, import_registration_pt *registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *registration = calloc(1, sizeof(**registration));
+ if (!*registration) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*registration)->context = context;
+ (*registration)->closed = false;
+ (*registration)->endpointDescription = endpoint;
+ (*registration)->rsa = rsa;
+ (*registration)->sendToCallback = sendToCallback;
+ (*registration)->reference = NULL;
+ (*registration)->importReference = NULL;
+ }
+
+ return status;
+}
+
+celix_status_t importRegistration_destroy(import_registration_pt registration)
+{
+ free(registration);
+
+ return CELIX_SUCCESS;
+}
+
+
+celix_status_t importRegistrationFactory_create(log_helper_pt helper, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *registration_factory = calloc(1, sizeof(**registration_factory));
+ if (!*registration_factory) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*registration_factory)->serviceName = strdup(serviceName);
+ (*registration_factory)->context = context;
+ (*registration_factory)->bundle = NULL;
+ (*registration_factory)->loghelper = helper;
+
+ arrayList_create(&(*registration_factory)->registrations);
+ }
+
+ return status;
+}
+
+
+
+celix_status_t importRegistrationFactory_destroy(import_registration_factory_pt* registration_factory) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (*registration_factory != NULL)
+ {
+ free((*registration_factory)->serviceName);
+ arrayList_destroy((*registration_factory)->registrations);
+
+ serviceTracker_destroy((*registration_factory)->proxyFactoryTracker);
+ free(*registration_factory);
+
+ *registration_factory = NULL;
+ }
+
+
+ return status;
+}
+
+
+celix_status_t importRegistrationFactory_open(import_registration_factory_pt registration_factory)
+{
+ celix_status_t status;
+
+ const char *bundleStore = NULL;
+ bundleContext_getProperty(registration_factory->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore);
+
+ if (bundleStore == NULL) {
+ bundleStore = DEFAULT_BUNDLE_STORE;
+ }
+
+ char name[256];
+ snprintf(name, 256, "%s/%s_proxy.zip", bundleStore, registration_factory->serviceName);
+
+ status = bundleContext_installBundle(registration_factory->context, name, ®istration_factory->bundle);
+
+ if (status == CELIX_SUCCESS) {
+ status = bundle_start(registration_factory->bundle);
+ if (status == CELIX_SUCCESS) {
+ logHelper_log(registration_factory->loghelper, OSGI_LOGSERVICE_INFO, "%s successfully started.", name);
+ }
+ }
+ else {
+ logHelper_log(registration_factory->loghelper, OSGI_LOGSERVICE_ERROR, "%s could not be installed.", name);
+ }
+
+ return status;
+}
+
+celix_status_t importRegistrationFactory_close(import_registration_factory_pt registration_factory)
+{
+ celix_status_t status = CELIX_SUCCESS;
+
+
+ if (registration_factory->proxyFactoryTracker != NULL) {
+ serviceTracker_close(registration_factory->proxyFactoryTracker);
+ }
+
+ if (registration_factory->bundle != NULL) {
+ bundle_uninstall(registration_factory->bundle);
+ }
+
+ return status;
+}
+
+
+celix_status_t importRegistration_createProxyFactoryTracker(import_registration_factory_pt registration_factory, service_tracker_pt *tracker) {
+ celix_status_t status;
+ service_tracker_customizer_pt customizer = NULL;
+
+ status = serviceTrackerCustomizer_create(registration_factory, importRegistration_proxyFactoryAdding, importRegistration_proxyFactoryAdded, importRegistration_proxyFactoryModified, importRegistration_proxyFactoryRemoved, &customizer);
+
+ if (status == CELIX_SUCCESS) {
+ char filter[512];
+
+ snprintf(filter, 512, "(&(%s=%s)(proxy.interface=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, (char*) OSGI_RSA_REMOTE_PROXY_FACTORY, registration_factory->serviceName);
+ status = serviceTracker_createWithFilter(registration_factory->context, filter, customizer, tracker);
+
+ if (status == CELIX_SUCCESS)
+ {
+ serviceTracker_open(*tracker);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t importRegistration_proxyFactoryAdding(void * handle, service_reference_pt reference, void **service) {
+ celix_status_t status = CELIX_SUCCESS;
+ import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
+
+ bundleContext_getService(registration_factory->context, reference, service);
+
+ return status;
+}
+
+celix_status_t importRegistration_proxyFactoryAdded(void * handle, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
+ registration_factory->trackedFactory = (remote_proxy_factory_service_pt) service;
+
+ return status;
+}
+
+celix_status_t importRegistration_proxyFactoryModified(void * handle, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ return status;
+}
+
+celix_status_t importRegistration_proxyFactoryRemoved(void * handle, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
+ registration_factory->trackedFactory = NULL;
+
+ return status;
+}
+
+
+
+celix_status_t importRegistrationFactory_install(log_helper_pt helper, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory)
+{
+ celix_status_t status;
+
+ if ( (status = importRegistrationFactory_create(helper, serviceName, context, registration_factory)) == CELIX_SUCCESS) {
+ // starting the proxy tracker first allows us to pick up already available proxy factories
+ importRegistration_createProxyFactoryTracker(*registration_factory, &((*registration_factory)->proxyFactoryTracker));
+ logHelper_log((*registration_factory)->loghelper, OSGI_LOGSERVICE_INFO, "remoteServiceAdmin_importService: new registration_factory added for %s at %p", serviceName, (*registration_factory)->proxyFactoryTracker);
+
+ // check whether factory is available
+ if (((*registration_factory)->trackedFactory == NULL) && ((status = importRegistrationFactory_open(*registration_factory)) != CELIX_SUCCESS)) {
+ logHelper_log((*registration_factory)->loghelper, OSGI_LOGSERVICE_ERROR, "remoteServiceAdmin_importService: cannot open registration_factory for %s.", serviceName);
+
+ importRegistrationFactory_close(*registration_factory);
+ importRegistrationFactory_destroy(registration_factory);
+ }
+ }
+
+ return status;
+}
+
+
+
+
+celix_status_t importRegistration_getException(import_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+
+celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (registration->importReference == NULL) {
+ registration->importReference = calloc(1, sizeof(*registration->importReference));
+ if (registration->importReference == NULL) {
+ status = CELIX_ENOMEM;
+ } else {
+ registration->importReference->endpoint = registration->endpointDescription;
+ registration->importReference->reference = registration->reference;
+ }
+ }
+
+ *reference = registration->importReference;
+
+ return status;
+}
+
+
+celix_status_t importReference_getImportedEndpoint(import_reference_pt reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t importReference_getImportedService(import_reference_pt reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_common/src/import_registration_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/rsa_common/src/import_registration_impl.h b/remote_services/rsa_common/src/import_registration_impl.h
new file mode 100644
index 0000000..7aa397f
--- /dev/null
+++ b/remote_services/rsa_common/src/import_registration_impl.h
@@ -0,0 +1,81 @@
+/**
+ *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.
+ */
+/*
+ * import_registration_impl.h
+ *
+ * \date Oct 14, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef IMPORT_REGISTRATION_IMPL_H_
+#define IMPORT_REGISTRATION_IMPL_H_
+
+#include "remote_service_admin.h"
+#include "remote_proxy.h"
+#include "service_tracker.h"
+#include "log_helper.h"
+
+struct import_registration {
+ bundle_context_pt context;
+ endpoint_description_pt endpointDescription;
+
+ service_reference_pt reference;
+ import_reference_pt importReference;
+
+ remote_service_admin_pt rsa;
+ sendToHandle sendToCallback;
+
+ bool closed;
+};
+
+
+
+struct import_registration_factory
+{
+ char* serviceName;
+ log_helper_pt loghelper;
+ remote_proxy_factory_service_pt trackedFactory;
+ service_tracker_pt proxyFactoryTracker;
+ bundle_context_pt context;
+ array_list_pt registrations;
+ bundle_pt bundle;
+};
+
+
+celix_status_t importRegistration_create(endpoint_description_pt endpoint, remote_service_admin_pt rsa, sendToHandle callback, bundle_context_pt context, import_registration_pt *registration);
+celix_status_t importRegistration_destroy(import_registration_pt registration);
+
+celix_status_t importRegistration_setEndpointDescription(import_registration_pt registration, endpoint_description_pt endpointDescription);
+celix_status_t importRegistration_setHandler(import_registration_pt registration, void * handler);
+celix_status_t importRegistration_setCallback(import_registration_pt registration, sendToHandle callback);
+
+celix_status_t importRegistration_getException(import_registration_pt registration);
+celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference);
+
+celix_status_t importRegistration_createProxyFactoryTracker(import_registration_factory_pt registration_factory, service_tracker_pt *tracker);
+
+celix_status_t importRegistrationFactory_destroy(import_registration_factory_pt* registration_factory);
+//celix_status_t importRegistrationFactory_open(import_registration_factory_pt registration_factory);
+celix_status_t importRegistrationFactory_close(import_registration_factory_pt registration_factory);
+celix_status_t importRegistrationFactory_install(log_helper_pt helper, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory);
+
+
+
+#endif /* IMPORT_REGISTRATION_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_common/src/remote_proxy_factory_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/rsa_common/src/remote_proxy_factory_impl.c b/remote_services/rsa_common/src/remote_proxy_factory_impl.c
new file mode 100644
index 0000000..9f996d6
--- /dev/null
+++ b/remote_services/rsa_common/src/remote_proxy_factory_impl.c
@@ -0,0 +1,252 @@
+/**
+ * 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.
+ */
+
+/*
+ * remote_proxy_factory_impl.c
+ *
+ * \date 22 Dec 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "remote_proxy.h"
+
+typedef struct proxy_instance {
+ service_registration_pt registration_ptr;
+ void *service;
+ properties_pt properties;
+} *proxy_instance_pt;
+
+static celix_status_t remoteProxyFactory_registerProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback);
+static celix_status_t remoteProxyFactory_unregisterProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription);
+
+celix_status_t remoteProxyFactory_create(bundle_context_pt context, char *service, void *handle,
+ createProxyService create, destroyProxyService destroy,
+ remote_proxy_factory_pt *remote_proxy_factory_ptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *remote_proxy_factory_ptr = calloc(1, sizeof(**remote_proxy_factory_ptr));
+ if (!*remote_proxy_factory_ptr) {
+ status = CELIX_ENOMEM;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ (*remote_proxy_factory_ptr)->context_ptr = context;
+ (*remote_proxy_factory_ptr)->service = strdup(service);
+
+ (*remote_proxy_factory_ptr)->remote_proxy_factory_service_ptr = NULL;
+ (*remote_proxy_factory_ptr)->properties = NULL;
+ (*remote_proxy_factory_ptr)->registration = NULL;
+
+ (*remote_proxy_factory_ptr)->proxy_instances = hashMap_create(NULL, NULL, NULL, NULL);
+
+ (*remote_proxy_factory_ptr)->handle = handle;
+
+ (*remote_proxy_factory_ptr)->create_proxy_service_ptr = create;
+ (*remote_proxy_factory_ptr)->destroy_proxy_service_ptr = destroy;
+ }
+
+ return status;
+}
+
+celix_status_t remoteProxyFactory_destroy(remote_proxy_factory_pt *remote_proxy_factory_ptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!*remote_proxy_factory_ptr) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ if ((*remote_proxy_factory_ptr)->proxy_instances) {
+ hashMap_destroy((*remote_proxy_factory_ptr)->proxy_instances, false, false);
+ (*remote_proxy_factory_ptr)->proxy_instances = NULL;
+ }
+ if ((*remote_proxy_factory_ptr)->service) {
+ free((*remote_proxy_factory_ptr)->service);
+ (*remote_proxy_factory_ptr)->service = NULL;
+ }
+ free(*remote_proxy_factory_ptr);
+ *remote_proxy_factory_ptr = NULL;
+ }
+
+ return status;
+}
+
+celix_status_t remoteProxyFactory_register(remote_proxy_factory_pt remote_proxy_factory_ptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ remote_proxy_factory_ptr->remote_proxy_factory_service_ptr = calloc(1, sizeof(*remote_proxy_factory_ptr->remote_proxy_factory_service_ptr));
+ if (!remote_proxy_factory_ptr->remote_proxy_factory_service_ptr) {
+ status = CELIX_ENOMEM;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->factory = remote_proxy_factory_ptr;
+ remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->registerProxyService = remoteProxyFactory_registerProxyService;
+ remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->unregisterProxyService = remoteProxyFactory_unregisterProxyService;
+
+ remote_proxy_factory_ptr->properties = properties_create();
+ if (!remote_proxy_factory_ptr->properties) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ properties_set(remote_proxy_factory_ptr->properties, "proxy.interface", remote_proxy_factory_ptr->service);
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = bundleContext_registerService(remote_proxy_factory_ptr->context_ptr, OSGI_RSA_REMOTE_PROXY_FACTORY,
+ remote_proxy_factory_ptr->remote_proxy_factory_service_ptr, remote_proxy_factory_ptr->properties, &remote_proxy_factory_ptr->registration);
+ }
+
+ return status;
+}
+
+celix_status_t remoteProxyFactory_unregister(remote_proxy_factory_pt remote_proxy_factory_ptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!remote_proxy_factory_ptr) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ // #TODO Remove proxy registrations
+ if (status == CELIX_SUCCESS) {
+
+ hash_map_iterator_pt iter = hashMapIterator_create(remote_proxy_factory_ptr->proxy_instances);
+ while(hashMapIterator_hasNext(iter)){
+ proxy_instance_pt proxy_instance_ptr = (proxy_instance_pt)hashMapIterator_nextValue(iter);
+
+ if (proxy_instance_ptr->service) {
+ remote_proxy_factory_ptr->destroy_proxy_service_ptr(remote_proxy_factory_ptr->handle, proxy_instance_ptr->service);
+ }
+ free(proxy_instance_ptr);
+ }
+ hashMapIterator_destroy(iter);
+
+ if (remote_proxy_factory_ptr->registration) {
+ status = serviceRegistration_unregister(remote_proxy_factory_ptr->registration);
+ remote_proxy_factory_ptr->properties = NULL;
+ }
+ if (remote_proxy_factory_ptr->properties) {
+ properties_destroy(remote_proxy_factory_ptr->properties);
+ }
+ if (remote_proxy_factory_ptr->remote_proxy_factory_service_ptr) {
+ free(remote_proxy_factory_ptr->remote_proxy_factory_service_ptr);
+ }
+ }
+
+ return status;
+}
+
+
+static celix_status_t remoteProxyFactory_registerProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback) {
+ celix_status_t status = CELIX_SUCCESS;
+ proxy_instance_pt proxy_instance_ptr = NULL;
+
+ if (!remote_proxy_factory_ptr || !remote_proxy_factory_ptr->create_proxy_service_ptr) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ proxy_instance_ptr = calloc(1, sizeof(*proxy_instance_ptr));
+ if (!proxy_instance_ptr) {
+ status = CELIX_ENOMEM;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ proxy_instance_ptr->properties = properties_create();
+ if (!proxy_instance_ptr->properties) {
+ status = CELIX_ENOMEM;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = remote_proxy_factory_ptr->create_proxy_service_ptr(remote_proxy_factory_ptr->handle, endpointDescription, rsa, sendToCallback, proxy_instance_ptr->properties, &proxy_instance_ptr->service);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ properties_set(proxy_instance_ptr->properties, "proxy.interface", remote_proxy_factory_ptr->service);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(endpointDescription->properties);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ char *key = hashMapEntry_getKey(entry);
+ char *value = hashMapEntry_getValue(entry);
+
+ properties_set(proxy_instance_ptr->properties, key, value);
+ }
+ hashMapIterator_destroy(iter);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = bundleContext_registerService(remote_proxy_factory_ptr->context_ptr, remote_proxy_factory_ptr->service, proxy_instance_ptr->service, proxy_instance_ptr->properties, &proxy_instance_ptr->registration_ptr);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ hashMap_put(remote_proxy_factory_ptr->proxy_instances, endpointDescription, proxy_instance_ptr);
+ }
+
+ if(status!=CELIX_SUCCESS){
+ if(proxy_instance_ptr != NULL){
+ if(proxy_instance_ptr->properties != NULL){
+ properties_destroy(proxy_instance_ptr->properties);
+ }
+ free(proxy_instance_ptr);
+ }
+ }
+
+ return status;
+}
+
+static celix_status_t remoteProxyFactory_unregisterProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription) {
+ celix_status_t status = CELIX_SUCCESS;
+ proxy_instance_pt proxy_instance_ptr = NULL;
+
+ if (!remote_proxy_factory_ptr || !endpointDescription || !remote_proxy_factory_ptr->proxy_instances || !remote_proxy_factory_ptr->handle) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ proxy_instance_ptr = hashMap_remove(remote_proxy_factory_ptr->proxy_instances, endpointDescription);
+ if (proxy_instance_ptr == NULL) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ if (proxy_instance_ptr->registration_ptr) {
+ status = serviceRegistration_unregister(proxy_instance_ptr->registration_ptr);
+ proxy_instance_ptr->properties = NULL;
+ }
+ if (proxy_instance_ptr->service) {
+ status = remote_proxy_factory_ptr->destroy_proxy_service_ptr(remote_proxy_factory_ptr->handle, proxy_instance_ptr->service);
+ }
+ if (proxy_instance_ptr->properties) {
+ properties_destroy(proxy_instance_ptr->properties);
+ }
+ free(proxy_instance_ptr);
+ }
+
+ return status;
+}
+
+
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_common/src/remote_service_admin_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/rsa_common/src/remote_service_admin_impl.h b/remote_services/rsa_common/src/remote_service_admin_impl.h
new file mode 100644
index 0000000..e8a5e1f
--- /dev/null
+++ b/remote_services/rsa_common/src/remote_service_admin_impl.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.
+ */
+/*
+ * remote_service_admin_impl.h
+ *
+ * \date Dec 5, 2013
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef REMOTE_SERVICE_ADMIN_IMPL_H_
+#define REMOTE_SERVICE_ADMIN_IMPL_H_
+
+#include "remote_service_admin.h"
+
+#define BUNDLE_STORE_PROPERTY_NAME "ENDPOINTS"
+#define DEFAULT_BUNDLE_STORE "endpoints"
+
+celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin);
+celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin);
+
+celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *methodSignature, char **reply, int* replyStatus);
+
+celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
+celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration);
+celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services);
+celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services);
+celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
+celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration);
+
+celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description);
+
+#endif /* REMOTE_SERVICE_ADMIN_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_spi/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/rsa_spi/CMakeLists.txt b/remote_services/rsa_spi/CMakeLists.txt
new file mode 100644
index 0000000..ea4ec95
--- /dev/null
+++ b/remote_services/rsa_spi/CMakeLists.txt
@@ -0,0 +1,29 @@
+# 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.
+
+add_library(rsa_spi INTERFACE)
+target_include_directories(rsa_spi INTERFACE
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
+ $<INSTALL_INTERFACE:include/celix/rsa>
+)
+target_link_libraries(rsa_spi INTERFACE Celix::remote_services_api)
+
+install(TARGETS rsa_spi EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT rsa)
+install(DIRECTORY include/ DESTINATION include/celix/rsa COMPONENT rsa)
+
+#Setup target aliases to match external usage
+add_library(Celix::rsa_spi ALIAS rsa_spi)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_spi/README.md
----------------------------------------------------------------------
diff --git a/remote_services/rsa_spi/README.md b/remote_services/rsa_spi/README.md
new file mode 100644
index 0000000..2e3d268
--- /dev/null
+++ b/remote_services/rsa_spi/README.md
@@ -0,0 +1,11 @@
+# Remote Service Admin
+
+The Remote Service Admin (RSA) provides the mechanisms to import and export services when instructed to do so by the Topology Manager.
+
+To delegate method calls to the actual service implementation, the RSA_SHM and the RSA_HTTP are using "endpoint/proxy" bundles, which has all the knowledge about the marshalling and unmarshalling of data for the service. The RSA_DFI implementation combines a [foreign function interface](https://en.wikipedia.org/wiki/Foreign_function_interface) technique together with manualy created descriptors.
+
+Note that this folder contains code commonly used by the RSA implementations and therefore does not include any CMAKE configuration.
+
+## Properties
+ ENDPOINTS defines the relative directory where endpoints and proxys can be found (default: endpoints)
+ CELIX_FRAMEWORK_EXTENDER_PATH Used in RSA_DFI only. Can be used to define a path to use as an extender path point for the framework bundle. For normal bundles the bundle cache is used.
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_spi/include/endpoint_description.h
----------------------------------------------------------------------
diff --git a/remote_services/rsa_spi/include/endpoint_description.h b/remote_services/rsa_spi/include/endpoint_description.h
new file mode 100644
index 0000000..de27d2e
--- /dev/null
+++ b/remote_services/rsa_spi/include/endpoint_description.h
@@ -0,0 +1,50 @@
+/**
+ *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.
+ */
+/*
+ * endpoint_description.h
+ *
+ * \date 25 Jul 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef ENDPOINT_DESCRIPTION_H_
+#define ENDPOINT_DESCRIPTION_H_
+
+#include "properties.h"
+#include "array_list.h"
+
+struct endpoint_description {
+ char *frameworkUUID;
+ char *id;
+ // array_list_pt intents;
+ char *service;
+ // HASH_MAP packageVersions;
+ properties_pt properties;
+ unsigned long serviceId;
+};
+
+typedef struct endpoint_description endpoint_description_t;
+typedef endpoint_description_t* endpoint_description_pt;
+
+celix_status_t endpointDescription_create(properties_pt properties, endpoint_description_pt *endpointDescription);
+celix_status_t endpointDescription_destroy(endpoint_description_pt description);
+
+
+#endif /* ENDPOINT_DESCRIPTION_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_spi/include/endpoint_listener.h
----------------------------------------------------------------------
diff --git a/remote_services/rsa_spi/include/endpoint_listener.h b/remote_services/rsa_spi/include/endpoint_listener.h
new file mode 100644
index 0000000..2e6359f
--- /dev/null
+++ b/remote_services/rsa_spi/include/endpoint_listener.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.
+ */
+/*
+ * endpoint_listener.h
+ *
+ * \date Sep 29, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef ENDPOINT_LISTENER_H_
+#define ENDPOINT_LISTENER_H_
+
+#include "array_list.h"
+#include "properties.h"
+
+#include "endpoint_description.h"
+
+static const char * const OSGI_ENDPOINT_LISTENER_SERVICE = "endpoint_listener";
+
+static const char * const OSGI_ENDPOINT_LISTENER_SCOPE = "endpoint.listener.scope";
+
+struct endpoint_listener {
+ void *handle;
+ celix_status_t (*endpointAdded)(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
+ celix_status_t (*endpointRemoved)(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
+};
+
+typedef struct endpoint_listener endpoint_listener_t;
+typedef endpoint_listener_t *endpoint_listener_pt;
+
+
+#endif /* ENDPOINT_LISTENER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_spi/include/export_registration.h
----------------------------------------------------------------------
diff --git a/remote_services/rsa_spi/include/export_registration.h b/remote_services/rsa_spi/include/export_registration.h
new file mode 100644
index 0000000..dc3882b
--- /dev/null
+++ b/remote_services/rsa_spi/include/export_registration.h
@@ -0,0 +1,22 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#ifndef CELIX_EXPORT_REGISTRATION_H
+#define CELIX_EXPORT_REGISTRATION_H
+
+#include "celix_errno.h"
+#include "endpoint_description.h"
+#include "service_reference.h"
+
+typedef struct export_registration *export_registration_pt;
+
+typedef struct export_reference *export_reference_pt;
+
+celix_status_t exportRegistration_close(export_registration_pt registration);
+celix_status_t exportRegistration_getException(export_registration_pt registration);
+celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *reference);
+
+celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint);
+celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service);
+
+#endif //CELIX_EXPORT_REGISTRATION_H
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_spi/include/import_registration.h
----------------------------------------------------------------------
diff --git a/remote_services/rsa_spi/include/import_registration.h b/remote_services/rsa_spi/include/import_registration.h
new file mode 100644
index 0000000..ef8193f
--- /dev/null
+++ b/remote_services/rsa_spi/include/import_registration.h
@@ -0,0 +1,22 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#ifndef CELIX_IMPORT_REGISTRATION_H
+#define CELIX_IMPORT_REGISTRATION_H
+
+#include "celix_errno.h"
+#include "endpoint_description.h"
+#include "service_reference.h"
+
+typedef struct import_registration *import_registration_pt;
+
+typedef struct import_reference *import_reference_pt;
+
+celix_status_t importRegistration_close(import_registration_pt registration);
+celix_status_t importRegistration_getException(import_registration_pt registration);
+celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference);
+
+celix_status_t importReference_getImportedEndpoint(import_reference_pt reference);
+celix_status_t importReference_getImportedService(import_reference_pt reference);
+
+#endif //CELIX_IMPORT_REGISTRATION_H
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_spi/include/remote_constants.h
----------------------------------------------------------------------
diff --git a/remote_services/rsa_spi/include/remote_constants.h b/remote_services/rsa_spi/include/remote_constants.h
new file mode 100644
index 0000000..0736685
--- /dev/null
+++ b/remote_services/rsa_spi/include/remote_constants.h
@@ -0,0 +1,38 @@
+/**
+ *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.
+ */
+/*
+ * remote_constants.h
+ *
+ * \date Sep 30, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef REMOTE_CONSTANTS_H_
+#define REMOTE_CONSTANTS_H_
+
+static const char * const OSGI_RSA_SERVICE_EXPORTED_INTERFACES = "service.exported.interfaces";
+static const char * const OSGI_RSA_ENDPOINT_FRAMEWORK_UUID = "endpoint.framework.uuid";
+static const char * const OSGI_RSA_ENDPOINT_SERVICE_ID = "endpoint.service.id";
+static const char * const OSGI_RSA_ENDPOINT_ID = "endpoint.id";
+static const char * const OSGI_RSA_SERVICE_IMPORTED = "service.imported";
+static const char * const OSGI_RSA_SERVICE_IMPORTED_CONFIGS = "service.imported.configs";
+static const char * const OSGI_RSA_SERVICE_LOCATION = "service.location";
+
+#endif /* REMOTE_CONSTANTS_H_ */
[49/54] [abbrv] celix git commit: CELIX-417: Fixes install location
of the CelixConfig.cmake file,
so that the CMake find_package will automatically find it
Posted by pn...@apache.org.
CELIX-417: Fixes install location of the CelixConfig.cmake file, so that the CMake find_package will automatically find it
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/e08b428a
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/e08b428a
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/e08b428a
Branch: refs/heads/develop
Commit: e08b428a83863b22d84100440d1b0a5c70f933b5
Parents: 984b19f
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Jan 30 12:20:32 2018 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Jan 30 12:20:32 2018 +0100
----------------------------------------------------------------------
CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/e08b428a/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 21117bb..0ad6145 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -106,4 +106,4 @@ configure_file(cmake/CelixConfigVersion.cmake.in
install(FILES
"cmake/CelixConfig.cmake"
"${PROJECT_BINARY_DIR}/celix/gen/CelixConfigVersion.cmake"
- DESTINATION "${CMAKE_INSTALL_LIBDIR}/CMake/Celix" COMPONENT cmake)
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Celix" COMPONENT cmake)
[21/54] [abbrv] celix git commit: CELIX-417: Refactors CMake usage
for the RSA bundles
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_dfi.c
deleted file mode 100644
index 9feab9f..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_dfi.c
+++ /dev/null
@@ -1,775 +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.
- */
-/*
- * remote_service_admin_impl.c
- *
- * \date May 21, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <ifaddrs.h>
-#include <string.h>
-#include <uuid/uuid.h>
-#include <curl/curl.h>
-
-#include <jansson.h>
-#include "json_serializer.h"
-#include "remote_service_admin.h"
-#include "celix_threads.h"
-#include "hash_map.h"
-#include "array_list.h"
-
-#include "import_registration_dfi.h"
-#include "export_registration_dfi.h"
-#include "remote_service_admin_dfi.h"
-#include "dyn_interface.h"
-#include "json_rpc.h"
-
-#include "remote_constants.h"
-#include "constants.h"
-#include "civetweb.h"
-
-// defines how often the webserver is restarted (with an increased port number)
-#define MAX_NUMBER_OF_RESTARTS 5
-
-
-#define RSA_LOG_ERROR(admin, msg, ...) \
- logHelper_log((admin)->loghelper, OSGI_LOGSERVICE_ERROR, (msg), ##__VA_ARGS__)
-
-#define RSA_LOG_WARNING(admin, msg, ...) \
- logHelper_log((admin)->loghelper, OSGI_LOGSERVICE_ERROR, (msg), ##__VA_ARGS__)
-
-#define RSA_LOG_DEBUG(admin, msg, ...) \
- logHelper_log((admin)->loghelper, OSGI_LOGSERVICE_ERROR, (msg), ##__VA_ARGS__)
-
-struct remote_service_admin {
- bundle_context_pt context;
- log_helper_pt loghelper;
-
- celix_thread_mutex_t exportedServicesLock;
- hash_map_pt exportedServices;
-
- celix_thread_mutex_t importedServicesLock;
- array_list_pt importedServices;
-
- char *port;
- char *ip;
-
- struct mg_context *ctx;
-};
-
-struct post {
- const char *readptr;
- int size;
-};
-
-struct get {
- char *writeptr;
- int size;
-};
-
-#define OSGI_RSA_REMOTE_PROXY_FACTORY "remote_proxy_factory"
-#define OSGI_RSA_REMOTE_PROXY_TIMEOUT "remote_proxy_timeout"
-
-static const char *data_response_headers =
- "HTTP/1.1 200 OK\r\n"
- "Cache: no-cache\r\n"
- "Content-Type: application/json\r\n"
- "\r\n";
-
-static const char *no_content_response_headers =
- "HTTP/1.1 204 OK\r\n";
-
-// TODO do we need to specify a non-Amdatu specific configuration type?!
-static const char * const CONFIGURATION_TYPE = "org.amdatu.remote.admin.http";
-static const char * const ENDPOINT_URL = "org.amdatu.remote.admin.http.url";
-
-static const char *DEFAULT_PORT = "8888";
-static const char *DEFAULT_IP = "127.0.0.1";
-
-static const unsigned int DEFAULT_TIMEOUT = 0;
-
-static int remoteServiceAdmin_callback(struct mg_connection *conn);
-static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, properties_pt props, char *interface, endpoint_description_pt *description);
-static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
-static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip);
-static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp);
-static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp);
-static void remoteServiceAdmin_log(remote_service_admin_pt admin, int level, const char *file, int line, const char *msg, ...);
-
-celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin) {
- celix_status_t status = CELIX_SUCCESS;
-
- *admin = calloc(1, sizeof(**admin));
-
- if (!*admin) {
- status = CELIX_ENOMEM;
- } else {
- unsigned int port_counter = 0;
- const char *port = NULL;
- const char *ip = NULL;
- char *detectedIp = NULL;
- (*admin)->context = context;
- (*admin)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL);
- arrayList_create(&(*admin)->importedServices);
-
- celixThreadMutex_create(&(*admin)->exportedServicesLock, NULL);
- celixThreadMutex_create(&(*admin)->importedServicesLock, NULL);
-
- if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
- logHelper_start((*admin)->loghelper);
- dynCommon_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
- dynType_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
- dynFunction_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
- dynInterface_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
- jsonSerializer_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
- jsonRpc_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
- }
-
- bundleContext_getProperty(context, "RSA_PORT", &port);
- if (port == NULL) {
- port = (char *)DEFAULT_PORT;
- }
-
- bundleContext_getProperty(context, "RSA_IP", &ip);
- if (ip == NULL) {
- const char *interface = NULL;
-
- bundleContext_getProperty(context, "RSA_INTERFACE", &interface);
- if ((interface != NULL) && (remoteServiceAdmin_getIpAdress((char*)interface, &detectedIp) != CELIX_SUCCESS)) {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: Could not retrieve IP adress for interface %s", interface);
- }
-
- if (ip == NULL) {
- remoteServiceAdmin_getIpAdress(NULL, &detectedIp);
- }
-
- ip = detectedIp;
- }
-
- if (ip != NULL) {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Using %s for service annunciation", ip);
- (*admin)->ip = strdup(ip);
- }
- else {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No IP address for service annunciation set. Using %s", DEFAULT_IP);
- (*admin)->ip = strdup((char*) DEFAULT_IP);
- }
-
- if (detectedIp != NULL) {
- free(detectedIp);
- }
-
- // Prepare callbacks structure. We have only one callback, the rest are NULL.
- struct mg_callbacks callbacks;
- memset(&callbacks, 0, sizeof(callbacks));
- callbacks.begin_request = remoteServiceAdmin_callback;
-
- char newPort[10];
-
- do {
-
- const char *options[] = { "listening_ports", port, "num_threads", "5", NULL};
-
- (*admin)->ctx = mg_start(&callbacks, (*admin), options);
-
- if ((*admin)->ctx != NULL) {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Start webserver: %s", port);
- (*admin)->port = strdup(port);
-
- }
- else {
- errno = 0;
- char* endptr = (char*)port;
- int currentPort = strtol(port, &endptr, 10);
-
- if (*endptr || errno != 0) {
- currentPort = strtol(DEFAULT_PORT, NULL, 10);
- }
-
- port_counter++;
- snprintf(&newPort[0], 6, "%d", (currentPort+1));
-
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_ERROR, "Error while starting rsa server on port %s - retrying on port %s...", port, newPort);
- port = newPort;
- }
- } while(((*admin)->ctx == NULL) && (port_counter < MAX_NUMBER_OF_RESTARTS));
-
- }
-
- return status;
-}
-
-
-celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin)
-{
- celix_status_t status = CELIX_SUCCESS;
-
- free((*admin)->ip);
- free((*admin)->port);
- free(*admin);
-
- //TODO destroy exports/imports
-
- *admin = NULL;
-
- return status;
-}
-
-
-celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin) {
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&admin->exportedServicesLock);
-
- hash_map_iterator_pt iter = hashMapIterator_create(admin->exportedServices);
- while (hashMapIterator_hasNext(iter)) {
- array_list_pt exports = hashMapIterator_nextValue(iter);
- int i;
- for (i = 0; i < arrayList_size(exports); i++) {
- export_registration_pt export = arrayList_get(exports, i);
- if (export != NULL) {
- exportRegistration_stop(export);
- exportRegistration_destroy(export);
- }
- }
- arrayList_destroy(exports);
- }
- hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&admin->exportedServicesLock);
-
- celixThreadMutex_lock(&admin->importedServicesLock);
- int i;
- int size = arrayList_size(admin->importedServices);
- for (i = 0; i < size ; i += 1) {
- import_registration_pt import = arrayList_get(admin->importedServices, i);
- if (import != NULL) {
- importRegistration_stop(import);
- importRegistration_destroy(import);
- }
- }
- celixThreadMutex_unlock(&admin->importedServicesLock);
-
- if (admin->ctx != NULL) {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Stopping webserver...");
- mg_stop(admin->ctx);
- admin->ctx = NULL;
- }
-
- hashMap_destroy(admin->exportedServices, false, false);
- arrayList_destroy(admin->importedServices);
-
- logHelper_stop(admin->loghelper);
- logHelper_destroy(&admin->loghelper);
-
- return status;
-}
-
-/**
- * Request: http://host:port/services/{service}/{request}
- */
-//void *remoteServiceAdmin_callback(enum mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info) {
-
-celix_status_t importRegistration_getFactory(import_registration_pt import, service_factory_pt *factory);
-
-static int remoteServiceAdmin_callback(struct mg_connection *conn) {
- int result = 1; // zero means: let civetweb handle it further, any non-zero value means it is handled by us...
-
- const struct mg_request_info *request_info = mg_get_request_info(conn);
- if (request_info->uri != NULL) {
- remote_service_admin_pt rsa = request_info->user_data;
-
-
- if (strncmp(request_info->uri, "/service/", 9) == 0 && strcmp("POST", request_info->request_method) == 0) {
-
- // uri = /services/myservice/call
- const char *uri = request_info->uri;
- // rest = myservice/call
-
- const char *rest = uri+9;
- char *interfaceStart = strchr(rest, '/');
- int pos = interfaceStart - rest;
- char service[pos+1];
- strncpy(service, rest, pos);
- service[pos] = '\0';
- unsigned long serviceId = strtoul(service,NULL,10);
-
- celixThreadMutex_lock(&rsa->exportedServicesLock);
-
- //find endpoint
- export_registration_pt export = NULL;
- hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- array_list_pt exports = hashMapEntry_getValue(entry);
- int expIt = 0;
- for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
- export_registration_pt check = arrayList_get(exports, expIt);
- export_reference_pt ref = NULL;
- exportRegistration_getExportReference(check, &ref);
- endpoint_description_pt checkEndpoint = NULL;
- exportReference_getExportedEndpoint(ref, &checkEndpoint);
- if (serviceId == checkEndpoint->serviceId) {
- export = check;
- free(ref);
- break;
- }
- free(ref);
- }
- }
- hashMapIterator_destroy(iter);
-
- if (export != NULL) {
-
- uint64_t datalength = request_info->content_length;
- char* data = malloc(datalength + 1);
- mg_read(conn, data, datalength);
- data[datalength] = '\0';
-
- char *response = NULL;
- int responceLength = 0;
- int rc = exportRegistration_call(export, data, -1, &response, &responceLength);
- if (rc != CELIX_SUCCESS) {
- RSA_LOG_ERROR(rsa, "Error trying to invoke remove service, got error %i\n", rc);
- }
-
- if (rc == CELIX_SUCCESS && response != NULL) {
- mg_write(conn, data_response_headers, strlen(data_response_headers));
- mg_write(conn, response, strlen(response));
- free(response);
- } else {
- mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
- }
- result = 1;
-
- free(data);
- } else {
- result = 0;
- RSA_LOG_WARNING(rsa, "NO export registration found for service id %lu", serviceId);
- }
-
- celixThreadMutex_unlock(&rsa->exportedServicesLock);
-
- }
- }
-
- return result;
-}
-
-celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations) {
- celix_status_t status;
-
- arrayList_create(registrations);
- array_list_pt references = NULL;
- service_reference_pt reference = NULL;
- char filter [256];
-
- snprintf(filter, 256, "(%s=%s)", (char *)OSGI_FRAMEWORK_SERVICE_ID, serviceId);
-
- status = bundleContext_getServiceReferences(admin->context, NULL, filter, &references);
-
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: exportService called for serviceId %s", serviceId);
-
- int i;
- int size = arrayList_size(references);
- for (i = 0; i < size; i += 1) {
- if (i == 0) {
- reference = arrayList_get(references, i);
- } else {
- bundleContext_ungetServiceReference(admin->context, arrayList_get(references, i));
- }
- }
- arrayList_destroy(references);
-
- if (reference == NULL) {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "ERROR: expected a reference for service id %s.", serviceId);
- status = CELIX_ILLEGAL_STATE;
- }
-
- const char *exports = NULL;
- const char *provided = NULL;
- if (status == CELIX_SUCCESS) {
- serviceReference_getProperty(reference, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exports);
- serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_OBJECTCLASS, &provided);
-
- if (exports == NULL || provided == NULL || strcmp(exports, provided) != 0) {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No Services to export.");
- status = CELIX_ILLEGAL_STATE;
- } else {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Export service (%s)", provided);
- }
- }
-
- if (status == CELIX_SUCCESS) {
- const char *interface = provided;
- endpoint_description_pt endpoint = NULL;
- export_registration_pt registration = NULL;
-
- remoteServiceAdmin_createEndpointDescription(admin, reference, properties, (char*)interface, &endpoint);
- //TODO precheck if descriptor exists
- status = exportRegistration_create(admin->loghelper, reference, endpoint, admin->context, ®istration);
- if (status == CELIX_SUCCESS) {
- status = exportRegistration_start(registration);
- if (status == CELIX_SUCCESS) {
- arrayList_add(*registrations, registration);
- }
- }
- }
-
-
- if (status == CELIX_SUCCESS) {
- celixThreadMutex_lock(&admin->exportedServicesLock);
- hashMap_put(admin->exportedServices, reference, *registrations);
- celixThreadMutex_unlock(&admin->exportedServicesLock);
- }
- else{
- arrayList_destroy(*registrations);
- *registrations = NULL;
- }
-
- return status;
-}
-
-celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration) {
- celix_status_t status;
-
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_DFI: Removing exported service");
-
- export_reference_pt ref = NULL;
- status = exportRegistration_getExportReference(registration, &ref);
-
- if (status == CELIX_SUCCESS && ref != NULL) {
- service_reference_pt servRef;
- celixThreadMutex_lock(&admin->exportedServicesLock);
- exportReference_getExportedService(ref, &servRef);
-
- array_list_pt exports = (array_list_pt)hashMap_remove(admin->exportedServices, servRef);
- if(exports!=NULL){
- arrayList_destroy(exports);
- }
-
- exportRegistration_close(registration);
- exportRegistration_destroy(registration);
-
- celixThreadMutex_unlock(&admin->exportedServicesLock);
-
- free(ref);
-
- } else {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "Cannot find reference for registration");
- }
-
- return status;
-}
-
-static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, properties_pt props, char *interface, endpoint_description_pt *endpoint) {
-
- celix_status_t status = CELIX_SUCCESS;
- properties_pt endpointProperties = properties_create();
-
-
- unsigned int size = 0;
- char **keys;
-
- serviceReference_getPropertyKeys(reference, &keys, &size);
- for (int i = 0; i < size; i++) {
- char *key = keys[i];
- const char *value = NULL;
-
- if (serviceReference_getProperty(reference, key, &value) == CELIX_SUCCESS
- && strcmp(key, (char*) OSGI_RSA_SERVICE_EXPORTED_INTERFACES) != 0
- && strcmp(key, (char*) OSGI_FRAMEWORK_OBJECTCLASS) != 0) {
- properties_set(endpointProperties, key, value);
- }
- }
-
- hash_map_entry_pt entry = hashMap_getEntry(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
-
- char* key = hashMapEntry_getKey(entry);
- char *serviceId = (char *) hashMap_remove(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
- const char *uuid = NULL;
-
- char buf[512];
- snprintf(buf, 512, "/service/%s/%s", serviceId, interface);
-
- char url[1024];
- snprintf(url, 1024, "http://%s:%s%s", admin->ip, admin->port, buf);
-
- uuid_t endpoint_uid;
- uuid_generate(endpoint_uid);
- char endpoint_uuid[37];
- uuid_unparse_lower(endpoint_uid, endpoint_uuid);
-
- bundleContext_getProperty(admin->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
- properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
- properties_set(endpointProperties, (char*) OSGI_FRAMEWORK_OBJECTCLASS, interface);
- properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_SERVICE_ID, serviceId);
- properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID, endpoint_uuid);
- properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED, "true");
- properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED_CONFIGS, (char*) CONFIGURATION_TYPE);
- properties_set(endpointProperties, (char*) ENDPOINT_URL, url);
-
- if (props != NULL) {
- hash_map_iterator_pt propIter = hashMapIterator_create(props);
- while (hashMapIterator_hasNext(propIter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(propIter);
- properties_set(endpointProperties, (char*)hashMapEntry_getKey(entry), (char*)hashMapEntry_getValue(entry));
- }
- hashMapIterator_destroy(propIter);
- }
-
- *endpoint = calloc(1, sizeof(**endpoint));
- if (!*endpoint) {
- status = CELIX_ENOMEM;
- } else {
- (*endpoint)->id = (char*)properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID);
- const char *serviceId = NULL;
- serviceReference_getProperty(reference, (char*) OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
- (*endpoint)->serviceId = strtoull(serviceId, NULL, 0);
- (*endpoint)->frameworkUUID = (char*) properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
- (*endpoint)->service = strndup(interface, 1024*10);
- (*endpoint)->properties = endpointProperties;
- }
-
- free(key);
- free(serviceId);
- free(keys);
-
- return status;
-}
-
-static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip) {
- celix_status_t status = CELIX_BUNDLE_EXCEPTION;
-
- struct ifaddrs *ifaddr, *ifa;
- char host[NI_MAXHOST];
-
- if (getifaddrs(&ifaddr) != -1)
- {
- for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
- {
- if (ifa->ifa_addr == NULL)
- continue;
-
- if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
- if (interface == NULL) {
- *ip = strdup(host);
- status = CELIX_SUCCESS;
- }
- else if (strcmp(ifa->ifa_name, interface) == 0) {
- *ip = strdup(host);
- status = CELIX_SUCCESS;
- }
- }
- }
-
- freeifaddrs(ifaddr);
- }
-
- return status;
-}
-
-
-celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description)
-{
- celix_status_t status = CELIX_SUCCESS;
-
- properties_destroy((*description)->properties);
- free((*description)->service);
- free(*description);
-
- return status;
-}
-
-
-celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpointDescription, import_registration_pt *out) {
- celix_status_t status = CELIX_SUCCESS;
- import_registration_pt import = NULL;
-
- const char *objectClass = properties_get(endpointDescription->properties, "objectClass");
- const char *serviceVersion = properties_get(endpointDescription->properties, (char*) CELIX_FRAMEWORK_SERVICE_VERSION);
-
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Import service %s", endpointDescription->service);
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "Registering service factory (proxy) for service '%s'\n", objectClass);
-
- if (objectClass != NULL) {
- status = importRegistration_create(admin->context, endpointDescription, objectClass, serviceVersion, &import);
- }
- if (status == CELIX_SUCCESS && import != NULL) {
- importRegistration_setSendFn(import, (send_func_type) remoteServiceAdmin_send, admin);
- }
-
- if (status == CELIX_SUCCESS && import != NULL) {
- status = importRegistration_start(import);
- }
-
- celixThreadMutex_lock(&admin->importedServicesLock);
- arrayList_add(admin->importedServices, import);
- celixThreadMutex_unlock(&admin->importedServicesLock);
-
- if (status == CELIX_SUCCESS) {
- *out = import;
- }
-
- return status;
-}
-
-
-celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_DFI: Removing imported service");
-
- celixThreadMutex_lock(&admin->importedServicesLock);
- int i;
- int size = arrayList_size(admin->importedServices);
- import_registration_pt current = NULL;
- for (i = 0; i < size; i += 1) {
- current = arrayList_get(admin->importedServices, i);
- if (current == registration) {
- arrayList_remove(admin->importedServices, i);
- importRegistration_close(current);
- importRegistration_destroy(current);
- break;
- }
- }
- celixThreadMutex_unlock(&admin->importedServicesLock);
-
- return status;
-}
-
-
-static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus) {
- remote_service_admin_pt rsa = handle;
- struct post post;
- post.readptr = request;
- post.size = strlen(request);
-
- struct get get;
- get.size = 0;
- get.writeptr = malloc(1);
-
- char *serviceUrl = (char*)properties_get(endpointDescription->properties, (char*) ENDPOINT_URL);
- char url[256];
- snprintf(url, 256, "%s", serviceUrl);
-
- // assume the default timeout
- int timeout = DEFAULT_TIMEOUT;
-
- const char *timeoutStr = NULL;
- // Check if the endpoint has a timeout, if so, use it.
- timeoutStr = (char*) properties_get(endpointDescription->properties, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT);
- if (timeoutStr == NULL) {
- // If not, get the global variable and use that one.
- bundleContext_getProperty(rsa->context, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT, &timeoutStr);
- }
-
- // Update timeout if a property is used to set it.
- if (timeoutStr != NULL) {
- timeout = atoi(timeoutStr);
- }
-
- celix_status_t status = CELIX_SUCCESS;
- CURL *curl;
- CURLcode res;
-
- curl = curl_easy_init();
- if(!curl) {
- status = CELIX_ILLEGAL_STATE;
- } else {
- curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
- curl_easy_setopt(curl, CURLOPT_URL, url);
- curl_easy_setopt(curl, CURLOPT_POST, 1L);
- curl_easy_setopt(curl, CURLOPT_READFUNCTION, remoteServiceAdmin_readCallback);
- curl_easy_setopt(curl, CURLOPT_READDATA, &post);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, remoteServiceAdmin_write);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&get);
- curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)post.size);
- logHelper_log(rsa->loghelper, OSGI_LOGSERVICE_DEBUG, "RSA: Performing curl post\n");
- res = curl_easy_perform(curl);
-
- *reply = get.writeptr;
- *replyStatus = res;
-
- curl_easy_cleanup(curl);
- }
-
- return status;
-}
-
-static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp) {
- struct post *post = userp;
-
- if (post->size) {
- *(char *) ptr = post->readptr[0];
- post->readptr++;
- post->size--;
- return 1;
- }
-
- return 0;
-}
-
-static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp) {
- size_t realsize = size * nmemb;
- struct get *mem = (struct get *)userp;
-
- mem->writeptr = realloc(mem->writeptr, mem->size + realsize + 1);
- if (mem->writeptr == NULL) {
- /* out of memory! */
- printf("not enough memory (realloc returned NULL)");
- exit(EXIT_FAILURE);
- }
-
- memcpy(&(mem->writeptr[mem->size]), contents, realsize);
- mem->size += realsize;
- mem->writeptr[mem->size] = 0;
-
- return realsize;
-}
-
-
-static void remoteServiceAdmin_log(remote_service_admin_pt admin, int level, const char *file, int line, const char *msg, ...) {
- va_list ap;
- va_start(ap, msg);
- int levels[5] = {0, OSGI_LOGSERVICE_ERROR, OSGI_LOGSERVICE_WARNING, OSGI_LOGSERVICE_INFO, OSGI_LOGSERVICE_DEBUG};
-
- char buf1[256];
- snprintf(buf1, 256, "FILE:%s, LINE:%i, MSG:", file, line);
-
- char buf2[256];
- vsnprintf(buf2, 256, msg, ap);
- logHelper_log(admin->loghelper, levels[level], "%s%s", buf1, buf2);
- va_end(ap);
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_dfi.h b/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_dfi.h
deleted file mode 100644
index 8b282f1..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/src/remote_service_admin_dfi.h
+++ /dev/null
@@ -1,57 +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.
- */
-/*
- * remote_service_admin_http_impl.h
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
-#define REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
-
-
-#include "bundle_context.h"
-#include "endpoint_description.h"
-
-//typedef struct remote_service_admin *remote_service_admin_pt;
-
-celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin);
-celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin);
-
-celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin);
-
-celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
-celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration);
-celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services);
-celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services);
-celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
-celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration);
-
-
-celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint);
-celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service);
-
-celix_status_t importReference_getImportedEndpoint(import_reference_pt reference);
-celix_status_t importReference_getImportedService(import_reference_pt reference);
-
-celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description);
-
-#endif /* REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt b/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
deleted file mode 100644
index b3b272e..0000000
--- a/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
+++ /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.
-
-include_directories(
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include
- ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include
- bundle
-)
-
-add_subdirectory(bundle)
-
-SET(CMAKE_SKIP_BUILD_RPATH FALSE) #TODO needed?
-SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) #TODO needed?
-SET(CMAKE_INSTALL_RPATH "${PROJECT_BINARY_DIR}/framework" "${PROJECT_BINARY_DIR}/utils" "${PROJECT_BINARY_DIR}/dfi")
-
-add_executable(test_rsa_dfi
- run_tests.cpp
- rsa_tests.cpp
- rsa_client_server_tests.cpp
-)
-target_link_libraries(test_rsa_dfi PRIVATE Celix::framework ${CURL_LIBRARIES} ${CPPUTEST_LIBRARY} remote_service_admin_common)
-
-get_property(rsa_bundle_file TARGET remote_service_admin_dfi PROPERTY BUNDLE_FILE)
-get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE_FILE)
-get_property(calculator_shell_bundle_file TARGET calculator_shell PROPERTY BUNDLE_FILE)
-get_property(discovery_configured_bundle_file TARGET discovery_configured PROPERTY BUNDLE_FILE)
-get_property(topology_manager_bundle_file TARGET topology_manager PROPERTY BUNDLE_FILE)
-get_property(tst_bundle_file TARGET rsa_dfi_tst_bundle PROPERTY BUNDLE_FILE)
-
-configure_file(config.properties.in config.properties)
-configure_file(client.properties.in client.properties)
-configure_file(server.properties.in server.properties)
-
-add_dependencies(test_rsa_dfi remote_service_admin_dfi calculator)
-
-add_test(NAME run_test_rsa_dfi COMMAND test_rsa_dfi)
-SETUP_TARGET_FOR_COVERAGE(test_rsa_dfi_cov test_rsa_dfi ${CMAKE_BINARY_DIR}/coverage/test_rsa_dfi/test_rsa_dfi)
-
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt
deleted file mode 100644
index 65b18e8..0000000
--- a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt
+++ /dev/null
@@ -1,29 +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.
-
-add_bundle(rsa_dfi_tst_bundle
- VERSION 0.0.1
- SOURCES
- tst_activator.c
-)
-
-bundle_files(rsa_dfi_tst_bundle
- ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_api/include/org.apache.celix.calc.api.Calculator2.descriptor
- DESTINATION .
-)
-target_include_directories(rsa_dfi_tst_bundle PRIVATE calculator)
-target_link_libraries(rsa_dfi_tst_bundle PRIVATE ${CPPUTEST_LIBRARY} calculator_api)
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c
deleted file mode 100644
index f5838f8..0000000
--- a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c
+++ /dev/null
@@ -1,153 +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.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <service_tracker_customizer.h>
-#include <service_tracker.h>
-
-#include "bundle_activator.h"
-#include "bundle_context.h"
-#include "service_registration.h"
-#include "service_reference.h"
-#include "celix_errno.h"
-
-#include "tst_service.h"
-#include "calculator_service.h"
-
-
-struct activator {
- bundle_context_pt context;
- struct tst_service serv;
- service_registration_pt reg;
-
- service_tracker_customizer_pt cust;
- service_tracker_pt tracker;
- calculator_service_pt calc;
-};
-
-static celix_status_t addCalc(void * handle, service_reference_pt reference, void * service);
-static celix_status_t removeCalc(void * handle, service_reference_pt reference, void * service);
-static int test(void *handle);
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **out) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *act = calloc(1, sizeof(*act));
- if (act != NULL) {
- act->context = context;
- act->serv.handle = act;
- act->serv.test = test;
-
- status = serviceTrackerCustomizer_create(act, NULL, addCalc, NULL, removeCalc, &act->cust);
- status = CELIX_DO_IF(status, serviceTracker_create(context, CALCULATOR2_SERVICE, act->cust, &act->tracker));
-
- } else {
- status = CELIX_ENOMEM;
- }
-
- if (status == CELIX_SUCCESS) {
- *out = act;
- } else if (act != NULL) {
- if (act->cust != NULL) {
- free(act->cust);
- act->cust = NULL;
- }
- if (act->tracker != NULL) {
- serviceTracker_destroy(act->tracker);
- act->tracker = NULL;
- }
- free(act);
- }
-
- return CELIX_SUCCESS;
-}
-
-static celix_status_t addCalc(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator * act = handle;
- act->calc = service;
- return status;
-}
-
-static celix_status_t removeCalc(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator * act = handle;
- if (act->calc == service) {
- act->calc = NULL;
- }
- return status;
-
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator * act = userData;
-
- act->reg = NULL;
- status = bundleContext_registerService(context, (char *)TST_SERVICE_NAME, &act->serv, NULL, &act->reg);
-
- status = CELIX_DO_IF(status, serviceTracker_open(act->tracker));
-
-
- return status;
-}
-
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator * act = userData;
-
- status = serviceRegistration_unregister(act->reg);
- status = CELIX_DO_IF(status, serviceTracker_close(act->tracker));
-
- return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- struct activator *act = userData;
- if (act != NULL) {
- if (act->tracker != NULL) {
- serviceTracker_destroy(act->tracker);
- act->tracker = NULL;
- }
- free(act);
- }
- return CELIX_SUCCESS;
-}
-
-static int test(void *handle) {
- int status = 0;
- struct activator *act = handle;
-
- double result = -1.0;
-
- int rc = 1;
- if (act->calc != NULL) {
- rc = act->calc->sqrt(act->calc->calculator, 4, &result);
- printf("calc result is %f\n", result);
- } else {
- printf("calc not ready\n");
- }
-
- if (rc != 0 || result != 2.0) {
- status = 1;
- }
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_service.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_service.h b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_service.h
deleted file mode 100644
index c8ca2e7..0000000
--- a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_service.h
+++ /dev/null
@@ -1,32 +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.
- */
-
-#ifndef CELIX_TST_SERVICE_H
-#define CELIX_TST_SERVICE_H
-
-#define TST_SERVICE_NAME "tst_service"
-
-struct tst_service {
- void *handle;
- int (*test)(void *handle);
-};
-
-typedef struct tst_service *tst_service_pt;
-
-#endif //CELIX_TST_SERVICE_H
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa_tst/client.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/client.properties.in b/remote_services/remote_service_admin_dfi/rsa_tst/client.properties.in
deleted file mode 100644
index a9a06fb..0000000
--- a/remote_services/remote_service_admin_dfi/rsa_tst/client.properties.in
+++ /dev/null
@@ -1,8 +0,0 @@
-cosgi.auto.start.1=@rsa_bundle_file@ @calculator_shell_bundle_file@ @discovery_configured_bundle_file@ @topology_manager_bundle_file@ @tst_bundle_file@
-LOGHELPER_ENABLE_STDOUT_FALLBACK=true
-RSA_PORT=50881
-DISCOVERY_CFG_SERVER_PORT=50991
-DISCOVERY_CFG_POLL_ENDPOINTS=http://127.0.0.1:50992/org.apache.celix.discovery.configured
-org.osgi.framework.storage.clean=onFirstInit
-org.osgi.framework.storage=.cacheClient
-DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa_tst/config.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/config.properties.in b/remote_services/remote_service_admin_dfi/rsa_tst/config.properties.in
deleted file mode 100644
index 5776ad8..0000000
--- a/remote_services/remote_service_admin_dfi/rsa_tst/config.properties.in
+++ /dev/null
@@ -1,20 +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.
-
-cosgi.auto.start.1=@rsa_bundle_file@ @calc_bundle_file@
-LOGHELPER_ENABLE_STDOUT_FALLBACK=true
-org.osgi.framework.storage.clean=onFirstInit
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp b/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp
deleted file mode 100644
index d091746..0000000
--- a/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp
+++ /dev/null
@@ -1,133 +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.
- */
-
-#include <CppUTest/TestHarness.h>
-#include <remote_constants.h>
-#include <constants.h>
-#include <tst_service.h>
-#include "CppUTest/CommandLineTestRunner.h"
-#include "../../examples/calculator_service/public/include/calculator_service.h"
-
-extern "C" {
-
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <unistd.h>
-
-#include "celix_launcher.h"
-#include "framework.h"
-#include "remote_service_admin.h"
-#include "calculator_service.h"
-
- static framework_pt serverFramework = NULL;
- static bundle_context_pt serverContext = NULL;
-
- static framework_pt clientFramework = NULL;
- static bundle_context_pt clientContext = NULL;
-
- static void setupFm(void) {
- int rc = 0;
- bundle_pt bundle = NULL;
-
- //server
- rc = celixLauncher_launch("server.properties", &serverFramework);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- bundle = NULL;
- rc = framework_getFrameworkBundle(serverFramework, &bundle);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- rc = bundle_getContext(bundle, &serverContext);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
-
- //client
- rc = celixLauncher_launch("client.properties", &clientFramework);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- bundle = NULL;
- rc = framework_getFrameworkBundle(clientFramework, &bundle);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- rc = bundle_getContext(bundle, &clientContext);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
- }
-
- static void teardownFm(void) {
- celixLauncher_stop(serverFramework);
- celixLauncher_waitForShutdown(serverFramework);
- celixLauncher_destroy(serverFramework);
-
- celixLauncher_stop(clientFramework);
- celixLauncher_waitForShutdown(clientFramework);
- celixLauncher_destroy(clientFramework);
-
- serverContext = NULL;
- serverFramework = NULL;
- clientContext = NULL;
- clientFramework = NULL;
- }
-
- static void test1(void) {
- celix_status_t rc;
- service_reference_pt ref = NULL;
- tst_service_pt tst = NULL;
- int retries = 4;
-
- while (ref == NULL && retries > 0) {
- printf("Waiting for service .. %d\n", retries);
- rc = bundleContext_getServiceReference(clientContext, (char *) TST_SERVICE_NAME, &ref);
- usleep(1000000);
- --retries;
- }
-
- CHECK_EQUAL(CELIX_SUCCESS, rc);
- CHECK(ref != NULL);
-
- rc = bundleContext_getService(clientContext, ref, (void **)&tst);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
- CHECK(tst != NULL);
-
- rc = tst->test(tst->handle);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- bool result;
- bundleContext_ungetService(clientContext, ref, &result);
- bundleContext_ungetServiceReference(clientContext, ref);
- }
-
-}
-
-
-TEST_GROUP(RsaDfiClientServerTests) {
- void setup() {
- setupFm();
- }
-
- void teardown() {
- teardownFm();
- }
-};
-
-TEST(RsaDfiClientServerTests, Test1) {
- test1();
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp b/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp
deleted file mode 100644
index 8b7988d..0000000
--- a/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp
+++ /dev/null
@@ -1,234 +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.
- */
-
-#include <CppUTest/TestHarness.h>
-#include <remote_constants.h>
-#include <constants.h>
-#include "CppUTest/CommandLineTestRunner.h"
-#include "../../examples/calculator_service/public/include/calculator_service.h"
-
-extern "C" {
-
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "celix_launcher.h"
-#include "framework.h"
-#include "remote_service_admin.h"
-#include "calculator_service.h"
-
-
- static framework_pt framework = NULL;
- static bundle_context_pt context = NULL;
-
- static service_reference_pt rsaRef = NULL;
- static remote_service_admin_service_pt rsa = NULL;
-
- static service_reference_pt calcRef = NULL;
- static calculator_service_pt calc = NULL;
-
- static void setupFm(void) {
- int rc = 0;
-
- rc = celixLauncher_launch("config.properties", &framework);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- bundle_pt bundle = NULL;
- rc = framework_getFrameworkBundle(framework, &bundle);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- rc = bundle_getContext(bundle, &context);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- rc = bundleContext_getServiceReference(context, (char *)OSGI_RSA_REMOTE_SERVICE_ADMIN, &rsaRef);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
- CHECK(rsaRef != NULL);
-
- rc = bundleContext_getService(context, rsaRef, (void **)&rsa);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- rc = bundleContext_getServiceReference(context, (char *)CALCULATOR2_SERVICE, &calcRef);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
- CHECK(calcRef != NULL);
-
- rc = bundleContext_getService(context, calcRef, (void **)&calc);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
- }
-
- static void teardownFm(void) {
- int rc = 0;
- rc = bundleContext_ungetService(context, rsaRef, NULL);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- rc = bundleContext_ungetServiceReference(context, rsaRef);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- rc = bundleContext_ungetService(context, calcRef, NULL);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- rc = bundleContext_ungetServiceReference(context, calcRef);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- celixLauncher_stop(framework);
- celixLauncher_waitForShutdown(framework);
- celixLauncher_destroy(framework);
-
- rsaRef = NULL;
- rsa = NULL;
- calcRef = NULL;
- calc = NULL;
- context = NULL;
- framework = NULL;
- }
-
- static void testServices(void) {
- int rc = 0;
- array_list_pt exported = NULL;
- array_list_pt imported = NULL;
- arrayList_create(&exported);
- arrayList_create(&imported);
-
- rc = rsa->getExportedServices(rsa->admin, &exported);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
- CHECK_EQUAL(0, arrayList_size(exported));
-
- rc = rsa->getImportedEndpoints(rsa->admin, &imported);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
- CHECK_EQUAL(0, arrayList_size(imported));
-
- double result = 0;
- rc = calc->add(calc->calculator, 2.0, 5.0, &result);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
- CHECK_EQUAL(7.0, result);
-
- arrayList_destroy(imported);
- arrayList_destroy(exported);
- }
-
- static void testExportService(void) {
- int rc = 0;
- const char *calcId = NULL;
- array_list_pt regs = NULL;
-
- rc = serviceReference_getProperty(calcRef, (char *)"service.id", &calcId);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- rc = rsa->exportService(rsa->admin, (char*)calcId, NULL, ®s);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- CHECK_EQUAL(1, arrayList_size(regs));
-
- rc = rsa->exportRegistration_close(rsa->admin,(export_registration_pt)(arrayList_get(regs,0)));
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- }
-
- static void testImportService(void) {
- int rc = 0;
- import_registration_pt reg = NULL;
- endpoint_description_pt endpoint = NULL;
-
- properties_pt props = properties_create();
- properties_set(props, (char *)OSGI_RSA_ENDPOINT_SERVICE_ID, (char *)"42");
- properties_set(props, (char *)OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42");
- properties_set(props, (char *)OSGI_RSA_ENDPOINT_ID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42-42");
- properties_set(props, (char *)OSGI_FRAMEWORK_OBJECTCLASS,(char *)"org.apache.celix.Example");
- properties_set(props, (char *)"service.version",(char *)"1.0.0"); //TODO find out standard in osgi spec
-
- rc = endpointDescription_create(props, &endpoint);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- rc = rsa->importService(rsa->admin, endpoint, ®);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
- CHECK(reg != NULL);
-
- service_reference_pt ref = NULL;
- rc = bundleContext_getServiceReference(context, (char *)"org.apache.celix.Example", &ref);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
- CHECK(ref != NULL);
-
- rc = bundleContext_ungetServiceReference(context, ref);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- rc = endpointDescription_destroy(endpoint);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
-
- /* Cannot test. uses requesting bundles descriptor
- void *service = NULL;
- rc = bundleContext_getService(context, ref, &service);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
- CHECK(service != NULL);
- */
- }
-
- static void testBundles(void) {
- array_list_pt bundles = NULL;
-
- int rc = bundleContext_getBundles(context, &bundles);
- CHECK_EQUAL(0, rc);
- CHECK_EQUAL(3, arrayList_size(bundles)); //framework, rsa_dfi & calc
-
- /*
- int size = arrayList_size(bundles);
- int i;
- for (i = 0; i < size; i += 1) {
- bundle_pt bundle = NULL;
- module_pt module = NULL;
- char *name = NULL;
-
- bundle = (bundle_pt) arrayList_get(bundles, i);
- bundle_getCurrentModule(bundle, &module);
- module_getSymbolicName(module, &name);
- printf("got bundle with symbolic name '%s'", name);
- }*/
-
- arrayList_destroy(bundles);
- }
-
-}
-
-
-TEST_GROUP(RsaDfiTests) {
- void setup() {
- setupFm();
- }
-
- void teardown() {
- teardownFm();
- }
-};
-
-TEST(RsaDfiTests, InfoTest) {
- testServices();
-}
-
-TEST(RsaDfiTests, ExportService) {
- testExportService();
-}
-
-TEST(RsaDfiTests, ImportService) {
- testImportService();
-}
-
-TEST(RsaDfiTests, TestBundles) {
- testBundles();
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa_tst/run_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/run_tests.cpp b/remote_services/remote_service_admin_dfi/rsa_tst/run_tests.cpp
deleted file mode 100644
index b5fd502..0000000
--- a/remote_services/remote_service_admin_dfi/rsa_tst/run_tests.cpp
+++ /dev/null
@@ -1,25 +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.
- */
-
-#include <CppUTest/TestHarness.h>
-#include "CppUTest/CommandLineTestRunner.h"
-
-int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/rsa_tst/server.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/server.properties.in b/remote_services/remote_service_admin_dfi/rsa_tst/server.properties.in
deleted file mode 100644
index 707c7e6..0000000
--- a/remote_services/remote_service_admin_dfi/rsa_tst/server.properties.in
+++ /dev/null
@@ -1,23 +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.
-cosgi.auto.start.1=@rsa_bundle_file@ @calc_bundle_file@ @discovery_configured_bundle_file@ @topology_manager_bundle_file@
-LOGHELPER_ENABLE_STDOUT_FALLBACK=true
-RSA_PORT=50882
-DISCOVERY_CFG_SERVER_PORT=50992
-org.osgi.framework.storage.clean=onFirstInit
-org.osgi.framework.storage=.cacheServer
-DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/src/dfi_utils.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/src/dfi_utils.c b/remote_services/remote_service_admin_dfi/src/dfi_utils.c
new file mode 100644
index 0000000..631152d
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/src/dfi_utils.c
@@ -0,0 +1,108 @@
+/**
+ *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.
+ */
+
+#include "dfi_utils.h"
+#include <stdlib.h>
+#include <unistd.h>
+
+static celix_status_t dfi_findFileForFramework(bundle_context_pt context, const char *fileName, FILE **out) {
+ celix_status_t status;
+
+ char pwd[1024];
+ char path[1024];
+ const char *extPath = NULL;
+
+ status = bundleContext_getProperty(context, "CELIX_FRAMEWORK_EXTENDER_PATH", &extPath);
+ if (status != CELIX_SUCCESS || extPath == NULL) {
+ getcwd(pwd, sizeof(pwd));
+ extPath = pwd;
+ }
+
+ snprintf(path, sizeof(path), "%s/%s", extPath, fileName);
+
+ if (status == CELIX_SUCCESS) {
+ FILE *df = fopen(path, "r");
+ if (df == NULL) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ } else {
+ *out = df;
+ }
+ }
+
+ return status;
+}
+
+static celix_status_t dfi_findFileForBundle(bundle_pt bundle, const char *fileName, FILE **out) {
+ celix_status_t status;
+
+ //Checking if descriptor is in root dir of bundle
+ char *path = NULL;
+ status = bundle_getEntry(bundle, fileName, &path);
+
+ char metaInfFileName[512];
+ if (status != CELIX_SUCCESS || path == NULL) {
+ free(path);
+ //Checking if descriptor is in META-INF/descriptors
+ snprintf(metaInfFileName, sizeof(metaInfFileName), "META-INF/descriptors/%s", fileName);
+ status = bundle_getEntry(bundle, metaInfFileName, &path);
+ }
+
+ if (status != CELIX_SUCCESS || path == NULL) {
+ free(path);
+ //Checking if descriptor is in META-INF/descriptors/services
+ snprintf(metaInfFileName, sizeof(metaInfFileName), "META-INF/descriptors/services/%s", fileName);
+ status = bundle_getEntry(bundle, metaInfFileName, &path);
+ }
+
+
+ if (status == CELIX_SUCCESS && path != NULL) {
+ FILE *df = fopen(path, "r");
+ if (df == NULL) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ } else {
+ *out = df;
+ }
+
+ }
+
+ free(path);
+ return status;
+}
+
+celix_status_t dfi_findDescriptor(bundle_context_pt context, bundle_pt bundle, const char *name, FILE **out) {
+ celix_status_t status;
+ char fileName[128];
+
+ snprintf(fileName, 128, "%s.descriptor", name);
+
+ long id;
+ status = bundle_getBundleId(bundle, &id);
+
+ if (status == CELIX_SUCCESS) {
+ if (id == 0) {
+ //framework bundle
+ status = dfi_findFileForFramework(context, fileName, out);
+ } else {
+ //normal bundle
+ status = dfi_findFileForBundle(bundle, fileName, out);
+ }
+ }
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/src/dfi_utils.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/src/dfi_utils.h b/remote_services/remote_service_admin_dfi/src/dfi_utils.h
new file mode 100644
index 0000000..cec8aa1
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/src/dfi_utils.h
@@ -0,0 +1,30 @@
+/**
+ *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.
+ */
+#ifndef DFI_UTILS_H_
+#define DFI_UTILS_H_
+
+#include "bundle.h"
+#include "bundle_context.h"
+#include <stdio.h>
+#include "celix_errno.h"
+
+
+celix_status_t dfi_findDescriptor(bundle_context_pt context, bundle_pt bundle, const char *name, FILE **out);
+
+#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c b/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c
new file mode 100644
index 0000000..b83b5a8
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c
@@ -0,0 +1,251 @@
+/**
+ *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.
+ */
+
+#include <jansson.h>
+#include <dyn_interface.h>
+#include <json_serializer.h>
+#include <remote_constants.h>
+#include <remote_service_admin.h>
+#include <service_tracker_customizer.h>
+#include <service_tracker.h>
+#include <json_rpc.h>
+#include "constants.h"
+#include "export_registration_dfi.h"
+#include "dfi_utils.h"
+
+struct export_reference {
+ endpoint_description_pt endpoint; //owner
+ service_reference_pt reference;
+};
+
+struct export_registration {
+ bundle_context_pt context;
+ struct export_reference exportReference;
+ char *servId;
+ dyn_interface_type *intf; //owner
+ service_tracker_pt tracker;
+
+ celix_thread_mutex_t mutex;
+ void *service; //protected by mutex
+
+ //TODO add tracker and lock
+ bool closed;
+};
+
+static void exportRegistration_addServ(export_registration_pt reg, service_reference_pt ref, void *service);
+static void exportRegistration_removeServ(export_registration_pt reg, service_reference_pt ref, void *service);
+
+celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, bundle_context_pt context, export_registration_pt *out) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ const char *servId = NULL;
+ status = serviceReference_getProperty(reference, "service.id", &servId);
+ if (status != CELIX_SUCCESS) {
+ logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "Cannot find service.id for ref");
+ }
+
+ export_registration_pt reg = NULL;
+ if (status == CELIX_SUCCESS) {
+ reg = calloc(1, sizeof(*reg));
+ if (reg == NULL) {
+ status = CELIX_ENOMEM;
+ }
+ }
+
+
+ if (status == CELIX_SUCCESS) {
+ reg->context = context;
+ reg->exportReference.endpoint = endpoint;
+ reg->exportReference.reference = reference;
+ reg->closed = false;
+
+ celixThreadMutex_create(®->mutex, NULL);
+ }
+
+ const char *exports = NULL;
+ CELIX_DO_IF(status, serviceReference_getProperty(reference, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exports));
+
+ bundle_pt bundle = NULL;
+ CELIX_DO_IF(status, serviceReference_getBundle(reference, &bundle));
+
+ FILE *descriptor = NULL;
+ if (status == CELIX_SUCCESS) {
+ status = dfi_findDescriptor(context, bundle, exports, &descriptor);
+ }
+
+ if (status != CELIX_SUCCESS || descriptor == NULL) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Cannot find/open descriptor for '%s'", exports);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ int rc = dynInterface_parse(descriptor, ®->intf);
+ fclose(descriptor);
+ if (rc != 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "RSA: Error parsing service descriptor.");
+ }
+ else{
+ /* Add the interface version as a property in the properties_map */
+ char* intfVersion = NULL;
+ dynInterface_getVersionString(reg->intf, &intfVersion);
+ const char *serviceVersion = properties_get(endpoint->properties,(char*) CELIX_FRAMEWORK_SERVICE_VERSION);
+ if(serviceVersion!=NULL){
+ if(strcmp(serviceVersion,intfVersion)!=0){
+ logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "Service version (%s) and interface version from the descriptor (%s) are not the same!",serviceVersion,intfVersion);
+ }
+ }
+ else{
+ properties_set(endpoint->properties, (char*) CELIX_FRAMEWORK_SERVICE_VERSION, intfVersion);
+ }
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ service_tracker_customizer_pt cust = NULL;
+ status = serviceTrackerCustomizer_create(reg, NULL, (void *) exportRegistration_addServ, NULL,
+ (void *) exportRegistration_removeServ, &cust);
+ if (status == CELIX_SUCCESS) {
+ char filter[32];
+ snprintf(filter, 32, "(service.id=%s)", servId);
+ status = serviceTracker_createWithFilter(reg->context, filter, cust, ®->tracker);
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *out = reg;
+ } else {
+ logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Error creating export registration");
+ exportRegistration_destroy(reg);
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_call(export_registration_pt export, char *data, int datalength, char **responseOut, int *responseLength) {
+ int status = CELIX_SUCCESS;
+
+ //printf("calling for '%s'\n");
+
+ *responseLength = -1;
+ celixThreadMutex_lock(&export->mutex);
+ status = jsonRpc_call(export->intf, export->service, data, responseOut);
+ celixThreadMutex_unlock(&export->mutex);
+
+ return status;
+}
+
+void exportRegistration_destroy(export_registration_pt reg) {
+ if (reg != NULL) {
+ if (reg->intf != NULL) {
+ dyn_interface_type *intf = reg->intf;
+ reg->intf = NULL;
+ dynInterface_destroy(intf);
+ }
+
+ if (reg->exportReference.endpoint != NULL) {
+ endpoint_description_pt ep = reg->exportReference.endpoint;
+ reg->exportReference.endpoint = NULL;
+ endpointDescription_destroy(ep);
+ }
+ if (reg->tracker != NULL) {
+ serviceTracker_destroy(reg->tracker);
+ }
+ celixThreadMutex_destroy(®->mutex);
+
+ free(reg);
+ }
+}
+
+celix_status_t exportRegistration_start(export_registration_pt reg) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ serviceTracker_open(reg->tracker);
+ return status;
+}
+
+
+celix_status_t exportRegistration_stop(export_registration_pt reg) {
+ celix_status_t status = CELIX_SUCCESS;
+ if (status == CELIX_SUCCESS) {
+ status = bundleContext_ungetServiceReference(reg->context, reg->exportReference.reference);
+ serviceTracker_close(reg->tracker);
+ }
+ return status;
+}
+
+static void exportRegistration_addServ(export_registration_pt reg, service_reference_pt ref, void *service) {
+ celixThreadMutex_lock(®->mutex);
+ reg->service = service;
+ celixThreadMutex_unlock(®->mutex);
+}
+
+static void exportRegistration_removeServ(export_registration_pt reg, service_reference_pt ref, void *service) {
+ celixThreadMutex_lock(®->mutex);
+ if (reg->service == service) {
+ reg->service = NULL;
+ }
+ celixThreadMutex_unlock(®->mutex);
+}
+
+
+celix_status_t exportRegistration_close(export_registration_pt reg) {
+ celix_status_t status = CELIX_SUCCESS;
+ exportRegistration_stop(reg);
+ return status;
+}
+
+
+celix_status_t exportRegistration_getException(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ //TODO
+ return status;
+}
+
+celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *out) {
+ celix_status_t status = CELIX_SUCCESS;
+ export_reference_pt ref = calloc(1, sizeof(*ref));
+ if (ref != NULL) {
+ ref->endpoint = registration->exportReference.endpoint;
+ ref->reference = registration->exportReference.reference;
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *out = ref;
+ }
+
+ return status;
+}
+
+celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint) {
+ celix_status_t status = CELIX_SUCCESS;
+ *endpoint = reference->endpoint;
+ return status;
+}
+
+celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *ref) {
+ celix_status_t status = CELIX_SUCCESS;
+ *ref = reference->reference;
+ return status;
+}
+
+
+
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/remote_service_admin_dfi/src/export_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/src/export_registration_dfi.h b/remote_services/remote_service_admin_dfi/src/export_registration_dfi.h
new file mode 100644
index 0000000..93f37ba
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/src/export_registration_dfi.h
@@ -0,0 +1,38 @@
+/**
+ *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.
+ */
+
+#ifndef CELIX_EXPORT_REGISTRATION_DFI_H
+#define CELIX_EXPORT_REGISTRATION_DFI_H
+
+
+#include "export_registration.h"
+#include "log_helper.h"
+#include "endpoint_description.h"
+
+celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, bundle_context_pt context, export_registration_pt *registration);
+celix_status_t exportRegistration_close(export_registration_pt registration);
+void exportRegistration_destroy(export_registration_pt registration);
+
+celix_status_t exportRegistration_start(export_registration_pt registration);
+celix_status_t exportRegistration_stop(export_registration_pt registration);
+
+celix_status_t exportRegistration_call(export_registration_pt export, char *data, int datalength, char **response, int *responseLength);
+
+
+#endif //CELIX_EXPORT_REGISTRATION_DFI_H
[52/54] [abbrv] celix git commit: CELIX-417: Fixes some clang errors
and removes unused cmake BUILD options from travis config
Posted by pn...@apache.org.
CELIX-417: Fixes some clang errors and removes unused cmake BUILD options from travis config
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/83d77f4d
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/83d77f4d
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/83d77f4d
Branch: refs/heads/develop
Commit: 83d77f4d04b21806cfeb4e9e10b89daa7d9be588
Parents: 326f275
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Jan 30 16:34:11 2018 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Jan 30 16:34:11 2018 +0100
----------------------------------------------------------------------
.travis.yml | 2 -
.../publisher/private/src/mp_pub_activator.c | 30 ++++++-------
.../subscriber/private/src/mp_sub_activator.c | 21 ++++-----
.../publisher/private/src/ps_pub_activator.c | 45 +++++++++-----------
.../subscriber/private/src/ps_sub_activator.c | 27 ++++++------
5 files changed, 56 insertions(+), 69 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/83d77f4d/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index 5af8c60..8bfc819 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -66,7 +66,6 @@ before_script:
- cd -
- mkdir build install
- export BUILD_OPTIONS=" \
- -DBUILD_CONFIG_ADMIN=OFF \
-DBUILD_RSA_REMOTE_SERVICE_ADMIN_DFI=ON \
-DBUILD_DEPLOYMENT_ADMIN=ON \
-DBUILD_DEPENDENCY_MANAGER=ON \
@@ -76,7 +75,6 @@ before_script:
-DBUILD_RSA_DISCOVERY_CONFIGURED=ON \
-DBUILD_RSA_DISCOVERY_ETCD=ON \
-DBUILD_RSA_EXAMPLES=ON \
- -DBUILD_RSA_REMOTE_SERVICE_ADMIN_HTTP=ON \
-DBUILD_REMOTE_SHELL=ON \
-DBUILD_SHELL=ON \
-DBUILD_SHELL_TUI=ON -DBUILD_DEVICE_ACCESS=ON \
http://git-wip-us.apache.org/repos/asf/celix/blob/83d77f4d/pubsub/examples/mp_pubsub/publisher/private/src/mp_pub_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/examples/mp_pubsub/publisher/private/src/mp_pub_activator.c b/pubsub/examples/mp_pubsub/publisher/private/src/mp_pub_activator.c
index 464d1ab..0b6041d 100644
--- a/pubsub/examples/mp_pubsub/publisher/private/src/mp_pub_activator.c
+++ b/pubsub/examples/mp_pubsub/publisher/private/src/mp_pub_activator.c
@@ -80,28 +80,26 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
int i;
- if(PUB_TOPICS != NULL) {
- char filter[128];
- for(i=0; PUB_TOPICS[i] != NULL; i++){
- const char* topic = PUB_TOPICS[i];
+ char filter[128];
+ for(i=0; PUB_TOPICS[i] != NULL; i++){
+ const char* topic = PUB_TOPICS[i];
- bundle_pt bundle = NULL;
- long bundleId = 0;
- bundleContext_getBundle(context,&bundle);
- bundle_getBundleId(bundle,&bundleId);
+ bundle_pt bundle = NULL;
+ long bundleId = 0;
+ bundleContext_getBundle(context,&bundle);
+ bundle_getBundleId(bundle,&bundleId);
- service_tracker_pt tracker = NULL;
- memset(filter,0,128);
+ service_tracker_pt tracker = NULL;
+ memset(filter,0,128);
- snprintf(filter, 128, "(&(%s=%s)(%s=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_PUBLISHER_SERVICE_NAME, PUBSUB_PUBLISHER_TOPIC,topic);
+ snprintf(filter, 128, "(&(%s=%s)(%s=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_PUBLISHER_SERVICE_NAME, PUBSUB_PUBLISHER_TOPIC,topic);
- service_tracker_customizer_pt customizer = NULL;
+ service_tracker_customizer_pt customizer = NULL;
- serviceTrackerCustomizer_create(act->client,NULL,publisher_publishSvcAdded,NULL,publisher_publishSvcRemoved,&customizer);
- serviceTracker_createWithFilter(context, filter, customizer, &tracker);
+ serviceTrackerCustomizer_create(act->client,NULL,publisher_publishSvcAdded,NULL,publisher_publishSvcRemoved,&customizer);
+ serviceTracker_createWithFilter(context, filter, customizer, &tracker);
- arrayList_add(act->trackerList,tracker);
- }
+ arrayList_add(act->trackerList,tracker);
}
publisher_start(act->client);
http://git-wip-us.apache.org/repos/asf/celix/blob/83d77f4d/pubsub/examples/mp_pubsub/subscriber/private/src/mp_sub_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/examples/mp_pubsub/subscriber/private/src/mp_sub_activator.c b/pubsub/examples/mp_pubsub/subscriber/private/src/mp_sub_activator.c
index df9cb0f..591a395 100644
--- a/pubsub/examples/mp_pubsub/subscriber/private/src/mp_sub_activator.c
+++ b/pubsub/examples/mp_pubsub/subscriber/private/src/mp_sub_activator.c
@@ -60,18 +60,15 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
act->subsvc = subsvc;
- if (SUB_TOPICS !=NULL) {
-
- int i;
- for(i=0; SUB_TOPICS[i] != NULL; i++){
- const char* topic = SUB_TOPICS[i];
-
- properties_pt props = properties_create();
- properties_set(props, PUBSUB_SUBSCRIBER_TOPIC,topic);
- service_registration_pt reg = NULL;
- bundleContext_registerService(context, PUBSUB_SUBSCRIBER_SERVICE_NAME, subsvc, props, ®);
- arrayList_add(act->registrationList,reg);
- }
+ int i;
+ for(i=0; SUB_TOPICS[i] != NULL; i++){
+ const char* topic = SUB_TOPICS[i];
+
+ properties_pt props = properties_create();
+ properties_set(props, PUBSUB_SUBSCRIBER_TOPIC,topic);
+ service_registration_pt reg = NULL;
+ bundleContext_registerService(context, PUBSUB_SUBSCRIBER_SERVICE_NAME, subsvc, props, ®);
+ arrayList_add(act->registrationList,reg);
}
subscriber_start((pubsub_receiver_pt)act->subsvc->handle);
http://git-wip-us.apache.org/repos/asf/celix/blob/83d77f4d/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c b/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c
index a1f2dc8..0da3ffc 100644
--- a/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c
+++ b/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c
@@ -76,37 +76,34 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
struct publisherActivator * act = (struct publisherActivator *) userData;
int i;
- if(PUB_TOPICS !=NULL){
+ char filter[128];
+ for(i=0; PUB_TOPICS[i] != NULL; i++){
+ const char* topic = PUB_TOPICS[i];
- char filter[128];
- for(i=0; PUB_TOPICS[i] != NULL; i++){
- const char* topic = PUB_TOPICS[i];
+ bundle_pt bundle = NULL;
+ long bundleId = 0;
+ bundleContext_getBundle(context,&bundle);
+ bundle_getBundleId(bundle,&bundleId);
- bundle_pt bundle = NULL;
- long bundleId = 0;
- bundleContext_getBundle(context,&bundle);
- bundle_getBundleId(bundle,&bundleId);
-
- service_tracker_pt tracker = NULL;
- memset(filter,0,128);
+ service_tracker_pt tracker = NULL;
+ memset(filter,0,128);
#ifdef USE_SCOPE
- char *scope;
- asprintf(&scope, "my_scope_%d", i);
- snprintf(filter, 128, "(&(&(%s=%s)(%s=%s))(%s=%s))",
- (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_PUBLISHER_SERVICE_NAME,
- PUBSUB_PUBLISHER_TOPIC, topic,
- PUBLISHER_SCOPE, scope);
- free(scope);
+ char *scope;
+ asprintf(&scope, "my_scope_%d", i);
+ snprintf(filter, 128, "(&(&(%s=%s)(%s=%s))(%s=%s))",
+ (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_PUBLISHER_SERVICE_NAME,
+ PUBSUB_PUBLISHER_TOPIC, topic,
+ PUBLISHER_SCOPE, scope);
+ free(scope);
#else
- snprintf(filter, 128, "(&(%s=%s)(%s=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_PUBLISHER_SERVICE_NAME, PUBSUB_PUBLISHER_TOPIC, topic);
+ snprintf(filter, 128, "(&(%s=%s)(%s=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_PUBLISHER_SERVICE_NAME, PUBSUB_PUBLISHER_TOPIC, topic);
#endif
- service_tracker_customizer_pt customizer = NULL;
- serviceTrackerCustomizer_create(act->client,NULL,publisher_publishSvcAdded,NULL,publisher_publishSvcRemoved,&customizer);
- serviceTracker_createWithFilter(context, filter, customizer, &tracker);
+ service_tracker_customizer_pt customizer = NULL;
+ serviceTrackerCustomizer_create(act->client,NULL,publisher_publishSvcAdded,NULL,publisher_publishSvcRemoved,&customizer);
+ serviceTracker_createWithFilter(context, filter, customizer, &tracker);
- arrayList_add(act->trackerList,tracker);
+ arrayList_add(act->trackerList,tracker);
- }
}
publisher_start(act->client);
http://git-wip-us.apache.org/repos/asf/celix/blob/83d77f4d/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c b/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c
index 4738abd..5f3b283 100644
--- a/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c
+++ b/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c
@@ -61,23 +61,20 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
act->subsvc = subsvc;
- if (SUB_TOPICS !=NULL){
-
- int i;
- for(i=0; SUB_TOPICS[i] != NULL ;i++){
- const char* topic = SUB_TOPICS[i];
- properties_pt props = properties_create();
- properties_set(props, PUBSUB_SUBSCRIBER_TOPIC,topic);
+ int i;
+ for(i=0; SUB_TOPICS[i] != NULL ;i++){
+ const char* topic = SUB_TOPICS[i];
+ properties_pt props = properties_create();
+ properties_set(props, PUBSUB_SUBSCRIBER_TOPIC,topic);
#ifdef USE_SCOPE
- char *scope;
- asprintf(&scope, "my_scope_%d", i);
- properties_set(props,SUBSCRIBER_SCOPE,scope);
- free(scope);
+ char *scope;
+ asprintf(&scope, "my_scope_%d", i);
+ properties_set(props,SUBSCRIBER_SCOPE,scope);
+ free(scope);
#endif
- service_registration_pt reg = NULL;
- bundleContext_registerService(context, PUBSUB_SUBSCRIBER_SERVICE_NAME, subsvc, props, ®);
- arrayList_add(act->registrationList,reg);
- }
+ service_registration_pt reg = NULL;
+ bundleContext_registerService(context, PUBSUB_SUBSCRIBER_SERVICE_NAME, subsvc, props, ®);
+ arrayList_add(act->registrationList,reg);
}
subscriber_start((pubsub_receiver_pt)act->subsvc->handle);
[42/54] [abbrv] celix git commit: Merge branch 'release/2.1.0' into
feature/CELIX-417-cmake-refactor
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/pubsub_admin_zmq/src/topic_subscription.c
----------------------------------------------------------------------
diff --cc pubsub/pubsub_admin_zmq/src/topic_subscription.c
index 0e7a794,0000000..9728865
mode 100644,000000..100644
--- a/pubsub/pubsub_admin_zmq/src/topic_subscription.c
+++ b/pubsub/pubsub_admin_zmq/src/topic_subscription.c
@@@ -1,732 -1,0 +1,732 @@@
+/**
+ *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.
+ */
+/*
+ * topic_subscription.c
+ *
+ * \date Oct 2, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include "topic_subscription.h"
+#include <czmq.h>
+/* The following undefs prevent the collision between:
+ * - sys/syslog.h (which is included within czmq)
+ * - celix/dfi/dfi_log_util.h
+ */
+#undef LOG_DEBUG
+#undef LOG_WARNING
+#undef LOG_INFO
+#undef LOG_WARNING
+
+#include <string.h>
+#include <stdlib.h>
+#include <signal.h>
+
+#include "utils.h"
+#include "celix_errno.h"
+#include "constants.h"
+#include "version.h"
+
- #include "subscriber.h"
- #include "publisher.h"
++#include "pubsub/subscriber.h"
++#include "pubsub/publisher.h"
+#include "pubsub_utils.h"
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+#include "zmq_crypto.h"
+
+#define MAX_CERT_PATH_LENGTH 512
+#endif
+
+#define POLL_TIMEOUT 250
+#define ZMQ_POLL_TIMEOUT_MS_ENV "ZMQ_POLL_TIMEOUT_MS"
+
+struct topic_subscription{
+
+ zsock_t* zmq_socket;
+ zcert_t * zmq_cert;
+ zcert_t * zmq_pub_cert;
+ pthread_mutex_t socket_lock;
+ service_tracker_pt tracker;
+ array_list_pt sub_ep_list;
+ celix_thread_t recv_thread;
+ bool running;
+ celix_thread_mutex_t ts_lock;
+ bundle_context_pt context;
+
+ pubsub_serializer_service_t *serializer;
+
+ hash_map_pt servicesMap; // key = service, value = msg types map
+
+ celix_thread_mutex_t pendingConnections_lock;
+ array_list_pt pendingConnections;
+
+ array_list_pt pendingDisconnections;
+ celix_thread_mutex_t pendingDisconnections_lock;
+
+ unsigned int nrSubscribers;
+};
+
+typedef struct complete_zmq_msg{
+ zframe_t* header;
+ zframe_t* payload;
+}* complete_zmq_msg_pt;
+
+typedef struct mp_handle{
+ hash_map_pt svc_msg_db;
+ hash_map_pt rcv_msg_map;
+}* mp_handle_pt;
+
+typedef struct msg_map_entry{
+ bool retain;
+ void* msgInst;
+}* msg_map_entry_pt;
+
+static celix_status_t topicsub_subscriberTracked(void * handle, service_reference_pt reference, void * service);
+static celix_status_t topicsub_subscriberUntracked(void * handle, service_reference_pt reference, void * service);
+static void* zmq_recv_thread_func(void* arg);
+static bool checkVersion(version_pt msgVersion,pubsub_msg_header_pt hdr);
+static void sigusr1_sighandler(int signo);
+static int pubsub_localMsgTypeIdForMsgType(void* handle, const char* msgType, unsigned int* msgTypeId);
+static int pubsub_getMultipart(void *handle, unsigned int msgTypeId, bool retain, void **part);
+static mp_handle_pt create_mp_handle(hash_map_pt svc_msg_db,array_list_pt rcv_msg_list);
+static void destroy_mp_handle(mp_handle_pt mp_handle);
+static void connectPendingPublishers(topic_subscription_pt sub);
+static void disconnectPendingPublishers(topic_subscription_pt sub);
+
+celix_status_t pubsub_topicSubscriptionCreate(bundle_context_pt bundle_context, char* scope, char* topic, pubsub_serializer_service_t *best_serializer, topic_subscription_pt* out){
+ celix_status_t status = CELIX_SUCCESS;
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ char* keys_bundle_dir = pubsub_getKeysBundleDir(bundle_context);
+ if (keys_bundle_dir == NULL){
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+ const char* keys_file_path = NULL;
+ const char* keys_file_name = NULL;
+ bundleContext_getProperty(bundle_context, PROPERTY_KEYS_FILE_PATH, &keys_file_path);
+ bundleContext_getProperty(bundle_context, PROPERTY_KEYS_FILE_NAME, &keys_file_name);
+
+ char sub_cert_path[MAX_CERT_PATH_LENGTH];
+ char pub_cert_path[MAX_CERT_PATH_LENGTH];
+
+ //certificate path ".cache/bundle{id}/version0.0/./META-INF/keys/subscriber/private/sub_{topic}.key.enc"
+ snprintf(sub_cert_path, MAX_CERT_PATH_LENGTH, "%s/META-INF/keys/subscriber/private/sub_%s.key.enc", keys_bundle_dir, topic);
+ snprintf(pub_cert_path, MAX_CERT_PATH_LENGTH, "%s/META-INF/keys/publisher/public/pub_%s.pub", keys_bundle_dir, topic);
+ free(keys_bundle_dir);
+
+ printf("PSA_ZMQ_PSA_ZMQ_TS: Loading subscriber key '%s'\n", sub_cert_path);
+ printf("PSA_ZMQ_PSA_ZMQ_TS: Loading publisher key '%s'\n", pub_cert_path);
+
+ zcert_t* sub_cert = get_zcert_from_encoded_file((char *) keys_file_path, (char *) keys_file_name, sub_cert_path);
+ if (sub_cert == NULL){
+ printf("PSA_ZMQ_PSA_ZMQ_TS: Cannot load key '%s'\n", sub_cert_path);
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+ zcert_t* pub_cert = zcert_load(pub_cert_path);
+ if (pub_cert == NULL){
+ zcert_destroy(&sub_cert);
+ printf("PSA_ZMQ_PSA_ZMQ_TS: Cannot load key '%s'\n", pub_cert_path);
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+ const char* pub_key = zcert_public_txt(pub_cert);
+#endif
+
+ zsock_t* zmq_s = zsock_new (ZMQ_SUB);
+ if(zmq_s==NULL){
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ zcert_destroy(&sub_cert);
+ zcert_destroy(&pub_cert);
+#endif
+
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ zcert_apply (sub_cert, zmq_s);
+ zsock_set_curve_serverkey (zmq_s, pub_key); //apply key of publisher to socket of subscriber
+#endif
+
+ if(strcmp(topic,PUBSUB_ANY_SUB_TOPIC)==0){
+ zsock_set_subscribe (zmq_s, "");
+ }
+ else{
+ zsock_set_subscribe (zmq_s, topic);
+ }
+
+ topic_subscription_pt ts = (topic_subscription_pt) calloc(1,sizeof(*ts));
+ ts->context = bundle_context;
+ ts->zmq_socket = zmq_s;
+ ts->running = false;
+ ts->nrSubscribers = 0;
+ ts->serializer = best_serializer;
+
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ ts->zmq_cert = sub_cert;
+ ts->zmq_pub_cert = pub_cert;
+#endif
+
+ celixThreadMutex_create(&ts->socket_lock, NULL);
+ celixThreadMutex_create(&ts->ts_lock,NULL);
+ arrayList_create(&ts->sub_ep_list);
+ ts->servicesMap = hashMap_create(NULL, NULL, NULL, NULL);
+
+ arrayList_create(&ts->pendingConnections);
+ arrayList_create(&ts->pendingDisconnections);
+ celixThreadMutex_create(&ts->pendingConnections_lock, NULL);
+ celixThreadMutex_create(&ts->pendingDisconnections_lock, NULL);
+
+ char filter[128];
+ memset(filter,0,128);
+ if(strncmp(PUBSUB_SUBSCRIBER_SCOPE_DEFAULT,scope,strlen(PUBSUB_SUBSCRIBER_SCOPE_DEFAULT)) == 0) {
+ // default scope, means that subscriber has not defined a scope property
+ snprintf(filter, 128, "(&(%s=%s)(%s=%s))",
+ (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_SUBSCRIBER_SERVICE_NAME,
+ PUBSUB_SUBSCRIBER_TOPIC,topic);
+
+ } else {
+ snprintf(filter, 128, "(&(%s=%s)(%s=%s)(%s=%s))",
+ (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_SUBSCRIBER_SERVICE_NAME,
+ PUBSUB_SUBSCRIBER_TOPIC,topic,
+ PUBSUB_SUBSCRIBER_SCOPE,scope);
+ }
+ service_tracker_customizer_pt customizer = NULL;
+ status += serviceTrackerCustomizer_create(ts,NULL,topicsub_subscriberTracked,NULL,topicsub_subscriberUntracked,&customizer);
+ status += serviceTracker_createWithFilter(bundle_context, filter, customizer, &ts->tracker);
+
+ struct sigaction actions;
+ memset(&actions, 0, sizeof(actions));
+ sigemptyset(&actions.sa_mask);
+ actions.sa_flags = 0;
+ actions.sa_handler = sigusr1_sighandler;
+
+ sigaction(SIGUSR1,&actions,NULL);
+
+ *out=ts;
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionDestroy(topic_subscription_pt ts){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+
+ ts->running = false;
+ serviceTracker_destroy(ts->tracker);
+ arrayList_clear(ts->sub_ep_list);
+ arrayList_destroy(ts->sub_ep_list);
+ /* TODO: Destroy all the serializer maps? */
+ hashMap_destroy(ts->servicesMap,false,false);
+
+ celixThreadMutex_lock(&ts->pendingConnections_lock);
+ arrayList_destroy(ts->pendingConnections);
+ celixThreadMutex_unlock(&ts->pendingConnections_lock);
+ celixThreadMutex_destroy(&ts->pendingConnections_lock);
+
+ celixThreadMutex_lock(&ts->pendingDisconnections_lock);
+ arrayList_destroy(ts->pendingDisconnections);
+ celixThreadMutex_unlock(&ts->pendingDisconnections_lock);
+ celixThreadMutex_destroy(&ts->pendingDisconnections_lock);
+
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ celixThreadMutex_lock(&ts->socket_lock);
+ zsock_destroy(&(ts->zmq_socket));
+#ifdef BUILD_WITH_ZMQ_SECURITY
+ zcert_destroy(&(ts->zmq_cert));
+ zcert_destroy(&(ts->zmq_pub_cert));
+#endif
+ celixThreadMutex_unlock(&ts->socket_lock);
+ celixThreadMutex_destroy(&ts->socket_lock);
+
+ celixThreadMutex_destroy(&ts->ts_lock);
+
+ free(ts);
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionStart(topic_subscription_pt ts){
+ celix_status_t status = CELIX_SUCCESS;
+
+ status = serviceTracker_open(ts->tracker);
+
+ ts->running = true;
+
+ if(status==CELIX_SUCCESS){
+ status=celixThread_create(&ts->recv_thread,NULL,zmq_recv_thread_func,ts);
+ }
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionStop(topic_subscription_pt ts){
+ celix_status_t status = CELIX_SUCCESS;
+
+ ts->running = false;
+
+ pthread_kill(ts->recv_thread.thread,SIGUSR1);
+
+ celixThread_join(ts->recv_thread,NULL);
+
+ status = serviceTracker_close(ts->tracker);
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionConnectPublisher(topic_subscription_pt ts, char* pubURL){
+ celix_status_t status = CELIX_SUCCESS;
+ celixThreadMutex_lock(&ts->socket_lock);
+ if(!zsock_is(ts->zmq_socket) || zsock_connect(ts->zmq_socket,"%s",pubURL) != 0){
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ celixThreadMutex_unlock(&ts->socket_lock);
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionAddConnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL) {
+ celix_status_t status = CELIX_SUCCESS;
+ char *url = strdup(pubURL);
+ celixThreadMutex_lock(&ts->pendingConnections_lock);
+ arrayList_add(ts->pendingConnections, url);
+ celixThreadMutex_unlock(&ts->pendingConnections_lock);
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL) {
+ celix_status_t status = CELIX_SUCCESS;
+ char *url = strdup(pubURL);
+ celixThreadMutex_lock(&ts->pendingDisconnections_lock);
+ arrayList_add(ts->pendingDisconnections, url);
+ celixThreadMutex_unlock(&ts->pendingDisconnections_lock);
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionDisconnectPublisher(topic_subscription_pt ts, char* pubURL){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->socket_lock);
+ if(!zsock_is(ts->zmq_socket) || zsock_disconnect(ts->zmq_socket,"%s",pubURL) != 0){
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ celixThreadMutex_unlock(&ts->socket_lock);
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionAddSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ arrayList_add(ts->sub_ep_list,subEP);
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+
+}
+
+celix_status_t pubsub_topicIncreaseNrSubscribers(topic_subscription_pt ts) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ ts->nrSubscribers++;
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionRemoveSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ arrayList_removeElement(ts->sub_ep_list,subEP);
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+}
+
+celix_status_t pubsub_topicDecreaseNrSubscribers(topic_subscription_pt ts) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ ts->nrSubscribers--;
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+}
+
+unsigned int pubsub_topicGetNrSubscribers(topic_subscription_pt ts) {
+ return ts->nrSubscribers;
+}
+
+array_list_pt pubsub_topicSubscriptionGetSubscribersList(topic_subscription_pt sub){
+ return sub->sub_ep_list;
+}
+
+static celix_status_t topicsub_subscriberTracked(void * handle, service_reference_pt reference, void * service){
+ celix_status_t status = CELIX_SUCCESS;
+ topic_subscription_pt ts = handle;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ if (!hashMap_containsKey(ts->servicesMap, service)) {
+ bundle_pt bundle = NULL;
+ hash_map_pt msgTypes = NULL;
+
+ serviceReference_getBundle(reference, &bundle);
+
+ if(ts->serializer != NULL && bundle!=NULL){
+ ts->serializer->createSerializerMap(ts->serializer->handle,bundle,&msgTypes);
+ if(msgTypes != NULL){
+ hashMap_put(ts->servicesMap, service, msgTypes);
+ printf("PSA_ZMQ_TS: New subscriber registered.\n");
+ }
+ }
+ else{
+ printf("PSA_ZMQ_TS: Cannot register new subscriber.\n");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ }
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+}
+
+static celix_status_t topicsub_subscriberUntracked(void * handle, service_reference_pt reference, void * service){
+ celix_status_t status = CELIX_SUCCESS;
+ topic_subscription_pt ts = handle;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ if (hashMap_containsKey(ts->servicesMap, service)) {
+ hash_map_pt msgTypes = hashMap_remove(ts->servicesMap, service);
+ if(msgTypes!=NULL && ts->serializer!=NULL){
+ ts->serializer->destroySerializerMap(ts->serializer->handle,msgTypes);
+ printf("PSA_ZMQ_TS: Subscriber unregistered.\n");
+ }
+ else{
+ printf("PSA_ZMQ_TS: Cannot unregister subscriber.\n");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ }
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+}
+
+
+static void process_msg(topic_subscription_pt sub,array_list_pt msg_list){
+
+ pubsub_msg_header_pt first_msg_hdr = (pubsub_msg_header_pt)zframe_data(((complete_zmq_msg_pt)arrayList_get(msg_list,0))->header);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(sub->servicesMap);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ pubsub_subscriber_pt subsvc = hashMapEntry_getKey(entry);
+ hash_map_pt msgTypes = hashMapEntry_getValue(entry);
+
+ pubsub_msg_serializer_t *msgSer = hashMap_get(msgTypes,(void*)(uintptr_t )first_msg_hdr->type);
+ if (msgSer == NULL) {
+ printf("PSA_ZMQ_TS: Primary message %d not supported. NOT sending any part of the whole message.\n",first_msg_hdr->type);
+ }
+ else{
+ void *msgInst = NULL;
+ bool validVersion = checkVersion(msgSer->msgVersion,first_msg_hdr);
+
+ if(validVersion){
+
+ celix_status_t status = msgSer->deserialize(msgSer, (const void *) zframe_data(((complete_zmq_msg_pt)arrayList_get(msg_list,0))->payload), 0, &msgInst);
+
+ if (status == CELIX_SUCCESS) {
+ bool release = true;
+ mp_handle_pt mp_handle = create_mp_handle(msgTypes,msg_list);
+ pubsub_multipart_callbacks_t mp_callbacks;
+ mp_callbacks.handle = mp_handle;
+ mp_callbacks.localMsgTypeIdForMsgType = pubsub_localMsgTypeIdForMsgType;
+ mp_callbacks.getMultipart = pubsub_getMultipart;
+ subsvc->receive(subsvc->handle, msgSer->msgName, first_msg_hdr->type, msgInst, &mp_callbacks, &release);
+
+ if(release){
+ msgSer->freeMsg(msgSer,msgInst); // pubsubSerializer_freeMsg(msgType, msgInst);
+ }
+ if(mp_handle!=NULL){
+ destroy_mp_handle(mp_handle);
+ }
+ }
+ else{
+ printf("PSA_ZMQ_TS: Cannot deserialize msgType %s.\n",msgSer->msgName);
+ }
+
+ }
+ else{
+ int major=0,minor=0;
+ version_getMajor(msgSer->msgVersion,&major);
+ version_getMinor(msgSer->msgVersion,&minor);
+ printf("PSA_ZMQ_TS: Version mismatch for primary message '%s' (have %d.%d, received %u.%u). NOT sending any part of the whole message.\n",
+ msgSer->msgName,major,minor,first_msg_hdr->major,first_msg_hdr->minor);
+ }
+
+ }
+ }
+ hashMapIterator_destroy(iter);
+
+ int i = 0;
+ for(;i<arrayList_size(msg_list);i++){
+ complete_zmq_msg_pt c_msg = arrayList_get(msg_list,i);
+ zframe_destroy(&(c_msg->header));
+ zframe_destroy(&(c_msg->payload));
+ free(c_msg);
+ }
+
+ arrayList_destroy(msg_list);
+
+}
+
+static void* zmq_recv_thread_func(void * arg) {
+ topic_subscription_pt sub = (topic_subscription_pt) arg;
+
+ while (sub->running) {
+
+ celixThreadMutex_lock(&sub->socket_lock);
+
+ zframe_t* headerMsg = zframe_recv(sub->zmq_socket);
+ if (headerMsg == NULL) {
+ if (errno == EINTR) {
+ //It means we got a signal and we have to exit...
+ printf("PSA_ZMQ_TS: header_recv thread for topic got a signal and will exit.\n");
+ } else {
+ perror("PSA_ZMQ_TS: header_recv thread");
+ }
+ }
+ else {
+
+ pubsub_msg_header_pt hdr = (pubsub_msg_header_pt) zframe_data(headerMsg);
+
+ if (zframe_more(headerMsg)) {
+
+ zframe_t* payloadMsg = zframe_recv(sub->zmq_socket);
+ if (payloadMsg == NULL) {
+ if (errno == EINTR) {
+ //It means we got a signal and we have to exit...
+ printf("PSA_ZMQ_TS: payload_recv thread for topic got a signal and will exit.\n");
+ } else {
+ perror("PSA_ZMQ_TS: payload_recv");
+ }
+ zframe_destroy(&headerMsg);
+ } else {
+
+ //Let's fetch all the messages from the socket
+ array_list_pt msg_list = NULL;
+ arrayList_create(&msg_list);
+ complete_zmq_msg_pt firstMsg = calloc(1, sizeof(struct complete_zmq_msg));
+ firstMsg->header = headerMsg;
+ firstMsg->payload = payloadMsg;
+ arrayList_add(msg_list, firstMsg);
+
+ bool more = zframe_more(payloadMsg);
+ while (more) {
+
+ zframe_t* h_msg = zframe_recv(sub->zmq_socket);
+ if (h_msg == NULL) {
+ if (errno == EINTR) {
+ //It means we got a signal and we have to exit...
+ printf("PSA_ZMQ_TS: h_recv thread for topic got a signal and will exit.\n");
+ } else {
+ perror("PSA_ZMQ_TS: h_recv");
+ }
+ break;
+ }
+
+ zframe_t* p_msg = zframe_recv(sub->zmq_socket);
+ if (p_msg == NULL) {
+ if (errno == EINTR) {
+ //It means we got a signal and we have to exit...
+ printf("PSA_ZMQ_TS: p_recv thread for topic got a signal and will exit.\n");
+ } else {
+ perror("PSA_ZMQ_TS: p_recv");
+ }
+ zframe_destroy(&h_msg);
+ break;
+ }
+
+ complete_zmq_msg_pt c_msg = calloc(1, sizeof(struct complete_zmq_msg));
+ c_msg->header = h_msg;
+ c_msg->payload = p_msg;
+ arrayList_add(msg_list, c_msg);
+
+ if (!zframe_more(p_msg)) {
+ more = false;
+ }
+ }
+
+ celixThreadMutex_lock(&sub->ts_lock);
+ process_msg(sub, msg_list);
+ celixThreadMutex_unlock(&sub->ts_lock);
+
+ }
+
+ } //zframe_more(headerMsg)
+ else {
+ free(headerMsg);
+ printf("PSA_ZMQ_TS: received message %u for topic %s without payload!\n", hdr->type, hdr->topic);
+ }
+
+ } // headerMsg != NULL
+ celixThreadMutex_unlock(&sub->socket_lock);
+ connectPendingPublishers(sub);
+ disconnectPendingPublishers(sub);
+ } // while
+
+ return NULL;
+}
+
+static void connectPendingPublishers(topic_subscription_pt sub) {
+ celixThreadMutex_lock(&sub->pendingConnections_lock);
+ while(!arrayList_isEmpty(sub->pendingConnections)) {
+ char * pubEP = arrayList_remove(sub->pendingConnections, 0);
+ pubsub_topicSubscriptionConnectPublisher(sub, pubEP);
+ free(pubEP);
+ }
+ celixThreadMutex_unlock(&sub->pendingConnections_lock);
+}
+
+static void disconnectPendingPublishers(topic_subscription_pt sub) {
+ celixThreadMutex_lock(&sub->pendingDisconnections_lock);
+ while(!arrayList_isEmpty(sub->pendingDisconnections)) {
+ char * pubEP = arrayList_remove(sub->pendingDisconnections, 0);
+ pubsub_topicSubscriptionDisconnectPublisher(sub, pubEP);
+ free(pubEP);
+ }
+ celixThreadMutex_unlock(&sub->pendingDisconnections_lock);
+}
+
+static void sigusr1_sighandler(int signo){
+ printf("PSA_ZMQ_TS: Topic subscription being shut down...\n");
+ return;
+}
+
+static bool checkVersion(version_pt msgVersion,pubsub_msg_header_pt hdr){
+ bool check=false;
+ int major=0,minor=0;
+
+ if(msgVersion!=NULL){
+ version_getMajor(msgVersion,&major);
+ version_getMinor(msgVersion,&minor);
+ if(hdr->major==((unsigned char)major)){ /* Different major means incompatible */
+ check = (hdr->minor>=((unsigned char)minor)); /* Compatible only if the provider has a minor equals or greater (means compatible update) */
+ }
+ }
+
+ return check;
+}
+
+static int pubsub_localMsgTypeIdForMsgType(void* handle, const char* msgType, unsigned int* msgTypeId){
+ *msgTypeId = utils_stringHash(msgType);
+ return 0;
+}
+
+static int pubsub_getMultipart(void *handle, unsigned int msgTypeId, bool retain, void **part){
+
+ if(handle==NULL){
+ *part = NULL;
+ return -1;
+ }
+
+ mp_handle_pt mp_handle = (mp_handle_pt)handle;
+ msg_map_entry_pt entry = hashMap_get(mp_handle->rcv_msg_map, (void*)(uintptr_t) msgTypeId);
+ if(entry!=NULL){
+ entry->retain = retain;
+ *part = entry->msgInst;
+ }
+ else{
+ printf("TP: getMultipart cannot find msg '%u'\n",msgTypeId);
+ *part=NULL;
+ return -2;
+ }
+
+ return 0;
+
+}
+
+static mp_handle_pt create_mp_handle(hash_map_pt svc_msg_db,array_list_pt rcv_msg_list){
+
+ if(arrayList_size(rcv_msg_list)==1){ //Means it's not a multipart message
+ return NULL;
+ }
+
+ mp_handle_pt mp_handle = calloc(1,sizeof(struct mp_handle));
+ mp_handle->svc_msg_db = svc_msg_db;
+ mp_handle->rcv_msg_map = hashMap_create(NULL, NULL, NULL, NULL);
+
+ int i=1; //We skip the first message, it will be handle differently
+ for(;i<arrayList_size(rcv_msg_list);i++){
+ complete_zmq_msg_pt c_msg = (complete_zmq_msg_pt)arrayList_get(rcv_msg_list,i);
+ pubsub_msg_header_pt header = (pubsub_msg_header_pt)zframe_data(c_msg->header);
+
+ pubsub_msg_serializer_t* msgSer = hashMap_get(svc_msg_db, (void*)(uintptr_t)(header->type));
+
+ if (msgSer!= NULL) {
+ void *msgInst = NULL;
+
+ bool validVersion = checkVersion(msgSer->msgVersion,header);
+
+ if(validVersion){
+ celix_status_t status = msgSer->deserialize(msgSer, (const void*)zframe_data(c_msg->payload), 0, &msgInst);
+
+ if(status == CELIX_SUCCESS){
+ msg_map_entry_pt entry = calloc(1,sizeof(struct msg_map_entry));
+ entry->msgInst = msgInst;
+ hashMap_put(mp_handle->rcv_msg_map, (void*)(uintptr_t)header->type,entry);
+ }
+ }
+ }
+ }
+
+ return mp_handle;
+
+}
+
+static void destroy_mp_handle(mp_handle_pt mp_handle){
+
+ hash_map_iterator_pt iter = hashMapIterator_create(mp_handle->rcv_msg_map);
+ while(hashMapIterator_hasNext(iter)){
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ unsigned int msgId = (unsigned int)(uintptr_t)hashMapEntry_getKey(entry);
+ msg_map_entry_pt msgEntry = hashMapEntry_getValue(entry);
+ pubsub_msg_serializer_t* msgSer = hashMap_get(mp_handle->svc_msg_db, (void*)(uintptr_t)msgId);
+
+ if(msgSer!=NULL){
+ if(!msgEntry->retain){
+ msgSer->freeMsg(msgSer->handle,msgEntry->msgInst);
+ }
+ }
+ else{
+ printf("PSA_ZMQ_TS: ERROR: Cannot find messageSerializer for msg %u, so cannot destroy it!\n",msgId);
+ }
+
+ free(msgEntry);
+ }
+ hashMapIterator_destroy(iter);
+
+ hashMap_destroy(mp_handle->rcv_msg_map,false,false);
+ free(mp_handle);
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/pubsub_discovery/CMakeLists.txt
----------------------------------------------------------------------
diff --cc pubsub/pubsub_discovery/CMakeLists.txt
index f92f81c,42017e7..d034a70
--- a/pubsub/pubsub_discovery/CMakeLists.txt
+++ b/pubsub/pubsub_discovery/CMakeLists.txt
@@@ -18,24 -18,26 +18,24 @@@
find_package(CURL REQUIRED)
find_package(Jansson REQUIRED)
- add_bundle(celix_pubsub_discovery_etcd
-include_directories("${CURL_INCLUDE_DIR}")
-include_directories("${JANSSON_INCLUDE_DIR}")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-include_directories("${PROJECT_SOURCE_DIR}/etcdlib/public/include")
-include_directories("private/include")
-include_directories("public/include")
-
-add_celix_bundle(org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
++add_celix_bundle(celix_pubsub_discovery_etcd
BUNDLE_SYMBOLICNAME "apache_celix_pubsub_discovery_etcd"
VERSION "1.0.0"
SOURCES
- private/src/psd_activator.c
- private/src/pubsub_discovery_impl.c
- private/src/etcd_common.c
- private/src/etcd_watcher.c
- private/src/etcd_writer.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_endpoint.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
+ src/psd_activator.c
+ src/pubsub_discovery_impl.c
+ src/etcd_common.c
+ src/etcd_watcher.c
+ src/etcd_writer.c
+)
+
+target_include_directories(celix_pubsub_discovery_etcd PRIVATE
+ src
+ ${CURL_INCLUDE_DIR}
+ ${JANSSON_INCLUDE_DIR}
)
-target_link_libraries(org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery celix_framework celix_utils etcdlib_static ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
-install_celix_bundle(org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery)
+target_link_libraries(celix_pubsub_discovery_etcd PRIVATE Celix::pubsub_spi Celix::framework Celix::etcdlib_static ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
- install_bundle(celix_pubsub_discovery_etcd)
++install_celix_bundle(celix_pubsub_discovery_etcd)
+
+add_library(Celix::pubsub_discovery_etcd ALIAS celix_pubsub_discovery_etcd)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/pubsub_serializer_json/CMakeLists.txt
----------------------------------------------------------------------
diff --cc pubsub/pubsub_serializer_json/CMakeLists.txt
index 1269cad,2aaa98a..9a486f2
--- a/pubsub/pubsub_serializer_json/CMakeLists.txt
+++ b/pubsub/pubsub_serializer_json/CMakeLists.txt
@@@ -17,24 -17,27 +17,24 @@@
find_package(Jansson REQUIRED)
-include_directories("private/include")
-include_directories("public/include")
-include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/dfi/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-include_directories("${JANSSON_INCLUDE_DIR}")
-
-add_celix_bundle(org.apache.celix.pubsub_serializer.PubSubSerializerJson
+
- add_bundle(celix_pubsub_serializer_json
++add_celix_bundle(celix_pubsub_serializer_json
BUNDLE_SYMBOLICNAME "apache_celix_pubsub_serializer_json"
VERSION "1.0.0"
SOURCES
- private/src/ps_activator.c
- private/src/pubsub_serializer_impl.c
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
+ src/ps_activator.c
+ src/pubsub_serializer_impl.c
+)
+
+target_include_directories(celix_pubsub_serializer_json PRIVATE
+ src
+ ${JANSSON_INCLUDE_DIR}
)
-set_target_properties(org.apache.celix.pubsub_serializer.PubSubSerializerJson PROPERTIES INSTALL_RPATH "$ORIGIN")
-target_link_libraries(org.apache.celix.pubsub_serializer.PubSubSerializerJson celix_framework celix_utils celix_dfi ${JANSSON_LIBRARIES})
+set_target_properties(celix_pubsub_serializer_json PROPERTIES INSTALL_RPATH "$ORIGIN")
+target_link_libraries(celix_pubsub_serializer_json PRIVATE Celix::pubsub_spi Celix::framework Celix::dfi ${JANSSON_LIBRARIES} Celix::log_helper)
+
- install_bundle(celix_pubsub_serializer_json)
++install_celix_bundle(celix_pubsub_serializer_json)
-install_celix_bundle(org.apache.celix.pubsub_serializer.PubSubSerializerJson)
+add_library(Celix::pubsub_serializer_json ALIAS celix_pubsub_serializer_json)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/pubsub_spi/CMakeLists.txt
----------------------------------------------------------------------
diff --cc pubsub/pubsub_spi/CMakeLists.txt
index 118dd3a,0000000..ee9d4b6
mode 100644,000000..100644
--- a/pubsub/pubsub_spi/CMakeLists.txt
+++ b/pubsub/pubsub_spi/CMakeLists.txt
@@@ -1,35 -1,0 +1,36 @@@
+# 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.
+
- add_library(celix_pubsub_spi STATIC
++add_library(pubsub_spi STATIC
+ src/pubsub_admin_match.c
+ src/pubsub_endpoint.c
+ src/pubsub_utils.c
+)
- target_include_directories(celix_pubsub_spi PUBLIC
++set_target_properties(pubsub_spi PROPERTIES OUTPUT_NAME "celix_pubsub_spi")
++target_include_directories(pubsub_spi PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
+ $<INSTALL_INTERFACE:include/celix/pubsub_spi>
+)
- target_link_libraries(celix_pubsub_spi PUBLIC Celix::framework Celix::pubsub_api)
++target_link_libraries(pubsub_spi PUBLIC Celix::framework Celix::pubsub_api)
+
- set_target_properties(celix_pubsub_spi PROPERTIES TOPIC_INFO_DESCRIPTOR ${CMAKE_CURRENT_LIST_DIR}/include/pubsub_topic_info.descriptor)
++set_target_properties(pubsub_spi PROPERTIES TOPIC_INFO_DESCRIPTOR ${CMAKE_CURRENT_LIST_DIR}/include/pubsub_topic_info.descriptor)
+#TODO how to make this descriptor available for imported targets? $<INSTALL_INTERFACE:include/celix/pubsub_spi/pubsub_topic_info.descriptor>
+
- add_library(Celix::pubsub_spi ALIAS celix_pubsub_spi)
++add_library(Celix::pubsub_spi ALIAS pubsub_spi)
+
- install(TARGETS celix_pubsub_spi EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT pubsub)
++install(TARGETS pubsub_spi EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT pubsub)
+install(DIRECTORY include/ DESTINATION include/celix/pubsub_spi COMPONENT pubsub)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/pubsub_topology_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --cc pubsub/pubsub_topology_manager/CMakeLists.txt
index 73b9ecb,a064143..181b30d
--- a/pubsub/pubsub_topology_manager/CMakeLists.txt
+++ b/pubsub/pubsub_topology_manager/CMakeLists.txt
@@@ -15,23 -15,30 +15,23 @@@
# specific language governing permissions and limitations
# under the License.
- add_bundle(celix_pubsub_topology_manager
-include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_admin/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-include_directories("private/include")
-include_directories("public/include")
-
-add_celix_bundle(org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
++add_celix_bundle(celix_pubsub_topology_manager
BUNDLE_SYMBOLICNAME "apache_celix_pubsub_topology_manager"
VERSION "1.0.0"
SOURCES
- private/src/pstm_activator.c
- private/src/pubsub_topology_manager.c
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_endpoint.c
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
+ src/pstm_activator.c
+ src/pubsub_topology_manager.c
+ src/pubsub_topology_manager.h
)
+target_link_libraries(celix_pubsub_topology_manager PRIVATE Celix::framework Celix::log_helper Celix::pubsub_spi)
-celix_bundle_files(org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
- ${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include/pubsub_topic_info.descriptor
+get_target_property(DESC Celix::pubsub_spi TOPIC_INFO_DESCRIPTOR)
- bundle_files(celix_pubsub_topology_manager
++celix_bundle_files(celix_pubsub_topology_manager
+ ${DESC}
DESTINATION "META-INF/descriptors/services"
)
- install_bundle(celix_pubsub_topology_manager)
-target_link_libraries(org.apache.celix.pubsub_topology_manager.PubSubTopologyManager celix_framework celix_utils)
-install_celix_bundle(org.apache.celix.pubsub_topology_manager.PubSubTopologyManager)
++install_celix_bundle(celix_pubsub_topology_manager)
+
+add_library(Celix::pubsub_topology_manager ALIAS celix_pubsub_topology_manager)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/pubsub/test/CMakeLists.txt
----------------------------------------------------------------------
diff --cc pubsub/test/CMakeLists.txt
index 9fd324e,41fffe0..13e7d82
--- a/pubsub/test/CMakeLists.txt
+++ b/pubsub/test/CMakeLists.txt
@@@ -20,22 -20,24 +20,22 @@@ find_program(ETCD_CMD NAMES etcd
find_package(CppUTest REQUIRED)
include_directories(${CPPUTEST_INCLUDE_DIR})
- add_bundle(pubsub_sut
-include_directories(
- ${CMAKE_SOURCE_DIR}/pubsub/api
- test
-)
-
+ add_celix_bundle(pubsub_sut
#"Vanilla" bundle which is under test
SOURCES
test/sut_activator.c
VERSION 1.0.0
)
-target_link_libraries(pubsub_sut celix_framework celix_utils)
+target_include_directories(pubsub_sut PRIVATE test)
+target_link_libraries(pubsub_sut PRIVATE Celix::pubsub_spi)
+
- bundle_files(pubsub_sut
+ celix_bundle_files(pubsub_sut
msg_descriptors/msg.descriptor
msg_descriptors/sync.descriptor
DESTINATION "META-INF/descriptors/messages"
)
+
- add_deploy(pubsub_udpmc_sut
+ add_celix_container(pubsub_udpmc_sut
NAME deploy_sut
BUNDLES
org.apache.celix.pubsub_serializer.PubSubSerializerJson
@@@ -64,12 -66,12 +64,12 @@@ add_celix_bundle(pubsub_ts
)
if (APPLE)
#Note that the launcher celix_test_runner is linked with CppuTest, not the bundle libs. Default libCppUTest.a is not compiled for relocation
- target_link_libraries(pubsub_tst celix_framework celix_utils -Wl,-undefined -Wl,dynamic_lookup)
+ target_link_libraries(pubsub_tst PRIVATE Celix::framework -Wl,-undefined -Wl,dynamic_lookup)
else ()
- target_link_libraries(pubsub_tst celix_framework celix_utils)
+ target_link_libraries(pubsub_tst PRIVATE Celix::framework)
endif ()
- bundle_files(pubsub_tst
+ celix_bundle_files(pubsub_tst
msg_descriptors/msg.descriptor
msg_descriptors/sync.descriptor
DESTINATION "META-INF/descriptors/messages"
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/remote_services/civetweb/CMakeLists.txt
----------------------------------------------------------------------
diff --cc remote_services/civetweb/CMakeLists.txt
index a6f7d10,0000000..46b9637
mode 100644,000000..100644
--- a/remote_services/civetweb/CMakeLists.txt
+++ b/remote_services/civetweb/CMakeLists.txt
@@@ -1,26 -1,0 +1,26 @@@
+# 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.
+
+
+add_library(civetweb OBJECT
+ src/civetweb.c
+ src/md5.inl
+)
+target_include_directories(civetweb PUBLIC include)
+
+#Setup target aliases to match external usage
- add_library(Celix::civetweb ALIAS civetweb)
++add_library(Celix::civetweb ALIAS civetweb)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/remote_services/discovery_common/CMakeLists.txt
----------------------------------------------------------------------
diff --cc remote_services/discovery_common/CMakeLists.txt
index 114f485,0000000..97e9676
mode 100644,000000..100644
--- a/remote_services/discovery_common/CMakeLists.txt
+++ b/remote_services/discovery_common/CMakeLists.txt
@@@ -1,39 -1,0 +1,39 @@@
+# 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.
+
+
+find_package(LibXml2 REQUIRED)
+
+add_library(rsa_discovery_common OBJECT
+ src/discovery.c
+ src/discovery_activator.c
+ src/endpoint_descriptor_reader.c
+ src/endpoint_descriptor_writer.c
+ src/endpoint_discovery_poller.c
+ src/endpoint_discovery_server.c
+)
+target_include_directories(rsa_discovery_common PUBLIC
+ include src
+ $<TARGET_PROPERTY:Celix::framework,INTERFACE_INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::utils,INTERFACE_INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::log_helper,INTERFACE_INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::rsa_spi,INTERFACE_INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:civetweb,INCLUDE_DIRECTORIES>
+ ${LIBXML2_INCLUDE_DIR})
+
+#Setup target aliases to match external usage
- add_library(Celix::rsa_discovery_common ALIAS rsa_discovery_common)
++add_library(Celix::rsa_discovery_common ALIAS rsa_discovery_common)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/remote_services/discovery_configured/CMakeLists.txt
----------------------------------------------------------------------
diff --cc remote_services/discovery_configured/CMakeLists.txt
index 83b18c7,c3180ad..fe658ca
--- a/remote_services/discovery_configured/CMakeLists.txt
+++ b/remote_services/discovery_configured/CMakeLists.txt
@@@ -19,24 -19,54 +19,24 @@@ if (RSA_DISCOVERY_CONFIGURED
find_package(CURL REQUIRED)
find_package(LibXml2 REQUIRED)
- add_bundle(rsa_discovery_configured
- include_directories("${CURL_INCLUDE_DIR}")
- include_directories("${LIBXML2_INCLUDE_DIR}")
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/discovery/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/discovery_configured/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
- include_directories(private/include)
-
- add_celix_bundle(discovery_configured
- VERSION 0.9.0
- SYMBOLIC_NAME "apache_celix_rsa_discovery_configured"
- NAME "Apache Celix RSA Configured Discovery"
- SOURCES
-
- private/src/discovery_impl.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/discovery_activator.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/discovery.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_descriptor_reader.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_descriptor_writer.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_discovery_poller.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_discovery_server.c
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
- ${PROJECT_SOURCE_DIR}/remote_services/utils/private/src/civetweb.c
-
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
++ add_celix_bundle(rsa_discovery_configured
+ VERSION 0.9.0
+ SYMBOLIC_NAME "apache_celix_rsa_discovery_configured"
+ NAME "Apache Celix RSA Configured Discovery"
+ SOURCES
+ src/discovery_impl.c
+ $<TARGET_OBJECTS:Celix::rsa_discovery_common>
+ $<TARGET_OBJECTS:Celix::civetweb>
)
+ target_include_directories(rsa_discovery_configured PRIVATE
+ src
+ $<TARGET_PROPERTY:Celix::rsa_discovery_common,INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::civetweb,INCLUDE_DIRECTORIES>
+ )
+ target_link_libraries(rsa_discovery_configured PRIVATE ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} Celix::log_helper Celix::rsa_common)
- install_bundle(rsa_discovery_configured)
- install_celix_bundle(discovery_configured)
-
- target_link_libraries(discovery_configured celix_framework ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES})
-
- if (RSA_ENDPOINT_TEST_READER)
- add_executable(descparser
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_descriptor_reader.c
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c)
-
- target_link_libraries(descparser ${LIBXML2_LIBRARIES} celix_framework celix_utils)
- endif (RSA_ENDPOINT_TEST_READER)
-
- if (RSA_ENDPOINT_TEST_WRITER)
- add_executable(descwriter
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_descriptor_writer.c
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c)
++ install_celix_bundle(rsa_discovery_configured)
- target_link_libraries(descwriter ${LIBXML2_LIBRARIES} celix_framework celix_utils)
- endif(RSA_ENDPOINT_TEST_WRITER)
+ #Setup target aliases to match external usage
+ add_library(Celix::rsa_discovery_configured ALIAS rsa_discovery_configured)
endif (RSA_DISCOVERY_CONFIGURED)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/remote_services/discovery_etcd/CMakeLists.txt
----------------------------------------------------------------------
diff --cc remote_services/discovery_etcd/CMakeLists.txt
index fe88532,ce25d22..776ad93
--- a/remote_services/discovery_etcd/CMakeLists.txt
+++ b/remote_services/discovery_etcd/CMakeLists.txt
@@@ -20,30 -20,42 +20,30 @@@ if (RSA_DISCOVERY_ETCD
find_package(CURL REQUIRED)
find_package(LibXml2 REQUIRED)
find_package(Jansson REQUIRED)
-
- include_directories("${CURL_INCLUDE_DIR}")
- include_directories("${JANSSON_INCLUDE_DIR}")
- include_directories("${LIBXML2_INCLUDE_DIR}")
- include_directories("${PROJECT_SOURCE_DIR}/etcdlib/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/discovery/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/discovery_etcd/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
- include_directories("private/include")
- add_bundle(rsa_discovery_etcd
- add_celix_bundle(discovery_etcd
++ add_celix_bundle(rsa_discovery_etcd
VERSION 0.9.0
SYMBOLIC_NAME "apache_celix_rsa_discovery_etcd"
NAME "Apache Celix RSA Discovery ETCD"
SOURCES
- private/src/discovery_impl.c
- private/src/etcd_watcher.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/discovery_activator.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/discovery.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_descriptor_reader.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_descriptor_writer.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_discovery_poller.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_discovery_server.c
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
- ${PROJECT_SOURCE_DIR}/remote_services/utils/private/src/civetweb.c
-
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
+ src/discovery_impl.c
+ src/etcd_watcher.c
+ $<TARGET_OBJECTS:Celix::rsa_discovery_common>
+ $<TARGET_OBJECTS:Celix::civetweb>
)
+ target_link_libraries(rsa_discovery_etcd PRIVATE Celix::log_helper Celix::etcdlib_static Celix::rsa_common)
+ target_include_directories(rsa_discovery_etcd PRIVATE src)
+ target_include_directories(rsa_discovery_etcd PRIVATE
+ $<TARGET_PROPERTY:Celix::rsa_discovery_common,INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::civetweb,INCLUDE_DIRECTORIES>
+ ${CURL_INCLUDE_DIR}
+ ${JANSSON_INCLUDE_DIR}
+ ${LIBXML2_INCLUDE_DIR}
+ )
+ target_link_libraries(rsa_discovery_etcd PRIVATE ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} ${JANSSON_LIBRARIES})
- install_bundle(rsa_discovery_etcd)
- install_celix_bundle(discovery_etcd)
-
- target_link_libraries(discovery_etcd celix_framework etcdlib ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} ${JANSSON_LIBRARIES})
++ install_celix_bundle(rsa_discovery_etcd)
+ #Setup target aliases to match external usage
+ add_library(Celix::rsa_discovery_etcd ALIAS rsa_discovery_etcd)
endif (RSA_DISCOVERY_ETCD)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/remote_services/discovery_shm/CMakeLists.txt
----------------------------------------------------------------------
diff --cc remote_services/discovery_shm/CMakeLists.txt
index fd822e6,3eec195..5557ae9
--- a/remote_services/discovery_shm/CMakeLists.txt
+++ b/remote_services/discovery_shm/CMakeLists.txt
@@@ -19,30 -19,40 +19,30 @@@ celix_subproject(RSA_DISCOVERY_SHM "Opt
if (RSA_DISCOVERY_SHM)
find_package(CURL REQUIRED)
find_package(LibXml2 REQUIRED)
-
- include_directories("${CURL_INCLUDE_DIR}")
- include_directories("${LIBXML2_INCLUDE_DIR}")
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/discovery/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/discovery_shm/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
- include_directories("private/include")
- add_bundle(rsa_discovery_shm
- add_celix_bundle(discovery_shm
++ add_celix_bundle(rsa_discovery_shm
VERSION 0.0.1
SYMBOLIC_NAME "apache_celix_rsa_discovery_shm"
NAME "Apache Celix RSA Discovery SHM"
SOURCES
- private/src/discovery_shm
- private/src/discovery_shmWatcher
- private/src/discovery_impl
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/discovery_activator.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/discovery.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_descriptor_reader.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_descriptor_writer.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_discovery_poller.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_discovery_server.c
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
- ${PROJECT_SOURCE_DIR}/remote_services/utils/private/src/civetweb.c
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
+ src/discovery_shm.c
+ src/discovery_shmWatcher.c
+ src/discovery_impl.c
+ $<TARGET_OBJECTS:Celix::rsa_discovery_common>
+ $<TARGET_OBJECTS:Celix::civetweb>
)
+ target_include_directories(rsa_discovery_shm PRIVATE
+ src
+ ${LIBXML2_INCLUDE_DIR}
+ ${CURL_INCLUDE_DIR}
+ $<TARGET_PROPERTY:Celix::rsa_discovery_common,INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::civetweb,INCLUDE_DIRECTORIES>
+ )
+ target_link_libraries(rsa_discovery_shm PRIVATE Celix::framework ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES})
+
- install_bundle(rsa_discovery_shm)
++ install_celix_bundle(rsa_discovery_shm)
- install_celix_bundle(discovery_shm)
-
- target_link_libraries(discovery_shm celix_framework ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES})
+ #Setup target aliases to match external usage
+ add_library(Celix::rsa_discovery_shm ALIAS rsa_discovery_shm)
endif (RSA_DISCOVERY_SHM)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/remote_services/examples/CMakeLists.txt
----------------------------------------------------------------------
diff --cc remote_services/examples/CMakeLists.txt
index 78bfbac,8916a18..0f8e7a9
--- a/remote_services/examples/CMakeLists.txt
+++ b/remote_services/examples/CMakeLists.txt
@@@ -17,44 -17,98 +17,44 @@@
celix_subproject(RSA_EXAMPLES "Option to enable building the RSA examples" ON DEPS LAUNCHER shell_tui log_writer RSA_TOPOLOGY_MANAGER)
if (RSA_EXAMPLES)
+ add_subdirectory(calculator_api)
add_subdirectory(calculator_service)
-
- add_subdirectory(calculator_endpoint)
- add_subdirectory(calculator_endpoint2)
-
- add_subdirectory(calculator_proxy)
- add_subdirectory(calculator_proxy2)
-
add_subdirectory(calculator_shell)
- if(BUILD_RSA_REMOTE_SERVICE_ADMIN_HTTP AND BUILD_RSA_DISCOVERY_CONFIGURED)
- add_celix_container(remote-services-cfg-server
- NAME "server"
- GROUP "remote-services/remote-services-cfg"
- BUNDLES discovery_configured topology_manager remote_service_admin_http calculator shell shell_tui log_service log_writer
- PROPERTIES
- RSA_PORT=8001
- DISCOVERY_CFG_POLL_ENDPOINTS=http://localhost:8082/org.apache.celix.discovery.configured
- DISCOVERY_CFG_SERVER_PORT=8081
- )
- celix_container_bundles_dir(remote-services-cfg-server DIR_NAME "endpoints" BUNDLES
- org.apache.celix.calc.api.Calculator_endpoint
- org.apache.celix.calc.api.Calculator2_endpoint
- )
-
- add_celix_container(remote-services-cfg-client
- NAME "client"
- GROUP "remote-services/remote-services-cfg"
- BUNDLES topology_manager remote_service_admin_http shell shell_tui log_service log_writer calculator_shell discovery_configured
- PROPERTIES
- RSA_PORT=8002
- DISCOVERY_CFG_POLL_ENDPOINTS=http://localhost:8081/org.apache.celix.discovery.configured
- DISCOVERY_CFG_SERVER_PORT=8082
- )
- celix_container_bundles_dir(remote-services-cfg-client DIR_NAME "endpoints"
- BUNDLES org.apache.celix.calc.api.Calculator_proxy org.apache.celix.calc.api.Calculator2_proxy
- )
- endif()
-
- if (BUILD_RSA_REMOTE_SERVICE_ADMIN_SHM AND BUILD_RSA_DISCOVERY_SHM)
- add_celix_container(remote-services-shm
- NAME "server"
- GROUP "remote-services/remote-services-shm"
- BUNDLES discovery_shm topology_manager remote_service_admin_shm calculator shell shell_tui log_service log_writer
- )
- celix_container_bundles_dir(remote-services-shm DIR_NAME "endpoints"
- BUNDLES org.apache.celix.calc.api.Calculator_endpoint
- )
-
- add_celix_container(remote-services-shm-client
- NAME "client"
- GROUP "remote-services/remote-services-shm"
- BUNDLES topology_manager remote_service_admin_shm shell shell_tui log_service log_writer calculator_shell discovery_shm
- )
- celix_container_bundles_dir(remote-services-shm-client DIR_NAME "endpoints"
- BUNDLES org.apache.celix.calc.api.Calculator_proxy
- )
- endif ()
- if (BUILD_RSA_DISCOVERY_ETCD AND BUILD_RSA_REMOTE_SERVICE_ADMIN_HTTP)
- add_celix_container(remote-services-etcd
- NAME "server"
- GROUP "remote-services/remote-services-etcd"
- BUNDLES discovery_etcd topology_manager remote_service_admin_http calculator shell shell_tui log_service log_writer
- )
- celix_container_bundles_dir(remote-services-etcd DIR_NAME "endpoints"
- BUNDLES
- org.apache.celix.calc.api.Calculator_endpoint
- org.apache.celix.calc.api.Calculator2_endpoint
- )
+# TODO refactor shm remote service admin to use dfi
+# if (BUILD_RSA_REMOTE_SERVICE_ADMIN_SHM AND BUILD_RSA_DISCOVERY_SHM)
- # add_deploy(remote-services-shm
++# add_celix_container(remote-services-shm
+# NAME "server"
+# GROUP "remote-services/remote-services-shm"
+# BUNDLES discovery_shm topology_manager remote_service_admin_shm calculator shell shell_tui log_service log_writer
+# )
- # deploy_bundles_dir(remote-services-shm DIR_NAME "endpoints"
++# celix_container_bundles_dir(remote-services-shm DIR_NAME "endpoints"
+# BUNDLES org.apache.celix.calc.api.Calculator_endpoint
+# )
+#
- # add_deploy(remote-services-shm-client
++# add_celix_container(remote-services-shm-client
+# NAME "client"
+# GROUP "remote-services/remote-services-shm"
+# BUNDLES topology_manager remote_service_admin_shm shell shell_tui log_service log_writer calculator_shell discovery_shm
+# )
- # deploy_bundles_dir(remote-services-shm-client DIR_NAME "endpoints"
++# celix_container_bundles_dir(remote-services-shm-client DIR_NAME "endpoints"
+# BUNDLES org.apache.celix.calc.api.Calculator_proxy
+# )
+# endif ()
- add_celix_container("remote-services-etcd-client"
- NAME "client"
- GROUP "remote-services/remote-services-etcd"
- BUNDLES topology_manager remote_service_admin_http shell shell_tui log_service log_writer calculator_shell discovery_etcd
- )
- celix_container_bundles_dir(remote-services-etcd-client DIR_NAME "endpoints"
- BUNDLES org.apache.celix.calc.api.Calculator_proxy
- )
- endif ()
if (BUILD_RSA_DISCOVERY_ETCD AND BUILD_RSA_REMOTE_SERVICE_ADMIN_DFI)
- add_deploy(remote-services-dfi
+ add_celix_container(remote-services-dfi
NAME "server"
GROUP "remote-services/remote-services-dfi"
- BUNDLES discovery_etcd topology_manager remote_service_admin_dfi calculator shell shell_tui log_service log_writer
+ BUNDLES Celix::rsa_discovery_etcd Celix::rsa_topology_manager Celix::rsa_dfi calculator Celix::shell Celix::shell_tui Celix::log_service Celix::log_writer_stdout
)
- add_deploy("remote-services-dfi-client"
+ add_celix_container("remote-services-dfi-client"
NAME "client"
GROUP "remote-services/remote-services-dfi"
- BUNDLES topology_manager remote_service_admin_dfi shell shell_tui log_service log_writer calculator_shell discovery_etcd
+ BUNDLES Celix::rsa_topology_manager Celix::rsa_dfi Celix::shell Celix::shell_tui Celix::log_service Celix::log_writer_stdout calculator_shell Celix::rsa_discovery_etcd
)
endif ()
endif (RSA_EXAMPLES)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/remote_services/examples/calculator_service/CMakeLists.txt
----------------------------------------------------------------------
diff --cc remote_services/examples/calculator_service/CMakeLists.txt
index 167e705,32cbea2..e3e739a
--- a/remote_services/examples/calculator_service/CMakeLists.txt
+++ b/remote_services/examples/calculator_service/CMakeLists.txt
@@@ -15,15 -15,23 +15,15 @@@
# specific language governing permissions and limitations
# under the License.
- add_bundle(calculator
-include_directories("../../../utils/public/include")
-include_directories("../../utils/public/include")
-include_directories("../../remote_service_admin/public/include")
-include_directories("private/include")
-include_directories("public/include")
-
-add_celix_bundle(calculator SOURCES
- private/src/calculator_impl
- private/src/calculator_activator
-
- private/include/calculator_impl.h
-
++add_celix_bundle(calculator
+ SOURCES
+ src/calculator_impl
+ src/calculator_activator
SYMBOLIC_NAME "apache_celix_remoting_calculator_impl"
VERSION 0.0.1
)
+target_include_directories(calculator PRIVATE src)
+target_link_libraries(calculator PRIVATE Celix::rsa_spi calculator_api)
-celix_bundle_files(calculator public/include/org.apache.celix.calc.api.Calculator2.descriptor
- DESTINATION .)
-
-target_link_libraries(calculator celix_framework)
+get_target_property(DESCR calculator_api INTERFACE_CALCULATOR_DESCRIPTOR)
- bundle_files(calculator ${DESCR} DESTINATION .)
++celix_bundle_files(calculator ${DESCR} DESTINATION .)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/remote_services/examples/calculator_shell/CMakeLists.txt
----------------------------------------------------------------------
diff --cc remote_services/examples/calculator_shell/CMakeLists.txt
index 78c0737,2a49b3b..1eef035
--- a/remote_services/examples/calculator_shell/CMakeLists.txt
+++ b/remote_services/examples/calculator_shell/CMakeLists.txt
@@@ -15,21 -15,28 +15,21 @@@
# specific language governing permissions and limitations
# under the License.
- add_bundle(calculator_shell
-include_directories("private/include")
-include_directories("../../../utils/public/include")
-include_directories("../calculator_service/public/include")
-include_directories("../../../shell/public/include")
-
-add_celix_bundle(calculator_shell SOURCES
- private/src/add_command
- private/src/sub_command
- private/src/sqrt_command
- private/src/calculator_shell_activator
-
- private/include/add_command.h
- private/include/sqrt_command.h
- private/include/sub_command.h
-
++add_celix_bundle(calculator_shell
+ SOURCES
+ src/add_command
+ src/sub_command
+ src/sqrt_command
+ src/calculator_shell_activator
VERSION 0.0.1
SYMBOLIC_NAME "apache_celix_remoting_calculator_shell"
)
+target_include_directories(calculator_shell PRIVATE src)
+target_link_libraries(calculator_shell PRIVATE Celix::shell_api calculator_api)
- bundle_files(calculator_shell
+ celix_bundle_files(calculator_shell
- ../calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
- #private/include/org.apache.celix.calc.api.Calculator2.descriptor ##Use this descriptor in case you want to try out versioning!
+ ../calculator_api/include/org.apache.celix.calc.api.Calculator2.descriptor
+ #src/org.apache.celix.calc.api.Calculator2.descriptor ##Use this descriptor in case you want to try out versioning!
DESTINATION .
)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/remote_services/remote_service_admin_dfi/CMakeLists.txt
----------------------------------------------------------------------
diff --cc remote_services/remote_service_admin_dfi/CMakeLists.txt
index ea79c31,4b28231..349c3ef
--- a/remote_services/remote_service_admin_dfi/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/CMakeLists.txt
@@@ -23,31 -23,21 +23,31 @@@ if (RSA_REMOTE_SERVICE_ADMIN_DFI
find_package(CURL REQUIRED)
find_package(Jansson REQUIRED)
- add_bundle(rsa_dfi
- include_directories(
- ${CURL_INCLUDE_DIRS}
- ${JANSSON_INCLUDE_DIRS}
++ add_celix_bundle(rsa_dfi
+ VERSION 0.9.0
+ SYMBOLIC_NAME "apache_celix_remote_service_admin_dfi"
+ NAME "Apache Celix Remote Service Admin Dynamic Function Interface (DFI)"
+ SOURCES
+ src/remote_service_admin_dfi.c
+ src/remote_service_admin_activator.c
+ src/export_registration_dfi.c
+ src/import_registration_dfi.c
+ src/dfi_utils.c
+ $<TARGET_OBJECTS:Celix::civetweb>
)
+ target_include_directories(rsa_dfi PRIVATE src $<TARGET_PROPERTY:Celix::civetweb,INCLUDE_DIRECTORIES>)
+ target_link_libraries(rsa_dfi PRIVATE
+ Celix::dfi_static
+ Celix::log_helper
+ Celix::rsa_common
+ ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
- install_bundle(rsa_dfi)
- if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
- include_directories(dynamic_function_interface/memstream)
- endif()
-
- add_subdirectory(rsa)
++ install_celix_bundle(rsa_dfi)
if (ENABLE_TESTING)
- find_package(CppUTest REQUIRED)
- include_directories(${CPPUTEST_INCLUDE_DIR})
- add_subdirectory(rsa_tst)
+ add_subdirectory(test)
endif()
+ #Setup target aliases to match external usage
+ add_library(Celix::rsa_dfi ALIAS rsa_dfi)
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/remote_services/remote_service_admin_dfi/test/CMakeLists.txt
----------------------------------------------------------------------
diff --cc remote_services/remote_service_admin_dfi/test/CMakeLists.txt
index 153b3d1,0000000..aa10ec3
mode 100644,000000..100644
--- a/remote_services/remote_service_admin_dfi/test/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/test/CMakeLists.txt
@@@ -1,60 -1,0 +1,60 @@@
+# 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.
+
+find_package(CppUTest REQUIRED)
+include_directories(${CPPUTEST_INCLUDE_DIR})
+
- add_bundle(rsa_dfi_tst_bundle
++add_celix_bundle(rsa_dfi_tst_bundle
+ VERSION 0.0.1
+ SOURCES
+ src/tst_activator.c
+)
+get_target_property(DESCR calculator_api INTERFACE_CALCULATOR_DESCRIPTOR)
- bundle_files(rsa_dfi_tst_bundle ${DESCR} DESTINATION .)
++celix_bundle_files(rsa_dfi_tst_bundle ${DESCR} DESTINATION .)
+target_link_libraries(rsa_dfi_tst_bundle PRIVATE ${CPPUTEST_LIBRARY} calculator_api)
+target_include_directories(rsa_dfi_tst_bundle PRIVATE src)
+
+add_executable(test_rsa_dfi
+ src/run_tests.cpp
+ src/rsa_tests.cpp
+ src/rsa_client_server_tests.cpp
+)
+target_include_directories(test_rsa_dfi PRIVATE src)
+target_link_libraries(test_rsa_dfi PRIVATE ${CURL_LIBRARIES} ${CPPUTEST_LIBRARY}
+ Celix::framework
+ Celix::rsa_common
+ calculator_api)
+
+get_property(rsa_bundle_file TARGET rsa_dfi PROPERTY BUNDLE_FILE)
+get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE_FILE)
+get_property(calculator_shell_bundle_file TARGET calculator_shell PROPERTY BUNDLE_FILE)
+get_property(discovery_configured_bundle_file TARGET rsa_discovery_configured PROPERTY BUNDLE_FILE)
+get_property(topology_manager_bundle_file TARGET Celix::rsa_topology_manager PROPERTY BUNDLE_FILE)
+get_property(tst_bundle_file TARGET rsa_dfi_tst_bundle PROPERTY BUNDLE_FILE)
+
+configure_file(config.properties.in config.properties)
+configure_file(client.properties.in client.properties)
+configure_file(server.properties.in server.properties)
+
+add_dependencies(test_rsa_dfi
+ rsa_dfi_bundle #note depend on the target creating the bundle zip not the lib target
+ calculator_bundle
+)
+
+add_test(NAME run_test_rsa_dfi COMMAND test_rsa_dfi)
+SETUP_TARGET_FOR_COVERAGE(test_rsa_dfi_cov test_rsa_dfi ${CMAKE_BINARY_DIR}/coverage/test_rsa_dfi/test_rsa_dfi)
+
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/remote_services/remote_services_api/CMakeLists.txt
----------------------------------------------------------------------
diff --cc remote_services/remote_services_api/CMakeLists.txt
index 67656d3,0000000..71f3306
mode 100644,000000..100644
--- a/remote_services/remote_services_api/CMakeLists.txt
+++ b/remote_services/remote_services_api/CMakeLists.txt
@@@ -1,28 -1,0 +1,28 @@@
+# 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.
+
- add_library(celix_remote_services_api INTERFACE)
- target_include_directories(celix_remote_services_api INTERFACE
++add_library(remote_services_api INTERFACE)
++target_include_directories(remote_services_api INTERFACE
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
+ $<INSTALL_INTERFACE:include/celix/remote_services>
+)
+
- install(TARGETS celix_remote_services_api EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT rsa)
++install(TARGETS remote_services_api EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT rsa)
+install(DIRECTORY include/ DESTINATION include/celix/remote_services COMPONENT rsa)
+
+#Setup target aliases to match external usage
- add_library(Celix::remote_services_api ALIAS celix_remote_services_api)
++add_library(Celix::remote_services_api ALIAS remote_services_api)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/remote_services/rsa_common/CMakeLists.txt
----------------------------------------------------------------------
diff --cc remote_services/rsa_common/CMakeLists.txt
index 27c2dba,0000000..397fa8c
mode 100644,000000..100644
--- a/remote_services/rsa_common/CMakeLists.txt
+++ b/remote_services/rsa_common/CMakeLists.txt
@@@ -1,29 -1,0 +1,30 @@@
+# 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.
+
- add_library(celix_rsa_common STATIC
++add_library(rsa_common STATIC
+ src/endpoint_description.c
+ src/export_registration_impl.c
+ src/import_registration_impl.c
+)
- target_include_directories(celix_rsa_common PRIVATE src)
- target_link_libraries(celix_rsa_common PUBLIC Celix::framework Celix::rsa_spi Celix::log_helper)
++set_target_properties(rsa_common PROPERTIES OUTPUT_NAME "celix_rsa_common")
++target_include_directories(rsa_common PRIVATE src)
++target_link_libraries(rsa_common PUBLIC Celix::framework Celix::rsa_spi Celix::log_helper)
+
- install(TARGETS celix_rsa_common EXPORT celix COMPONENT rsa DESTINATION ${CMAKE_INSTALL_LIBDIR})
++#install(TARGETS rsa_common EXPORT celix COMPONENT rsa DESTINATION ${CMAKE_INSTALL_LIBDIR})
+
+#Setup target aliases to match external usage
- add_library(Celix::rsa_common ALIAS celix_rsa_common)
++add_library(Celix::rsa_common ALIAS rsa_common)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/remote_services/topology_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --cc remote_services/topology_manager/CMakeLists.txt
index 6050229,69d14ed..763067d
--- a/remote_services/topology_manager/CMakeLists.txt
+++ b/remote_services/topology_manager/CMakeLists.txt
@@@ -16,21 -16,30 +16,21 @@@
# under the License.
celix_subproject(RSA_TOPOLOGY_MANAGER "Option to enable building the Remote Service Admin Service SHM bundle" ON DEPS REMOTE_SERVICE_ADMIN_DFI)
if (RSA_TOPOLOGY_MANAGER)
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/topology_manager/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/topology_manager/public/include")
- add_bundle(rsa_topology_manager
- add_celix_bundle(topology_manager SOURCES
- private/src/topology_manager
- private/src/scope
- private/src/activator
-
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
-
- private/include/topology_manager.h
- public/include/tm_scope.h
++ add_celix_bundle(rsa_topology_manager
+ SOURCES
+ src/topology_manager
+ src/scope
+ src/activator
VERSION 0.9.0
SYMBOLIC_NAME "apache_celix_rs_topology_manager"
- NAME
- "Apache Celix RS Topology Manager"
+ NAME "Apache Celix RS Topology Manager"
)
+ target_include_directories(rsa_topology_manager PRIVATE src)
+ target_include_directories(rsa_topology_manager PUBLIC include)
+ target_link_libraries(rsa_topology_manager PRIVATE Celix::log_helper Celix::rsa_spi)
- install_bundle(rsa_topology_manager)
- install_celix_bundle(topology_manager)
++ install_celix_bundle(rsa_topology_manager)
if (ENABLE_TESTING)
find_package(CppUTest REQUIRED)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
----------------------------------------------------------------------
diff --cc remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
index dc5dea5,6cf53fb..c9a9d62
--- a/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
+++ b/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
@@@ -27,7 -27,7 +27,7 @@@ add_celix_bundle(topology_manager_test_
SOURCES
tst_activator.c
)
- bundle_files(topology_manager_test_bundle
-celix_bundle_files(topology_manager_test_bundle
++celix_celix_bundle_files(topology_manager_test_bundle
org.apache.celix.test.MyBundle.descriptor
DESTINATION .
)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt
----------------------------------------------------------------------
diff --cc remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt
index 3e93174,cb88a21..6b8ae43
--- a/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt
+++ b/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt
@@@ -15,7 -15,15 +15,7 @@@
# specific language governing permissions and limitations
# under the License.
- add_bundle(topology_manager_disc_mock_bundle
-include_directories(
- ${CPPUTEST_INCLUDE_DIR}
- ${PROJECT_SOURCE_DIR}/framework/public/include
- ${PROJECT_SOURCE_DIR}/utils/public/include
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/include
-)
-
-
+ add_celix_bundle(topology_manager_disc_mock_bundle
VERSION 0.0.1
SOURCES
disc_mock_activator.c
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/remote_shell/CMakeLists.txt
----------------------------------------------------------------------
diff --cc remote_shell/CMakeLists.txt
index a7f5d36,aac0366..cd9ed98
--- a/remote_shell/CMakeLists.txt
+++ b/remote_shell/CMakeLists.txt
@@@ -22,23 -22,25 +22,23 @@@ if (REMOTE_SHELL
VERSION "0.0.2"
NAME: "Apache Celix Remote Shell"
SOURCES
- private/src/activator
- private/src/connection_listener
- private/src/shell_mediator
- private/src/remote_shell
-
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
-
- private/include/remote_shell.h
- private/include/connection_listener.h
+ src/activator
+ src/connection_listener
+ src/shell_mediator
+ src/remote_shell
)
-
+
+ target_include_directories(remote_shell PRIVATE src)
+ target_link_libraries(remote_shell PRIVATE log_helper)
- install_bundle(remote_shell)
+ install_celix_bundle(remote_shell)
-
- include_directories("private/include")
+
include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/shell/public/include")
include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
- target_link_libraries(remote_shell celix_framework)
+ target_link_libraries(remote_shell PRIVATE Celix::shell_api)
+
+ #Alias setup to match external usage
+ add_library(Celix::remote_shell ALIAS remote_shell)
- add_deploy("remote_shell_deploy" NAME "remote_shell" BUNDLES Celix::shell Celix::remote_shell Celix::shell_tui log_service)
- add_celix_container("remote_shell_deploy" NAME "remote_shell" BUNDLES shell remote_shell shell_tui log_service)
++ add_celix_container("remote_shell_deploy" NAME "remote_shell" BUNDLES Celix::shell Celix::remote_shell Celix::shell_tui log_service)
endif (REMOTE_SHELL)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/shell/CMakeLists.txt
----------------------------------------------------------------------
diff --cc shell/CMakeLists.txt
index b8aaac3,a2bf88e..93c066f
--- a/shell/CMakeLists.txt
+++ b/shell/CMakeLists.txt
@@@ -18,35 -18,38 +18,35 @@@ celix_subproject(SHELL "Option to enabl
if (SHELL)
find_package(CURL REQUIRED)
+ add_library(shell_api INTERFACE)
+ target_include_directories(shell_api INTERFACE include)
+
- add_bundle(shell
+ add_celix_bundle(shell
SYMBOLIC_NAME "apache_celix_shell"
VERSION "2.1.0"
NAME "Apache Celix Shell"
-
SOURCES
+ src/activator
+ src/shell
+ src/lb_command
+ src/start_command
+ src/stop_command
+ src/install_command
+ src/update_command
+ src/uninstall_command
+ src/log_command
+ src/inspect_command
+ src/help_command
+ )
+ target_include_directories(shell PRIVATE src ${CURL_INCLUDE_DIRS})
+ target_link_libraries(shell PRIVATE Celix::shell_api ${CURL_LIBRARIES} Celix::log_service_api Celix::log_helper)
- install_bundle(shell
- private/src/activator
- private/src/shell
- private/src/lb_command
- private/src/start_command
- private/src/stop_command
- private/src/install_command
- private/src/update_command
- private/src/uninstall_command
- private/src/log_command
- private/src/inspect_command
- private/src/help_command
-
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
-
- )
-
- install_celix_bundle(shell
++ install_celix_bundle(shell
HEADERS
- public/include/shell.h public/include/command.h public/include/shell_constants.h
- )
+ include/shell.h include/command.h include/shell_constants.h
+ )
- include_directories("public/include")
- include_directories("private/include")
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
- include_directories(${CURL_INCLUDE_DIRS})
- target_link_libraries(shell celix_framework ${CURL_LIBRARIES})
+ #Setup target aliases to match external usage
+ add_library(Celix::shell_api ALIAS shell_api)
+ add_library(Celix::shell ALIAS shell)
endif (SHELL)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/shell/README.md
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/shell_bonjour/CMakeLists.txt
----------------------------------------------------------------------
diff --cc shell_bonjour/CMakeLists.txt
index 2276f09,e12d250..034a4f3
--- a/shell_bonjour/CMakeLists.txt
+++ b/shell_bonjour/CMakeLists.txt
@@@ -26,24 -26,28 +26,24 @@@ if (SHELL_BONJOUR
set(BUNDLE_VERSION "0.1.0")
set(BUNDLE_NAME "bonjour_shell")
- add_bundle(bonjour_shell
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/shell/public/include")
- include_directories("${LIBXML2_INCLUDE_DIR}")
- include_directories("private/include")
-
- set(MEMSTREAM_SOURCES )
- if (APPLE OR ANDROID)
- set(MEMSTREAM_SOURCES ${PROJECT_SOURCE_DIR}/utils/private/src/memstream/open_memstream.c ${PROJECT_SOURCE_DIR}/utils/private/src/memstream/fmemopen.c)
- include_directories(${PROJECT_SOURCE_DIR}/utils/public/include/memstream)
- endif()
+ add_celix_bundle(bonjour_shell
- VERSION "1.0.0"
+ VERSION "1.0.0"
SOURCES
private/src/activator.c
private/src/bonjour_shell.c
- ${MEMSTREAM_SOURCES}
)
-
- target_link_libraries(bonjour_shell celix_framework celix_utils ${LIBXML2_LIBRARIES} ${DNS_SD_LIB})
+ add_library(Celix::bonjour_shell ALIAS bonjour_shell)
+
+
+ target_include_directories(bonjour_shell PRIVATE
+ "${PROJECT_SOURCE_DIR}/utils/public/include"
+ "${LIBXML2_INCLUDE_DIR}"
+ private/include
+ )
+ target_link_libraries(bonjour_shell PRIVATE ${LIBXML2_LIBRARIES} ${DNS_SD_LIB} Celix::shell_api)
- add_deploy("bonjour_shell_deploy" BUNDLES
+ add_celix_container("bonjour_shell_deploy" BUNDLES
- shell
+ Celix::shell
bonjour_shell
PROPERTIES "bonjour.shell.id=Apache Celix"
)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/shell_tui/CMakeLists.txt
----------------------------------------------------------------------
diff --cc shell_tui/CMakeLists.txt
index bd6b316,35153fe..acfe439
--- a/shell_tui/CMakeLists.txt
+++ b/shell_tui/CMakeLists.txt
@@@ -27,14 -27,10 +27,14 @@@ if (SHELL_TUI
private/src/history
)
+ target_include_directories(shell_tui PRIVATE
+ "${PROJECT_SOURCE_DIR}/utils/public/include"
+ private/include
+ )
+ target_link_libraries(shell_tui PRIVATE Celix::shell_api)
+
- install_bundle(shell_tui)
+ install_celix_bundle(shell_tui)
-
- include_directories("private/include")
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/shell/public/include")
- target_link_libraries(shell_tui celix_framework)
+
+ #Alias setup to match external usage
+ add_library(Celix::shell_tui ALIAS shell_tui)
endif (SHELL_TUI)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ea8de64/shell_tui/README.md
----------------------------------------------------------------------
[34/54] [abbrv] celix git commit: CELIX-417: Refactors cmake usage of
pubsub and rsa. Started with installing exported targets
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_spi/include/remote_endpoint.h
----------------------------------------------------------------------
diff --git a/remote_services/rsa_spi/include/remote_endpoint.h b/remote_services/rsa_spi/include/remote_endpoint.h
new file mode 100644
index 0000000..ab80abb
--- /dev/null
+++ b/remote_services/rsa_spi/include/remote_endpoint.h
@@ -0,0 +1,44 @@
+/**
+ *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.
+ */
+/*
+ * remote_endpoint.h
+ *
+ * \date Oct 7, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef REMOTE_ENDPOINT_H_
+#define REMOTE_ENDPOINT_H_
+
+#define OSGI_RSA_REMOTE_ENDPOINT "remote_endpoint"
+
+typedef struct remote_endpoint remote_endpoint_t;
+typedef remote_endpoint_t* remote_endpoint_pt;
+
+struct remote_endpoint_service {
+ remote_endpoint_pt endpoint;
+ celix_status_t (*setService)(remote_endpoint_pt endpoint, void *service);
+ celix_status_t (*handleRequest)(remote_endpoint_pt endpoint, char *data, char **reply);
+};
+
+typedef struct remote_endpoint_service *remote_endpoint_service_pt;
+
+
+#endif /* REMOTE_ENDPOINT_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_spi/include/remote_endpoint_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/rsa_spi/include/remote_endpoint_impl.h b/remote_services/rsa_spi/include/remote_endpoint_impl.h
new file mode 100644
index 0000000..3782d62
--- /dev/null
+++ b/remote_services/rsa_spi/include/remote_endpoint_impl.h
@@ -0,0 +1,38 @@
+/**
+ *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.
+ */
+/*
+ * remote_endpoint_impl.h
+ *
+ * \date Oct 11, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef REMOTE_ENDPOINT_IMPL_H_
+#define REMOTE_ENDPOINT_IMPL_H_
+
+#include "remote_endpoint.h"
+#include "celix_threads.h"
+
+struct remote_endpoint {
+ celix_thread_mutex_t serviceLock;
+ void *service;
+};
+
+#endif /* REMOTE_ENDPOINT_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_spi/include/remote_proxy.h
----------------------------------------------------------------------
diff --git a/remote_services/rsa_spi/include/remote_proxy.h b/remote_services/rsa_spi/include/remote_proxy.h
new file mode 100644
index 0000000..4c3f5c3
--- /dev/null
+++ b/remote_services/rsa_spi/include/remote_proxy.h
@@ -0,0 +1,76 @@
+/**
+ *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.
+ */
+/*
+ * remote_proxy.h
+ *
+ * \date Oct 13, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef REMOTE_PROXY_H_
+#define REMOTE_PROXY_H_
+
+#include "endpoint_listener.h"
+#include "remote_service_admin.h"
+
+#define OSGI_RSA_REMOTE_PROXY_FACTORY "remote_proxy_factory"
+#define OSGI_RSA_REMOTE_PROXY_TIMEOUT "remote_proxy_timeout"
+
+typedef celix_status_t (*sendToHandle)(remote_service_admin_pt remote_service_admin_ptr, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
+typedef celix_status_t (*createProxyService)(void *handle, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback, properties_pt properties, void **service);
+typedef celix_status_t (*destroyProxyService)(void *handle, void *service);
+
+typedef struct remote_proxy_factory *remote_proxy_factory_pt;
+typedef struct remote_proxy_factory_service *remote_proxy_factory_service_pt;
+
+struct remote_proxy_factory {
+ bundle_context_pt context_ptr;
+ char *service;
+
+ remote_proxy_factory_service_pt remote_proxy_factory_service_ptr;
+ properties_pt properties;
+ service_registration_pt registration;
+
+ hash_map_pt proxy_instances;
+
+ void *handle;
+
+ createProxyService create_proxy_service_ptr;
+ destroyProxyService destroy_proxy_service_ptr;
+};
+
+struct remote_proxy_factory_service {
+ remote_proxy_factory_pt factory;
+ celix_status_t (*registerProxyService)(remote_proxy_factory_pt proxyFactoryService, endpoint_description_pt endpoint, remote_service_admin_pt remote_service_admin_ptr, sendToHandle callback);
+ celix_status_t (*unregisterProxyService)(remote_proxy_factory_pt proxyFactoryService, endpoint_description_pt endpoint);
+};
+
+celix_status_t remoteProxyFactory_create(bundle_context_pt context, char *service, void *handle,
+ createProxyService create, destroyProxyService destroy,
+ remote_proxy_factory_pt *remote_proxy_factory_ptr);
+celix_status_t remoteProxyFactory_destroy(remote_proxy_factory_pt *remote_proxy_factory_ptr);
+
+celix_status_t remoteProxyFactory_register(remote_proxy_factory_pt remote_proxy_factory_ptr);
+celix_status_t remoteProxyFactory_unregister(remote_proxy_factory_pt remote_proxy_factory_ptr);
+
+
+
+
+#endif /* REMOTE_PROXY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/rsa_spi/include/remote_service_admin.h
----------------------------------------------------------------------
diff --git a/remote_services/rsa_spi/include/remote_service_admin.h b/remote_services/rsa_spi/include/remote_service_admin.h
new file mode 100644
index 0000000..cc7fd98
--- /dev/null
+++ b/remote_services/rsa_spi/include/remote_service_admin.h
@@ -0,0 +1,73 @@
+/**
+ *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.
+ */
+/*
+ * remote_service_admin.h
+ *
+ * \date Sep 30, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef REMOTE_SERVICE_ADMIN_H_
+#define REMOTE_SERVICE_ADMIN_H_
+
+#include "endpoint_listener.h"
+#include "service_reference.h"
+#include "export_registration.h"
+#include "import_registration.h"
+
+#define OSGI_RSA_REMOTE_SERVICE_ADMIN "remote_service_admin"
+
+typedef struct import_registration_factory import_registration_factory_t;
+typedef import_registration_factory_t* import_registration_factory_pt;
+
+typedef struct remote_service_admin remote_service_admin_t;
+typedef remote_service_admin_t* remote_service_admin_pt;
+
+struct remote_service_admin_service {
+ remote_service_admin_pt admin;
+ celix_status_t (*exportService)(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
+ celix_status_t (*removeExportedService)(remote_service_admin_pt admin, export_registration_pt registration);
+ celix_status_t (*getExportedServices)(remote_service_admin_pt admin, array_list_pt *services);
+ celix_status_t (*getImportedEndpoints)(remote_service_admin_pt admin, array_list_pt *services);
+ celix_status_t (*importService)(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
+
+ celix_status_t (*exportReference_getExportedEndpoint)(export_reference_pt reference, endpoint_description_pt *endpoint);
+ celix_status_t (*exportReference_getExportedService)(export_reference_pt reference, service_reference_pt *service);
+
+ celix_status_t (*exportRegistration_close)(remote_service_admin_pt admin, export_registration_pt registration);
+ celix_status_t (*exportRegistration_getException)(export_registration_pt registration);
+ celix_status_t (*exportRegistration_getExportReference)(export_registration_pt registration, export_reference_pt *reference);
+ celix_status_t (*exportRegistration_freeExportReference)(export_reference_pt *reference);
+ celix_status_t (*exportRegistration_getEndpointDescription)(export_registration_pt registration, endpoint_description_pt endpointDescription);
+
+ celix_status_t (*importReference_getImportedEndpoint)(import_reference_pt reference);
+ celix_status_t (*importReference_getImportedService)(import_reference_pt reference);
+
+ celix_status_t (*importRegistration_close)(remote_service_admin_pt admin, import_registration_pt registration);
+ celix_status_t (*importRegistration_getException)(import_registration_pt registration);
+ celix_status_t (*importRegistration_getImportReference)(import_registration_pt registration, import_reference_pt *reference);
+
+};
+
+typedef struct remote_service_admin_service remote_service_admin_service_t;
+typedef remote_service_admin_service_t* remote_service_admin_service_pt;
+
+
+#endif /* REMOTE_SERVICE_ADMIN_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/topology_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/CMakeLists.txt b/remote_services/topology_manager/CMakeLists.txt
index 568054e..6050229 100644
--- a/remote_services/topology_manager/CMakeLists.txt
+++ b/remote_services/topology_manager/CMakeLists.txt
@@ -28,7 +28,7 @@ if (RSA_TOPOLOGY_MANAGER)
)
target_include_directories(rsa_topology_manager PRIVATE src)
target_include_directories(rsa_topology_manager PUBLIC include)
- target_link_libraries(rsa_topology_manager PRIVATE Celix::log_helper Celix::rsa_api)
+ target_link_libraries(rsa_topology_manager PRIVATE Celix::log_helper Celix::rsa_spi)
install_bundle(rsa_topology_manager)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt b/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
index eaf0a26..dc5dea5 100644
--- a/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
+++ b/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
@@ -32,4 +32,4 @@ bundle_files(topology_manager_test_bundle
DESTINATION .
)
-target_link_libraries(topology_manager_test_bundle PRIVATE ${CPPUTEST_LIBRARY} Celix::rsa_api calculator_api)
+target_link_libraries(topology_manager_test_bundle PRIVATE ${CPPUTEST_LIBRARY} Celix::rsa_spi calculator_api)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/utils/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
index e0c187f..1826902 100644
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@ -19,7 +19,8 @@ set(MEMSTREAM_SOURCES )
set(MEMSTREAM_INCLUDES )
if (APPLE OR ANDROID)
set(MEMSTREAM_SOURCES src/memstream/open_memstream.c src/memstream/fmemopen.c)
- set(MEMSTREAM_INCLUDE_DIR include/memstream)
+ set(MEMSTREAM_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include/memstream)
+ install(DIRECTORY include/memstream/ DESTINATION include/celix/memstream COMPONENT framework)
endif()
add_library(utils SHARED
@@ -41,7 +42,11 @@ if (ANDROID)
target_compile_definitions(utils PRIVATE -DUSE_FILE32API)
endif ()
-target_include_directories(utils PUBLIC include ${MEMSTREAM_INCLUDE_DIR})
+target_include_directories(utils PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
+ $<BUILD_INTERFACE:${MEMSTREAM_INCLUDE_DIR}>
+ $<INSTALL_INTERFACE:include/celix>
+)
target_include_directories(utils PRIVATE src)
set_target_properties(utils PROPERTIES "SOVERSION" 2)
@@ -51,7 +56,9 @@ ELSEIF(ANDROID)
target_link_libraries(utils PRIVATE m)
ENDIF()
-install(TARGETS utils DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT framework)
+install(TARGETS utils EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT framework)
+install(DIRECTORY include/ DESTINATION include/celix COMPONENT framework
+ PATTERN memstream* EXCLUDE)
#Alias setup to match external usage
add_library(Celix::utils ALIAS utils)
[11/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/src/desc.xml
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/src/desc.xml b/remote_services/discovery_common/src/desc.xml
new file mode 100644
index 0000000..5998992
--- /dev/null
+++ b/remote_services/discovery_common/src/desc.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ *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.
+ -->
+<endpoint-descriptions xmlns="http://www.osgi.org/xmlns/rsa/v1.0.0">
+ <endpoint-description>
+ <property name="service.intents">
+ <list>
+ <value>SOAP</value>
+ <value>HTTP</value>
+ </list>
+ </property>
+ <property name="endpoint.id" value="http://ws.acme.com:9000/hello" />
+ <property name="objectClass" value="com.acme.Foo" />
+ <property name="endpoint.package.version.com.acme" value="4.2" />
+ <property name="service.imported.configs" value="com.acme" />
+ <property name="com.acme.ws.xml">
+ <xml>
+ <config xmlns="http://acme.com/defs">
+ <port>1029</port>
+ <host>www.acme.com</host>
+ </config>
+ </xml>
+ </property>
+ </endpoint-description>
+</endpoint-descriptions>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/src/discovery.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/src/discovery.c b/remote_services/discovery_common/src/discovery.c
new file mode 100644
index 0000000..d124c15
--- /dev/null
+++ b/remote_services/discovery_common/src/discovery.c
@@ -0,0 +1,234 @@
+/**
+ * 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.
+ */
+/*
+ * discovery.c
+ *
+ * \date Aug 8, 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdbool.h>
+#include <netdb.h>
+#include <string.h>
+
+#include "celix_threads.h"
+#include "bundle_context.h"
+#include "log_helper.h"
+#include "discovery.h"
+#include "endpoint_discovery_server.h"
+#include "discovery_impl.h" //TODO rename impl
+
+
+celix_status_t discovery_endpointAdded(void *handle, endpoint_description_pt endpoint, char *matchedFilter) {
+ celix_status_t status;
+ discovery_pt discovery = handle;
+
+ logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "Endpoint for %s, with filter \"%s\" added...", endpoint->service, matchedFilter);
+
+ status = endpointDiscoveryServer_addEndpoint(discovery->server, endpoint);
+
+ return status;
+}
+
+celix_status_t discovery_endpointRemoved(void *handle, endpoint_description_pt endpoint, char *matchedFilter) {
+ celix_status_t status;
+ discovery_pt discovery = handle;
+
+ logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "Endpoint for %s, with filter \"%s\" removed...", endpoint->service, matchedFilter);
+
+ status = endpointDiscoveryServer_removeEndpoint(discovery->server, endpoint);
+
+ return status;
+}
+
+celix_status_t discovery_endpointListenerAdding(void* handle, service_reference_pt reference, void** service) {
+ celix_status_t status = CELIX_SUCCESS;
+ discovery_pt discovery = handle;
+
+ bundleContext_getService(discovery->context, reference, service);
+
+ return status;
+}
+
+celix_status_t discovery_endpointListenerAdded(void* handle, service_reference_pt reference, void* service) {
+ celix_status_t status = CELIX_SUCCESS;
+ discovery_pt discovery = handle;
+
+ const char *discoveryListener = NULL;
+ serviceReference_getProperty(reference, "DISCOVERY", &discoveryListener);
+ const char *scope = NULL;
+ serviceReference_getProperty(reference, OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
+
+ filter_pt filter = filter_create(scope);
+
+ if (discoveryListener != NULL && strcmp(discoveryListener, "true") == 0) {
+ logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "EndpointListener Ignored - Discovery listener");
+ } else {
+ celixThreadMutex_lock(&discovery->discoveredServicesMutex);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(discovery->discoveredServices);
+ while (hashMapIterator_hasNext(iter)) {
+ endpoint_description_pt endpoint = hashMapIterator_nextValue(iter);
+
+ bool matchResult = false;
+ filter_match(filter, endpoint->properties, &matchResult);
+ if (matchResult) {
+ endpoint_listener_pt listener = service;
+
+ logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "EndpointListener Added - Add Scope");
+
+ listener->endpointAdded(listener->handle, endpoint, NULL);
+ }
+ }
+ hashMapIterator_destroy(iter);
+
+ celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
+
+ celixThreadMutex_lock(&discovery->listenerReferencesMutex);
+
+ hashMap_put(discovery->listenerReferences, reference, NULL);
+
+ celixThreadMutex_unlock(&discovery->listenerReferencesMutex);
+ }
+
+ filter_destroy(filter);
+
+ return status;
+}
+
+celix_status_t discovery_endpointListenerModified(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status;
+
+ status = discovery_endpointListenerRemoved(handle, reference, service);
+ if (status == CELIX_SUCCESS) {
+ status = discovery_endpointListenerAdded(handle, reference, service);
+ }
+
+ return status;
+}
+
+celix_status_t discovery_endpointListenerRemoved(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status;
+ discovery_pt discovery = handle;
+
+ status = celixThreadMutex_lock(&discovery->listenerReferencesMutex);
+
+ if (status == CELIX_SUCCESS) {
+ if (discovery->listenerReferences != NULL) {
+ if (hashMap_remove(discovery->listenerReferences, reference)) {
+ logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "EndpointListener Removed");
+ }
+ }
+
+ status = celixThreadMutex_unlock(&discovery->listenerReferencesMutex);
+ }
+
+ return status;
+}
+
+celix_status_t discovery_informEndpointListeners(discovery_pt discovery, endpoint_description_pt endpoint, bool endpointAdded) {
+ celix_status_t status;
+
+ // Inform listeners of new endpoint
+ status = celixThreadMutex_lock(&discovery->listenerReferencesMutex);
+
+ if (status == CELIX_SUCCESS) {
+ if (discovery->listenerReferences != NULL) {
+ hash_map_iterator_pt iter = hashMapIterator_create(discovery->listenerReferences);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+
+ service_reference_pt reference = hashMapEntry_getKey(entry);
+ endpoint_listener_pt listener = NULL;
+
+ const char* scope = NULL;
+ serviceReference_getProperty(reference, OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
+
+ filter_pt filter = filter_create(scope);
+ bool matchResult = false;
+
+ status = filter_match(filter, endpoint->properties, &matchResult);
+ if (status == CELIX_SUCCESS) {
+ if (matchResult) {
+ bundleContext_getService(discovery->context, reference, (void **) &listener);
+ if (endpointAdded) {
+ logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "Adding service (%s)", endpoint->service);
+
+ listener->endpointAdded(listener->handle, endpoint, (char*)scope);
+ } else {
+ logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "Removing service (%s)", endpoint->service);
+
+ listener->endpointRemoved(listener->handle, endpoint, (char*)scope);
+ }
+ }
+
+ filter_destroy(filter);
+ }
+ }
+ hashMapIterator_destroy(iter);
+ }
+
+ status = celixThreadMutex_unlock(&discovery->listenerReferencesMutex);
+ }
+
+ return status;
+}
+
+celix_status_t discovery_addDiscoveredEndpoint(discovery_pt discovery, endpoint_description_pt endpoint) {
+ celix_status_t status;
+
+ status = celixThreadMutex_lock(&discovery->discoveredServicesMutex);
+
+ if (status == CELIX_SUCCESS) {
+ char *endpointId = endpoint->id;
+ bool exists = hashMap_get(discovery->discoveredServices, endpointId) != NULL;
+ if (!exists) {
+ hashMap_put(discovery->discoveredServices, endpointId, endpoint);
+ }
+
+ status = celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
+
+ if (!exists) {
+ // notify our listeners that a new endpoint is available...
+ discovery_informEndpointListeners(discovery, endpoint, true /* addingService */);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t discovery_removeDiscoveredEndpoint(discovery_pt discovery, endpoint_description_pt endpoint) {
+ celix_status_t status;
+
+ status = celixThreadMutex_lock(&discovery->discoveredServicesMutex);
+
+ if (status == CELIX_SUCCESS) {
+ char *endpointId = endpoint->id;
+ void *oldValue = hashMap_remove(discovery->discoveredServices, endpointId);
+
+ status = celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
+
+ if (oldValue) {
+ status = discovery_informEndpointListeners(discovery, endpoint, false /* removeService */);
+ }
+ }
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/src/discovery_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/src/discovery_activator.c b/remote_services/discovery_common/src/discovery_activator.c
new file mode 100644
index 0000000..3267d25
--- /dev/null
+++ b/remote_services/discovery_common/src/discovery_activator.c
@@ -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.
+ */
+/*
+ * discovery_activator.c
+ *
+ * \date Aug 8, 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+#include "bundle_activator.h"
+#include "service_tracker.h"
+#include "constants.h"
+
+#include "log_helper.h"
+#include "discovery.h"
+#include "remote_constants.h"
+
+struct activator {
+ bundle_context_pt context;
+ discovery_pt discovery;
+ log_helper_pt loghelper;
+
+ service_tracker_pt endpointListenerTracker;
+ endpoint_listener_pt endpointListener;
+ service_registration_pt endpointListenerService;
+};
+
+celix_status_t bundleActivator_createEPLTracker(struct activator *activator, service_tracker_pt *tracker) {
+ celix_status_t status;
+
+ service_tracker_customizer_pt customizer = NULL;
+
+ status = serviceTrackerCustomizer_create(activator->discovery, discovery_endpointListenerAdding, discovery_endpointListenerAdded, discovery_endpointListenerModified,
+ discovery_endpointListenerRemoved, &customizer);
+
+ if (status == CELIX_SUCCESS) {
+ status = serviceTracker_create(activator->context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, customizer, tracker);
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+ celix_status_t status;
+
+ struct activator* activator = calloc(1,sizeof(struct activator));
+ if (!activator) {
+ return CELIX_ENOMEM;
+ }
+
+ status = discovery_create(context, &activator->discovery);
+ if (status == CELIX_SUCCESS) {
+ activator->context = context;
+
+ logHelper_create(context, &activator->loghelper);
+
+ status = bundleActivator_createEPLTracker(activator, &activator->endpointListenerTracker);
+ if(status==CELIX_SUCCESS){
+ *userData = activator;
+ }
+ else{
+ bundleActivator_destroy(activator,context);
+ }
+ }
+ else{
+ free(activator);
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+ celix_status_t status;
+ struct activator *activator = userData;
+ const char *uuid = NULL;
+
+ logHelper_start(activator->loghelper);
+
+ status = bundleContext_getProperty(context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
+ if (!uuid) {
+ logHelper_log(activator->loghelper, OSGI_LOGSERVICE_DEBUG, "no framework UUID defined?!");
+ return CELIX_ILLEGAL_STATE;
+ }
+
+ size_t len = 11 + strlen(OSGI_FRAMEWORK_OBJECTCLASS) + strlen(OSGI_RSA_ENDPOINT_FRAMEWORK_UUID) + strlen(uuid);
+ char *scope = malloc(len + 1);
+ if (!scope) {
+ return CELIX_ENOMEM;
+ }
+
+ sprintf(scope, "(&(%s=*)(%s=%s))", OSGI_FRAMEWORK_OBJECTCLASS, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
+ scope[len] = 0;
+
+ logHelper_log(activator->loghelper, OSGI_LOGSERVICE_DEBUG, "using scope %s.", scope);
+
+ properties_pt props = properties_create();
+ properties_set(props, "DISCOVERY", "true");
+ properties_set(props, (char *) OSGI_ENDPOINT_LISTENER_SCOPE, scope);
+
+ if (status == CELIX_SUCCESS) {
+ status = serviceTracker_open(activator->endpointListenerTracker);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = discovery_start(activator->discovery);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ endpoint_listener_pt endpointListener = calloc(1, sizeof(struct endpoint_listener));
+
+ if (endpointListener) {
+ endpointListener->handle = activator->discovery;
+ endpointListener->endpointAdded = discovery_endpointAdded;
+ endpointListener->endpointRemoved = discovery_endpointRemoved;
+
+ status = bundleContext_registerService(context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, endpointListener, props, &activator->endpointListenerService);
+
+ if (status == CELIX_SUCCESS) {
+ activator->endpointListener = endpointListener;
+ }
+ }
+ }
+ // We can release the scope, as properties_set makes a copy of the key & value...
+ free(scope);
+
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+ celix_status_t status;
+ struct activator *activator = userData;
+
+ status = discovery_stop(activator->discovery);
+
+ status = serviceTracker_close(activator->endpointListenerTracker);
+
+ status = serviceRegistration_unregister(activator->endpointListenerService);
+ free(activator->endpointListener);
+
+ logHelper_stop(activator->loghelper);
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+ celix_status_t status;
+ struct activator *activator = userData;
+
+ status = serviceTracker_destroy(activator->endpointListenerTracker);
+
+ status = discovery_destroy(activator->discovery);
+
+ logHelper_destroy(&activator->loghelper);
+
+ activator->loghelper = NULL;
+ activator->endpointListenerTracker = NULL;
+ activator->endpointListenerService = NULL;
+ activator->discovery = NULL;
+ activator->context = NULL;
+
+ free(activator);
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/src/endpoint_descriptor_reader.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/src/endpoint_descriptor_reader.c b/remote_services/discovery_common/src/endpoint_descriptor_reader.c
new file mode 100644
index 0000000..ea176bf
--- /dev/null
+++ b/remote_services/discovery_common/src/endpoint_descriptor_reader.c
@@ -0,0 +1,387 @@
+/**
+ *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.
+ */
+/*
+ * endpoint_descriptor_reader.c
+ *
+ * \date 24 Jul 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdbool.h>
+#include <string.h>
+#include <libxml/xmlreader.h>
+
+#include "log_helper.h"
+#include "remote_constants.h"
+
+#include "endpoint_description.h"
+#include "endpoint_descriptor_common.h"
+#include "endpoint_descriptor_reader.h"
+
+struct endpoint_descriptor_reader {
+ xmlTextReaderPtr reader;
+ log_helper_pt* loghelper;
+};
+
+static valueType valueTypeFromString(char *name);
+
+celix_status_t endpointDescriptorReader_create(endpoint_discovery_poller_pt poller, endpoint_descriptor_reader_pt *reader) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *reader = malloc(sizeof(**reader));
+ if (!*reader) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*reader)->reader = NULL;
+ (*reader)->loghelper = poller->loghelper;
+ }
+
+ return status;
+}
+
+celix_status_t endpointDescriptorReader_destroy(endpoint_descriptor_reader_pt reader) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ reader->loghelper = NULL;
+
+ free(reader);
+
+ return status;
+}
+
+void endpointDescriptorReader_addSingleValuedProperty(properties_pt properties, const xmlChar* name, const xmlChar* value) {
+ properties_set(properties, (char *) name, (char*) value);
+}
+
+void endpointDescriptorReader_addMultiValuedProperty(properties_pt properties, const xmlChar* name, array_list_pt values) {
+ char *value = calloc(256, sizeof(*value));
+ if (value) {
+ unsigned int size = arrayList_size(values);
+ unsigned int i;
+ for (i = 0; i < size; i++) {
+ char* item = (char*) arrayList_get(values, i);
+ if (i > 0) {
+ value = strcat(value, ",");
+ }
+ value = strcat(value, item);
+ }
+
+ properties_set(properties, (char *) name, value);
+
+ free(value);
+ }
+}
+
+celix_status_t endpointDescriptorReader_parseDocument(endpoint_descriptor_reader_pt reader, char *document, array_list_pt *endpoints) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ reader->reader = xmlReaderForMemory(document, (int) strlen(document), NULL, "UTF-8", 0);
+ if (reader->reader == NULL) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ bool inProperty = false;
+ bool inXml = false;
+ bool inArray = false;
+ bool inList = false;
+ bool inSet = false;
+ bool inValue = false;
+
+ const xmlChar *propertyName = NULL;
+ const xmlChar *propertyValue = NULL;
+ valueType propertyType = VALUE_TYPE_STRING;
+ xmlChar *valueBuffer = xmlMalloc(256);
+ valueBuffer[0] = '\0';
+
+ array_list_pt propertyValues = NULL;
+ arrayList_create(&propertyValues);
+
+ array_list_pt endpointDescriptions = NULL;
+ if (*endpoints) {
+ // use the given arraylist...
+ endpointDescriptions = *endpoints;
+ } else {
+ arrayList_create(&endpointDescriptions);
+ // return the read endpoints...
+ *endpoints = endpointDescriptions;
+ }
+
+ properties_pt endpointProperties = NULL;
+
+ int read = xmlTextReaderRead(reader->reader);
+ while (read == XML_TEXTREADER_MODE_INTERACTIVE) {
+ int type = xmlTextReaderNodeType(reader->reader);
+
+ if (type == XML_READER_TYPE_ELEMENT) {
+ const xmlChar *localname = xmlTextReaderConstLocalName(reader->reader);
+
+ if (inXml) {
+ valueBuffer = xmlStrcat(valueBuffer, BAD_CAST "<");
+ valueBuffer = xmlStrcat(valueBuffer, localname);
+
+ int i = xmlTextReaderMoveToFirstAttribute(reader->reader);
+ while (i == 1) {
+ const xmlChar *name = xmlTextReaderConstName(reader->reader);
+ const xmlChar *value = xmlTextReaderConstValue(reader->reader);
+
+ valueBuffer = xmlStrcat(valueBuffer, BAD_CAST " ");
+ valueBuffer = xmlStrcat(valueBuffer, name);
+ valueBuffer = xmlStrcat(valueBuffer, BAD_CAST "=\"");
+ valueBuffer = xmlStrcat(valueBuffer, BAD_CAST value);
+ valueBuffer = xmlStrcat(valueBuffer, BAD_CAST "\"");
+
+ i = xmlTextReaderMoveToNextAttribute(reader->reader);
+ }
+
+ valueBuffer = xmlStrcat(valueBuffer, BAD_CAST ">");
+ } else if (xmlStrcmp(localname, ENDPOINT_DESCRIPTION) == 0) {
+
+ if (endpointProperties != NULL)
+ properties_destroy(endpointProperties);
+
+ endpointProperties = properties_create();
+ } else if (xmlStrcmp(localname, PROPERTY) == 0) {
+ inProperty = true;
+
+ propertyName = xmlTextReaderGetAttribute(reader->reader, NAME);
+ propertyValue = xmlTextReaderGetAttribute(reader->reader, VALUE);
+ xmlChar *vtype = xmlTextReaderGetAttribute(reader->reader, VALUE_TYPE);
+ propertyType = valueTypeFromString((char*) vtype);
+ arrayList_clear(propertyValues);
+
+ if (xmlTextReaderIsEmptyElement(reader->reader)) {
+ inProperty = false;
+
+ if (propertyValue != NULL) {
+ endpointDescriptorReader_addSingleValuedProperty(endpointProperties, propertyName, propertyValue);
+ }
+
+ xmlFree((void *) propertyName);
+ xmlFree((void *) propertyValue);
+ xmlFree((void *) vtype);
+ }
+ } else {
+ valueBuffer[0] = 0;
+ inArray |= inProperty && xmlStrcmp(localname, ARRAY) == 0;
+ inList |= inProperty && xmlStrcmp(localname, LIST) == 0;
+ inSet |= inProperty && xmlStrcmp(localname, SET) == 0;
+ inXml |= inProperty && xmlStrcmp(localname, XML) == 0;
+ inValue |= inProperty && xmlStrcmp(localname, VALUE) == 0;
+ }
+ } else if (type == XML_READER_TYPE_END_ELEMENT) {
+ const xmlChar *localname = xmlTextReaderConstLocalName(reader->reader);
+
+ if (inXml) {
+ if (xmlStrcmp(localname, XML) != 0) {
+ valueBuffer = xmlStrcat(valueBuffer, BAD_CAST "</");
+ valueBuffer = xmlStrcat(valueBuffer, localname);
+ valueBuffer = xmlStrcat(valueBuffer, BAD_CAST ">");
+ }
+ else {
+ inXml = false;
+ }
+ } else if (xmlStrcmp(localname, ENDPOINT_DESCRIPTION) == 0) {
+ endpoint_description_pt endpointDescription = NULL;
+ // Completely parsed endpoint description, add it to our list of results...
+ if(endpointDescription_create(endpointProperties, &endpointDescription) == CELIX_SUCCESS){
+ arrayList_add(endpointDescriptions, endpointDescription);
+ }
+
+ endpointProperties = properties_create();
+ } else if (xmlStrcmp(localname, PROPERTY) == 0) {
+ inProperty = false;
+
+ if (inArray || inList || inSet) {
+ endpointDescriptorReader_addMultiValuedProperty(endpointProperties, propertyName, propertyValues);
+ }
+ else if (propertyValue != NULL) {
+ if (propertyType != VALUE_TYPE_STRING) {
+ logHelper_log(*reader->loghelper, OSGI_LOGSERVICE_WARNING, "ENDPOINT_DESCRIPTOR_READER: Only string support for %s\n", propertyName);
+ }
+ endpointDescriptorReader_addSingleValuedProperty(endpointProperties, propertyName, propertyValue);
+
+ xmlFree((void *) propertyValue);
+ }
+ else {
+ endpointDescriptorReader_addSingleValuedProperty(endpointProperties, propertyName, valueBuffer);
+ }
+
+ xmlFree((void *) propertyName);
+ unsigned int k=0;
+ for(;k<arrayList_size(propertyValues);k++){
+ free(arrayList_get(propertyValues,k));
+ }
+ arrayList_clear(propertyValues);
+
+ propertyType = VALUE_TYPE_STRING;
+ inArray = false;
+ inList = false;
+ inSet = false;
+ inXml = false;
+ } else if (xmlStrcmp(localname, VALUE) == 0) {
+ arrayList_add(propertyValues, strdup((char*) valueBuffer));
+ valueBuffer[0] = 0;
+ inValue = false;
+ }
+ } else if (type == XML_READER_TYPE_TEXT) {
+ if (inValue || inXml) {
+ const xmlChar *value = xmlTextReaderValue(reader->reader);
+ valueBuffer = xmlStrcat(valueBuffer, value);
+ xmlFree((void *)value);
+ }
+ }
+
+ read = xmlTextReaderRead(reader->reader);
+ }
+
+ if(endpointProperties!=NULL){
+ properties_destroy(endpointProperties);
+ }
+
+ unsigned int k=0;
+ for(;k<arrayList_size(propertyValues);k++){
+ free(arrayList_get(propertyValues,k));
+ }
+ arrayList_destroy(propertyValues);
+ xmlFree(valueBuffer);
+
+ xmlFreeTextReader(reader->reader);
+ }
+
+ return status;
+}
+
+static valueType valueTypeFromString(char *name) {
+ if (name == NULL || strcmp(name, "") == 0 || strcmp(name, "String") == 0) {
+ return VALUE_TYPE_STRING;
+ } else if (strcmp(name, "long") == 0 || strcmp(name, "Long") == 0) {
+ return VALUE_TYPE_LONG;
+ } else if (strcmp(name, "double") == 0 || strcmp(name, "Double") == 0) {
+ return VALUE_TYPE_DOUBLE;
+ } else if (strcmp(name, "float") == 0 || strcmp(name, "Float") == 0) {
+ return VALUE_TYPE_FLOAT;
+ } else if (strcmp(name, "int") == 0 || strcmp(name, "integer") == 0 || strcmp(name, "Integer") == 0) {
+ return VALUE_TYPE_INTEGER;
+ } else if (strcmp(name, "short") == 0 || strcmp(name, "Short") == 0) {
+ return VALUE_TYPE_SHORT;
+ } else if (strcmp(name, "byte") == 0 || strcmp(name, "Byte") == 0) {
+ return VALUE_TYPE_BYTE;
+ } else if (strcmp(name, "char") == 0 || strcmp(name, "Character") == 0) {
+ return VALUE_TYPE_CHAR;
+ } else if (strcmp(name, "boolean") == 0 || strcmp(name, "Boolean") == 0) {
+ return VALUE_TYPE_BOOLEAN;
+ } else {
+ return VALUE_TYPE_STRING;
+ }
+}
+
+#ifdef RSA_ENDPOINT_TEST_READER
+int main() {
+ array_list_pt list = NULL;
+ endpoint_descriptor_reader_pt reader = NULL;
+
+ char *doc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+"<endpoint-descriptions xmlns=\"http://www.osgi.org/xmlns/rsa/v1.0.0\">"
+ "<endpoint-description>"
+ "<property name=\"endpoint.service.id\" value-type=\"long\" value=\"6\"/>"
+ "<property name=\"endpoint.framework.uuid\" value=\"2983D849-93B1-4C2C-AC6D-5BCDA93ACB96\"/>"
+ "<property name=\"service.intents\">"
+ "<list>"
+ "<value>SOAP</value>"
+ "<value>HTTP</value>"
+ "</list>"
+ "</property>"
+ "<property name=\"endpoint.id\" value=\"11111111-1111-1111-1111-111111111111\" />"
+ "<property name=\"objectClass\"><array><value>com.acme.Foo</value></array></property>"
+ "<property name=\"endpoint.package.version.com.acme\" value=\"4.2\" />"
+ "<property name=\"service.imported.configs\" value=\"com.acme\" />"
+ "<property name=\"service.imported\" value=\"true\"/>"
+ "<property name=\"com.acme.ws.xml\">"
+ "<xml>"
+ "<config xmlns=\"http://acme.com/defs\">"
+ "<port>1029</port>"
+ "<host>www.acme.com</host>"
+ "</config>"
+ "</xml>"
+ "</property>"
+ "</endpoint-description>"
+ "<endpoint-description>"
+ "<property name=\"endpoint.service.id\" value-type=\"long\" value=\"5\"/>"
+ "<property name=\"endpoint.framework.uuid\" value=\"2983D849-93B1-4C2C-AC6D-5BCDA93ACB96\"/>"
+ "<property name=\"service.intents\">"
+ "<list>"
+ "<value>SOAP</value>"
+ "<value>HTTP</value>"
+ "</list>"
+ "</property>"
+ "<property name=\"endpoint.id\" value=\"22222222-2222-2222-2222-222222222222\" />"
+ "<property name=\"objectClass\"><array><value>com.acme.Bar</value></array></property>"
+ "<property name=\"endpoint.package.version.com.acme\" value=\"4.2\" />"
+ "<property name=\"service.imported.configs\" value=\"com.acme\" />"
+ "<property name=\"com.acme.ws.xml\">"
+ "<xml>"
+ "<config xmlns=\"http://acme.com/defs\">"
+ "<port>1029</port>"
+ "<host>www.acme.com</host>"
+ "</config>"
+ "</xml>"
+ "</property>"
+ "</endpoint-description>"
+ "</endpoint-descriptions>";
+
+ endpointDescriptorReader_create(&reader);
+
+ endpointDescriptorReader_parseDocument(reader, doc, &list);
+
+ int i;
+ for (i = 0; i < arrayList_size(list); i++) {
+ printf("\nEndpoint description #%d:\n", (i+1));
+ endpoint_description_pt edp = arrayList_get(list, i);
+ printf("Id: %s\n", edp->id);
+ printf("Service Id: %lu\n", edp->serviceId);
+ printf("Framework UUID: %s\n", edp->frameworkUUID);
+ printf("Service: %s\n", edp->service);
+
+ properties_pt props = edp->properties;
+ if (props) {
+ printf("Service properties:\n");
+ hash_map_iterator_pt iter = hashMapIterator_create(props);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+
+ printf("- %s => '%s'\n", hashMapEntry_getKey(entry), hashMapEntry_getValue(entry));
+ }
+ hashMapIterator_destroy(iter);
+ } else {
+ printf("No service properties...\n");
+ }
+
+
+ endpointDescription_destroy(edp);
+ }
+
+ if (list != NULL) {
+ arrayList_destroy(list);
+ }
+
+ endpointDescriptorReader_destroy(reader);
+
+ return 0;
+}
+#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/src/endpoint_descriptor_writer.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/src/endpoint_descriptor_writer.c b/remote_services/discovery_common/src/endpoint_descriptor_writer.c
new file mode 100644
index 0000000..71b07b4
--- /dev/null
+++ b/remote_services/discovery_common/src/endpoint_descriptor_writer.c
@@ -0,0 +1,233 @@
+/**
+ *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.
+ */
+/*
+ * endpoint_descriptor_writer.c
+ *
+ * \date 26 Jul 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <string.h>
+#include <libxml/xmlwriter.h>
+
+#include "constants.h"
+#include "remote_constants.h"
+
+#include "endpoint_description.h"
+#include "endpoint_descriptor_common.h"
+#include "endpoint_descriptor_writer.h"
+
+struct endpoint_descriptor_writer {
+ xmlBufferPtr buffer;
+ xmlTextWriterPtr writer;
+};
+
+static celix_status_t endpointDescriptorWriter_writeEndpoint(endpoint_descriptor_writer_pt writer, endpoint_description_pt endpoint);
+
+static char* valueTypeToString(valueType type);
+
+celix_status_t endpointDescriptorWriter_create(endpoint_descriptor_writer_pt *writer) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *writer = malloc(sizeof(**writer));
+ if (!*writer) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*writer)->buffer = xmlBufferCreate();
+ if ((*writer)->buffer == NULL) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ (*writer)->writer = xmlNewTextWriterMemory((*writer)->buffer, 0);
+ if ((*writer)->writer == NULL) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+ }
+ }
+
+ return status;
+}
+
+celix_status_t endpointDescriptorWriter_destroy(endpoint_descriptor_writer_pt writer) {
+ xmlFreeTextWriter(writer->writer);
+ xmlBufferFree(writer->buffer);
+ free(writer);
+ return CELIX_SUCCESS;
+}
+
+celix_status_t endpointDescriptorWriter_writeDocument(endpoint_descriptor_writer_pt writer, array_list_pt endpoints, char **document) {
+ celix_status_t status = CELIX_SUCCESS;
+ int rc;
+
+ rc = xmlTextWriterStartDocument(writer->writer, NULL, "UTF-8", NULL);
+ if (rc < 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ rc = xmlTextWriterStartElementNS(writer->writer, NULL, ENDPOINT_DESCRIPTIONS, XMLNS);
+ if (rc < 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ unsigned int i;
+ for (i = 0; i < arrayList_size(endpoints); i++) {
+ endpoint_description_pt endpoint = arrayList_get(endpoints, i);
+ status = endpointDescriptorWriter_writeEndpoint(writer, endpoint);
+ }
+ if (status == CELIX_SUCCESS) {
+ rc = xmlTextWriterEndElement(writer->writer);
+ if (rc < 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ rc = xmlTextWriterEndDocument(writer->writer);
+ if (rc < 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ *document = (char *) writer->buffer->content;
+ }
+ }
+ }
+ }
+ }
+
+ return status;
+}
+
+static celix_status_t endpointDescriptorWriter_writeArrayValue(xmlTextWriterPtr writer, const xmlChar* value) {
+ xmlTextWriterStartElement(writer, ARRAY);
+ xmlTextWriterStartElement(writer, VALUE);
+ xmlTextWriterWriteString(writer, value);
+ xmlTextWriterEndElement(writer); // value
+ xmlTextWriterEndElement(writer); // array
+
+ return CELIX_SUCCESS;
+}
+
+static celix_status_t endpointDescriptorWriter_writeTypedValue(xmlTextWriterPtr writer, valueType type, const xmlChar* value) {
+ xmlTextWriterWriteAttribute(writer, VALUE_TYPE, (const xmlChar*) valueTypeToString(type));
+ xmlTextWriterWriteAttribute(writer, VALUE, value);
+
+ return CELIX_SUCCESS;
+}
+
+static celix_status_t endpointDescriptorWriter_writeUntypedValue(xmlTextWriterPtr writer, const xmlChar* value) {
+ xmlTextWriterWriteAttribute(writer, VALUE, value);
+
+ return CELIX_SUCCESS;
+}
+
+static celix_status_t endpointDescriptorWriter_writeEndpoint(endpoint_descriptor_writer_pt writer, endpoint_description_pt endpoint) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (endpoint == NULL || writer == NULL) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ } else {
+ xmlTextWriterStartElement(writer->writer, ENDPOINT_DESCRIPTION);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(endpoint->properties);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+
+ void* propertyName = hashMapEntry_getKey(entry);
+ const xmlChar* propertyValue = (const xmlChar*) hashMapEntry_getValue(entry);
+
+ xmlTextWriterStartElement(writer->writer, PROPERTY);
+ xmlTextWriterWriteAttribute(writer->writer, NAME, propertyName);
+
+ if (strcmp(OSGI_FRAMEWORK_OBJECTCLASS, (char*) propertyName) == 0) {
+ // objectClass *must* be represented as array of string values...
+ endpointDescriptorWriter_writeArrayValue(writer->writer, propertyValue);
+ } else if (strcmp(OSGI_RSA_ENDPOINT_SERVICE_ID, (char*) propertyName) == 0) {
+ // endpoint.service.id *must* be represented as long value...
+ endpointDescriptorWriter_writeTypedValue(writer->writer, VALUE_TYPE_LONG, propertyValue);
+ } else {
+ // represent all other values as plain string values...
+ endpointDescriptorWriter_writeUntypedValue(writer->writer, propertyValue);
+ }
+
+ xmlTextWriterEndElement(writer->writer);
+ }
+ hashMapIterator_destroy(iter);
+
+ xmlTextWriterEndElement(writer->writer);
+ }
+
+ return status;
+}
+
+
+static char* valueTypeToString(valueType type) {
+ switch (type) {
+ case VALUE_TYPE_BOOLEAN:
+ return "boolean";
+ case VALUE_TYPE_BYTE:
+ return "byte";
+ case VALUE_TYPE_CHAR:
+ return "char";
+ case VALUE_TYPE_DOUBLE:
+ return "double";
+ case VALUE_TYPE_FLOAT:
+ return "float";
+ case VALUE_TYPE_INTEGER:
+ return "int";
+ case VALUE_TYPE_LONG:
+ return "long";
+ case VALUE_TYPE_SHORT:
+ return "short";
+ case VALUE_TYPE_STRING:
+ // FALL-THROUGH!
+ default:
+ return "string";
+ }
+}
+
+#ifdef RSA_ENDPOINT_TEST_WRITER
+int main() {
+ endpoint_descriptor_writer_pt writer = NULL;
+ endpointDescriptorWriter_create(&writer);
+ array_list_pt list = NULL;
+ arrayList_create(&list);
+
+ properties_pt props = properties_create();
+ properties_set(props, "objectClass", "com.acme.Foo");
+ properties_set(props, "endpoint.service.id", "3");
+ properties_set(props, "endpoint.id", "abcdefghijklmnopqrstuvwxyz");
+ properties_set(props, "endpoint.framework.uuid", "2983D849-93B1-4C2C-AC6D-5BCDA93ACB96");
+ endpoint_description_pt epd = NULL;
+ endpointDescription_create(props, &epd);
+ arrayList_add(list, epd);
+
+ properties_pt props2 = properties_create();
+ properties_set(props2, "objectClass", "com.acme.Bar");
+ properties_set(props, "endpoint.service.id", "4");
+ properties_set(props, "endpoint.id", "abcdefghijklmnopqrstuvwxyz");
+ properties_set(props, "endpoint.framework.uuid", "2983D849-93B1-4C2C-AC6D-5BCDA93ACB96");
+ endpoint_description_pt epd2 = NULL;
+ endpointDescription_create(props2, &epd2);
+ arrayList_add(list, epd2);
+
+ char *buffer = NULL;
+ endpointDescriptorWriter_writeDocument(writer, list, &buffer);
+
+ arrayList_destroy(list);
+ endpointDescription_destroy(epd);
+ endpointDescription_destroy(epd2);
+ endpointDescriptorWriter_destroy(writer);
+
+ printf("%s\n", buffer);
+}
+#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/src/endpoint_discovery_poller.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/src/endpoint_discovery_poller.c b/remote_services/discovery_common/src/endpoint_discovery_poller.c
new file mode 100644
index 0000000..73fb7ba
--- /dev/null
+++ b/remote_services/discovery_common/src/endpoint_discovery_poller.c
@@ -0,0 +1,403 @@
+/**
+ * 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.
+ */
+/*
+ * endpoint_discovery_poller.c
+ *
+ * \date 3 Jul 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <curl/curl.h>
+
+#include "bundle_context.h"
+#include "log_helper.h"
+#include "utils.h"
+
+#include "discovery_impl.h"
+
+#include "endpoint_descriptor_reader.h"
+
+
+#define DISCOVERY_POLL_INTERVAL "DISCOVERY_CFG_POLL_INTERVAL"
+#define DEFAULT_POLL_INTERVAL "10"
+
+
+static void *endpointDiscoveryPoller_performPeriodicPoll(void *data);
+celix_status_t endpointDiscoveryPoller_poll(endpoint_discovery_poller_pt poller, char *url, array_list_pt currentEndpoints);
+static celix_status_t endpointDiscoveryPoller_getEndpoints(endpoint_discovery_poller_pt poller, char *url, array_list_pt *updatedEndpoints);
+static celix_status_t endpointDiscoveryPoller_endpointDescriptionEquals(const void *endpointPtr, const void *comparePtr, bool *equals);
+
+/**
+ * Allocates memory and initializes a new endpoint_discovery_poller instance.
+ */
+celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_poller_pt *poller) {
+ celix_status_t status;
+
+ *poller = malloc(sizeof(struct endpoint_discovery_poller));
+ if (!*poller) {
+ return CELIX_ENOMEM;
+ }
+
+ (*poller)->loghelper = &discovery->loghelper;
+
+ status = celixThreadMutex_create(&(*poller)->pollerLock, NULL);
+ if (status != CELIX_SUCCESS) {
+ return status;
+ }
+
+ const char* interval = NULL;
+ status = bundleContext_getProperty(context, DISCOVERY_POLL_INTERVAL, &interval);
+ if (!interval) {
+ interval = DEFAULT_POLL_INTERVAL;
+ }
+
+ const char* endpointsProp = NULL;
+ status = bundleContext_getProperty(context, DISCOVERY_POLL_ENDPOINTS, &endpointsProp);
+ if (!endpointsProp) {
+ endpointsProp = DEFAULT_POLL_ENDPOINTS;
+ }
+ // we're going to mutate the string with strtok, so create a copy...
+ char* endpoints = strdup(endpointsProp);
+
+ (*poller)->poll_interval = atoi(interval);
+ (*poller)->discovery = discovery;
+ (*poller)->running = false;
+ (*poller)->entries = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+
+ const char* sep = ",";
+ char *save_ptr = NULL;
+ char* tok = strtok_r(endpoints, sep, &save_ptr);
+ while (tok) {
+ endpointDiscoveryPoller_addDiscoveryEndpoint(*poller, utils_stringTrim(tok));
+ tok = strtok_r(NULL, sep, &save_ptr);
+ }
+ // Clean up after ourselves...
+ free(endpoints);
+
+ status = celixThreadMutex_lock(&(*poller)->pollerLock);
+ if (status != CELIX_SUCCESS) {
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+
+ (*poller)->running = true;
+
+ status += celixThread_create(&(*poller)->pollerThread, NULL, endpointDiscoveryPoller_performPeriodicPoll, *poller);
+ status += celixThreadMutex_unlock(&(*poller)->pollerLock);
+
+ if(status != CELIX_SUCCESS){
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+
+ return status;
+}
+
+/**
+ * Destroys and frees up memory for a given endpoint_discovery_poller struct.
+ */
+celix_status_t endpointDiscoveryPoller_destroy(endpoint_discovery_poller_pt poller) {
+ celix_status_t status;
+
+ poller->running = false;
+
+ celixThread_join(poller->pollerThread, NULL);
+
+ hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries);
+ while (hashMapIterator_hasNext(iterator)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);
+
+ if ( endpointDiscoveryPoller_removeDiscoveryEndpoint(poller, (char*) hashMapEntry_getKey(entry)) == CELIX_SUCCESS) {
+ hashMapIterator_destroy(iterator);
+ iterator = hashMapIterator_create(poller->entries);
+ }
+ }
+ hashMapIterator_destroy(iterator);
+
+ status = celixThreadMutex_lock(&poller->pollerLock);
+
+ if (status != CELIX_SUCCESS) {
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+
+ hashMap_destroy(poller->entries, true, false);
+
+ status = celixThreadMutex_unlock(&poller->pollerLock);
+
+ poller->loghelper = NULL;
+
+ free(poller);
+
+ return status;
+}
+
+
+celix_status_t endpointDiscoveryPoller_getDiscoveryEndpoints(endpoint_discovery_poller_pt poller, array_list_pt urls) {
+ celixThreadMutex_lock(&(poller)->pollerLock);
+
+ hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries);
+
+ while(hashMapIterator_hasNext(iterator)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);
+ char* toAdd = strdup((char*) hashMapEntry_getKey(entry));
+ arrayList_add(urls, toAdd);
+ }
+
+ hashMapIterator_destroy(iterator);
+
+ celixThreadMutex_unlock(&(poller)->pollerLock);
+
+ return CELIX_SUCCESS;
+}
+
+/**
+ * Adds a new endpoint URL to the list of polled endpoints.
+ */
+celix_status_t endpointDiscoveryPoller_addDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url) {
+ celix_status_t status;
+
+ status = celixThreadMutex_lock(&(poller)->pollerLock);
+ if (status != CELIX_SUCCESS) {
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+
+ // Avoid memory leaks when adding an already existing URL...
+ array_list_pt endpoints = hashMap_get(poller->entries, url);
+ if (endpoints == NULL) {
+ status = arrayList_createWithEquals(endpointDiscoveryPoller_endpointDescriptionEquals, &endpoints);
+
+ if (status == CELIX_SUCCESS) {
+ logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_DEBUG, "ENDPOINT_POLLER: add new discovery endpoint with url %s", url);
+ hashMap_put(poller->entries, strdup(url), endpoints);
+ endpointDiscoveryPoller_poll(poller, url, endpoints);
+ }
+ }
+
+ status = celixThreadMutex_unlock(&poller->pollerLock);
+
+ return status;
+}
+
+/**
+ * Removes an endpoint URL from the list of polled endpoints.
+ */
+celix_status_t endpointDiscoveryPoller_removeDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (celixThreadMutex_lock(&poller->pollerLock) != CELIX_SUCCESS) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ hash_map_entry_pt entry = hashMap_getEntry(poller->entries, url);
+
+ if (entry == NULL) {
+ logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_DEBUG, "ENDPOINT_POLLER: There was no entry found belonging to url %s - maybe already removed?", url);
+ } else {
+ char* origKey = hashMapEntry_getKey(entry);
+
+ logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_DEBUG, "ENDPOINT_POLLER: remove discovery endpoint with url %s", url);
+
+ array_list_pt entries = hashMap_remove(poller->entries, url);
+
+ if (entries != NULL) {
+ for (unsigned int i = arrayList_size(entries); i > 0; i--) {
+ endpoint_description_pt endpoint = arrayList_get(entries, i - 1);
+ discovery_removeDiscoveredEndpoint(poller->discovery, endpoint);
+ arrayList_remove(entries, i - 1);
+ endpointDescription_destroy(endpoint);
+ }
+ arrayList_destroy(entries);
+ }
+
+ free(origKey);
+ }
+ status = celixThreadMutex_unlock(&poller->pollerLock);
+ }
+
+ return status;
+}
+
+
+
+
+celix_status_t endpointDiscoveryPoller_poll(endpoint_discovery_poller_pt poller, char *url, array_list_pt currentEndpoints) {
+ celix_status_t status;
+ array_list_pt updatedEndpoints = NULL;
+
+ // create an arraylist with a custom equality test to ensure we can find endpoints properly...
+ arrayList_createWithEquals(endpointDiscoveryPoller_endpointDescriptionEquals, &updatedEndpoints);
+ status = endpointDiscoveryPoller_getEndpoints(poller, url, &updatedEndpoints);
+
+ if (status == CELIX_SUCCESS) {
+ if (updatedEndpoints!=NULL) {
+ for (unsigned int i = arrayList_size(currentEndpoints); i > 0; i--) {
+ endpoint_description_pt endpoint = arrayList_get(currentEndpoints, i - 1);
+
+ if (!arrayList_contains(updatedEndpoints, endpoint)) {
+ status = discovery_removeDiscoveredEndpoint(poller->discovery, endpoint);
+ arrayList_remove(currentEndpoints, i - 1);
+ endpointDescription_destroy(endpoint);
+ }
+ }
+
+ for (int i = arrayList_size(updatedEndpoints); i > 0; i--) {
+ endpoint_description_pt endpoint = arrayList_remove(updatedEndpoints, 0);
+
+ if (!arrayList_contains(currentEndpoints, endpoint)) {
+ arrayList_add(currentEndpoints, endpoint);
+ status = discovery_addDiscoveredEndpoint(poller->discovery, endpoint);
+ } else {
+ endpointDescription_destroy(endpoint);
+
+ }
+ }
+ }
+ }
+
+ if(updatedEndpoints!=NULL){
+ arrayList_destroy(updatedEndpoints);
+ }
+
+ return status;
+}
+
+static void *endpointDiscoveryPoller_performPeriodicPoll(void *data) {
+ endpoint_discovery_poller_pt poller = (endpoint_discovery_poller_pt) data;
+
+ useconds_t interval = (useconds_t) (poller->poll_interval * 1000000L);
+
+ while (poller->running) {
+ usleep(interval);
+ celix_status_t status = celixThreadMutex_lock(&poller->pollerLock);
+
+ if (status != CELIX_SUCCESS) {
+ logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_WARNING, "ENDPOINT_POLLER: failed to obtain lock; retrying...");
+ } else {
+ hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries);
+
+ while (hashMapIterator_hasNext(iterator)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);
+
+ char *url = hashMapEntry_getKey(entry);
+ array_list_pt currentEndpoints = hashMapEntry_getValue(entry);
+
+ endpointDiscoveryPoller_poll(poller, url, currentEndpoints);
+ }
+
+ hashMapIterator_destroy(iterator);
+ }
+
+ status = celixThreadMutex_unlock(&poller->pollerLock);
+ if (status != CELIX_SUCCESS) {
+ logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_WARNING, "ENDPOINT_POLLER: failed to release lock; retrying...");
+ }
+ }
+
+ return NULL;
+}
+
+
+
+struct MemoryStruct {
+ char *memory;
+ size_t size;
+};
+
+static size_t endpointDiscoveryPoller_writeMemory(void *contents, size_t size, size_t nmemb, void *memoryPtr) {
+ size_t realsize = size * nmemb;
+ struct MemoryStruct *mem = (struct MemoryStruct *)memoryPtr;
+
+ mem->memory = realloc(mem->memory, mem->size + realsize + 1);
+ if(mem->memory == NULL) {
+ printf("ENDPOINT_POLLER: not enough memory (realloc returned NULL)!");
+ return 0;
+ }
+
+ memcpy(&(mem->memory[mem->size]), contents, realsize);
+ mem->size += realsize;
+ mem->memory[mem->size] = 0;
+
+ return realsize;
+}
+
+static celix_status_t endpointDiscoveryPoller_getEndpoints(endpoint_discovery_poller_pt poller, char *url, array_list_pt *updatedEndpoints) {
+ celix_status_t status = CELIX_SUCCESS;
+
+
+ CURL *curl = NULL;
+ CURLcode res = CURLE_OK;
+
+ struct MemoryStruct chunk;
+ chunk.memory = malloc(1);
+ chunk.size = 0;
+
+ curl = curl_easy_init();
+ if (!curl) {
+ status = CELIX_ILLEGAL_STATE;
+ } else {
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, endpointDiscoveryPoller_writeMemory);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
+ curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5L);
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
+ res = curl_easy_perform(curl);
+
+ curl_easy_cleanup(curl);
+ }
+
+ // process endpoints file
+ if (res == CURLE_OK) {
+ endpoint_descriptor_reader_pt reader = NULL;
+
+ status = endpointDescriptorReader_create(poller, &reader);
+ if (status == CELIX_SUCCESS) {
+ status = endpointDescriptorReader_parseDocument(reader, chunk.memory, updatedEndpoints);
+ }
+
+ if (reader) {
+ endpointDescriptorReader_destroy(reader);
+ }
+ } else {
+ logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_ERROR, "ENDPOINT_POLLER: unable to read endpoints from %s, reason: %s", url, curl_easy_strerror(res));
+ }
+
+ // clean up endpoints file
+ if (chunk.memory) {
+ free(chunk.memory);
+ }
+
+ return status;
+}
+
+static celix_status_t endpointDiscoveryPoller_endpointDescriptionEquals(const void *endpointPtr, const void *comparePtr, bool *equals) {
+ endpoint_description_pt endpoint = (endpoint_description_pt) endpointPtr;
+ endpoint_description_pt compare = (endpoint_description_pt) comparePtr;
+
+ if (strcmp(endpoint->id, compare->id) == 0) {
+ *equals = true;
+ } else {
+ *equals = false;
+ }
+
+ return CELIX_SUCCESS;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/src/endpoint_discovery_server.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/src/endpoint_discovery_server.c b/remote_services/discovery_common/src/endpoint_discovery_server.c
new file mode 100644
index 0000000..f5f82af
--- /dev/null
+++ b/remote_services/discovery_common/src/endpoint_discovery_server.c
@@ -0,0 +1,450 @@
+/**
+ * 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.
+ */
+/*
+ * endpoint_discovery_server.c
+ *
+ * \date Aug 12, 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <string.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#ifndef ANDROID
+#include <ifaddrs.h>
+#endif
+#include "civetweb.h"
+#include "celix_errno.h"
+#include "utils.h"
+#include "log_helper.h"
+#include "discovery.h"
+#include "discovery_impl.h"
+
+#include "endpoint_descriptor_writer.h"
+
+// defines how often the webserver is restarted (with an increased port number)
+#define MAX_NUMBER_OF_RESTARTS 15
+#define DEFAULT_SERVER_THREADS "1"
+
+#define CIVETWEB_REQUEST_NOT_HANDLED 0
+#define CIVETWEB_REQUEST_HANDLED 1
+
+static const char *response_headers =
+ "HTTP/1.1 200 OK\r\n"
+ "Cache: no-cache\r\n"
+ "Content-Type: application/xml;charset=utf-8\r\n"
+ "\r\n";
+
+struct endpoint_discovery_server {
+ log_helper_pt* loghelper;
+ hash_map_pt entries; // key = endpointId, value = endpoint_descriptor_pt
+
+ celix_thread_mutex_t serverLock;
+
+ const char* path;
+ const char *port;
+ const char* ip;
+ struct mg_context* ctx;
+};
+
+// Forward declarations...
+static int endpointDiscoveryServer_callback(struct mg_connection *conn);
+static char* format_path(const char* path);
+
+#ifndef ANDROID
+static celix_status_t endpointDiscoveryServer_getIpAdress(char* interface, char** ip);
+#endif
+
+celix_status_t endpointDiscoveryServer_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_server_pt *server) {
+ celix_status_t status;
+
+ const char *port = NULL;
+ const char *ip = NULL;
+ char *detectedIp = NULL;
+ const char *path = NULL;
+ const char *retries = NULL;
+
+ int max_ep_num = MAX_NUMBER_OF_RESTARTS;
+
+ *server = malloc(sizeof(struct endpoint_discovery_server));
+ if (!*server) {
+ return CELIX_ENOMEM;
+ }
+
+ (*server)->loghelper = &discovery->loghelper;
+ (*server)->entries = hashMap_create(&utils_stringHash, NULL, &utils_stringEquals, NULL);
+ if (!(*server)->entries) {
+ return CELIX_ENOMEM;
+ }
+
+ status = celixThreadMutex_create(&(*server)->serverLock, NULL);
+ if (status != CELIX_SUCCESS) {
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+
+ bundleContext_getProperty(context, DISCOVERY_SERVER_IP, &ip);
+#ifndef ANDROID
+ if (ip == NULL) {
+ const char *interface = NULL;
+
+ bundleContext_getProperty(context, DISCOVERY_SERVER_INTERFACE, &interface);
+ if ((interface != NULL) && (endpointDiscoveryServer_getIpAdress((char*)interface, &detectedIp) != CELIX_SUCCESS)) {
+ logHelper_log(*(*server)->loghelper, OSGI_LOGSERVICE_WARNING, "Could not retrieve IP adress for interface %s", interface);
+ }
+
+ if (detectedIp == NULL) {
+ endpointDiscoveryServer_getIpAdress(NULL, &detectedIp);
+ }
+
+ ip = detectedIp;
+ }
+#endif
+
+ if (ip != NULL) {
+ logHelper_log(*(*server)->loghelper, OSGI_LOGSERVICE_INFO, "Using %s for service annunciation", ip);
+ (*server)->ip = strdup(ip);
+ }
+ else {
+ logHelper_log(*(*server)->loghelper, OSGI_LOGSERVICE_WARNING, "No IP address for service annunciation set. Using %s", DEFAULT_SERVER_IP);
+ (*server)->ip = strdup((char*) DEFAULT_SERVER_IP);
+ }
+
+ if (detectedIp != NULL) {
+ free(detectedIp);
+ }
+
+ bundleContext_getProperty(context, DISCOVERY_SERVER_PORT, &port);
+ if (port == NULL) {
+ port = DEFAULT_SERVER_PORT;
+ }
+
+ bundleContext_getProperty(context, DISCOVERY_SERVER_PATH, &path);
+ if (path == NULL) {
+ path = DEFAULT_SERVER_PATH;
+ }
+
+ bundleContext_getProperty(context, DISCOVERY_SERVER_MAX_EP, &retries);
+ if (retries != NULL) {
+ errno=0;
+ max_ep_num = strtol(retries,NULL,10);
+ if(errno!=0 || max_ep_num<=0){
+ max_ep_num=MAX_NUMBER_OF_RESTARTS;
+ }
+ }
+
+ (*server)->path = format_path(path);
+
+ const struct mg_callbacks callbacks = {
+ .begin_request = endpointDiscoveryServer_callback,
+ };
+
+ unsigned int port_counter = 0;
+ char newPort[10];
+
+ do {
+ const char *options[] = {
+ "listening_ports", port,
+ "num_threads", DEFAULT_SERVER_THREADS,
+ NULL
+ };
+
+ (*server)->ctx = mg_start(&callbacks, (*server), options);
+
+ if ((*server)->ctx != NULL)
+ {
+ logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "Starting discovery server on port %s...", port);
+ }
+ else {
+ errno = 0;
+ char* endptr = (char*)port;
+ long currentPort = strtol(port, &endptr, 10);
+
+ if (*endptr || errno != 0) {
+ currentPort = strtol(DEFAULT_SERVER_PORT, NULL, 10);
+ }
+
+ port_counter++;
+ snprintf(&newPort[0], 10, "%ld", (currentPort+1));
+
+ logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_ERROR, "Error while starting discovery server on port %s - retrying on port %s...", port, newPort);
+ port = newPort;
+
+ }
+
+ } while(((*server)->ctx == NULL) && (port_counter < max_ep_num));
+
+ (*server)->port = strdup(port);
+
+ return status;
+}
+
+celix_status_t endpointDiscoveryServer_getUrl(endpoint_discovery_server_pt server, char* url)
+{
+ celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+
+ if (server->ip && server->port && server->path) {
+ sprintf(url, "http://%s:%s/%s", server->ip, server->port, server->path);
+ status = CELIX_SUCCESS;
+ }
+
+ return status;
+}
+
+celix_status_t endpointDiscoveryServer_destroy(endpoint_discovery_server_pt server) {
+ celix_status_t status;
+
+ // stop & block until the actual server is shut down...
+ if (server->ctx != NULL) {
+ mg_stop(server->ctx);
+ server->ctx = NULL;
+ }
+
+ status = celixThreadMutex_lock(&server->serverLock);
+
+ hashMap_destroy(server->entries, true /* freeKeys */, false /* freeValues */);
+
+ status = celixThreadMutex_unlock(&server->serverLock);
+ status = celixThreadMutex_destroy(&server->serverLock);
+
+ free((void*) server->path);
+ free((void*) server->port);
+ free((void*) server->ip);
+
+ free(server);
+
+ return status;
+}
+
+celix_status_t endpointDiscoveryServer_addEndpoint(endpoint_discovery_server_pt server, endpoint_description_pt endpoint) {
+ celix_status_t status;
+
+ status = celixThreadMutex_lock(&server->serverLock);
+ if (status != CELIX_SUCCESS) {
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+
+ // create a local copy of the endpointId which we can control...
+ char* endpointId = strdup(endpoint->id);
+ endpoint_description_pt cur_value = hashMap_get(server->entries, endpointId);
+ if (!cur_value) {
+ logHelper_log(*server->loghelper, OSGI_LOGSERVICE_INFO, "exposing new endpoint \"%s\"...", endpointId);
+
+ hashMap_put(server->entries, endpointId, endpoint);
+ }
+
+ status = celixThreadMutex_unlock(&server->serverLock);
+ if (status != CELIX_SUCCESS) {
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+
+ return status;
+}
+
+celix_status_t endpointDiscoveryServer_removeEndpoint(endpoint_discovery_server_pt server, endpoint_description_pt endpoint) {
+ celix_status_t status;
+
+ status = celixThreadMutex_lock(&server->serverLock);
+ if (status != CELIX_SUCCESS) {
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+
+ hash_map_entry_pt entry = hashMap_getEntry(server->entries, endpoint->id);
+ if (entry) {
+ char* key = hashMapEntry_getKey(entry);
+
+ logHelper_log(*server->loghelper, OSGI_LOGSERVICE_INFO, "removing endpoint \"%s\"...\n", key);
+
+ hashMap_remove(server->entries, key);
+
+ // we've made this key, see _addEnpoint above...
+ free((void*) key);
+ }
+
+ status = celixThreadMutex_unlock(&server->serverLock);
+ if (status != CELIX_SUCCESS) {
+ return CELIX_BUNDLE_EXCEPTION;
+ }
+
+ return status;
+}
+
+static char* format_path(const char* path) {
+ char* result = strdup(path);
+ result = utils_stringTrim(result);
+ // check whether the path starts with a leading slash...
+ if (result[0] != '/') {
+ size_t len = strlen(result);
+ result = realloc(result, len + 2);
+ memmove(result + 1, result, len);
+ result[0] = '/';
+ result[len + 1] = 0;
+ }
+ return result;
+}
+
+static celix_status_t endpointDiscoveryServer_getEndpoints(endpoint_discovery_server_pt server, const char* the_endpoint_id, array_list_pt *endpoints) {
+ celix_status_t status;
+
+ status = arrayList_create(endpoints);
+ if (status != CELIX_SUCCESS) {
+ return CELIX_ENOMEM;
+ }
+
+
+ hash_map_iterator_pt iter = hashMapIterator_create(server->entries);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+
+ char* endpoint_id = hashMapEntry_getKey(entry);
+ if (the_endpoint_id == NULL || strcmp(the_endpoint_id, endpoint_id) == 0) {
+ endpoint_description_pt endpoint = hashMapEntry_getValue(entry);
+
+ arrayList_add(*endpoints, endpoint);
+ }
+ }
+ hashMapIterator_destroy(iter);
+
+ return status;
+}
+
+static int endpointDiscoveryServer_writeEndpoints(struct mg_connection* conn, array_list_pt endpoints) {
+ celix_status_t status;
+ int rv = CIVETWEB_REQUEST_NOT_HANDLED;
+
+ endpoint_descriptor_writer_pt writer = NULL;
+ status = endpointDescriptorWriter_create(&writer);
+ if (status == CELIX_SUCCESS) {
+
+ char *buffer = NULL;
+ status = endpointDescriptorWriter_writeDocument(writer, endpoints, &buffer);
+ if (buffer) {
+ mg_write(conn, response_headers, strlen(response_headers));
+ mg_write(conn, buffer, strlen(buffer));
+ }
+
+ rv = CIVETWEB_REQUEST_HANDLED;
+ }
+
+ if(writer!=NULL){
+ endpointDescriptorWriter_destroy(writer);
+ }
+
+ return rv;
+}
+
+// returns all endpoints as XML...
+static int endpointDiscoveryServer_returnAllEndpoints(endpoint_discovery_server_pt server, struct mg_connection* conn) {
+ int status = CIVETWEB_REQUEST_NOT_HANDLED;
+
+ array_list_pt endpoints = NULL;
+
+ if (celixThreadMutex_lock(&server->serverLock) == CELIX_SUCCESS) {
+ endpointDiscoveryServer_getEndpoints(server, NULL, &endpoints);
+ if (endpoints) {
+ status = endpointDiscoveryServer_writeEndpoints(conn, endpoints);
+
+ arrayList_destroy(endpoints);
+ }
+
+
+ celixThreadMutex_unlock(&server->serverLock);
+ }
+
+ return status;
+}
+
+// returns a single endpoint as XML...
+static int endpointDiscoveryServer_returnEndpoint(endpoint_discovery_server_pt server, struct mg_connection* conn, const char* endpoint_id) {
+ int status = CIVETWEB_REQUEST_NOT_HANDLED;
+
+ array_list_pt endpoints = NULL;
+
+ if (celixThreadMutex_lock(&server->serverLock) == CELIX_SUCCESS) {
+ endpointDiscoveryServer_getEndpoints(server, endpoint_id, &endpoints);
+ if (endpoints) {
+ status = endpointDiscoveryServer_writeEndpoints(conn, endpoints);
+
+ arrayList_destroy(endpoints);
+ }
+
+ celixThreadMutex_unlock(&server->serverLock);
+ }
+
+ return status;
+}
+
+static int endpointDiscoveryServer_callback(struct mg_connection* conn) {
+ int status = CIVETWEB_REQUEST_NOT_HANDLED;
+
+ const struct mg_request_info *request_info = mg_get_request_info(conn);
+ if (request_info->uri != NULL && strcmp("GET", request_info->request_method) == 0) {
+ endpoint_discovery_server_pt server = request_info->user_data;
+
+ const char *uri = request_info->uri;
+ const size_t path_len = strlen(server->path);
+ const size_t uri_len = strlen(uri);
+
+ if (strncmp(server->path, uri, strlen(server->path)) == 0) {
+ // Be lenient when it comes to the trailing slash...
+ if (path_len == uri_len || (uri_len == (path_len + 1) && uri[path_len] == '/')) {
+ status = endpointDiscoveryServer_returnAllEndpoints(server, conn);
+ } else {
+ const char* endpoint_id = uri + path_len + 1; // right after the slash...
+
+ status = endpointDiscoveryServer_returnEndpoint(server, conn, endpoint_id);
+ }
+ }
+ }
+
+ return status;
+}
+
+#ifndef ANDROID
+static celix_status_t endpointDiscoveryServer_getIpAdress(char* interface, char** ip) {
+ celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+
+ struct ifaddrs *ifaddr, *ifa;
+ char host[NI_MAXHOST];
+
+ if (getifaddrs(&ifaddr) != -1)
+ {
+ for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
+ {
+ if (ifa->ifa_addr == NULL)
+ continue;
+
+ if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
+ if (interface == NULL) {
+ *ip = strdup(host);
+ status = CELIX_SUCCESS;
+ }
+ else if (strcmp(ifa->ifa_name, interface) == 0) {
+ *ip = strdup(host);
+ status = CELIX_SUCCESS;
+ }
+ }
+ }
+
+ freeifaddrs(ifaddr);
+ }
+
+ return status;
+}
+#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_common/src/md5.inl
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/src/md5.inl b/remote_services/discovery_common/src/md5.inl
new file mode 100644
index 0000000..4da933d
--- /dev/null
+++ b/remote_services/discovery_common/src/md5.inl
@@ -0,0 +1,461 @@
+/*
+ * This an amalgamation of md5.c and md5.h into a single file
+ * with all static declaration to reduce linker conflicts
+ * in Civetweb.
+ *
+ * The MD5_STATIC declaration was added to facilitate static
+ * inclusion.
+ * No Face Press, LLC
+ */
+
+/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
+/*
+ Independent implementation of MD5 (RFC 1321).
+
+ This code implements the MD5 Algorithm defined in RFC 1321, whose
+ text is available at
+ http://www.ietf.org/rfc/rfc1321.txt
+ The code is derived from the text of the RFC, including the test suite
+ (section A.5) but excluding the rest of Appendix A. It does not include
+ any code or documentation that is identified in the RFC as being
+ copyrighted.
+
+ The original and principal author of md5.h is L. Peter Deutsch
+ <gh...@aladdin.com>. Other authors are noted in the change history
+ that follows (in reverse chronological order):
+
+ 2002-04-13 lpd Removed support for non-ANSI compilers; removed
+ references to Ghostscript; clarified derivation from RFC 1321;
+ now handles byte order either statically or dynamically.
+ 1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
+ 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
+ added conditionalization for C++ compilation from Martin
+ Purschke <pu...@bnl.gov>.
+ 1999-05-03 lpd Original version.
+ */
+
+#ifndef md5_INCLUDED
+# define md5_INCLUDED
+
+/*
+ * This package supports both compile-time and run-time determination of CPU
+ * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
+ * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
+ * defined as non-zero, the code will be compiled to run only on big-endian
+ * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
+ * run on either big- or little-endian CPUs, but will run slightly less
+ * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
+ */
+
+typedef unsigned char md5_byte_t; /* 8-bit byte */
+typedef unsigned int md5_word_t; /* 32-bit word */
+
+/* Define the state of the MD5 Algorithm. */
+typedef struct md5_state_s {
+ md5_word_t count[2]; /* message length in bits, lsw first */
+ md5_word_t abcd[4]; /* digest buffer */
+ md5_byte_t buf[64]; /* accumulate block */
+} md5_state_t;
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* Initialize the algorithm. */
+MD5_STATIC void md5_init(md5_state_t *pms);
+
+/* Append a string to the message. */
+MD5_STATIC void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);
+
+/* Finish the message and return the digest. */
+MD5_STATIC void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
+
+#ifdef __cplusplus
+} /* end extern "C" */
+#endif
+
+#endif /* md5_INCLUDED */
+
+/*
+ Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved.
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ L. Peter Deutsch
+ ghost@aladdin.com
+
+ */
+/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */
+/*
+ Independent implementation of MD5 (RFC 1321).
+
+ This code implements the MD5 Algorithm defined in RFC 1321, whose
+ text is available at
+ http://www.ietf.org/rfc/rfc1321.txt
+ The code is derived from the text of the RFC, including the test suite
+ (section A.5) but excluding the rest of Appendix A. It does not include
+ any code or documentation that is identified in the RFC as being
+ copyrighted.
+
+ The original and principal author of md5.c is L. Peter Deutsch
+ <gh...@aladdin.com>. Other authors are noted in the change history
+ that follows (in reverse chronological order):
+
+ 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order
+ either statically or dynamically; added missing #include <string.h>
+ in library.
+ 2002-03-11 lpd Corrected argument list for main(), and added int return
+ type, in test program and T value program.
+ 2002-02-21 lpd Added missing #include <stdio.h> in test program.
+ 2000-07-03 lpd Patched to eliminate warnings about "constant is
+ unsigned in ANSI C, signed in traditional"; made test program
+ self-checking.
+ 1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
+ 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
+ 1999-05-03 lpd Original version.
+ */
+
+#ifndef MD5_STATIC
+#include <string.h>
+#endif
+
+#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
+#ifdef ARCH_IS_BIG_ENDIAN
+# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
+#else
+# define BYTE_ORDER 0
+#endif
+
+#define T_MASK ((md5_word_t)~0)
+#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87)
+#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9)
+#define T3 0x242070db
+#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111)
+#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050)
+#define T6 0x4787c62a
+#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec)
+#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe)
+#define T9 0x698098d8
+#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850)
+#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e)
+#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841)
+#define T13 0x6b901122
+#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c)
+#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71)
+#define T16 0x49b40821
+#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d)
+#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf)
+#define T19 0x265e5a51
+#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855)
+#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2)
+#define T22 0x02441453
+#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e)
+#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437)
+#define T25 0x21e1cde6
+#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829)
+#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278)
+#define T28 0x455a14ed
+#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa)
+#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07)
+#define T31 0x676f02d9
+#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375)
+#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd)
+#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e)
+#define T35 0x6d9d6122
+#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3)
+#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb)
+#define T38 0x4bdecfa9
+#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f)
+#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f)
+#define T41 0x289b7ec6
+#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805)
+#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a)
+#define T44 0x04881d05
+#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6)
+#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a)
+#define T47 0x1fa27cf8
+#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a)
+#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb)
+#define T50 0x432aff97
+#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58)
+#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6)
+#define T53 0x655b59c3
+#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d)
+#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82)
+#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e)
+#define T57 0x6fa87e4f
+#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f)
+#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb)
+#define T60 0x4e0811a1
+#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d)
+#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca)
+#define T63 0x2ad7d2bb
+#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e)
+
+
+static void
+md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
+{
+ md5_word_t
+ a = pms->abcd[0], b = pms->abcd[1],
+ c = pms->abcd[2], d = pms->abcd[3];
+ md5_word_t t;
+#if BYTE_ORDER > 0
+ /* Define storage only for big-endian CPUs. */
+ md5_word_t X[16];
+#else
+ /* Define storage for little-endian or both types of CPUs. */
+ md5_word_t xbuf[16];
+ const md5_word_t *X;
+#endif
+
+ {
+#if BYTE_ORDER == 0
+ /*
+ * Determine dynamically whether this is a big-endian or
+ * little-endian machine, since we can use a more efficient
+ * algorithm on the latter.
+ */
+ static const int w = 1;
+
+ if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
+#endif
+#if BYTE_ORDER <= 0 /* little-endian */
+ {
+ /*
+ * On little-endian machines, we can process properly aligned
+ * data without copying it.
+ */
+ if (!((data - (const md5_byte_t *)0) & 3)) {
+ /* data are properly aligned */
+ X = (const md5_word_t *)data;
+ } else {
+ /* not aligned */
+ memcpy(xbuf, data, 64);
+ X = xbuf;
+ }
+ }
+#endif
+#if BYTE_ORDER == 0
+ else /* dynamic big-endian */
+#endif
+#if BYTE_ORDER >= 0 /* big-endian */
+ {
+ /*
+ * On big-endian machines, we must arrange the bytes in the
+ * right order.
+ */
+ const md5_byte_t *xp = data;
+ int i;
+
+# if BYTE_ORDER == 0
+ X = xbuf; /* (dynamic only) */
+# else
+# define xbuf X /* (static only) */
+# endif
+ for (i = 0; i < 16; ++i, xp += 4)
+ xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
+ }
+#endif
+ }
+
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
+
+ /* Round 1. */
+ /* Let [abcd k s i] denote the operation
+ a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
+#define F(x, y, z) (((x) & (y)) | (~(x) & (z)))
+#define SET(a, b, c, d, k, s, Ti)\
+ t = a + F(b,c,d) + X[k] + Ti;\
+ a = ROTATE_LEFT(t, s) + b
+ /* Do the following 16 operations. */
+ SET(a, b, c, d, 0, 7, T1);
+ SET(d, a, b, c, 1, 12, T2);
+ SET(c, d, a, b, 2, 17, T3);
+ SET(b, c, d, a, 3, 22, T4);
+ SET(a, b, c, d, 4, 7, T5);
+ SET(d, a, b, c, 5, 12, T6);
+ SET(c, d, a, b, 6, 17, T7);
+ SET(b, c, d, a, 7, 22, T8);
+ SET(a, b, c, d, 8, 7, T9);
+ SET(d, a, b, c, 9, 12, T10);
+ SET(c, d, a, b, 10, 17, T11);
+ SET(b, c, d, a, 11, 22, T12);
+ SET(a, b, c, d, 12, 7, T13);
+ SET(d, a, b, c, 13, 12, T14);
+ SET(c, d, a, b, 14, 17, T15);
+ SET(b, c, d, a, 15, 22, T16);
+#undef SET
+
+ /* Round 2. */
+ /* Let [abcd k s i] denote the operation
+ a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
+#define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
+#define SET(a, b, c, d, k, s, Ti)\
+ t = a + G(b,c,d) + X[k] + Ti;\
+ a = ROTATE_LEFT(t, s) + b
+ /* Do the following 16 operations. */
+ SET(a, b, c, d, 1, 5, T17);
+ SET(d, a, b, c, 6, 9, T18);
+ SET(c, d, a, b, 11, 14, T19);
+ SET(b, c, d, a, 0, 20, T20);
+ SET(a, b, c, d, 5, 5, T21);
+ SET(d, a, b, c, 10, 9, T22);
+ SET(c, d, a, b, 15, 14, T23);
+ SET(b, c, d, a, 4, 20, T24);
+ SET(a, b, c, d, 9, 5, T25);
+ SET(d, a, b, c, 14, 9, T26);
+ SET(c, d, a, b, 3, 14, T27);
+ SET(b, c, d, a, 8, 20, T28);
+ SET(a, b, c, d, 13, 5, T29);
+ SET(d, a, b, c, 2, 9, T30);
+ SET(c, d, a, b, 7, 14, T31);
+ SET(b, c, d, a, 12, 20, T32);
+#undef SET
+
+ /* Round 3. */
+ /* Let [abcd k s t] denote the operation
+ a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define SET(a, b, c, d, k, s, Ti)\
+ t = a + H(b,c,d) + X[k] + Ti;\
+ a = ROTATE_LEFT(t, s) + b
+ /* Do the following 16 operations. */
+ SET(a, b, c, d, 5, 4, T33);
+ SET(d, a, b, c, 8, 11, T34);
+ SET(c, d, a, b, 11, 16, T35);
+ SET(b, c, d, a, 14, 23, T36);
+ SET(a, b, c, d, 1, 4, T37);
+ SET(d, a, b, c, 4, 11, T38);
+ SET(c, d, a, b, 7, 16, T39);
+ SET(b, c, d, a, 10, 23, T40);
+ SET(a, b, c, d, 13, 4, T41);
+ SET(d, a, b, c, 0, 11, T42);
+ SET(c, d, a, b, 3, 16, T43);
+ SET(b, c, d, a, 6, 23, T44);
+ SET(a, b, c, d, 9, 4, T45);
+ SET(d, a, b, c, 12, 11, T46);
+ SET(c, d, a, b, 15, 16, T47);
+ SET(b, c, d, a, 2, 23, T48);
+#undef SET
+
+ /* Round 4. */
+ /* Let [abcd k s t] denote the operation
+ a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
+#define I(x, y, z) ((y) ^ ((x) | ~(z)))
+#define SET(a, b, c, d, k, s, Ti)\
+ t = a + I(b,c,d) + X[k] + Ti;\
+ a = ROTATE_LEFT(t, s) + b
+ /* Do the following 16 operations. */
+ SET(a, b, c, d, 0, 6, T49);
+ SET(d, a, b, c, 7, 10, T50);
+ SET(c, d, a, b, 14, 15, T51);
+ SET(b, c, d, a, 5, 21, T52);
+ SET(a, b, c, d, 12, 6, T53);
+ SET(d, a, b, c, 3, 10, T54);
+ SET(c, d, a, b, 10, 15, T55);
+ SET(b, c, d, a, 1, 21, T56);
+ SET(a, b, c, d, 8, 6, T57);
+ SET(d, a, b, c, 15, 10, T58);
+ SET(c, d, a, b, 6, 15, T59);
+ SET(b, c, d, a, 13, 21, T60);
+ SET(a, b, c, d, 4, 6, T61);
+ SET(d, a, b, c, 11, 10, T62);
+ SET(c, d, a, b, 2, 15, T63);
+ SET(b, c, d, a, 9, 21, T64);
+#undef SET
+
+ /* Then perform the following additions. (That is increment each
+ of the four registers by the value it had before this block
+ was started.) */
+ pms->abcd[0] += a;
+ pms->abcd[1] += b;
+ pms->abcd[2] += c;
+ pms->abcd[3] += d;
+}
+
+MD5_STATIC void
+md5_init(md5_state_t *pms)
+{
+ pms->count[0] = pms->count[1] = 0;
+ pms->abcd[0] = 0x67452301;
+ pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476;
+ pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301;
+ pms->abcd[3] = 0x10325476;
+}
+
+MD5_STATIC void
+md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
+{
+ const md5_byte_t *p = data;
+ int left = nbytes;
+ int offset = (pms->count[0] >> 3) & 63;
+ md5_word_t nbits = (md5_word_t)(nbytes << 3);
+
+ if (nbytes <= 0)
+ return;
+
+ /* Update the message length. */
+ pms->count[1] += nbytes >> 29;
+ pms->count[0] += nbits;
+ if (pms->count[0] < nbits)
+ pms->count[1]++;
+
+ /* Process an initial partial block. */
+ if (offset) {
+ int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
+
+ memcpy(pms->buf + offset, p, copy);
+ if (offset + copy < 64)
+ return;
+ p += copy;
+ left -= copy;
+ md5_process(pms, pms->buf);
+ }
+
+ /* Process full blocks. */
+ for (; left >= 64; p += 64, left -= 64)
+ md5_process(pms, p);
+
+ /* Process a final partial block. */
+ if (left)
+ memcpy(pms->buf, p, left);
+}
+
+MD5_STATIC void
+md5_finish(md5_state_t *pms, md5_byte_t digest[16])
+{
+ static const md5_byte_t pad[64] = {
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+ md5_byte_t data[8];
+ int i;
+
+ /* Save the length before padding. */
+ for (i = 0; i < 8; ++i)
+ data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
+ /* Pad to 56 bytes mod 64. */
+ md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
+ /* Append the length. */
+ md5_append(pms, data, 8);
+ for (i = 0; i < 16; ++i)
+ digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery_configured/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/discovery_configured/CMakeLists.txt b/remote_services/discovery_configured/CMakeLists.txt
index b9f849d..e0f3e9b 100644
--- a/remote_services/discovery_configured/CMakeLists.txt
+++ b/remote_services/discovery_configured/CMakeLists.txt
@@ -19,39 +19,19 @@ if (RSA_DISCOVERY_CONFIGURED)
find_package(CURL REQUIRED)
find_package(LibXml2 REQUIRED)
- include_directories("${CURL_INCLUDE_DIR}")
- include_directories("${LIBXML2_INCLUDE_DIR}")
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/discovery/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/discovery_configured/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
- include_directories(private/include)
-
add_bundle(discovery_configured
- VERSION 0.9.0
- SYMBOLIC_NAME "apache_celix_rsa_discovery_configured"
- NAME "Apache Celix RSA Configured Discovery"
- SOURCES
-
- private/src/discovery_impl.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/discovery_activator.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/discovery.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_descriptor_reader.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_descriptor_writer.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_discovery_poller.c
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_discovery_server.c
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
- ${PROJECT_SOURCE_DIR}/remote_services/utils/private/src/civetweb.c
+ VERSION 0.9.0
+ SYMBOLIC_NAME "apache_celix_rsa_discovery_configured"
+ NAME "Apache Celix RSA Configured Discovery"
+ SOURCES
+ src/discovery_impl.c
)
- target_link_libraries(discovery_configured PRIVATE Celix::log_helper)
+ target_include_directories(discovery_configured PRIVATE src)
+ target_link_libraries(discovery_configured PRIVATE ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} Celix::log_helper discovery_common)
install_bundle(discovery_configured)
- target_link_libraries(discovery_configured PRIVATE ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES})
+
if (RSA_ENDPOINT_TEST_READER)
add_executable(descparser
[33/54] [abbrv] celix git commit: Merge commit
'ee29b00d7a80af43d351e61916d5a5aa90f97e46' into
feature/CELIX-417-cmake-refactor
Posted by pn...@apache.org.
Merge commit 'ee29b00d7a80af43d351e61916d5a5aa90f97e46' into feature/CELIX-417-cmake-refactor
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/ac0d0d77
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/ac0d0d77
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/ac0d0d77
Branch: refs/heads/develop
Commit: ac0d0d7712fe30420da22f828efe7fc8287da498
Parents: 5ecaa64 ee29b00
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Thu Jan 18 18:04:41 2018 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Thu Jan 18 18:04:41 2018 +0100
----------------------------------------------------------------------
CMakeLists.txt | 11 +-
KEYS | 59 +++++
NOTICE | 2 +-
RELEASE_NOTES | 39 ++-
cmake/CMakeCelix-local.cmake | 31 ---
cmake/CMakeCelix.cmake | 31 +++
cmake/cmake_celix/BundlePackaging.cmake | 88 +++++--
cmake/cmake_celix/DeployPackaging.cmake | 137 +++++++----
cmake/cmake_celix/DockerPackaging.cmake | 236 ++++++++++---------
cmake/cmake_celix/Runtimes.cmake | 17 ++
cmake/cmake_celix/create_target_filesystem.sh | 3 +-
dependency_manager/src/dm_component_impl.c | 67 +++---
dfi/CMakeLists.txt | 40 ++--
documents/cmake_commands/readme.md | 135 +++++------
etcdlib/CMakeLists.txt | 3 +-
examples/dm_example/CMakeLists.txt | 44 ++--
.../dm_example/phase1/src/phase1_activator.c | 1 +
examples/dm_example/phase1/src/phase1_cmp.c | 11 +
examples/dm_example/phase1/src/phase1_cmp.h | 3 +-
examples/dm_example_cxx/CMakeLists.txt | 42 ++--
examples/log_service_example/CMakeLists.txt | 2 +-
framework/include/celix_launcher.h | 2 +
framework/src/celix_launcher.c | 77 +++++-
pubsub/examples/keys/publisher/private/.gitkeep | 14 ++
pubsub/examples/keys/publisher/public/.gitkeep | 16 ++
.../examples/keys/subscriber/private/.gitkeep | 16 ++
pubsub/examples/keys/subscriber/public/.gitkeep | 16 ++
.../pubsub/msg_descriptors/poi1.properties | 17 ++
.../pubsub/msg_descriptors/poi2.properties | 17 ++
.../pubsub_admin_udp_mc/src/topic_publication.c | 11 +-
.../private/src/topic_publication.c | 9 +-
.../private/src/topic_subscription.c | 4 +-
.../public/include/pubsub_admin_match.h | 21 +-
.../public/src/pubsub_admin_match.c | 31 ++-
shell/CMakeLists.txt | 2 +-
utils/include/properties.h | 2 +
utils/src/properties.c | 28 +++
37 files changed, 856 insertions(+), 429 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/CMakeLists.txt
----------------------------------------------------------------------
diff --cc CMakeLists.txt
index 9697da9,2fbf62d..d05ec8a
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@@ -21,10 -21,24 +21,10 @@@ cmake_policy(SET CMP0042 NEW
project (Celix C CXX)
- include(GNUInstallDirs)
+ include(GNUInstallDirs)
+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
- set(CMAKE_BUILD_TYPE "Debug")
-#Setup vars conform the FindCelix setup, so that examples and supporting cmake command can assume these variables are set
-set(CELIX_FOUND true)
-set(CELIX_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/framework/public/include ${CMAKE_SOURCE_DIR}/utils/public/include)
-set(CELIX_LIBRARIES celix_framework celix_utils celix_dfi)
-set(CELIX_LAUNCHER celix)
-set(CELIX_FRAMEWORK_LIBRARY celix_framework)
-set(CELIX_UTILS_LIBRARY celix_utils)
-set(CELIX_DFI_LIBRARY celix_dfi)
-set(CELIX_DM_LIB dependency_manager_so)
-set(CELIX_DM_STATIC_LIB dependency_manager_static)
-set(CELIX_DM_STATIC_CXX_LIB dependency_manager_cxx_static)
-set(CELIX_PROJECT true) #Note this var is not set by FindCelix and can be used to test if this is the celix project or a project using celix
-
-set(CMAKE_BUILD_TYPE "Debug")
# see https://public.kitware.com/Bug/view.php?id=15696
IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} EQUAL 3.3 AND ${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
@@@ -73,13 -86,11 +72,13 @@@ set(DEFAULT_VERSION 1.0.0
add_subdirectory(utils)
add_subdirectory(dfi)
add_subdirectory(etcdlib)
+
add_subdirectory(framework)
- include_directories(framework/public/include)
-include_directories(framework/public/include)
+#launcher
add_subdirectory(launcher)
+
+#Bundles
add_subdirectory(config_admin)
add_subdirectory(device_access)
add_subdirectory(deployment_admin)
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/cmake/CMakeCelix.cmake
----------------------------------------------------------------------
diff --cc cmake/CMakeCelix.cmake
index 0000000,8c14577..f67648b
mode 000000,100644..100644
--- a/cmake/CMakeCelix.cmake
+++ b/cmake/CMakeCelix.cmake
@@@ -1,0 -1,32 +1,31 @@@
+ # 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.
+
-
+ set(CELIX_CMAKE_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
+
-if (ANDROID)
- add_definitions( -DANDROID )
-endif ()
-
+ include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/Dependencies.cmake)
-include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/BundlePackaging.cmake)
-include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/DeployPackaging.cmake)
-include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/DockerPackaging.cmake)
-include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/Runtimes.cmake)
+ include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/ApacheRat.cmake)
+ include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/CodeCoverage.cmake)
+ include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/BuildOptions.cmake)
++
++include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/UseCelix.cmake)
++
++#UseCelix includes:
++#include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/BundlePackaging.cmake)
++#include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/DeployPackaging.cmake)
++#include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/DockerPackaging.cmake)
++#include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/Runtimes.cmake)
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/cmake/cmake_celix/BundlePackaging.cmake
----------------------------------------------------------------------
diff --cc cmake/cmake_celix/BundlePackaging.cmake
index 205bec1,f3adde3..8e1755c
--- a/cmake/cmake_celix/BundlePackaging.cmake
+++ b/cmake/cmake_celix/BundlePackaging.cmake
@@@ -88,13 -88,16 +88,17 @@@ function(check_bundle BUNDLE
endif()
endfunction()
+
function(add_bundle)
+ #message(DEPRECATION"add_bundle is DEPRECATION, use add_celix_bundle instead.")
+ add_celix_bundle(${ARGN})
+ endfunction()
+ function(add_celix_bundle)
list(GET ARGN 0 BUNDLE_TARGET_NAME)
list(REMOVE_AT ARGN 0)
set(OPTIONS NO_ACTIVATOR)
- set(ONE_VAL_ARGS VERSION ACTIVATOR SYMBOLIC_NAME NAME DESCRIPTION FILENAME)
- set(ONE_VAL_ARGS VERSION ACTIVATOR SYMBOLIC_NAME NAME DESCRIPTION)
++ set(ONE_VAL_ARGS VERSION ACTIVATOR SYMBOLIC_NAME NAME DESCRIPTION FILE_NAME)
set(MULTI_VAL_ARGS SOURCES PRIVATE_LIBRARIES EXPORT_LIBRARIES IMPORT_LIBRARIES HEADERS)
cmake_parse_arguments(BUNDLE "${OPTIONS}" "${ONE_VAL_ARGS}" "${MULTI_VAL_ARGS}" ${ARGN})
@@@ -143,22 -143,14 +147,22 @@@
#create lib from sources
add_library(${BUNDLE_TARGET_NAME} SHARED ${BUNDLE_SOURCES})
set_library_version(${BUNDLE_TARGET_NAME} ${BUNDLE_VERSION})
- set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_TARGET_IS_LIB" TRUE)
+ set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES
+ "BUNDLE_TARGET_IS_LIB" TRUE
+ "BUNDLE_TARGET" "${BUNDLE_TARGET_NAME}_bundle"
+ )
+ target_link_libraries(${BUNDLE_TARGET_NAME} PRIVATE Celix::framework)
else()
add_custom_target(${BUNDLE_TARGET_NAME})
+ set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES
+ "BUNDLE_TARGET_IS_LIB" FALSE
+ "BUNDLE_TARGET" "${BUNDLE_TARGET_NAME}_bundle"
+ )
endif()
add_custom_target(${BUNDLE_TARGET_NAME}_bundle
- DEPENDS "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_FILE>"
+ DEPENDS ${BUNDLE_TARGET_NAME} "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_FILE>"
)
- add_dependencies(bundles ${BUNDLE_TARGET_NAME}_bundle)
+ add_dependencies(celix-bundles ${BUNDLE_TARGET_NAME}_bundle)
#######################################################################
@@@ -211,18 -203,14 +215,19 @@@
#############################
### BUNDLE TARGET PROPERTIES
#############################
+ #alreadyer set
+ # BUNDLE_TARGET_IS_LIB -> true (can be use to test if target is bundle target
+ # BUNDLE_TARGET -> refers to the _bundle target which is responsible for building the zip file
#internal use
+ set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_IS_BUNDLE_TARGET" TRUE) #indicate that this is a bundle target
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_DEPEND_TARGETS" "") #bundle target dependencies. Note can be extended after the add_bundle call
-- set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_GEN_DIR" ${BUNDLE_GEN_DIR}) #location for generated output.
++ set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_GEN_DIR" ${BUNDLE_GEN_DIR}) #location for generated output.
++ set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_CREATE_BUNDLE_TARGET" ${BUNDLE_TARGET_NAME}_bundle)
#bundle specific
- set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_CONTENT_DIR" ${BUNDLE_CONTENT_DIR}) #location where the content to be jar/zipped.
- set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_FILE" ${BUNDLE_FILE}) #target bundle file (.zip)
- set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_FILE_NAME" ${BUNDLE_FILE_NAME}) #target bundle file (.zip)
+ set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_CONTENT_DIR" ${BUNDLE_CONTENT_DIR}) #location where the content to be jar/zipped.
+ set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_FILENAME" ${BUNDLE_FILENAME}) #target bundle filename (.zip)
+ set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_FILE" ${BUNDLE_FILE}) #target bundle abs file path (.zip)
#name and version
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_NAME" ${BUNDLE_NAME}) #The bundle name default target name
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/cmake/cmake_celix/DeployPackaging.cmake
----------------------------------------------------------------------
diff --cc cmake/cmake_celix/DeployPackaging.cmake
index dfef9dd,26f5c90..2065b47
--- a/cmake/cmake_celix/DeployPackaging.cmake
+++ b/cmake/cmake_celix/DeployPackaging.cmake
@@@ -28,9 -28,10 +28,9 @@@ set_directory_properties(PROPERTIES ADD
#####
function(add_deploy)
- #message(DEPRECATION "add_deploy is depecrated, use add_celix_container instead.")
++ #message(DEPRECATION "deploy_bundles_dir is depecrated, use celix_container_bundles_dir instead.")
add_celix_container(${ARGN})
endfunction()
--
function(add_celix_container)
list(GET ARGN 0 CONTAINER_TARGET)
list(REMOVE_AT ARGN 0)
@@@ -59,55 -60,77 +59,64 @@@
endif ()
######
- get_target_property(CONTAINERDEPS containers "CONTAINER_DEPLOYMENTS")
++ #add this target as depependency to the celix-containers target
+ get_target_property(CONTAINERDEPS celix-containers "CONTAINER_DEPLOYMENTS")
list(APPEND CONTAINERDEPS ${CONTAINER_TARGET})
- set_target_properties(containers PROPERTIES "CONTAINER_DEPLOYMENTS" "${CONTAINERDEPS}")
+ set_target_properties(celix-containers PROPERTIES "CONTAINER_DEPLOYMENTS" "${CONTAINERDEPS}")
#FILE TARGETS FOR CONTAINER
set(CONTAINER_PROPS "${CONTAINER_LOC}/config.properties")
set(CONTAINER_ECLIPSE_LAUNCHER "${CONTAINER_LOC}/${CONTAINER_NAME}.launch")
-- if (CONTAINER_LAUNCHER_SRC)
- get_filename_component(SRC_FILENAME ${LAUNCHER_SRC} NAME)
- get_filename_component(SRC_FILENAME ${CONTAINER_LAUNCHER_SRC} NAME)
-- set(LAUNCHER_SRC "${PROJECT_BINARY_DIR}/celix/gen/${CONTAINER_TARGET}-${SRC_FILENAME}")
-- set(LAUNCHER_ORG "${CONTAINER_LAUNCHER_SRC}")
-- elseif (CONTAINER_CXX)
-- set(LAUNCHER_SRC "${PROJECT_BINARY_DIR}/celix/gen/${CONTAINER_TARGET}-main.cc")
-- set(LAUNCHER_ORG "${CELIX_CMAKE_DIRECTORY}/cmake_celix/main.c.in")
-- else()
-- set(LAUNCHER_SRC "${PROJECT_BINARY_DIR}/celix/gen/${CONTAINER_TARGET}-main.c")
-- set(LAUNCHER_ORG "${CELIX_CMAKE_DIRECTORY}/cmake_celix/main.c.in")
-- endif()
--
++ set(LAUNCHER_DEP )
if (CONTAINER_LAUNCHER)
if (IS_ABSOLUTE "${CONTAINER_LAUNCHER}")
set(LAUNCHER "${CONTAINER_LAUNCHER}")
else()
#assuming target
set(LAUNCHER "$<TARGET_FILE:${CONTAINER_LAUNCHER}>")
++ set(LAUNCHER_DEP ${CONTAINER_LAUNCHER})
endif()
-- add_custom_target(${CONTAINER_TARGET}
-- COMMAND ${CMAKE_COMMAND} -E create_symlink ${LAUNCHER} ${CONTAINER_LOC}/${CONTAINER_TARGET}
- DEPENDS "$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_TARGET_DEPS>"
- COMMENT "Deploying ${CONTAINER_PRINT_NAME} Celix container" VERBATIM
-- )
-- else ()
-- add_custom_command(OUTPUT ${LAUNCHER_SRC}
-- COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/celix/gen
- COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LAUNCHER_ORG} ${LAUNCHER_SRC}
- DEPENDS "$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_TARGET_DEPS>"
- COMMENT "Deploying ${CONTAINER_PRINT_NAME} Celix container" VERBATIM
- )
-
++ elseif (CONTAINER_LAUNCHER_SRC)
++ get_filename_component(SRC_FILENAME ${CONTAINER_LAUNCHER_SRC} NAME)
++ set(LAUNCHER_SRC "${PROJECT_BINARY_DIR}/celix/gen/${CONTAINER_TARGET}-${SRC_FILENAME}")
++ set(LAUNCHER_ORG "${CONTAINER_LAUNCHER_SRC}")
++ else () #generate custom launcher
+ if (CONTAINER_CXX)
- set(STAGE1_LAUNCHER "${CMAKE_CURRENT_BINARY_DIR}/${CONTAINER_TARGET}-main-stage1.cc")
++ set(LAUNCHER_SRC "${PROJECT_BINARY_DIR}/celix/gen/${CONTAINER_TARGET}-main.cc")
+ else()
- set(STAGE1_LAUNCHER "${CMAKE_CURRENT_BINARY_DIR}/${CONTAINER_TARGET}-main-stage1.c")
++ set(LAUNCHER_SRC "${PROJECT_BINARY_DIR}/celix/gen/${CONTAINER_TARGET}-main.c")
+ endif()
+
+ file(GENERATE
- OUTPUT "${STAGE1_LAUNCHER}"
++ OUTPUT "${LAUNCHER_SRC}"
+ CONTENT "#include <celix_launcher.h>
-
+ int main(int argc, char *argv[]) {
- const char * config = \"cosgi.auto.start.1=$<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_BUNDLES>, >\\n\\
++ const char * config = \"\\
+ $<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_EMBEDDED_PROPERTIES>,\\n\\
+ >\";
+
+ properties_pt packedConfig = properties_loadFromString(config);
-
+ return celixLauncher_launchWithArgsAndProps(argc, argv, packedConfig);
+ }
+ "
)
++ endif ()
- file(GENERATE
- OUTPUT "${LAUNCHER_SRC}"
- INPUT "${STAGE1_LAUNCHER}"
- )
-
-- include_directories(${CELIX_INCLUDE_DIRS})
++ if (LAUNCHER_SRC) #compilation needed
add_executable(${CONTAINER_TARGET} ${LAUNCHER_SRC})
set_target_properties(${CONTAINER_TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CONTAINER_LOC})
- target_link_libraries(${CONTAINER_TARGET} PRIVATE ${CELIX_FRAMEWORK_LIBRARY} ${CELIX_UTILS_LIBRARY})
+ target_link_libraries(${CONTAINER_TARGET} PRIVATE Celix::framework)
set(LAUNCHER "$<TARGET_FILE:${CONTAINER_TARGET}>")
++ else ()
++ #LAUNCHER already set
++ add_custom_target(${CONTAINER_TARGET}
++ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LAUNCHER} ${CONTAINER_LOC}/${CONTAINER_TARGET}
++ )
endif ()
#generate config.properties
-- set(STAGE1_PROPERTIES "${CMAKE_CURRENT_BINARY_DIR}/${CONTAINER_TARGET}-container-config-stage1.properties")
++ set(STAGE1_PROPERTIES "${PROJECT_BINARY_DIR}/celix/gen/${CONTAINER_TARGET}-container-config-stage1.properties")
file(GENERATE
OUTPUT "${STAGE1_PROPERTIES}"
CONTENT "cosgi.auto.start.1=$<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_BUNDLES>, >
@@@ -133,20 -156,26 +142,21 @@@ $<JOIN:$<TARGET_PROPERTY:${CONTAINER_TA
get_filename_component(CELIX_BIN_DIR ${CELIX_LAUNCHER} DIRECTORY)
endif()
- if (CONTAINER_COPY)
- add_custom_target(${CONTAINER_TARGET}-deps
- DEPENDS $<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_DEPS>
- )
- add_dependencies(${CONTAINER_TARGET} ${CONTAINER_TARGET}-deps)
- endif ()
--
#generate release.sh and optional run.sh
if(APPLE)
set(LIB_PATH_NAME "DYLD_LIBRARY_PATH")
else()
set(LIB_PATH_NAME "LD_LIBRARY_PATH")
endif()
++
set(RELEASE_SH ${CONTAINER_LOC}/release.sh)
-- set(RUN_SH ${CONTAINER_LOC}/run.sh)
set(RELEASE_CONTENT "#!/bin/sh\nexport ${LIB_PATH_NAME}=${CELIX_LIB_DIRS}:\${${LIB_PATH_NAME}}\nexport PATH=${CELIX_BIN_DIR}:\${PATH}")
file(GENERATE
OUTPUT ${RELEASE_SH}
CONTENT ${RELEASE_CONTENT}
)
++
++ set(RUN_SH ${CONTAINER_LOC}/run.sh)
set(RUN_CONTENT "${RELEASE_CONTENT}\n${LAUNCHER} \$@\n")
file(GENERATE
OUTPUT ${RUN_SH}
@@@ -163,11 -192,11 +173,23 @@@
CONTENT "${RUN_CONFIG_IN}"
)
++ #add a custom target which can depend on generation expressions
++ add_custom_target(${CONTAINER_TARGET}-deps
++ DEPENDS
++ ${RUN_SH}
++ ${CONTAINER_ECLIPSE_LAUNCHER}
++ ${RELEASE_SH}
++ ${CONTAINER_PROPS}
++ $<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_TARGET_DEPS>
++ )
++ add_dependencies(${CONTAINER_TARGET} ${CONTAINER_TARGET}-deps)
++
++
##### Container Target Properties #####
#internal use
+ set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_TARGET_DEPS" "") #target deps for the container.
set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_BUNDLES" "") #bundles to deploy fro the container.
set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_COPY_BUNDLES" ${CONTAINER_COPY}) #copy bundles in bundle dir or link using abs paths. NOTE this cannot be changed after a add_deploy command
- set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_DEPS" "") #target deps for copy of bundles
#deploy specific
set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_NAME" "${CONTAINER_NAME}")
@@@ -188,8 -219,9 +212,8 @@@ endfunction(
#NOTE can be used for drivers/proxies/endpoints bundle dirs
--
function(deploy_bundles_dir)
+ #message(DEPRECATION "deploy_bundles_dir is depecrated, use celix_container_bundles_dir instead.")
celix_container_bundles_dir(${ARGN})
endfunction()
function(celix_container_bundles_dir)
@@@ -218,24 -250,18 +242,21 @@@
DEPENDS ${BUNDLE}
)
else()
- #assuming target
- get_target_property(BFN ${BUNDLE} BUNDLE_FILE_NAME) #would prefer to used target generator, but this is not supporte in a OUTPUT argument
- set(OUT "${CONTAINER_LOC}/${BD_DIR_NAME}/${BFN}")
+ string(MAKE_C_IDENTIFIER ${BUNDLE} BUNDLE_ID) #Create id with no special chars (e.g. for target like Celix::shell)
+ set(OUT "${CMAKE_BINARY_DIR}/celix/gen/${CONTAINER_TARGET}-copy-bundle-for-target-${BUNDLE_ID}.timestamp")
+ set(DEST "${CONTAINER_LOC}/${BD_DIR_NAME}/$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
add_custom_command(OUTPUT ${OUT}
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILE>" ${OUT}
- COMMENT "Copying bundle '${BFN}' to '${CONTAINER_LOC}/${BD_DIR_NAME}'"
- DEPENDS ${BUNDLE} ${BUNDLE}_bundle
+ COMMAND ${CMAKE_COMMAND} -E touch ${OUT}
++ COMMAND ${CMAKE_COMMAND} -E make_directory ${CONTAINER_LOC}/${BD_DIR_NAME}
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILE>" ${DEST}
+ COMMENT "Copying bundle '${BUNDLE}' to '${CONTAINER_LOC}/${BD_DIR_NAME}'"
- DEPENDS $<TARGET_PROPERTY:${BUNDLE},BUNDLE_BUILD_BUNDLE_TARGET>
++ DEPENDS ${BUNDLE} $<TARGET_PROPERTY:${BUNDLE},BUNDLE_CREATE_BUNDLE_TARGET>
)
- get_target_property(BUILD_BUNDLE_TARGET ${BUNDLE} BUNDLE_TARGET)
- add_dependencies(${CONTAINER_TARGET} ${BUILD_BUNDLE_TARGET}) #ensure the the deploy depends on the _bundle target, custom_command depends on add_library
-
endif()
list(APPEND DEPS "${OUT}")
-
endforeach()
- set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_DEPS" "${DEPS}")
+
+ set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_TARGET_DEPS" "${DEPS}")
endfunction()
function(deploy_bundles)
@@@ -249,28 -276,30 +271,40 @@@ function(celix_container_bundles
get_target_property(BUNDLES ${CONTAINER_TARGET} "CONTAINER_BUNDLES")
get_target_property(COPY ${CONTAINER_TARGET} "CONTAINER_COPY_BUNDLES")
++ get_target_property(DEPS ${CONTAINER_TARGET} "CONTAINER_TARGET_DEPS")
foreach(BUNDLE IN ITEMS ${ARGN})
+ if (IS_ABSOLUTE ${BUNDLE} AND EXISTS ${BUNDLE})
+ get_filename_component(BUNDLE_FILENAME ${BUNDLE} NAME)
+ set(COPY_LOC "bundles/${BUNDLE_FILENAME}")
+ set(ABS_LOC "${BUNDLE}")
+ else () #assume target (could be a future target -> if (TARGET ...) not possible
+ set(COPY_LOC "bundles/$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
+ set(ABS_LOC "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILE>")
++
++ if (NOT COPY) #in case of COPY dep will be added in celix_container_bundles_dir
++ string(MAKE_C_IDENTIFIER ${BUNDLE} BUNDLE_ID) #Create id with no special chars (e.g. for target like Celix::shell)
++ set(OUT "${CMAKE_BINARY_DIR}/celix/gen/${CONTAINER_TARGET}-check-bundle-for-target-${BUNDLE_ID}.timestamp")
++ add_custom_command(OUTPUT ${OUT}
++ COMMAND ${CMAKE_COMMAND} -E touch ${OUT}
++ DEPENDS ${BUNDLE} $<TARGET_PROPERTY:${BUNDLE},BUNDLE_CREATE_BUNDLE_TARGET>
++ )
++ list(APPEND DEPS ${OUT})
++ endif ()
+ endif ()
if(COPY)
- if(IS_ABSOLUTE ${BUNDLE} AND EXISTS ${BUNDLE})
- get_filename_component(BUNDLE_FILENAME ${BUNDLE} NAME)
- list(APPEND BUNDLES "bundles/${BUNDLE_FILENAME}")
- else() #assuming target
- get_target_property(BFN ${BUNDLE} BUNDLE_FILE_NAME)
- list(APPEND BUNDLES "bundles/${BFN}")
- endif()
+ list(APPEND BUNDLES ${COPY_LOC})
else()
- if(IS_ABSOLUTE ${BUNDLE} AND EXISTS ${BUNDLE})
- list(APPEND BUNDLES ${BUNDLE})
- else() #assuming target
- list(APPEND BUNDLES "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILE>")
- endif()
+ list(APPEND BUNDLES ${ABS_LOC})
endif()
endforeach()
++ set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_BUNDLES" "${BUNDLES}")
++ set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_TARGET_DEPS" "${DEPS}")
++
if(COPY)
celix_container_bundles_dir(${CONTAINER_TARGET} DIR_NAME bundles BUNDLES ${ARGN})
endif()
--
-- set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_BUNDLES" "${BUNDLES}")
endfunction()
function(deploy_properties)
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/cmake/cmake_celix/DockerPackaging.cmake
----------------------------------------------------------------------
diff --cc cmake/cmake_celix/DockerPackaging.cmake
index b85da11,e0ffe5e..cb1442c
--- a/cmake/cmake_celix/DockerPackaging.cmake
+++ b/cmake/cmake_celix/DockerPackaging.cmake
@@@ -109,14 -75,75 +75,64 @@@ function(add_celix_docker
list(APPEND CLEANFILES "$<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_LOC>")
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CLEANFILES}")
- ###### Setup docker custom target timestamp
- set(TIMESTAMP_FILE "${CMAKE_CURRENT_BINARY_DIR}/${DOCKER_TARGET}-docker-timestamp")
+ if (DOCKER_LAUNCHER_SRC)
+ get_filename_component(SRC_FILENAME ${DOCKER_LAUNCHER_SRC} NAME)
+ set(LAUNCHER_SRC "${PROJECT_BINARY_DIR}/celix/gen/${DOCKER_TARGET}-${SRC_FILENAME}")
+ set(LAUNCHER_ORG "${DOCKER_LAUNCHER_SRC}")
+ elseif (DOCKER_CXX)
+ set(LAUNCHER_SRC "${PROJECT_BINARY_DIR}/celix/gen/${DOCKER_TARGET}-main.cc")
+ set(LAUNCHER_ORG "${CELIX_CMAKE_DIRECTORY}/cmake_celix/main.c.in")
+ else()
+ set(LAUNCHER_SRC "${PROJECT_BINARY_DIR}/celix/gen/${DOCKER_TARGET}-main.c")
+ set(LAUNCHER_ORG "${CELIX_CMAKE_DIRECTORY}/cmake_celix/main.c.in")
+ endif()
- add_custom_target(${DOCKER_TARGET}
- DEPENDS ${TIMESTAMP_FILE}
- )
+ if (DOCKER_LAUNCHER)
+ add_custom_target(${DOCKER_TARGET})
+ if (IS_ABSOLUTE "${DOCKER_LAUNCHER}")
+ set(LAUNCHER "${DOCKER_LAUNCHER}")
+ get_filename_component(EXE_FILENAME ${DOCKER_LAUNCHER} NAME)
+ set(DOCKER_ENTRYPOINT "ENTRYPOINT [\"/bin/${EXE_FILENAME}\"]")
+ else()
+ #assuming target
+ set(LAUNCHER "$<TARGET_FILE:${DOCKER_LAUNCHER}>")
+ set(DOCKER_ENTRYPOINT "ENTRYPOINT [\"/bin/$<TARGET_FILE_NAME:${DOCKER_TARGET}>\"]")
+ endif()
+ else ()
- add_custom_command(OUTPUT ${LAUNCHER_SRC}
- COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/celix/gen
- )
- set(CELIX_LAUNCHER "$<TARGET_FILE:Celix::launcher>")
+ if (DOCKER_CXX)
- set(LAUNCHER_STAGE1 "${CMAKE_CURRENT_BINARY_DIR}/${DOCKER_TARGET}-docker-main-stage1.cc")
++ set(LAUNCHER_SRC "${CMAKE_CURRENT_BINARY_DIR}/${DOCKER_TARGET}-docker-main.cc")
+ else()
- set(LAUNCHER_STAGE1 "${CMAKE_CURRENT_BINARY_DIR}/${DOCKER_TARGET}-docker-main-stage1.c")
++ set(LAUNCHER_SRC "${CMAKE_CURRENT_BINARY_DIR}/${DOCKER_TARGET}-docker-main.c")
+ endif()
+
+ file(GENERATE
- OUTPUT "${LAUNCHER_STAGE1}"
++ OUTPUT ${LAUNCHER_SRC}
+ CONTENT "#include <celix_launcher.h>
+
+ int main(int argc, char *argv[]) {
- const char * config = \"cosgi.auto.start.1=$<JOIN:$<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_BUNDLES>, >\\n\\
-$<JOIN:$<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_PROPERTIES>,\\n\\
++ const char * config = \"\\
++$<JOIN:$<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_EMBEDDED_PROPERTIES>,\\n\\
+ >\";
+
+ properties_pt packedConfig = properties_loadFromString(config);
-
+ return celixLauncher_launchWithArgsAndProps(argc, argv, packedConfig);
+ }
+ "
+ )
+
- file(GENERATE
- OUTPUT "${LAUNCHER_SRC}"
- INPUT "${LAUNCHER_STAGE1}"
- )
-
- add_executable(${DOCKER_TARGET} ${LAUNCHER_SRC})
- # set_target_properties(${DOCKER_TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${DOCKER_LOC})
- target_include_directories(${DOCKER_TARGET} PRIVATE ${CELIX_INCLUDE_DIRS})
- target_link_libraries(${DOCKER_TARGET} PRIVATE ${CELIX_FRAMEWORK_LIBRARY} ${CELIX_UTILS_LIBRARY})
++ add_executable(${DOCKER_TARGET} EXCLUDE_FROM_ALL ${LAUNCHER_SRC})
++ target_link_libraries(${DOCKER_TARGET} PRIVATE Celix::framework)
+ set(LAUNCHER "$<TARGET_FILE:${DOCKER_TARGET}>")
+ set(DOCKER_ENTRYPOINT "ENTRYPOINT [\"/bin/$<TARGET_FILE_NAME:${DOCKER_TARGET}>\"]")
+ endif ()
+
+
+ ###### Setup docker custom target timestamp
+ add_custom_target(${DOCKER_TARGET}-deps
+ DEPENDS ${FS_TIMESTAMP_FILE} $<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_DEPS>
+ )
+ add_dependencies(${DOCKER_TARGET} ${DOCKER_TARGET}-deps)
#setup dependencies based on timestamp
if (DOCKER_CREATE_FS)
@@@ -149,8 -173,9 +162,10 @@@
set_target_properties(${DOCKER_TARGET} PROPERTIES "DOCKER_CREATE_FS" "${DOCKER_CREATE_FS}") #wether to create a fs with the minimal needed libraries / etc files
set_target_properties(${DOCKER_TARGET} PROPERTIES "DOCKER_INSTRUCTIONS" "") #list of additional instructions
set_target_properties(${DOCKER_TARGET} PROPERTIES "DOCKER_PROPERTIES" "")
++ set_target_properties(${DOCKER_TARGET} PROPERTIES "DOCKER_EMBEDDED_PROPERTIES" "")
set_target_properties(${DOCKER_TARGET} PROPERTIES "DOCKER_DEPS" "")
+ set(DOCKERFILE_STAGE1 ${CMAKE_BINARY_DIR}/celix/gen/${DOCKER_TARGET}-Dockerfile.in)
set(DOCKERFILE "$<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_LOC>/Dockerfile")
file(GENERATE
@@@ -227,23 -246,22 +236,25 @@@ function(celix_docker_bundles
foreach(BUNDLE IN ITEMS ${ARGN})
if(IS_ABSOLUTE ${BUNDLE} AND EXISTS ${BUNDLE})
get_filename_component(BUNDLE_FILENAME ${BUNDLE} NAME)
-- list(APPEND BUNDLES "${BUNDLES_DIR}/${BUNDLE_FILENAME}")
set(OUT "${LOC}/${BUNDLES_DIR}/${BUNDLE_FILENAME}")
add_custom_command(OUTPUT ${OUT}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${BUNDLE} ${OUT}
-- COMMENT "Copying bundle '${BUNDLE}' to '${OUT}'"
++ COMMENT "Copying bundle '${BUNDLE}' to '${LOC}/${BUNDLES_DIR}'"
DEPENDS ${BUNDLE}
)
++ list(APPEND BUNDLES "${BUNDLES_DIR}/${BUNDLE_FILENAME}")
else() #assuming target
- list(APPEND BUNDLES "${BUNDLES_DIR}/${BUNDLE}.zip")
- set(OUT ${LOC}/${BUNDLES_DIR}/${BUNDLE}.zip)
- get_target_property(BFN ${BUNDLE} BUNDLE_FILE_NAME)
- list(APPEND BUNDLES "${BUNDLES_DIR}/${BFN}")
- set(OUT ${LOC}/${BUNDLES_DIR}/${BFN})
++ string(MAKE_C_IDENTIFIER ${BUNDLE} BUNDLE_ID) #Create id with no special chars (e.g. for target like Celix::shell)
++ set(OUT "${CMAKE_BINARY_DIR}/celix/gen/${DOCKER_TARGET}-copy-bundle-for-target-${BUNDLE_ID}.timestamp")
++ set(DEST "${LOC}/${BUNDLES_DIR}/$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
add_custom_command(OUTPUT ${OUT}
-- COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILE>" "${OUT}"
-- COMMENT "Copying bundle '${BUNDLE}' to '${OUT}'"
- DEPENDS ${BUNDLE}
- DEPENDS ${BUNDLE} ${BUNDLE}_bundle
++ COMMAND ${CMAKE_COMMAND} -E touch ${OUT}
++ COMMAND ${CMAKE_COMMAND} -E make_directory ${LOC}/${BUNDLES_DIR}
++ COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILE>" ${DEST}
++ COMMENT "Copying bundle '${BUNDLE}' to '${LOC}/${BUNDLES_DIR}'"
++ DEPENDS ${BUNDLE} $<TARGET_PROPERTY:${BUNDLE},BUNDLE_CREATE_BUNDLE_TARGET>
)
- get_target_property(BUILD_BUNDLE_TARGET ${BUNDLE} BUNDLE_BUILD_BUNDLE_TARGET)
- add_dependencies(${DOCKER_TARGET} ${BUILD_BUNDLE_TARGET}) #ensure the the deploy depends on the _bundle target, custom_command depends on add_library
++ list(APPEND BUNDLES "${BUNDLES_DIR}/$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
endif()
list(APPEND DEPS "${OUT}")
endforeach()
@@@ -271,11 -285,7 +278,22 @@@ function(celix_docker_properties
set_target_properties(${DOCKER_TARGET} PROPERTIES "DOCKER_PROPERTIES" "${PROPS}")
endfunction()
- function(celix_docker_instructions)
- if (NOT ENABLE_DOCKER)
- return()
- endif()
++function(celix_docker_embedded_properties)
++ #0 is docker TARGET
++ #1..n is properties
++ list(GET ARGN 0 DOCKER_TARGET)
++ list(REMOVE_AT ARGN 0)
++
++ get_target_property(PROPS ${DOCKER_TARGET} "DOCKER_EMBEDDED_PROPERTIES")
+
++ foreach(PROP IN ITEMS ${ARGN})
++ list(APPEND PROPS ${PROP})
++ endforeach()
++
++ set_target_properties(${DOCKER_TARGET} PROPERTIES "DOCKER_EMBEDDED_PROPERTIES" "${PROPS}")
++endfunction()
++
+ function(celix_docker_instructions)
#0 is docker TARGET
#1..n is instructions
list(GET ARGN 0 DOCKER_TARGET)
[54/54] [abbrv] celix git commit: Merge branch
'feature/CELIX-417-cmake-refactor' into develop
Posted by pn...@apache.org.
Merge branch 'feature/CELIX-417-cmake-refactor' into develop
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/398da49c
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/398da49c
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/398da49c
Branch: refs/heads/develop
Commit: 398da49c70dbdeb8ec0cfc70de3ebbea2730e39c
Parents: e78ecc5 481e798
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Jan 30 20:38:20 2018 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Jan 30 20:38:20 2018 +0100
----------------------------------------------------------------------
.travis.yml | 6 +-
CMakeLists.txt | 52 +-
cmake/CMakeCelix.cmake | 32 -
cmake/CelixConfig.cmake | 72 +
cmake/CelixConfigVersion.cmake.in | 28 +
cmake/FindCELIX.cmake | 125 -
cmake/FindCUnit.cmake | 65 -
cmake/FindCZMQ.cmake | 42 -
cmake/FindCppUTest.cmake | 54 -
cmake/FindFFI.cmake | 57 -
cmake/FindJansson.cmake | 42 -
cmake/FindSlp.cmake | 42 -
cmake/FindSyslog.cmake | 26 -
cmake/FindUUID.cmake | 37 -
cmake/FindZMQ.cmake | 42 -
cmake/Modules/FindCUnit.cmake | 65 +
cmake/Modules/FindCZMQ.cmake | 42 +
cmake/Modules/FindCppUTest.cmake | 54 +
cmake/Modules/FindFFI.cmake | 57 +
cmake/Modules/FindJansson.cmake | 42 +
cmake/Modules/FindSlp.cmake | 42 +
cmake/Modules/FindSyslog.cmake | 26 +
cmake/Modules/FindUUID.cmake | 37 +
cmake/Modules/FindZMQ.cmake | 42 +
cmake/UseDoxygen.cmake | 170 -
cmake/celix_project/ApacheRat.cmake | 30 +
cmake/celix_project/CelixProject.cmake | 80 +
cmake/celix_project/CodeCoverage.cmake | 126 +
cmake/cmake_celix/ApacheRat.cmake | 30 -
cmake/cmake_celix/BuildOptions.cmake | 24 -
cmake/cmake_celix/BundlePackaging.cmake | 176 +-
cmake/cmake_celix/CodeCoverage.cmake | 126 -
cmake/cmake_celix/Dependencies.cmake | 69 -
cmake/cmake_celix/DeployPackaging.cmake | 184 +-
cmake/cmake_celix/DockerPackaging.cmake | 101 +-
cmake/cmake_celix/Runtimes.cmake | 6 +-
cmake/cmake_celix/UseCelix.cmake | 25 +
cmake/cmake_celix/main.c.in | 24 -
config_admin/CMakeLists.txt | 7 +-
config_admin/config_admin_tst/CMakeLists.txt | 2 +-
.../example_test/CMakeLists.txt | 2 +-
.../example_test2/CMakeLists.txt | 2 +-
config_admin/example/CMakeLists.txt | 2 -
config_admin/service/CMakeLists.txt | 3 -
dependency_manager/CMakeLists.txt | 97 +-
dependency_manager/api/dm_activator.h | 65 +
dependency_manager/api/dm_component.h | 158 +
dependency_manager/api/dm_dependency_manager.h | 79 +
dependency_manager/api/dm_info.h | 81 +
dependency_manager/api/dm_service_dependency.h | 171 +
.../private/include/dm_component_impl.h | 48 -
.../private/include/dm_dependency.h | 41 -
.../include/dm_dependency_manager_impl.h | 45 -
dependency_manager/private/include/dm_event.h | 72 -
.../include/dm_service_dependency_impl.h | 104 -
.../private/include/dm_shell_list_command.h | 42 -
dependency_manager/private/src/dm_activator.c | 119 -
.../private/src/dm_component_impl.c | 1451 ----
.../private/src/dm_dependency_manager_impl.c | 129 -
dependency_manager/private/src/dm_event.c | 105 -
.../private/src/dm_service_dependency.c | 811 --
.../private/src/dm_shell_activator.c | 94 -
.../private/src/dm_shell_list_command.c | 126 -
.../public/include/dm_activator.h | 65 -
.../public/include/dm_component.h | 158 -
.../public/include/dm_dependency_manager.h | 79 -
dependency_manager/public/include/dm_info.h | 81 -
.../public/include/dm_service_dependency.h | 171 -
dependency_manager/readme.md | 18 +-
dependency_manager/src/dm_activator.c | 119 +
dependency_manager/src/dm_component_impl.c | 1451 ++++
dependency_manager/src/dm_component_impl.h | 48 +
dependency_manager/src/dm_dependency.h | 41 +
.../src/dm_dependency_manager_impl.c | 129 +
.../src/dm_dependency_manager_impl.h | 45 +
dependency_manager/src/dm_event.c | 105 +
dependency_manager/src/dm_event.h | 72 +
dependency_manager/src/dm_service_dependency.c | 811 ++
.../src/dm_service_dependency_impl.h | 104 +
dependency_manager/src/dm_shell_activator.c | 94 +
dependency_manager/src/dm_shell_list_command.c | 126 +
dependency_manager/src/dm_shell_list_command.h | 42 +
dependency_manager_cxx/CMakeLists.txt | 48 +-
dependency_manager_cxx/readme.md | 6 +
deployment_admin/CMakeLists.txt | 59 +-
deployment_admin/README.md | 20 +-
deployment_admin/api/resource_processor.h | 54 +
.../private/include/deployment_admin.h | 57 -
.../private/include/deployment_package.h | 76 -
deployment_admin/private/include/ioapi.h | 200 -
deployment_admin/private/include/log.h | 44 -
deployment_admin/private/include/log_event.h | 43 -
deployment_admin/private/include/log_store.h | 45 -
deployment_admin/private/include/log_sync.h | 36 -
deployment_admin/private/include/miniunz.h | 34 -
deployment_admin/private/include/unzip.h | 437 -
deployment_admin/private/src/deployment_admin.c | 809 --
.../private/src/deployment_admin_activator.c | 78 -
.../private/src/deployment_package.c | 219 -
deployment_admin/private/src/ioapi.c | 235 -
deployment_admin/private/src/log.c | 73 -
deployment_admin/private/src/log_store.c | 94 -
deployment_admin/private/src/log_sync.c | 209 -
deployment_admin/private/src/miniunz.c | 402 -
deployment_admin/private/src/unzip.c | 2128 -----
.../public/include/resource_processor.h | 54 -
deployment_admin/src/deployment_admin.c | 809 ++
deployment_admin/src/deployment_admin.h | 57 +
.../src/deployment_admin_activator.c | 78 +
deployment_admin/src/deployment_package.c | 219 +
deployment_admin/src/deployment_package.h | 76 +
deployment_admin/src/ioapi.c | 235 +
deployment_admin/src/ioapi.h | 200 +
deployment_admin/src/log.c | 73 +
deployment_admin/src/log.h | 44 +
deployment_admin/src/log_event.h | 43 +
deployment_admin/src/log_store.c | 94 +
deployment_admin/src/log_store.h | 45 +
deployment_admin/src/log_sync.c | 209 +
deployment_admin/src/log_sync.h | 36 +
deployment_admin/src/miniunz.c | 402 +
deployment_admin/src/miniunz.h | 34 +
deployment_admin/src/unzip.c | 2128 +++++
deployment_admin/src/unzip.h | 437 +
device_access/README.md | 11 +-
device_access/device_access/CMakeLists.txt | 42 +-
device_access/device_access/include/device.h | 47 +
device_access/device_access/include/driver.h | 45 +
.../device_access/include/driver_locator.h | 46 +
.../device_access/include/driver_selector.h | 41 +
device_access/device_access/include/match.h | 38 +
.../private/include/device_manager.h | 56 -
.../private/include/driver_attributes.h | 46 -
.../private/include/driver_loader.h | 48 -
.../private/include/driver_matcher.h | 42 -
.../device_access/private/src/activator.c | 194 -
.../device_access/private/src/device_manager.c | 570 --
.../private/src/driver_attributes.c | 169 -
.../device_access/private/src/driver_loader.c | 185 -
.../device_access/private/src/driver_matcher.c | 274 -
.../device_access/public/include/device.h | 47 -
.../device_access/public/include/driver.h | 45 -
.../public/include/driver_locator.h | 46 -
.../public/include/driver_selector.h | 41 -
.../device_access/public/include/match.h | 38 -
device_access/device_access/src/activator.c | 194 +
.../device_access/src/device_manager.c | 570 ++
.../device_access/src/device_manager.h | 56 +
.../device_access/src/driver_attributes.c | 169 +
.../device_access/src/driver_attributes.h | 46 +
device_access/device_access/src/driver_loader.c | 185 +
device_access/device_access/src/driver_loader.h | 48 +
.../device_access/src/driver_matcher.c | 274 +
.../device_access/src/driver_matcher.h | 42 +
device_access/driver_locator/CMakeLists.txt | 14 +-
.../private/include/driver_locator_private.h | 39 -
.../driver_locator/private/src/activator.c | 89 -
.../driver_locator/private/src/driver_locator.c | 91 -
device_access/driver_locator/src/activator.c | 89 +
.../driver_locator/src/driver_locator.c | 91 +
.../driver_locator/src/driver_locator_private.h | 39 +
device_access/example/CMakeLists.txt | 2 +-
.../example/base_driver/CMakeLists.txt | 15 +-
.../base_driver/include/base_driver_device.h | 44 +
.../private/include/base_driver_private.h | 41 -
.../example/base_driver/private/src/activator.c | 140 -
.../base_driver/private/src/base_driver.c | 111 -
.../public/include/base_driver_device.h | 44 -
.../example/base_driver/src/activator.c | 140 +
.../example/base_driver/src/base_driver.c | 111 +
.../base_driver/src/base_driver_private.h | 41 +
.../example/consuming_driver/CMakeLists.txt | 12 +-
.../private/include/consuming_driver_private.h | 43 -
.../consuming_driver/private/src/activator.c | 104 -
.../private/src/consuming_driver.c | 125 -
.../example/consuming_driver/src/activator.c | 104 +
.../consuming_driver/src/consuming_driver.c | 125 +
.../src/consuming_driver_private.h | 43 +
.../example/refining_driver/CMakeLists.txt | 15 +-
.../include/refining_driver_device.h | 45 +
.../private/include/refining_driver_private.h | 58 -
.../refining_driver/private/src/activator.c | 104 -
.../private/src/refining_driver.c | 281 -
.../public/include/refining_driver_device.h | 45 -
.../example/refining_driver/src/activator.c | 104 +
.../refining_driver/src/refining_driver.c | 281 +
.../src/refining_driver_private.h | 58 +
dfi/CMakeLists.txt | 93 +-
dfi/include/dfi_log_util.h | 63 +
dfi/include/dyn_common.h | 47 +
dfi/include/dyn_function.h | 60 +
dfi/include/dyn_interface.h | 66 +
dfi/include/dyn_message.h | 56 +
dfi/include/dyn_type.h | 155 +
dfi/include/json_rpc.h | 37 +
dfi/include/json_serializer.h | 37 +
dfi/private/src/dyn_common.c | 151 -
dfi/private/src/dyn_function.c | 331 -
dfi/private/src/dyn_interface.c | 444 -
dfi/private/src/dyn_message.c | 358 -
dfi/private/src/dyn_type.c | 1160 ---
dfi/private/src/json_rpc.c | 341 -
dfi/private/src/json_serializer.c | 484 --
.../test/avro_descriptor_translator_tests.cpp | 180 -
.../test/descriptors/example1.descriptor | 13 -
.../test/descriptors/example2.descriptor | 9 -
.../test/descriptors/example3.descriptor | 11 -
.../test/descriptors/example4.descriptor | 8 -
.../descriptors/invalids/invalid.descriptor | 13 -
.../invalids/invalidMetaType.descriptor | 8 -
.../invalids/invalidMethod.descriptor | 8 -
.../invalids/invalidMethodReturnType.descriptor | 8 -
.../invalids/invalidMsgHdr.descriptor | 9 -
.../invalids/invalidMsgInvalidName.descriptor | 9 -
.../invalidMsgInvalidSection.descriptor | 10 -
.../invalids/invalidMsgInvalidType.descriptor | 9 -
.../invalidMsgInvalidVersion.descriptor | 10 -
.../invalidMsgMissingVersion.descriptor | 10 -
.../invalids/invalidSection.descriptor | 6 -
.../descriptors/invalids/invalidType.descriptor | 10 -
.../invalids/invalidVersion.descriptor | 9 -
.../descriptors/invalids/noVersion.descriptor | 12 -
.../test/descriptors/msg_example1.descriptor | 10 -
.../test/descriptors/msg_example2.descriptor | 12 -
.../test/descriptors/msg_example3.descriptor | 10 -
.../test/descriptors/msg_example4.descriptor | 10 -
dfi/private/test/dyn_closure_tests.cpp | 162 -
dfi/private/test/dyn_function_tests.cpp | 274 -
dfi/private/test/dyn_interface_tests.cpp | 207 -
dfi/private/test/dyn_message_tests.cpp | 253 -
dfi/private/test/dyn_type_tests.cpp | 297 -
dfi/private/test/json_rpc_tests.cpp | 433 -
dfi/private/test/json_serializer_tests.cpp | 558 --
dfi/private/test/run_tests.cpp | 24 -
dfi/private/test/schemas/complex.avdl | 30 -
dfi/private/test/schemas/complex.avpr | 55 -
dfi/private/test/schemas/invalid1.avpr | 47 -
dfi/private/test/schemas/invalid2.avpr | 49 -
dfi/private/test/schemas/simple.avdl | 24 -
dfi/private/test/schemas/simple.avpr | 51 -
dfi/private/test/schemas/simple_min.avpr | 19 -
dfi/public/include/dfi_log_util.h | 63 -
dfi/public/include/dyn_common.h | 47 -
dfi/public/include/dyn_function.h | 60 -
dfi/public/include/dyn_interface.h | 66 -
dfi/public/include/dyn_message.h | 56 -
dfi/public/include/dyn_type.h | 155 -
dfi/public/include/json_rpc.h | 37 -
dfi/public/include/json_serializer.h | 37 -
dfi/src/dyn_common.c | 151 +
dfi/src/dyn_function.c | 331 +
dfi/src/dyn_interface.c | 444 +
dfi/src/dyn_message.c | 358 +
dfi/src/dyn_type.c | 1160 +++
dfi/src/json_rpc.c | 341 +
dfi/src/json_serializer.c | 484 ++
dfi/test/avro_descriptor_translator_tests.cpp | 180 +
dfi/test/descriptors/example1.descriptor | 13 +
dfi/test/descriptors/example2.descriptor | 9 +
dfi/test/descriptors/example3.descriptor | 11 +
dfi/test/descriptors/example4.descriptor | 8 +
.../descriptors/invalids/invalid.descriptor | 13 +
.../invalids/invalidMetaType.descriptor | 8 +
.../invalids/invalidMethod.descriptor | 8 +
.../invalids/invalidMethodReturnType.descriptor | 8 +
.../invalids/invalidMsgHdr.descriptor | 9 +
.../invalids/invalidMsgInvalidName.descriptor | 9 +
.../invalidMsgInvalidSection.descriptor | 10 +
.../invalids/invalidMsgInvalidType.descriptor | 9 +
.../invalidMsgInvalidVersion.descriptor | 10 +
.../invalidMsgMissingVersion.descriptor | 10 +
.../invalids/invalidSection.descriptor | 6 +
.../descriptors/invalids/invalidType.descriptor | 10 +
.../invalids/invalidVersion.descriptor | 9 +
.../descriptors/invalids/noVersion.descriptor | 12 +
dfi/test/descriptors/msg_example1.descriptor | 10 +
dfi/test/descriptors/msg_example2.descriptor | 12 +
dfi/test/descriptors/msg_example3.descriptor | 10 +
dfi/test/descriptors/msg_example4.descriptor | 10 +
dfi/test/dyn_closure_tests.cpp | 162 +
dfi/test/dyn_function_tests.cpp | 274 +
dfi/test/dyn_interface_tests.cpp | 207 +
dfi/test/dyn_message_tests.cpp | 253 +
dfi/test/dyn_type_tests.cpp | 297 +
dfi/test/json_rpc_tests.cpp | 433 +
dfi/test/json_serializer_tests.cpp | 558 ++
dfi/test/run_tests.cpp | 24 +
dfi/test/schemas/complex.avdl | 30 +
dfi/test/schemas/complex.avpr | 55 +
dfi/test/schemas/invalid1.avpr | 47 +
dfi/test/schemas/invalid2.avpr | 49 +
dfi/test/schemas/simple.avdl | 24 +
dfi/test/schemas/simple.avpr | 51 +
dfi/test/schemas/simple_min.avpr | 19 +
doap/doap_Celix.rdf | 2 +-
etcdlib/CMakeLists.txt | 30 +-
etcdlib/api/etcd.h | 110 +
etcdlib/private/src/etcd.c | 487 --
etcdlib/public/include/etcd.h | 110 -
etcdlib/src/etcd.c | 487 ++
event_admin/event_admin/CMakeLists.txt | 2 +-
event_admin/event_handler/CMakeLists.txt | 2 +-
event_admin/event_publisher/CMakeLists.txt | 2 +-
examples/CMakeLists.txt | 8 +-
examples/dm_example/CMakeLists.txt | 40 +-
examples/dm_example/api/CMakeLists.txt | 19 +
examples/dm_example/api/include/phase1.h | 44 +
examples/dm_example/api/include/phase2.h | 41 +
examples/dm_example/phase1/CMakeLists.txt | 21 +-
.../phase1/private/include/phase1_cmp.h | 44 -
.../phase1/private/src/phase1_activator.c | 86 -
.../dm_example/phase1/private/src/phase1_cmp.c | 110 -
.../dm_example/phase1/src/phase1_activator.c | 86 +
examples/dm_example/phase1/src/phase1_cmp.c | 110 +
examples/dm_example/phase1/src/phase1_cmp.h | 44 +
examples/dm_example/phase2a/CMakeLists.txt | 19 +-
.../phase2a/private/include/phase2a_cmp.h | 46 -
.../phase2a/private/src/phase2a_activator.c | 95 -
.../phase2a/private/src/phase2a_cmp.c | 116 -
.../dm_example/phase2a/src/phase2a_activator.c | 95 +
examples/dm_example/phase2a/src/phase2a_cmp.c | 116 +
examples/dm_example/phase2a/src/phase2a_cmp.h | 46 +
examples/dm_example/phase2b/CMakeLists.txt | 21 +-
.../phase2b/private/include/phase2b_cmp.h | 46 -
.../phase2b/private/src/phase2b_activator.c | 95 -
.../phase2b/private/src/phase2b_cmp.c | 115 -
.../dm_example/phase2b/src/phase2b_activator.c | 95 +
examples/dm_example/phase2b/src/phase2b_cmp.c | 115 +
examples/dm_example/phase2b/src/phase2b_cmp.h | 46 +
examples/dm_example/phase3/CMakeLists.txt | 21 +-
.../phase3/private/include/phase3_cmp.h | 45 -
.../phase3/private/src/phase3_activator.c | 84 -
.../dm_example/phase3/private/src/phase3_cmp.c | 116 -
.../dm_example/phase3/src/phase3_activator.c | 84 +
examples/dm_example/phase3/src/phase3_cmp.c | 116 +
examples/dm_example/phase3/src/phase3_cmp.h | 45 +
examples/dm_example/services/phase1.h | 44 -
examples/dm_example/services/phase2.h | 41 -
examples/dm_example_cxx/CMakeLists.txt | 76 +-
examples/dm_example_cxx/api/CMakeLists.txt | 19 +
examples/dm_example_cxx/api/IName.h | 39 -
examples/dm_example_cxx/api/IPhase1.h | 33 -
examples/dm_example_cxx/api/IPhase2.h | 33 -
examples/dm_example_cxx/api/include/IName.h | 39 +
examples/dm_example_cxx/api/include/IPhase1.h | 33 +
examples/dm_example_cxx/api/include/IPhase2.h | 33 +
examples/dm_example_cxx/phase1/CMakeLists.txt | 17 +-
.../phase1/include/Phase1Activator.h | 36 -
.../dm_example_cxx/phase1/include/Phase1Cmp.h | 44 -
.../dm_example_cxx/phase1/src/Phase1Activator.h | 36 +
examples/dm_example_cxx/phase1/src/Phase1Cmp.h | 44 +
examples/dm_example_cxx/phase2/CMakeLists.txt | 51 +
.../phase2/include/Phase2Activator.h | 34 -
.../dm_example_cxx/phase2/include/Phase2Cmp.h | 56 -
.../dm_example_cxx/phase2/src/Phase2Activator.h | 34 +
examples/dm_example_cxx/phase2/src/Phase2Cmp.h | 56 +
.../phase2/src/Phase2aActivator.cc | 57 +
.../dm_example_cxx/phase2/src/Phase2aCmp.cc | 45 +
.../phase2/src/Phase2bActivator.cc | 50 +
.../dm_example_cxx/phase2/src/Phase2bCmp.cc | 45 +
examples/dm_example_cxx/phase2a/CMakeLists.txt | 42 -
.../phase2a/src/Phase2aActivator.cc | 57 -
.../dm_example_cxx/phase2a/src/Phase2aCmp.cc | 45 -
examples/dm_example_cxx/phase2b/CMakeLists.txt | 43 -
.../phase2b/src/Phase2bActivator.cc | 50 -
.../dm_example_cxx/phase2b/src/Phase2bCmp.cc | 45 -
examples/dm_example_cxx/phase3/CMakeLists.txt | 17 +-
.../phase3/include/Phase3Activator.h | 33 -
.../phase3/include/Phase3BaseActivator.h | 35 -
.../dm_example_cxx/phase3/include/Phase3Cmp.h | 50 -
.../dm_example_cxx/phase3/src/Phase3Activator.h | 33 +
.../phase3/src/Phase3BaseActivator.h | 35 +
examples/dm_example_cxx/phase3/src/Phase3Cmp.h | 50 +
.../phase3_locking/CMakeLists.txt | 16 +-
.../include/Phase3LockingActivator.h | 33 -
.../phase3_locking/include/Phase3LockingCmp.h | 50 -
.../phase3_locking/src/Phase3LockingActivator.h | 33 +
.../phase3_locking/src/Phase3LockingCmp.h | 50 +
examples/embedding/CMakeLists.txt | 3 +-
examples/hello_world/CMakeLists.txt | 8 +-
examples/hello_world_test/CMakeLists.txt | 12 +-
examples/log_service_example/CMakeLists.txt | 13 +-
.../log_service_example/private/src/activator.c | 85 -
examples/log_service_example/src/activator.c | 85 +
examples/mongoose/CMakeLists.txt | 4 +-
examples/service_hook_example/CMakeLists.txt | 25 +-
.../private/src/activator.c | 137 -
examples/service_hook_example/src/activator.c | 137 +
examples/services_example_c/CMakeLists.txt | 4 +-
examples/services_example_c/bar/CMakeLists.txt | 6 +-
examples/services_example_c/foo1/CMakeLists.txt | 6 +-
examples/services_example_c/foo2/CMakeLists.txt | 6 +-
examples/services_example_cxx/CMakeLists.txt | 4 +-
.../services_example_cxx/bar/CMakeLists.txt | 6 +-
.../services_example_cxx/baz/CMakeLists.txt | 6 +-
.../services_example_cxx/foo/CMakeLists.txt | 6 +-
examples/whiteboard/CMakeLists.txt | 24 -
examples/whiteboard/publisherA/CMakeLists.txt | 23 -
.../publisherA/private/src/activator.c | 83 -
.../publisherA/private/src/publisher.c | 33 -
examples/whiteboard/publisherB/CMakeLists.txt | 22 -
.../publisherB/private/src/activator.c | 77 -
.../publisherB/private/src/publisher.c | 33 -
.../private/include/publisher_private.h | 38 -
.../publisherService/public/include/publisher.h | 42 -
examples/whiteboard/tracker/CMakeLists.txt | 21 -
.../whiteboard/tracker/private/src/activator.c | 126 -
.../whiteboard/tracker_depman/CMakeLists.txt | 36 -
.../tracker_depman/private/include/tracker.h | 63 -
.../private/src/dependency_activator.c | 116 -
.../tracker_depman/private/src/tracker.c | 142 -
framework/CMakeLists.txt | 626 +-
framework/include/archive.h | 58 +
framework/include/bundle.h | 139 +
framework/include/bundle_activator.h | 126 +
framework/include/bundle_archive.h | 93 +
framework/include/bundle_context.h | 175 +
framework/include/bundle_event.h | 63 +
framework/include/bundle_listener.h | 57 +
framework/include/bundle_revision.h | 142 +
framework/include/bundle_state.h | 49 +
framework/include/capability.h | 54 +
framework/include/celix_launcher.h | 57 +
framework/include/celix_log.h | 85 +
framework/include/constants.h | 67 +
framework/include/filter.h | 55 +
framework/include/framework.h | 57 +
framework/include/framework_event.h | 71 +
framework/include/framework_exports.h | 65 +
framework/include/framework_listener.h | 55 +
framework/include/listener_hook_service.h | 60 +
framework/include/manifest.h | 67 +
framework/include/module.h | 94 +
framework/include/requirement.h | 53 +
framework/include/service_event.h | 68 +
framework/include/service_factory.h | 60 +
framework/include/service_listener.h | 55 +
framework/include/service_reference.h | 72 +
framework/include/service_registration.h | 58 +
framework/include/service_registry.h | 103 +
framework/include/service_tracker.h | 72 +
framework/include/service_tracker_customizer.h | 78 +
framework/include/wire.h | 120 +
framework/private/include/attribute.h | 39 -
framework/private/include/attribute_private.h | 39 -
framework/private/include/bundle_cache.h | 115 -
.../private/include/bundle_cache_private.h | 39 -
.../private/include/bundle_context_private.h | 43 -
framework/private/include/bundle_private.h | 48 -
.../private/include/bundle_revision_private.h | 42 -
framework/private/include/capability_private.h | 41 -
framework/private/include/filter_private.h | 57 -
framework/private/include/framework_private.h | 145 -
framework/private/include/ioapi.h | 200 -
framework/private/include/iowin32.h | 28 -
.../private/include/listener_hook_info_impl.h | 34 -
framework/private/include/manifest_parser.h | 45 -
.../private/include/registry_callback_private.h | 42 -
framework/private/include/requirement_private.h | 40 -
framework/private/include/resolver.h | 45 -
.../private/include/service_reference_private.h | 69 -
.../include/service_registration_private.h | 71 -
.../private/include/service_registry_private.h | 67 -
.../service_tracker_customizer_private.h | 49 -
.../private/include/service_tracker_private.h | 52 -
framework/private/include/unzip.h | 437 -
framework/private/src/attribute.c | 71 -
framework/private/src/bundle.c | 695 --
framework/private/src/bundle_archive.c | 792 --
framework/private/src/bundle_cache.c | 218 -
framework/private/src/bundle_context.c | 384 -
framework/private/src/bundle_revision.c | 153 -
framework/private/src/capability.c | 100 -
framework/private/src/celix_errorcodes.c | 64 -
framework/private/src/celix_launcher.c | 316 -
framework/private/src/celix_log.c | 83 -
framework/private/src/filter.c | 687 --
framework/private/src/framework.c | 2620 ------
framework/private/src/ioapi.c | 235 -
framework/private/src/iowin32.c | 389 -
framework/private/src/manifest.c | 271 -
framework/private/src/manifest_parser.c | 490 --
framework/private/src/miniunz.c | 382 -
framework/private/src/module.c | 281 -
framework/private/src/requirement.c | 114 -
framework/private/src/resolver.c | 495 --
framework/private/src/service_reference.c | 378 -
framework/private/src/service_registration.c | 291 -
framework/private/src/service_registry.c | 800 --
framework/private/src/service_tracker.c | 449 -
.../private/src/service_tracker_customizer.c | 107 -
framework/private/src/unzip.c | 2128 -----
framework/private/src/wire.c | 87 -
framework/public/include/archive.h | 58 -
framework/public/include/bundle.h | 139 -
framework/public/include/bundle_activator.h | 126 -
framework/public/include/bundle_archive.h | 93 -
framework/public/include/bundle_context.h | 159 -
framework/public/include/bundle_event.h | 63 -
framework/public/include/bundle_listener.h | 57 -
framework/public/include/bundle_revision.h | 142 -
framework/public/include/bundle_state.h | 49 -
framework/public/include/capability.h | 54 -
framework/public/include/celix_launcher.h | 57 -
framework/public/include/celix_log.h | 85 -
framework/public/include/constants.h | 67 -
framework/public/include/filter.h | 55 -
framework/public/include/framework.h | 57 -
framework/public/include/framework_event.h | 71 -
framework/public/include/framework_exports.h | 65 -
framework/public/include/framework_listener.h | 55 -
.../public/include/listener_hook_service.h | 60 -
framework/public/include/manifest.h | 67 -
framework/public/include/module.h | 94 -
framework/public/include/requirement.h | 53 -
framework/public/include/service_event.h | 68 -
framework/public/include/service_factory.h | 60 -
framework/public/include/service_listener.h | 55 -
framework/public/include/service_reference.h | 72 -
framework/public/include/service_registration.h | 58 -
framework/public/include/service_registry.h | 103 -
framework/public/include/service_tracker.h | 72 -
.../public/include/service_tracker_customizer.h | 78 -
framework/public/include/wire.h | 120 -
framework/src/attribute.c | 71 +
framework/src/attribute.h | 39 +
framework/src/attribute_private.h | 39 +
framework/src/bundle.c | 695 ++
framework/src/bundle_archive.c | 792 ++
framework/src/bundle_cache.c | 218 +
framework/src/bundle_cache.h | 115 +
framework/src/bundle_cache_private.h | 39 +
framework/src/bundle_context.c | 384 +
framework/src/bundle_context_private.h | 43 +
framework/src/bundle_private.h | 48 +
framework/src/bundle_revision.c | 153 +
framework/src/bundle_revision_private.h | 42 +
framework/src/capability.c | 100 +
framework/src/capability_private.h | 41 +
framework/src/celix_errorcodes.c | 64 +
framework/src/celix_launcher.c | 317 +
framework/src/celix_log.c | 83 +
framework/src/filter.c | 687 ++
framework/src/filter_private.h | 57 +
framework/src/framework.c | 2620 ++++++
framework/src/framework_private.h | 145 +
framework/src/ioapi.c | 235 +
framework/src/ioapi.h | 200 +
framework/src/iowin32.c | 389 +
framework/src/iowin32.h | 28 +
framework/src/listener_hook_info_impl.h | 34 +
framework/src/manifest.c | 271 +
framework/src/manifest_parser.c | 490 ++
framework/src/manifest_parser.h | 45 +
framework/src/miniunz.c | 382 +
framework/src/module.c | 281 +
framework/src/registry_callback_private.h | 42 +
framework/src/requirement.c | 114 +
framework/src/requirement_private.h | 40 +
framework/src/resolver.c | 495 ++
framework/src/resolver.h | 45 +
framework/src/service_reference.c | 378 +
framework/src/service_reference_private.h | 69 +
framework/src/service_registration.c | 291 +
framework/src/service_registration_private.h | 71 +
framework/src/service_registry.c | 800 ++
framework/src/service_registry_private.h | 67 +
framework/src/service_tracker.c | 449 +
framework/src/service_tracker_customizer.c | 107 +
.../src/service_tracker_customizer_private.h | 49 +
framework/src/service_tracker_private.h | 52 +
framework/src/unzip.c | 2128 +++++
framework/src/unzip.h | 437 +
framework/src/wire.c | 87 +
framework/tst/CMakeLists.txt | 12 +-
launcher/CMakeLists.txt | 33 +-
launcher/private/src/celix_test_runner.cpp | 73 -
launcher/private/src/main.c | 24 -
launcher/src/celix_test_runner.cpp | 73 +
launcher/src/main.c | 24 +
log_service/CMakeLists.txt | 60 +-
log_service/README.md | 30 +-
log_service/include/log_entry.h | 55 +
log_service/include/log_listener.h | 43 +
log_service/include/log_reader_service.h | 50 +
log_service/include/log_service.h | 58 +
log_service/loghelper_include/log_helper.h | 36 +
log_service/private/include/log.h | 48 -
log_service/private/include/log_factory.h | 40 -
.../private/include/log_reader_service_impl.h | 43 -
log_service/private/include/log_service_impl.h | 39 -
log_service/private/src/log.c | 375 -
log_service/private/src/log_entry.c | 94 -
log_service/private/src/log_factory.c | 100 -
.../private/src/log_reader_service_impl.c | 82 -
log_service/private/src/log_service_activator.c | 198 -
log_service/private/src/log_service_impl.c | 96 -
log_service/public/include/log_entry.h | 55 -
log_service/public/include/log_helper.h | 35 -
log_service/public/include/log_listener.h | 43 -
log_service/public/include/log_reader_service.h | 50 -
log_service/public/include/log_service.h | 58 -
log_service/public/src/log_helper.c | 211 -
log_service/src/log.c | 375 +
log_service/src/log.h | 48 +
log_service/src/log_entry.c | 94 +
log_service/src/log_factory.c | 100 +
log_service/src/log_factory.h | 40 +
log_service/src/log_helper.c | 211 +
log_service/src/log_reader_service_impl.c | 82 +
log_service/src/log_reader_service_impl.h | 43 +
log_service/src/log_service_activator.c | 198 +
log_service/src/log_service_impl.c | 96 +
log_service/src/log_service_impl.h | 39 +
log_writer/CMakeLists.txt | 7 +-
log_writer/README.md | 27 +-
log_writer/log_writer/CMakeLists.txt | 24 +
log_writer/log_writer/include/log_writer.h | 53 +
.../log_writer/private/include/log_writer.h | 54 -
log_writer/log_writer/private/src/log_writer.c | 122 -
.../private/src/log_writer_activator.c | 57 -
log_writer/log_writer/src/log_writer.c | 122 +
.../log_writer/src/log_writer_activator.c | 57 +
log_writer/log_writer_stdout/CMakeLists.txt | 18 +-
.../private/src/log_writer_stdout.c | 49 -
.../log_writer_stdout/src/log_writer_stdout.c | 49 +
log_writer/log_writer_syslog/CMakeLists.txt | 16 +-
pubsub/CMakeLists.txt | 33 +-
pubsub/api/pubsub/publisher.h | 88 -
pubsub/api/pubsub/subscriber.h | 75 -
pubsub/deploy/CMakeLists.txt | 239 -
pubsub/examples/CMakeLists.txt | 213 +
.../examples/mp_pubsub/publisher/CMakeLists.txt | 11 +-
.../private/include/mp_publisher_private.h | 2 +-
.../publisher/private/src/mp_pub_activator.c | 50 +-
.../publisher/private/src/mp_publisher.c | 1 -
.../mp_pubsub/subscriber/CMakeLists.txt | 15 +-
.../private/include/mp_subscriber_private.h | 3 +-
.../subscriber/private/src/mp_sub_activator.c | 43 +-
pubsub/examples/pubsub/publisher/CMakeLists.txt | 21 +-
.../private/include/pubsub_publisher_private.h | 2 +-
.../publisher/private/src/ps_pub_activator.c | 69 +-
.../publisher/private/src/pubsub_publisher.c | 1 -
.../examples/pubsub/publisher2/CMakeLists.txt | 23 +-
.../examples/pubsub/subscriber/CMakeLists.txt | 25 +-
.../private/include/pubsub_subscriber_private.h | 3 +-
.../subscriber/private/src/ps_sub_activator.c | 49 +-
pubsub/mock/CMakeLists.txt | 21 +-
pubsub/pubsub_admin_udp_mc/CMakeLists.txt | 39 +-
.../private/include/large_udp.h | 45 -
.../private/include/pubsub_admin_impl.h | 93 -
.../private/include/topic_publication.h | 57 -
.../private/include/topic_subscription.h | 60 -
.../pubsub_admin_udp_mc/private/src/large_udp.c | 372 -
.../private/src/psa_activator.c | 141 -
.../private/src/pubsub_admin_impl.c | 1039 ---
.../private/src/topic_publication.c | 437 -
.../private/src/topic_subscription.c | 635 --
pubsub/pubsub_admin_udp_mc/src/large_udp.c | 372 +
pubsub/pubsub_admin_udp_mc/src/large_udp.h | 45 +
pubsub/pubsub_admin_udp_mc/src/psa_activator.c | 141 +
.../pubsub_admin_udp_mc/src/pubsub_admin_impl.c | 1039 +++
.../pubsub_admin_udp_mc/src/pubsub_admin_impl.h | 93 +
.../pubsub_admin_udp_mc/src/topic_publication.c | 437 +
.../pubsub_admin_udp_mc/src/topic_publication.h | 57 +
.../src/topic_subscription.c | 635 ++
.../src/topic_subscription.h | 60 +
pubsub/pubsub_admin_zmq/CMakeLists.txt | 51 +-
.../private/include/pubsub_admin_impl.h | 109 -
.../private/include/topic_publication.h | 49 -
.../private/include/topic_subscription.h | 60 -
.../private/include/zmq_crypto.h | 41 -
.../private/src/psa_activator.c | 142 -
.../private/src/pubsub_admin_impl.c | 1040 ---
.../private/src/topic_publication.c | 630 --
.../private/src/topic_subscription.c | 732 --
.../pubsub_admin_zmq/private/src/zmq_crypto.c | 281 -
pubsub/pubsub_admin_zmq/src/psa_activator.c | 142 +
pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.c | 1040 +++
pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.h | 109 +
pubsub/pubsub_admin_zmq/src/topic_publication.c | 630 ++
pubsub/pubsub_admin_zmq/src/topic_publication.h | 49 +
.../pubsub_admin_zmq/src/topic_subscription.c | 732 ++
.../pubsub_admin_zmq/src/topic_subscription.h | 60 +
pubsub/pubsub_admin_zmq/src/zmq_crypto.c | 281 +
pubsub/pubsub_admin_zmq/src/zmq_crypto.h | 41 +
pubsub/pubsub_api/CMakeLists.txt | 32 +
pubsub/pubsub_api/include/pubsub/publisher.h | 88 +
pubsub/pubsub_api/include/pubsub/subscriber.h | 75 +
.../include/publisher_endpoint_announce.h | 36 -
.../pubsub_common/public/include/pubsub_admin.h | 72 -
.../public/include/pubsub_admin_match.h | 40 -
.../public/include/pubsub_common.h | 52 -
.../public/include/pubsub_endpoint.h | 58 -
.../public/include/pubsub_serializer.h | 66 -
.../public/include/pubsub_topic_info.descriptor | 10 -
.../pubsub_common/public/include/pubsub_utils.h | 39 -
.../public/src/pubsub_admin_match.c | 320 -
.../pubsub_common/public/src/pubsub_endpoint.c | 254 -
pubsub/pubsub_common/public/src/pubsub_utils.c | 170 -
pubsub/pubsub_discovery/CMakeLists.txt | 34 +-
.../private/include/etcd_common.h | 28 -
.../private/include/etcd_watcher.h | 38 -
.../private/include/etcd_writer.h | 39 -
.../private/include/pubsub_discovery_impl.h | 72 -
.../pubsub_discovery/private/src/etcd_common.c | 82 -
.../pubsub_discovery/private/src/etcd_watcher.c | 290 -
.../pubsub_discovery/private/src/etcd_writer.c | 189 -
.../private/src/psd_activator.c | 171 -
.../private/src/pubsub_discovery_impl.c | 457 -
.../public/include/pubsub_discovery.h | 26 -
pubsub/pubsub_discovery/src/etcd_common.c | 82 +
pubsub/pubsub_discovery/src/etcd_common.h | 28 +
pubsub/pubsub_discovery/src/etcd_watcher.c | 290 +
pubsub/pubsub_discovery/src/etcd_watcher.h | 38 +
pubsub/pubsub_discovery/src/etcd_writer.c | 189 +
pubsub/pubsub_discovery/src/etcd_writer.h | 39 +
pubsub/pubsub_discovery/src/psd_activator.c | 171 +
pubsub/pubsub_discovery/src/pubsub_discovery.h | 26 +
.../src/pubsub_discovery_impl.c | 457 +
.../src/pubsub_discovery_impl.h | 72 +
pubsub/pubsub_serializer_json/CMakeLists.txt | 31 +-
.../private/include/pubsub_serializer_impl.h | 55 -
.../private/src/ps_activator.c | 107 -
.../private/src/pubsub_serializer_impl.c | 295 -
.../pubsub_serializer_json/src/ps_activator.c | 107 +
.../src/pubsub_serializer_impl.c | 295 +
.../src/pubsub_serializer_impl.h | 55 +
pubsub/pubsub_spi/CMakeLists.txt | 36 +
.../include/publisher_endpoint_announce.h | 36 +
pubsub/pubsub_spi/include/pubsub_admin.h | 72 +
pubsub/pubsub_spi/include/pubsub_admin_match.h | 40 +
pubsub/pubsub_spi/include/pubsub_common.h | 52 +
pubsub/pubsub_spi/include/pubsub_endpoint.h | 58 +
pubsub/pubsub_spi/include/pubsub_serializer.h | 66 +
.../include/pubsub_topic_info.descriptor | 10 +
pubsub/pubsub_spi/include/pubsub_utils.h | 39 +
pubsub/pubsub_spi/src/pubsub_admin_match.c | 320 +
pubsub/pubsub_spi/src/pubsub_endpoint.c | 254 +
pubsub/pubsub_spi/src/pubsub_utils.c | 170 +
pubsub/pubsub_topology_manager/CMakeLists.txt | 29 +-
.../private/include/pubsub_topology_manager.h | 83 -
.../private/src/pstm_activator.c | 246 -
.../private/src/pubsub_topology_manager.c | 723 --
.../src/pstm_activator.c | 244 +
.../src/pubsub_topology_manager.c | 721 ++
.../src/pubsub_topology_manager.h | 82 +
pubsub/test/CMakeLists.txt | 14 +-
remote_services/CMakeLists.txt | 26 +-
remote_services/civetweb/CMakeLists.txt | 26 +
remote_services/civetweb/include/civetweb.h | 657 ++
remote_services/civetweb/src/civetweb.c | 7907 ++++++++++++++++++
remote_services/civetweb/src/md5.inl | 461 +
.../discovery/private/include/discovery.h | 67 -
.../include/endpoint_descriptor_common.h | 61 -
.../include/endpoint_descriptor_reader.h | 42 -
.../include/endpoint_descriptor_writer.h | 39 -
.../private/include/endpoint_discovery_poller.h | 56 -
.../private/include/endpoint_discovery_server.h | 81 -
remote_services/discovery/private/src/desc.xml | 41 -
.../discovery/private/src/discovery.c | 233 -
.../discovery/private/src/discovery_activator.c | 186 -
.../private/src/endpoint_descriptor_reader.c | 387 -
.../private/src/endpoint_descriptor_writer.c | 233 -
.../private/src/endpoint_discovery_poller.c | 403 -
.../private/src/endpoint_discovery_server.c | 450 -
remote_services/discovery_common/CMakeLists.txt | 39 +
.../discovery_common/include/discovery.h | 88 +
.../discovery_common/include/discovery_type.h | 27 +
.../include/endpoint_descriptor_common.h | 61 +
.../include/endpoint_descriptor_reader.h | 42 +
.../include/endpoint_descriptor_writer.h | 39 +
.../include/endpoint_discovery_poller.h | 57 +
.../include/endpoint_discovery_server.h | 88 +
remote_services/discovery_common/src/desc.xml | 41 +
.../discovery_common/src/discovery.c | 233 +
.../discovery_common/src/discovery_activator.c | 186 +
.../src/endpoint_descriptor_reader.c | 293 +
.../src/endpoint_descriptor_writer.c | 196 +
.../src/endpoint_discovery_poller.c | 402 +
.../src/endpoint_discovery_server.c | 454 +
.../discovery_configured/CMakeLists.txt | 64 +-
.../private/include/discovery_impl.h | 62 -
.../discovery_configured/private/src/desc.xml | 41 -
.../private/src/discovery_impl.c | 123 -
.../discovery_configured/src/desc.xml | 41 +
.../discovery_configured/src/discovery_impl.c | 123 +
.../discovery_configured/src/discovery_impl.h | 62 +
remote_services/discovery_etcd/CMakeLists.txt | 48 +-
.../private/include/discovery_impl.h | 66 -
.../private/include/etcd_watcher.h | 40 -
.../discovery_etcd/private/src/discovery_impl.c | 183 -
.../discovery_etcd/private/src/etcd_watcher.c | 397 -
.../discovery_etcd/src/discovery_impl.c | 193 +
.../discovery_etcd/src/discovery_impl.h | 54 +
.../discovery_etcd/src/etcd_watcher.c | 397 +
.../discovery_etcd/src/etcd_watcher.h | 41 +
remote_services/discovery_shm/CMakeLists.txt | 46 +-
.../private/include/discovery_impl.h | 66 -
.../private/include/discovery_shm.h | 56 -
.../private/include/discovery_shmWatcher.h | 40 -
.../discovery_shm/private/src/discovery_impl.c | 163 -
.../discovery_shm/private/src/discovery_shm.c | 284 -
.../private/src/discovery_shmWatcher.c | 246 -
.../discovery_shm/src/discovery_impl.c | 169 +
.../discovery_shm/src/discovery_impl.h | 53 +
.../discovery_shm/src/discovery_shm.c | 284 +
.../discovery_shm/src/discovery_shm.h | 56 +
.../discovery_shm/src/discovery_shmWatcher.c | 255 +
.../discovery_shm/src/discovery_shmWatcher.h | 41 +
remote_services/examples/CMakeLists.txt | 100 +-
.../examples/calculator_api/CMakeLists.txt | 22 +
.../calculator_api/include/calculator_service.h | 56 +
...apache.celix.calc.api.Calculator2.descriptor | 11 +
.../examples/calculator_endpoint/CMakeLists.txt | 35 -
.../private/include/calculator_endpoint_impl.h | 46 -
.../private/src/calculator_endpoint_activator.c | 96 -
.../private/src/calculator_endpoint_impl.c | 184 -
.../calculator_endpoint2/CMakeLists.txt | 35 -
.../private/include/calculator_endpoint_impl.h | 46 -
.../private/src/calculator_endpoint_activator.c | 96 -
.../private/src/calculator_endpoint_impl.c | 184 -
.../examples/calculator_proxy/CMakeLists.txt | 37 -
.../private/include/calculator_proxy_impl.h | 59 -
.../private/src/calculator_proxy_activator.c | 124 -
.../private/src/calculator_proxy_impl.c | 173 -
.../examples/calculator_proxy2/CMakeLists.txt | 37 -
.../private/include/calculator_proxy_impl.h | 59 -
.../private/src/calculator_proxy_activator.c | 124 -
.../private/src/calculator_proxy_impl.c | 173 -
.../examples/calculator_service/CMakeLists.txt | 24 +-
.../private/include/calculator_impl.h | 43 -
.../private/src/calculator_activator.c | 110 -
.../private/src/calculator_impl.c | 79 -
.../public/include/calculator_service.h | 56 -
...apache.celix.calc.api.Calculator2.descriptor | 11 -
.../src/calculator_activator.c | 110 +
.../calculator_service/src/calculator_impl.c | 79 +
.../calculator_service/src/calculator_impl.h | 43 +
.../examples/calculator_shell/CMakeLists.txt | 29 +-
.../private/include/add_command.h | 32 -
...apache.celix.calc.api.Calculator2.descriptor | 11 -
.../private/include/sqrt_command.h | 32 -
.../private/include/sub_command.h | 32 -
.../calculator_shell/private/src/add_command.c | 101 -
.../private/src/calculator_shell_activator.c | 125 -
.../calculator_shell/private/src/sqrt_command.c | 96 -
.../calculator_shell/private/src/sub_command.c | 99 -
.../examples/calculator_shell/src/add_command.c | 101 +
.../examples/calculator_shell/src/add_command.h | 32 +
.../src/calculator_shell_activator.c | 125 +
...apache.celix.calc.api.Calculator2.descriptor | 11 +
.../calculator_shell/src/sqrt_command.c | 96 +
.../calculator_shell/src/sqrt_command.h | 32 +
.../examples/calculator_shell/src/sub_command.c | 99 +
.../examples/calculator_shell/src/sub_command.h | 32 +
.../remote_service_admin/CMakeLists.txt | 46 -
remote_services/remote_service_admin/README.md | 28 -
.../private/include/export_registration_impl.h | 61 -
.../private/include/import_registration_impl.h | 81 -
.../private/include/remote_service_admin_impl.h | 49 -
.../private/src/endpoint_description.c | 89 -
.../private/src/export_registration_impl.c | 257 -
.../private/src/import_registration_impl.c | 274 -
.../private/src/remote_proxy_factory_impl.c | 252 -
.../public/include/endpoint_description.h | 50 -
.../public/include/endpoint_listener.h | 49 -
.../public/include/export_registration.h | 22 -
.../public/include/import_registration.h | 22 -
.../public/include/remote_constants.h | 38 -
.../public/include/remote_endpoint.h | 44 -
.../public/include/remote_endpoint_impl.h | 38 -
.../public/include/remote_proxy.h | 76 -
.../public/include/remote_service_admin.h | 73 -
.../remote_service_admin_dfi/CMakeLists.txt | 32 +-
.../remote_service_admin_dfi/rsa/CMakeLists.txt | 48 -
.../rsa/private/include/dfi_utils.h | 30 -
.../private/include/export_registration_dfi.h | 38 -
.../private/include/import_registration_dfi.h | 44 -
.../private/include/remote_service_admin_dfi.h | 57 -
.../rsa/private/src/dfi_utils.c | 98 -
.../rsa/private/src/export_registration_dfi.c | 251 -
.../rsa/private/src/import_registration_dfi.c | 402 -
.../src/remote_service_admin_activator.c | 124 -
.../rsa/private/src/remote_service_admin_dfi.c | 775 --
.../rsa_tst/CMakeLists.txt | 57 -
.../rsa_tst/bundle/CMakeLists.txt | 37 -
.../rsa_tst/bundle/tst_activator.c | 153 -
.../rsa_tst/bundle/tst_service.h | 32 -
.../rsa_tst/client.properties.in | 8 -
.../rsa_tst/config.properties.in | 20 -
.../rsa_tst/rsa_client_server_tests.cpp | 133 -
.../rsa_tst/rsa_tests.cpp | 234 -
.../rsa_tst/run_tests.cpp | 25 -
.../rsa_tst/server.properties.in | 23 -
.../remote_service_admin_dfi/src/dfi_utils.c | 108 +
.../remote_service_admin_dfi/src/dfi_utils.h | 30 +
.../src/export_registration_dfi.c | 251 +
.../src/export_registration_dfi.h | 38 +
.../src/import_registration_dfi.c | 402 +
.../src/import_registration_dfi.h | 44 +
.../src/remote_service_admin_activator.c | 124 +
.../src/remote_service_admin_dfi.c | 771 ++
.../src/remote_service_admin_dfi.h | 57 +
.../test/CMakeLists.txt | 60 +
.../test/client.properties.in | 8 +
.../test/config.properties.in | 20 +
.../test/server.properties.in | 23 +
.../test/src/rsa_client_server_tests.cpp | 133 +
.../test/src/rsa_tests.cpp | 234 +
.../test/src/run_tests.cpp | 25 +
.../test/src/tst_activator.c | 162 +
.../test/src/tst_service.h | 32 +
.../remote_service_admin_http/CMakeLists.txt | 55 -
.../include/remote_service_admin_http_impl.h | 52 -
.../src/remote_service_admin_activator.c | 123 -
.../private/src/remote_service_admin_impl.c | 822 --
.../private/test/CMakeLists.txt | 58 -
.../private/test/client.properties.in | 26 -
.../private/test/rsa_client_server_tests.cpp | 495 --
.../private/test/run_tests.cpp | 24 -
.../private/test/server.properties.in | 25 -
.../remote_services_api/CMakeLists.txt | 28 +
remote_services/remote_services_api/README.md | 11 +
.../include/remote_constants.h | 31 +
remote_services/rsa_common/CMakeLists.txt | 30 +
.../rsa_common/src/endpoint_description.c | 89 +
.../rsa_common/src/export_registration_impl.c | 257 +
.../rsa_common/src/export_registration_impl.h | 61 +
.../rsa_common/src/import_registration_impl.c | 274 +
.../rsa_common/src/import_registration_impl.h | 81 +
.../rsa_common/src/remote_proxy_factory_impl.c | 252 +
.../rsa_common/src/remote_service_admin_impl.h | 49 +
remote_services/rsa_spi/CMakeLists.txt | 29 +
remote_services/rsa_spi/README.md | 11 +
.../rsa_spi/include/endpoint_description.h | 50 +
.../rsa_spi/include/endpoint_listener.h | 49 +
.../rsa_spi/include/export_registration.h | 22 +
.../rsa_spi/include/import_registration.h | 22 +
.../rsa_spi/include/remote_constants.h | 38 +
.../rsa_spi/include/remote_endpoint.h | 44 +
.../rsa_spi/include/remote_endpoint_impl.h | 38 +
remote_services/rsa_spi/include/remote_proxy.h | 76 +
.../rsa_spi/include/remote_service_admin.h | 73 +
remote_services/topology_manager/CMakeLists.txt | 32 +-
.../topology_manager/include/tm_scope.h | 46 +
.../topology_manager/private/include/scope.h | 150 -
.../private/include/topology_manager.h | 65 -
.../topology_manager/private/src/activator.c | 289 -
.../topology_manager/private/src/scope.c | 326 -
.../private/src/topology_manager.c | 985 ---
.../topology_manager/public/include/tm_scope.h | 46 -
.../topology_manager/src/activator.c | 289 +
remote_services/topology_manager/src/scope.c | 326 +
remote_services/topology_manager/src/scope.h | 150 +
.../topology_manager/src/topology_manager.c | 985 +++
.../topology_manager/src/topology_manager.h | 66 +
.../topology_manager/tms_tst/CMakeLists.txt | 24 +-
.../tms_tst/bundle/CMakeLists.txt | 2 +-
.../tms_tst/disc_mock/CMakeLists.txt | 15 +-
.../tms_tst/disc_mock/disc_mock_activator.c | 1 -
.../utils/private/include/civetweb.h | 657 --
remote_services/utils/private/src/civetweb.c | 7907 ------------------
remote_services/utils/private/src/md5.inl | 461 -
remote_shell/CMakeLists.txt | 28 +-
.../private/include/connection_listener.h | 42 -
remote_shell/private/include/remote_shell.h | 50 -
remote_shell/private/include/shell_mediator.h | 54 -
remote_shell/private/src/activator.c | 153 -
remote_shell/private/src/connection_listener.c | 221 -
remote_shell/private/src/remote_shell.c | 242 -
remote_shell/private/src/shell_mediator.c | 139 -
remote_shell/src/activator.c | 153 +
remote_shell/src/connection_listener.c | 221 +
remote_shell/src/connection_listener.h | 42 +
remote_shell/src/remote_shell.c | 242 +
remote_shell/src/remote_shell.h | 50 +
remote_shell/src/shell_mediator.c | 139 +
remote_shell/src/shell_mediator.h | 54 +
shell/CMakeLists.txt | 55 +-
shell/README.md | 12 +-
shell/include/command.h | 57 +
shell/include/shell.h | 51 +
shell/include/shell_constants.h | 27 +
shell/private/include/shell_private.h | 51 -
shell/private/include/std_commands.h | 44 -
shell/private/src/activator.c | 269 -
shell/private/src/help_command.c | 112 -
shell/private/src/inspect_command.c | 277 -
shell/private/src/install_command.c | 76 -
shell/private/src/lb_command.c | 205 -
shell/private/src/log_command.c | 94 -
shell/private/src/shell.c | 305 -
shell/private/src/start_command.c | 84 -
shell/private/src/stop_command.c | 82 -
shell/private/src/uninstall_command.c | 58 -
shell/private/src/update_command.c | 117 -
shell/public/include/command.h | 57 -
shell/public/include/shell.h | 51 -
shell/public/include/shell_constants.h | 27 -
shell/src/activator.c | 269 +
shell/src/help_command.c | 112 +
shell/src/inspect_command.c | 277 +
shell/src/install_command.c | 76 +
shell/src/lb_command.c | 205 +
shell/src/log_command.c | 94 +
shell/src/shell.c | 305 +
shell/src/shell_private.h | 51 +
shell/src/start_command.c | 84 +
shell/src/std_commands.h | 44 +
shell/src/stop_command.c | 82 +
shell/src/uninstall_command.c | 58 +
shell/src/update_command.c | 117 +
shell_bonjour/CMakeLists.txt | 26 +-
shell_tui/CMakeLists.txt | 16 +-
shell_tui/README.md | 5 +
utils/CMakeLists.txt | 186 +-
utils/include/array_list.h | 99 +
utils/include/celix_errno.h | 119 +
utils/include/celix_threads.h | 135 +
utils/include/celixbool.h | 61 +
utils/include/exports.h | 49 +
utils/include/hash_map.h | 161 +
utils/include/linked_list.h | 91 +
utils/include/linked_list_iterator.h | 66 +
utils/include/memstream/README.md | 49 +
utils/include/memstream/fmemopen.h | 52 +
utils/include/memstream/open_memstream.h | 15 +
utils/include/properties.h | 68 +
utils/include/thpool.h | 168 +
utils/include/utils.h | 61 +
utils/include/version.h | 186 +
utils/include/version_range.h | 160 +
utils/private/include/array_list_private.h | 52 -
utils/private/include/hash_map_private.h | 74 -
utils/private/include/linked_list_private.h | 44 -
utils/private/include/version_private.h | 41 -
utils/private/include/version_range_private.h | 41 -
utils/private/src/array_list.c | 337 -
utils/private/src/celix_threads.c | 184 -
utils/private/src/hash_map.c | 607 --
utils/private/src/linked_list.c | 268 -
utils/private/src/linked_list_iterator.c | 153 -
utils/private/src/memstream/fmemopen.c | 76 -
utils/private/src/memstream/open_memstream.c | 130 -
utils/private/src/properties.c | 330 -
utils/private/src/thpool.c | 535 --
utils/private/src/utils.c | 141 -
utils/private/src/version.c | 264 -
utils/private/src/version_range.c | 233 -
utils/public/include/array_list.h | 99 -
utils/public/include/celix_errno.h | 119 -
utils/public/include/celix_threads.h | 135 -
utils/public/include/celixbool.h | 61 -
utils/public/include/exports.h | 49 -
utils/public/include/hash_map.h | 161 -
utils/public/include/linked_list.h | 91 -
utils/public/include/linked_list_iterator.h | 66 -
utils/public/include/memstream/README.md | 49 -
utils/public/include/memstream/fmemopen.h | 52 -
utils/public/include/memstream/open_memstream.h | 15 -
utils/public/include/properties.h | 68 -
utils/public/include/thpool.h | 168 -
utils/public/include/utils.h | 61 -
utils/public/include/version.h | 186 -
utils/public/include/version_range.h | 160 -
utils/src/array_list.c | 337 +
utils/src/array_list_private.h | 52 +
utils/src/celix_threads.c | 184 +
utils/src/hash_map.c | 607 ++
utils/src/hash_map_private.h | 74 +
utils/src/linked_list.c | 268 +
utils/src/linked_list_iterator.c | 153 +
utils/src/linked_list_private.h | 44 +
utils/src/memstream/fmemopen.c | 76 +
utils/src/memstream/open_memstream.c | 130 +
utils/src/properties.c | 330 +
utils/src/thpool.c | 535 ++
utils/src/utils.c | 141 +
utils/src/version.c | 264 +
utils/src/version_private.h | 41 +
utils/src/version_range.c | 233 +
utils/src/version_range_private.h | 41 +
1083 files changed, 81386 insertions(+), 85767 deletions(-)
----------------------------------------------------------------------
[27/54] [abbrv] celix git commit: CELIX-417: Renames remote services
target. Mostly adding the rsa prefix
Posted by pn...@apache.org.
CELIX-417: Renames remote services target. Mostly adding the rsa prefix
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/486d4f0d
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/486d4f0d
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/486d4f0d
Branch: refs/heads/develop
Commit: 486d4f0d5c86f0770f047e3ecc4caf77af9886a7
Parents: 27a2aa7
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Nov 24 11:58:59 2017 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Fri Nov 24 11:58:59 2017 +0100
----------------------------------------------------------------------
remote_services/CMakeLists.txt | 1 -
remote_services/civetweb/CMakeLists.txt | 5 +-
remote_services/discovery_common/CMakeLists.txt | 10 +--
.../src/endpoint_descriptor_reader.c | 94 --------------------
.../src/endpoint_descriptor_writer.c | 37 --------
.../discovery_configured/CMakeLists.txt | 35 +++-----
remote_services/discovery_etcd/CMakeLists.txt | 23 ++---
remote_services/discovery_shm/CMakeLists.txt | 19 ++--
remote_services/examples/CMakeLists.txt | 4 +-
.../examples/calculator_service/CMakeLists.txt | 2 +-
.../remote_service_admin_api/CMakeLists.txt | 6 +-
.../remote_service_admin_common/CMakeLists.txt | 9 +-
.../remote_service_admin_dfi/CMakeLists.txt | 14 +--
.../test/CMakeLists.txt | 11 ++-
remote_services/topology_manager/CMakeLists.txt | 13 +--
.../topology_manager/tms_tst/CMakeLists.txt | 10 +--
.../tms_tst/bundle/CMakeLists.txt | 2 +-
.../tms_tst/disc_mock/CMakeLists.txt | 2 +-
18 files changed, 79 insertions(+), 218 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/CMakeLists.txt b/remote_services/CMakeLists.txt
index 4e1f5b3..bb45908 100644
--- a/remote_services/CMakeLists.txt
+++ b/remote_services/CMakeLists.txt
@@ -23,7 +23,6 @@ if (REMOTE_SERVICE_ADMIN)
add_subdirectory(topology_manager)
add_subdirectory(civetweb)
-
add_subdirectory(discovery_common)
add_subdirectory(discovery_configured)
add_subdirectory(discovery_etcd)
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/civetweb/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/civetweb/CMakeLists.txt b/remote_services/civetweb/CMakeLists.txt
index e9e272e..a6f7d10 100644
--- a/remote_services/civetweb/CMakeLists.txt
+++ b/remote_services/civetweb/CMakeLists.txt
@@ -20,4 +20,7 @@ add_library(civetweb OBJECT
src/civetweb.c
src/md5.inl
)
-target_include_directories(civetweb PUBLIC include)
\ No newline at end of file
+target_include_directories(civetweb PUBLIC include)
+
+#Setup target aliases to match external usage
+add_library(Celix::civetweb ALIAS civetweb)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/discovery_common/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/CMakeLists.txt b/remote_services/discovery_common/CMakeLists.txt
index 5b28b13..c3242a6 100644
--- a/remote_services/discovery_common/CMakeLists.txt
+++ b/remote_services/discovery_common/CMakeLists.txt
@@ -18,7 +18,7 @@
find_package(LibXml2 REQUIRED)
-add_library(discovery_common OBJECT
+add_library(rsa_discovery_common OBJECT
src/discovery.c
src/discovery_activator.c
src/endpoint_descriptor_reader.c
@@ -26,14 +26,14 @@ add_library(discovery_common OBJECT
src/endpoint_discovery_poller.c
src/endpoint_discovery_server.c
)
-target_include_directories(discovery_common PUBLIC
+target_include_directories(rsa_discovery_common PUBLIC
include src
$<TARGET_PROPERTY:Celix::framework,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:Celix::utils,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:Celix::log_helper,INTERFACE_INCLUDE_DIRECTORIES>
- $<TARGET_PROPERTY:Celix::remote_service_admin_api,INTERFACE_INCLUDE_DIRECTORIES>
- $<TARGET_PROPERTY:Celix::remote_service_admin_api,INTERFACE_INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::rsa_api,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:civetweb,INCLUDE_DIRECTORIES>
${LIBXML2_INCLUDE_DIR})
-add_library(Celix::discovery_common ALIAS discovery_common)
\ No newline at end of file
+#Setup target aliases to match external usage
+add_library(Celix::rsa_discovery_common ALIAS rsa_discovery_common)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/discovery_common/src/endpoint_descriptor_reader.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/src/endpoint_descriptor_reader.c b/remote_services/discovery_common/src/endpoint_descriptor_reader.c
index ea176bf..887bc29 100644
--- a/remote_services/discovery_common/src/endpoint_descriptor_reader.c
+++ b/remote_services/discovery_common/src/endpoint_descriptor_reader.c
@@ -291,97 +291,3 @@ static valueType valueTypeFromString(char *name) {
}
}
-#ifdef RSA_ENDPOINT_TEST_READER
-int main() {
- array_list_pt list = NULL;
- endpoint_descriptor_reader_pt reader = NULL;
-
- char *doc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
-"<endpoint-descriptions xmlns=\"http://www.osgi.org/xmlns/rsa/v1.0.0\">"
- "<endpoint-description>"
- "<property name=\"endpoint.service.id\" value-type=\"long\" value=\"6\"/>"
- "<property name=\"endpoint.framework.uuid\" value=\"2983D849-93B1-4C2C-AC6D-5BCDA93ACB96\"/>"
- "<property name=\"service.intents\">"
- "<list>"
- "<value>SOAP</value>"
- "<value>HTTP</value>"
- "</list>"
- "</property>"
- "<property name=\"endpoint.id\" value=\"11111111-1111-1111-1111-111111111111\" />"
- "<property name=\"objectClass\"><array><value>com.acme.Foo</value></array></property>"
- "<property name=\"endpoint.package.version.com.acme\" value=\"4.2\" />"
- "<property name=\"service.imported.configs\" value=\"com.acme\" />"
- "<property name=\"service.imported\" value=\"true\"/>"
- "<property name=\"com.acme.ws.xml\">"
- "<xml>"
- "<config xmlns=\"http://acme.com/defs\">"
- "<port>1029</port>"
- "<host>www.acme.com</host>"
- "</config>"
- "</xml>"
- "</property>"
- "</endpoint-description>"
- "<endpoint-description>"
- "<property name=\"endpoint.service.id\" value-type=\"long\" value=\"5\"/>"
- "<property name=\"endpoint.framework.uuid\" value=\"2983D849-93B1-4C2C-AC6D-5BCDA93ACB96\"/>"
- "<property name=\"service.intents\">"
- "<list>"
- "<value>SOAP</value>"
- "<value>HTTP</value>"
- "</list>"
- "</property>"
- "<property name=\"endpoint.id\" value=\"22222222-2222-2222-2222-222222222222\" />"
- "<property name=\"objectClass\"><array><value>com.acme.Bar</value></array></property>"
- "<property name=\"endpoint.package.version.com.acme\" value=\"4.2\" />"
- "<property name=\"service.imported.configs\" value=\"com.acme\" />"
- "<property name=\"com.acme.ws.xml\">"
- "<xml>"
- "<config xmlns=\"http://acme.com/defs\">"
- "<port>1029</port>"
- "<host>www.acme.com</host>"
- "</config>"
- "</xml>"
- "</property>"
- "</endpoint-description>"
- "</endpoint-descriptions>";
-
- endpointDescriptorReader_create(&reader);
-
- endpointDescriptorReader_parseDocument(reader, doc, &list);
-
- int i;
- for (i = 0; i < arrayList_size(list); i++) {
- printf("\nEndpoint description #%d:\n", (i+1));
- endpoint_description_pt edp = arrayList_get(list, i);
- printf("Id: %s\n", edp->id);
- printf("Service Id: %lu\n", edp->serviceId);
- printf("Framework UUID: %s\n", edp->frameworkUUID);
- printf("Service: %s\n", edp->service);
-
- properties_pt props = edp->properties;
- if (props) {
- printf("Service properties:\n");
- hash_map_iterator_pt iter = hashMapIterator_create(props);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
-
- printf("- %s => '%s'\n", hashMapEntry_getKey(entry), hashMapEntry_getValue(entry));
- }
- hashMapIterator_destroy(iter);
- } else {
- printf("No service properties...\n");
- }
-
-
- endpointDescription_destroy(edp);
- }
-
- if (list != NULL) {
- arrayList_destroy(list);
- }
-
- endpointDescriptorReader_destroy(reader);
-
- return 0;
-}
-#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/discovery_common/src/endpoint_descriptor_writer.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/src/endpoint_descriptor_writer.c b/remote_services/discovery_common/src/endpoint_descriptor_writer.c
index 71b07b4..4a5bcd7 100644
--- a/remote_services/discovery_common/src/endpoint_descriptor_writer.c
+++ b/remote_services/discovery_common/src/endpoint_descriptor_writer.c
@@ -194,40 +194,3 @@ static char* valueTypeToString(valueType type) {
return "string";
}
}
-
-#ifdef RSA_ENDPOINT_TEST_WRITER
-int main() {
- endpoint_descriptor_writer_pt writer = NULL;
- endpointDescriptorWriter_create(&writer);
- array_list_pt list = NULL;
- arrayList_create(&list);
-
- properties_pt props = properties_create();
- properties_set(props, "objectClass", "com.acme.Foo");
- properties_set(props, "endpoint.service.id", "3");
- properties_set(props, "endpoint.id", "abcdefghijklmnopqrstuvwxyz");
- properties_set(props, "endpoint.framework.uuid", "2983D849-93B1-4C2C-AC6D-5BCDA93ACB96");
- endpoint_description_pt epd = NULL;
- endpointDescription_create(props, &epd);
- arrayList_add(list, epd);
-
- properties_pt props2 = properties_create();
- properties_set(props2, "objectClass", "com.acme.Bar");
- properties_set(props, "endpoint.service.id", "4");
- properties_set(props, "endpoint.id", "abcdefghijklmnopqrstuvwxyz");
- properties_set(props, "endpoint.framework.uuid", "2983D849-93B1-4C2C-AC6D-5BCDA93ACB96");
- endpoint_description_pt epd2 = NULL;
- endpointDescription_create(props2, &epd2);
- arrayList_add(list, epd2);
-
- char *buffer = NULL;
- endpointDescriptorWriter_writeDocument(writer, list, &buffer);
-
- arrayList_destroy(list);
- endpointDescription_destroy(epd);
- endpointDescription_destroy(epd2);
- endpointDescriptorWriter_destroy(writer);
-
- printf("%s\n", buffer);
-}
-#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/discovery_configured/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/discovery_configured/CMakeLists.txt b/remote_services/discovery_configured/CMakeLists.txt
index f7d104b..bea485e 100644
--- a/remote_services/discovery_configured/CMakeLists.txt
+++ b/remote_services/discovery_configured/CMakeLists.txt
@@ -19,39 +19,24 @@ if (RSA_DISCOVERY_CONFIGURED)
find_package(CURL REQUIRED)
find_package(LibXml2 REQUIRED)
- add_bundle(discovery_configured
+ add_bundle(rsa_discovery_configured
VERSION 0.9.0
SYMBOLIC_NAME "apache_celix_rsa_discovery_configured"
NAME "Apache Celix RSA Configured Discovery"
SOURCES
src/discovery_impl.c
- $<TARGET_OBJECTS:discovery_common>
- $<TARGET_OBJECTS:civetweb>
+ $<TARGET_OBJECTS:Celix::rsa_discovery_common>
+ $<TARGET_OBJECTS:Celix::civetweb>
)
- target_include_directories(discovery_configured PRIVATE
+ target_include_directories(rsa_discovery_configured PRIVATE
src
- $<TARGET_PROPERTY:discovery_common,INCLUDE_DIRECTORIES>
- $<TARGET_PROPERTY:civetweb,INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::rsa_discovery_common,INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::civetweb,INCLUDE_DIRECTORIES>
)
- target_link_libraries(discovery_configured PRIVATE ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} Celix::log_helper)
+ target_link_libraries(rsa_discovery_configured PRIVATE ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} Celix::log_helper)
- install_bundle(discovery_configured)
+ install_bundle(rsa_discovery_configured)
-
-
- if (RSA_ENDPOINT_TEST_READER)
- add_executable(descparser
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_descriptor_reader.c
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c)
-
- target_link_libraries(descparser ${LIBXML2_LIBRARIES} celix_framework celix_utils)
- endif (RSA_ENDPOINT_TEST_READER)
-
- if (RSA_ENDPOINT_TEST_WRITER)
- add_executable(descwriter
- ${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/endpoint_descriptor_writer.c
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c)
-
- target_link_libraries(descwriter ${LIBXML2_LIBRARIES} celix_framework celix_utils)
- endif(RSA_ENDPOINT_TEST_WRITER)
+ #Setup target aliases to match external usage
+ add_library(Celix::rsa_discovery_configured ALIAS rsa_discovery_configured)
endif (RSA_DISCOVERY_CONFIGURED)
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/discovery_etcd/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/discovery_etcd/CMakeLists.txt b/remote_services/discovery_etcd/CMakeLists.txt
index 9c8edc8..19726fc 100644
--- a/remote_services/discovery_etcd/CMakeLists.txt
+++ b/remote_services/discovery_etcd/CMakeLists.txt
@@ -21,26 +21,29 @@ if (RSA_DISCOVERY_ETCD)
find_package(LibXml2 REQUIRED)
find_package(Jansson REQUIRED)
- add_bundle(discovery_etcd
+ add_bundle(rsa_discovery_etcd
VERSION 0.9.0
SYMBOLIC_NAME "apache_celix_rsa_discovery_etcd"
NAME "Apache Celix RSA Discovery ETCD"
SOURCES
src/discovery_impl.c
src/etcd_watcher.c
- $<TARGET_OBJECTS:discovery_common>
- $<TARGET_OBJECTS:civetweb>
+ $<TARGET_OBJECTS:Celix::rsa_discovery_common>
+ $<TARGET_OBJECTS:Celix::civetweb>
)
- target_link_libraries(discovery_etcd PRIVATE Celix::log_helper Celix::etcdlib_static)
- target_include_directories(discovery_etcd PRIVATE src)
- target_include_directories(discovery_etcd PRIVATE
- $<TARGET_PROPERTY:discovery_common,INCLUDE_DIRECTORIES>
- $<TARGET_PROPERTY:civetweb,INCLUDE_DIRECTORIES>
+ target_link_libraries(rsa_discovery_etcd PRIVATE Celix::log_helper Celix::etcdlib_static)
+ target_include_directories(rsa_discovery_etcd PRIVATE src)
+ target_include_directories(rsa_discovery_etcd PRIVATE
+ $<TARGET_PROPERTY:Celix::rsa_discovery_common,INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::civetweb,INCLUDE_DIRECTORIES>
${CURL_INCLUDE_DIR}
${JANSSON_INCLUDE_DIR}
${LIBXML2_INCLUDE_DIR}
)
- target_link_libraries(discovery_etcd PRIVATE ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} ${JANSSON_LIBRARIES})
+ target_link_libraries(rsa_discovery_etcd PRIVATE ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} ${JANSSON_LIBRARIES})
- install_bundle(discovery_etcd)
+ install_bundle(rsa_discovery_etcd)
+
+ #Setup target aliases to match external usage
+ add_library(Celix::rsa_discovery_etcd ALIAS rsa_discovery_etcd)
endif (RSA_DISCOVERY_ETCD)
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/discovery_shm/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/CMakeLists.txt b/remote_services/discovery_shm/CMakeLists.txt
index 61e54f7..fd822e6 100644
--- a/remote_services/discovery_shm/CMakeLists.txt
+++ b/remote_services/discovery_shm/CMakeLists.txt
@@ -20,7 +20,7 @@ if (RSA_DISCOVERY_SHM)
find_package(CURL REQUIRED)
find_package(LibXml2 REQUIRED)
- add_bundle(discovery_shm
+ add_bundle(rsa_discovery_shm
VERSION 0.0.1
SYMBOLIC_NAME "apache_celix_rsa_discovery_shm"
NAME "Apache Celix RSA Discovery SHM"
@@ -28,20 +28,21 @@ find_package(CURL REQUIRED)
src/discovery_shm.c
src/discovery_shmWatcher.c
src/discovery_impl.c
- $<TARGET_OBJECTS:discovery_common>
- $<TARGET_OBJECTS:civetweb>
+ $<TARGET_OBJECTS:Celix::rsa_discovery_common>
+ $<TARGET_OBJECTS:Celix::civetweb>
)
- target_include_directories(discovery_shm PRIVATE
+ target_include_directories(rsa_discovery_shm PRIVATE
src
${LIBXML2_INCLUDE_DIR}
${CURL_INCLUDE_DIR}
- $<TARGET_PROPERTY:discovery_common,INCLUDE_DIRECTORIES>
- $<TARGET_PROPERTY:civetweb,INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::rsa_discovery_common,INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::civetweb,INCLUDE_DIRECTORIES>
)
- target_link_libraries(discovery_shm PRIVATE Celix::framework ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES})
+ target_link_libraries(rsa_discovery_shm PRIVATE Celix::framework ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES})
- install_bundle(discovery_shm)
-
+ install_bundle(rsa_discovery_shm)
+ #Setup target aliases to match external usage
+ add_library(Celix::rsa_discovery_shm ALIAS rsa_discovery_shm)
endif (RSA_DISCOVERY_SHM)
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/examples/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/CMakeLists.txt b/remote_services/examples/CMakeLists.txt
index 2b1f35f..78bfbac 100644
--- a/remote_services/examples/CMakeLists.txt
+++ b/remote_services/examples/CMakeLists.txt
@@ -48,13 +48,13 @@ if (RSA_EXAMPLES)
add_deploy(remote-services-dfi
NAME "server"
GROUP "remote-services/remote-services-dfi"
- BUNDLES discovery_etcd topology_manager remote_service_admin_dfi calculator Celix::shell Celix::shell_tui Celix::log_service Celix::log_writer_stdout
+ BUNDLES Celix::rsa_discovery_etcd Celix::rsa_topology_manager Celix::rsa_dfi calculator Celix::shell Celix::shell_tui Celix::log_service Celix::log_writer_stdout
)
add_deploy("remote-services-dfi-client"
NAME "client"
GROUP "remote-services/remote-services-dfi"
- BUNDLES topology_manager remote_service_admin_dfi Celix::shell Celix::shell_tui Celix::log_service Celix::log_writer_stdout calculator_shell discovery_etcd
+ BUNDLES Celix::rsa_topology_manager Celix::rsa_dfi Celix::shell Celix::shell_tui Celix::log_service Celix::log_writer_stdout calculator_shell Celix::rsa_discovery_etcd
)
endif ()
endif (RSA_EXAMPLES)
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/examples/calculator_service/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/CMakeLists.txt b/remote_services/examples/calculator_service/CMakeLists.txt
index ff4d2d7..5d97d16 100644
--- a/remote_services/examples/calculator_service/CMakeLists.txt
+++ b/remote_services/examples/calculator_service/CMakeLists.txt
@@ -23,7 +23,7 @@ add_bundle(calculator
VERSION 0.0.1
)
target_include_directories(calculator PRIVATE src)
-target_link_libraries(calculator PRIVATE Celix::remote_service_admin_api calculator_api)
+target_link_libraries(calculator PRIVATE Celix::rsa_api calculator_api)
get_target_property(DESCR calculator_api INTERFACE_CALCULATOR_DESCRIPTOR)
bundle_files(calculator ${DESCR} DESTINATION .)
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/remote_service_admin_api/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/CMakeLists.txt b/remote_services/remote_service_admin_api/CMakeLists.txt
index a7d0640..f665576 100644
--- a/remote_services/remote_service_admin_api/CMakeLists.txt
+++ b/remote_services/remote_service_admin_api/CMakeLists.txt
@@ -15,8 +15,8 @@
# specific language governing permissions and limitations
# under the License.
-add_library(remote_service_admin_api INTERFACE)
-target_include_directories(remote_service_admin_api INTERFACE include)
+add_library(rsa_api INTERFACE)
+target_include_directories(rsa_api INTERFACE include)
install (FILES
include/remote_endpoint_impl.h
@@ -42,4 +42,4 @@ install (FILES
)
#Setup target aliases to match external usage
-add_library(Celix::remote_service_admin_api ALIAS remote_service_admin_api)
+add_library(Celix::rsa_api ALIAS rsa_api)
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/remote_service_admin_common/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/CMakeLists.txt b/remote_services/remote_service_admin_common/CMakeLists.txt
index a421cda..018d868 100644
--- a/remote_services/remote_service_admin_common/CMakeLists.txt
+++ b/remote_services/remote_service_admin_common/CMakeLists.txt
@@ -15,12 +15,13 @@
# specific language governing permissions and limitations
# under the License.
-add_library(remote_service_admin_common STATIC
+add_library(rsa_common STATIC
src/endpoint_description.c
src/export_registration_impl.c
src/import_registration_impl.c
)
-target_include_directories(remote_service_admin_common PRIVATE src)
-target_link_libraries(remote_service_admin_common PUBLIC Celix::framework Celix::remote_service_admin_api Celix::log_helper)
+target_include_directories(rsa_common PRIVATE src)
+target_link_libraries(rsa_common PUBLIC Celix::framework Celix::rsa_api Celix::log_helper)
-add_library(Celix::remote_service_admin_common ALIAS remote_service_admin_common)
\ No newline at end of file
+#Setup target aliases to match external usage
+add_library(Celix::rsa_common ALIAS rsa_common)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/remote_service_admin_dfi/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/CMakeLists.txt b/remote_services/remote_service_admin_dfi/CMakeLists.txt
index 206c6dc..ea79c31 100644
--- a/remote_services/remote_service_admin_dfi/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/CMakeLists.txt
@@ -23,7 +23,7 @@ if (RSA_REMOTE_SERVICE_ADMIN_DFI)
find_package(CURL REQUIRED)
find_package(Jansson REQUIRED)
- add_bundle(remote_service_admin_dfi
+ add_bundle(rsa_dfi
VERSION 0.9.0
SYMBOLIC_NAME "apache_celix_remote_service_admin_dfi"
NAME "Apache Celix Remote Service Admin Dynamic Function Interface (DFI)"
@@ -33,21 +33,21 @@ if (RSA_REMOTE_SERVICE_ADMIN_DFI)
src/export_registration_dfi.c
src/import_registration_dfi.c
src/dfi_utils.c
- $<TARGET_OBJECTS:civetweb>
+ $<TARGET_OBJECTS:Celix::civetweb>
)
- target_include_directories(remote_service_admin_dfi PRIVATE src $<TARGET_PROPERTY:civetweb,INCLUDE_DIRECTORIES>)
- target_link_libraries(remote_service_admin_dfi PRIVATE
+ target_include_directories(rsa_dfi PRIVATE src $<TARGET_PROPERTY:Celix::civetweb,INCLUDE_DIRECTORIES>)
+ target_link_libraries(rsa_dfi PRIVATE
Celix::dfi_static
Celix::log_helper
- Celix::remote_service_admin_common
+ Celix::rsa_common
${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
- install_bundle(remote_service_admin_dfi)
+ install_bundle(rsa_dfi)
if (ENABLE_TESTING)
add_subdirectory(test)
endif()
#Setup target aliases to match external usage
- add_library(Celix::remote_service_admin_dfi ALIAS remote_service_admin_dfi)
+ add_library(Celix::rsa_dfi ALIAS rsa_dfi)
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/remote_service_admin_dfi/test/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/test/CMakeLists.txt b/remote_services/remote_service_admin_dfi/test/CMakeLists.txt
index a78a6d0..153b3d1 100644
--- a/remote_services/remote_service_admin_dfi/test/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/test/CMakeLists.txt
@@ -36,15 +36,14 @@ add_executable(test_rsa_dfi
target_include_directories(test_rsa_dfi PRIVATE src)
target_link_libraries(test_rsa_dfi PRIVATE ${CURL_LIBRARIES} ${CPPUTEST_LIBRARY}
Celix::framework
- Celix::remote_service_admin_api
- Celix::remote_service_admin_common
+ Celix::rsa_common
calculator_api)
-get_property(rsa_bundle_file TARGET remote_service_admin_dfi PROPERTY BUNDLE_FILE)
+get_property(rsa_bundle_file TARGET rsa_dfi PROPERTY BUNDLE_FILE)
get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE_FILE)
get_property(calculator_shell_bundle_file TARGET calculator_shell PROPERTY BUNDLE_FILE)
-get_property(discovery_configured_bundle_file TARGET discovery_configured PROPERTY BUNDLE_FILE)
-get_property(topology_manager_bundle_file TARGET topology_manager PROPERTY BUNDLE_FILE)
+get_property(discovery_configured_bundle_file TARGET rsa_discovery_configured PROPERTY BUNDLE_FILE)
+get_property(topology_manager_bundle_file TARGET Celix::rsa_topology_manager PROPERTY BUNDLE_FILE)
get_property(tst_bundle_file TARGET rsa_dfi_tst_bundle PROPERTY BUNDLE_FILE)
configure_file(config.properties.in config.properties)
@@ -52,7 +51,7 @@ configure_file(client.properties.in client.properties)
configure_file(server.properties.in server.properties)
add_dependencies(test_rsa_dfi
- remote_service_admin_dfi_bundle #note depend on the target creating the bundle zip not the lib target
+ rsa_dfi_bundle #note depend on the target creating the bundle zip not the lib target
calculator_bundle
)
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/topology_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/CMakeLists.txt b/remote_services/topology_manager/CMakeLists.txt
index defee5c..568054e 100644
--- a/remote_services/topology_manager/CMakeLists.txt
+++ b/remote_services/topology_manager/CMakeLists.txt
@@ -17,7 +17,7 @@
celix_subproject(RSA_TOPOLOGY_MANAGER "Option to enable building the Remote Service Admin Service SHM bundle" ON DEPS REMOTE_SERVICE_ADMIN_DFI)
if (RSA_TOPOLOGY_MANAGER)
- add_bundle(topology_manager
+ add_bundle(rsa_topology_manager
SOURCES
src/topology_manager
src/scope
@@ -26,11 +26,11 @@ if (RSA_TOPOLOGY_MANAGER)
SYMBOLIC_NAME "apache_celix_rs_topology_manager"
NAME "Apache Celix RS Topology Manager"
)
- target_include_directories(topology_manager PRIVATE src)
- target_include_directories(topology_manager PUBLIC include)
- target_link_libraries(topology_manager PRIVATE Celix::log_helper remote_service_admin_api)
+ target_include_directories(rsa_topology_manager PRIVATE src)
+ target_include_directories(rsa_topology_manager PUBLIC include)
+ target_link_libraries(rsa_topology_manager PRIVATE Celix::log_helper Celix::rsa_api)
- install_bundle(topology_manager)
+ install_bundle(rsa_topology_manager)
if (ENABLE_TESTING)
find_package(CppUTest REQUIRED)
@@ -41,4 +41,7 @@ if (RSA_TOPOLOGY_MANAGER)
include_directories(${CPPUTEST_EXT_INCLUDE_DIR})
add_subdirectory(tms_tst)
endif (ENABLE_TESTING)
+
+ #Setup target aliases to match external usage
+ add_library(Celix::rsa_topology_manager ALIAS rsa_topology_manager)
endif (RSA_TOPOLOGY_MANAGER)
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/topology_manager/tms_tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/tms_tst/CMakeLists.txt b/remote_services/topology_manager/tms_tst/CMakeLists.txt
index 5e27139..6dedf32 100644
--- a/remote_services/topology_manager/tms_tst/CMakeLists.txt
+++ b/remote_services/topology_manager/tms_tst/CMakeLists.txt
@@ -42,18 +42,16 @@ target_link_libraries(test_tm_scoped PRIVATE
Celix::framework
${CPPUTEST_LIBRARY}
${JANSSON_LIBRARY}
- Celix::log_helper
calculator_api
- Celix::remote_service_admin_api
- Celix::remote_service_admin_common
+ Celix::rsa_common
)
-add_dependencies(test_tm_scoped remote_service_admin_dfi_bundle topology_manager_bundle)
+add_dependencies(test_tm_scoped rsa_dfi_bundle rsa_topology_manager_bundle)
file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/config.properties"
CONTENT "
-cosgi.auto.start.1=$<TARGET_PROPERTY:remote_service_admin_dfi,BUNDLE_FILE> $<TARGET_PROPERTY:calculator,BUNDLE_FILE> $<TARGET_PROPERTY:topology_manager,BUNDLE_FILE> $<TARGET_PROPERTY:topology_manager_disc_mock_bundle,BUNDLE_FILE>
+cosgi.auto.start.1=$<TARGET_PROPERTY:Celix::rsa_dfi,BUNDLE_FILE> $<TARGET_PROPERTY:calculator,BUNDLE_FILE> $<TARGET_PROPERTY:Celix::rsa_topology_manager,BUNDLE_FILE> $<TARGET_PROPERTY:topology_manager_disc_mock_bundle,BUNDLE_FILE>
LOGHELPER_ENABLE_STDOUT_FALLBACK=true
org.osgi.framework.storage.clean=onFirstInit
")
@@ -61,7 +59,7 @@ org.osgi.framework.storage.clean=onFirstInit
file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/config_import.properties"
CONTENT "
-cosgi.auto.start.1=$<TARGET_PROPERTY:remote_service_admin_dfi,BUNDLE_FILE> $<TARGET_PROPERTY:calculator,BUNDLE_FILE> $<TARGET_PROPERTY:topology_manager,BUNDLE_FILE> $<TARGET_PROPERTY:topology_manager_test_bundle,BUNDLE_FILE>
+cosgi.auto.start.1=$<TARGET_PROPERTY:Celix::rsa_dfi,BUNDLE_FILE> $<TARGET_PROPERTY:calculator,BUNDLE_FILE> $<TARGET_PROPERTY:Celix::rsa_topology_manager,BUNDLE_FILE> $<TARGET_PROPERTY:topology_manager_test_bundle,BUNDLE_FILE>
LOGHELPER_ENABLE_STDOUT_FALLBACK=true
org.osgi.framework.storage.clean=onFirstInit
")
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt b/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
index 551995b..eaf0a26 100644
--- a/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
+++ b/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
@@ -32,4 +32,4 @@ bundle_files(topology_manager_test_bundle
DESTINATION .
)
-target_link_libraries(topology_manager_test_bundle PRIVATE ${CPPUTEST_LIBRARY} Celix::remote_service_admin_api calculator_api)
+target_link_libraries(topology_manager_test_bundle PRIVATE ${CPPUTEST_LIBRARY} Celix::rsa_api calculator_api)
http://git-wip-us.apache.org/repos/asf/celix/blob/486d4f0d/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt b/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt
index 653b69c..3e93174 100644
--- a/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt
+++ b/remote_services/topology_manager/tms_tst/disc_mock/CMakeLists.txt
@@ -23,6 +23,6 @@ add_bundle(topology_manager_disc_mock_bundle
)
target_include_directories(topology_manager_disc_mock_bundle PRIVATE
${CPPUTEST_INCLUDE_DIR}
- $<TARGET_PROPERTY:discovery_common,INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::rsa_discovery_common,INCLUDE_DIRECTORIES>
)
target_link_libraries(topology_manager_disc_mock_bundle PRIVATE ${CPPUTEST_LIBRARY} Celix::framework)
[07/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_common/src/export_registration_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/export_registration_impl.c b/remote_services/remote_service_admin_common/src/export_registration_impl.c
new file mode 100644
index 0000000..1c684e7
--- /dev/null
+++ b/remote_services/remote_service_admin_common/src/export_registration_impl.c
@@ -0,0 +1,257 @@
+/**
+ *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.
+ */
+/*
+ * export_registration_impl.c
+ *
+ * \date Oct 6, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+
+#include "constants.h"
+
+#include "celix_errno.h"
+
+#include "export_registration_impl.h"
+#include "remote_service_admin_impl.h"
+
+
+struct export_reference {
+ endpoint_description_pt endpoint;
+ service_reference_pt reference;
+};
+
+celix_status_t exportRegistration_endpointAdding(void * handle, service_reference_pt reference, void **service);
+celix_status_t exportRegistration_endpointAdded(void * handle, service_reference_pt reference, void *service);
+celix_status_t exportRegistration_endpointModified(void * handle, service_reference_pt reference, void *service);
+celix_status_t exportRegistration_endpointRemoved(void * handle, service_reference_pt reference, void *service);
+
+celix_status_t exportRegistration_createEndpointTracker(export_registration_pt registration, service_tracker_pt *tracker);
+
+celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, remote_service_admin_pt rsa, bundle_context_pt context, export_registration_pt *registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *registration = calloc(1, sizeof(**registration));
+ if (!*registration) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*registration)->context = context;
+ (*registration)->closed = false;
+ (*registration)->endpointDescription = endpoint;
+ (*registration)->reference = reference;
+ (*registration)->rsa = rsa;
+ (*registration)->tracker = NULL;
+ (*registration)->endpoint = NULL;
+ (*registration)->endpointTracker = NULL;
+ (*registration)->exportReference = NULL;
+ (*registration)->bundle = NULL;
+ (*registration)->loghelper = helper;
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_destroy(export_registration_pt *registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ remoteServiceAdmin_destroyEndpointDescription(&(*registration)->endpointDescription);
+ free(*registration);
+
+ return status;
+}
+
+celix_status_t exportRegistration_startTracking(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (registration->endpointTracker == NULL) {
+ status = exportRegistration_createEndpointTracker(registration, ®istration->endpointTracker);
+ if (status == CELIX_SUCCESS) {
+ status = serviceTracker_open(registration->endpointTracker);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_stopTracking(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (registration->endpointTracker != NULL) {
+ status = serviceTracker_close(registration->endpointTracker);
+ if (status != CELIX_SUCCESS) {
+ logHelper_log(registration->loghelper, OSGI_LOGSERVICE_ERROR, "EXPORT_REGISTRATION: Could not close endpoint tracker");
+ }
+ else {
+ status = serviceTracker_destroy(registration->endpointTracker);
+ }
+ }
+ if (registration->tracker != NULL) {
+ status = serviceTracker_close(registration->tracker);
+ if (status != CELIX_SUCCESS) {
+ logHelper_log(registration->loghelper, OSGI_LOGSERVICE_ERROR, "EXPORT_REGISTRATION: Could not close service tracker");
+ }
+ else {
+ status = serviceTracker_destroy(registration->tracker);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_createEndpointTracker(export_registration_pt registration, service_tracker_pt *tracker) {
+ celix_status_t status;
+
+ service_tracker_customizer_pt customizer = NULL;
+
+ status = serviceTrackerCustomizer_create(registration, exportRegistration_endpointAdding,
+ exportRegistration_endpointAdded, exportRegistration_endpointModified, exportRegistration_endpointRemoved, &customizer);
+
+ if (status == CELIX_SUCCESS) {
+ char filter[512];
+
+ snprintf(filter, 512, "(&(%s=%s)(remote.interface=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, (char*) OSGI_RSA_REMOTE_ENDPOINT, registration->endpointDescription->service);
+ status = serviceTracker_createWithFilter(registration->context, filter, customizer, tracker);
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_endpointAdding(void * handle, service_reference_pt reference, void **service) {
+ celix_status_t status;
+ export_registration_pt registration = handle;
+
+ status = bundleContext_getService(registration->context, reference, service);
+
+ return status;
+}
+
+celix_status_t exportRegistration_endpointAdded(void * handle, service_reference_pt reference, void *endpoint_service) {
+ celix_status_t status = CELIX_SUCCESS;
+ export_registration_pt registration = handle;
+
+ remote_endpoint_service_pt endpoint = endpoint_service;
+ if (registration->endpoint == NULL) {
+ registration->endpoint = endpoint;
+ void *service = NULL;
+ status = bundleContext_getService(registration->context, registration->reference, &service);
+ if (status == CELIX_SUCCESS) {
+ endpoint->setService(endpoint->endpoint, service);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_endpointModified(void * handle, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ return status;
+}
+
+celix_status_t exportRegistration_endpointRemoved(void * handle, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+ export_registration_pt registration = handle;
+
+ remote_endpoint_service_pt endpoint = service;
+ if (registration->endpoint != NULL) {
+ endpoint->setService(endpoint->endpoint, NULL);
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_open(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ const char *bundleStore = NULL;
+
+ bundleContext_getProperty(registration->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore);
+
+ if (bundleStore == NULL) {
+ bundleStore = DEFAULT_BUNDLE_STORE;
+ }
+ char name[256];
+
+ snprintf(name, 256, "%s/%s_endpoint.zip", bundleStore, registration->endpointDescription->service);
+
+ status = bundleContext_installBundle(registration->context, name, ®istration->bundle);
+ if (status == CELIX_SUCCESS) {
+ status = bundle_start(registration->bundle);
+ if (status == CELIX_SUCCESS) {
+ }
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_close(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ exportRegistration_stopTracking(registration);
+
+ bundle_uninstall(registration->bundle);
+
+
+ return status;
+}
+
+celix_status_t exportRegistration_getException(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *reference) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ registration->exportReference = calloc(1, sizeof(*registration->exportReference));
+
+ if (registration->exportReference == NULL) {
+ status = CELIX_ENOMEM;
+ } else {
+ registration->exportReference->endpoint = registration->endpointDescription;
+ registration->exportReference->reference = registration->reference;
+ }
+
+ *reference = registration->exportReference;
+
+ return status;
+}
+
+celix_status_t exportRegistration_setEndpointDescription(export_registration_pt registration, endpoint_description_pt endpointDescription) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ registration->endpointDescription = endpointDescription;
+
+ return status;
+}
+
+celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *endpoint = reference->endpoint;
+
+ return status;
+}
+
+celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service) {
+ celix_status_t status = CELIX_SUCCESS;
+ *service = reference->reference;
+ return status;
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_common/src/export_registration_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/export_registration_impl.h b/remote_services/remote_service_admin_common/src/export_registration_impl.h
new file mode 100644
index 0000000..bb276f9
--- /dev/null
+++ b/remote_services/remote_service_admin_common/src/export_registration_impl.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.
+ */
+/*
+ * export_registration_impl.h
+ *
+ * \date Oct 6, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef EXPORT_REGISTRATION_IMPL_H_
+#define EXPORT_REGISTRATION_IMPL_H_
+
+#include "remote_service_admin.h"
+#include "remote_endpoint.h"
+#include "service_tracker.h"
+#include "log_helper.h"
+
+struct export_registration {
+ bundle_context_pt context;
+ remote_service_admin_pt rsa;
+ endpoint_description_pt endpointDescription;
+ service_reference_pt reference;
+ log_helper_pt loghelper;
+
+ service_tracker_pt tracker;
+ service_tracker_pt endpointTracker;
+
+ remote_endpoint_service_pt endpoint;
+
+ export_reference_pt exportReference;
+ bundle_pt bundle;
+
+ bool closed;
+};
+
+celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, remote_service_admin_pt rsa, bundle_context_pt context, export_registration_pt *registration);
+celix_status_t exportRegistration_destroy(export_registration_pt *registration);
+celix_status_t exportRegistration_open(export_registration_pt registration);
+
+celix_status_t exportRegistration_setEndpointDescription(export_registration_pt registration, endpoint_description_pt endpointDescription);
+celix_status_t exportRegistration_startTracking(export_registration_pt registration);
+celix_status_t exportRegistration_stopTracking(export_registration_pt registration);
+
+#endif /* EXPORT_REGISTRATION_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_common/src/import_registration_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/import_registration_impl.c b/remote_services/remote_service_admin_common/src/import_registration_impl.c
new file mode 100644
index 0000000..9a84327
--- /dev/null
+++ b/remote_services/remote_service_admin_common/src/import_registration_impl.c
@@ -0,0 +1,274 @@
+/**
+ *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.
+ */
+/*
+ * import_registration_impl.c
+ *
+ * \date Oct 14, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <constants.h>
+
+#include "celix_errno.h"
+
+#include "import_registration_impl.h"
+#include "remote_service_admin_impl.h"
+
+struct import_reference {
+ endpoint_description_pt endpoint;
+ service_reference_pt reference;
+};
+
+
+
+celix_status_t importRegistration_proxyFactoryAdding(void * handle, service_reference_pt reference, void **service);
+celix_status_t importRegistration_proxyFactoryAdded(void * handle, service_reference_pt reference, void *service);
+celix_status_t importRegistration_proxyFactoryModified(void * handle, service_reference_pt reference, void *service);
+celix_status_t importRegistration_proxyFactoryRemoved(void * handle, service_reference_pt reference, void *service);
+
+celix_status_t importRegistration_create(endpoint_description_pt endpoint, remote_service_admin_pt rsa, sendToHandle sendToCallback, bundle_context_pt context, import_registration_pt *registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *registration = calloc(1, sizeof(**registration));
+ if (!*registration) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*registration)->context = context;
+ (*registration)->closed = false;
+ (*registration)->endpointDescription = endpoint;
+ (*registration)->rsa = rsa;
+ (*registration)->sendToCallback = sendToCallback;
+ (*registration)->reference = NULL;
+ (*registration)->importReference = NULL;
+ }
+
+ return status;
+}
+
+celix_status_t importRegistration_destroy(import_registration_pt registration)
+{
+ free(registration);
+
+ return CELIX_SUCCESS;
+}
+
+
+celix_status_t importRegistrationFactory_create(log_helper_pt helper, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *registration_factory = calloc(1, sizeof(**registration_factory));
+ if (!*registration_factory) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*registration_factory)->serviceName = strdup(serviceName);
+ (*registration_factory)->context = context;
+ (*registration_factory)->bundle = NULL;
+ (*registration_factory)->loghelper = helper;
+
+ arrayList_create(&(*registration_factory)->registrations);
+ }
+
+ return status;
+}
+
+
+
+celix_status_t importRegistrationFactory_destroy(import_registration_factory_pt* registration_factory) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (*registration_factory != NULL)
+ {
+ free((*registration_factory)->serviceName);
+ arrayList_destroy((*registration_factory)->registrations);
+
+ serviceTracker_destroy((*registration_factory)->proxyFactoryTracker);
+ free(*registration_factory);
+
+ *registration_factory = NULL;
+ }
+
+
+ return status;
+}
+
+
+celix_status_t importRegistrationFactory_open(import_registration_factory_pt registration_factory)
+{
+ celix_status_t status;
+
+ const char *bundleStore = NULL;
+ bundleContext_getProperty(registration_factory->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore);
+
+ if (bundleStore == NULL) {
+ bundleStore = DEFAULT_BUNDLE_STORE;
+ }
+
+ char name[256];
+ snprintf(name, 256, "%s/%s_proxy.zip", bundleStore, registration_factory->serviceName);
+
+ status = bundleContext_installBundle(registration_factory->context, name, ®istration_factory->bundle);
+
+ if (status == CELIX_SUCCESS) {
+ status = bundle_start(registration_factory->bundle);
+ if (status == CELIX_SUCCESS) {
+ logHelper_log(registration_factory->loghelper, OSGI_LOGSERVICE_INFO, "%s successfully started.", name);
+ }
+ }
+ else {
+ logHelper_log(registration_factory->loghelper, OSGI_LOGSERVICE_ERROR, "%s could not be installed.", name);
+ }
+
+ return status;
+}
+
+celix_status_t importRegistrationFactory_close(import_registration_factory_pt registration_factory)
+{
+ celix_status_t status = CELIX_SUCCESS;
+
+
+ if (registration_factory->proxyFactoryTracker != NULL) {
+ serviceTracker_close(registration_factory->proxyFactoryTracker);
+ }
+
+ if (registration_factory->bundle != NULL) {
+ bundle_uninstall(registration_factory->bundle);
+ }
+
+ return status;
+}
+
+
+celix_status_t importRegistration_createProxyFactoryTracker(import_registration_factory_pt registration_factory, service_tracker_pt *tracker) {
+ celix_status_t status;
+ service_tracker_customizer_pt customizer = NULL;
+
+ status = serviceTrackerCustomizer_create(registration_factory, importRegistration_proxyFactoryAdding, importRegistration_proxyFactoryAdded, importRegistration_proxyFactoryModified, importRegistration_proxyFactoryRemoved, &customizer);
+
+ if (status == CELIX_SUCCESS) {
+ char filter[512];
+
+ snprintf(filter, 512, "(&(%s=%s)(proxy.interface=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, (char*) OSGI_RSA_REMOTE_PROXY_FACTORY, registration_factory->serviceName);
+ status = serviceTracker_createWithFilter(registration_factory->context, filter, customizer, tracker);
+
+ if (status == CELIX_SUCCESS)
+ {
+ serviceTracker_open(*tracker);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t importRegistration_proxyFactoryAdding(void * handle, service_reference_pt reference, void **service) {
+ celix_status_t status = CELIX_SUCCESS;
+ import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
+
+ bundleContext_getService(registration_factory->context, reference, service);
+
+ return status;
+}
+
+celix_status_t importRegistration_proxyFactoryAdded(void * handle, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
+ registration_factory->trackedFactory = (remote_proxy_factory_service_pt) service;
+
+ return status;
+}
+
+celix_status_t importRegistration_proxyFactoryModified(void * handle, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ return status;
+}
+
+celix_status_t importRegistration_proxyFactoryRemoved(void * handle, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
+ registration_factory->trackedFactory = NULL;
+
+ return status;
+}
+
+
+
+celix_status_t importRegistrationFactory_install(log_helper_pt helper, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory)
+{
+ celix_status_t status;
+
+ if ( (status = importRegistrationFactory_create(helper, serviceName, context, registration_factory)) == CELIX_SUCCESS) {
+ // starting the proxy tracker first allows us to pick up already available proxy factories
+ importRegistration_createProxyFactoryTracker(*registration_factory, &((*registration_factory)->proxyFactoryTracker));
+ logHelper_log((*registration_factory)->loghelper, OSGI_LOGSERVICE_INFO, "remoteServiceAdmin_importService: new registration_factory added for %s at %p", serviceName, (*registration_factory)->proxyFactoryTracker);
+
+ // check whether factory is available
+ if (((*registration_factory)->trackedFactory == NULL) && ((status = importRegistrationFactory_open(*registration_factory)) != CELIX_SUCCESS)) {
+ logHelper_log((*registration_factory)->loghelper, OSGI_LOGSERVICE_ERROR, "remoteServiceAdmin_importService: cannot open registration_factory for %s.", serviceName);
+
+ importRegistrationFactory_close(*registration_factory);
+ importRegistrationFactory_destroy(registration_factory);
+ }
+ }
+
+ return status;
+}
+
+
+
+
+celix_status_t importRegistration_getException(import_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+
+celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (registration->importReference == NULL) {
+ registration->importReference = calloc(1, sizeof(*registration->importReference));
+ if (registration->importReference == NULL) {
+ status = CELIX_ENOMEM;
+ } else {
+ registration->importReference->endpoint = registration->endpointDescription;
+ registration->importReference->reference = registration->reference;
+ }
+ }
+
+ *reference = registration->importReference;
+
+ return status;
+}
+
+
+celix_status_t importReference_getImportedEndpoint(import_reference_pt reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t importReference_getImportedService(import_reference_pt reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_common/src/import_registration_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/import_registration_impl.h b/remote_services/remote_service_admin_common/src/import_registration_impl.h
new file mode 100644
index 0000000..7aa397f
--- /dev/null
+++ b/remote_services/remote_service_admin_common/src/import_registration_impl.h
@@ -0,0 +1,81 @@
+/**
+ *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.
+ */
+/*
+ * import_registration_impl.h
+ *
+ * \date Oct 14, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef IMPORT_REGISTRATION_IMPL_H_
+#define IMPORT_REGISTRATION_IMPL_H_
+
+#include "remote_service_admin.h"
+#include "remote_proxy.h"
+#include "service_tracker.h"
+#include "log_helper.h"
+
+struct import_registration {
+ bundle_context_pt context;
+ endpoint_description_pt endpointDescription;
+
+ service_reference_pt reference;
+ import_reference_pt importReference;
+
+ remote_service_admin_pt rsa;
+ sendToHandle sendToCallback;
+
+ bool closed;
+};
+
+
+
+struct import_registration_factory
+{
+ char* serviceName;
+ log_helper_pt loghelper;
+ remote_proxy_factory_service_pt trackedFactory;
+ service_tracker_pt proxyFactoryTracker;
+ bundle_context_pt context;
+ array_list_pt registrations;
+ bundle_pt bundle;
+};
+
+
+celix_status_t importRegistration_create(endpoint_description_pt endpoint, remote_service_admin_pt rsa, sendToHandle callback, bundle_context_pt context, import_registration_pt *registration);
+celix_status_t importRegistration_destroy(import_registration_pt registration);
+
+celix_status_t importRegistration_setEndpointDescription(import_registration_pt registration, endpoint_description_pt endpointDescription);
+celix_status_t importRegistration_setHandler(import_registration_pt registration, void * handler);
+celix_status_t importRegistration_setCallback(import_registration_pt registration, sendToHandle callback);
+
+celix_status_t importRegistration_getException(import_registration_pt registration);
+celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference);
+
+celix_status_t importRegistration_createProxyFactoryTracker(import_registration_factory_pt registration_factory, service_tracker_pt *tracker);
+
+celix_status_t importRegistrationFactory_destroy(import_registration_factory_pt* registration_factory);
+//celix_status_t importRegistrationFactory_open(import_registration_factory_pt registration_factory);
+celix_status_t importRegistrationFactory_close(import_registration_factory_pt registration_factory);
+celix_status_t importRegistrationFactory_install(log_helper_pt helper, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory);
+
+
+
+#endif /* IMPORT_REGISTRATION_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_common/src/remote_proxy_factory_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/remote_proxy_factory_impl.c b/remote_services/remote_service_admin_common/src/remote_proxy_factory_impl.c
new file mode 100644
index 0000000..9f996d6
--- /dev/null
+++ b/remote_services/remote_service_admin_common/src/remote_proxy_factory_impl.c
@@ -0,0 +1,252 @@
+/**
+ * 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.
+ */
+
+/*
+ * remote_proxy_factory_impl.c
+ *
+ * \date 22 Dec 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "remote_proxy.h"
+
+typedef struct proxy_instance {
+ service_registration_pt registration_ptr;
+ void *service;
+ properties_pt properties;
+} *proxy_instance_pt;
+
+static celix_status_t remoteProxyFactory_registerProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback);
+static celix_status_t remoteProxyFactory_unregisterProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription);
+
+celix_status_t remoteProxyFactory_create(bundle_context_pt context, char *service, void *handle,
+ createProxyService create, destroyProxyService destroy,
+ remote_proxy_factory_pt *remote_proxy_factory_ptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *remote_proxy_factory_ptr = calloc(1, sizeof(**remote_proxy_factory_ptr));
+ if (!*remote_proxy_factory_ptr) {
+ status = CELIX_ENOMEM;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ (*remote_proxy_factory_ptr)->context_ptr = context;
+ (*remote_proxy_factory_ptr)->service = strdup(service);
+
+ (*remote_proxy_factory_ptr)->remote_proxy_factory_service_ptr = NULL;
+ (*remote_proxy_factory_ptr)->properties = NULL;
+ (*remote_proxy_factory_ptr)->registration = NULL;
+
+ (*remote_proxy_factory_ptr)->proxy_instances = hashMap_create(NULL, NULL, NULL, NULL);
+
+ (*remote_proxy_factory_ptr)->handle = handle;
+
+ (*remote_proxy_factory_ptr)->create_proxy_service_ptr = create;
+ (*remote_proxy_factory_ptr)->destroy_proxy_service_ptr = destroy;
+ }
+
+ return status;
+}
+
+celix_status_t remoteProxyFactory_destroy(remote_proxy_factory_pt *remote_proxy_factory_ptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!*remote_proxy_factory_ptr) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ if ((*remote_proxy_factory_ptr)->proxy_instances) {
+ hashMap_destroy((*remote_proxy_factory_ptr)->proxy_instances, false, false);
+ (*remote_proxy_factory_ptr)->proxy_instances = NULL;
+ }
+ if ((*remote_proxy_factory_ptr)->service) {
+ free((*remote_proxy_factory_ptr)->service);
+ (*remote_proxy_factory_ptr)->service = NULL;
+ }
+ free(*remote_proxy_factory_ptr);
+ *remote_proxy_factory_ptr = NULL;
+ }
+
+ return status;
+}
+
+celix_status_t remoteProxyFactory_register(remote_proxy_factory_pt remote_proxy_factory_ptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ remote_proxy_factory_ptr->remote_proxy_factory_service_ptr = calloc(1, sizeof(*remote_proxy_factory_ptr->remote_proxy_factory_service_ptr));
+ if (!remote_proxy_factory_ptr->remote_proxy_factory_service_ptr) {
+ status = CELIX_ENOMEM;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->factory = remote_proxy_factory_ptr;
+ remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->registerProxyService = remoteProxyFactory_registerProxyService;
+ remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->unregisterProxyService = remoteProxyFactory_unregisterProxyService;
+
+ remote_proxy_factory_ptr->properties = properties_create();
+ if (!remote_proxy_factory_ptr->properties) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ properties_set(remote_proxy_factory_ptr->properties, "proxy.interface", remote_proxy_factory_ptr->service);
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = bundleContext_registerService(remote_proxy_factory_ptr->context_ptr, OSGI_RSA_REMOTE_PROXY_FACTORY,
+ remote_proxy_factory_ptr->remote_proxy_factory_service_ptr, remote_proxy_factory_ptr->properties, &remote_proxy_factory_ptr->registration);
+ }
+
+ return status;
+}
+
+celix_status_t remoteProxyFactory_unregister(remote_proxy_factory_pt remote_proxy_factory_ptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!remote_proxy_factory_ptr) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ // #TODO Remove proxy registrations
+ if (status == CELIX_SUCCESS) {
+
+ hash_map_iterator_pt iter = hashMapIterator_create(remote_proxy_factory_ptr->proxy_instances);
+ while(hashMapIterator_hasNext(iter)){
+ proxy_instance_pt proxy_instance_ptr = (proxy_instance_pt)hashMapIterator_nextValue(iter);
+
+ if (proxy_instance_ptr->service) {
+ remote_proxy_factory_ptr->destroy_proxy_service_ptr(remote_proxy_factory_ptr->handle, proxy_instance_ptr->service);
+ }
+ free(proxy_instance_ptr);
+ }
+ hashMapIterator_destroy(iter);
+
+ if (remote_proxy_factory_ptr->registration) {
+ status = serviceRegistration_unregister(remote_proxy_factory_ptr->registration);
+ remote_proxy_factory_ptr->properties = NULL;
+ }
+ if (remote_proxy_factory_ptr->properties) {
+ properties_destroy(remote_proxy_factory_ptr->properties);
+ }
+ if (remote_proxy_factory_ptr->remote_proxy_factory_service_ptr) {
+ free(remote_proxy_factory_ptr->remote_proxy_factory_service_ptr);
+ }
+ }
+
+ return status;
+}
+
+
+static celix_status_t remoteProxyFactory_registerProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback) {
+ celix_status_t status = CELIX_SUCCESS;
+ proxy_instance_pt proxy_instance_ptr = NULL;
+
+ if (!remote_proxy_factory_ptr || !remote_proxy_factory_ptr->create_proxy_service_ptr) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ proxy_instance_ptr = calloc(1, sizeof(*proxy_instance_ptr));
+ if (!proxy_instance_ptr) {
+ status = CELIX_ENOMEM;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ proxy_instance_ptr->properties = properties_create();
+ if (!proxy_instance_ptr->properties) {
+ status = CELIX_ENOMEM;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = remote_proxy_factory_ptr->create_proxy_service_ptr(remote_proxy_factory_ptr->handle, endpointDescription, rsa, sendToCallback, proxy_instance_ptr->properties, &proxy_instance_ptr->service);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ properties_set(proxy_instance_ptr->properties, "proxy.interface", remote_proxy_factory_ptr->service);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(endpointDescription->properties);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ char *key = hashMapEntry_getKey(entry);
+ char *value = hashMapEntry_getValue(entry);
+
+ properties_set(proxy_instance_ptr->properties, key, value);
+ }
+ hashMapIterator_destroy(iter);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = bundleContext_registerService(remote_proxy_factory_ptr->context_ptr, remote_proxy_factory_ptr->service, proxy_instance_ptr->service, proxy_instance_ptr->properties, &proxy_instance_ptr->registration_ptr);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ hashMap_put(remote_proxy_factory_ptr->proxy_instances, endpointDescription, proxy_instance_ptr);
+ }
+
+ if(status!=CELIX_SUCCESS){
+ if(proxy_instance_ptr != NULL){
+ if(proxy_instance_ptr->properties != NULL){
+ properties_destroy(proxy_instance_ptr->properties);
+ }
+ free(proxy_instance_ptr);
+ }
+ }
+
+ return status;
+}
+
+static celix_status_t remoteProxyFactory_unregisterProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription) {
+ celix_status_t status = CELIX_SUCCESS;
+ proxy_instance_pt proxy_instance_ptr = NULL;
+
+ if (!remote_proxy_factory_ptr || !endpointDescription || !remote_proxy_factory_ptr->proxy_instances || !remote_proxy_factory_ptr->handle) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ proxy_instance_ptr = hashMap_remove(remote_proxy_factory_ptr->proxy_instances, endpointDescription);
+ if (proxy_instance_ptr == NULL) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ if (proxy_instance_ptr->registration_ptr) {
+ status = serviceRegistration_unregister(proxy_instance_ptr->registration_ptr);
+ proxy_instance_ptr->properties = NULL;
+ }
+ if (proxy_instance_ptr->service) {
+ status = remote_proxy_factory_ptr->destroy_proxy_service_ptr(remote_proxy_factory_ptr->handle, proxy_instance_ptr->service);
+ }
+ if (proxy_instance_ptr->properties) {
+ properties_destroy(proxy_instance_ptr->properties);
+ }
+ free(proxy_instance_ptr);
+ }
+
+ return status;
+}
+
+
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_common/src/remote_service_admin_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/remote_service_admin_impl.h b/remote_services/remote_service_admin_common/src/remote_service_admin_impl.h
new file mode 100644
index 0000000..e8a5e1f
--- /dev/null
+++ b/remote_services/remote_service_admin_common/src/remote_service_admin_impl.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.
+ */
+/*
+ * remote_service_admin_impl.h
+ *
+ * \date Dec 5, 2013
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef REMOTE_SERVICE_ADMIN_IMPL_H_
+#define REMOTE_SERVICE_ADMIN_IMPL_H_
+
+#include "remote_service_admin.h"
+
+#define BUNDLE_STORE_PROPERTY_NAME "ENDPOINTS"
+#define DEFAULT_BUNDLE_STORE "endpoints"
+
+celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin);
+celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin);
+
+celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *methodSignature, char **reply, int* replyStatus);
+
+celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
+celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration);
+celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services);
+celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services);
+celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
+celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration);
+
+celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description);
+
+#endif /* REMOTE_SERVICE_ADMIN_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt b/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
index 01ab9bd..3efabf8 100644
--- a/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
@@ -15,33 +15,20 @@
# specific language governing permissions and limitations
# under the License.
-include_directories(
- private/include
- ${PROJECT_SOURCE_DIR}/utils/public/include
- ${PROJECT_SOURCE_DIR}/log_service/public/include
- ${PROJECT_SOURCE_DIR}/remote_services/utils/private/include
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/include
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_http/private/include
- ${PROJECT_SOURCE_DIR}/dfi/public/include
- ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include
-)
-
add_bundle(remote_service_admin_dfi
VERSION 0.9.0
SYMBOLIC_NAME "apache_celix_remote_service_admin_dfi"
NAME "Apache Celix Remote Service Admin Dynamic Function Interface (DFI)"
SOURCES
- private/src/remote_service_admin_dfi.c
- private/src/remote_service_admin_activator.c
- private/src/export_registration_dfi.c
- private/src/import_registration_dfi.c
- private/src/dfi_utils.c
-
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
-
- ${PROJECT_SOURCE_DIR}/remote_services/utils/private/src/civetweb.c
+ src/remote_service_admin_dfi.c
+ src/remote_service_admin_activator.c
+ src/export_registration_dfi.c
+ src/import_registration_dfi.c
+ src/dfi_utils.c
)
-target_link_libraries(remote_service_admin_dfi PRIVATE Celix::dfi Celix::log_helper ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
+target_include_directories(remote_service_admin_dfi PRIVATE src)
+target_link_libraries(remote_service_admin_dfi PRIVATE
+ Celix::dfi Celix::log_helper remote_service_admin_common
+ ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
install_bundle(remote_service_admin_dfi)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/private/include/dfi_utils.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/dfi_utils.h b/remote_services/remote_service_admin_dfi/rsa/private/include/dfi_utils.h
deleted file mode 100644
index cec8aa1..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/include/dfi_utils.h
+++ /dev/null
@@ -1,30 +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.
- */
-#ifndef DFI_UTILS_H_
-#define DFI_UTILS_H_
-
-#include "bundle.h"
-#include "bundle_context.h"
-#include <stdio.h>
-#include "celix_errno.h"
-
-
-celix_status_t dfi_findDescriptor(bundle_context_pt context, bundle_pt bundle, const char *name, FILE **out);
-
-#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h b/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
deleted file mode 100644
index 93f37ba..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
+++ /dev/null
@@ -1,38 +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.
- */
-
-#ifndef CELIX_EXPORT_REGISTRATION_DFI_H
-#define CELIX_EXPORT_REGISTRATION_DFI_H
-
-
-#include "export_registration.h"
-#include "log_helper.h"
-#include "endpoint_description.h"
-
-celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, bundle_context_pt context, export_registration_pt *registration);
-celix_status_t exportRegistration_close(export_registration_pt registration);
-void exportRegistration_destroy(export_registration_pt registration);
-
-celix_status_t exportRegistration_start(export_registration_pt registration);
-celix_status_t exportRegistration_stop(export_registration_pt registration);
-
-celix_status_t exportRegistration_call(export_registration_pt export, char *data, int datalength, char **response, int *responseLength);
-
-
-#endif //CELIX_EXPORT_REGISTRATION_DFI_H
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h b/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
deleted file mode 100644
index aac4bc7..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.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.
- */
-
-#ifndef CELIX_IMPORT_REGISTRATION_DFI_H
-#define CELIX_IMPORT_REGISTRATION_DFI_H
-
-#include "import_registration.h"
-#include "dfi_utils.h"
-
-#include <celix_errno.h>
-
-typedef void (*send_func_type)(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
-
-celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt description, const char *classObject, const char* serviceVersion,
- import_registration_pt *import);
-celix_status_t importRegistration_close(import_registration_pt import);
-void importRegistration_destroy(import_registration_pt import);
-
-celix_status_t importRegistration_setSendFn(import_registration_pt reg,
- send_func_type,
- void *handle);
-celix_status_t importRegistration_start(import_registration_pt import);
-celix_status_t importRegistration_stop(import_registration_pt import);
-
-celix_status_t importRegistration_getService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **service);
-celix_status_t importRegistration_ungetService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **service);
-
-#endif //CELIX_IMPORT_REGISTRATION_DFI_H
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h b/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h
deleted file mode 100644
index 8b282f1..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h
+++ /dev/null
@@ -1,57 +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.
- */
-/*
- * remote_service_admin_http_impl.h
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
-#define REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
-
-
-#include "bundle_context.h"
-#include "endpoint_description.h"
-
-//typedef struct remote_service_admin *remote_service_admin_pt;
-
-celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin);
-celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin);
-
-celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin);
-
-celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
-celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration);
-celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services);
-celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services);
-celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
-celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration);
-
-
-celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint);
-celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service);
-
-celix_status_t importReference_getImportedEndpoint(import_reference_pt reference);
-celix_status_t importReference_getImportedService(import_reference_pt reference);
-
-celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description);
-
-#endif /* REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/private/src/dfi_utils.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/dfi_utils.c b/remote_services/remote_service_admin_dfi/rsa/private/src/dfi_utils.c
deleted file mode 100644
index 1b1eb36..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/dfi_utils.c
+++ /dev/null
@@ -1,98 +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.
- */
-
-#include "dfi_utils.h"
-#include <stdlib.h>
-#include <unistd.h>
-
-static celix_status_t dfi_findFileForFramework(bundle_context_pt context, const char *fileName, FILE **out) {
- celix_status_t status;
-
- char pwd[1024];
- char path[1024];
- const char *extPath = NULL;
-
- status = bundleContext_getProperty(context, "CELIX_FRAMEWORK_EXTENDER_PATH", &extPath);
- if (status != CELIX_SUCCESS || extPath == NULL) {
- getcwd(pwd, sizeof(pwd));
- extPath = pwd;
- }
-
- snprintf(path, sizeof(path), "%s/%s", extPath, fileName);
-
- if (status == CELIX_SUCCESS) {
- FILE *df = fopen(path, "r");
- if (df == NULL) {
- status = CELIX_FILE_IO_EXCEPTION;
- } else {
- *out = df;
- }
- }
-
- return status;
-}
-
-static celix_status_t dfi_findFileForBundle(bundle_pt bundle, const char *fileName, FILE **out) {
- celix_status_t status;
-
- char *path = NULL;
- char metaInfFileName[512];
- snprintf(metaInfFileName, sizeof(metaInfFileName), "META-INF/descriptors/%s", fileName);
-
- status = bundle_getEntry(bundle, fileName, &path);
-
- if (status != CELIX_SUCCESS || path == NULL) {
- status = bundle_getEntry(bundle, metaInfFileName, &path);
- }
-
- if (status == CELIX_SUCCESS && path != NULL) {
- FILE *df = fopen(path, "r");
- if (df == NULL) {
- status = CELIX_FILE_IO_EXCEPTION;
- } else {
- *out = df;
- }
-
- }
-
- free(path);
- return status;
-}
-
-celix_status_t dfi_findDescriptor(bundle_context_pt context, bundle_pt bundle, const char *name, FILE **out) {
- celix_status_t status;
- char fileName[128];
-
- snprintf(fileName, 128, "%s.descriptor", name);
-
- long id;
- status = bundle_getBundleId(bundle, &id);
-
- if (status == CELIX_SUCCESS) {
- if (id == 0) {
- //framework bundle
- status = dfi_findFileForFramework(context, fileName, out);
- } else {
- //normal bundle
- status = dfi_findFileForBundle(bundle, fileName, out);
- }
- }
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
deleted file mode 100644
index b83b5a8..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
+++ /dev/null
@@ -1,251 +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.
- */
-
-#include <jansson.h>
-#include <dyn_interface.h>
-#include <json_serializer.h>
-#include <remote_constants.h>
-#include <remote_service_admin.h>
-#include <service_tracker_customizer.h>
-#include <service_tracker.h>
-#include <json_rpc.h>
-#include "constants.h"
-#include "export_registration_dfi.h"
-#include "dfi_utils.h"
-
-struct export_reference {
- endpoint_description_pt endpoint; //owner
- service_reference_pt reference;
-};
-
-struct export_registration {
- bundle_context_pt context;
- struct export_reference exportReference;
- char *servId;
- dyn_interface_type *intf; //owner
- service_tracker_pt tracker;
-
- celix_thread_mutex_t mutex;
- void *service; //protected by mutex
-
- //TODO add tracker and lock
- bool closed;
-};
-
-static void exportRegistration_addServ(export_registration_pt reg, service_reference_pt ref, void *service);
-static void exportRegistration_removeServ(export_registration_pt reg, service_reference_pt ref, void *service);
-
-celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, bundle_context_pt context, export_registration_pt *out) {
- celix_status_t status = CELIX_SUCCESS;
-
- const char *servId = NULL;
- status = serviceReference_getProperty(reference, "service.id", &servId);
- if (status != CELIX_SUCCESS) {
- logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "Cannot find service.id for ref");
- }
-
- export_registration_pt reg = NULL;
- if (status == CELIX_SUCCESS) {
- reg = calloc(1, sizeof(*reg));
- if (reg == NULL) {
- status = CELIX_ENOMEM;
- }
- }
-
-
- if (status == CELIX_SUCCESS) {
- reg->context = context;
- reg->exportReference.endpoint = endpoint;
- reg->exportReference.reference = reference;
- reg->closed = false;
-
- celixThreadMutex_create(®->mutex, NULL);
- }
-
- const char *exports = NULL;
- CELIX_DO_IF(status, serviceReference_getProperty(reference, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exports));
-
- bundle_pt bundle = NULL;
- CELIX_DO_IF(status, serviceReference_getBundle(reference, &bundle));
-
- FILE *descriptor = NULL;
- if (status == CELIX_SUCCESS) {
- status = dfi_findDescriptor(context, bundle, exports, &descriptor);
- }
-
- if (status != CELIX_SUCCESS || descriptor == NULL) {
- status = CELIX_BUNDLE_EXCEPTION;
- logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Cannot find/open descriptor for '%s'", exports);
- }
-
- if (status == CELIX_SUCCESS) {
- int rc = dynInterface_parse(descriptor, ®->intf);
- fclose(descriptor);
- if (rc != 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "RSA: Error parsing service descriptor.");
- }
- else{
- /* Add the interface version as a property in the properties_map */
- char* intfVersion = NULL;
- dynInterface_getVersionString(reg->intf, &intfVersion);
- const char *serviceVersion = properties_get(endpoint->properties,(char*) CELIX_FRAMEWORK_SERVICE_VERSION);
- if(serviceVersion!=NULL){
- if(strcmp(serviceVersion,intfVersion)!=0){
- logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "Service version (%s) and interface version from the descriptor (%s) are not the same!",serviceVersion,intfVersion);
- }
- }
- else{
- properties_set(endpoint->properties, (char*) CELIX_FRAMEWORK_SERVICE_VERSION, intfVersion);
- }
- }
- }
-
- if (status == CELIX_SUCCESS) {
- service_tracker_customizer_pt cust = NULL;
- status = serviceTrackerCustomizer_create(reg, NULL, (void *) exportRegistration_addServ, NULL,
- (void *) exportRegistration_removeServ, &cust);
- if (status == CELIX_SUCCESS) {
- char filter[32];
- snprintf(filter, 32, "(service.id=%s)", servId);
- status = serviceTracker_createWithFilter(reg->context, filter, cust, ®->tracker);
- }
- }
-
- if (status == CELIX_SUCCESS) {
- *out = reg;
- } else {
- logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Error creating export registration");
- exportRegistration_destroy(reg);
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_call(export_registration_pt export, char *data, int datalength, char **responseOut, int *responseLength) {
- int status = CELIX_SUCCESS;
-
- //printf("calling for '%s'\n");
-
- *responseLength = -1;
- celixThreadMutex_lock(&export->mutex);
- status = jsonRpc_call(export->intf, export->service, data, responseOut);
- celixThreadMutex_unlock(&export->mutex);
-
- return status;
-}
-
-void exportRegistration_destroy(export_registration_pt reg) {
- if (reg != NULL) {
- if (reg->intf != NULL) {
- dyn_interface_type *intf = reg->intf;
- reg->intf = NULL;
- dynInterface_destroy(intf);
- }
-
- if (reg->exportReference.endpoint != NULL) {
- endpoint_description_pt ep = reg->exportReference.endpoint;
- reg->exportReference.endpoint = NULL;
- endpointDescription_destroy(ep);
- }
- if (reg->tracker != NULL) {
- serviceTracker_destroy(reg->tracker);
- }
- celixThreadMutex_destroy(®->mutex);
-
- free(reg);
- }
-}
-
-celix_status_t exportRegistration_start(export_registration_pt reg) {
- celix_status_t status = CELIX_SUCCESS;
-
- serviceTracker_open(reg->tracker);
- return status;
-}
-
-
-celix_status_t exportRegistration_stop(export_registration_pt reg) {
- celix_status_t status = CELIX_SUCCESS;
- if (status == CELIX_SUCCESS) {
- status = bundleContext_ungetServiceReference(reg->context, reg->exportReference.reference);
- serviceTracker_close(reg->tracker);
- }
- return status;
-}
-
-static void exportRegistration_addServ(export_registration_pt reg, service_reference_pt ref, void *service) {
- celixThreadMutex_lock(®->mutex);
- reg->service = service;
- celixThreadMutex_unlock(®->mutex);
-}
-
-static void exportRegistration_removeServ(export_registration_pt reg, service_reference_pt ref, void *service) {
- celixThreadMutex_lock(®->mutex);
- if (reg->service == service) {
- reg->service = NULL;
- }
- celixThreadMutex_unlock(®->mutex);
-}
-
-
-celix_status_t exportRegistration_close(export_registration_pt reg) {
- celix_status_t status = CELIX_SUCCESS;
- exportRegistration_stop(reg);
- return status;
-}
-
-
-celix_status_t exportRegistration_getException(export_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- //TODO
- return status;
-}
-
-celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *out) {
- celix_status_t status = CELIX_SUCCESS;
- export_reference_pt ref = calloc(1, sizeof(*ref));
- if (ref != NULL) {
- ref->endpoint = registration->exportReference.endpoint;
- ref->reference = registration->exportReference.reference;
- } else {
- status = CELIX_ENOMEM;
- }
-
- if (status == CELIX_SUCCESS) {
- *out = ref;
- }
-
- return status;
-}
-
-celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint) {
- celix_status_t status = CELIX_SUCCESS;
- *endpoint = reference->endpoint;
- return status;
-}
-
-celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *ref) {
- celix_status_t status = CELIX_SUCCESS;
- *ref = reference->reference;
- return status;
-}
-
-
-
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
deleted file mode 100644
index 0b8dcf7..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
+++ /dev/null
@@ -1,402 +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.
- */
-
-#include <stdlib.h>
-#include <jansson.h>
-#include <json_rpc.h>
-#include <assert.h>
-#include "version.h"
-#include "json_serializer.h"
-#include "dyn_interface.h"
-#include "import_registration.h"
-#include "import_registration_dfi.h"
-
-struct import_registration {
- bundle_context_pt context;
- endpoint_description_pt endpoint; //TODO owner? -> free when destroyed
- const char *classObject; //NOTE owned by endpoint
- version_pt version;
-
- celix_thread_mutex_t mutex; //protects send & sendhandle
- send_func_type send;
- void *sendHandle;
-
- service_factory_pt factory;
- service_registration_pt factoryReg;
-
- hash_map_pt proxies; //key -> bundle, value -> service_proxy
- celix_thread_mutex_t proxiesMutex; //protects proxies
-};
-
-struct service_proxy {
- dyn_interface_type *intf;
- void *service;
- size_t count;
-};
-
-static celix_status_t importRegistration_createProxy(import_registration_pt import, bundle_pt bundle,
- struct service_proxy **proxy);
-static void importRegistration_proxyFunc(void *userData, void *args[], void *returnVal);
-static void importRegistration_destroyProxy(struct service_proxy *proxy);
-static void importRegistration_clearProxies(import_registration_pt import);
-
-celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt endpoint, const char *classObject, const char* serviceVersion,
- import_registration_pt *out) {
- celix_status_t status = CELIX_SUCCESS;
- import_registration_pt reg = calloc(1, sizeof(*reg));
-
- if (reg != NULL) {
- reg->factory = calloc(1, sizeof(*reg->factory));
- }
-
- if (reg != NULL && reg->factory != NULL) {
- reg->context = context;
- reg->endpoint = endpoint;
- reg->classObject = classObject;
- reg->proxies = hashMap_create(NULL, NULL, NULL, NULL);
-
- celixThreadMutex_create(®->mutex, NULL);
- celixThreadMutex_create(®->proxiesMutex, NULL);
- status = version_createVersionFromString((char*)serviceVersion,&(reg->version));
-
- reg->factory->handle = reg;
- reg->factory->getService = (void *)importRegistration_getService;
- reg->factory->ungetService = (void *)importRegistration_ungetService;
- } else {
- status = CELIX_ENOMEM;
- }
-
- if (status == CELIX_SUCCESS) {
- //printf("IMPORT REGISTRATION IS %p\n", reg);
- *out = reg;
- }
- else{
- importRegistration_destroy(reg);
- }
-
- return status;
-}
-
-
-celix_status_t importRegistration_setSendFn(import_registration_pt reg,
- send_func_type send,
- void *handle) {
- celixThreadMutex_lock(®->mutex);
- reg->send = send;
- reg->sendHandle = handle;
- celixThreadMutex_unlock(®->mutex);
-
- return CELIX_SUCCESS;
-}
-
-static void importRegistration_clearProxies(import_registration_pt import) {
- if (import != NULL) {
- pthread_mutex_lock(&import->proxiesMutex);
- if (import->proxies != NULL) {
- hash_map_iterator_pt iter = hashMapIterator_create(import->proxies);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- struct service_proxy *proxy = hashMapEntry_getValue(entry);
- importRegistration_destroyProxy(proxy);
- }
- hashMapIterator_destroy(iter);
- }
- pthread_mutex_unlock(&import->proxiesMutex);
- }
-}
-
-void importRegistration_destroy(import_registration_pt import) {
- if (import != NULL) {
- if (import->proxies != NULL) {
- hashMap_destroy(import->proxies, false, false);
- import->proxies = NULL;
- }
-
- pthread_mutex_destroy(&import->mutex);
- pthread_mutex_destroy(&import->proxiesMutex);
-
- if (import->factory != NULL) {
- free(import->factory);
- }
-
- if(import->version!=NULL){
- version_destroy(import->version);
- }
- free(import);
- }
-}
-
-celix_status_t importRegistration_start(import_registration_pt import) {
- celix_status_t status = CELIX_SUCCESS;
- if (import->factoryReg == NULL && import->factory != NULL) {
- properties_pt props = NULL;
- properties_copy(import->endpoint->properties, &props);
- status = bundleContext_registerServiceFactory(import->context, (char *)import->classObject, import->factory, props, &import->factoryReg);
- } else {
- status = CELIX_ILLEGAL_STATE;
- }
- return status;
-}
-
-celix_status_t importRegistration_stop(import_registration_pt import) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (import->factoryReg != NULL) {
- serviceRegistration_unregister(import->factoryReg);
- import->factoryReg = NULL;
- }
-
- importRegistration_clearProxies(import);
-
- return status;
-}
-
-
-celix_status_t importRegistration_getService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **out) {
- celix_status_t status = CELIX_SUCCESS;
-
- /*
- module_pt module = NULL;
- char *name = NULL;
- bundle_getCurrentModule(bundle, &module);
- module_getSymbolicName(module, &name);
- printf("getting service for bundle '%s'\n", name);
- */
-
-
- pthread_mutex_lock(&import->proxiesMutex);
- struct service_proxy *proxy = hashMap_get(import->proxies, bundle);
- if (proxy == NULL) {
- status = importRegistration_createProxy(import, bundle, &proxy);
- if (status == CELIX_SUCCESS) {
- hashMap_put(import->proxies, bundle, proxy);
- }
- }
-
- if (status == CELIX_SUCCESS) {
- proxy->count += 1;
- *out = proxy->service;
- }
- pthread_mutex_unlock(&import->proxiesMutex);
-
- return status;
-}
-
-static celix_status_t importRegistration_createProxy(import_registration_pt import, bundle_pt bundle, struct service_proxy **out) {
- celix_status_t status;
- dyn_interface_type* intf = NULL;
- FILE *descriptor = NULL;
-
- status = dfi_findDescriptor(import->context, bundle, import->classObject, &descriptor);
-
- if (status != CELIX_SUCCESS || descriptor == NULL) {
- //TODO use log helper logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Cannot find/open descriptor for '%s'", import->classObject);
- fprintf(stderr, "RSA_DFI: Cannot find/open descriptor for '%s'", import->classObject);
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- if (status == CELIX_SUCCESS) {
- int rc = dynInterface_parse(descriptor, &intf);
- fclose(descriptor);
- if (rc != 0 || intf==NULL) {
- return CELIX_BUNDLE_EXCEPTION;
- }
- }
-
- /* Check if the imported service version is compatible with the one in the consumer descriptor */
- version_pt consumerVersion = NULL;
- bool isCompatible = false;
- dynInterface_getVersion(intf,&consumerVersion);
- version_isCompatible(consumerVersion,import->version,&isCompatible);
-
- if(!isCompatible){
- char* cVerString = NULL;
- char* pVerString = NULL;
- version_toString(consumerVersion,&cVerString);
- version_toString(import->version,&pVerString);
- printf("Service version mismatch: consumer has %s, provider has %s. NOT creating proxy.\n",cVerString,pVerString);
- dynInterface_destroy(intf);
- free(cVerString);
- free(pVerString);
- status = CELIX_SERVICE_EXCEPTION;
- }
-
- struct service_proxy *proxy = NULL;
- if (status == CELIX_SUCCESS) {
- proxy = calloc(1, sizeof(*proxy));
- if (proxy == NULL) {
- status = CELIX_ENOMEM;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- proxy->intf = intf;
- size_t count = dynInterface_nrOfMethods(proxy->intf);
- proxy->service = calloc(1 + count, sizeof(void *));
- if (proxy->service == NULL) {
- status = CELIX_ENOMEM;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- void **serv = proxy->service;
- serv[0] = import;
-
- struct methods_head *list = NULL;
- dynInterface_methods(proxy->intf, &list);
- struct method_entry *entry = NULL;
- void (*fn)(void) = NULL;
- int index = 0;
- TAILQ_FOREACH(entry, list, entries) {
- int rc = dynFunction_createClosure(entry->dynFunc, importRegistration_proxyFunc, entry, &fn);
- serv[index + 1] = fn;
- index += 1;
-
- if (rc != 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- break;
- }
- }
- }
-
- if (status == CELIX_SUCCESS) {
- *out = proxy;
- } else if (proxy != NULL) {
- if (proxy->intf != NULL) {
- dynInterface_destroy(proxy->intf);
- proxy->intf = NULL;
- }
- free(proxy->service);
- free(proxy);
- }
-
- return status;
-}
-
-static void importRegistration_proxyFunc(void *userData, void *args[], void *returnVal) {
- int status = CELIX_SUCCESS;
- struct method_entry *entry = userData;
- import_registration_pt import = *((void **)args[0]);
-
- if (import == NULL || import->send == NULL) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
-
- char *invokeRequest = NULL;
- if (status == CELIX_SUCCESS) {
- status = jsonRpc_prepareInvokeRequest(entry->dynFunc, entry->id, args, &invokeRequest);
- //printf("Need to send following json '%s'\n", invokeRequest);
- }
-
-
- if (status == CELIX_SUCCESS) {
- char *reply = NULL;
- int rc = 0;
- //printf("sending request\n");
- celixThreadMutex_lock(&import->mutex);
- if (import->send != NULL) {
- import->send(import->sendHandle, import->endpoint, invokeRequest, &reply, &rc);
- }
- celixThreadMutex_unlock(&import->mutex);
- //printf("request sended. got reply '%s' with status %i\n", reply, rc);
-
- if (rc == 0) {
- //fjprintf("Handling reply '%s'\n", reply);
- status = jsonRpc_handleReply(entry->dynFunc, reply, args);
- }
-
- *(int *) returnVal = rc;
-
- free(invokeRequest); //Allocated by json_dumps in jsonRpc_prepareInvokeRequest
- free(reply); //Allocated by json_dumps in remoteServiceAdmin_send through curl call
- }
-
- if (status != CELIX_SUCCESS) {
- //TODO log error
- }
-}
-
-celix_status_t importRegistration_ungetService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **out) {
- celix_status_t status = CELIX_SUCCESS;
-
- assert(import != NULL);
- assert(import->proxies != NULL);
-
- pthread_mutex_lock(&import->proxiesMutex);
-
- struct service_proxy *proxy = hashMap_get(import->proxies, bundle);
- if (proxy != NULL) {
- if (*out == proxy->service) {
- proxy->count -= 1;
- } else {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (proxy->count == 0) {
- hashMap_remove(import->proxies, bundle);
- importRegistration_destroyProxy(proxy);
- }
- }
-
- pthread_mutex_unlock(&import->proxiesMutex);
-
- return status;
-}
-
-static void importRegistration_destroyProxy(struct service_proxy *proxy) {
- if (proxy != NULL) {
- if (proxy->intf != NULL) {
- dynInterface_destroy(proxy->intf);
- }
- if (proxy->service != NULL) {
- free(proxy->service);
- }
- free(proxy);
- }
-}
-
-
-celix_status_t importRegistration_close(import_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- importRegistration_stop(registration);
- return status;
-}
-
-celix_status_t importRegistration_getException(import_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- //TODO
- return status;
-}
-
-celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference) {
- celix_status_t status = CELIX_SUCCESS;
- //TODO
- return status;
-}
-
-celix_status_t importReference_getImportedEndpoint(import_reference_pt reference) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-celix_status_t importReference_getImportedService(import_reference_pt reference) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c
deleted file mode 100644
index d4cc765..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c
+++ /dev/null
@@ -1,124 +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.
- */
-/*
- * remote_service_admin_activator.c
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <remote_service_admin.h>
-
-#include "remote_service_admin_dfi.h"
-
-#include "bundle_activator.h"
-#include "service_registration.h"
-
-#include "export_registration_dfi.h"
-#include "import_registration_dfi.h"
-
-struct activator {
- remote_service_admin_pt admin;
- remote_service_admin_service_pt adminService;
- service_registration_pt registration;
-};
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator;
-
- activator = calloc(1, sizeof(*activator));
- if (!activator) {
- status = CELIX_ENOMEM;
- } else {
- activator->admin = NULL;
- activator->registration = NULL;
-
- *userData = activator;
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
- remote_service_admin_service_pt remoteServiceAdmin = NULL;
-
- status = remoteServiceAdmin_create(context, &activator->admin);
- if (status == CELIX_SUCCESS) {
- remoteServiceAdmin = calloc(1, sizeof(*remoteServiceAdmin));
- if (!remoteServiceAdmin) {
- status = CELIX_ENOMEM;
- } else {
- remoteServiceAdmin->admin = activator->admin;
- remoteServiceAdmin->exportService = remoteServiceAdmin_exportService;
-
- remoteServiceAdmin->getExportedServices = remoteServiceAdmin_getExportedServices;
- remoteServiceAdmin->getImportedEndpoints = remoteServiceAdmin_getImportedEndpoints;
- remoteServiceAdmin->importService = remoteServiceAdmin_importService;
-
- remoteServiceAdmin->exportReference_getExportedEndpoint = exportReference_getExportedEndpoint;
- remoteServiceAdmin->exportReference_getExportedService = exportReference_getExportedService;
-
- remoteServiceAdmin->exportRegistration_close = remoteServiceAdmin_removeExportedService;
- remoteServiceAdmin->exportRegistration_getException = exportRegistration_getException;
- remoteServiceAdmin->exportRegistration_getExportReference = exportRegistration_getExportReference;
-
- remoteServiceAdmin->importReference_getImportedEndpoint = importReference_getImportedEndpoint;
- remoteServiceAdmin->importReference_getImportedService = importReference_getImportedService;
-
- remoteServiceAdmin->importRegistration_close = remoteServiceAdmin_removeImportedService;
- remoteServiceAdmin->importRegistration_getException = importRegistration_getException;
- remoteServiceAdmin->importRegistration_getImportReference = importRegistration_getImportReference;
-
- status = bundleContext_registerService(context, OSGI_RSA_REMOTE_SERVICE_ADMIN, remoteServiceAdmin, NULL, &activator->registration);
- activator->adminService = remoteServiceAdmin;
- }
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- serviceRegistration_unregister(activator->registration);
- activator->registration = NULL;
-
- remoteServiceAdmin_stop(activator->admin);
- remoteServiceAdmin_destroy(&activator->admin);
-
- free(activator->adminService);
-
- return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- free(activator);
-
- return status;
-}
-
-
[48/54] [abbrv] celix git commit: CELIX-417: Fixes some issues with
the moved cmake_celix dir and imported bundle targets
Posted by pn...@apache.org.
CELIX-417: Fixes some issues with the moved cmake_celix dir and imported bundle targets
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/984b19f0
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/984b19f0
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/984b19f0
Branch: refs/heads/develop
Commit: 984b19f0c3bc1b285b02aa6080470cbd5887ebeb
Parents: ae8e2e3
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Jan 30 12:09:22 2018 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Jan 30 12:09:22 2018 +0100
----------------------------------------------------------------------
cmake/cmake_celix/DockerPackaging.cmake | 47 ++++++++++++--------
cmake/cmake_celix/Runtimes.cmake | 6 +--
cmake/cmake_celix/main.c.in | 24 ----------
examples/dm_example_cxx/phase3/CMakeLists.txt | 2 +-
.../phase3_locking/CMakeLists.txt | 2 +-
5 files changed, 34 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/984b19f0/cmake/cmake_celix/DockerPackaging.cmake
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/DockerPackaging.cmake b/cmake/cmake_celix/DockerPackaging.cmake
index cb1442c..37c08a3 100644
--- a/cmake/cmake_celix/DockerPackaging.cmake
+++ b/cmake/cmake_celix/DockerPackaging.cmake
@@ -75,18 +75,6 @@ function(add_celix_docker)
list(APPEND CLEANFILES "$<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_LOC>")
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CLEANFILES}")
- if (DOCKER_LAUNCHER_SRC)
- get_filename_component(SRC_FILENAME ${DOCKER_LAUNCHER_SRC} NAME)
- set(LAUNCHER_SRC "${PROJECT_BINARY_DIR}/celix/gen/${DOCKER_TARGET}-${SRC_FILENAME}")
- set(LAUNCHER_ORG "${DOCKER_LAUNCHER_SRC}")
- elseif (DOCKER_CXX)
- set(LAUNCHER_SRC "${PROJECT_BINARY_DIR}/celix/gen/${DOCKER_TARGET}-main.cc")
- set(LAUNCHER_ORG "${CELIX_CMAKE_DIRECTORY}/cmake_celix/main.c.in")
- else()
- set(LAUNCHER_SRC "${PROJECT_BINARY_DIR}/celix/gen/${DOCKER_TARGET}-main.c")
- set(LAUNCHER_ORG "${CELIX_CMAKE_DIRECTORY}/cmake_celix/main.c.in")
- endif()
-
if (DOCKER_LAUNCHER)
add_custom_target(${DOCKER_TARGET})
if (IS_ABSOLUTE "${DOCKER_LAUNCHER}")
@@ -98,8 +86,12 @@ function(add_celix_docker)
set(LAUNCHER "$<TARGET_FILE:${DOCKER_LAUNCHER}>")
set(DOCKER_ENTRYPOINT "ENTRYPOINT [\"/bin/$<TARGET_FILE_NAME:${DOCKER_TARGET}>\"]")
endif()
- else ()
-
+ elseif (DOCKER_LAUNHCER_SRC)
+ add_executable(${DOCKER_TARGET} EXCLUDE_FROM_ALL ${DOCKER_LAUNCHER_SRC})
+ target_link_libraries(${DOCKER_TARGET} PRIVATE Celix::framework)
+ set(LAUNCHER "$<TARGET_FILE:${DOCKER_TARGET}>")
+ set(DOCKER_ENTRYPOINT "ENTRYPOINT [\"/bin/$<TARGET_FILE_NAME:${DOCKER_TARGET}>\"]")
+ else()
if (DOCKER_CXX)
set(LAUNCHER_SRC "${CMAKE_CURRENT_BINARY_DIR}/${DOCKER_TARGET}-docker-main.cc")
else()
@@ -138,7 +130,7 @@ $<JOIN:$<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_EMBEDDED_PROPERTIES>,\\n\\
if (DOCKER_CREATE_FS)
add_custom_command(TARGET ${DOCKER_TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_LOC>
- COMMAND cd $<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_LOC> && /bin/bash ${CELIX_CMAKE_DIRECTORY}/cmake_celix/create_target_filesystem.sh -e ${LAUNCHER} > /dev/null
+ COMMAND cd $<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_LOC> && /bin/bash ${CELIX_CMAKE_DIRECTORY}/create_target_filesystem.sh -e ${LAUNCHER} > /dev/null
WORKING_DIRECTORY "${DOCKER_LOC}"
COMMENT "Creating docker dir for ${DOCKER_TARGET}" VERBATIM
)
@@ -234,16 +226,35 @@ function(celix_docker_bundles)
get_target_property(DEPS ${DOCKER_TARGET} "DOCKER_DEPS")
foreach(BUNDLE IN ITEMS ${ARGN})
+ set(HANDLED FALSE)
if(IS_ABSOLUTE ${BUNDLE} AND EXISTS ${BUNDLE})
get_filename_component(BUNDLE_FILENAME ${BUNDLE} NAME)
set(OUT "${LOC}/${BUNDLES_DIR}/${BUNDLE_FILENAME}")
add_custom_command(OUTPUT ${OUT}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${BUNDLE} ${OUT}
- COMMENT "Copying bundle '${BUNDLE}' to '${LOC}/${BUNDLES_DIR}'"
+ COMMENT "Copying (file) bundle '${BUNDLE}' to '${LOC}/${BUNDLES_DIR}'"
DEPENDS ${BUNDLE}
)
list(APPEND BUNDLES "${BUNDLES_DIR}/${BUNDLE_FILENAME}")
- else() #assuming target
+ set(HANDLED TRUE)
+ elseif (TARGET ${BUNDLE})
+ get_target_property(IMP ${BUNDLE} BUNDLE_IMPORTED)
+ if (IMP) #An imported bundle target -> handle target without DEPENDS
+ string(MAKE_C_IDENTIFIER ${BUNDLE} BUNDLE_ID) #Create id with no special chars (e.g. for target like Celix::shell)
+ set(OUT "${CMAKE_BINARY_DIR}/celix/gen/${CONTAINER_TARGET}-copy-bundle-for-target-${BUNDLE_ID}.timestamp")
+ set(DEST "${LOC}/${BUNDLES_DIR}/$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
+ add_custom_command(OUTPUT ${OUT}
+ COMMAND ${CMAKE_COMMAND} -E touch ${OUT}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${LOC}/${BUNDLES_DIR}
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILE>" ${DEST}
+ COMMENT "Copying (imported) bundle '${BUNDLE}' to '${LOC}/${BUNDLES_DIR}'"
+ )
+ list(APPEND BUNDLES "${BUNDLES_DIR}/$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
+ set(HANDLED TRUE)
+ endif ()
+ endif ()
+
+ if(NOT HANDLED) #assuming (future) bundle target
string(MAKE_C_IDENTIFIER ${BUNDLE} BUNDLE_ID) #Create id with no special chars (e.g. for target like Celix::shell)
set(OUT "${CMAKE_BINARY_DIR}/celix/gen/${DOCKER_TARGET}-copy-bundle-for-target-${BUNDLE_ID}.timestamp")
set(DEST "${LOC}/${BUNDLES_DIR}/$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
@@ -251,7 +262,7 @@ function(celix_docker_bundles)
COMMAND ${CMAKE_COMMAND} -E touch ${OUT}
COMMAND ${CMAKE_COMMAND} -E make_directory ${LOC}/${BUNDLES_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILE>" ${DEST}
- COMMENT "Copying bundle '${BUNDLE}' to '${LOC}/${BUNDLES_DIR}'"
+ COMMENT "Copying (target) bundle '${BUNDLE}' to '${LOC}/${BUNDLES_DIR}'"
DEPENDS ${BUNDLE} $<TARGET_PROPERTY:${BUNDLE},BUNDLE_CREATE_BUNDLE_TARGET>
)
list(APPEND BUNDLES "${BUNDLES_DIR}/$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
http://git-wip-us.apache.org/repos/asf/celix/blob/984b19f0/cmake/cmake_celix/Runtimes.cmake
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/Runtimes.cmake b/cmake/cmake_celix/Runtimes.cmake
index 785a8c0..40c9586 100644
--- a/cmake/cmake_celix/Runtimes.cmake
+++ b/cmake/cmake_celix/Runtimes.cmake
@@ -77,9 +77,9 @@ function(add_runtime)
#replaces @RUNTIME_TARGET_NAME@
#TODO move to another location
- configure_file("${CELIX_CMAKE_DIRECTORY}/cmake_celix/runtime_start.sh.in" "${CMAKE_CURRENT_BINARY_DIR}/start.sh.${RUNTIME_TARGET_NAME}.in.1" @ONLY)
- configure_file("${CELIX_CMAKE_DIRECTORY}/cmake_celix/runtime_stop.sh.in" "${CMAKE_CURRENT_BINARY_DIR}/stop.sh.${RUNTIME_TARGET_NAME}.in.1" @ONLY)
- configure_file("${CELIX_CMAKE_DIRECTORY}/cmake_celix/runtime_common.sh.in" "${CMAKE_CURRENT_BINARY_DIR}/common.sh.${RUNTIME_TARGET_NAME}.in.1" @ONLY)
+ configure_file("${CELIX_CMAKE_DIRECTORY}/runtime_start.sh.in" "${CMAKE_CURRENT_BINARY_DIR}/start.sh.${RUNTIME_TARGET_NAME}.in.1" @ONLY)
+ configure_file("${CELIX_CMAKE_DIRECTORY}/runtime_stop.sh.in" "${CMAKE_CURRENT_BINARY_DIR}/stop.sh.${RUNTIME_TARGET_NAME}.in.1" @ONLY)
+ configure_file("${CELIX_CMAKE_DIRECTORY}/runtime_common.sh.in" "${CMAKE_CURRENT_BINARY_DIR}/common.sh.${RUNTIME_TARGET_NAME}.in.1" @ONLY)
#replaces $<TARGET_PROPERTY:<RUNTIME_NAME>,RUNTIME_DEPLOYMENTS>
http://git-wip-us.apache.org/repos/asf/celix/blob/984b19f0/cmake/cmake_celix/main.c.in
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/main.c.in b/cmake/cmake_celix/main.c.in
deleted file mode 100644
index 455b7dd..0000000
--- a/cmake/cmake_celix/main.c.in
+++ /dev/null
@@ -1,24 +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.
- */
-
-#include <celix_launcher.h>
-
-int main(int argc, char *argv[]) {
- return celixLauncher_launchWithArgs(argc, argv);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/984b19f0/examples/dm_example_cxx/phase3/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3/CMakeLists.txt b/examples/dm_example_cxx/phase3/CMakeLists.txt
index 3728abc..c583f25 100644
--- a/examples/dm_example_cxx/phase3/CMakeLists.txt
+++ b/examples/dm_example_cxx/phase3/CMakeLists.txt
@@ -24,7 +24,7 @@ add_celix_bundle(dm_example_cxx_phase3
src/Phase3Cmp.cc
)
target_include_directories(dm_example_cxx_phase3 PRIVATE src)
-target_link_libraries(dm_example_cxx_phase3 PRIVATE dm_example_cxx_api)
+target_link_libraries(dm_example_cxx_phase3 PRIVATE dm_example_cxx_api pthread)
IF(APPLE)
target_link_libraries(dm_example_cxx_phase3 PRIVATE -Wl,-all_load Celix::dependency_manager_cxx_static)
http://git-wip-us.apache.org/repos/asf/celix/blob/984b19f0/examples/dm_example_cxx/phase3_locking/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3_locking/CMakeLists.txt b/examples/dm_example_cxx/phase3_locking/CMakeLists.txt
index 35ca3c9..7a6823a 100644
--- a/examples/dm_example_cxx/phase3_locking/CMakeLists.txt
+++ b/examples/dm_example_cxx/phase3_locking/CMakeLists.txt
@@ -24,7 +24,7 @@ add_celix_bundle(dm_example_cxx_phase3_locking
src/Phase3LockingCmp.cc
)
target_include_directories(dm_example_cxx_phase3_locking PRIVATE src)
-target_link_libraries(dm_example_cxx_phase3_locking PRIVATE dm_example_cxx_api)
+target_link_libraries(dm_example_cxx_phase3_locking PRIVATE dm_example_cxx_api pthread)
IF(APPLE)
target_link_libraries(dm_example_cxx_phase3_locking PRIVATE -Wl,-all_load Celix::dependency_manager_cxx_static)
[19/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
CELIX-417: Refactor for CMake usage in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/2a670f26
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/2a670f26
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/2a670f26
Branch: refs/heads/develop
Commit: 2a670f26579d89e5404979d7fffb4ed27040441c
Parents: a1c3088
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Nov 21 21:07:44 2017 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Nov 21 21:07:44 2017 +0100
----------------------------------------------------------------------
cmake/cmake_celix/BundlePackaging.cmake | 2 +-
cmake/cmake_celix/DockerPackaging.cmake | 17 +-
deployment_admin/CMakeLists.txt | 2 +-
examples/dm_example_cxx/CMakeLists.txt | 16 +-
examples/dm_example_cxx/phase1/CMakeLists.txt | 4 +-
examples/hello_world/CMakeLists.txt | 8 +-
examples/services_example_c/bar/CMakeLists.txt | 4 +-
log_writer/CMakeLists.txt | 6 +-
log_writer/README.md | 10 +-
log_writer/log_writer_stdout/CMakeLists.txt | 10 +-
log_writer/log_writer_syslog/CMakeLists.txt | 4 -
pubsub/CMakeLists.txt | 2 +-
pubsub/deploy/CMakeLists.txt | 2 +-
.../examples/mp_pubsub/publisher/CMakeLists.txt | 2 +-
.../mp_pubsub/subscriber/CMakeLists.txt | 2 +-
pubsub/examples/pubsub/publisher/CMakeLists.txt | 2 +-
.../examples/pubsub/publisher2/CMakeLists.txt | 2 +-
.../examples/pubsub/subscriber/CMakeLists.txt | 2 +-
pubsub/pubsub_admin_udp_mc/CMakeLists.txt | 28 +-
.../private/include/large_udp.h | 45 -
.../private/include/pubsub_admin_impl.h | 93 -
.../private/include/topic_publication.h | 57 -
.../private/include/topic_subscription.h | 60 -
.../pubsub_admin_udp_mc/private/src/large_udp.c | 372 -
.../private/src/psa_activator.c | 141 -
.../private/src/pubsub_admin_impl.c | 1039 ---
.../private/src/topic_publication.c | 444 -
.../private/src/topic_subscription.c | 635 --
pubsub/pubsub_admin_udp_mc/src/large_udp.c | 372 +
pubsub/pubsub_admin_udp_mc/src/large_udp.h | 45 +
pubsub/pubsub_admin_udp_mc/src/psa_activator.c | 141 +
.../pubsub_admin_udp_mc/src/pubsub_admin_impl.c | 1039 +++
.../pubsub_admin_udp_mc/src/pubsub_admin_impl.h | 93 +
.../pubsub_admin_udp_mc/src/topic_publication.c | 444 +
.../pubsub_admin_udp_mc/src/topic_publication.h | 57 +
.../src/topic_subscription.c | 635 ++
.../src/topic_subscription.h | 60 +
pubsub/pubsub_admin_zmq/CMakeLists.txt | 5 +-
pubsub/pubsub_discovery/CMakeLists.txt | 27 +-
.../private/include/etcd_common.h | 28 -
.../private/include/etcd_watcher.h | 38 -
.../private/include/etcd_writer.h | 39 -
.../private/include/pubsub_discovery_impl.h | 72 -
.../pubsub_discovery/private/src/etcd_common.c | 82 -
.../pubsub_discovery/private/src/etcd_watcher.c | 290 -
.../pubsub_discovery/private/src/etcd_writer.c | 189 -
.../private/src/psd_activator.c | 171 -
.../private/src/pubsub_discovery_impl.c | 457 -
.../public/include/pubsub_discovery.h | 26 -
pubsub/pubsub_discovery/src/etcd_common.c | 82 +
pubsub/pubsub_discovery/src/etcd_common.h | 28 +
pubsub/pubsub_discovery/src/etcd_watcher.c | 290 +
pubsub/pubsub_discovery/src/etcd_watcher.h | 38 +
pubsub/pubsub_discovery/src/etcd_writer.c | 189 +
pubsub/pubsub_discovery/src/etcd_writer.h | 39 +
pubsub/pubsub_discovery/src/psd_activator.c | 171 +
pubsub/pubsub_discovery/src/pubsub_discovery.h | 26 +
.../src/pubsub_discovery_impl.c | 457 +
.../src/pubsub_discovery_impl.h | 72 +
pubsub/pubsub_serializer_json/CMakeLists.txt | 20 +-
.../private/include/pubsub_serializer_impl.h | 55 -
.../private/src/ps_activator.c | 107 -
.../private/src/pubsub_serializer_impl.c | 295 -
.../pubsub_serializer_json/src/ps_activator.c | 107 +
.../src/pubsub_serializer_impl.c | 295 +
.../src/pubsub_serializer_impl.h | 55 +
pubsub/pubsub_topology_manager/CMakeLists.txt | 12 +-
pubsub/test/CMakeLists.txt | 6 +-
remote_services/CMakeLists.txt | 6 +-
.../discovery/private/include/discovery.h | 67 -
.../include/endpoint_descriptor_common.h | 61 -
.../include/endpoint_descriptor_reader.h | 42 -
.../include/endpoint_descriptor_writer.h | 39 -
.../private/include/endpoint_discovery_poller.h | 56 -
.../private/include/endpoint_discovery_server.h | 81 -
remote_services/discovery/private/src/desc.xml | 41 -
.../discovery/private/src/discovery.c | 233 -
.../discovery/private/src/discovery_activator.c | 186 -
.../private/src/endpoint_descriptor_reader.c | 387 -
.../private/src/endpoint_descriptor_writer.c | 233 -
.../private/src/endpoint_discovery_poller.c | 403 -
.../private/src/endpoint_discovery_server.c | 450 -
remote_services/discovery_common/CMakeLists.txt | 33 +
.../discovery_common/include/civetweb.h | 657 ++
.../discovery_common/include/discovery.h | 67 +
.../include/endpoint_descriptor_common.h | 61 +
.../include/endpoint_descriptor_reader.h | 42 +
.../include/endpoint_descriptor_writer.h | 39 +
.../include/endpoint_discovery_poller.h | 56 +
.../include/endpoint_discovery_server.h | 81 +
remote_services/discovery_common/src/civetweb.c | 7907 ++++++++++++++++++
remote_services/discovery_common/src/desc.xml | 41 +
.../discovery_common/src/discovery.c | 234 +
.../discovery_common/src/discovery_activator.c | 186 +
.../src/endpoint_descriptor_reader.c | 387 +
.../src/endpoint_descriptor_writer.c | 233 +
.../src/endpoint_discovery_poller.c | 403 +
.../src/endpoint_discovery_server.c | 450 +
remote_services/discovery_common/src/md5.inl | 461 +
.../discovery_configured/CMakeLists.txt | 36 +-
.../private/include/discovery_impl.h | 62 -
.../discovery_configured/private/src/desc.xml | 41 -
.../private/src/discovery_impl.c | 123 -
.../discovery_configured/src/desc.xml | 41 +
.../discovery_configured/src/discovery_impl.c | 123 +
.../discovery_configured/src/discovery_impl.h | 62 +
remote_services/discovery_etcd/CMakeLists.txt | 33 +-
remote_services/discovery_shm/CMakeLists.txt | 35 +-
.../private/include/discovery_impl.h | 66 -
.../private/include/discovery_shm.h | 56 -
.../private/include/discovery_shmWatcher.h | 40 -
.../discovery_shm/private/src/discovery_impl.c | 163 -
.../discovery_shm/private/src/discovery_shm.c | 284 -
.../private/src/discovery_shmWatcher.c | 246 -
.../discovery_shm/src/discovery_impl.c | 163 +
.../discovery_shm/src/discovery_impl.h | 66 +
.../discovery_shm/src/discovery_shm.c | 284 +
.../discovery_shm/src/discovery_shm.h | 56 +
.../discovery_shm/src/discovery_shmWatcher.c | 246 +
.../discovery_shm/src/discovery_shmWatcher.h | 40 +
remote_services/examples/CMakeLists.txt | 5 +-
.../examples/calculator_api/CMakeLists.txt | 22 +
.../calculator_api/include/calculator_service.h | 56 +
...apache.celix.calc.api.Calculator2.descriptor | 11 +
.../examples/calculator_service/CMakeLists.txt | 22 +-
.../private/include/calculator_impl.h | 43 -
.../private/src/calculator_activator.c | 110 -
.../private/src/calculator_impl.c | 79 -
.../public/include/calculator_service.h | 56 -
...apache.celix.calc.api.Calculator2.descriptor | 11 -
.../src/calculator_activator.c | 110 +
.../calculator_service/src/calculator_impl.c | 79 +
.../calculator_service/src/calculator_impl.h | 43 +
.../examples/calculator_shell/CMakeLists.txt | 28 +-
.../private/include/add_command.h | 32 -
...apache.celix.calc.api.Calculator2.descriptor | 11 -
.../private/include/sqrt_command.h | 32 -
.../private/include/sub_command.h | 32 -
.../calculator_shell/private/src/add_command.c | 101 -
.../private/src/calculator_shell_activator.c | 125 -
.../calculator_shell/private/src/sqrt_command.c | 96 -
.../calculator_shell/private/src/sub_command.c | 99 -
.../examples/calculator_shell/src/add_command.c | 101 +
.../examples/calculator_shell/src/add_command.h | 32 +
.../src/calculator_shell_activator.c | 125 +
...apache.celix.calc.api.Calculator2.descriptor | 11 +
.../calculator_shell/src/sqrt_command.c | 96 +
.../calculator_shell/src/sqrt_command.h | 32 +
.../examples/calculator_shell/src/sub_command.c | 99 +
.../examples/calculator_shell/src/sub_command.h | 32 +
.../remote_service_admin/CMakeLists.txt | 46 -
remote_services/remote_service_admin/README.md | 11 -
.../private/include/export_registration_impl.h | 61 -
.../private/include/import_registration_impl.h | 81 -
.../private/include/remote_service_admin_impl.h | 49 -
.../private/src/endpoint_description.c | 89 -
.../private/src/export_registration_impl.c | 257 -
.../private/src/import_registration_impl.c | 274 -
.../private/src/remote_proxy_factory_impl.c | 252 -
.../public/include/endpoint_description.h | 50 -
.../public/include/endpoint_listener.h | 49 -
.../public/include/export_registration.h | 22 -
.../public/include/import_registration.h | 22 -
.../public/include/remote_constants.h | 38 -
.../public/include/remote_endpoint.h | 44 -
.../public/include/remote_endpoint_impl.h | 38 -
.../public/include/remote_proxy.h | 76 -
.../public/include/remote_service_admin.h | 73 -
.../remote_service_admin_api/CMakeLists.txt | 45 +
.../remote_service_admin_api/README.md | 11 +
.../include/endpoint_description.h | 50 +
.../include/endpoint_listener.h | 49 +
.../include/export_registration.h | 22 +
.../include/import_registration.h | 22 +
.../include/remote_constants.h | 38 +
.../include/remote_endpoint.h | 44 +
.../include/remote_endpoint_impl.h | 38 +
.../include/remote_proxy.h | 76 +
.../include/remote_service_admin.h | 73 +
.../remote_service_admin_common/CMakeLists.txt | 24 +
.../src/endpoint_description.c | 89 +
.../src/export_registration_impl.c | 257 +
.../src/export_registration_impl.h | 61 +
.../src/import_registration_impl.c | 274 +
.../src/import_registration_impl.h | 81 +
.../src/remote_proxy_factory_impl.c | 252 +
.../src/remote_service_admin_impl.h | 49 +
.../remote_service_admin_dfi/rsa/CMakeLists.txt | 31 +-
.../rsa/private/include/dfi_utils.h | 30 -
.../private/include/export_registration_dfi.h | 38 -
.../private/include/import_registration_dfi.h | 44 -
.../private/include/remote_service_admin_dfi.h | 57 -
.../rsa/private/src/dfi_utils.c | 98 -
.../rsa/private/src/export_registration_dfi.c | 251 -
.../rsa/private/src/import_registration_dfi.c | 402 -
.../src/remote_service_admin_activator.c | 124 -
.../rsa/private/src/remote_service_admin_dfi.c | 775 --
.../rsa/src/dfi_utils.c | 98 +
.../rsa/src/dfi_utils.h | 30 +
.../rsa/src/export_registration_dfi.c | 251 +
.../rsa/src/export_registration_dfi.h | 38 +
.../rsa/src/import_registration_dfi.c | 402 +
.../rsa/src/import_registration_dfi.h | 44 +
.../rsa/src/remote_service_admin_activator.c | 124 +
.../rsa/src/remote_service_admin_dfi.c | 775 ++
.../rsa/src/remote_service_admin_dfi.h | 57 +
.../rsa_tst/CMakeLists.txt | 4 +-
.../rsa_tst/bundle/CMakeLists.txt | 14 +-
remote_services/topology_manager/CMakeLists.txt | 26 +-
.../topology_manager/include/tm_scope.h | 46 +
.../topology_manager/private/include/scope.h | 150 -
.../private/include/topology_manager.h | 65 -
.../topology_manager/private/src/activator.c | 289 -
.../topology_manager/private/src/scope.c | 326 -
.../private/src/topology_manager.c | 985 ---
.../topology_manager/public/include/tm_scope.h | 46 -
.../topology_manager/src/activator.c | 289 +
remote_services/topology_manager/src/scope.c | 326 +
remote_services/topology_manager/src/scope.h | 150 +
.../topology_manager/src/topology_manager.c | 985 +++
.../topology_manager/src/topology_manager.h | 65 +
.../topology_manager/tms_tst/CMakeLists.txt | 4 +-
.../tms_tst/bundle/CMakeLists.txt | 2 +-
.../tms_tst/disc_mock/CMakeLists.txt | 11 +-
.../utils/private/include/civetweb.h | 657 --
remote_services/utils/private/src/civetweb.c | 7907 ------------------
remote_services/utils/private/src/md5.inl | 461 -
shell/CMakeLists.txt | 2 +-
shell/README.md | 3 +-
229 files changed, 23404 insertions(+), 23450 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/cmake/cmake_celix/BundlePackaging.cmake
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/BundlePackaging.cmake b/cmake/cmake_celix/BundlePackaging.cmake
index 2071fca..c5d75d6 100644
--- a/cmake/cmake_celix/BundlePackaging.cmake
+++ b/cmake/cmake_celix/BundlePackaging.cmake
@@ -371,7 +371,7 @@ function(bundle_import_libs)
list(APPEND LIBS "$<TARGET_SONAME_FILE_NAME:${LIB}>")
endif()
- target_link_libraries(${BUNDLE} ${LIB})
+ target_link_libraries(${BUNDLE} PRIVATE ${LIB})
endforeach()
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/cmake/cmake_celix/DockerPackaging.cmake
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/DockerPackaging.cmake b/cmake/cmake_celix/DockerPackaging.cmake
index 7cce6dd..b85da11 100644
--- a/cmake/cmake_celix/DockerPackaging.cmake
+++ b/cmake/cmake_celix/DockerPackaging.cmake
@@ -116,22 +116,16 @@ function(add_celix_docker)
DEPENDS ${TIMESTAMP_FILE}
)
- #Setting CELIX_LIB_DIRS, CELIX_BIN_DIR and CELIX_LAUNCHER
- if (EXISTS ${CELIX_FRAMEWORK_LIBRARY})
- #CELIX_FRAMEWORK_LIBRARY set by FindCelix.cmake -> Celix Based Project
- #CELIX_LAUNCHER is set by FindCelix.cmake
- else()
- set(CELIX_LAUNCHER "$<TARGET_FILE:celix>")
- endif()
+ set(CELIX_LAUNCHER "$<TARGET_FILE:Celix::launcher>")
#setup dependencies based on timestamp
if (DOCKER_CREATE_FS)
add_custom_command(OUTPUT "${TIMESTAMP_FILE}"
COMMAND ${CMAKE_COMMAND} -E touch ${TIMESTAMP_FILE}
- COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_LOC>
- COMMAND cd $<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_LOC> && /bin/bash ${CELIX_CMAKE_DIRECTORY}/cmake_celix/create_target_filesystem.sh -e ${CELIX_LAUNCHER} -l $<TARGET_FILE:${DOCKER_DEPSLIB}> > /dev/null
+ COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_LOC>
+ COMMAND cd $<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_LOC> && /bin/bash ${CELIX_CMAKE_DIRECTORY}/cmake_celix/create_target_filesystem.sh -e ${CELIX_LAUNCHER} -l $<TARGET_FILE:${DOCKER_DEPSLIB}> > /dev/null
DEPENDS "$<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_DEPS>" ${DOCKERFILE} ${DOCKER_DEPSLIB}
- WORKING_DIRECTORY "${DOCKER_LOC}"
+ WORKING_DIRECTORY "${DOCKER_LOC}"
COMMENT "Creating docker dir for ${DOCKER_TARGET}" VERBATIM
)
else ()
@@ -248,7 +242,8 @@ function(celix_docker_bundles)
COMMENT "Copying bundle '${BUNDLE}' to '${OUT}'"
DEPENDS ${BUNDLE}
)
- add_dependencies(${DOCKER_TARGET} ${BUNDLE}_bundle) #ensure the the deploy depends on the _bundle target, custom_command depends on add_library
+ get_target_property(BUILD_BUNDLE_TARGET ${BUNDLE} BUNDLE_BUILD_BUNDLE_TARGET)
+ add_dependencies(${DOCKER_TARGET} ${BUILD_BUNDLE_TARGET}) #ensure the the deploy depends on the _bundle target, custom_command depends on add_library
endif()
list(APPEND DEPS "${OUT}")
endforeach()
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/deployment_admin/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/deployment_admin/CMakeLists.txt b/deployment_admin/CMakeLists.txt
index 4a06be5..3eb38ec 100644
--- a/deployment_admin/CMakeLists.txt
+++ b/deployment_admin/CMakeLists.txt
@@ -57,7 +57,7 @@ if (DEPLOYMENT_ADMIN)
add_library(Celix::deployment_admin ALIAS deployment_admin)
add_deploy(deployment-admin
- BUNDLES Celix::deployment_admin Celix::shell Celix::shell_tui log_service log_writer
+ BUNDLES Celix::deployment_admin Celix::shell Celix::shell_tui Celix::log_service Celix::log_writer_stdout
PROPERTIES
"deployment_admin_url=http://localhost:8080"
"deployment_admin_identification=celix"
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/examples/dm_example_cxx/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/CMakeLists.txt b/examples/dm_example_cxx/CMakeLists.txt
index 1a47113..012f706 100644
--- a/examples/dm_example_cxx/CMakeLists.txt
+++ b/examples/dm_example_cxx/CMakeLists.txt
@@ -36,9 +36,9 @@ if (BUILD_DEPENDENCY_MANAGER_CXX)
BUNDLES
Celix::shell
Celix::shell_tui
- dm_shell
- log_service
- log_writer
+ Celix::dm_shell
+ Celix::log_service
+ Celix::log_writer_stdout
phase1_cxx
phase2a_cxx
@@ -55,11 +55,11 @@ if (BUILD_DEPENDENCY_MANAGER_CXX)
BUNDLES_DIR /usr/share/bundles
WORKDIR /workspace
BUNDLES
- celix_shell
- shell_tui
- dm_shell
- log_service
- log_writer
+ Celix::shell
+ Celix::shell_tui
+ Celix::dm_shell
+ Celix::log_service
+ Celix::log_writer_stdout
phase1_cxx
phase2a_cxx
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/examples/dm_example_cxx/phase1/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase1/CMakeLists.txt b/examples/dm_example_cxx/phase1/CMakeLists.txt
index 728278b..62b1658 100644
--- a/examples/dm_example_cxx/phase1/CMakeLists.txt
+++ b/examples/dm_example_cxx/phase1/CMakeLists.txt
@@ -35,8 +35,8 @@ IF(APPLE)
else()
if(ENABLE_ADDRESS_SANITIZER)
#With asan there can be undefined symbols
- target_link_libraries(phase1_cxx -Wl,--whole-archive dependency_manager_cxx_static -Wl,--no-whole-archive Celix::shell_api)
+ target_link_libraries(phase1_cxx PRIVATE -Wl,--whole-archive dependency_manager_cxx_static -Wl,--no-whole-archive Celix::shell_api)
else()
- target_link_libraries(phase1_cxx -Wl,--no-undefined -Wl,--whole-archive dependency_manager_cxx_static -Wl,--no-whole-archive Celix::shell_api)
+ target_link_libraries(phase1_cxx PRIVATE -Wl,--no-undefined -Wl,--whole-archive dependency_manager_cxx_static -Wl,--no-whole-archive Celix::shell_api)
endif()
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/examples/hello_world/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/hello_world/CMakeLists.txt b/examples/hello_world/CMakeLists.txt
index 7cb590f..ca72eec 100644
--- a/examples/hello_world/CMakeLists.txt
+++ b/examples/hello_world/CMakeLists.txt
@@ -32,7 +32,7 @@ add_library(hello_test2lib SHARED
)
set_library_version(hello_test2lib "3.3.3")
-add_bundle(hello
+add_bundle(hello_bundle
VERSION "1.2"
SOURCES
private/src/activator.c
@@ -45,19 +45,19 @@ add_bundle(hello_export
EXPORT_LIBRARIES hello_test2lib
)
-bundle_private_libs(hello
+bundle_private_libs(hello_bundle
hello_testlib
)
add_deploy(helloworld_byref
GROUP hello
- BUNDLES hello_export hello ${CELIX_SHELL_BUNDLE} ${CELIX_SHELL_TUI_BUNDLE}
+ BUNDLES hello_export hello_bundle ${CELIX_SHELL_BUNDLE} ${CELIX_SHELL_TUI_BUNDLE}
)
add_deploy(helloworld_withcopy
GROUP hello
COPY #Ensures that bundles are copied in the deploy location
- BUNDLES hello_export hello ${SHELL_BUNDLE} ${SHELL_TUI_BUNDLE}
+ BUNDLES hello_export hello_bundle ${SHELL_BUNDLE} ${SHELL_TUI_BUNDLE}
)
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/examples/services_example_c/bar/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/services_example_c/bar/CMakeLists.txt b/examples/services_example_c/bar/CMakeLists.txt
index 2332931..0633c06 100644
--- a/examples/services_example_c/bar/CMakeLists.txt
+++ b/examples/services_example_c/bar/CMakeLists.txt
@@ -32,8 +32,8 @@ IF(APPLE)
else()
if(ENABLE_ADDRESS_SANITIZER)
#With asan there can be undefined symbols
- target_link_libraries(bar -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive Celix::framework )
+ target_link_libraries(bar PRIVATE -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive Celix::framework )
else()
- target_link_libraries(bar -Wl,--no-undefined -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive Celix::framework )
+ target_link_libraries(bar PRIVATE -Wl,--no-undefined -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive Celix::framework )
endif()
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/log_writer/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/log_writer/CMakeLists.txt b/log_writer/CMakeLists.txt
index a742af2..340af15 100644
--- a/log_writer/CMakeLists.txt
+++ b/log_writer/CMakeLists.txt
@@ -19,5 +19,9 @@ celix_subproject(LOG_WRITER "Option to enable building the Log Writer bundles" O
if (LOG_WRITER)
add_subdirectory(log_writer)
add_subdirectory(log_writer_stdout)
- add_subdirectory(log_writer_syslog)
+ add_subdirectory(log_writer_syslog)
+
+ #Setup target aliases to match external usage
+ add_library(Celix::log_writer_stdout ALIAS log_writer_stdout)
+ add_library(Celix::log_writer_syslog ALIAS log_writer_syslog)
endif (LOG_WRITER)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/log_writer/README.md
----------------------------------------------------------------------
diff --git a/log_writer/README.md b/log_writer/README.md
index 6de181d..29aebcc 100644
--- a/log_writer/README.md
+++ b/log_writer/README.md
@@ -1,7 +1,13 @@
-## Log Writer
+# Log Writer
The Celix Log Writers are components that read/listen to the Log Service and print the Log entries to the console or syslog, respectively.
-###### CMake options
+## CMake options
BUILD_LOG_WRITER=ON
BUILD_LOG_WRITER_SYSLOG=ON
+
+## Using info
+
+If the Celix Log Writers is installed The `FindCelix.cmake` will set:
+ - The `Celix::log_writer_stdout` bundle target
+ - The `Celix::log_writer_syslog` bundle target
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/log_writer/log_writer_stdout/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/log_writer/log_writer_stdout/CMakeLists.txt b/log_writer/log_writer_stdout/CMakeLists.txt
index 11734cc..6070b2e 100644
--- a/log_writer/log_writer_stdout/CMakeLists.txt
+++ b/log_writer/log_writer_stdout/CMakeLists.txt
@@ -15,18 +15,14 @@
# specific language governing permissions and limitations
# under the License.
-add_bundle(log_writer
+add_bundle(log_writer_stdout
SYMBOLIC_NAME "apache_celix_log_writer"
VERSION "1.1.0"
NAME "Apache Celix Log Writer"
SOURCES
- #${PROJECT_SOURCE_DIR}/log_writer/log_writer/private/src/log_writer_activator
- #${PROJECT_SOURCE_DIR}/log_writer/log_writer/private/src/log_writer
- #${PROJECT_SOURCE_DIR}/log_writer/log_writer/private/include/log_writer.h
-
src/log_writer_stdout
)
-install_bundle(log_writer)
+install_bundle(log_writer_stdout)
-target_link_libraries(log_writer PRIVATE Celix::log_service_api log_writer_common)
\ No newline at end of file
+target_link_libraries(log_writer_stdout PRIVATE Celix::log_service_api log_writer_common)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/log_writer/log_writer_syslog/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/log_writer/log_writer_syslog/CMakeLists.txt b/log_writer/log_writer_syslog/CMakeLists.txt
index caad713..b98b914 100644
--- a/log_writer/log_writer_syslog/CMakeLists.txt
+++ b/log_writer/log_writer_syslog/CMakeLists.txt
@@ -23,10 +23,6 @@ if (LOG_WRITER_SYSLOG)
SYMBOLIC_NAME "apache_celix_log_writer_syslog"
NAME "Apache Celix Log Writer Syslog"
SOURCES
-
- #${PROJECT_SOURCE_DIR}/log_writer/log_writer/private/src/log_writer_activator
- #${PROJECT_SOURCE_DIR}/log_writer/log_writer/private/src/log_writer
- #${PROJECT_SOURCE_DIR}/log_writer/log_writer/private/include/log_writer.h
private/src/log_writer_syslog
)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/CMakeLists.txt b/pubsub/CMakeLists.txt
index a866ba4..9d18175 100644
--- a/pubsub/CMakeLists.txt
+++ b/pubsub/CMakeLists.txt
@@ -43,7 +43,7 @@ if (PUBSUB)
endif()
#api target
- add_libary(pubsub_api INTERFACE)
+ add_library(pubsub_api INTERFACE)
target_include_directories(pubsub_api INTERFACE api)
#install api
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/deploy/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/deploy/CMakeLists.txt b/pubsub/deploy/CMakeLists.txt
index 6f9234d..e76f91b 100644
--- a/pubsub/deploy/CMakeLists.txt
+++ b/pubsub/deploy/CMakeLists.txt
@@ -165,7 +165,7 @@ if (BUILD_PUBSUB_PSA_ZMQ)
add_deploy("pubsub_mp_subscriber_zmq"
GROUP "pubsub"
BUNDLES
- Celix::hell
+ Celix::shell
Celix::shell_tui
org.apache.celix.pubsub_serializer.PubSubSerializerJson
org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/examples/mp_pubsub/publisher/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/examples/mp_pubsub/publisher/CMakeLists.txt b/pubsub/examples/mp_pubsub/publisher/CMakeLists.txt
index 76a01f1..1ef8645 100644
--- a/pubsub/examples/mp_pubsub/publisher/CMakeLists.txt
+++ b/pubsub/examples/mp_pubsub/publisher/CMakeLists.txt
@@ -47,4 +47,4 @@ bundle_files(org.apache.celix.pubsub_publisher.MpPublisher
DESTINATION "META-INF/keys/subscriber"
)
-target_link_libraries(org.apache.celix.pubsub_publisher.MpPublisher celix_framework celix_utils)
+target_link_libraries(org.apache.celix.pubsub_publisher.MpPublisher PRIVATE Celix::framework)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/examples/mp_pubsub/subscriber/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/examples/mp_pubsub/subscriber/CMakeLists.txt b/pubsub/examples/mp_pubsub/subscriber/CMakeLists.txt
index a480a73..e281ab1 100644
--- a/pubsub/examples/mp_pubsub/subscriber/CMakeLists.txt
+++ b/pubsub/examples/mp_pubsub/subscriber/CMakeLists.txt
@@ -47,4 +47,4 @@ bundle_files(org.apache.celix.pubsub_subscriber.MpSubscriber
DESTINATION "META-INF/keys/publisher"
)
-target_link_libraries(org.apache.celix.pubsub_subscriber.MpSubscriber celix_framework celix_utils)
+target_link_libraries(org.apache.celix.pubsub_subscriber.MpSubscriber PRIVATE Celix::framework)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/examples/pubsub/publisher/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/examples/pubsub/publisher/CMakeLists.txt b/pubsub/examples/pubsub/publisher/CMakeLists.txt
index e35c137..fcf50c7 100644
--- a/pubsub/examples/pubsub/publisher/CMakeLists.txt
+++ b/pubsub/examples/pubsub/publisher/CMakeLists.txt
@@ -51,4 +51,4 @@ bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher
DESTINATION "META-INF/keys/subscriber"
)
-target_link_libraries(org.apache.celix.pubsub_publisher.PoiPublisher celix_framework celix_utils)
+target_link_libraries(org.apache.celix.pubsub_publisher.PoiPublisher PRIVATE Celix::framework)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/examples/pubsub/publisher2/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/examples/pubsub/publisher2/CMakeLists.txt b/pubsub/examples/pubsub/publisher2/CMakeLists.txt
index b83f7dd..82ffb75 100644
--- a/pubsub/examples/pubsub/publisher2/CMakeLists.txt
+++ b/pubsub/examples/pubsub/publisher2/CMakeLists.txt
@@ -51,4 +51,4 @@ bundle_files(org.apache.celix.pubsub_publisher.PoiPublisher2
DESTINATION "META-INF/keys/subscriber"
)
-target_link_libraries(org.apache.celix.pubsub_publisher.PoiPublisher2 celix_framework celix_utils)
+target_link_libraries(org.apache.celix.pubsub_publisher.PoiPublisher2 PRIVATE Celix::framework)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/examples/pubsub/subscriber/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/examples/pubsub/subscriber/CMakeLists.txt b/pubsub/examples/pubsub/subscriber/CMakeLists.txt
index 7fd9fae..28569b0 100644
--- a/pubsub/examples/pubsub/subscriber/CMakeLists.txt
+++ b/pubsub/examples/pubsub/subscriber/CMakeLists.txt
@@ -52,4 +52,4 @@ bundle_files(org.apache.celix.pubsub_subscriber.PoiSubscriber
DESTINATION "META-INF/keys/publisher"
)
-target_link_libraries(org.apache.celix.pubsub_subscriber.PoiSubscriber celix_framework celix_utils)
+target_link_libraries(org.apache.celix.pubsub_subscriber.PoiSubscriber PRIVATE Celix::framework)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/CMakeLists.txt b/pubsub/pubsub_admin_udp_mc/CMakeLists.txt
index 3ab0c54..a57693f 100644
--- a/pubsub/pubsub_admin_udp_mc/CMakeLists.txt
+++ b/pubsub/pubsub_admin_udp_mc/CMakeLists.txt
@@ -17,32 +17,28 @@
find_package(Jansson REQUIRED)
-include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/dfi/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-include_directories("private/include")
-include_directories("public/include")
-include_directories("${JANSSON_INCLUDE_DIR}")
-
add_bundle(org.apache.celix.pubsub_admin.PubSubAdminUdpMc
BUNDLE_SYMBOLICNAME "apache_celix_pubsub_admin_udp_multicast"
VERSION "1.0.0"
SOURCES
- private/src/psa_activator.c
- private/src/pubsub_admin_impl.c
- private/src/topic_subscription.c
- private/src/topic_publication.c
- private/src/large_udp.c
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
+ src/psa_activator.c
+ src/pubsub_admin_impl.c
+ src/topic_subscription.c
+ src/topic_publication.c
+ src/large_udp.c
${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_endpoint.c
${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_admin_match.c
${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
)
+
+target_include_directories(org.apache.celix.pubsub_admin.PubSubAdminUdpMc PRIVATE
+ src
+ ${JANSSON_INCLUDE_DIR}
+)
+
set_target_properties(org.apache.celix.pubsub_admin.PubSubAdminUdpMc PROPERTIES INSTALL_RPATH "$ORIGIN")
-target_link_libraries(org.apache.celix.pubsub_admin.PubSubAdminUdpMc celix_framework celix_utils celix_dfi)
+target_link_libraries(org.apache.celix.pubsub_admin.PubSubAdminUdpMc PRIVATE Celix::framework Celix::dfi Celix::log_helper)
install_bundle(org.apache.celix.pubsub_admin.PubSubAdminUdpMc)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/private/include/large_udp.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/private/include/large_udp.h b/pubsub/pubsub_admin_udp_mc/private/include/large_udp.h
deleted file mode 100644
index a21e654..0000000
--- a/pubsub/pubsub_admin_udp_mc/private/include/large_udp.h
+++ /dev/null
@@ -1,45 +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.
- */
-/*
- * large_udp.h
- *
- * \date Mar 1, 2016
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef _LARGE_UDP_H_
-#define _LARGE_UDP_H_
-#include <stdbool.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-typedef struct largeUdp *largeUdp_pt;
-
-largeUdp_pt largeUdp_create(unsigned int maxNrUdpReceptions);
-void largeUdp_destroy(largeUdp_pt handle);
-
-int largeUdp_sendto(largeUdp_pt handle, int fd, void *buf, size_t count, int flags, struct sockaddr_in *dest_addr, size_t addrlen);
-int largeUdp_sendmsg(largeUdp_pt handle, int fd, struct iovec *largeMsg_iovec, int len, int flags, struct sockaddr_in *dest_addr, size_t addrlen);
-bool largeUdp_dataAvailable(largeUdp_pt handle, int fd, unsigned int *index, unsigned int *size);
-int largeUdp_read(largeUdp_pt handle, unsigned int index, void ** buffer, unsigned int size);
-
-#endif /* _LARGE_UDP_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/private/include/pubsub_admin_impl.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/private/include/pubsub_admin_impl.h b/pubsub/pubsub_admin_udp_mc/private/include/pubsub_admin_impl.h
deleted file mode 100644
index de4b813..0000000
--- a/pubsub/pubsub_admin_udp_mc/private/include/pubsub_admin_impl.h
+++ /dev/null
@@ -1,93 +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.
- */
-/*
- * pubsub_admin_impl.h
- *
- * \date Dec 5, 2013
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PUBSUB_ADMIN_UDP_MC_IMPL_H_
-#define PUBSUB_ADMIN_UDP_MC_IMPL_H_
-
-#include "pubsub_admin.h"
-#include "log_helper.h"
-
-#define PUBSUB_ADMIN_TYPE "udp_mc"
-
-struct pubsub_admin {
-
- bundle_context_pt bundle_context;
- log_helper_pt loghelper;
-
- /* List of the available serializers */
- celix_thread_mutex_t serializerListLock; // List<serializers>
- array_list_pt serializerList;
-
- celix_thread_mutex_t localPublicationsLock;
- hash_map_pt localPublications;//<topic(string),service_factory_pt>
-
- celix_thread_mutex_t externalPublicationsLock;
- hash_map_pt externalPublications;//<topic(string),List<pubsub_ep>>
-
- celix_thread_mutex_t subscriptionsLock;
- hash_map_pt subscriptions; //<topic(string),topic_subscription>
-
- celix_thread_mutex_t pendingSubscriptionsLock;
- celix_thread_mutexattr_t pendingSubscriptionsAttr;
- hash_map_pt pendingSubscriptions; //<topic(string),List<pubsub_ep>>
-
- /* Those are used to keep track of valid subscriptions/publications that still have no valid serializer */
- celix_thread_mutex_t noSerializerPendingsLock;
- celix_thread_mutexattr_t noSerializerPendingsAttr;
- array_list_pt noSerializerSubscriptions; // List<pubsub_ep>
- array_list_pt noSerializerPublications; // List<pubsub_ep>
-
- celix_thread_mutex_t usedSerializersLock;
- hash_map_pt topicSubscriptionsPerSerializer; // <serializer,List<topicSubscription>>
- hash_map_pt topicPublicationsPerSerializer; // <serializer,List<topicPublications>>
-
- char* ifIpAddress; // The local interface which is used for multicast communication
- char* mcIpAddress; // The multicast IP address
-
- int sendSocket;
- void* zmq_context; // to be removed
-
-};
-
-celix_status_t pubsubAdmin_create(bundle_context_pt context, pubsub_admin_pt *admin);
-celix_status_t pubsubAdmin_destroy(pubsub_admin_pt admin);
-
-celix_status_t pubsubAdmin_addSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
-celix_status_t pubsubAdmin_removeSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
-
-celix_status_t pubsubAdmin_addPublication(pubsub_admin_pt admin,pubsub_endpoint_pt pubEP);
-celix_status_t pubsubAdmin_removePublication(pubsub_admin_pt admin,pubsub_endpoint_pt pubEP);
-
-celix_status_t pubsubAdmin_closeAllPublications(pubsub_admin_pt admin,char* scope, char* topic);
-celix_status_t pubsubAdmin_closeAllSubscriptions(pubsub_admin_pt admin,char* scope, char* topic);
-
-celix_status_t pubsubAdmin_serializerAdded(void * handle, service_reference_pt reference, void * service);
-celix_status_t pubsubAdmin_serializerRemoved(void * handle, service_reference_pt reference, void * service);
-
-celix_status_t pubsubAdmin_matchEndpoint(pubsub_admin_pt admin, pubsub_endpoint_pt endpoint, double* score);
-
-
-#endif /* PUBSUB_ADMIN_UDP_MC_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/private/include/topic_publication.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/private/include/topic_publication.h b/pubsub/pubsub_admin_udp_mc/private/include/topic_publication.h
deleted file mode 100644
index 4363d71..0000000
--- a/pubsub/pubsub_admin_udp_mc/private/include/topic_publication.h
+++ /dev/null
@@ -1,57 +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.
- */
-/*
- * topic_publication.h
- *
- * \date Sep 24, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef TOPIC_PUBLICATION_H_
-#define TOPIC_PUBLICATION_H_
-
-#include "publisher.h"
-#include "pubsub_endpoint.h"
-#include "pubsub_common.h"
-
-#include "pubsub_serializer.h"
-
-#define UDP_BASE_PORT 49152
-#define UDP_MAX_PORT 65000
-
-typedef struct pubsub_udp_msg {
- struct pubsub_msg_header header;
- unsigned int payloadSize;
- char payload[];
-} pubsub_udp_msg_t;
-
-typedef struct topic_publication *topic_publication_pt;
-celix_status_t pubsub_topicPublicationCreate(int sendSocket, pubsub_endpoint_pt pubEP, pubsub_serializer_service_t *best_serializer, char* bindIP, topic_publication_pt *out);
-celix_status_t pubsub_topicPublicationDestroy(topic_publication_pt pub);
-
-celix_status_t pubsub_topicPublicationAddPublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep);
-celix_status_t pubsub_topicPublicationRemovePublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep);
-
-celix_status_t pubsub_topicPublicationStart(bundle_context_pt bundle_context,topic_publication_pt pub,service_factory_pt* svcFactory);
-celix_status_t pubsub_topicPublicationStop(topic_publication_pt pub);
-
-array_list_pt pubsub_topicPublicationGetPublisherList(topic_publication_pt pub);
-
-#endif /* TOPIC_PUBLICATION_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/private/include/topic_subscription.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/private/include/topic_subscription.h b/pubsub/pubsub_admin_udp_mc/private/include/topic_subscription.h
deleted file mode 100644
index 475416a..0000000
--- a/pubsub/pubsub_admin_udp_mc/private/include/topic_subscription.h
+++ /dev/null
@@ -1,60 +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.
- */
-/*
- * topic_subscription.h
- *
- * \date Sep 22, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef TOPIC_SUBSCRIPTION_H_
-#define TOPIC_SUBSCRIPTION_H_
-
-#include "celix_threads.h"
-#include "array_list.h"
-#include "celixbool.h"
-#include "service_tracker.h"
-
-#include "pubsub_endpoint.h"
-#include "pubsub_common.h"
-#include "pubsub_serializer.h"
-
-typedef struct topic_subscription* topic_subscription_pt;
-
-celix_status_t pubsub_topicSubscriptionCreate(bundle_context_pt bundle_context, char* ifIp,char* scope, char* topic ,pubsub_serializer_service_t *best_serializer, topic_subscription_pt* out);
-celix_status_t pubsub_topicSubscriptionDestroy(topic_subscription_pt ts);
-celix_status_t pubsub_topicSubscriptionStart(topic_subscription_pt ts);
-celix_status_t pubsub_topicSubscriptionStop(topic_subscription_pt ts);
-
-celix_status_t pubsub_topicSubscriptionAddConnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL);
-celix_status_t pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL);
-
-celix_status_t pubsub_topicSubscriptionConnectPublisher(topic_subscription_pt ts, char* pubURL);
-celix_status_t pubsub_topicSubscriptionDisconnectPublisher(topic_subscription_pt ts, char* pubURL);
-
-celix_status_t pubsub_topicSubscriptionAddSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP);
-celix_status_t pubsub_topicSubscriptionRemoveSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP);
-
-array_list_pt pubsub_topicSubscriptionGetSubscribersList(topic_subscription_pt sub);
-celix_status_t pubsub_topicIncreaseNrSubscribers(topic_subscription_pt subscription);
-celix_status_t pubsub_topicDecreaseNrSubscribers(topic_subscription_pt subscription);
-unsigned int pubsub_topicGetNrSubscribers(topic_subscription_pt subscription);
-
-#endif /*TOPIC_SUBSCRIPTION_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/private/src/large_udp.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/private/src/large_udp.c b/pubsub/pubsub_admin_udp_mc/private/src/large_udp.c
deleted file mode 100644
index 7455925..0000000
--- a/pubsub/pubsub_admin_udp_mc/private/src/large_udp.c
+++ /dev/null
@@ -1,372 +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.
- */
-/*
- * large_udp.c
- *
- * \date Mar 1, 2016
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include "large_udp.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <array_list.h>
-#include <pthread.h>
-
-#define MAX_UDP_MSG_SIZE 65535 /* 2^16 -1 */
-#define IP_HEADER_SIZE 20
-#define UDP_HEADER_SIZE 8
-//#define MTU_SIZE 1500
-#define MTU_SIZE 8000
-#define MAX_MSG_VECTOR_LEN 64
-
-//#define NO_IP_FRAGMENTATION
-
-struct largeUdp {
- unsigned int maxNrLists;
- array_list_pt udpPartLists;
- pthread_mutex_t dbLock;
-};
-
-typedef struct udpPartList {
- unsigned int msg_ident;
- unsigned int msg_size;
- unsigned int nrPartsRemaining;
- char *data;
-} *udpPartList_pt;
-
-
-typedef struct msg_part_header {
- unsigned int msg_ident;
- unsigned int total_msg_size;
- unsigned int part_msg_size;
- unsigned int offset;
-} msg_part_header_t;
-
-#ifdef NO_IP_FRAGMENTATION
-#define MAX_PART_SIZE (MTU_SIZE - (IP_HEADER_SIZE + UDP_HEADER_SIZE + sizeof(struct msg_part_header) ))
-#else
-#define MAX_PART_SIZE (MAX_UDP_MSG_SIZE - (IP_HEADER_SIZE + UDP_HEADER_SIZE + sizeof(struct msg_part_header) ))
-#endif
-
-typedef struct msg_part {
- msg_part_header_t header;
- char data[MAX_PART_SIZE];
-} msg_part_t;
-
-//
-// Create a handle
-//
-largeUdp_pt largeUdp_create(unsigned int maxNrUdpReceptions)
-{
- printf("## Creating large UDP\n");
- largeUdp_pt handle = calloc(sizeof(*handle), 1);
- if(handle != NULL) {
- handle->maxNrLists = maxNrUdpReceptions;
- if(arrayList_create(&handle->udpPartLists) != CELIX_SUCCESS) {
- free(handle);
- handle = NULL;
- }
- pthread_mutex_init(&handle->dbLock, 0);
- }
-
- return handle;
-}
-
-//
-// Destroys the handle
-//
-void largeUdp_destroy(largeUdp_pt handle)
-{
- printf("### Destroying large UDP\n");
- if(handle != NULL) {
- pthread_mutex_lock(&handle->dbLock);
- int nrUdpLists = arrayList_size(handle->udpPartLists);
- int i;
- for(i=0; i < nrUdpLists; i++) {
- udpPartList_pt udpPartList = arrayList_remove(handle->udpPartLists, i);
- if(udpPartList) {
- if(udpPartList->data) {
- free(udpPartList->data);
- udpPartList->data = NULL;
- }
- free(udpPartList);
- }
- }
- arrayList_destroy(handle->udpPartLists);
- handle->udpPartLists = NULL;
- pthread_mutex_unlock(&handle->dbLock);
- pthread_mutex_destroy(&handle->dbLock);
- free(handle);
- }
-}
-
-//
-// Write large data to UDP. This function splits the data in chunks and sends these chunks with a header over UDP.
-//
-int largeUdp_sendmsg(largeUdp_pt handle, int fd, struct iovec *largeMsg_iovec, int len, int flags, struct sockaddr_in *dest_addr, size_t addrlen)
-{
- int n;
- int result = 0;
- msg_part_header_t header;
-
- int written = 0;
- header.msg_ident = (unsigned int)random();
- header.total_msg_size = 0;
- for(n = 0; n < len ;n++) {
- header.total_msg_size += largeMsg_iovec[n].iov_len;
- }
- int nr_buffers = (header.total_msg_size / MAX_PART_SIZE) + 1;
-
- struct iovec msg_iovec[MAX_MSG_VECTOR_LEN];
- struct msghdr msg;
- msg.msg_name = dest_addr;
- msg.msg_namelen = addrlen;
- msg.msg_flags = 0;
- msg.msg_iov = msg_iovec;
- msg.msg_iovlen = 2; // header and payload;
- msg.msg_control = NULL;
- msg.msg_controllen = 0;
-
- msg.msg_iov[0].iov_base = &header;
- msg.msg_iov[0].iov_len = sizeof(header);
-
- for(n = 0; n < nr_buffers; n++) {
-
- header.part_msg_size = (((header.total_msg_size - n * MAX_PART_SIZE) > MAX_PART_SIZE) ? MAX_PART_SIZE : (header.total_msg_size - n * MAX_PART_SIZE));
- header.offset = n * MAX_PART_SIZE;
- int remainingOffset = header.offset;
- int recvPart = 0;
- // find the start of the part
- while(remainingOffset > largeMsg_iovec[recvPart].iov_len) {
- remainingOffset -= largeMsg_iovec[recvPart].iov_len;
- recvPart++;
- }
- int remainingData = header.part_msg_size;
- int sendPart = 1;
- msg.msg_iovlen = 1;
-
- // fill in the output iovec from the input iovec in such a way that all UDP frames are filled maximal.
- while(remainingData > 0) {
- int partLen = ( (largeMsg_iovec[recvPart].iov_len - remainingOffset) <= remainingData ? (largeMsg_iovec[recvPart].iov_len -remainingOffset) : remainingData);
- msg.msg_iov[sendPart].iov_base = largeMsg_iovec[recvPart].iov_base + remainingOffset;
- msg.msg_iov[sendPart].iov_len = partLen;
- remainingData -= partLen;
- remainingOffset = 0;
- sendPart++;
- recvPart++;
- msg.msg_iovlen++;
- }
- int tmp, tmptot;
- for(tmp = 0, tmptot=0; tmp < msg.msg_iovlen; tmp++) {
- tmptot += msg.msg_iov[tmp].iov_len;
- }
-
- int w = sendmsg(fd, &msg, 0);
- if(w == -1) {
- perror("send()");
- result = -1;
- break;
- }
- written += w;
- }
-
- return (result == 0 ? written : result);
-}
-
-//
-// Write large data to UDP. This function splits the data in chunks and sends these chunks with a header over UDP.
-//
-int largeUdp_sendto(largeUdp_pt handle, int fd, void *buf, size_t count, int flags, struct sockaddr_in *dest_addr, size_t addrlen)
-{
- int n;
- int nr_buffers = (count / MAX_PART_SIZE) + 1;
- int result = 0;
- msg_part_header_t header;
-
- int written = 0;
- header.msg_ident = (unsigned int)random();
- header.total_msg_size = count;
- char *databuf = buf;
-
- struct iovec msg_iovec[2];
- struct msghdr msg;
- msg.msg_name = dest_addr;
- msg.msg_namelen = addrlen;
- msg.msg_flags = 0;
- msg.msg_iov = msg_iovec;
- msg.msg_iovlen = 2; // header and payload;
- msg.msg_control = NULL;
- msg.msg_controllen = 0;
-
- msg.msg_iov[0].iov_base = &header;
- msg.msg_iov[0].iov_len = sizeof(header);
-
- for(n = 0; n < nr_buffers; n++) {
-
- header.part_msg_size = (((header.total_msg_size - n * MAX_PART_SIZE) > MAX_PART_SIZE) ? MAX_PART_SIZE : (header.total_msg_size - n * MAX_PART_SIZE));
- header.offset = n * MAX_PART_SIZE;
- msg.msg_iov[1].iov_base = &databuf[header.offset];
- msg.msg_iov[1].iov_len = header.part_msg_size;
- int w = sendmsg(fd, &msg, 0);
- if(w == -1) {
- perror("send()");
- result = -1;
- break;
- }
- written += w;
- //usleep(1000); // TODO: If not slept a UDP buffer overflow occurs and parts are missing at the reception side (at least via localhost)
- }
-
- return (result == 0 ? written : result);
-}
-
-//
-// Reads data from the filedescriptor which has date (determined by epoll()) and stores it in the internal structure
-// If the message is completely reassembled true is returned and the index and size have valid values
-//
-bool largeUdp_dataAvailable(largeUdp_pt handle, int fd, unsigned int *index, unsigned int *size) {
- msg_part_header_t header;
- int result = false;
- // Only read the header, we don't know yet where to store the payload
- if(recv(fd, &header, sizeof(header), MSG_PEEK) < 0) {
- perror("read()");
- return false;
- }
-
- struct iovec msg_vec[2];
- struct msghdr msg;
- msg.msg_name = NULL;
- msg.msg_namelen = 0;
- msg.msg_flags = 0;
- msg.msg_iov = msg_vec;
- msg.msg_iovlen = 2; // header and payload;
- msg.msg_control = NULL;
- msg.msg_controllen = 0;
-
- msg.msg_iov[0].iov_base = &header;
- msg.msg_iov[0].iov_len = sizeof(header);
-
- pthread_mutex_lock(&handle->dbLock);
-
- int nrUdpLists = arrayList_size(handle->udpPartLists);
- int i;
- bool found = false;
- for(i = 0; i < nrUdpLists; i++) {
- udpPartList_pt udpPartList = arrayList_get(handle->udpPartLists, i);
- if(udpPartList->msg_ident == header.msg_ident) {
- found = true;
-
- //sanity check
- if(udpPartList->msg_size != header.total_msg_size) {
- // Corruption occurred. Remove the existing administration and build up a new one.
- arrayList_remove(handle->udpPartLists, i);
- free(udpPartList->data);
- free(udpPartList);
- found = false;
- break;
- }
-
- msg.msg_iov[1].iov_base = &udpPartList->data[header.offset];
- msg.msg_iov[1].iov_len = header.part_msg_size;
- if(recvmsg(fd, &msg, 0)<0){
- found=true;
- result=false;
- break;
- }
-
- udpPartList->nrPartsRemaining--;
- if(udpPartList->nrPartsRemaining == 0) {
- *index = i;
- *size = udpPartList->msg_size;
- result = true;
- break;
- } else {
- result = false; // not complete
- break;
- }
- }
- }
-
- if(found == false) {
- udpPartList_pt udpPartList = NULL;
- if(nrUdpLists == handle->maxNrLists) {
- // remove list at index 0
- udpPartList = arrayList_remove(handle->udpPartLists, 0);
- fprintf(stderr, "ERROR: Removing entry for id %d: %d parts not received\n",udpPartList->msg_ident, udpPartList->nrPartsRemaining );
- free(udpPartList->data);
- free(udpPartList);
- nrUdpLists--;
- }
- udpPartList = calloc(sizeof(*udpPartList), 1);
- udpPartList->msg_ident = header.msg_ident;
- udpPartList->msg_size = header.total_msg_size;
- udpPartList->nrPartsRemaining = header.total_msg_size / MAX_PART_SIZE;
- udpPartList->data = calloc(sizeof(char), header.total_msg_size);
-
- msg.msg_iov[1].iov_base = &udpPartList->data[header.offset];
- msg.msg_iov[1].iov_len = header.part_msg_size;
- if(recvmsg(fd, &msg, 0)<0){
- free(udpPartList->data);
- free(udpPartList);
- result=false;
- }
- else{
- arrayList_add(handle->udpPartLists, udpPartList);
-
- if(udpPartList->nrPartsRemaining == 0) {
- *index = nrUdpLists;
- *size = udpPartList->msg_size;
- result = true;
- } else {
- result = false;
- }
- }
-
- }
-
- pthread_mutex_unlock(&handle->dbLock);
-
- return result;
-}
-
-//
-// Read out the message which is indicated available by the largeUdp_dataAvailable function
-//
-int largeUdp_read(largeUdp_pt handle, unsigned int index, void ** buffer, unsigned int size)
-{
- int result = 0;
- pthread_mutex_lock(&handle->dbLock);
-
- udpPartList_pt udpPartList = arrayList_remove(handle->udpPartLists, index);
- if(udpPartList) {
- *buffer = udpPartList->data;
- free(udpPartList);
- } else {
- result = -1;
- }
- pthread_mutex_unlock(&handle->dbLock);
-
- return result;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/private/src/psa_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/private/src/psa_activator.c b/pubsub/pubsub_admin_udp_mc/private/src/psa_activator.c
deleted file mode 100644
index cd4ee07..0000000
--- a/pubsub/pubsub_admin_udp_mc/private/src/psa_activator.c
+++ /dev/null
@@ -1,141 +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.
- */
-/*
- * psa_activator.c
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-
-#include "bundle_activator.h"
-#include "service_registration.h"
-#include "service_tracker.h"
-
-#include "pubsub_admin_impl.h"
-
-struct activator {
- pubsub_admin_pt admin;
- pubsub_admin_service_pt adminService;
- service_registration_pt registration;
- service_tracker_pt serializerTracker;
-};
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator;
-
- activator = calloc(1, sizeof(*activator));
- if (!activator) {
- status = CELIX_ENOMEM;
- }
- else{
- *userData = activator;
-
- status = pubsubAdmin_create(context, &(activator->admin));
-
- if(status == CELIX_SUCCESS){
- service_tracker_customizer_pt customizer = NULL;
- status = serviceTrackerCustomizer_create(activator->admin,
- NULL,
- pubsubAdmin_serializerAdded,
- NULL,
- pubsubAdmin_serializerRemoved,
- &customizer);
- if(status == CELIX_SUCCESS){
- status = serviceTracker_create(context, PUBSUB_SERIALIZER_SERVICE, customizer, &(activator->serializerTracker));
- if(status != CELIX_SUCCESS){
- serviceTrackerCustomizer_destroy(customizer);
- pubsubAdmin_destroy(activator->admin);
- }
- }
- else{
- pubsubAdmin_destroy(activator->admin);
- }
- }
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
- pubsub_admin_service_pt pubsubAdminSvc = calloc(1, sizeof(*pubsubAdminSvc));
-
- if (!pubsubAdminSvc) {
- status = CELIX_ENOMEM;
- }
- else{
- pubsubAdminSvc->admin = activator->admin;
-
- pubsubAdminSvc->addPublication = pubsubAdmin_addPublication;
- pubsubAdminSvc->removePublication = pubsubAdmin_removePublication;
-
- pubsubAdminSvc->addSubscription = pubsubAdmin_addSubscription;
- pubsubAdminSvc->removeSubscription = pubsubAdmin_removeSubscription;
-
- pubsubAdminSvc->closeAllPublications = pubsubAdmin_closeAllPublications;
- pubsubAdminSvc->closeAllSubscriptions = pubsubAdmin_closeAllSubscriptions;
-
- pubsubAdminSvc->matchEndpoint = pubsubAdmin_matchEndpoint;
-
- activator->adminService = pubsubAdminSvc;
-
- status = bundleContext_registerService(context, PUBSUB_ADMIN_SERVICE, pubsubAdminSvc, NULL, &activator->registration);
-
- status += serviceTracker_open(activator->serializerTracker);
-
- }
-
-
- return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- status += serviceTracker_close(activator->serializerTracker);
- status += serviceRegistration_unregister(activator->registration);
-
- activator->registration = NULL;
-
- free(activator->adminService);
- activator->adminService = NULL;
-
- return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- serviceTracker_destroy(activator->serializerTracker);
- pubsubAdmin_destroy(activator->admin);
- activator->admin = NULL;
-
- free(activator);
-
- return status;
-}
-
-
[18/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/private/src/pubsub_admin_impl.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/private/src/pubsub_admin_impl.c b/pubsub/pubsub_admin_udp_mc/private/src/pubsub_admin_impl.c
deleted file mode 100644
index 1fbdb08..0000000
--- a/pubsub/pubsub_admin_udp_mc/private/src/pubsub_admin_impl.c
+++ /dev/null
@@ -1,1039 +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.
- */
-/*
- * pubsub_admin_impl.c
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#ifndef ANDROID
-#include <ifaddrs.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-
-#include "constants.h"
-#include "utils.h"
-#include "hash_map.h"
-#include "array_list.h"
-#include "bundle_context.h"
-#include "bundle.h"
-#include "service_reference.h"
-#include "service_registration.h"
-#include "log_helper.h"
-#include "log_service.h"
-#include "celix_threads.h"
-#include "service_factory.h"
-
-#include "pubsub_admin_impl.h"
-#include "topic_subscription.h"
-#include "topic_publication.h"
-#include "pubsub_endpoint.h"
-#include "subscriber.h"
-#include "pubsub_admin_match.h"
-
-static const char *DEFAULT_MC_IP = "224.100.1.1";
-static char *DEFAULT_MC_PREFIX = "224.100";
-
-static celix_status_t pubsubAdmin_getIpAddress(const char* interface, char** ip);
-static celix_status_t pubsubAdmin_addSubscriptionToPendingList(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
-static celix_status_t pubsubAdmin_addAnySubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
-
-static celix_status_t pubsubAdmin_getBestSerializer(pubsub_admin_pt admin,pubsub_endpoint_pt ep, pubsub_serializer_service_t **serSvc);
-static void connectTopicPubSubToSerializer(pubsub_admin_pt admin,pubsub_serializer_service_t *serializer,void *topicPubSub,bool isPublication);
-static void disconnectTopicPubSubFromSerializer(pubsub_admin_pt admin,void *topicPubSub,bool isPublication);
-
-celix_status_t pubsubAdmin_create(bundle_context_pt context, pubsub_admin_pt *admin) {
- celix_status_t status = CELIX_SUCCESS;
-
- *admin = calloc(1, sizeof(**admin));
-
- if (!*admin) {
- return CELIX_ENOMEM;
- }
-
- char *mc_ip = NULL;
- char *if_ip = NULL;
- int sendSocket = -1;
-
- if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
- logHelper_start((*admin)->loghelper);
- }
- const char *mc_ip_prop = NULL;
- bundleContext_getProperty(context,PSA_IP , &mc_ip_prop);
- if(mc_ip_prop) {
- mc_ip = strdup(mc_ip_prop);
- }
-
-#ifndef ANDROID
- if (mc_ip == NULL) {
- const char *mc_prefix = NULL;
- const char *interface = NULL;
- int b0 = 0, b1 = 0, b2 = 0, b3 = 0;
- bundleContext_getProperty(context,PSA_MULTICAST_IP_PREFIX , &mc_prefix);
- if(mc_prefix == NULL) {
- mc_prefix = DEFAULT_MC_PREFIX;
- }
-
- bundleContext_getProperty(context, PSA_ITF, &interface);
- if (pubsubAdmin_getIpAddress(interface, &if_ip) != CELIX_SUCCESS) {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "PSA_UDP_MC: Could not retrieve IP address for interface %s", interface);
- }
-
- printf("IP Detected : %s\n", if_ip);
- if(if_ip && sscanf(if_ip, "%i.%i.%i.%i", &b0, &b1, &b2, &b3) != 4) {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "PSA_UDP_MC: Could not parse IP address %s", if_ip);
- b2 = 1;
- b3 = 1;
- }
-
- asprintf(&mc_ip, "%s.%d.%d",mc_prefix, b2, b3);
-
- sendSocket = socket(AF_INET, SOCK_DGRAM, 0);
- if(sendSocket == -1) {
- perror("pubsubAdmin_create:socket");
- status = CELIX_SERVICE_EXCEPTION;
- }
-
- if(status == CELIX_SUCCESS){
- char loop = 1;
- if(setsockopt(sendSocket, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)) != 0) {
- perror("pubsubAdmin_create:setsockopt(IP_MULTICAST_LOOP)");
- status = CELIX_SERVICE_EXCEPTION;
- }
- }
-
- if(status == CELIX_SUCCESS){
- struct in_addr multicast_interface;
- inet_aton(if_ip, &multicast_interface);
- if(setsockopt(sendSocket, IPPROTO_IP, IP_MULTICAST_IF, &multicast_interface, sizeof(multicast_interface)) != 0) {
- perror("pubsubAdmin_create:setsockopt(IP_MULTICAST_IF)");
- status = CELIX_SERVICE_EXCEPTION;
- }
- }
-
- }
-
-
- if(status != CELIX_SUCCESS){
- logHelper_stop((*admin)->loghelper);
- logHelper_destroy(&((*admin)->loghelper));
- if(sendSocket >=0){
- close(sendSocket);
- }
- if(if_ip != NULL){
- free(if_ip);
- }
- if(mc_ip != NULL){
- free(mc_ip);
- }
- return status;
- }
- else{
- (*admin)->sendSocket = sendSocket;
- }
-
-#endif
-
- (*admin)->bundle_context= context;
- (*admin)->localPublications = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- (*admin)->subscriptions = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- (*admin)->pendingSubscriptions = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- (*admin)->externalPublications = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- (*admin)->topicSubscriptionsPerSerializer = hashMap_create(NULL, NULL, NULL, NULL);
- (*admin)->topicPublicationsPerSerializer = hashMap_create(NULL, NULL, NULL, NULL);
- arrayList_create(&((*admin)->noSerializerSubscriptions));
- arrayList_create(&((*admin)->noSerializerPublications));
- arrayList_create(&((*admin)->serializerList));
-
- celixThreadMutex_create(&(*admin)->localPublicationsLock, NULL);
- celixThreadMutex_create(&(*admin)->subscriptionsLock, NULL);
- celixThreadMutex_create(&(*admin)->externalPublicationsLock, NULL);
- celixThreadMutex_create(&(*admin)->serializerListLock, NULL);
- celixThreadMutex_create(&(*admin)->usedSerializersLock, NULL);
-
- celixThreadMutexAttr_create(&(*admin)->noSerializerPendingsAttr);
- celixThreadMutexAttr_settype(&(*admin)->noSerializerPendingsAttr, CELIX_THREAD_MUTEX_RECURSIVE);
- celixThreadMutex_create(&(*admin)->noSerializerPendingsLock, &(*admin)->noSerializerPendingsAttr);
-
- celixThreadMutexAttr_create(&(*admin)->pendingSubscriptionsAttr);
- celixThreadMutexAttr_settype(&(*admin)->pendingSubscriptionsAttr, CELIX_THREAD_MUTEX_RECURSIVE);
- celixThreadMutex_create(&(*admin)->pendingSubscriptionsLock, &(*admin)->pendingSubscriptionsAttr);
-
- if (if_ip != NULL) {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "PSA_UDP_MC: Using %s as interface for multicast communication", if_ip);
- (*admin)->ifIpAddress = if_ip;
- } else {
- (*admin)->ifIpAddress = strdup("127.0.0.1");
- }
-
- if (mc_ip != NULL) {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "PSA_UDP_MC: Using %s for service annunciation", mc_ip);
- (*admin)->mcIpAddress = mc_ip;
- }
- else {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "PSA_UDP_MC: No IP address for service annunciation set. Using %s", DEFAULT_MC_IP);
- (*admin)->mcIpAddress = strdup(DEFAULT_MC_IP);
- }
-
- return status;
-}
-
-
-celix_status_t pubsubAdmin_destroy(pubsub_admin_pt admin)
-{
- celix_status_t status = CELIX_SUCCESS;
-
- free(admin->mcIpAddress);
- free(admin->ifIpAddress);
-
- celixThreadMutex_lock(&admin->pendingSubscriptionsLock);
- hash_map_iterator_pt iter = hashMapIterator_create(admin->pendingSubscriptions);
- while(hashMapIterator_hasNext(iter)){
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- free((char*)hashMapEntry_getKey(entry));
- arrayList_destroy((array_list_pt)hashMapEntry_getValue(entry));
- }
- hashMapIterator_destroy(iter);
- hashMap_destroy(admin->pendingSubscriptions,false,false);
- celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);
-
- celixThreadMutex_lock(&admin->subscriptionsLock);
- hashMap_destroy(admin->subscriptions,false,false);
- celixThreadMutex_unlock(&admin->subscriptionsLock);
-
- celixThreadMutex_lock(&admin->localPublicationsLock);
- hashMap_destroy(admin->localPublications,true,false);
- celixThreadMutex_unlock(&admin->localPublicationsLock);
-
- celixThreadMutex_lock(&admin->externalPublicationsLock);
- iter = hashMapIterator_create(admin->externalPublications);
- while(hashMapIterator_hasNext(iter)){
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- free((char*)hashMapEntry_getKey(entry));
- arrayList_destroy((array_list_pt)hashMapEntry_getValue(entry));
- }
- hashMapIterator_destroy(iter);
- hashMap_destroy(admin->externalPublications,false,false);
- celixThreadMutex_unlock(&admin->externalPublicationsLock);
-
- celixThreadMutex_lock(&admin->serializerListLock);
- arrayList_destroy(admin->serializerList);
- celixThreadMutex_unlock(&admin->serializerListLock);
-
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
- arrayList_destroy(admin->noSerializerSubscriptions);
- arrayList_destroy(admin->noSerializerPublications);
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
-
- celixThreadMutex_lock(&admin->usedSerializersLock);
-
- iter = hashMapIterator_create(admin->topicSubscriptionsPerSerializer);
- while(hashMapIterator_hasNext(iter)){
- arrayList_destroy((array_list_pt)hashMapIterator_nextValue(iter));
- }
- hashMapIterator_destroy(iter);
- hashMap_destroy(admin->topicSubscriptionsPerSerializer,false,false);
-
- iter = hashMapIterator_create(admin->topicPublicationsPerSerializer);
- while(hashMapIterator_hasNext(iter)){
- arrayList_destroy((array_list_pt)hashMapIterator_nextValue(iter));
- }
- hashMapIterator_destroy(iter);
- hashMap_destroy(admin->topicPublicationsPerSerializer,false,false);
-
- celixThreadMutex_unlock(&admin->usedSerializersLock);
-
- celixThreadMutex_destroy(&admin->usedSerializersLock);
- celixThreadMutex_destroy(&admin->serializerListLock);
-
- celixThreadMutexAttr_destroy(&admin->noSerializerPendingsAttr);
- celixThreadMutex_destroy(&admin->noSerializerPendingsLock);
-
- celixThreadMutex_destroy(&admin->pendingSubscriptionsLock);
- celixThreadMutexAttr_destroy(&admin->pendingSubscriptionsAttr);
-
- celixThreadMutex_destroy(&admin->subscriptionsLock);
- celixThreadMutex_destroy(&admin->localPublicationsLock);
- celixThreadMutex_destroy(&admin->externalPublicationsLock);
-
- logHelper_stop(admin->loghelper);
-
- logHelper_destroy(&admin->loghelper);
-
- free(admin);
-
- return status;
-}
-
-static celix_status_t pubsubAdmin_addAnySubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&admin->subscriptionsLock);
-
- topic_subscription_pt any_sub = hashMap_get(admin->subscriptions,PUBSUB_ANY_SUB_TOPIC);
-
- if(any_sub==NULL){
-
- int i;
- pubsub_serializer_service_t *best_serializer = NULL;
- if( (status=pubsubAdmin_getBestSerializer(admin, subEP, &best_serializer)) == CELIX_SUCCESS){
- status = pubsub_topicSubscriptionCreate(admin->bundle_context, admin->ifIpAddress, PUBSUB_SUBSCRIBER_SCOPE_DEFAULT, PUBSUB_ANY_SUB_TOPIC, best_serializer, &any_sub);
- }
- else{
- printf("PSA_UDP_MC: Cannot find a serializer for subscribing topic %s. Adding it to pending list.\n",subEP->topic);
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
- arrayList_add(admin->noSerializerSubscriptions,subEP);
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
- }
-
- if (status == CELIX_SUCCESS){
-
- /* Connect all internal publishers */
- celixThreadMutex_lock(&admin->localPublicationsLock);
- hash_map_iterator_pt lp_iter =hashMapIterator_create(admin->localPublications);
- while(hashMapIterator_hasNext(lp_iter)){
- service_factory_pt factory = (service_factory_pt)hashMapIterator_nextValue(lp_iter);
- topic_publication_pt topic_pubs = (topic_publication_pt)factory->handle;
- array_list_pt topic_publishers = pubsub_topicPublicationGetPublisherList(topic_pubs);
-
- if(topic_publishers!=NULL){
- for(i=0;i<arrayList_size(topic_publishers);i++){
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(topic_publishers,i);
- if(pubEP->endpoint !=NULL){
- status += pubsub_topicSubscriptionConnectPublisher(any_sub,pubEP->endpoint);
- }
- }
- arrayList_destroy(topic_publishers);
- }
- }
- hashMapIterator_destroy(lp_iter);
- celixThreadMutex_unlock(&admin->localPublicationsLock);
-
- /* Connect also all external publishers */
- celixThreadMutex_lock(&admin->externalPublicationsLock);
- hash_map_iterator_pt extp_iter =hashMapIterator_create(admin->externalPublications);
- while(hashMapIterator_hasNext(extp_iter)){
- array_list_pt ext_pub_list = (array_list_pt)hashMapIterator_nextValue(extp_iter);
- if(ext_pub_list!=NULL){
- for(i=0;i<arrayList_size(ext_pub_list);i++){
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
- if(pubEP->endpoint !=NULL){
- status += pubsub_topicSubscriptionConnectPublisher(any_sub,pubEP->endpoint);
- }
- }
- }
- }
- hashMapIterator_destroy(extp_iter);
- celixThreadMutex_unlock(&admin->externalPublicationsLock);
-
-
- pubsub_topicSubscriptionAddSubscriber(any_sub,subEP);
-
- status += pubsub_topicSubscriptionStart(any_sub);
-
- }
-
- if (status == CELIX_SUCCESS){
- hashMap_put(admin->subscriptions,strdup(PUBSUB_ANY_SUB_TOPIC),any_sub);
- connectTopicPubSubToSerializer(admin, best_serializer, any_sub, false);
- }
-
- }
-
- celixThreadMutex_unlock(&admin->subscriptionsLock);
-
- return status;
-}
-
-celix_status_t pubsubAdmin_addSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
- celix_status_t status = CELIX_SUCCESS;
-
- printf("PSA_UDP_MC: Received subscription [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n",subEP->frameworkUUID,subEP->serviceID,subEP->scope,subEP->topic);
-
- if(strcmp(subEP->topic,PUBSUB_ANY_SUB_TOPIC)==0){
- return pubsubAdmin_addAnySubscription(admin,subEP);
- }
-
- /* Check if we already know some publisher about this topic, otherwise let's put the subscription in the pending hashmap */
- celixThreadMutex_lock(&admin->pendingSubscriptionsLock);
- celixThreadMutex_lock(&admin->subscriptionsLock);
- celixThreadMutex_lock(&admin->localPublicationsLock);
- celixThreadMutex_lock(&admin->externalPublicationsLock);
-
- char* scope_topic = createScopeTopicKey(subEP->scope,subEP->topic);
-
- service_factory_pt factory = (service_factory_pt)hashMap_get(admin->localPublications,scope_topic);
- array_list_pt ext_pub_list = (array_list_pt)hashMap_get(admin->externalPublications,scope_topic);
-
- if(factory==NULL && ext_pub_list==NULL){ //No (local or external) publishers yet for this topic
- pubsubAdmin_addSubscriptionToPendingList(admin,subEP);
- }
- else{
- int i;
- topic_subscription_pt subscription = hashMap_get(admin->subscriptions, scope_topic);
-
- if(subscription == NULL) {
- pubsub_serializer_service_t *best_serializer = NULL;
- if( (status=pubsubAdmin_getBestSerializer(admin, subEP, &best_serializer)) == CELIX_SUCCESS){
- status += pubsub_topicSubscriptionCreate(admin->bundle_context,admin->ifIpAddress, subEP->scope, subEP->topic, best_serializer, &subscription);
- }
- else{
- printf("PSA_UDP_MC: Cannot find a serializer for subscribing topic %s. Adding it to pending list.\n",subEP->topic);
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
- arrayList_add(admin->noSerializerSubscriptions,subEP);
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
- }
-
- if (status==CELIX_SUCCESS){
-
- /* Try to connect internal publishers */
- if(factory!=NULL){
- topic_publication_pt topic_pubs = (topic_publication_pt)factory->handle;
- array_list_pt topic_publishers = pubsub_topicPublicationGetPublisherList(topic_pubs);
-
- if(topic_publishers!=NULL){
- for(i=0;i<arrayList_size(topic_publishers);i++){
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(topic_publishers,i);
- if(pubEP->endpoint !=NULL){
- status += pubsub_topicSubscriptionConnectPublisher(subscription,pubEP->endpoint);
- }
- }
- arrayList_destroy(topic_publishers);
- }
-
- }
-
- /* Look also for external publishers */
- if(ext_pub_list!=NULL){
- for(i=0;i<arrayList_size(ext_pub_list);i++){
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
- if(pubEP->endpoint !=NULL){
- status += pubsub_topicSubscriptionConnectPublisher(subscription,pubEP->endpoint);
- }
- }
- }
-
- pubsub_topicSubscriptionAddSubscriber(subscription,subEP);
-
- status += pubsub_topicSubscriptionStart(subscription);
-
- }
-
- if(status==CELIX_SUCCESS){
-
- hashMap_put(admin->subscriptions,strdup(scope_topic),subscription);
-
- connectTopicPubSubToSerializer(admin, best_serializer, subscription, false);
- }
- }
-
- if (status == CELIX_SUCCESS){
- pubsub_topicIncreaseNrSubscribers(subscription);
- }
- }
-
- free(scope_topic);
- celixThreadMutex_unlock(&admin->externalPublicationsLock);
- celixThreadMutex_unlock(&admin->localPublicationsLock);
- celixThreadMutex_unlock(&admin->subscriptionsLock);
- celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);
-
- return status;
-
-}
-
-celix_status_t pubsubAdmin_removeSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
- celix_status_t status = CELIX_SUCCESS;
-
- printf("PSA_UDP_MC: Removing subscription [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n",subEP->frameworkUUID,subEP->serviceID,subEP->scope, subEP->topic);
-
- char* scope_topic = createScopeTopicKey(subEP->scope, subEP->topic);
-
- celixThreadMutex_lock(&admin->subscriptionsLock);
- topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic);
- if(sub!=NULL){
- pubsub_topicDecreaseNrSubscribers(sub);
- if(pubsub_topicGetNrSubscribers(sub) == 0) {
- status = pubsub_topicSubscriptionRemoveSubscriber(sub,subEP);
- }
- }
- celixThreadMutex_unlock(&admin->subscriptionsLock);
-
- if(sub==NULL){
- /* Maybe the endpoint was pending */
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
- if(!arrayList_removeElement(admin->noSerializerSubscriptions, subEP)){
- status = CELIX_ILLEGAL_STATE;
- }
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
- }
-
- free(scope_topic);
-
-
-
- return status;
-
-}
-
-celix_status_t pubsubAdmin_addPublication(pubsub_admin_pt admin,pubsub_endpoint_pt pubEP){
- celix_status_t status = CELIX_SUCCESS;
-
- printf("PSA_UDP_MC: Received publication [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n",pubEP->frameworkUUID,pubEP->serviceID,pubEP->scope, pubEP->topic);
-
- const char* fwUUID = NULL;
-
- bundleContext_getProperty(admin->bundle_context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
- if(fwUUID==NULL){
- printf("PSA_UDP_MC: Cannot retrieve fwUUID.\n");
- return CELIX_INVALID_BUNDLE_CONTEXT;
- }
- char* scope_topic = createScopeTopicKey(pubEP->scope, pubEP->topic);
-
- if ((strcmp(pubEP->frameworkUUID, fwUUID) == 0) && (pubEP->endpoint == NULL)) {
-
- celixThreadMutex_lock(&admin->localPublicationsLock);
-
- service_factory_pt factory = (service_factory_pt) hashMap_get(admin->localPublications, scope_topic);
-
- if (factory == NULL) {
- topic_publication_pt pub = NULL;
- pubsub_serializer_service_t *best_serializer = NULL;
- if( (status=pubsubAdmin_getBestSerializer(admin, pubEP, &best_serializer)) == CELIX_SUCCESS){
- status = pubsub_topicPublicationCreate(admin->sendSocket, pubEP, best_serializer, admin->mcIpAddress, &pub);
- }
- else{
- printf("PSA_UDP_MC: Cannot find a serializer for publishing topic %s. Adding it to pending list.\n", pubEP->topic);
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
- arrayList_add(admin->noSerializerPublications,pubEP);
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
- }
-
- if (status == CELIX_SUCCESS) {
- status = pubsub_topicPublicationStart(admin->bundle_context, pub, &factory);
- if (status == CELIX_SUCCESS && factory != NULL) {
- hashMap_put(admin->localPublications, strdup(scope_topic), factory);
- connectTopicPubSubToSerializer(admin, best_serializer, pub, true);
- }
- } else {
- printf("PSA_UDP_MC: Cannot create a topicPublication for scope=%s, topic=%s (bundle %ld).\n", pubEP->scope, pubEP->topic, pubEP->serviceID);
- }
- } else {
- //just add the new EP to the list
- topic_publication_pt pub = (topic_publication_pt) factory->handle;
- pubsub_topicPublicationAddPublisherEP(pub, pubEP);
- }
-
- celixThreadMutex_unlock(&admin->localPublicationsLock);
- }
- else{
-
- celixThreadMutex_lock(&admin->externalPublicationsLock);
- array_list_pt ext_pub_list = (array_list_pt) hashMap_get(admin->externalPublications, scope_topic);
- if (ext_pub_list == NULL) {
- arrayList_create(&ext_pub_list);
- hashMap_put(admin->externalPublications, strdup(scope_topic), ext_pub_list);
- }
-
- arrayList_add(ext_pub_list, pubEP);
-
- celixThreadMutex_unlock(&admin->externalPublicationsLock);
- }
-
- /* Re-evaluate the pending subscriptions */
- celixThreadMutex_lock(&admin->pendingSubscriptionsLock);
-
- hash_map_entry_pt pendingSub = hashMap_getEntry(admin->pendingSubscriptions, scope_topic);
- if (pendingSub != NULL) { //There were pending subscription for the just published topic. Let's connect them.
- char* topic = (char*) hashMapEntry_getKey(pendingSub);
- array_list_pt pendingSubList = (array_list_pt) hashMapEntry_getValue(pendingSub);
- int i;
- for (i = 0; i < arrayList_size(pendingSubList); i++) {
- pubsub_endpoint_pt subEP = (pubsub_endpoint_pt) arrayList_get(pendingSubList, i);
- pubsubAdmin_addSubscription(admin, subEP);
- }
- hashMap_remove(admin->pendingSubscriptions, scope_topic);
- arrayList_clear(pendingSubList);
- arrayList_destroy(pendingSubList);
- free(topic);
- }
-
- celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);
-
- /* Connect the new publisher to the subscription for his topic, if there is any */
- celixThreadMutex_lock(&admin->subscriptionsLock);
-
- topic_subscription_pt sub = (topic_subscription_pt) hashMap_get(admin->subscriptions, scope_topic);
- if (sub != NULL && pubEP->endpoint != NULL) {
- pubsub_topicSubscriptionAddConnectPublisherToPendingList(sub, pubEP->endpoint);
- }
-
- /* And check also for ANY subscription */
- topic_subscription_pt any_sub = (topic_subscription_pt) hashMap_get(admin->subscriptions, PUBSUB_ANY_SUB_TOPIC);
- if (any_sub != NULL && pubEP->endpoint != NULL) {
- pubsub_topicSubscriptionAddConnectPublisherToPendingList(any_sub, pubEP->endpoint);
- }
-
- free(scope_topic);
-
- celixThreadMutex_unlock(&admin->subscriptionsLock);
-
- return status;
-
-}
-
-celix_status_t pubsubAdmin_removePublication(pubsub_admin_pt admin,pubsub_endpoint_pt pubEP){
- celix_status_t status = CELIX_SUCCESS;
- int count = 0;
-
- printf("PSA_UDP_MC: Removing publication [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n",pubEP->frameworkUUID,pubEP->serviceID,pubEP->scope, pubEP->topic);
-
- const char* fwUUID = NULL;
-
- bundleContext_getProperty(admin->bundle_context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
- if(fwUUID==NULL){
- printf("PSA_UDP_MC: Cannot retrieve fwUUID.\n");
- return CELIX_INVALID_BUNDLE_CONTEXT;
- }
- char *scope_topic = createScopeTopicKey(pubEP->scope, pubEP->topic);
-
- if(strcmp(pubEP->frameworkUUID,fwUUID)==0){
-
- celixThreadMutex_lock(&admin->localPublicationsLock);
- service_factory_pt factory = (service_factory_pt)hashMap_get(admin->localPublications,scope_topic);
- if(factory!=NULL){
- topic_publication_pt pub = (topic_publication_pt)factory->handle;
- pubsub_topicPublicationRemovePublisherEP(pub,pubEP);
- }
- celixThreadMutex_unlock(&admin->localPublicationsLock);
-
- if(factory==NULL){
- /* Maybe the endpoint was pending */
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
- if(!arrayList_removeElement(admin->noSerializerPublications, pubEP)){
- status = CELIX_ILLEGAL_STATE;
- }
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
- }
-
- }
- else{
-
- celixThreadMutex_lock(&admin->externalPublicationsLock);
- array_list_pt ext_pub_list = (array_list_pt)hashMap_get(admin->externalPublications,scope_topic);
- if(ext_pub_list!=NULL){
- int i;
- bool found = false;
- for(i=0;!found && i<arrayList_size(ext_pub_list);i++){
- pubsub_endpoint_pt p = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
- found = pubsubEndpoint_equals(pubEP,p);
- if (found){
- arrayList_remove(ext_pub_list,i);
- }
- }
- // Check if there are more publishers on the same endpoint (happens when 1 celix-instance with multiple bundles publish in same topic)
- for(i=0; i<arrayList_size(ext_pub_list);i++) {
- pubsub_endpoint_pt p = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
- if (strcmp(pubEP->endpoint,p->endpoint) == 0) {
- count++;
- }
- }
-
- if(arrayList_size(ext_pub_list)==0){
- hash_map_entry_pt entry = hashMap_getEntry(admin->externalPublications,scope_topic);
- char* topic = (char*)hashMapEntry_getKey(entry);
- array_list_pt list = (array_list_pt)hashMapEntry_getValue(entry);
- hashMap_remove(admin->externalPublications,topic);
- arrayList_destroy(list);
- free(topic);
- }
- }
-
- celixThreadMutex_unlock(&admin->externalPublicationsLock);
- }
-
- /* Check if this publisher was connected to one of our subscribers*/
- celixThreadMutex_lock(&admin->subscriptionsLock);
-
- topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic);
- if(sub!=NULL && pubEP->endpoint!=NULL && count == 0){
- pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(sub,pubEP->endpoint);
- }
-
- /* And check also for ANY subscription */
- topic_subscription_pt any_sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,PUBSUB_ANY_SUB_TOPIC);
- if(any_sub!=NULL && pubEP->endpoint!=NULL && count == 0){
- pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(any_sub,pubEP->endpoint);
- }
-
- free(scope_topic);
- celixThreadMutex_unlock(&admin->subscriptionsLock);
-
- return status;
-
-}
-
-celix_status_t pubsubAdmin_closeAllPublications(pubsub_admin_pt admin,char *scope, char* topic){
- celix_status_t status = CELIX_SUCCESS;
-
- printf("PSA_UDP_MC: Closing all publications for scope=%s,topic=%s\n", scope, topic);
-
- celixThreadMutex_lock(&admin->localPublicationsLock);
- char* scope_topic =createScopeTopicKey(scope, topic);
- hash_map_entry_pt pubsvc_entry = (hash_map_entry_pt)hashMap_getEntry(admin->localPublications,scope_topic);
- if(pubsvc_entry!=NULL){
- char* key = (char*)hashMapEntry_getKey(pubsvc_entry);
- service_factory_pt factory= (service_factory_pt)hashMapEntry_getValue(pubsvc_entry);
- topic_publication_pt pub = (topic_publication_pt)factory->handle;
- status += pubsub_topicPublicationStop(pub);
- disconnectTopicPubSubFromSerializer(admin, pub, true);
- status += pubsub_topicPublicationDestroy(pub);
- hashMap_remove(admin->localPublications,scope_topic);
- free(key);
- free(factory);
- }
- free(scope_topic);
- celixThreadMutex_unlock(&admin->localPublicationsLock);
-
- return status;
-
-}
-
-celix_status_t pubsubAdmin_closeAllSubscriptions(pubsub_admin_pt admin,char *scope, char* topic){
- celix_status_t status = CELIX_SUCCESS;
-
- printf("PSA_UDP_MC: Closing all subscriptions\n");
-
- celixThreadMutex_lock(&admin->subscriptionsLock);
- char* scope_topic =createScopeTopicKey(scope, topic);
- hash_map_entry_pt sub_entry = (hash_map_entry_pt)hashMap_getEntry(admin->subscriptions,scope_topic);
- if(sub_entry!=NULL){
- char* topic = (char*)hashMapEntry_getKey(sub_entry);
-
- topic_subscription_pt ts = (topic_subscription_pt)hashMapEntry_getValue(sub_entry);
- status += pubsub_topicSubscriptionStop(ts);
- disconnectTopicPubSubFromSerializer(admin, ts, false);
- status += pubsub_topicSubscriptionDestroy(ts);
- hashMap_remove(admin->subscriptions,topic);
- free(topic);
-
- }
- free(scope_topic);
- celixThreadMutex_unlock(&admin->subscriptionsLock);
-
- return status;
-
-}
-
-
-#ifndef ANDROID
-static celix_status_t pubsubAdmin_getIpAddress(const char* interface, char** ip) {
- celix_status_t status = CELIX_BUNDLE_EXCEPTION;
-
- struct ifaddrs *ifaddr, *ifa;
- char host[NI_MAXHOST];
-
- if (getifaddrs(&ifaddr) != -1)
- {
- for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
- {
- if (ifa->ifa_addr == NULL)
- continue;
-
- if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
- if (interface == NULL) {
- *ip = strdup(host);
- status = CELIX_SUCCESS;
- }
- else if (strcmp(ifa->ifa_name, interface) == 0) {
- *ip = strdup(host);
- status = CELIX_SUCCESS;
- }
- }
- }
-
- freeifaddrs(ifaddr);
- }
-
- return status;
-}
-#endif
-
-static celix_status_t pubsubAdmin_addSubscriptionToPendingList(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
- celix_status_t status = CELIX_SUCCESS;
-
- char* scope_topic =createScopeTopicKey(subEP->scope, subEP->topic);
- array_list_pt pendingListPerTopic = hashMap_get(admin->pendingSubscriptions,scope_topic);
- if(pendingListPerTopic==NULL){
- arrayList_create(&pendingListPerTopic);
- hashMap_put(admin->pendingSubscriptions,strdup(scope_topic),pendingListPerTopic);
- }
- arrayList_add(pendingListPerTopic,subEP);
- free(scope_topic);
-
- return status;
-}
-
-
-celix_status_t pubsubAdmin_serializerAdded(void * handle, service_reference_pt reference, void * service){
- /* Assumption: serializers are all available at startup.
- * If a new (possibly better) serializer is installed and started, already created topic_publications/subscriptions will not be destroyed and recreated */
-
- celix_status_t status = CELIX_SUCCESS;
- int i=0;
-
- const char *serType = NULL;
- serviceReference_getProperty(reference, PUBSUB_SERIALIZER_TYPE_KEY,&serType);
- if(serType == NULL){
- printf("Serializer serviceReference %p has no pubsub_serializer.type property specified\n",reference);
- return CELIX_SERVICE_EXCEPTION;
- }
-
- pubsub_admin_pt admin = (pubsub_admin_pt)handle;
- celixThreadMutex_lock(&admin->serializerListLock);
- arrayList_add(admin->serializerList, reference);
- celixThreadMutex_unlock(&admin->serializerListLock);
-
- /* Now let's re-evaluate the pending */
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
-
- for(i=0;i<arrayList_size(admin->noSerializerSubscriptions);i++){
- pubsub_endpoint_pt ep = (pubsub_endpoint_pt)arrayList_get(admin->noSerializerSubscriptions,i);
- pubsub_serializer_service_t *best_serializer = NULL;
- pubsubAdmin_getBestSerializer(admin, ep, &best_serializer);
- if(best_serializer != NULL){ /* Finally we have a valid serializer! */
- pubsubAdmin_addSubscription(admin, ep);
- }
- }
-
- for(i=0;i<arrayList_size(admin->noSerializerPublications);i++){
- pubsub_endpoint_pt ep = (pubsub_endpoint_pt)arrayList_get(admin->noSerializerPublications,i);
- pubsub_serializer_service_t *best_serializer = NULL;
- pubsubAdmin_getBestSerializer(admin, ep, &best_serializer);
- if(best_serializer != NULL){ /* Finally we have a valid serializer! */
- pubsubAdmin_addPublication(admin, ep);
- }
- }
-
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
-
- printf("PSA_UDP_MC: %s serializer added\n",serType);
-
- return status;
-}
-
-celix_status_t pubsubAdmin_serializerRemoved(void * handle, service_reference_pt reference, void * service){
-
- pubsub_admin_pt admin = (pubsub_admin_pt)handle;
- int i=0, j=0;
- const char *serType = NULL;
-
- serviceReference_getProperty(reference, PUBSUB_SERIALIZER_TYPE_KEY,&serType);
- if(serType == NULL){
- printf("Serializer serviceReference %p has no pubsub_serializer.type property specified\n",reference);
- return CELIX_SERVICE_EXCEPTION;
- }
-
- celixThreadMutex_lock(&admin->serializerListLock);
- /* Remove the serializer from the list */
- arrayList_removeElement(admin->serializerList, reference);
- celixThreadMutex_unlock(&admin->serializerListLock);
-
- celixThreadMutex_lock(&admin->usedSerializersLock);
- array_list_pt topicPubList = (array_list_pt)hashMap_remove(admin->topicPublicationsPerSerializer, service);
- array_list_pt topicSubList = (array_list_pt)hashMap_remove(admin->topicSubscriptionsPerSerializer, service);
- celixThreadMutex_unlock(&admin->usedSerializersLock);
-
- /* Now destroy the topicPublications, but first put back the pubsub_endpoints back to the noSerializer pending list */
- if(topicPubList!=NULL){
- for(i=0;i<arrayList_size(topicPubList);i++){
- topic_publication_pt topicPub = (topic_publication_pt)arrayList_get(topicPubList,i);
- /* Stop the topic publication */
- pubsub_topicPublicationStop(topicPub);
- /* Get the endpoints that are going to be orphan */
- array_list_pt pubList = pubsub_topicPublicationGetPublisherList(topicPub);
- for(j=0;j<arrayList_size(pubList);j++){
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pubList,j);
- /* Remove the publication */
- pubsubAdmin_removePublication(admin, pubEP);
- /* Reset the endpoint field, so that will be recreated from scratch when a new serializer will be found */
- if(pubEP->endpoint!=NULL){
- free(pubEP->endpoint);
- pubEP->endpoint = NULL;
- }
- /* Add the orphan endpoint to the noSerializer pending list */
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
- arrayList_add(admin->noSerializerPublications,pubEP);
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
- }
- arrayList_destroy(pubList);
-
- /* Cleanup also the localPublications hashmap*/
- celixThreadMutex_lock(&admin->localPublicationsLock);
- hash_map_iterator_pt iter = hashMapIterator_create(admin->localPublications);
- char *key = NULL;
- service_factory_pt factory = NULL;
- while(hashMapIterator_hasNext(iter)){
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- factory = (service_factory_pt)hashMapEntry_getValue(entry);
- topic_publication_pt pub = (topic_publication_pt)factory->handle;
- if(pub==topicPub){
- key = (char*)hashMapEntry_getKey(entry);
- break;
- }
- }
- hashMapIterator_destroy(iter);
- if(key!=NULL){
- hashMap_remove(admin->localPublications, key);
- free(factory);
- free(key);
- }
- celixThreadMutex_unlock(&admin->localPublicationsLock);
-
- /* Finally destroy the topicPublication */
- pubsub_topicPublicationDestroy(topicPub);
- }
- arrayList_destroy(topicPubList);
- }
-
- /* Now destroy the topicSubscriptions, but first put back the pubsub_endpoints back to the noSerializer pending list */
- if(topicSubList!=NULL){
- for(i=0;i<arrayList_size(topicSubList);i++){
- topic_subscription_pt topicSub = (topic_subscription_pt)arrayList_get(topicSubList,i);
- /* Stop the topic subscription */
- pubsub_topicSubscriptionStop(topicSub);
- /* Get the endpoints that are going to be orphan */
- array_list_pt subList = pubsub_topicSubscriptionGetSubscribersList(topicSub);
- for(j=0;j<arrayList_size(subList);j++){
- pubsub_endpoint_pt subEP = (pubsub_endpoint_pt)arrayList_get(subList,j);
- /* Remove the subscription */
- pubsubAdmin_removeSubscription(admin, subEP);
- /* Reset the endpoint field, so that will be recreated from scratch when a new serializer will be found */
- if(subEP->endpoint!=NULL){
- free(subEP->endpoint);
- subEP->endpoint = NULL;
- }
- /* Add the orphan endpoint to the noSerializer pending list */
- celixThreadMutex_lock(&admin->noSerializerPendingsLock);
- arrayList_add(admin->noSerializerSubscriptions,subEP);
- celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
- }
-
- /* Cleanup also the subscriptions hashmap*/
- celixThreadMutex_lock(&admin->subscriptionsLock);
- hash_map_iterator_pt iter = hashMapIterator_create(admin->subscriptions);
- char *key = NULL;
- while(hashMapIterator_hasNext(iter)){
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- topic_subscription_pt sub = (topic_subscription_pt)hashMapEntry_getValue(entry);
- if(sub==topicSub){
- key = (char*)hashMapEntry_getKey(entry);
- break;
- }
- }
- hashMapIterator_destroy(iter);
- if(key!=NULL){
- hashMap_remove(admin->subscriptions, key);
- free(key);
- }
- celixThreadMutex_unlock(&admin->subscriptionsLock);
-
- /* Finally destroy the topicSubscription */
- pubsub_topicSubscriptionDestroy(topicSub);
- }
- arrayList_destroy(topicSubList);
- }
-
- printf("PSA_UDP_MC: %s serializer removed\n",serType);
-
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t pubsubAdmin_matchEndpoint(pubsub_admin_pt admin, pubsub_endpoint_pt endpoint, double* score){
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&admin->serializerListLock);
- status = pubsub_admin_match(endpoint->topic_props,PUBSUB_ADMIN_TYPE,admin->serializerList,score);
- celixThreadMutex_unlock(&admin->serializerListLock);
-
- return status;
-}
-
-/* This one recall the same logic as in the match function */
-static celix_status_t pubsubAdmin_getBestSerializer(pubsub_admin_pt admin,pubsub_endpoint_pt ep, pubsub_serializer_service_t **serSvc){
-
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&admin->serializerListLock);
- status = pubsub_admin_get_best_serializer(ep->topic_props, admin->serializerList, serSvc);
- celixThreadMutex_unlock(&admin->serializerListLock);
-
- return status;
-
-}
-
-static void connectTopicPubSubToSerializer(pubsub_admin_pt admin,pubsub_serializer_service_t *serializer,void *topicPubSub,bool isPublication){
-
- celixThreadMutex_lock(&admin->usedSerializersLock);
-
- hash_map_pt map = isPublication?admin->topicPublicationsPerSerializer:admin->topicSubscriptionsPerSerializer;
- array_list_pt list = (array_list_pt)hashMap_get(map,serializer);
- if(list==NULL){
- arrayList_create(&list);
- hashMap_put(map,serializer,list);
- }
- arrayList_add(list,topicPubSub);
-
- celixThreadMutex_unlock(&admin->usedSerializersLock);
-
-}
-
-static void disconnectTopicPubSubFromSerializer(pubsub_admin_pt admin,void *topicPubSub,bool isPublication){
-
- celixThreadMutex_lock(&admin->usedSerializersLock);
-
- hash_map_pt map = isPublication?admin->topicPublicationsPerSerializer:admin->topicSubscriptionsPerSerializer;
- hash_map_iterator_pt iter = hashMapIterator_create(map);
- while(hashMapIterator_hasNext(iter)){
- array_list_pt list = (array_list_pt)hashMapIterator_nextValue(iter);
- if(arrayList_removeElement(list, topicPubSub)){ //Found it!
- break;
- }
- }
- hashMapIterator_destroy(iter);
-
- celixThreadMutex_unlock(&admin->usedSerializersLock);
-
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/private/src/topic_publication.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/private/src/topic_publication.c b/pubsub/pubsub_admin_udp_mc/private/src/topic_publication.c
deleted file mode 100644
index e43ec29..0000000
--- a/pubsub/pubsub_admin_udp_mc/private/src/topic_publication.c
+++ /dev/null
@@ -1,444 +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
- *
- * htPSA_UDP_MC_TP://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.
- */
-/*
- * topic_publication.c
- *
- * \date Sep 24, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include "array_list.h"
-#include "celixbool.h"
-#include "service_registration.h"
-#include "utils.h"
-#include "service_factory.h"
-#include "version.h"
-
-#include "topic_publication.h"
-#include "pubsub_common.h"
-#include "publisher.h"
-#include "large_udp.h"
-
-#include "pubsub_serializer.h"
-
-#define EP_ADDRESS_LEN 32
-
-#define FIRST_SEND_DELAY 2
-
-struct topic_publication {
- int sendSocket;
- char* endpoint;
- service_registration_pt svcFactoryReg;
- array_list_pt pub_ep_list; //List<pubsub_endpoint>
- hash_map_pt boundServices; //<bundle_pt,bound_service>
- celix_thread_mutex_t tp_lock;
- pubsub_serializer_service_t *serializer;
- struct sockaddr_in destAddr;
-};
-
-typedef struct publish_bundle_bound_service {
- topic_publication_pt parent;
- pubsub_publisher_t service;
- bundle_pt bundle;
- char *scope;
- char *topic;
- hash_map_pt msgTypes;
- unsigned short getCount;
- celix_thread_mutex_t mp_lock;
- largeUdp_pt largeUdpHandle;
-}* publish_bundle_bound_service_pt;
-
-
-typedef struct pubsub_msg{
- pubsub_msg_header_pt header;
- char* payload;
- unsigned int payloadSize;
-} pubsub_msg_t;
-
-
-static unsigned int rand_range(unsigned int min, unsigned int max);
-
-static celix_status_t pubsub_topicPublicationGetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service);
-static celix_status_t pubsub_topicPublicationUngetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service);
-
-static publish_bundle_bound_service_pt pubsub_createPublishBundleBoundService(topic_publication_pt tp,bundle_pt bundle);
-static void pubsub_destroyPublishBundleBoundService(publish_bundle_bound_service_pt boundSvc);
-
-static int pubsub_topicPublicationSend(void* handle,unsigned int msgTypeId, const void *msg);
-
-static int pubsub_localMsgTypeIdForUUID(void* handle, const char* msgType, unsigned int* msgTypeId);
-
-
-static void delay_first_send_for_late_joiners(void);
-
-
-celix_status_t pubsub_topicPublicationCreate(int sendSocket, pubsub_endpoint_pt pubEP, pubsub_serializer_service_t *best_serializer, char* bindIP, topic_publication_pt *out){
-
- char* ep = malloc(EP_ADDRESS_LEN);
- memset(ep,0,EP_ADDRESS_LEN);
- unsigned int port = pubEP->serviceID + rand_range(UDP_BASE_PORT+pubEP->serviceID+3, UDP_MAX_PORT);
- snprintf(ep,EP_ADDRESS_LEN,"udp://%s:%u",bindIP,port);
-
-
- topic_publication_pt pub = calloc(1,sizeof(*pub));
-
- arrayList_create(&(pub->pub_ep_list));
- pub->boundServices = hashMap_create(NULL,NULL,NULL,NULL);
- celixThreadMutex_create(&(pub->tp_lock),NULL);
-
- pub->endpoint = ep;
- pub->sendSocket = sendSocket;
- pub->destAddr.sin_family = AF_INET;
- pub->destAddr.sin_addr.s_addr = inet_addr(bindIP);
- pub->destAddr.sin_port = htons(port);
-
- pub->serializer = best_serializer;
-
- pubsub_topicPublicationAddPublisherEP(pub,pubEP);
-
- *out = pub;
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t pubsub_topicPublicationDestroy(topic_publication_pt pub){
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&(pub->tp_lock));
-
- free(pub->endpoint);
- arrayList_destroy(pub->pub_ep_list);
-
- hash_map_iterator_pt iter = hashMapIterator_create(pub->boundServices);
- while(hashMapIterator_hasNext(iter)){
- publish_bundle_bound_service_pt bound = hashMapIterator_nextValue(iter);
- pubsub_destroyPublishBundleBoundService(bound);
- }
- hashMapIterator_destroy(iter);
- hashMap_destroy(pub->boundServices,false,false);
-
- pub->svcFactoryReg = NULL;
- pub->serializer = NULL;
-
- if(close(pub->sendSocket) != 0){
- status = CELIX_FILE_IO_EXCEPTION;
- }
-
- celixThreadMutex_unlock(&(pub->tp_lock));
-
- celixThreadMutex_destroy(&(pub->tp_lock));
-
- free(pub);
-
- return status;
-}
-
-celix_status_t pubsub_topicPublicationStart(bundle_context_pt bundle_context,topic_publication_pt pub,service_factory_pt* svcFactory){
- celix_status_t status = CELIX_SUCCESS;
-
- /* Let's register the new service */
-
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pub->pub_ep_list,0);
-
- if(pubEP!=NULL){
- service_factory_pt factory = calloc(1, sizeof(*factory));
- factory->handle = pub;
- factory->getService = pubsub_topicPublicationGetService;
- factory->ungetService = pubsub_topicPublicationUngetService;
-
- properties_pt props = properties_create();
- properties_set(props,PUBSUB_PUBLISHER_SCOPE,pubEP->scope);
- properties_set(props,PUBSUB_PUBLISHER_TOPIC,pubEP->topic);
-
- status = bundleContext_registerServiceFactory(bundle_context,PUBSUB_PUBLISHER_SERVICE_NAME,factory,props,&(pub->svcFactoryReg));
-
- if(status != CELIX_SUCCESS){
- properties_destroy(props);
- printf("PSA_UDP_MC_PSA_UDP_MC_TP: Cannot register ServiceFactory for topic %s, topic %s (bundle %ld).\n",pubEP->scope, pubEP->topic,pubEP->serviceID);
- }
- else{
- *svcFactory = factory;
- }
- }
- else{
- printf("PSA_UDP_MC_PSA_UDP_MC_TP: Cannot find pubsub_endpoint after adding it...Should never happen!\n");
- status = CELIX_SERVICE_EXCEPTION;
- }
-
- return status;
-}
-
-celix_status_t pubsub_topicPublicationStop(topic_publication_pt pub){
- return serviceRegistration_unregister(pub->svcFactoryReg);
-}
-
-celix_status_t pubsub_topicPublicationAddPublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep){
-
- celixThreadMutex_lock(&(pub->tp_lock));
- ep->endpoint = strdup(pub->endpoint);
- arrayList_add(pub->pub_ep_list,ep);
- celixThreadMutex_unlock(&(pub->tp_lock));
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t pubsub_topicPublicationRemovePublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep){
-
- celixThreadMutex_lock(&(pub->tp_lock));
- arrayList_removeElement(pub->pub_ep_list,ep);
- celixThreadMutex_unlock(&(pub->tp_lock));
-
- return CELIX_SUCCESS;
-}
-
-array_list_pt pubsub_topicPublicationGetPublisherList(topic_publication_pt pub){
- array_list_pt list = NULL;
- celixThreadMutex_lock(&(pub->tp_lock));
- list = arrayList_clone(pub->pub_ep_list);
- celixThreadMutex_unlock(&(pub->tp_lock));
- return list;
-}
-
-
-static celix_status_t pubsub_topicPublicationGetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service) {
- celix_status_t status = CELIX_SUCCESS;
-
- topic_publication_pt publish = (topic_publication_pt)handle;
-
- celixThreadMutex_lock(&(publish->tp_lock));
-
- publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt)hashMap_get(publish->boundServices,bundle);
- if(bound==NULL){
- bound = pubsub_createPublishBundleBoundService(publish,bundle);
- if(bound!=NULL){
- hashMap_put(publish->boundServices,bundle,bound);
- }
- }
- else{
- bound->getCount++;
- }
-
- if (bound != NULL) {
- *service = &bound->service;
- }
-
- celixThreadMutex_unlock(&(publish->tp_lock));
-
- return status;
-}
-
-static celix_status_t pubsub_topicPublicationUngetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service) {
-
- topic_publication_pt publish = (topic_publication_pt)handle;
-
- celixThreadMutex_lock(&(publish->tp_lock));
-
- publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt)hashMap_get(publish->boundServices,bundle);
- if(bound!=NULL){
-
- bound->getCount--;
- if(bound->getCount==0){
- pubsub_destroyPublishBundleBoundService(bound);
- hashMap_remove(publish->boundServices,bundle);
- }
-
- }
- else{
- long bundleId = -1;
- bundle_getBundleId(bundle,&bundleId);
- printf("PSA_UDP_MC_TP: Unexpected ungetService call for bundle %ld.\n", bundleId);
- }
-
- /* service should be never used for unget, so let's set the pointer to NULL */
- *service = NULL;
-
- celixThreadMutex_unlock(&(publish->tp_lock));
-
- return CELIX_SUCCESS;
-}
-
-static bool send_pubsub_msg(publish_bundle_bound_service_pt bound, pubsub_msg_t* msg, bool last, pubsub_release_callback_t *releaseCallback){
- const int iovec_len = 3; // header + size + payload
- bool ret = true;
-
- struct iovec msg_iovec[iovec_len];
- msg_iovec[0].iov_base = msg->header;
- msg_iovec[0].iov_len = sizeof(*msg->header);
- msg_iovec[1].iov_base = &msg->payloadSize;
- msg_iovec[1].iov_len = sizeof(msg->payloadSize);
- msg_iovec[2].iov_base = msg->payload;
- msg_iovec[2].iov_len = msg->payloadSize;
-
- delay_first_send_for_late_joiners();
-
- if(largeUdp_sendmsg(bound->largeUdpHandle, bound->parent->sendSocket, msg_iovec, iovec_len, 0, &bound->parent->destAddr, sizeof(bound->parent->destAddr)) == -1) {
- perror("send_pubsub_msg:sendSocket");
- ret = false;
- }
-
- if(releaseCallback) {
- releaseCallback->release(msg->payload, bound);
- }
- return ret;
-
-}
-
-
-static int pubsub_topicPublicationSend(void* handle, unsigned int msgTypeId, const void *inMsg) {
- int status = 0;
- publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt) handle;
-
- celixThreadMutex_lock(&(bound->parent->tp_lock));
- celixThreadMutex_lock(&(bound->mp_lock));
-
- pubsub_msg_serializer_t* msgSer = (pubsub_msg_serializer_t*)hashMap_get(bound->msgTypes, (void*)(uintptr_t)msgTypeId);
-
- if (msgSer != NULL) {
- int major=0, minor=0;
-
- pubsub_msg_header_pt msg_hdr = calloc(1,sizeof(struct pubsub_msg_header));
- strncpy(msg_hdr->topic,bound->topic,MAX_TOPIC_LEN-1);
- msg_hdr->type = msgTypeId;
-
-
- if (msgSer->msgVersion != NULL){
- version_getMajor(msgSer->msgVersion, &major);
- version_getMinor(msgSer->msgVersion, &minor);
- msg_hdr->major = major;
- msg_hdr->minor = minor;
- }
-
- void* serializedOutput = NULL;
- size_t serializedOutputLen = 0;
- msgSer->serialize(msgSer,inMsg,&serializedOutput, &serializedOutputLen);
-
- pubsub_msg_t *msg = calloc(1,sizeof(pubsub_msg_t));
- msg->header = msg_hdr;
- msg->payload = (char*)serializedOutput;
- msg->payloadSize = serializedOutputLen;
-
-
- if(send_pubsub_msg(bound, msg,true, NULL) == false) {
- status = -1;
- }
- free(msg_hdr);
- free(msg);
- free(serializedOutput);
-
-
- } else {
- printf("PSA_UDP_MC_TP: No msg serializer available for msg type id %d\n", msgTypeId);
- status=-1;
- }
-
- celixThreadMutex_unlock(&(bound->mp_lock));
- celixThreadMutex_unlock(&(bound->parent->tp_lock));
-
- return status;
-}
-
-static int pubsub_localMsgTypeIdForUUID(void* handle, const char* msgType, unsigned int* msgTypeId){
- *msgTypeId = utils_stringHash(msgType);
- return 0;
-}
-
-
-static unsigned int rand_range(unsigned int min, unsigned int max){
-
- double scaled = (double)(((double)random())/((double)RAND_MAX));
- return (max-min+1)*scaled + min;
-
-}
-
-static publish_bundle_bound_service_pt pubsub_createPublishBundleBoundService(topic_publication_pt tp,bundle_pt bundle){
-
- publish_bundle_bound_service_pt bound = calloc(1, sizeof(*bound));
-
- if (bound != NULL) {
-
- bound->parent = tp;
- bound->bundle = bundle;
- bound->getCount = 1;
- celixThreadMutex_create(&bound->mp_lock,NULL);
-
- if(tp->serializer != NULL){
- tp->serializer->createSerializerMap(tp->serializer->handle,bundle,&bound->msgTypes);
- }
-
- pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(bound->parent->pub_ep_list,0);
- bound->scope=strdup(pubEP->scope);
- bound->topic=strdup(pubEP->topic);
- bound->largeUdpHandle = largeUdp_create(1);
-
- bound->service.handle = bound;
- bound->service.localMsgTypeIdForMsgType = pubsub_localMsgTypeIdForUUID;
- bound->service.send = pubsub_topicPublicationSend;
- bound->service.sendMultipart = NULL; //Multipart not supported for UDP
-
- }
-
- return bound;
-}
-
-static void pubsub_destroyPublishBundleBoundService(publish_bundle_bound_service_pt boundSvc){
-
- celixThreadMutex_lock(&boundSvc->mp_lock);
-
- if(boundSvc->parent->serializer != NULL && boundSvc->msgTypes != NULL){
- boundSvc->parent->serializer->destroySerializerMap(boundSvc->parent->serializer->handle, boundSvc->msgTypes);
- }
-
- if(boundSvc->scope!=NULL){
- free(boundSvc->scope);
- }
-
- if(boundSvc->topic!=NULL){
- free(boundSvc->topic);
- }
-
- largeUdp_destroy(boundSvc->largeUdpHandle);
-
- celixThreadMutex_unlock(&boundSvc->mp_lock);
- celixThreadMutex_destroy(&boundSvc->mp_lock);
-
- free(boundSvc);
-
-}
-
-static void delay_first_send_for_late_joiners(){
-
- static bool firstSend = true;
-
- if(firstSend){
- printf("PSA_UDP_MC_TP: Delaying first send for late joiners...\n");
- sleep(FIRST_SEND_DELAY);
- firstSend = false;
- }
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/private/src/topic_subscription.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/private/src/topic_subscription.c b/pubsub/pubsub_admin_udp_mc/private/src/topic_subscription.c
deleted file mode 100644
index d8e6f45..0000000
--- a/pubsub/pubsub_admin_udp_mc/private/src/topic_subscription.c
+++ /dev/null
@@ -1,635 +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.
- */
-/*
- * topic_subscription.c
- *
- * \date Oct 2, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/epoll.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include "utils.h"
-#include "celix_errno.h"
-#include "constants.h"
-#include "version.h"
-
-#include "topic_subscription.h"
-#include "topic_publication.h"
-#include "subscriber.h"
-#include "publisher.h"
-#include "large_udp.h"
-
-#include "pubsub_serializer.h"
-
-#define MAX_EPOLL_EVENTS 10
-#define RECV_THREAD_TIMEOUT 5
-#define UDP_BUFFER_SIZE 65535
-#define MAX_UDP_SESSIONS 16
-
-struct topic_subscription{
- char* ifIpAddress;
- service_tracker_pt tracker;
- array_list_pt sub_ep_list;
- celix_thread_t recv_thread;
- bool running;
- celix_thread_mutex_t ts_lock;
- bundle_context_pt context;
-
- pubsub_serializer_service_t *serializer;
-
- int topicEpollFd; // EPOLL filedescriptor where the sockets are registered.
- hash_map_pt servicesMap; // key = service, value = msg types map
- hash_map_pt socketMap; // key = URL, value = listen-socket
- celix_thread_mutex_t socketMap_lock;
-
- celix_thread_mutex_t pendingConnections_lock;
- array_list_pt pendingConnections;
-
- array_list_pt pendingDisconnections;
- celix_thread_mutex_t pendingDisconnections_lock;
-
- //array_list_pt rawServices;
- unsigned int nrSubscribers;
- largeUdp_pt largeUdpHandle;
-};
-
-typedef struct msg_map_entry{
- bool retain;
- void* msgInst;
-}* msg_map_entry_pt;
-
-static celix_status_t topicsub_subscriberTracked(void * handle, service_reference_pt reference, void * service);
-static celix_status_t topicsub_subscriberUntracked(void * handle, service_reference_pt reference, void * service);
-static void* udp_recv_thread_func(void* arg);
-static bool checkVersion(version_pt msgVersion,pubsub_msg_header_pt hdr);
-static void sigusr1_sighandler(int signo);
-static int pubsub_localMsgTypeIdForMsgType(void* handle, const char* msgType, unsigned int* msgTypeId);
-static void connectPendingPublishers(topic_subscription_pt sub);
-static void disconnectPendingPublishers(topic_subscription_pt sub);
-
-
-celix_status_t pubsub_topicSubscriptionCreate(bundle_context_pt bundle_context, char* ifIp,char* scope, char* topic ,pubsub_serializer_service_t *best_serializer, topic_subscription_pt* out){
- celix_status_t status = CELIX_SUCCESS;
-
- topic_subscription_pt ts = (topic_subscription_pt) calloc(1,sizeof(*ts));
- ts->context = bundle_context;
- ts->ifIpAddress = strdup(ifIp);
-#if defined(__APPLE__) && defined(__MACH__)
- //TODO: Use kqueue for OSX
-#else
- ts->topicEpollFd = epoll_create1(0);
-#endif
- if(ts->topicEpollFd == -1) {
- status += CELIX_SERVICE_EXCEPTION;
- }
-
- ts->running = false;
- ts->nrSubscribers = 0;
- ts->serializer = best_serializer;
-
- celixThreadMutex_create(&ts->ts_lock,NULL);
- arrayList_create(&ts->sub_ep_list);
- ts->servicesMap = hashMap_create(NULL, NULL, NULL, NULL);
- ts->socketMap = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
-
- arrayList_create(&ts->pendingConnections);
- arrayList_create(&ts->pendingDisconnections);
- celixThreadMutex_create(&ts->pendingConnections_lock, NULL);
- celixThreadMutex_create(&ts->pendingDisconnections_lock, NULL);
- celixThreadMutex_create(&ts->socketMap_lock, NULL);
-
- ts->largeUdpHandle = largeUdp_create(MAX_UDP_SESSIONS);
-
- char filter[128];
- memset(filter,0,128);
- if(strncmp(PUBSUB_SUBSCRIBER_SCOPE_DEFAULT, scope, strlen(PUBSUB_SUBSCRIBER_SCOPE_DEFAULT)) == 0) {
- // default scope, means that subscriber has not defined a scope property
- snprintf(filter, 128, "(&(%s=%s)(%s=%s))",
- (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_SUBSCRIBER_SERVICE_NAME,
- PUBSUB_SUBSCRIBER_TOPIC,topic);
-
- } else {
- snprintf(filter, 128, "(&(%s=%s)(%s=%s)(%s=%s))",
- (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_SUBSCRIBER_SERVICE_NAME,
- PUBSUB_SUBSCRIBER_TOPIC,topic,
- PUBSUB_SUBSCRIBER_SCOPE,scope);
- }
-
- service_tracker_customizer_pt customizer = NULL;
- status += serviceTrackerCustomizer_create(ts,NULL,topicsub_subscriberTracked,NULL,topicsub_subscriberUntracked,&customizer);
- status += serviceTracker_createWithFilter(bundle_context, filter, customizer, &ts->tracker);
-
- struct sigaction actions;
- memset(&actions, 0, sizeof(actions));
- sigemptyset(&actions.sa_mask);
- actions.sa_flags = 0;
- actions.sa_handler = sigusr1_sighandler;
-
- sigaction(SIGUSR1,&actions,NULL);
-
- if (status == CELIX_SUCCESS) {
- *out=ts;
- }
-
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionDestroy(topic_subscription_pt ts){
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&ts->ts_lock);
- ts->running = false;
- free(ts->ifIpAddress);
- serviceTracker_destroy(ts->tracker);
- arrayList_clear(ts->sub_ep_list);
- arrayList_destroy(ts->sub_ep_list);
- hashMap_destroy(ts->servicesMap,false,false);
-
- celixThreadMutex_lock(&ts->socketMap_lock);
- hashMap_destroy(ts->socketMap,true,true);
- celixThreadMutex_unlock(&ts->socketMap_lock);
- celixThreadMutex_destroy(&ts->socketMap_lock);
-
- celixThreadMutex_lock(&ts->pendingConnections_lock);
- arrayList_destroy(ts->pendingConnections);
- celixThreadMutex_unlock(&ts->pendingConnections_lock);
- celixThreadMutex_destroy(&ts->pendingConnections_lock);
-
- celixThreadMutex_lock(&ts->pendingDisconnections_lock);
- arrayList_destroy(ts->pendingDisconnections);
- celixThreadMutex_unlock(&ts->pendingDisconnections_lock);
- celixThreadMutex_destroy(&ts->pendingDisconnections_lock);
-
- largeUdp_destroy(ts->largeUdpHandle);
-#if defined(__APPLE__) && defined(__MACH__)
- //TODO: Use kqueue for OSX
-#else
- close(ts->topicEpollFd);
-#endif
-
- celixThreadMutex_unlock(&ts->ts_lock);
-
- celixThreadMutex_destroy(&ts->ts_lock);
-
- free(ts);
-
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionStart(topic_subscription_pt ts){
- celix_status_t status = CELIX_SUCCESS;
-
- status = serviceTracker_open(ts->tracker);
-
- ts->running = true;
-
- if(status==CELIX_SUCCESS){
- status=celixThread_create(&ts->recv_thread,NULL,udp_recv_thread_func,ts);
- }
-
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionStop(topic_subscription_pt ts){
- celix_status_t status = CELIX_SUCCESS;
- struct epoll_event ev;
- memset(&ev, 0, sizeof(ev));
-
- ts->running = false;
-
- pthread_kill(ts->recv_thread.thread,SIGUSR1);
-
- celixThread_join(ts->recv_thread,NULL);
-
- status = serviceTracker_close(ts->tracker);
-
- celixThreadMutex_lock(&ts->socketMap_lock);
- hash_map_iterator_pt it = hashMapIterator_create(ts->socketMap);
- while(hashMapIterator_hasNext(it)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(it);
- char *url = hashMapEntry_getKey(entry);
- int *s = hashMapEntry_getValue(entry);
- memset(&ev, 0, sizeof(ev));
- if(epoll_ctl(ts->topicEpollFd, EPOLL_CTL_DEL, *s, &ev) == -1) {
- printf("in if error()\n");
- perror("epoll_ctl() EPOLL_CTL_DEL");
- status += CELIX_SERVICE_EXCEPTION;
- }
- free(s);
- free(url);
- //hashMapIterator_remove(it);
- }
- hashMapIterator_destroy(it);
- hashMap_clear(ts->socketMap, false, false);
- celixThreadMutex_unlock(&ts->socketMap_lock);
-
-
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionConnectPublisher(topic_subscription_pt ts, char* pubURL) {
-
- printf("pubsub_topicSubscriptionConnectPublisher : pubURL = %s\n", pubURL);
-
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&ts->socketMap_lock);
-
- if(!hashMap_containsKey(ts->socketMap, pubURL)){
-
- int *recvSocket = calloc(sizeof(int), 1);
- *recvSocket = socket(AF_INET, SOCK_DGRAM, 0);
- if (*recvSocket < 0) {
- perror("pubsub_topicSubscriptionCreate:socket");
- status = CELIX_SERVICE_EXCEPTION;
- }
-
- if (status == CELIX_SUCCESS){
- int reuse = 1;
- if (setsockopt(*recvSocket, SOL_SOCKET, SO_REUSEADDR, (char*) &reuse, sizeof(reuse)) != 0) {
- perror("setsockopt() SO_REUSEADDR");
- status = CELIX_SERVICE_EXCEPTION;
- }
- }
-
- if(status == CELIX_SUCCESS){
- // TODO Check if there is a better way to parse the URL to IP/Portnr
- //replace ':' by spaces
- char *url = strdup(pubURL);
- char *pt = url;
- while((pt=strchr(pt, ':')) != NULL) {
- *pt = ' ';
- }
- char mcIp[100];
- unsigned short mcPort;
- sscanf(url, "udp //%s %hu", mcIp, &mcPort);
- free(url);
-
- printf("pubsub_topicSubscriptionConnectPublisher : IP = %s, Port = %hu\n", mcIp, mcPort);
-
- struct ip_mreq mc_addr;
- mc_addr.imr_multiaddr.s_addr = inet_addr(mcIp);
- mc_addr.imr_interface.s_addr = inet_addr(ts->ifIpAddress);
- printf("Adding MC %s at interface %s\n", mcIp, ts->ifIpAddress);
- if (setsockopt(*recvSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*) &mc_addr, sizeof(mc_addr)) != 0) {
- perror("setsockopt() IP_ADD_MEMBERSHIP");
- status = CELIX_SERVICE_EXCEPTION;
- }
-
- if (status == CELIX_SUCCESS){
- struct sockaddr_in mcListenAddr;
- mcListenAddr.sin_family = AF_INET;
- mcListenAddr.sin_addr.s_addr = INADDR_ANY;
- mcListenAddr.sin_port = htons(mcPort);
- if(bind(*recvSocket, (struct sockaddr*)&mcListenAddr, sizeof(mcListenAddr)) != 0) {
- perror("bind()");
- status = CELIX_SERVICE_EXCEPTION;
- }
- }
-
- if (status == CELIX_SUCCESS){
-#if defined(__APPLE__) && defined(__MACH__)
- //TODO: Use kqueue for OSX
-#else
- struct epoll_event ev;
- memset(&ev, 0, sizeof(ev));
- ev.events = EPOLLIN;
- ev.data.fd = *recvSocket;
- if(epoll_ctl(ts->topicEpollFd, EPOLL_CTL_ADD, *recvSocket, &ev) == -1) {
- perror("epoll_ctl() EPOLL_CTL_ADD");
- status = CELIX_SERVICE_EXCEPTION;
- }
-#endif
- }
-
- }
-
- if (status == CELIX_SUCCESS){
- hashMap_put(ts->socketMap, strdup(pubURL), (void*)recvSocket);
- }
- else{
- free(recvSocket);
- }
- }
-
- celixThreadMutex_unlock(&ts->socketMap_lock);
-
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionAddConnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL) {
- celix_status_t status = CELIX_SUCCESS;
- char *url = strdup(pubURL);
- celixThreadMutex_lock(&ts->pendingConnections_lock);
- arrayList_add(ts->pendingConnections, url);
- celixThreadMutex_unlock(&ts->pendingConnections_lock);
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL) {
- celix_status_t status = CELIX_SUCCESS;
- char *url = strdup(pubURL);
- celixThreadMutex_lock(&ts->pendingDisconnections_lock);
- arrayList_add(ts->pendingDisconnections, url);
- celixThreadMutex_unlock(&ts->pendingDisconnections_lock);
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionDisconnectPublisher(topic_subscription_pt ts, char* pubURL){
- printf("pubsub_topicSubscriptionDisconnectPublisher : pubURL = %s\n", pubURL);
- celix_status_t status = CELIX_SUCCESS;
- struct epoll_event ev;
- memset(&ev, 0, sizeof(ev));
-
- celixThreadMutex_lock(&ts->socketMap_lock);
-
- if (hashMap_containsKey(ts->socketMap, pubURL)){
-
-#if defined(__APPLE__) && defined(__MACH__)
- //TODO: Use kqueue for OSX
-#else
- int *s = hashMap_remove(ts->socketMap, pubURL);
- if(epoll_ctl(ts->topicEpollFd, EPOLL_CTL_DEL, *s, &ev) == -1) {
- printf("in if error()\n");
- perror("epoll_ctl() EPOLL_CTL_DEL");
- status = CELIX_SERVICE_EXCEPTION;
- }
- free(s);
-#endif
-
- }
-
- celixThreadMutex_unlock(&ts->socketMap_lock);
-
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionAddSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP){
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&ts->ts_lock);
- arrayList_add(ts->sub_ep_list,subEP);
- celixThreadMutex_unlock(&ts->ts_lock);
-
- return status;
-
-}
-
-celix_status_t pubsub_topicIncreaseNrSubscribers(topic_subscription_pt ts) {
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&ts->ts_lock);
- ts->nrSubscribers++;
- celixThreadMutex_unlock(&ts->ts_lock);
-
- return status;
-}
-
-celix_status_t pubsub_topicSubscriptionRemoveSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP){
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&ts->ts_lock);
- arrayList_removeElement(ts->sub_ep_list,subEP);
- celixThreadMutex_unlock(&ts->ts_lock);
-
- return status;
-}
-
-celix_status_t pubsub_topicDecreaseNrSubscribers(topic_subscription_pt ts) {
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&ts->ts_lock);
- ts->nrSubscribers--;
- celixThreadMutex_unlock(&ts->ts_lock);
-
- return status;
-}
-
-unsigned int pubsub_topicGetNrSubscribers(topic_subscription_pt ts) {
- return ts->nrSubscribers;
-}
-
-array_list_pt pubsub_topicSubscriptionGetSubscribersList(topic_subscription_pt sub){
- return sub->sub_ep_list;
-}
-
-
-static celix_status_t topicsub_subscriberTracked(void * handle, service_reference_pt reference, void * service){
- celix_status_t status = CELIX_SUCCESS;
- topic_subscription_pt ts = handle;
-
- celixThreadMutex_lock(&ts->ts_lock);
- if (!hashMap_containsKey(ts->servicesMap, service)) {
- bundle_pt bundle = NULL;
- hash_map_pt msgTypes = NULL;
-
- serviceReference_getBundle(reference, &bundle);
-
- if(ts->serializer != NULL && bundle!=NULL){
- ts->serializer->createSerializerMap(ts->serializer->handle,bundle,&msgTypes);
- if(msgTypes != NULL){
- hashMap_put(ts->servicesMap, service, msgTypes);
- printf("PSA_UDP_MC_TS: New subscriber registered.\n");
- }
- }
- else{
- printf("PSA_UDP_MC_TS: Cannot register new subscriber.\n");
- status = CELIX_SERVICE_EXCEPTION;
- }
- }
- celixThreadMutex_unlock(&ts->ts_lock);
-
- return status;
-
-}
-
-static celix_status_t topicsub_subscriberUntracked(void * handle, service_reference_pt reference, void * service){
- celix_status_t status = CELIX_SUCCESS;
- topic_subscription_pt ts = handle;
-
- celixThreadMutex_lock(&ts->ts_lock);
- if (hashMap_containsKey(ts->servicesMap, service)) {
- hash_map_pt msgTypes = hashMap_remove(ts->servicesMap, service);
- if(msgTypes!=NULL && ts->serializer!=NULL){
- ts->serializer->destroySerializerMap(ts->serializer->handle,msgTypes);
- printf("PSA_ZMQ_TS: Subscriber unregistered.\n");
- }
- else{
- printf("PSA_ZMQ_TS: Cannot unregister subscriber.\n");
- status = CELIX_SERVICE_EXCEPTION;
- }
- }
- celixThreadMutex_unlock(&ts->ts_lock);
-
- printf("PSA_UDP_MC_TS: Subscriber unregistered.\n");
- return status;
-}
-
-
-static void process_msg(topic_subscription_pt sub,pubsub_udp_msg_t *msg){
-
- celixThreadMutex_lock(&sub->ts_lock);
- hash_map_iterator_pt iter = hashMapIterator_create(sub->servicesMap);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- pubsub_subscriber_pt subsvc = hashMapEntry_getKey(entry);
- hash_map_pt msgTypes = hashMapEntry_getValue(entry);
-
- pubsub_msg_serializer_t *msgSer = hashMap_get(msgTypes,(void*)(uintptr_t )msg->header.type);
- if (msgSer == NULL) {
- printf("PSA_UDP_MC_TS: Serializer not available for message %d.\n",msg->header.type);
- }
- else{
- void *msgInst = NULL;
- bool validVersion = checkVersion(msgSer->msgVersion,&msg->header);
-
- if(validVersion){
-
- celix_status_t status = msgSer->deserialize(msgSer, (const void *) msg->payload, 0, &msgInst);
-
- if (status == CELIX_SUCCESS) {
- bool release = true;
- pubsub_multipart_callbacks_t mp_callbacks;
- mp_callbacks.handle = sub;
- mp_callbacks.localMsgTypeIdForMsgType = pubsub_localMsgTypeIdForMsgType;
- mp_callbacks.getMultipart = NULL;
-
- subsvc->receive(subsvc->handle, msgSer->msgName, msg->header.type, msgInst, &mp_callbacks, &release);
-
- if(release){
- msgSer->freeMsg(msgSer,msgInst);
- }
- }
- else{
- printf("PSA_UDP_MC_TS: Cannot deserialize msgType %s.\n",msgSer->msgName);
- }
-
- }
- else{
- int major=0,minor=0;
- version_getMajor(msgSer->msgVersion,&major);
- version_getMinor(msgSer->msgVersion,&minor);
- printf("PSA_UDP_MC_TS: Version mismatch for primary message '%s' (have %d.%d, received %u.%u). NOT sending any part of the whole message.\n",
- msgSer->msgName,major,minor,msg->header.major,msg->header.minor);
- }
-
- }
- }
- hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&sub->ts_lock);
-}
-
-static void* udp_recv_thread_func(void * arg) {
- topic_subscription_pt sub = (topic_subscription_pt) arg;
-
-#if defined(__APPLE__) && defined(__MACH__)
- //TODO: use kqueue for OSX
- //struct kevent events[MAX_EPOLL_EVENTS];
- while (sub->running) {
- int nfds = 0;
- if(nfds > 0) {
- pubsub_udp_msg_t* udpMsg = NULL;
- process_msg(sub, udpMsg);
- }
- }
-#else
- struct epoll_event events[MAX_EPOLL_EVENTS];
-
- while (sub->running) {
- int nfds = epoll_wait(sub->topicEpollFd, events, MAX_EPOLL_EVENTS, RECV_THREAD_TIMEOUT * 1000);
- int i;
- for(i = 0; i < nfds; i++ ) {
- unsigned int index;
- unsigned int size;
- if(largeUdp_dataAvailable(sub->largeUdpHandle, events[i].data.fd, &index, &size) == true) {
- // Handle data
- pubsub_udp_msg_t *udpMsg = NULL;
- if(largeUdp_read(sub->largeUdpHandle, index, (void**)&udpMsg, size) != 0) {
- printf("PSA_UDP_MC_TS: ERROR largeUdp_read with index %d\n", index);
- continue;
- }
-
- process_msg(sub, udpMsg);
-
- free(udpMsg);
- }
- }
- connectPendingPublishers(sub);
- disconnectPendingPublishers(sub);
- }
-#endif
-
- return NULL;
-}
-
-static void connectPendingPublishers(topic_subscription_pt sub) {
- celixThreadMutex_lock(&sub->pendingConnections_lock);
- while(!arrayList_isEmpty(sub->pendingConnections)) {
- char * pubEP = arrayList_remove(sub->pendingConnections, 0);
- pubsub_topicSubscriptionConnectPublisher(sub, pubEP);
- free(pubEP);
- }
- celixThreadMutex_unlock(&sub->pendingConnections_lock);
-}
-
-static void disconnectPendingPublishers(topic_subscription_pt sub) {
- celixThreadMutex_lock(&sub->pendingDisconnections_lock);
- while(!arrayList_isEmpty(sub->pendingDisconnections)) {
- char * pubEP = arrayList_remove(sub->pendingDisconnections, 0);
- pubsub_topicSubscriptionDisconnectPublisher(sub, pubEP);
- free(pubEP);
- }
- celixThreadMutex_unlock(&sub->pendingDisconnections_lock);
-}
-
-static void sigusr1_sighandler(int signo){
- printf("PSA_UDP_MC_TS: Topic subscription being shut down...\n");
- return;
-}
-
-static bool checkVersion(version_pt msgVersion,pubsub_msg_header_pt hdr){
- bool check=false;
- int major=0,minor=0;
-
- if(msgVersion!=NULL){
- version_getMajor(msgVersion,&major);
- version_getMinor(msgVersion,&minor);
- if(hdr->major==((unsigned char)major)){ /* Different major means incompatible */
- check = (hdr->minor>=((unsigned char)minor)); /* Compatible only if the provider has a minor equals or greater (means compatible update) */
- }
- }
-
- return check;
-}
-
-static int pubsub_localMsgTypeIdForMsgType(void* handle, const char* msgType, unsigned int* msgTypeId){
- *msgTypeId = utils_stringHash(msgType);
- return 0;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/src/large_udp.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/src/large_udp.c b/pubsub/pubsub_admin_udp_mc/src/large_udp.c
new file mode 100644
index 0000000..7455925
--- /dev/null
+++ b/pubsub/pubsub_admin_udp_mc/src/large_udp.c
@@ -0,0 +1,372 @@
+/**
+ *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.
+ */
+/*
+ * large_udp.c
+ *
+ * \date Mar 1, 2016
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include "large_udp.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <array_list.h>
+#include <pthread.h>
+
+#define MAX_UDP_MSG_SIZE 65535 /* 2^16 -1 */
+#define IP_HEADER_SIZE 20
+#define UDP_HEADER_SIZE 8
+//#define MTU_SIZE 1500
+#define MTU_SIZE 8000
+#define MAX_MSG_VECTOR_LEN 64
+
+//#define NO_IP_FRAGMENTATION
+
+struct largeUdp {
+ unsigned int maxNrLists;
+ array_list_pt udpPartLists;
+ pthread_mutex_t dbLock;
+};
+
+typedef struct udpPartList {
+ unsigned int msg_ident;
+ unsigned int msg_size;
+ unsigned int nrPartsRemaining;
+ char *data;
+} *udpPartList_pt;
+
+
+typedef struct msg_part_header {
+ unsigned int msg_ident;
+ unsigned int total_msg_size;
+ unsigned int part_msg_size;
+ unsigned int offset;
+} msg_part_header_t;
+
+#ifdef NO_IP_FRAGMENTATION
+#define MAX_PART_SIZE (MTU_SIZE - (IP_HEADER_SIZE + UDP_HEADER_SIZE + sizeof(struct msg_part_header) ))
+#else
+#define MAX_PART_SIZE (MAX_UDP_MSG_SIZE - (IP_HEADER_SIZE + UDP_HEADER_SIZE + sizeof(struct msg_part_header) ))
+#endif
+
+typedef struct msg_part {
+ msg_part_header_t header;
+ char data[MAX_PART_SIZE];
+} msg_part_t;
+
+//
+// Create a handle
+//
+largeUdp_pt largeUdp_create(unsigned int maxNrUdpReceptions)
+{
+ printf("## Creating large UDP\n");
+ largeUdp_pt handle = calloc(sizeof(*handle), 1);
+ if(handle != NULL) {
+ handle->maxNrLists = maxNrUdpReceptions;
+ if(arrayList_create(&handle->udpPartLists) != CELIX_SUCCESS) {
+ free(handle);
+ handle = NULL;
+ }
+ pthread_mutex_init(&handle->dbLock, 0);
+ }
+
+ return handle;
+}
+
+//
+// Destroys the handle
+//
+void largeUdp_destroy(largeUdp_pt handle)
+{
+ printf("### Destroying large UDP\n");
+ if(handle != NULL) {
+ pthread_mutex_lock(&handle->dbLock);
+ int nrUdpLists = arrayList_size(handle->udpPartLists);
+ int i;
+ for(i=0; i < nrUdpLists; i++) {
+ udpPartList_pt udpPartList = arrayList_remove(handle->udpPartLists, i);
+ if(udpPartList) {
+ if(udpPartList->data) {
+ free(udpPartList->data);
+ udpPartList->data = NULL;
+ }
+ free(udpPartList);
+ }
+ }
+ arrayList_destroy(handle->udpPartLists);
+ handle->udpPartLists = NULL;
+ pthread_mutex_unlock(&handle->dbLock);
+ pthread_mutex_destroy(&handle->dbLock);
+ free(handle);
+ }
+}
+
+//
+// Write large data to UDP. This function splits the data in chunks and sends these chunks with a header over UDP.
+//
+int largeUdp_sendmsg(largeUdp_pt handle, int fd, struct iovec *largeMsg_iovec, int len, int flags, struct sockaddr_in *dest_addr, size_t addrlen)
+{
+ int n;
+ int result = 0;
+ msg_part_header_t header;
+
+ int written = 0;
+ header.msg_ident = (unsigned int)random();
+ header.total_msg_size = 0;
+ for(n = 0; n < len ;n++) {
+ header.total_msg_size += largeMsg_iovec[n].iov_len;
+ }
+ int nr_buffers = (header.total_msg_size / MAX_PART_SIZE) + 1;
+
+ struct iovec msg_iovec[MAX_MSG_VECTOR_LEN];
+ struct msghdr msg;
+ msg.msg_name = dest_addr;
+ msg.msg_namelen = addrlen;
+ msg.msg_flags = 0;
+ msg.msg_iov = msg_iovec;
+ msg.msg_iovlen = 2; // header and payload;
+ msg.msg_control = NULL;
+ msg.msg_controllen = 0;
+
+ msg.msg_iov[0].iov_base = &header;
+ msg.msg_iov[0].iov_len = sizeof(header);
+
+ for(n = 0; n < nr_buffers; n++) {
+
+ header.part_msg_size = (((header.total_msg_size - n * MAX_PART_SIZE) > MAX_PART_SIZE) ? MAX_PART_SIZE : (header.total_msg_size - n * MAX_PART_SIZE));
+ header.offset = n * MAX_PART_SIZE;
+ int remainingOffset = header.offset;
+ int recvPart = 0;
+ // find the start of the part
+ while(remainingOffset > largeMsg_iovec[recvPart].iov_len) {
+ remainingOffset -= largeMsg_iovec[recvPart].iov_len;
+ recvPart++;
+ }
+ int remainingData = header.part_msg_size;
+ int sendPart = 1;
+ msg.msg_iovlen = 1;
+
+ // fill in the output iovec from the input iovec in such a way that all UDP frames are filled maximal.
+ while(remainingData > 0) {
+ int partLen = ( (largeMsg_iovec[recvPart].iov_len - remainingOffset) <= remainingData ? (largeMsg_iovec[recvPart].iov_len -remainingOffset) : remainingData);
+ msg.msg_iov[sendPart].iov_base = largeMsg_iovec[recvPart].iov_base + remainingOffset;
+ msg.msg_iov[sendPart].iov_len = partLen;
+ remainingData -= partLen;
+ remainingOffset = 0;
+ sendPart++;
+ recvPart++;
+ msg.msg_iovlen++;
+ }
+ int tmp, tmptot;
+ for(tmp = 0, tmptot=0; tmp < msg.msg_iovlen; tmp++) {
+ tmptot += msg.msg_iov[tmp].iov_len;
+ }
+
+ int w = sendmsg(fd, &msg, 0);
+ if(w == -1) {
+ perror("send()");
+ result = -1;
+ break;
+ }
+ written += w;
+ }
+
+ return (result == 0 ? written : result);
+}
+
+//
+// Write large data to UDP. This function splits the data in chunks and sends these chunks with a header over UDP.
+//
+int largeUdp_sendto(largeUdp_pt handle, int fd, void *buf, size_t count, int flags, struct sockaddr_in *dest_addr, size_t addrlen)
+{
+ int n;
+ int nr_buffers = (count / MAX_PART_SIZE) + 1;
+ int result = 0;
+ msg_part_header_t header;
+
+ int written = 0;
+ header.msg_ident = (unsigned int)random();
+ header.total_msg_size = count;
+ char *databuf = buf;
+
+ struct iovec msg_iovec[2];
+ struct msghdr msg;
+ msg.msg_name = dest_addr;
+ msg.msg_namelen = addrlen;
+ msg.msg_flags = 0;
+ msg.msg_iov = msg_iovec;
+ msg.msg_iovlen = 2; // header and payload;
+ msg.msg_control = NULL;
+ msg.msg_controllen = 0;
+
+ msg.msg_iov[0].iov_base = &header;
+ msg.msg_iov[0].iov_len = sizeof(header);
+
+ for(n = 0; n < nr_buffers; n++) {
+
+ header.part_msg_size = (((header.total_msg_size - n * MAX_PART_SIZE) > MAX_PART_SIZE) ? MAX_PART_SIZE : (header.total_msg_size - n * MAX_PART_SIZE));
+ header.offset = n * MAX_PART_SIZE;
+ msg.msg_iov[1].iov_base = &databuf[header.offset];
+ msg.msg_iov[1].iov_len = header.part_msg_size;
+ int w = sendmsg(fd, &msg, 0);
+ if(w == -1) {
+ perror("send()");
+ result = -1;
+ break;
+ }
+ written += w;
+ //usleep(1000); // TODO: If not slept a UDP buffer overflow occurs and parts are missing at the reception side (at least via localhost)
+ }
+
+ return (result == 0 ? written : result);
+}
+
+//
+// Reads data from the filedescriptor which has date (determined by epoll()) and stores it in the internal structure
+// If the message is completely reassembled true is returned and the index and size have valid values
+//
+bool largeUdp_dataAvailable(largeUdp_pt handle, int fd, unsigned int *index, unsigned int *size) {
+ msg_part_header_t header;
+ int result = false;
+ // Only read the header, we don't know yet where to store the payload
+ if(recv(fd, &header, sizeof(header), MSG_PEEK) < 0) {
+ perror("read()");
+ return false;
+ }
+
+ struct iovec msg_vec[2];
+ struct msghdr msg;
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
+ msg.msg_flags = 0;
+ msg.msg_iov = msg_vec;
+ msg.msg_iovlen = 2; // header and payload;
+ msg.msg_control = NULL;
+ msg.msg_controllen = 0;
+
+ msg.msg_iov[0].iov_base = &header;
+ msg.msg_iov[0].iov_len = sizeof(header);
+
+ pthread_mutex_lock(&handle->dbLock);
+
+ int nrUdpLists = arrayList_size(handle->udpPartLists);
+ int i;
+ bool found = false;
+ for(i = 0; i < nrUdpLists; i++) {
+ udpPartList_pt udpPartList = arrayList_get(handle->udpPartLists, i);
+ if(udpPartList->msg_ident == header.msg_ident) {
+ found = true;
+
+ //sanity check
+ if(udpPartList->msg_size != header.total_msg_size) {
+ // Corruption occurred. Remove the existing administration and build up a new one.
+ arrayList_remove(handle->udpPartLists, i);
+ free(udpPartList->data);
+ free(udpPartList);
+ found = false;
+ break;
+ }
+
+ msg.msg_iov[1].iov_base = &udpPartList->data[header.offset];
+ msg.msg_iov[1].iov_len = header.part_msg_size;
+ if(recvmsg(fd, &msg, 0)<0){
+ found=true;
+ result=false;
+ break;
+ }
+
+ udpPartList->nrPartsRemaining--;
+ if(udpPartList->nrPartsRemaining == 0) {
+ *index = i;
+ *size = udpPartList->msg_size;
+ result = true;
+ break;
+ } else {
+ result = false; // not complete
+ break;
+ }
+ }
+ }
+
+ if(found == false) {
+ udpPartList_pt udpPartList = NULL;
+ if(nrUdpLists == handle->maxNrLists) {
+ // remove list at index 0
+ udpPartList = arrayList_remove(handle->udpPartLists, 0);
+ fprintf(stderr, "ERROR: Removing entry for id %d: %d parts not received\n",udpPartList->msg_ident, udpPartList->nrPartsRemaining );
+ free(udpPartList->data);
+ free(udpPartList);
+ nrUdpLists--;
+ }
+ udpPartList = calloc(sizeof(*udpPartList), 1);
+ udpPartList->msg_ident = header.msg_ident;
+ udpPartList->msg_size = header.total_msg_size;
+ udpPartList->nrPartsRemaining = header.total_msg_size / MAX_PART_SIZE;
+ udpPartList->data = calloc(sizeof(char), header.total_msg_size);
+
+ msg.msg_iov[1].iov_base = &udpPartList->data[header.offset];
+ msg.msg_iov[1].iov_len = header.part_msg_size;
+ if(recvmsg(fd, &msg, 0)<0){
+ free(udpPartList->data);
+ free(udpPartList);
+ result=false;
+ }
+ else{
+ arrayList_add(handle->udpPartLists, udpPartList);
+
+ if(udpPartList->nrPartsRemaining == 0) {
+ *index = nrUdpLists;
+ *size = udpPartList->msg_size;
+ result = true;
+ } else {
+ result = false;
+ }
+ }
+
+ }
+
+ pthread_mutex_unlock(&handle->dbLock);
+
+ return result;
+}
+
+//
+// Read out the message which is indicated available by the largeUdp_dataAvailable function
+//
+int largeUdp_read(largeUdp_pt handle, unsigned int index, void ** buffer, unsigned int size)
+{
+ int result = 0;
+ pthread_mutex_lock(&handle->dbLock);
+
+ udpPartList_pt udpPartList = arrayList_remove(handle->udpPartLists, index);
+ if(udpPartList) {
+ *buffer = udpPartList->data;
+ free(udpPartList);
+ } else {
+ result = -1;
+ }
+ pthread_mutex_unlock(&handle->dbLock);
+
+ return result;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/src/large_udp.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/src/large_udp.h b/pubsub/pubsub_admin_udp_mc/src/large_udp.h
new file mode 100644
index 0000000..a21e654
--- /dev/null
+++ b/pubsub/pubsub_admin_udp_mc/src/large_udp.h
@@ -0,0 +1,45 @@
+/**
+ *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.
+ */
+/*
+ * large_udp.h
+ *
+ * \date Mar 1, 2016
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef _LARGE_UDP_H_
+#define _LARGE_UDP_H_
+#include <stdbool.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+typedef struct largeUdp *largeUdp_pt;
+
+largeUdp_pt largeUdp_create(unsigned int maxNrUdpReceptions);
+void largeUdp_destroy(largeUdp_pt handle);
+
+int largeUdp_sendto(largeUdp_pt handle, int fd, void *buf, size_t count, int flags, struct sockaddr_in *dest_addr, size_t addrlen);
+int largeUdp_sendmsg(largeUdp_pt handle, int fd, struct iovec *largeMsg_iovec, int len, int flags, struct sockaddr_in *dest_addr, size_t addrlen);
+bool largeUdp_dataAvailable(largeUdp_pt handle, int fd, unsigned int *index, unsigned int *size);
+int largeUdp_read(largeUdp_pt handle, unsigned int index, void ** buffer, unsigned int size);
+
+#endif /* _LARGE_UDP_H_ */
[32/54] [abbrv] celix git commit: Merge commit
'ee29b00d7a80af43d351e61916d5a5aa90f97e46' into
feature/CELIX-417-cmake-refactor
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/dependency_manager/src/dm_component_impl.c
----------------------------------------------------------------------
diff --cc dependency_manager/src/dm_component_impl.c
index 13a2ee0,0000000..e0d9f52
mode 100644,000000..100644
--- a/dependency_manager/src/dm_component_impl.c
+++ b/dependency_manager/src/dm_component_impl.c
@@@ -1,1442 -1,0 +1,1451 @@@
+/**
+ *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.
+ */
+/*
+ * dm_component_impl.c
+ *
+ * \date 9 Oct 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "constants.h"
+#include "filter.h"
+#include "dm_component_impl.h"
+
+
+typedef struct dm_executor_struct * dm_executor_pt;
+
+struct dm_component_struct {
+ char id[DM_COMPONENT_MAX_ID_LENGTH];
+ char name[DM_COMPONENT_MAX_NAME_LENGTH];
+ bundle_context_pt context;
- array_list_pt dm_interfaces;
++ array_list_pt dm_interfaces; //protected by mutex
+
+ void* implementation;
+
+ init_fpt callbackInit;
+ start_fpt callbackStart;
+ stop_fpt callbackStop;
+ deinit_fpt callbackDeinit;
+
+ array_list_pt dependencies; //protected by mutex
+ pthread_mutex_t mutex;
+
+ dm_component_state_t state;
+ bool isStarted;
+ bool active;
+
+ bool setCLanguageProperty;
+
+ hash_map_pt dependencyEvents; //protected by mutex
+
+ dm_executor_pt executor;
+};
+
+typedef struct dm_interface_struct {
+ char* serviceName;
+ const void* service;
+ properties_pt properties;
+ service_registration_pt registration;
+} dm_interface_t;
+
+struct dm_executor_struct {
+ pthread_t runningThread;
+ bool runningThreadSet;
+ linked_list_pt workQueue;
+ pthread_mutex_t mutex;
+};
+
+typedef struct dm_executor_task_struct {
+ dm_component_pt component;
+ void (*command)(void *command_ptr, void *data);
+ void *data;
+} dm_executor_task_t;
+
+typedef struct dm_handle_event_type_struct {
+ dm_service_dependency_pt dependency;
+ dm_event_pt event;
+ dm_event_pt newEvent;
+} *dm_handle_event_type_pt;
+
+static celix_status_t executor_runTasks(dm_executor_pt executor, pthread_t currentThread __attribute__((unused)));
+static celix_status_t executor_execute(dm_executor_pt executor);
+static celix_status_t executor_executeTask(dm_executor_pt executor, dm_component_pt component, void (*command), void *data);
+static celix_status_t executor_schedule(dm_executor_pt executor, dm_component_pt component, void (*command), void *data);
+static celix_status_t executor_create(dm_component_pt component __attribute__((unused)), dm_executor_pt *executor);
+static void executor_destroy(dm_executor_pt executor);
+
+static celix_status_t component_invokeRemoveRequiredDependencies(dm_component_pt component);
+static celix_status_t component_invokeRemoveInstanceBoundDependencies(dm_component_pt component);
+static celix_status_t component_invokeRemoveOptionalDependencies(dm_component_pt component);
+static celix_status_t component_registerServices(dm_component_pt component);
+static celix_status_t component_unregisterServices(dm_component_pt component);
+static celix_status_t component_invokeAddOptionalDependencies(dm_component_pt component);
+static celix_status_t component_invokeAddRequiredInstanceBoundDependencies(dm_component_pt component);
+static celix_status_t component_invokeAddRequiredDependencies(dm_component_pt component);
+static celix_status_t component_invokeAutoConfigInstanceBoundDependencies(dm_component_pt component);
+static celix_status_t component_invokeAutoConfigDependencies(dm_component_pt component);
+static celix_status_t component_configureImplementation(dm_component_pt component, dm_service_dependency_pt dependency);
+static celix_status_t component_allInstanceBoundAvailable(dm_component_pt component, bool *available);
+static celix_status_t component_allRequiredAvailable(dm_component_pt component, bool *available);
+static celix_status_t component_performTransition(dm_component_pt component, dm_component_state_t oldState, dm_component_state_t newState, bool *transition);
+static celix_status_t component_calculateNewState(dm_component_pt component, dm_component_state_t currentState, dm_component_state_t *newState);
+static celix_status_t component_handleChange(dm_component_pt component);
+static celix_status_t component_startDependencies(dm_component_pt component __attribute__((unused)), array_list_pt dependencies);
+static celix_status_t component_getDependencyEvent(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt *event_pptr);
+static celix_status_t component_updateInstance(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event, bool update, bool add);
+
+static celix_status_t component_addTask(dm_component_pt component, dm_service_dependency_pt dep);
+static celix_status_t component_startTask(dm_component_pt component, void * data __attribute__((unused)));
+static celix_status_t component_stopTask(dm_component_pt component, void * data __attribute__((unused)));
+static celix_status_t component_removeTask(dm_component_pt component, dm_service_dependency_pt dependency);
+static celix_status_t component_handleEventTask(dm_component_pt component, dm_handle_event_type_pt data);
+
+static celix_status_t component_handleAdded(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event);
+static celix_status_t component_handleChanged(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event);
+static celix_status_t component_handleRemoved(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event);
+static celix_status_t component_handleSwapped(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event, dm_event_pt newEvent);
+
+static celix_status_t component_suspend(dm_component_pt component, dm_service_dependency_pt dependency);
+static celix_status_t component_resume(dm_component_pt component, dm_service_dependency_pt dependency);
+
+celix_status_t component_create(bundle_context_pt context, const char *name, dm_component_pt *out) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ dm_component_pt component = calloc(1, sizeof(*component));
+
+ if (!component) {
+ status = CELIX_ENOMEM;
+ } else {
+ snprintf(component->id, DM_COMPONENT_MAX_ID_LENGTH, "%p", component);
+ snprintf(component->name, DM_COMPONENT_MAX_NAME_LENGTH, "%s", name == NULL ? "n/a" : name);
+
+ component->context = context;
+
+ arrayList_create(&component->dm_interfaces);
+ arrayList_create(&(component)->dependencies);
+ pthread_mutex_init(&(component)->mutex, NULL);
+
+ component->implementation = NULL;
+
+ component->callbackInit = NULL;
+ component->callbackStart = NULL;
+ component->callbackStop = NULL;
+ component->callbackDeinit = NULL;
+
+ component->state = DM_CMP_STATE_INACTIVE;
+ component->isStarted = false;
+ component->active = false;
+
+ component->setCLanguageProperty = false;
+
+ component->dependencyEvents = hashMap_create(NULL, NULL, NULL, NULL);
+
+ component->executor = NULL;
+ executor_create(component, &component->executor);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *out = component;
+ }
+
+ return status;
+}
+
+void component_destroy(dm_component_pt component) {
+ if (component) {
+ unsigned int i;
+
+ for (i = 0; i < arrayList_size(component->dm_interfaces); i++) {
+ dm_interface_t *interface = arrayList_get(component->dm_interfaces, i);
+
+ if(interface->properties!=NULL){
+ properties_destroy(interface->properties);
+ }
+ free (interface->serviceName);
+ free (interface);
+ }
+ arrayList_destroy(component->dm_interfaces);
+
+ executor_destroy(component->executor);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(component->dependencyEvents);
+ while(hashMapIterator_hasNext(iter)){
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ dm_service_dependency_pt sdep = (dm_service_dependency_pt)hashMapEntry_getKey(entry);
+ array_list_pt eventList = (array_list_pt)hashMapEntry_getValue(entry);
+ serviceDependency_destroy(&sdep);
+ arrayList_destroy(eventList);
+ }
+ hashMapIterator_destroy(iter);
+
+ hashMap_destroy(component->dependencyEvents, false, false);
+
+ arrayList_destroy(component->dependencies);
+ pthread_mutex_destroy(&component->mutex);
+
+ free(component);
+ }
+}
+
+celix_status_t component_addServiceDependency(dm_component_pt component, dm_service_dependency_pt dep) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ executor_executeTask(component->executor, component, component_addTask, dep);
+
+ return status;
+}
+
+
+static celix_status_t component_addTask(dm_component_pt component, dm_service_dependency_pt dep) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ array_list_pt bounds = NULL;
+ arrayList_create(&bounds);
+
+ array_list_pt events = NULL;
+ arrayList_createWithEquals(event_equals, &events);
+
+ pthread_mutex_lock(&component->mutex);
+ hashMap_put(component->dependencyEvents, dep, events);
+ arrayList_add(component->dependencies, dep);
+ pthread_mutex_unlock(&component->mutex);
+
+ serviceDependency_setComponent(dep, component);
+
+ if (component->state != DM_CMP_STATE_INACTIVE) {
+ serviceDependency_setInstanceBound(dep, true);
+ arrayList_add(bounds, dep);
+ }
+ component_startDependencies(component, bounds);
+ component_handleChange(component);
+
+ arrayList_destroy(bounds);
+
+ return status;
+}
+
+dm_component_state_t component_currentState(dm_component_pt cmp) {
+ return cmp->state;
+}
+
+void * component_getImplementation(dm_component_pt cmp) {
+ return cmp->implementation;
+}
+
+const char * component_getName(dm_component_pt cmp) {
+ return cmp->name;
+}
+
+celix_status_t component_removeServiceDependency(dm_component_pt component, dm_service_dependency_pt dependency) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ executor_executeTask(component->executor, component, component_removeTask, dependency);
+
+ return status;
+}
+
+celix_status_t component_removeTask(dm_component_pt component, dm_service_dependency_pt dependency) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ arrayList_removeElement(component->dependencies, dependency);
+ pthread_mutex_unlock(&component->mutex);
+
+ if (component->state != DM_CMP_STATE_INACTIVE) {
+ serviceDependency_stop(dependency);
+ }
+
+ pthread_mutex_lock(&component->mutex);
+ array_list_pt events = hashMap_remove(component->dependencyEvents, dependency);
+ pthread_mutex_unlock(&component->mutex);
+
+ serviceDependency_destroy(&dependency);
+
+ while (!arrayList_isEmpty(events)) {
+ dm_event_pt event = arrayList_remove(events, 0);
+ event_destroy(&event);
+ }
+ arrayList_destroy(events);
+
+ component_handleChange(component);
+
+ return status;
+}
+
+celix_status_t component_start(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ component->active = true;
+ executor_executeTask(component->executor, component, component_startTask, NULL);
+
+ return status;
+}
+
+celix_status_t component_startTask(dm_component_pt component, void *data __attribute__((unused))) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ component->isStarted = true;
+ component_handleChange(component);
+
+ return status;
+}
+
+celix_status_t component_stop(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ component->active = false;
+ executor_executeTask(component->executor, component, component_stopTask, NULL);
+
+ return status;
+}
+
+celix_status_t component_stopTask(dm_component_pt component, void *data __attribute__((unused))) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ component->isStarted = false;
+ component_handleChange(component);
+ component->active = false;
+
+ return status;
+}
+
+celix_status_t component_setCLanguageProperty(dm_component_pt component, bool setCLangProp) {
+ component->setCLanguageProperty = setCLangProp;
+ return CELIX_SUCCESS;
+}
+
+celix_status_t component_addInterface(dm_component_pt component, const char* serviceName, const char* serviceVersion, const void* service, properties_pt properties) {
+ celix_status_t status = CELIX_SUCCESS;
+
- if (component->active) {
- return CELIX_ILLEGAL_STATE;
- } else {
- dm_interface_t *interface = (dm_interface_t *) calloc(1, sizeof(*interface));
- char *name = strdup(serviceName);
++ dm_interface_t *interface = (dm_interface_t *) calloc(1, sizeof(*interface));
++ char *name = strdup(serviceName);
+
- if (properties == NULL) {
- properties = properties_create();
- }
++ if (properties == NULL) {
++ properties = properties_create();
++ }
+
- if ((properties_get(properties, CELIX_FRAMEWORK_SERVICE_VERSION) == NULL) && (serviceVersion != NULL)) {
- properties_set(properties, CELIX_FRAMEWORK_SERVICE_VERSION, serviceVersion);
- }
++ if ((properties_get(properties, CELIX_FRAMEWORK_SERVICE_VERSION) == NULL) && (serviceVersion != NULL)) {
++ properties_set(properties, CELIX_FRAMEWORK_SERVICE_VERSION, serviceVersion);
++ }
+
- if (component->setCLanguageProperty && properties_get(properties, CELIX_FRAMEWORK_SERVICE_LANGUAGE) == NULL) { //always set default lang to C
- properties_set(properties, CELIX_FRAMEWORK_SERVICE_LANGUAGE, CELIX_FRAMEWORK_SERVICE_C_LANGUAGE);
- }
++ if (component->setCLanguageProperty && properties_get(properties, CELIX_FRAMEWORK_SERVICE_LANGUAGE) == NULL) { //always set default lang to C
++ properties_set(properties, CELIX_FRAMEWORK_SERVICE_LANGUAGE, CELIX_FRAMEWORK_SERVICE_C_LANGUAGE);
++ }
+
- if (interface && name) {
- interface->serviceName = name;
- interface->service = service;
- interface->properties = properties;
- interface->registration = NULL;
- arrayList_add(component->dm_interfaces, interface);
- } else {
- free(interface);
- free(name);
- status = CELIX_ENOMEM;
++ if (interface && name) {
++ interface->serviceName = name;
++ interface->service = service;
++ interface->properties = properties;
++ interface->registration = NULL;
++ celixThreadMutex_lock(&component->mutex);
++ arrayList_add(component->dm_interfaces, interface);
++ celixThreadMutex_unlock(&component->mutex);
++ if (component->state == DM_CMP_STATE_TRACKING_OPTIONAL) {
++ component_registerServices(component);
+ }
++ } else {
++ free(interface);
++ free(name);
++ status = CELIX_ENOMEM;
+ }
+
+ return status;
+}
+
++
+celix_status_t component_getInterfaces(dm_component_pt component, array_list_pt *out) {
+ celix_status_t status = CELIX_SUCCESS;
+ array_list_pt names = NULL;
+ arrayList_create(&names);
+ celixThreadMutex_lock(&component->mutex);
+ int size = arrayList_size(component->dm_interfaces);
+ int i;
+ for (i = 0; i < size; i += 1) {
+ dm_interface_info_pt info = calloc(1, sizeof(*info));
+ dm_interface_t *interface = arrayList_get(component->dm_interfaces, i);
+ info->name = strdup(interface->serviceName);
+ properties_copy(interface->properties, &info->properties);
+ arrayList_add(names, info);
+ }
+ celixThreadMutex_unlock(&component->mutex);
+
+ if (status == CELIX_SUCCESS) {
+ *out = names;
+ }
+
+ return status;
+}
+
+celix_status_t component_handleEvent(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ dm_handle_event_type_pt data = calloc(1, sizeof(*data));
+ data->dependency = dependency;
+ data->event = event;
+ data->newEvent = NULL;
+
+ status = executor_executeTask(component->executor, component, component_handleEventTask, data);
+// component_handleEventTask(component, data);
+
+ return status;
+}
+
+celix_status_t component_handleEventTask(dm_component_pt component, dm_handle_event_type_pt data) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ switch (data->event->event_type) {
+ case DM_EVENT_ADDED:
+ component_handleAdded(component,data->dependency, data->event);
+ break;
+ case DM_EVENT_CHANGED:
+ component_handleChanged(component,data->dependency, data->event);
+ break;
+ case DM_EVENT_REMOVED:
+ component_handleRemoved(component,data->dependency, data->event);
+ break;
+ case DM_EVENT_SWAPPED:
+ component_handleSwapped(component,data->dependency, data->event, data->newEvent);
+ break;
+ default:
+ break;
+ }
+
+ free(data);
+
+ return status;
+}
+
+static celix_status_t component_suspend(dm_component_pt component, dm_service_dependency_pt dependency) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ dm_service_dependency_strategy_t strategy;
+ serviceDependency_getStrategy(dependency, &strategy);
+ if (strategy == DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND && component->callbackStop != NULL) {
+ status = component->callbackStop(component->implementation);
+ }
+
+ return status;
+}
+
+static celix_status_t component_resume(dm_component_pt component, dm_service_dependency_pt dependency) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ dm_service_dependency_strategy_t strategy;
+ serviceDependency_getStrategy(dependency, &strategy);
+ if (strategy == DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND && component->callbackStop != NULL) {
+ status = component->callbackStart(component->implementation);
+ }
+
+ return status;
+}
+
+celix_status_t component_handleAdded(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ arrayList_add(events, event);
+ pthread_mutex_unlock(&component->mutex);
+
+ serviceDependency_setAvailable(dependency, true);
+
+ switch (component->state) {
+ case DM_CMP_STATE_WAITING_FOR_REQUIRED: {
+ serviceDependency_invokeSet(dependency, event);
+ bool required = false;
+ serviceDependency_isRequired(dependency, &required);
+ if (required) {
+ component_handleChange(component);
+ }
+ break;
+ }
+ case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
+ bool instanceBound = false;
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+ bool required = false;
+ serviceDependency_isRequired(dependency, &required);
+ if (!instanceBound) {
+ if (required) {
+ serviceDependency_invokeSet(dependency, event);
+ serviceDependency_invokeAdd(dependency, event);
+ }
+ dm_event_pt event = NULL;
+ component_getDependencyEvent(component, dependency, &event);
+ component_updateInstance(component, dependency, event, false, true);
+ }
+
+ if (required) {
+ component_handleChange(component);
+ }
+ break;
+ }
+ case DM_CMP_STATE_TRACKING_OPTIONAL:
+ component_suspend(component,dependency);
+ serviceDependency_invokeSet(dependency, event);
+ serviceDependency_invokeAdd(dependency, event);
+ component_resume(component,dependency);
+ dm_event_pt event = NULL;
+ component_getDependencyEvent(component, dependency, &event);
+ component_updateInstance(component, dependency, event, false, true);
+ break;
+ default:
+ break;
+ }
+
+ return status;
+}
+
+celix_status_t component_handleChanged(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ int index = arrayList_indexOf(events, event);
+ if (index < 0) {
+ pthread_mutex_unlock(&component->mutex);
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ dm_event_pt old = arrayList_remove(events, (unsigned int) index);
+ arrayList_add(events, event);
+ pthread_mutex_unlock(&component->mutex);
+
+ serviceDependency_invokeSet(dependency, event);
+ switch (component->state) {
+ case DM_CMP_STATE_TRACKING_OPTIONAL:
+ component_suspend(component,dependency);
+ serviceDependency_invokeChange(dependency, event);
+ component_resume(component,dependency);
+ dm_event_pt hevent = NULL;
+ component_getDependencyEvent(component, dependency, &hevent);
+ component_updateInstance(component, dependency, hevent, true, false);
+ break;
+ case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
+ bool instanceBound = false;
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+ if (!instanceBound) {
+ serviceDependency_invokeChange(dependency, event);
+ dm_event_pt hevent = NULL;
+ component_getDependencyEvent(component, dependency, &hevent);
+ component_updateInstance(component, dependency, hevent, true, false);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+
+ event_destroy(&old);
+ }
+
+ return status;
+}
+
+celix_status_t component_handleRemoved(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ int size = arrayList_size(events);
+ if (arrayList_contains(events, event)) {
+ size--;
+ }
+ pthread_mutex_unlock(&component->mutex);
+ serviceDependency_setAvailable(dependency, size > 0);
+ component_handleChange(component);
+
+ pthread_mutex_lock(&component->mutex);
+ int index = arrayList_indexOf(events, event);
+ if (index < 0) {
+ pthread_mutex_unlock(&component->mutex);
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ dm_event_pt old = arrayList_remove(events, (unsigned int) index);
+ pthread_mutex_unlock(&component->mutex);
+
+
+ switch (component->state) {
+ case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
+ serviceDependency_invokeSet(dependency, event);
+ bool instanceBound = false;
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+ if (!instanceBound) {
+ bool required = false;
+ serviceDependency_isRequired(dependency, &required);
+ if (required) {
+ serviceDependency_invokeRemove(dependency, event);
+ }
+ dm_event_pt hevent = NULL;
+ component_getDependencyEvent(component, dependency, &hevent);
+ component_updateInstance(component, dependency, hevent, false, false);
+ }
+ break;
+ }
+ case DM_CMP_STATE_TRACKING_OPTIONAL:
+ component_suspend(component,dependency);
+ serviceDependency_invokeSet(dependency, event);
+ serviceDependency_invokeRemove(dependency, event);
+ component_resume(component,dependency);
+ dm_event_pt hevent = NULL;
+ component_getDependencyEvent(component, dependency, &hevent);
+ component_updateInstance(component, dependency, hevent, false, false);
+ break;
+ default:
+ break;
+ }
+
+ event_destroy(&event);
+ if (old) {
+ event_destroy(&old);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t component_handleSwapped(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event, dm_event_pt newEvent) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ int index = arrayList_indexOf(events, event);
+ if (index < 0) {
+ pthread_mutex_unlock(&component->mutex);
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ dm_event_pt old = arrayList_remove(events, (unsigned int) index);
+ arrayList_add(events, newEvent);
+ pthread_mutex_unlock(&component->mutex);
+
+ serviceDependency_invokeSet(dependency, event);
+
+ switch (component->state) {
+ case DM_CMP_STATE_WAITING_FOR_REQUIRED:
+ break;
+ case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
+ bool instanceBound = false;
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+ if (!instanceBound) {
+ bool required = false;
+ serviceDependency_isRequired(dependency, &required);
+ if (required) {
+ serviceDependency_invokeSwap(dependency, event, newEvent);
+ }
+ }
+ break;
+ }
+ case DM_CMP_STATE_TRACKING_OPTIONAL:
+ component_suspend(component,dependency);
+ serviceDependency_invokeSwap(dependency, event, newEvent);
+ component_resume(component,dependency);
+ break;
+ default:
+ break;
+ }
+
+ event_destroy(&event);
+ if (old) {
+ event_destroy(&old);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t component_updateInstance(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event, bool update, bool add) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ bool autoConfig = false;
+
+ serviceDependency_isAutoConfig(dependency, &autoConfig);
+
+ if (autoConfig) {
+ const void *service = NULL;
+ const void **field = NULL;
+
+ if (event != NULL) {
+ event_getService(event, &service);
+ }
+ serviceDependency_getAutoConfig(dependency, &field);
+ serviceDependency_lock(dependency);
+ *field = service;
+ serviceDependency_unlock(dependency);
+ }
+
+ return status;
+}
+
+celix_status_t component_startDependencies(dm_component_pt component __attribute__((unused)), array_list_pt dependencies) {
+ celix_status_t status = CELIX_SUCCESS;
+ array_list_pt required_dependencies = NULL;
+ arrayList_create(&required_dependencies);
+
+ for (unsigned int i = 0; i < arrayList_size(dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(dependencies, i);
+ bool required = false;
+ serviceDependency_isRequired(dependency, &required);
+ if (required) {
+ arrayList_add(required_dependencies, dependency);
+ continue;
+ }
+
+ serviceDependency_start(dependency);
+ }
+
+ for (unsigned int i = 0; i < arrayList_size(required_dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(required_dependencies, i);
+ serviceDependency_start(dependency);
+ }
+
+ arrayList_destroy(required_dependencies);
+
+ return status;
+}
+
+celix_status_t component_stopDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+ pthread_mutex_unlock(&component->mutex);
+ serviceDependency_stop(dependency);
+ pthread_mutex_lock(&component->mutex);
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_handleChange(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ dm_component_state_t oldState;
+ dm_component_state_t newState;
+
+ bool transition = false;
+ do {
+ oldState = component->state;
+ status = component_calculateNewState(component, oldState, &newState);
+ if (status == CELIX_SUCCESS) {
+ component->state = newState;
+ status = component_performTransition(component, oldState, newState, &transition);
+ }
+
+ if (status != CELIX_SUCCESS) {
+ break;
+ }
+ } while (transition);
+
+ return status;
+}
+
+celix_status_t component_calculateNewState(dm_component_pt component, dm_component_state_t currentState, dm_component_state_t *newState) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (currentState == DM_CMP_STATE_INACTIVE) {
+ if (component->isStarted) {
+ *newState = DM_CMP_STATE_WAITING_FOR_REQUIRED;
+ } else {
+ *newState = currentState;
+ }
+ } else if (currentState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
+ if (!component->isStarted) {
+ *newState = DM_CMP_STATE_INACTIVE;
+ } else {
+ bool available = false;
+ component_allRequiredAvailable(component, &available);
+
+ if (available) {
+ *newState = DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED;
+ } else {
+ *newState = currentState;
+ }
+ }
+ } else if (currentState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED) {
+ if (!component->isStarted) {
+ *newState = DM_CMP_STATE_WAITING_FOR_REQUIRED;
+ } else {
+ bool available = false;
+ component_allRequiredAvailable(component, &available);
+
+ if (available) {
+ bool instanceBoundAvailable = false;
+ component_allInstanceBoundAvailable(component, &instanceBoundAvailable);
+
+ if (instanceBoundAvailable) {
+ *newState = DM_CMP_STATE_TRACKING_OPTIONAL;
+ } else {
+ *newState = currentState;
+ }
+ } else {
+ *newState = currentState;
+ }
+ }
+ } else if (currentState == DM_CMP_STATE_TRACKING_OPTIONAL) {
+ bool instanceBoundAvailable = false;
+ bool available = false;
+
+ component_allInstanceBoundAvailable(component, &instanceBoundAvailable);
+ component_allRequiredAvailable(component, &available);
+
+ if (component->isStarted && available && instanceBoundAvailable) {
+ *newState = currentState;
+ } else {
+ *newState = DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED;
+ }
+ } else {
+ //should not reach
+ *newState = DM_CMP_STATE_INACTIVE;
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+
+ return status;
+}
+
+celix_status_t component_performTransition(dm_component_pt component, dm_component_state_t oldState, dm_component_state_t newState, bool *transition) {
+ celix_status_t status = CELIX_SUCCESS;
+ //printf("performing transition for %s in thread %i from %i to %i\n", component->name, (int) pthread_self(), oldState, newState);
+
+ if (oldState == newState) {
+ *transition = false;
+ } else if (oldState == DM_CMP_STATE_INACTIVE && newState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
+ component_startDependencies(component, component->dependencies);
+ *transition = true;
+ } else if (oldState == DM_CMP_STATE_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED) {
+ component_invokeAddRequiredDependencies(component);
+ component_invokeAutoConfigDependencies(component);
+ if (component->callbackInit) {
+ status = component->callbackInit(component->implementation);
+ }
+ *transition = true;
+ } else if (oldState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_TRACKING_OPTIONAL) {
+ component_invokeAddRequiredInstanceBoundDependencies(component);
+ component_invokeAutoConfigInstanceBoundDependencies(component);
+ component_invokeAddOptionalDependencies(component);
+ if (component->callbackStart) {
+ status = component->callbackStart(component->implementation);
+ }
+ component_registerServices(component);
+ *transition = true;
+ } else if (oldState == DM_CMP_STATE_TRACKING_OPTIONAL && newState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED) {
+ component_unregisterServices(component);
+ if (component->callbackStop) {
+ status = component->callbackStop(component->implementation);
+ }
+ component_invokeRemoveOptionalDependencies(component);
+ component_invokeRemoveInstanceBoundDependencies(component);
+ *transition = true;
+ } else if (oldState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
+ if (component->callbackDeinit) {
+ status = component->callbackDeinit(component->implementation);
+ }
+ component_invokeRemoveRequiredDependencies(component);
+ *transition = true;
+ } else if (oldState == DM_CMP_STATE_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_INACTIVE) {
+ component_stopDependencies(component);
+ *transition = true;
+ }
+
+ return status;
+}
+
+celix_status_t component_allRequiredAvailable(dm_component_pt component, bool *available) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ *available = true;
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+ bool required = false;
+ bool instanceBound = false;
+
+ serviceDependency_isRequired(dependency, &required);
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+ if (required && !instanceBound) {
+ bool isAvailable = false;
+ serviceDependency_isAvailable(dependency, &isAvailable);
+ if (!isAvailable) {
+ *available = false;
+ break;
+ }
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_allInstanceBoundAvailable(dm_component_pt component, bool *available) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ *available = true;
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+ bool required = false;
+ bool instanceBound = false;
+
+ serviceDependency_isRequired(dependency, &required);
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+ if (required && instanceBound) {
+ bool isAvailable = false;
+ serviceDependency_isAvailable(dependency, &isAvailable);
+ if (!isAvailable) {
+ *available = false;
+ break;
+ }
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_invokeAddRequiredDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+ bool required = false;
+ bool instanceBound = false;
+
+ serviceDependency_isRequired(dependency, &required);
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+ if (required && !instanceBound) {
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ if (events) {
+ for (unsigned int j = 0; j < arrayList_size(events); j++) {
+ dm_event_pt event = arrayList_get(events, j);
+ serviceDependency_invokeAdd(dependency, event);
+ }
+ }
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_invokeAutoConfigDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+ bool autoConfig = false;
+ bool instanceBound = false;
+
+ serviceDependency_isAutoConfig(dependency, &autoConfig);
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+ if (autoConfig && !instanceBound) {
+ component_configureImplementation(component, dependency);
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_invokeAutoConfigInstanceBoundDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+ bool autoConfig = false;
+ bool instanceBound = false;
+
+ serviceDependency_isAutoConfig(dependency, &autoConfig);
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+ if (autoConfig && instanceBound) {
+ component_configureImplementation(component, dependency);
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_invokeAddRequiredInstanceBoundDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+ bool required = false;
+ bool instanceBound = false;
+
+ serviceDependency_isRequired(dependency, &required);
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+ if (instanceBound && required) {
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ if (events) {
+ for (unsigned int j = 0; j < arrayList_size(events); j++) {
+ dm_event_pt event = arrayList_get(events, j);
+ serviceDependency_invokeAdd(dependency, event);
+ }
+ }
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_invokeAddOptionalDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+ bool required = false;
+
+ serviceDependency_isRequired(dependency, &required);
+
+ if (!required) {
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ if (events) {
+ for (unsigned int j = 0; j < arrayList_size(events); j++) {
+ dm_event_pt event = arrayList_get(events, j);
+ serviceDependency_invokeAdd(dependency, event);
+ }
+ }
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_invokeRemoveOptionalDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+ bool required = false;
+
+ serviceDependency_isRequired(dependency, &required);
+
+ if (!required) {
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ if (events) {
+ for (unsigned int j = 0; j < arrayList_size(events); j++) {
+ dm_event_pt event = arrayList_get(events, j);
+ serviceDependency_invokeRemove(dependency, event);
+ }
+ }
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_invokeRemoveInstanceBoundDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+ bool instanceBound = false;
+
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+ if (instanceBound) {
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ if (events) {
+ for (unsigned int j = 0; j < arrayList_size(events); j++) {
+ dm_event_pt event = arrayList_get(events, j);
+ serviceDependency_invokeRemove(dependency, event);
+ }
+ }
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_invokeRemoveRequiredDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+ bool required = false;
+ bool instanceBound = false;
+
+ serviceDependency_isRequired(dependency, &required);
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+ if (!instanceBound && required) {
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ if (events) {
+ for (unsigned int j = 0; j < arrayList_size(events); j++) {
+ dm_event_pt event = arrayList_get(events, j);
+ serviceDependency_invokeRemove(dependency, event);
+ }
+ }
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_getDependencyEvent(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt *event_pptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ *event_pptr = NULL;
+
+ if (events) {
+ for (unsigned int j = 0; j < arrayList_size(events); j++) {
+ dm_event_pt event_ptr = arrayList_get(events, j);
+ if (*event_pptr != NULL) {
+ int compare = 0;
+ event_compareTo(event_ptr, *event_pptr, &compare);
+ if (compare > 0) {
+ *event_pptr = event_ptr;
+ }
+ } else {
+ *event_pptr = event_ptr;
+ }
+ }
+ }
+
+ return status;
+}
+
+celix_status_t component_configureImplementation(dm_component_pt component, dm_service_dependency_pt dependency) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ const void **field = NULL;
+
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ if (events) {
+ const void *service = NULL;
+ dm_event_pt event = NULL;
+ component_getDependencyEvent(component, dependency, &event);
+ if (event != NULL) {
+ event_getService(event, &service);
+ serviceDependency_getAutoConfig(dependency, &field);
+ serviceDependency_lock(dependency);
+ *field = service;
+ serviceDependency_unlock(dependency);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t component_registerServices(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (component->context != NULL) {
+ unsigned int i;
++ celixThreadMutex_lock(&component->mutex);
+ for (i = 0; i < arrayList_size(component->dm_interfaces); i++) {
+ dm_interface_t *interface = arrayList_get(component->dm_interfaces, i);
++ if (interface->registration == NULL) {
+ properties_pt regProps = NULL;
+ properties_copy(interface->properties, ®Props);
- bundleContext_registerService(component->context, interface->serviceName, interface->service, regProps, &interface->registration);
++ bundleContext_registerService(component->context, interface->serviceName, interface->service, regProps,
++ &interface->registration);
++ }
+ }
++ celixThreadMutex_unlock(&component->mutex);
+ }
+
+ return status;
+}
+
+celix_status_t component_unregisterServices(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ unsigned int i;
+
++ celixThreadMutex_lock(&component->mutex);
+ for (i = 0; i < arrayList_size(component->dm_interfaces); i++) {
- dm_interface_t *interface = arrayList_get(component->dm_interfaces, i);
++ dm_interface_t *interface = arrayList_get(component->dm_interfaces, i);
+
- serviceRegistration_unregister(interface->registration);
- interface->registration = NULL;
++ serviceRegistration_unregister(interface->registration);
++ interface->registration = NULL;
+ }
++ celixThreadMutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_setCallbacks(dm_component_pt component, init_fpt init, start_fpt start, stop_fpt stop, deinit_fpt deinit) {
+ if (component->active) {
+ return CELIX_ILLEGAL_STATE;
+ }
+ component->callbackInit = init;
+ component->callbackStart = start;
+ component->callbackStop = stop;
+ component->callbackDeinit = deinit;
+ return CELIX_SUCCESS;
+}
+
+celix_status_t component_isAvailable(dm_component_pt component, bool *available) {
+ *available = component->state == DM_CMP_STATE_TRACKING_OPTIONAL;
+ return CELIX_SUCCESS;
+}
+
+celix_status_t component_setImplementation(dm_component_pt component, void *implementation) {
+ component->implementation = implementation;
+ return CELIX_SUCCESS;
+}
+
+celix_status_t component_getBundleContext(dm_component_pt component, bundle_context_pt *context) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!component) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *context = component->context;
+ }
+
+ return status;
+}
+
+
+static celix_status_t executor_create(dm_component_pt component __attribute__((unused)), dm_executor_pt *executor) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *executor = malloc(sizeof(**executor));
+ if (!*executor) {
+ status = CELIX_ENOMEM;
+ } else {
+ linkedList_create(&(*executor)->workQueue);
+ pthread_mutex_init(&(*executor)->mutex, NULL);
+ (*executor)->runningThreadSet = false;
+ }
+
+ return status;
+}
+
+static void executor_destroy(dm_executor_pt executor) {
+
+ if (executor) {
+ pthread_mutex_destroy(&executor->mutex);
+ linkedList_destroy(executor->workQueue);
+
+ free(executor);
+ }
+}
+
+static celix_status_t executor_schedule(dm_executor_pt executor, dm_component_pt component, void (*command), void *data) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ dm_executor_task_t *task = NULL;
+ task = malloc(sizeof(*task));
+ if (!task) {
+ status = CELIX_ENOMEM;
+ } else {
+ task->component = component;
+ task->command = command;
+ task->data = data;
+
+ pthread_mutex_lock(&executor->mutex);
+ linkedList_addLast(executor->workQueue, task);
+ pthread_mutex_unlock(&executor->mutex);
+ }
+
+ return status;
+}
+
+static celix_status_t executor_executeTask(dm_executor_pt executor, dm_component_pt component, void (*command), void *data) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ // Check thread and executor thread, if the same, execute immediately.
+// bool execute = false;
+// pthread_mutex_lock(&executor->mutex);
+// pthread_t currentThread = pthread_self();
+// if (pthread_equal(executor->runningThread, currentThread)) {
+// execute = true;
+// }
+// pthread_mutex_unlock(&executor->mutex);
+
+ // For now, just schedule.
+ executor_schedule(executor, component, command, data);
+ executor_execute(executor);
+
+ return status;
+}
+
+static celix_status_t executor_execute(dm_executor_pt executor) {
+ celix_status_t status = CELIX_SUCCESS;
+ pthread_t currentThread = pthread_self();
+
+ pthread_mutex_lock(&executor->mutex);
+ bool execute = false;
+ if (!executor->runningThreadSet) {
+ executor->runningThread = currentThread;
+ executor->runningThreadSet = true;
+ execute = true;
+ }
+ pthread_mutex_unlock(&executor->mutex);
+ if (execute) {
+ executor_runTasks(executor, currentThread);
+ }
+
+ return status;
+}
+
+static celix_status_t executor_runTasks(dm_executor_pt executor, pthread_t currentThread __attribute__((unused))) {
+ celix_status_t status = CELIX_SUCCESS;
+// bool execute = false;
+
+ do {
+ dm_executor_task_t *entry = NULL;
+ pthread_mutex_lock(&executor->mutex);
+ while ((entry = linkedList_removeFirst(executor->workQueue)) != NULL) {
+ pthread_mutex_unlock(&executor->mutex);
+
+ entry->command(entry->component, entry->data);
+
+ pthread_mutex_lock(&executor->mutex);
+
+ free(entry);
+ }
+ executor->runningThreadSet = false;
+ pthread_mutex_unlock(&executor->mutex);
+
+// pthread_mutex_lock(&executor->mutex);
+// if (executor->runningThread == NULL) {
+// executor->runningThread = currentThread;
+// execute = true;
+// }
+// pthread_mutex_unlock(&executor->mutex);
+ } while (!linkedList_isEmpty(executor->workQueue)); // && execute
+
+ return status;
+}
+
+celix_status_t component_getComponentInfo(dm_component_pt component, dm_component_info_pt *out) {
+ celix_status_t status = CELIX_SUCCESS;
+ int i;
+ int size;
+ dm_component_info_pt info = NULL;
+ info = calloc(1, sizeof(*info));
+
+ if (info == NULL) {
+ return CELIX_ENOMEM;
+ }
+
+ arrayList_create(&info->dependency_list);
+ component_getInterfaces(component, &info->interfaces);
+ info->active = false;
+ memcpy(info->id, component->id, DM_COMPONENT_MAX_ID_LENGTH);
+ memcpy(info->name, component->name, DM_COMPONENT_MAX_NAME_LENGTH);
+
+ switch (component->state) {
+ case DM_CMP_STATE_INACTIVE :
+ info->state = strdup("INACTIVE");
+ break;
+ case DM_CMP_STATE_WAITING_FOR_REQUIRED :
+ info->state = strdup("WAITING_FOR_REQUIRED");
+ break;
+ case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED :
+ info->state = strdup("INSTANTIATED_AND_WAITING_FOR_REQUIRED");
+ break;
+ case DM_CMP_STATE_TRACKING_OPTIONAL :
+ info->state = strdup("TRACKING_OPTIONAL");
+ info->active = true;
+ break;
+ default :
+ info->state = strdup("UNKNOWN");
+ break;
+ }
+
+ celixThreadMutex_lock(&component->mutex);
+ size = arrayList_size(component->dependencies);
+ for (i = 0; i < size; i += 1) {
+ dm_service_dependency_pt dep = arrayList_get(component->dependencies, i);
+ dm_service_dependency_info_pt depInfo = NULL;
+ status = serviceDependency_getServiceDependencyInfo(dep, &depInfo);
+ if (status == CELIX_SUCCESS) {
+ arrayList_add(info->dependency_list, depInfo);
+ } else {
+ break;
+ }
+ }
+ celixThreadMutex_unlock(&component->mutex);
+
+ if (status == CELIX_SUCCESS) {
+ *out = info;
+ } else if (info != NULL) {
+ component_destroyComponentInfo(info);
+ }
+
+ return status;
+}
+
+void component_destroyComponentInfo(dm_component_info_pt info) {
+ int i;
+ int size;
+ if (info != NULL) {
+ free(info->state);
+
+ if (info->interfaces != NULL) {
+ size = arrayList_size(info->interfaces);
+ for (i = 0; i < size; i += 1) {
+ dm_interface_info_pt intfInfo = arrayList_get(info->interfaces, i);
+ free(intfInfo->name);
+ properties_destroy(intfInfo->properties);
+ free(intfInfo);
+ }
+ arrayList_destroy(info->interfaces);
+ }
+ if (info->dependency_list != NULL) {
+ size = arrayList_size(info->dependency_list);
+ for (i = 0; i < size; i += 1) {
+ dm_service_dependency_info_pt depInfo = arrayList_get(info->dependency_list, i);
+ dependency_destroyDependencyInfo(depInfo);
+ }
+ arrayList_destroy(info->dependency_list);
+ }
+ }
+ free(info);
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/dfi/CMakeLists.txt
----------------------------------------------------------------------
diff --cc dfi/CMakeLists.txt
index 642ac68,676277c..950aaa5
--- a/dfi/CMakeLists.txt
+++ b/dfi/CMakeLists.txt
@@@ -18,57 -18,73 +18,65 @@@
find_package(FFI REQUIRED)
find_package(Jansson REQUIRED)
-include_directories(
- ${FFI_INCLUDE_DIRS}
- ${JANSSON_INCLUDE_DIRS}
- private/include
- public/include
- ${PROJECT_SOURCE_DIR}/utils/public/include
+set(SOURCES
+ src/dyn_common.c
+ src/dyn_type.c
+ src/dyn_function.c
+ src/dyn_interface.c
+ src/dyn_message.c
+ src/json_serializer.c
+ src/json_rpc.c
)
- add_library(dfi SHARED ${SOURCES})
- set_target_properties(dfi PROPERTIES OUTPUT_NAME "celix_dfi")
- target_include_directories(dfi PUBLIC include ${JANSSON_INCLUDE_DIRS})
- target_include_directories(dfi PRIVATE src ${FFI_INCLUDE_DIRS})
- target_link_libraries(dfi PUBLIC ${JANSSON_LIBRARY})
- target_link_libraries(dfi PRIVATE Celix::utils ${FFI_LIBRARIES})
- set_target_properties(dfi PROPERTIES "SOVERSION" 1)
-set(MEMSTREAM_SOURCES )
-set(MEMSTREAM_INCLUDES )
-if (APPLE OR ANDROID)
- set(MEMSTREAM_SOURCES ${PROJECT_SOURCE_DIR}/utils/private/src/memstream/open_memstream.c ${PROJECT_SOURCE_DIR}/utils/private/src/memstream/fmemopen.c)
- set(MEMSTREAM_INCLUDES ${PROJECT_SOURCE_DIR}/utils/public/include/memstream/open_memstream.h ${PROJECT_SOURCE_DIR}/utils/public/include/memstream/fmemopen.h)
- include_directories(${PROJECT_SOURCE_DIR}/utils/public/include/memstream)
-endif()
++add_library(celix_dfi SHARED ${SOURCES})
++set_target_properties(celix_dfi PROPERTIES OUTPUT_NAME "celix_dfi")
++target_include_directories(celix_dfi PUBLIC include ${JANSSON_INCLUDE_DIRS})
++target_include_directories(celix_dfi PRIVATE src ${FFI_INCLUDE_DIRS})
++target_link_libraries(celix_dfi PUBLIC ${JANSSON_LIBRARY})
++target_link_libraries(celix_dfi PRIVATE Celix::utils ${FFI_LIBRARIES})
++set_target_properties(celix_dfi PROPERTIES "SOVERSION" 1)
- add_library(dfi_static STATIC ${SOURCES})
- set_target_properties(dfi_static PROPERTIES OUTPUT_NAME "celix_dfi_static")
- target_include_directories(dfi_static PUBLIC include ${JANSSON_INCLUDE_DIRS})
- target_include_directories(dfi_static PRIVATE src ${FFI_INCLUDE_DIRS})
- target_link_libraries(dfi_static PUBLIC ${JANSSON_LIBRARY})
- target_link_libraries(dfi_static PRIVATE Celix::utils ${FFI_LIBRARIES})
-add_library(celix_dfi SHARED
- private/src/dyn_common.c
- private/src/dyn_type.c
- private/src/dyn_function.c
- private/src/dyn_interface.c
- private/src/dyn_message.c
- private/src/json_serializer.c
- private/src/json_rpc.c
- ${MEMSTREAM_SOURCES}
++add_library(celix_dfi_static STATIC ${SOURCES})
++set_target_properties(celix_dfi_static PROPERTIES OUTPUT_NAME "celix_dfi_static")
++target_include_directories(celix_dfi_static PUBLIC include ${JANSSON_INCLUDE_DIRS})
++target_include_directories(celix_dfi_static PRIVATE src ${FFI_INCLUDE_DIRS})
++target_link_libraries(celix_dfi_static PUBLIC ${JANSSON_LIBRARY})
++target_link_libraries(celix_dfi_static PRIVATE Celix::utils ${FFI_LIBRARIES})
- install(TARGETS dfi dfi_static DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT framework)
- public/include/dyn_common.h
- public/include/dyn_type.h
- public/include/dyn_function.h
- public/include/dyn_interface.h
- public/include/dyn_message.h
- public/include/json_serializer.h
- public/include/json_rpc.h
- ${MEMSTREAM_INCLUDES}
-)
-set_target_properties(celix_dfi PROPERTIES "SOVERSION" 1)
-set_target_properties(celix_dfi PROPERTIES "VERSION" 1.1.0)
-target_link_libraries(celix_dfi celix_utils ${FFI_LIBRARIES} ${JANSSON_LIBRARY})
++install(TARGETS celix_dfi celix_dfi_static DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT framework)
+ install(TARGETS celix_dfi DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT framework)
-FILE(GLOB files "public/include/*.h" ${MEMSTREAM_INCLUDES})
++FILE(GLOB files "include/*.h")
+ INSTALL(FILES ${files} DESTINATION include/celix/dfi COMPONENT framework)
+#Alias setup to match external usage
- add_library(Celix::dfi ALIAS dfi)
- add_library(Celix::dfi_static ALIAS dfi_static)
++add_library(Celix::dfi ALIAS celix_dfi)
++add_library(Celix::dfi_static ALIAS celix_dfi_static)
if (ENABLE_TESTING)
find_package(CppUTest REQUIRED)
+
include_directories(${CPPUTEST_INCLUDE_DIR})
+ SET(CMAKE_SKIP_BUILD_RPATH FALSE) #TODO needed?
+ SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) #TODO needed?
+ SET(CMAKE_INSTALL_RPATH "${PROJECT_BINARY_DIR}/dfi" "${PROJECT_BINARY_DIR}/utils")
+
add_executable(test_dfi
- private/test/dyn_type_tests.cpp
- private/test/dyn_function_tests.cpp
- private/test/dyn_closure_tests.cpp
- private/test/dyn_interface_tests.cpp
- private/test/dyn_message_tests.cpp
- private/test/json_serializer_tests.cpp
- private/test/json_rpc_tests.cpp
- private/test/run_tests.cpp
+ test/dyn_type_tests.cpp
+ test/dyn_function_tests.cpp
+ test/dyn_closure_tests.cpp
+ test/dyn_interface_tests.cpp
+ test/dyn_message_tests.cpp
+ test/json_serializer_tests.cpp
+ test/json_rpc_tests.cpp
+ test/run_tests.cpp
)
- target_link_libraries(test_dfi celix_dfi ${FFI_LIBRARIES} ${CPPUTEST_LIBRARY})
+ target_link_libraries(test_dfi PRIVATE Celix::dfi Celix::utils ${FFI_LIBRARIES} ${CPPUTEST_LIBRARY})
+ target_include_directories(test_dfi PRIVATE ${FFI_INCLUDE_DIRS})
- file(COPY ${CMAKE_CURRENT_LIST_DIR}/private/test/schemas DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
- file(COPY ${CMAKE_CURRENT_LIST_DIR}/private/test/descriptors DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
+ file(COPY ${CMAKE_CURRENT_LIST_DIR}/test/schemas DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
+ file(COPY ${CMAKE_CURRENT_LIST_DIR}/test/descriptors DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
add_test(NAME run_test_dfi COMMAND test_dfi)
SETUP_TARGET_FOR_COVERAGE(test_dfi_cov test_dfi ${CMAKE_BINARY_DIR}/coverage/test_dfi/test_dfi)
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/etcdlib/CMakeLists.txt
----------------------------------------------------------------------
diff --cc etcdlib/CMakeLists.txt
index 060eeb0,1904dea..fac356a
--- a/etcdlib/CMakeLists.txt
+++ b/etcdlib/CMakeLists.txt
@@@ -41,17 -41,19 +41,18 @@@ endif (
find_package(CURL REQUIRED)
find_package(Jansson REQUIRED)
-include_directories(
- ${CURL_INCLUDE_DIRS}
- ${JANSSON_INCLUDE_DIRS}
- private/include
- public/include
-)
-
add_library(etcdlib SHARED
- private/src/etcd.c
+ src/etcd.c
+)
+target_include_directories(etcdlib PUBLIC api)
+target_include_directories(etcdlib PRIVATE
+ src
+ ${CURL_INCLUDE_DIRS}
+ ${JANSSON_INCLUDE_DIRS}
)
- set_target_properties(etcdlib PROPERTIES "SOVERSION" 1)
+ set_target_properties(etcdlib PROPERTIES SOVERSION 1)
+ set_target_properties(etcdlib PROPERTIES VERSION 1.0.0)
target_link_libraries(etcdlib ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
add_library(etcdlib_static STATIC
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/examples/dm_example/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/dm_example/CMakeLists.txt
index 2cef7ec,fa6ec57..a18a675
--- a/examples/dm_example/CMakeLists.txt
+++ b/examples/dm_example/CMakeLists.txt
@@@ -24,42 -27,41 +24,40 @@@ if (BUILD_DEPENDENCY_MANAGER
add_subdirectory(phase3)
-- add_deploy("dm_example"
++ add_deploy(dm_example
COPY
BUNDLES
- shell
- shell_tui
- dm_shell
- phase1
- phase2a
- phase2b
- phase3
+ Celix::shell
+ Celix::shell_tui
+ Celix::dm_shell
+ dm_example_phase1
+ dm_example_phase2a
+ dm_example_phase2b
+ dm_example_phase3
PROPERTIES
LOGHELPER_ENABLE_STDOUT_FALLBACK=true
)
- if (ENABLE_DOCKER)
- add_celix_docker(dm_exmpl_base
- NAME dmbase
- IMAGE_NAME dmbase
- GROUP examples
- INSTRUCTIONS
- "LABEL exmpl=value"
- )
- add_celix_docker(dm_exmpl
- FROM dmbase
+ add_celix_docker(dm_exmpl_base
+ NAME dmbase
+ IMAGE_NAME dmbase
GROUP examples
- BUNDLES
- Celix::shell
- Celix::shell_tui
- Celix::dm_shell
- dm_example_phase1
- dm_example_phase2a
- dm_example_phase2b
- dm_example_phase3
- PROPERTIES
- LOGHELPER_ENABLE_STDOUT_FALLBACK=true
- )
- endif ()
+ INSTRUCTIONS
+ "LABEL exmpl=value"
+ )
+ add_celix_docker(dm_exmpl
+ FROM dmbase
+ GROUP examples
+ BUNDLES
- shell
- shell_tui
- dm_shell
- phase1
- phase2a
- phase2b
- phase3
++ Celix::shell
++ Celix::shell_tui
++ Celix::dm_shell
++ dm_example_phase1
++ dm_example_phase2a
++ dm_example_phase2b
++ dm_example_phase3
+ PROPERTIES
+ LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+ )
- add_dependencies(celix-build-dm_exmpl-docker-image celix-build-dm_exmpl_base-docker-image)
endif ()
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/examples/dm_example/phase1/src/phase1_activator.c
----------------------------------------------------------------------
diff --cc examples/dm_example/phase1/src/phase1_activator.c
index 783e642,0000000..31dcb16
mode 100644,000000..100644
--- a/examples/dm_example/phase1/src/phase1_activator.c
+++ b/examples/dm_example/phase1/src/phase1_activator.c
@@@ -1,85 -1,0 +1,86 @@@
+/**
+ *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.
+ */
+/*
+ * activator.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <phase1_cmp.h>
+
+#include "bundle_activator.h"
+#include "dm_activator.h"
+
+#include "phase1.h"
+
+struct phase1_activator_struct {
+ phase1_cmp_t *phase1Cmp;
+ phase1_t phase1Serv;
+};
+
+celix_status_t dm_create(bundle_context_pt context, void **userData) {
+ printf("PHASE1: dm_create\n");
+ *userData = calloc(1, sizeof(struct phase1_activator_struct));
+ return *userData != NULL ? CELIX_SUCCESS : CELIX_ENOMEM;
+}
+
+celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("PHASE1: dm_init\n");
+ celix_status_t status = CELIX_SUCCESS;
+
+
+ struct phase1_activator_struct *act = (struct phase1_activator_struct *)userData;
+
+ act->phase1Cmp = phase1_create();
+ if (act->phase1Cmp != NULL) {
+
+ act->phase1Serv.handle = act->phase1Cmp;
+ act->phase1Serv.getData = (void *)phase1_getData;
+
+ properties_pt props = properties_create();
+ properties_set(props, "id", "phase1");
+
+ dm_component_pt cmp;
+ component_create(context, "PHASE1_PROCESSING_COMPONENT", &cmp);
+ component_setImplementation(cmp, act->phase1Cmp);
+ component_setCallbacksSafe(cmp, phase1_cmp_t *, phase1_init, phase1_start, phase1_stop, phase1_deinit);
++ phase1_setComp(act->phase1Cmp, cmp);
+ component_addInterface(cmp, PHASE1_NAME, PHASE1_VERSION, &act->phase1Serv, props);
+
+ dependencyManager_add(manager, cmp);
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ return status;
+}
+
+celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("PHASE1: dm-destroy\n");
+
+ struct phase1_activator_struct *act = (struct phase1_activator_struct *)userData;
+ if (act->phase1Cmp != NULL) {
+ phase1_destroy(act->phase1Cmp);
+ }
+ free(act);
+
+ return CELIX_SUCCESS;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/examples/dm_example/phase1/src/phase1_cmp.c
----------------------------------------------------------------------
diff --cc examples/dm_example/phase1/src/phase1_cmp.c
index 75de182,0000000..40da821
mode 100644,000000..100644
--- a/examples/dm_example/phase1/src/phase1_cmp.c
+++ b/examples/dm_example/phase1/src/phase1_cmp.c
@@@ -1,99 -1,0 +1,110 @@@
+/**
+ *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.
+ */
+/*
+ * publisher.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+
+#include "celix_threads.h"
+#include "phase1_cmp.h"
++#include "dm_component.h"
+
+#define SLEEPTIME 1000
+
+struct phase1_cmp_struct {
+ celix_thread_t thread;
+ bool running;
+ unsigned int counter;
++ dm_component_pt component;
++
+};
+
+static void *phase1_thread(void *data);
+
+phase1_cmp_t *phase1_create(void) {
+ phase1_cmp_t *cmp = calloc(1, sizeof(*cmp));
+ if (cmp != NULL) {
+ cmp->counter = 0;
+ cmp->running = false;
+ }
+ return cmp;
+}
+
++void phase1_setComp(phase1_cmp_t *cmp, dm_component_pt dmCmp) {
++ cmp->component = dmCmp;
++}
++
+int phase1_init(phase1_cmp_t *cmp) {
+ printf("init phase1\n");
+ return 0;
+}
+
+int phase1_start(phase1_cmp_t *cmp) {
+ printf("start phase1\n");
+ cmp->running = true;
+ celixThread_create(&cmp->thread, NULL, phase1_thread, cmp);
+ return 0;
+}
+
+int phase1_stop(phase1_cmp_t *cmp) {
+ printf("stop phase1\n");
+ cmp->running = false;
+ celixThread_kill(cmp->thread, SIGUSR1);
+ celixThread_join(cmp->thread, NULL);
+ return 0;
+}
+
+int phase1_deinit(phase1_cmp_t *cmp) {
+ printf("deinit phase1\n");
+ return 0;
+}
+
+void phase1_destroy(phase1_cmp_t *cmp) {
+ free(cmp);
+ printf("destroy phase1\n");
+}
+
+static void *phase1_thread(void *data) {
+ phase1_cmp_t *cmp = data;
+
+ while (cmp->running) {
+ cmp->counter += 1;
++ if (cmp->counter == 2) {
++ static char *runtime_interface = "DUMMY INTERFACE: DO NOT USE\n";
++ component_addInterface(cmp->component, "RUNTIME_ADDED_INTERFACE", "1.0.0", runtime_interface, NULL);
++ }
+ usleep(SLEEPTIME);
+ }
+
+ celixThread_exit(NULL);
+ return NULL;
+}
+
+int phase1_getData(phase1_cmp_t *cmp, unsigned int *data) {
+ *data = cmp->counter;
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/examples/dm_example/phase1/src/phase1_cmp.h
----------------------------------------------------------------------
diff --cc examples/dm_example/phase1/src/phase1_cmp.h
index 5715f6e,0000000..153eed1
mode 100644,000000..100644
--- a/examples/dm_example/phase1/src/phase1_cmp.h
+++ b/examples/dm_example/phase1/src/phase1_cmp.h
@@@ -1,43 -1,0 +1,44 @@@
+/**
+ *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.
+ */
+/*
+ * publisher.h
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PHASE1_CMP_H
+#define PHASE1_CMP_H
-
++#include "dm_component.h"
+
+typedef struct phase1_cmp_struct phase1_cmp_t;
+
+phase1_cmp_t *phase1_create(void);
++void phase1_setComp(phase1_cmp_t *cmp, dm_component_pt dmCmp);
+int phase1_init(phase1_cmp_t *cmp);
+int phase1_start(phase1_cmp_t *cmp);
+int phase1_stop(phase1_cmp_t *cmp);
+int phase1_deinit(phase1_cmp_t *cmp);
+void phase1_destroy(phase1_cmp_t *cmp);
+
+int phase1_getData(phase1_cmp_t *cmp, unsigned int *data);
+
+
+#endif //PHASE1_CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/examples/dm_example_cxx/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/dm_example_cxx/CMakeLists.txt
index 9ef4c1e,b07f5cc..3f37373
--- a/examples/dm_example_cxx/CMakeLists.txt
+++ b/examples/dm_example_cxx/CMakeLists.txt
@@@ -24,45 -31,44 +24,45 @@@ if (BUILD_DEPENDENCY_MANAGER_CXX
add_subdirectory(phase3_locking)
-- add_deploy("dm_example_cxx"
++ add_celix_container("dm_example_cxx"
COPY
- CXX
+ CXX
BUNDLES
- shell
- shell_tui
- dm_shell
- log_service
- log_writer
+ Celix::shell
+ Celix::shell_tui
+ Celix::dm_shell
+ Celix::log_service
+ Celix::log_writer_stdout
- phase1_cxx
- phase2a_cxx
- phase2b_cxx
- phase3_cxx
- phase3_locking_cxx
+ dm_example_cxx_phase1
+ dm_example_cxx_phase2a
+ dm_example_cxx_phase2b
+ dm_example_cxx_phase3
+ dm_example_cxx_phase3_locking
PROPERTIES
LOGHELPER_ENABLE_STDOUT_FALLBACK=true
)
- if (ENABLE_DOCKER)
- add_celix_docker(dm_exmpl_cxx
- GROUP examples
- BUNDLES_DIR /usr/share/bundles
- WORKDIR /workspace
- BUNDLES
- Celix::shell
- Celix::shell_tui
- Celix::dm_shell
- Celix::log_service
- Celix::log_writer_stdout
- add_celix_docker(dm_exmpl_cxx
- CXX
- GROUP examples
- BUNDLES_DIR /usr/share/bundles
- WORKDIR /workspace
- BUNDLES
- shell
- shell_tui
- dm_shell
- log_service
- log_writer
- dm_example_cxx_phase1
- dm_example_cxx_phase2a
- dm_example_cxx_phase2b
- dm_example_cxx_phase3
- dm_example_cxx_phase3_locking
- PROPERTIES
- LOGHELPER_ENABLE_STDOUT_FALLBACK=true
- )
- endif ()
- phase1_cxx
- phase2a_cxx
- phase2b_cxx
- phase3_cxx
- phase3_locking_cxx
- PROPERTIES
- LOGHELPER_ENABLE_STDOUT_FALLBACK=true
- )
++ add_celix_docker(dm_exmpl_cxx_docker
++ IMAGE_NAME dm_exmpl_cxx
++ GROUP examples
++ BUNDLES_DIR /usr/share/bundles
++ WORKDIR /workspace
++ BUNDLES
++ Celix::shell
++ Celix::shell_tui
++ Celix::dm_shell
++ Celix::log_service
++ Celix::log_writer_stdout
++
++ dm_example_cxx_phase1
++ dm_example_cxx_phase2a
++ dm_example_cxx_phase2b
++ dm_example_cxx_phase3
++ dm_example_cxx_phase3_locking
++ PROPERTIES
++ LOGHELPER_ENABLE_STDOUT_FALLBACK=true
++ )
endif ()
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/examples/log_service_example/CMakeLists.txt
----------------------------------------------------------------------
diff --cc examples/log_service_example/CMakeLists.txt
index 0363da3,6b7e681..1326a0f
--- a/examples/log_service_example/CMakeLists.txt
+++ b/examples/log_service_example/CMakeLists.txt
@@@ -27,5 -30,7 +27,5 @@@ target_link_libraries(log_service_examp
add_deploy(log_example
GROUP log_service
- BUNDLES log_service_example log_service shell shell_tui
+ BUNDLES log_service_example Celix::log_service Celix::shell Celix::shell_tui
- )
+ )
-
-target_link_libraries(log_service_example celix_framework celix_utils)
http://git-wip-us.apache.org/repos/asf/celix/blob/ac0d0d77/framework/include/celix_launcher.h
----------------------------------------------------------------------
diff --cc framework/include/celix_launcher.h
index 0d819c9,0000000..5c7cf4d
mode 100644,000000..100644
--- a/framework/include/celix_launcher.h
+++ b/framework/include/celix_launcher.h
@@@ -1,55 -1,0 +1,57 @@@
+/**
+ *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_launcher.h
+ *
+ * \date Jul 30, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef CELIX_LAUNCHER_H
+#define CELIX_LAUNCHER_H
+
+#include <stdio.h>
+#include "framework.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int celixLauncher_launchWithArgs(int argc, char *argv[]);
+
++int celixLauncher_launchWithArgsAndProps(int argc, char *argv[], properties_pt config);
++
+int celixLauncher_launch(const char *configFile, framework_pt *framework);
+
+int celixLauncher_launchWithStream(FILE *config, framework_pt *framework);
+
+int celixLauncher_launchWithProperties(properties_pt config, framework_pt *framework);
+
+void celixLauncher_stop(framework_pt framework);
+
+void celixLauncher_destroy(framework_pt framework);
+
+void celixLauncher_waitForShutdown(framework_pt framework);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //CELIX_LAUNCHER_H
[24/54] [abbrv] celix git commit: CELIX-417: Refactors CMake usage
for the RSA bundles
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/civetweb/src/md5.inl
----------------------------------------------------------------------
diff --git a/remote_services/civetweb/src/md5.inl b/remote_services/civetweb/src/md5.inl
new file mode 100644
index 0000000..4da933d
--- /dev/null
+++ b/remote_services/civetweb/src/md5.inl
@@ -0,0 +1,461 @@
+/*
+ * This an amalgamation of md5.c and md5.h into a single file
+ * with all static declaration to reduce linker conflicts
+ * in Civetweb.
+ *
+ * The MD5_STATIC declaration was added to facilitate static
+ * inclusion.
+ * No Face Press, LLC
+ */
+
+/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
+/*
+ Independent implementation of MD5 (RFC 1321).
+
+ This code implements the MD5 Algorithm defined in RFC 1321, whose
+ text is available at
+ http://www.ietf.org/rfc/rfc1321.txt
+ The code is derived from the text of the RFC, including the test suite
+ (section A.5) but excluding the rest of Appendix A. It does not include
+ any code or documentation that is identified in the RFC as being
+ copyrighted.
+
+ The original and principal author of md5.h is L. Peter Deutsch
+ <gh...@aladdin.com>. Other authors are noted in the change history
+ that follows (in reverse chronological order):
+
+ 2002-04-13 lpd Removed support for non-ANSI compilers; removed
+ references to Ghostscript; clarified derivation from RFC 1321;
+ now handles byte order either statically or dynamically.
+ 1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
+ 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
+ added conditionalization for C++ compilation from Martin
+ Purschke <pu...@bnl.gov>.
+ 1999-05-03 lpd Original version.
+ */
+
+#ifndef md5_INCLUDED
+# define md5_INCLUDED
+
+/*
+ * This package supports both compile-time and run-time determination of CPU
+ * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
+ * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
+ * defined as non-zero, the code will be compiled to run only on big-endian
+ * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
+ * run on either big- or little-endian CPUs, but will run slightly less
+ * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
+ */
+
+typedef unsigned char md5_byte_t; /* 8-bit byte */
+typedef unsigned int md5_word_t; /* 32-bit word */
+
+/* Define the state of the MD5 Algorithm. */
+typedef struct md5_state_s {
+ md5_word_t count[2]; /* message length in bits, lsw first */
+ md5_word_t abcd[4]; /* digest buffer */
+ md5_byte_t buf[64]; /* accumulate block */
+} md5_state_t;
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* Initialize the algorithm. */
+MD5_STATIC void md5_init(md5_state_t *pms);
+
+/* Append a string to the message. */
+MD5_STATIC void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);
+
+/* Finish the message and return the digest. */
+MD5_STATIC void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
+
+#ifdef __cplusplus
+} /* end extern "C" */
+#endif
+
+#endif /* md5_INCLUDED */
+
+/*
+ Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved.
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ L. Peter Deutsch
+ ghost@aladdin.com
+
+ */
+/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */
+/*
+ Independent implementation of MD5 (RFC 1321).
+
+ This code implements the MD5 Algorithm defined in RFC 1321, whose
+ text is available at
+ http://www.ietf.org/rfc/rfc1321.txt
+ The code is derived from the text of the RFC, including the test suite
+ (section A.5) but excluding the rest of Appendix A. It does not include
+ any code or documentation that is identified in the RFC as being
+ copyrighted.
+
+ The original and principal author of md5.c is L. Peter Deutsch
+ <gh...@aladdin.com>. Other authors are noted in the change history
+ that follows (in reverse chronological order):
+
+ 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order
+ either statically or dynamically; added missing #include <string.h>
+ in library.
+ 2002-03-11 lpd Corrected argument list for main(), and added int return
+ type, in test program and T value program.
+ 2002-02-21 lpd Added missing #include <stdio.h> in test program.
+ 2000-07-03 lpd Patched to eliminate warnings about "constant is
+ unsigned in ANSI C, signed in traditional"; made test program
+ self-checking.
+ 1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
+ 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
+ 1999-05-03 lpd Original version.
+ */
+
+#ifndef MD5_STATIC
+#include <string.h>
+#endif
+
+#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
+#ifdef ARCH_IS_BIG_ENDIAN
+# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
+#else
+# define BYTE_ORDER 0
+#endif
+
+#define T_MASK ((md5_word_t)~0)
+#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87)
+#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9)
+#define T3 0x242070db
+#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111)
+#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050)
+#define T6 0x4787c62a
+#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec)
+#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe)
+#define T9 0x698098d8
+#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850)
+#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e)
+#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841)
+#define T13 0x6b901122
+#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c)
+#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71)
+#define T16 0x49b40821
+#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d)
+#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf)
+#define T19 0x265e5a51
+#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855)
+#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2)
+#define T22 0x02441453
+#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e)
+#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437)
+#define T25 0x21e1cde6
+#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829)
+#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278)
+#define T28 0x455a14ed
+#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa)
+#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07)
+#define T31 0x676f02d9
+#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375)
+#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd)
+#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e)
+#define T35 0x6d9d6122
+#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3)
+#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb)
+#define T38 0x4bdecfa9
+#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f)
+#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f)
+#define T41 0x289b7ec6
+#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805)
+#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a)
+#define T44 0x04881d05
+#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6)
+#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a)
+#define T47 0x1fa27cf8
+#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a)
+#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb)
+#define T50 0x432aff97
+#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58)
+#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6)
+#define T53 0x655b59c3
+#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d)
+#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82)
+#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e)
+#define T57 0x6fa87e4f
+#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f)
+#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb)
+#define T60 0x4e0811a1
+#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d)
+#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca)
+#define T63 0x2ad7d2bb
+#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e)
+
+
+static void
+md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
+{
+ md5_word_t
+ a = pms->abcd[0], b = pms->abcd[1],
+ c = pms->abcd[2], d = pms->abcd[3];
+ md5_word_t t;
+#if BYTE_ORDER > 0
+ /* Define storage only for big-endian CPUs. */
+ md5_word_t X[16];
+#else
+ /* Define storage for little-endian or both types of CPUs. */
+ md5_word_t xbuf[16];
+ const md5_word_t *X;
+#endif
+
+ {
+#if BYTE_ORDER == 0
+ /*
+ * Determine dynamically whether this is a big-endian or
+ * little-endian machine, since we can use a more efficient
+ * algorithm on the latter.
+ */
+ static const int w = 1;
+
+ if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
+#endif
+#if BYTE_ORDER <= 0 /* little-endian */
+ {
+ /*
+ * On little-endian machines, we can process properly aligned
+ * data without copying it.
+ */
+ if (!((data - (const md5_byte_t *)0) & 3)) {
+ /* data are properly aligned */
+ X = (const md5_word_t *)data;
+ } else {
+ /* not aligned */
+ memcpy(xbuf, data, 64);
+ X = xbuf;
+ }
+ }
+#endif
+#if BYTE_ORDER == 0
+ else /* dynamic big-endian */
+#endif
+#if BYTE_ORDER >= 0 /* big-endian */
+ {
+ /*
+ * On big-endian machines, we must arrange the bytes in the
+ * right order.
+ */
+ const md5_byte_t *xp = data;
+ int i;
+
+# if BYTE_ORDER == 0
+ X = xbuf; /* (dynamic only) */
+# else
+# define xbuf X /* (static only) */
+# endif
+ for (i = 0; i < 16; ++i, xp += 4)
+ xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
+ }
+#endif
+ }
+
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
+
+ /* Round 1. */
+ /* Let [abcd k s i] denote the operation
+ a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
+#define F(x, y, z) (((x) & (y)) | (~(x) & (z)))
+#define SET(a, b, c, d, k, s, Ti)\
+ t = a + F(b,c,d) + X[k] + Ti;\
+ a = ROTATE_LEFT(t, s) + b
+ /* Do the following 16 operations. */
+ SET(a, b, c, d, 0, 7, T1);
+ SET(d, a, b, c, 1, 12, T2);
+ SET(c, d, a, b, 2, 17, T3);
+ SET(b, c, d, a, 3, 22, T4);
+ SET(a, b, c, d, 4, 7, T5);
+ SET(d, a, b, c, 5, 12, T6);
+ SET(c, d, a, b, 6, 17, T7);
+ SET(b, c, d, a, 7, 22, T8);
+ SET(a, b, c, d, 8, 7, T9);
+ SET(d, a, b, c, 9, 12, T10);
+ SET(c, d, a, b, 10, 17, T11);
+ SET(b, c, d, a, 11, 22, T12);
+ SET(a, b, c, d, 12, 7, T13);
+ SET(d, a, b, c, 13, 12, T14);
+ SET(c, d, a, b, 14, 17, T15);
+ SET(b, c, d, a, 15, 22, T16);
+#undef SET
+
+ /* Round 2. */
+ /* Let [abcd k s i] denote the operation
+ a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
+#define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
+#define SET(a, b, c, d, k, s, Ti)\
+ t = a + G(b,c,d) + X[k] + Ti;\
+ a = ROTATE_LEFT(t, s) + b
+ /* Do the following 16 operations. */
+ SET(a, b, c, d, 1, 5, T17);
+ SET(d, a, b, c, 6, 9, T18);
+ SET(c, d, a, b, 11, 14, T19);
+ SET(b, c, d, a, 0, 20, T20);
+ SET(a, b, c, d, 5, 5, T21);
+ SET(d, a, b, c, 10, 9, T22);
+ SET(c, d, a, b, 15, 14, T23);
+ SET(b, c, d, a, 4, 20, T24);
+ SET(a, b, c, d, 9, 5, T25);
+ SET(d, a, b, c, 14, 9, T26);
+ SET(c, d, a, b, 3, 14, T27);
+ SET(b, c, d, a, 8, 20, T28);
+ SET(a, b, c, d, 13, 5, T29);
+ SET(d, a, b, c, 2, 9, T30);
+ SET(c, d, a, b, 7, 14, T31);
+ SET(b, c, d, a, 12, 20, T32);
+#undef SET
+
+ /* Round 3. */
+ /* Let [abcd k s t] denote the operation
+ a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define SET(a, b, c, d, k, s, Ti)\
+ t = a + H(b,c,d) + X[k] + Ti;\
+ a = ROTATE_LEFT(t, s) + b
+ /* Do the following 16 operations. */
+ SET(a, b, c, d, 5, 4, T33);
+ SET(d, a, b, c, 8, 11, T34);
+ SET(c, d, a, b, 11, 16, T35);
+ SET(b, c, d, a, 14, 23, T36);
+ SET(a, b, c, d, 1, 4, T37);
+ SET(d, a, b, c, 4, 11, T38);
+ SET(c, d, a, b, 7, 16, T39);
+ SET(b, c, d, a, 10, 23, T40);
+ SET(a, b, c, d, 13, 4, T41);
+ SET(d, a, b, c, 0, 11, T42);
+ SET(c, d, a, b, 3, 16, T43);
+ SET(b, c, d, a, 6, 23, T44);
+ SET(a, b, c, d, 9, 4, T45);
+ SET(d, a, b, c, 12, 11, T46);
+ SET(c, d, a, b, 15, 16, T47);
+ SET(b, c, d, a, 2, 23, T48);
+#undef SET
+
+ /* Round 4. */
+ /* Let [abcd k s t] denote the operation
+ a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
+#define I(x, y, z) ((y) ^ ((x) | ~(z)))
+#define SET(a, b, c, d, k, s, Ti)\
+ t = a + I(b,c,d) + X[k] + Ti;\
+ a = ROTATE_LEFT(t, s) + b
+ /* Do the following 16 operations. */
+ SET(a, b, c, d, 0, 6, T49);
+ SET(d, a, b, c, 7, 10, T50);
+ SET(c, d, a, b, 14, 15, T51);
+ SET(b, c, d, a, 5, 21, T52);
+ SET(a, b, c, d, 12, 6, T53);
+ SET(d, a, b, c, 3, 10, T54);
+ SET(c, d, a, b, 10, 15, T55);
+ SET(b, c, d, a, 1, 21, T56);
+ SET(a, b, c, d, 8, 6, T57);
+ SET(d, a, b, c, 15, 10, T58);
+ SET(c, d, a, b, 6, 15, T59);
+ SET(b, c, d, a, 13, 21, T60);
+ SET(a, b, c, d, 4, 6, T61);
+ SET(d, a, b, c, 11, 10, T62);
+ SET(c, d, a, b, 2, 15, T63);
+ SET(b, c, d, a, 9, 21, T64);
+#undef SET
+
+ /* Then perform the following additions. (That is increment each
+ of the four registers by the value it had before this block
+ was started.) */
+ pms->abcd[0] += a;
+ pms->abcd[1] += b;
+ pms->abcd[2] += c;
+ pms->abcd[3] += d;
+}
+
+MD5_STATIC void
+md5_init(md5_state_t *pms)
+{
+ pms->count[0] = pms->count[1] = 0;
+ pms->abcd[0] = 0x67452301;
+ pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476;
+ pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301;
+ pms->abcd[3] = 0x10325476;
+}
+
+MD5_STATIC void
+md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
+{
+ const md5_byte_t *p = data;
+ int left = nbytes;
+ int offset = (pms->count[0] >> 3) & 63;
+ md5_word_t nbits = (md5_word_t)(nbytes << 3);
+
+ if (nbytes <= 0)
+ return;
+
+ /* Update the message length. */
+ pms->count[1] += nbytes >> 29;
+ pms->count[0] += nbits;
+ if (pms->count[0] < nbits)
+ pms->count[1]++;
+
+ /* Process an initial partial block. */
+ if (offset) {
+ int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
+
+ memcpy(pms->buf + offset, p, copy);
+ if (offset + copy < 64)
+ return;
+ p += copy;
+ left -= copy;
+ md5_process(pms, pms->buf);
+ }
+
+ /* Process full blocks. */
+ for (; left >= 64; p += 64, left -= 64)
+ md5_process(pms, p);
+
+ /* Process a final partial block. */
+ if (left)
+ memcpy(pms->buf, p, left);
+}
+
+MD5_STATIC void
+md5_finish(md5_state_t *pms, md5_byte_t digest[16])
+{
+ static const md5_byte_t pad[64] = {
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+ md5_byte_t data[8];
+ int i;
+
+ /* Save the length before padding. */
+ for (i = 0; i < 8; ++i)
+ data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
+ /* Pad to 56 bytes mod 64. */
+ md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
+ /* Append the length. */
+ md5_append(pms, data, 8);
+ for (i = 0; i < 16; ++i)
+ digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_common/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/CMakeLists.txt b/remote_services/discovery_common/CMakeLists.txt
index 9388c90..5b28b13 100644
--- a/remote_services/discovery_common/CMakeLists.txt
+++ b/remote_services/discovery_common/CMakeLists.txt
@@ -18,16 +18,22 @@
find_package(LibXml2 REQUIRED)
-add_library(discovery_common STATIC
+add_library(discovery_common OBJECT
src/discovery.c
src/discovery_activator.c
src/endpoint_descriptor_reader.c
src/endpoint_descriptor_writer.c
src/endpoint_discovery_poller.c
src/endpoint_discovery_server.c
- src/civetweb.c
)
-target_include_directories(discovery_common PUBLIC include)
-target_include_directories(discovery_common PRIVATE src ${LIBXML2_INCLUDE_DIR})
-target_link_libraries(discovery_common PRIVATE ${LIBXML2_LIBRARIES} Celix::framework)
-target_link_libraries(discovery_common PUBLIC Celix::log_helper Celix::remote_service_admin_api)
\ No newline at end of file
+target_include_directories(discovery_common PUBLIC
+ include src
+ $<TARGET_PROPERTY:Celix::framework,INTERFACE_INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::utils,INTERFACE_INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::log_helper,INTERFACE_INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::remote_service_admin_api,INTERFACE_INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::remote_service_admin_api,INTERFACE_INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:civetweb,INCLUDE_DIRECTORIES>
+ ${LIBXML2_INCLUDE_DIR})
+
+add_library(Celix::discovery_common ALIAS discovery_common)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_common/include/civetweb.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/include/civetweb.h b/remote_services/discovery_common/include/civetweb.h
deleted file mode 100644
index 61a8e98..0000000
--- a/remote_services/discovery_common/include/civetweb.h
+++ /dev/null
@@ -1,657 +0,0 @@
-/* Copyright (c) 2013-2014 the Civetweb developers
- * Copyright (c) 2004-2013 Sergey Lyubka
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef CIVETWEB_HEADER_INCLUDED
-#define CIVETWEB_HEADER_INCLUDED
-
-#ifndef CIVETWEB_VERSION
-#define CIVETWEB_VERSION "1.7"
-#endif
-
-#ifndef CIVETWEB_API
- #if defined(_WIN32)
- #if defined(CIVETWEB_DLL_EXPORTS)
- #define CIVETWEB_API __declspec(dllexport)
- #elif defined(CIVETWEB_DLL_IMPORTS)
- #define CIVETWEB_API __declspec(dllimport)
- #else
- #define CIVETWEB_API
- #endif
- #else
- #define CIVETWEB_API
- #endif
-#endif
-
-#include <stdio.h>
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-struct mg_context; /* Handle for the HTTP service itself */
-struct mg_connection; /* Handle for the individual connection */
-
-
-/* This structure contains information about the HTTP request. */
-struct mg_request_info {
- const char *request_method; /* "GET", "POST", etc */
- const char *uri; /* URL-decoded URI */
- const char *http_version; /* E.g. "1.0", "1.1" */
- const char *query_string; /* URL part after '?', not including '?', or
- NULL */
- const char *remote_user; /* Authenticated user, or NULL if no auth
- used */
- char remote_addr[48]; /* Client's IP address as a string. */
- long remote_ip; /* Client's IP address. Deprecated: use remote_addr instead */
-
- long long content_length; /* Length (in bytes) of the request body,
- can be -1 if no length was given. */
- int remote_port; /* Client's port */
- int is_ssl; /* 1 if SSL-ed, 0 if not */
- void *user_data; /* User data pointer passed to mg_start() */
- void *conn_data; /* Connection-specific user data */
-
- int num_headers; /* Number of HTTP headers */
- struct mg_header {
- const char *name; /* HTTP header name */
- const char *value; /* HTTP header value */
- } http_headers[64]; /* Maximum 64 headers */
-};
-
-
-/* This structure needs to be passed to mg_start(), to let civetweb know
- which callbacks to invoke. For a detailed description, see
- https://github.com/bel2125/civetweb/blob/master/docs/UserManual.md */
-struct mg_callbacks {
- /* Called when civetweb has received new HTTP request.
- If the callback returns one, it must process the request
- by sending valid HTTP headers and a body. Civetweb will not do
- any further processing. Otherwise it must return zero.
- Note that since V1.7 the "begin_request" function is called
- before an authorization check. If an authorization check is
- required, use a request_handler instead.
- Return value:
- 0: civetweb will process the request itself. In this case,
- the callback must not send any data to the client.
- 1: callback already processed the request. Civetweb will
- not send any data after the callback returned. */
- int (*begin_request)(struct mg_connection *);
-
- /* Called when civetweb has finished processing request. */
- void (*end_request)(const struct mg_connection *, int reply_status_code);
-
- /* Called when civetweb is about to log a message. If callback returns
- non-zero, civetweb does not log anything. */
- int (*log_message)(const struct mg_connection *, const char *message);
-
- /* Called when civetweb initializes SSL library.
- Parameters:
- user_data: parameter user_data passed when starting the server.
- Return value:
- 0: civetweb will set up the SSL certificate.
- 1: civetweb assumes the callback already set up the certificate.
- -1: initializing ssl fails. */
- int (*init_ssl)(void *ssl_context, void *user_data);
-
- /* Called when websocket request is received, before websocket handshake.
- Return value:
- 0: civetweb proceeds with websocket handshake.
- 1: connection is closed immediately. */
- int (*websocket_connect)(const struct mg_connection *);
-
- /* Called when websocket handshake is successfully completed, and
- connection is ready for data exchange. */
- void (*websocket_ready)(struct mg_connection *);
-
- /* Called when data frame has been received from the client.
- Parameters:
- bits: first byte of the websocket frame, see websocket RFC at
- http://tools.ietf.org/html/rfc6455, section 5.2
- data, data_len: payload, with mask (if any) already applied.
- Return value:
- 1: keep this websocket connection open.
- 0: close this websocket connection. */
- int (*websocket_data)(struct mg_connection *, int bits,
- char *data, size_t data_len);
-
- /* Called when civetweb is closing a connection. The per-context mutex is
- locked when this is invoked. This is primarily useful for noting when
- a websocket is closing and removing it from any application-maintained
- list of clients. */
- void (*connection_close)(struct mg_connection *);
-
- /* Called when civetweb tries to open a file. Used to intercept file open
- calls, and serve file data from memory instead.
- Parameters:
- path: Full path to the file to open.
- data_len: Placeholder for the file size, if file is served from
- memory.
- Return value:
- NULL: do not serve file from memory, proceed with normal file open.
- non-NULL: pointer to the file contents in memory. data_len must be
- initilized with the size of the memory block. */
- const char * (*open_file)(const struct mg_connection *,
- const char *path, size_t *data_len);
-
- /* Called when civetweb is about to serve Lua server page, if
- Lua support is enabled.
- Parameters:
- lua_context: "lua_State *" pointer. */
- void (*init_lua)(struct mg_connection *, void *lua_context);
-
- /* Called when civetweb has uploaded a file to a temporary directory as a
- result of mg_upload() call.
- Parameters:
- file_name: full path name to the uploaded file. */
- void (*upload)(struct mg_connection *, const char *file_name);
-
- /* Called when civetweb is about to send HTTP error to the client.
- Implementing this callback allows to create custom error pages.
- Parameters:
- status: HTTP error status code.
- Return value:
- 1: run civetweb error handler.
- 0: callback already handled the error. */
- int (*http_error)(struct mg_connection *, int status);
-
- /* Called after civetweb context has been created, before requests
- are processed.
- Parameters:
- ctx: context handle */
- void (*init_context)(struct mg_context * ctx);
-
- /* Called when civetweb context is deleted.
- Parameters:
- ctx: context handle */
- void (*exit_context)(struct mg_context * ctx);
-};
-
-
-/* Start web server.
-
- Parameters:
- callbacks: mg_callbacks structure with user-defined callbacks.
- options: NULL terminated list of option_name, option_value pairs that
- specify Civetweb configuration parameters.
-
- Side-effects: on UNIX, ignores SIGCHLD and SIGPIPE signals. If custom
- processing is required for these, signal handlers must be set up
- after calling mg_start().
-
-
- Example:
- const char *options[] = {
- "document_root", "/var/www",
- "listening_ports", "80,443s",
- NULL
- };
- struct mg_context *ctx = mg_start(&my_func, NULL, options);
-
- Refer to https://github.com/bel2125/civetweb/blob/master/docs/UserManual.md
- for the list of valid option and their possible values.
-
- Return:
- web server context, or NULL on error. */
-CIVETWEB_API struct mg_context *mg_start(const struct mg_callbacks *callbacks,
- void *user_data,
- const char **configuration_options);
-
-
-/* Stop the web server.
-
- Must be called last, when an application wants to stop the web server and
- release all associated resources. This function blocks until all Civetweb
- threads are stopped. Context pointer becomes invalid. */
-CIVETWEB_API void mg_stop(struct mg_context *);
-
-
-/* mg_request_handler
-
- Called when a new request comes in. This callback is URI based
- and configured with mg_set_request_handler().
-
- Parameters:
- conn: current connection information.
- cbdata: the callback data configured with mg_set_request_handler().
- Returns:
- 0: the handler could not handle the request, so fall through.
- 1: the handler processed the request. */
-typedef int (* mg_request_handler)(struct mg_connection *conn, void *cbdata);
-
-
-/* mg_set_request_handler
-
- Sets or removes a URI mapping for a request handler.
-
- URI's are ordered and prefixed URI's are supported. For example,
- consider two URIs: /a/b and /a
- /a matches /a
- /a/b matches /a/b
- /a/c matches /a
-
- Parameters:
- ctx: server context
- uri: the URI to configure
- handler: the callback handler to use when the URI is requested.
- If NULL, the URI will be removed.
- cbdata: the callback data to give to the handler when it s requested. */
-CIVETWEB_API void mg_set_request_handler(struct mg_context *ctx, const char *uri, mg_request_handler handler, void *cbdata);
-
-
-/* Get the value of particular configuration parameter.
- The value returned is read-only. Civetweb does not allow changing
- configuration at run time.
- If given parameter name is not valid, NULL is returned. For valid
- names, return value is guaranteed to be non-NULL. If parameter is not
- set, zero-length string is returned. */
-CIVETWEB_API const char *mg_get_option(const struct mg_context *ctx, const char *name);
-
-
-/* Get context from connection. */
-CIVETWEB_API struct mg_context *mg_get_context(struct mg_connection *conn);
-
-
-/* Get user data passed to mg_start from context. */
-CIVETWEB_API void *mg_get_user_data(struct mg_context *ctx);
-
-
-#if defined(MG_LEGACY_INTERFACE)
-/* Return array of strings that represent valid configuration options.
- For each option, option name and default value is returned, i.e. the
- number of entries in the array equals to number_of_options x 2.
- Array is NULL terminated. */
-/* Deprecated: Use mg_get_valid_options instead. */
-CIVETWEB_API const char **mg_get_valid_option_names(void);
-#endif
-
-
-struct mg_option {
- const char * name;
- int type;
- const char * default_value;
-};
-
-enum {
- CONFIG_TYPE_UNKNOWN = 0x0,
- CONFIG_TYPE_NUMBER = 0x1,
- CONFIG_TYPE_STRING = 0x2,
- CONFIG_TYPE_FILE = 0x3,
- CONFIG_TYPE_DIRECTORY = 0x4,
- CONFIG_TYPE_BOOLEAN = 0x5,
- CONFIG_TYPE_EXT_PATTERN = 0x6
-};
-
-
-/* Return array of struct mg_option, representing all valid configuration
- options of civetweb.c.
- The array is terminated by a NULL name option. */
-CIVETWEB_API const struct mg_option *mg_get_valid_options(void);
-
-
-/* Get the list of ports that civetweb is listening on.
- size is the size of the ports int array and ssl int array to fill.
- It is the caller's responsibility to make sure ports and ssl each
- contain at least size int elements worth of memory to write into.
- Return value is the number of ports and ssl information filled in.
- The value returned is read-only. Civetweb does not allow changing
- configuration at run time. */
-CIVETWEB_API size_t mg_get_ports(const struct mg_context *ctx, size_t size, int* ports, int* ssl);
-
-
-/* Add, edit or delete the entry in the passwords file.
-
- This function allows an application to manipulate .htpasswd files on the
- fly by adding, deleting and changing user records. This is one of the
- several ways of implementing authentication on the server side. For another,
- cookie-based way please refer to the examples/chat in the source tree.
-
- If password is not NULL, entry is added (or modified if already exists).
- If password is NULL, entry is deleted.
-
- Return:
- 1 on success, 0 on error. */
-CIVETWEB_API int mg_modify_passwords_file(const char *passwords_file_name,
- const char *domain,
- const char *user,
- const char *password);
-
-
-/* Return information associated with the request. */
-CIVETWEB_API struct mg_request_info *mg_get_request_info(struct mg_connection *);
-
-
-/* Send data to the client.
- Return:
- 0 when the connection has been closed
- -1 on error
- >0 number of bytes written on success */
-CIVETWEB_API int mg_write(struct mg_connection *, const void *buf, size_t len);
-
-
-/* Send data to a websocket client wrapped in a websocket frame. Uses mg_lock
- to ensure that the transmission is not interrupted, i.e., when the
- application is proactively communicating and responding to a request
- simultaneously.
-
- Send data to a websocket client wrapped in a websocket frame.
- This function is available when civetweb is compiled with -DUSE_WEBSOCKET
-
- Return:
- 0 when the connection has been closed
- -1 on error
- >0 number of bytes written on success */
-CIVETWEB_API int mg_websocket_write(struct mg_connection* conn, int opcode,
- const char *data, size_t data_len);
-
-
-/* Blocks until unique access is obtained to this connection. Intended for use
- with websockets only.
- Invoke this before mg_write or mg_printf when communicating with a
- websocket if your code has server-initiated communication as well as
- communication in direct response to a message. */
-CIVETWEB_API void mg_lock_connection(struct mg_connection* conn);
-CIVETWEB_API void mg_unlock_connection(struct mg_connection* conn);
-
-#if defined(MG_LEGACY_INTERFACE)
-#define mg_lock mg_lock_connection
-#define mg_unlock mg_unlock_connection
-#endif
-
-/* Lock server context. This lock may be used to protect ressources
- that are shared between different connection/worker threads. */
-CIVETWEB_API void mg_lock_context(struct mg_context* ctx);
-CIVETWEB_API void mg_unlock_context(struct mg_context* ctx);
-
-
-/* Opcodes, from http://tools.ietf.org/html/rfc6455 */
-enum {
- WEBSOCKET_OPCODE_CONTINUATION = 0x0,
- WEBSOCKET_OPCODE_TEXT = 0x1,
- WEBSOCKET_OPCODE_BINARY = 0x2,
- WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
- WEBSOCKET_OPCODE_PING = 0x9,
- WEBSOCKET_OPCODE_PONG = 0xa
-};
-
-
-/* Macros for enabling compiler-specific checks forprintf-like arguments. */
-#undef PRINTF_FORMAT_STRING
-#if defined(_MSC_VER) && _MSC_VER >= 1400
-#include <sal.h>
-#if defined(_MSC_VER) && _MSC_VER > 1400
-#define PRINTF_FORMAT_STRING(s) _Printf_format_string_ s
-#else
-#define PRINTF_FORMAT_STRING(s) __format_string s
-#endif
-#else
-#define PRINTF_FORMAT_STRING(s) s
-#endif
-
-#ifdef __GNUC__
-#define PRINTF_ARGS(x, y) __attribute__((format(printf, x, y)))
-#else
-#define PRINTF_ARGS(x, y)
-#endif
-
-/* Send data to the client usingprintf() semantics.
- Works exactly like mg_write(), but allows to do message formatting. */
-CIVETWEB_API int mg_printf(struct mg_connection *,
- PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(2, 3);
-
-
-/* Send contents of the entire file together with HTTP headers. */
-CIVETWEB_API void mg_send_file(struct mg_connection *conn, const char *path);
-
-
-/* Read data from the remote end, return number of bytes read.
- Return:
- 0 connection has been closed by peer. No more data could be read.
- < 0 read error. No more data could be read from the connection.
- > 0 number of bytes read into the buffer. */
-CIVETWEB_API int mg_read(struct mg_connection *, void *buf, size_t len);
-
-
-/* Get the value of particular HTTP header.
-
- This is a helper function. It traverses request_info->http_headers array,
- and if the header is present in the array, returns its value. If it is
- not present, NULL is returned. */
-CIVETWEB_API const char *mg_get_header(const struct mg_connection *, const char *name);
-
-
-/* Get a value of particular form variable.
-
- Parameters:
- data: pointer to form-uri-encoded buffer. This could be either POST data,
- or request_info.query_string.
- data_len: length of the encoded data.
- var_name: variable name to decode from the buffer
- dst: destination buffer for the decoded variable
- dst_len: length of the destination buffer
-
- Return:
- On success, length of the decoded variable.
- On error:
- -1 (variable not found).
- -2 (destination buffer is NULL, zero length or too small to hold the
- decoded variable).
-
- Destination buffer is guaranteed to be '\0' - terminated if it is not
- NULL or zero length. */
-CIVETWEB_API int mg_get_var(const char *data, size_t data_len,
- const char *var_name, char *dst, size_t dst_len);
-
-
-/* Get a value of particular form variable.
-
- Parameters:
- data: pointer to form-uri-encoded buffer. This could be either POST data,
- or request_info.query_string.
- data_len: length of the encoded data.
- var_name: variable name to decode from the buffer
- dst: destination buffer for the decoded variable
- dst_len: length of the destination buffer
- occurrence: which occurrence of the variable, 0 is the first, 1 the
- second...
- this makes it possible to parse a query like
- b=x&a=y&a=z which will have occurrence values b:0, a:0 and a:1
-
- Return:
- On success, length of the decoded variable.
- On error:
- -1 (variable not found).
- -2 (destination buffer is NULL, zero length or too small to hold the
- decoded variable).
-
- Destination buffer is guaranteed to be '\0' - terminated if it is not
- NULL or zero length. */
-CIVETWEB_API int mg_get_var2(const char *data, size_t data_len,
- const char *var_name, char *dst, size_t dst_len, size_t occurrence);
-
-
-/* Fetch value of certain cookie variable into the destination buffer.
-
- Destination buffer is guaranteed to be '\0' - terminated. In case of
- failure, dst[0] == '\0'. Note that RFC allows many occurrences of the same
- parameter. This function returns only first occurrence.
-
- Return:
- On success, value length.
- On error:
- -1 (either "Cookie:" header is not present at all or the requested
- parameter is not found).
- -2 (destination buffer is NULL, zero length or too small to hold the
- value). */
-CIVETWEB_API int mg_get_cookie(const char *cookie, const char *var_name,
- char *buf, size_t buf_len);
-
-
-/* Download data from the remote web server.
- host: host name to connect to, e.g. "foo.com", or "10.12.40.1".
- port: port number, e.g. 80.
- use_ssl: wether to use SSL connection.
- error_buffer, error_buffer_size: error message placeholder.
- request_fmt,...: HTTP request.
- Return:
- On success, valid pointer to the new connection, suitable for mg_read().
- On error, NULL. error_buffer contains error message.
- Example:
- char ebuf[100];
- struct mg_connection *conn;
- conn = mg_download("google.com", 80, 0, ebuf, sizeof(ebuf),
- "%s", "GET / HTTP/1.0\r\nHost: google.com\r\n\r\n");
- */
-CIVETWEB_API struct mg_connection *mg_download(const char *host, int port, int use_ssl,
- char *error_buffer, size_t error_buffer_size,
- PRINTF_FORMAT_STRING(const char *request_fmt),
- ...) PRINTF_ARGS(6, 7);
-
-
-/* Close the connection opened by mg_download(). */
-CIVETWEB_API void mg_close_connection(struct mg_connection *conn);
-
-
-/* File upload functionality. Each uploaded file gets saved into a temporary
- file and MG_UPLOAD event is sent.
- Return number of uploaded files. */
-CIVETWEB_API int mg_upload(struct mg_connection *conn, const char *destination_dir);
-
-
-/* Convenience function -- create detached thread.
- Return: 0 on success, non-0 on error. */
-typedef void * (*mg_thread_func_t)(void *);
-CIVETWEB_API int mg_start_thread(mg_thread_func_t f, void *p);
-
-
-/* Return builtin mime type for the given file name.
- For unrecognized extensions, "text/plain" is returned. */
-CIVETWEB_API const char *mg_get_builtin_mime_type(const char *file_name);
-
-
-/* Return Civetweb version. */
-CIVETWEB_API const char *mg_version(void);
-
-
-/* URL-decode input buffer into destination buffer.
- 0-terminate the destination buffer.
- form-url-encoded data differs from URI encoding in a way that it
- uses '+' as character for space, see RFC 1866 section 8.2.1
- http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
- Return: length of the decoded data, or -1 if dst buffer is too small. */
-CIVETWEB_API int mg_url_decode(const char *src, int src_len, char *dst,
- int dst_len, int is_form_url_encoded);
-
-
-/* URL-encode input buffer into destination buffer.
- returns the length of the resulting buffer or -1
- is the buffer is too small. */
-CIVETWEB_API int mg_url_encode(const char *src, char *dst, size_t dst_len);
-
-
-/* MD5 hash given strings.
- Buffer 'buf' must be 33 bytes long. Varargs is a NULL terminated list of
- ASCIIz strings. When function returns, buf will contain human-readable
- MD5 hash. Example:
- char buf[33];
- mg_md5(buf, "aa", "bb", NULL); */
-CIVETWEB_API char *mg_md5(char buf[33], ...);
-
-
-/* Print error message to the opened error log stream.
- This utilizes the provided logging configuration.
- conn: connection
- fmt: format string without the line return
- ...: variable argument list
- Example:
- mg_cry(conn,"i like %s", "logging"); */
-CIVETWEB_API void mg_cry(struct mg_connection *conn,
- PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(2, 3);
-
-
-/* utility method to compare two buffers, case incensitive. */
-CIVETWEB_API int mg_strncasecmp(const char *s1, const char *s2, size_t len);
-
-/* Connect to a websocket as a client
- Parameters:
- host: host to connect to, i.e. "echo.websocket.org" or "192.168.1.1" or "localhost"
- port: server port
- use_ssl: make a secure connection to server
- error_buffer, error_buffer_size: buffer for an error message
- path: server path you are trying to connect to, i.e. if connection to localhost/app, path should be "/app"
- origin: value of the Origin HTTP header
- data_func: callback that should be used when data is received from the server
- user_data: user supplied argument
-
- Return:
- On success, valid mg_connection object.
- On error, NULL. Se error_buffer for details.
-*/
-
-typedef int (*websocket_data_func)(struct mg_connection *, int bits,
- char *data, size_t data_len);
-
-typedef void (*websocket_close_func)(struct mg_connection *);
-
-CIVETWEB_API struct mg_connection *mg_connect_websocket_client(const char *host, int port, int use_ssl,
- char *error_buffer, size_t error_buffer_size,
- const char *path, const char *origin,
- websocket_data_func data_func, websocket_close_func close_func,
- void * user_data);
-
-/* Connect to a TCP server as a client (can be used to connect to a HTTP server)
- Parameters:
- host: host to connect to, i.e. "www.wikipedia.org" or "192.168.1.1" or "localhost"
- port: server port
- use_ssl: make a secure connection to server
- error_buffer, error_buffer_size: buffer for an error message
-
- Return:
- On success, valid mg_connection object.
- On error, NULL. Se error_buffer for details.
-*/
-CIVETWEB_API struct mg_connection *mg_connect_client(const char *host, int port, int use_ssl,
- char *error_buffer, size_t error_buffer_size);
-
-
-enum {
- TIMEOUT_INFINITE = -1
-};
-
-/* Wait for a response from the server
- Parameters:
- conn: connection
- ebuf, ebuf_len: error message placeholder.
- timeout: time to wait for a response in milliseconds (if < 0 then wait forever)
-
- Return:
- On success, >= 0
- On error/timeout, < 0
-*/
-CIVETWEB_API int mg_get_response(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int timeout);
-
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* CIVETWEB_HEADER_INCLUDED */
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_common/include/discovery.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/include/discovery.h b/remote_services/discovery_common/include/discovery.h
index ee79caf..ede3d5e 100644
--- a/remote_services/discovery_common/include/discovery.h
+++ b/remote_services/discovery_common/include/discovery.h
@@ -27,12 +27,18 @@
#ifndef DISCOVERY_H_
#define DISCOVERY_H_
+#include "discovery_type.h"
#include "bundle_context.h"
#include "service_reference.h"
#include "endpoint_description.h"
#include "endpoint_listener.h"
+#include "endpoint_discovery_server.h"
+#include "endpoint_discovery_poller.h"
+
+#include "log_helper.h"
+
#define DISCOVERY_SERVER_INTERFACE "DISCOVERY_CFG_SERVER_INTERFACE"
#define DISCOVERY_SERVER_IP "DISCOVERY_CFG_SERVER_IP"
#define DISCOVERY_SERVER_PORT "DISCOVERY_CFG_SERVER_PORT"
@@ -40,7 +46,22 @@
#define DISCOVERY_POLL_ENDPOINTS "DISCOVERY_CFG_POLL_ENDPOINTS"
#define DISCOVERY_SERVER_MAX_EP "DISCOVERY_CFG_SERVER_MAX_EP"
-typedef struct discovery *discovery_pt;
+struct discovery {
+ bundle_context_t* context;
+
+ celix_thread_mutex_t listenerReferencesMutex;
+ celix_thread_mutex_t discoveredServicesMutex;
+
+ hash_map_t* listenerReferences; //key=serviceReference, value=nop
+ hash_map_t* discoveredServices; //key=endpointId (string), value=endpoint_description_pt
+
+ endpoint_discovery_poller_t* poller;
+ endpoint_discovery_server_t* server;
+
+ log_helper_t* loghelper;
+
+ discovery_impl_t* pImpl;
+};
/* those one could be put into a general discovery.h - file */
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_common/include/discovery_type.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/include/discovery_type.h b/remote_services/discovery_common/include/discovery_type.h
new file mode 100644
index 0000000..222a495
--- /dev/null
+++ b/remote_services/discovery_common/include/discovery_type.h
@@ -0,0 +1,27 @@
+/**
+ *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.
+ */
+
+#ifndef DISCOVERY_TYPE_H_
+#define DISCOVERY_TYPE_H_
+
+typedef struct discovery discovery_t;
+typedef struct discovery* discovery_pt;
+typedef struct discovery_impl discovery_impl_t;
+
+#endif //DISCOVERY_TYPE_H_
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_common/include/endpoint_discovery_poller.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/include/endpoint_discovery_poller.h b/remote_services/discovery_common/include/endpoint_discovery_poller.h
index d344e55..3c537f1 100644
--- a/remote_services/discovery_common/include/endpoint_discovery_poller.h
+++ b/remote_services/discovery_common/include/endpoint_discovery_poller.h
@@ -28,9 +28,12 @@
#define ENDPOINT_DISCOVERY_POLLER_H_
#include "celix_errno.h"
-#include "discovery.h"
+#include "discovery_type.h"
#include "log_helper.h"
+typedef struct endpoint_discovery_poller endpoint_discovery_poller_t;
+typedef struct endpoint_discovery_poller *endpoint_discovery_poller_pt;
+
struct endpoint_discovery_poller {
discovery_pt discovery;
hash_map_pt entries;
@@ -43,9 +46,7 @@ struct endpoint_discovery_poller {
volatile bool running;
};
-typedef struct endpoint_discovery_poller *endpoint_discovery_poller_pt;
-
-celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_poller_pt *poller);
+celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_context_pt context, const char* defaultPollEndpoints, endpoint_discovery_poller_pt *poller);
celix_status_t endpointDiscoveryPoller_destroy(endpoint_discovery_poller_pt poller);
celix_status_t endpointDiscoveryPoller_addDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url);
http://git-wip-us.apache.org/repos/asf/celix/blob/27a2aa75/remote_services/discovery_common/include/endpoint_discovery_server.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/include/endpoint_discovery_server.h b/remote_services/discovery_common/include/endpoint_discovery_server.h
index 51082b5..d70c145 100644
--- a/remote_services/discovery_common/include/endpoint_discovery_server.h
+++ b/remote_services/discovery_common/include/endpoint_discovery_server.h
@@ -28,8 +28,9 @@
#define ENDPOINT_DISCOVERY_SERVER_H_
#include "celix_errno.h"
-#include "discovery.h"
+#include "discovery_type.h"
+typedef struct endpoint_discovery_server endpoint_discovery_server_t;
typedef struct endpoint_discovery_server *endpoint_discovery_server_pt;
/**
@@ -40,7 +41,13 @@ typedef struct endpoint_discovery_server *endpoint_discovery_server_pt;
* @param server [out] the pointer to the created instance.
* @return CELIX_SUCCESS when successful.
*/
-celix_status_t endpointDiscoveryServer_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_server_pt *server);
+celix_status_t endpointDiscoveryServer_create(
+ discovery_pt discovery,
+ bundle_context_pt context,
+ const char* defaultServerPath,
+ const char* defaultServerPort,
+ const char* defaultServerIp,
+ endpoint_discovery_server_pt *server);
/**
* Stops and destroys a given instance of an endpoint discovery server.
[51/54] [abbrv] celix git commit: Adds Debug build type option to
travis config to ensure the current -O optimilization for testing
Posted by pn...@apache.org.
Adds Debug build type option to travis config to ensure the current -O optimilization for testing
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/326f2759
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/326f2759
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/326f2759
Branch: refs/heads/develop
Commit: 326f27594c8d36a72f6fd0cb81c76c7da3ce382d
Parents: 49d0e35
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Jan 30 15:58:43 2018 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Jan 30 15:58:43 2018 +0100
----------------------------------------------------------------------
.travis.yml | 4 ++--
framework/src/service_registration.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/326f2759/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index 279e548..5af8c60 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -101,8 +101,8 @@ script:
# RSA_SHM is only working on linux, but both compilers (see CELIX-277)
- cd build
- if [ "$CC" = "gcc" ] && [ "$TRAVIS_OS_NAME" = "linux" ]; then export BUILD_OPTS="${BUILD_OPTS} -DENABLE_CODE_COVERAGE=ON"; fi
- - if [ "$TRAVIS_OS_NAME" = "linux" ] && [ -z "$ANDROID" ]; then cmake ${BUILD_OPTIONS} ${BUILD_OPTIONS_LINUX} -DBUILD_FRAMEWORK_TESTS=ON -DBUILD_UTILS-TESTS=ON -DENABLE_TESTING=ON ${BUILD_OPTS} -DCMAKE_INSTALL_PREFIX=../install ..; fi
- - if [ "$TRAVIS_OS_NAME" = "osx" ]; then cmake ${BUILD_OPTIONS} ${BUILD_OPTIONS_OSX} -DBUILD_FRAMEWORK_TESTS=ON -DBUILD_UTILS-TESTS=ON -DENABLE_TESTING=ON -DFFI_LIBRARY=/usr/local/opt/libffi/lib/libffi.dylib ${BUILD_OPTS} -DCMAKE_INSTALL_PREFIX=../install ..; fi
+ - if [ "$TRAVIS_OS_NAME" = "linux" ] && [ -z "$ANDROID" ]; then cmake -DCMAKE_BUILD_TYPE=Debug ${BUILD_OPTIONS} ${BUILD_OPTIONS_LINUX} -DBUILD_FRAMEWORK_TESTS=ON -DBUILD_UTILS-TESTS=ON -DENABLE_TESTING=ON ${BUILD_OPTS} -DCMAKE_INSTALL_PREFIX=../install ..; fi
+ - if [ "$TRAVIS_OS_NAME" = "osx" ]; then cmake -DCMAKE_BUILD_TYPE=Debug ${BUILD_OPTIONS} ${BUILD_OPTIONS_OSX} -DBUILD_FRAMEWORK_TESTS=ON -DBUILD_UTILS-TESTS=ON -DENABLE_TESTING=ON -DFFI_LIBRARY=/usr/local/opt/libffi/lib/libffi.dylib ${BUILD_OPTS} -DCMAKE_INSTALL_PREFIX=../install ..; fi
- if [ -z "$ANDROID" ]; then make all && make deploy && sudo make install; else cd .. && docker build -t celixandroid - < Dockerfile.Android ; fi
- if [ -z "$ANDROID" ]; then export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH:`pwd`/utils:`pwd`/framework:`pwd`/dfi && make test ARGS="-V"; else docker run celixandroid; fi
http://git-wip-us.apache.org/repos/asf/celix/blob/326f2759/framework/src/service_registration.c
----------------------------------------------------------------------
diff --git a/framework/src/service_registration.c b/framework/src/service_registration.c
index 5d23dbf..262a104 100644
--- a/framework/src/service_registration.c
+++ b/framework/src/service_registration.c
@@ -210,7 +210,7 @@ celix_status_t serviceRegistration_ungetService(service_registration_pt registra
if (registration->isServiceFactory) {
service_factory_pt factory = (void*) registration->serviceFactory;
/*NOTE the service argument of the service_factory should be const void**.
- To ensure backwards compatability a cast is made instead.
+ To ensure backwards compatibility a cast is made instead.
*/
factory->ungetService(factory->handle, bundle, registration, (void**) service);
}
[02/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/utils/private/src/civetweb.c
----------------------------------------------------------------------
diff --git a/remote_services/utils/private/src/civetweb.c b/remote_services/utils/private/src/civetweb.c
deleted file mode 100644
index a6093b7..0000000
--- a/remote_services/utils/private/src/civetweb.c
+++ /dev/null
@@ -1,7907 +0,0 @@
- /* Copyright (c) 2013-2015 the Civetweb developers
- * Copyright (c) 2004-2013 Sergey Lyubka
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#if defined(_WIN32)
-#if !defined(_CRT_SECURE_NO_WARNINGS)
-#define _CRT_SECURE_NO_WARNINGS /* Disable deprecation warning in VS2005 */
-#endif
-#else
-#ifdef __linux__
-#define _XOPEN_SOURCE 600 /* For flockfile() on Linux */
-#endif
-#ifndef _LARGEFILE_SOURCE
-#define _LARGEFILE_SOURCE /* For fseeko(), ftello() */
-#endif
-#ifndef _FILE_OFFSET_BITS
-#define _FILE_OFFSET_BITS 64 /* Use 64-bit file offsets by default */
-#endif
-#ifndef __STDC_FORMAT_MACROS
-#define __STDC_FORMAT_MACROS /* <inttypes.h> wants this for C++ */
-#endif
-#ifndef __STDC_LIMIT_MACROS
-#define __STDC_LIMIT_MACROS /* C++ wants that for INT64_MAX */
-#endif
-#endif
-
-#if defined (_MSC_VER)
-/* 'type cast' : conversion from 'int' to 'HANDLE' of greater size */
-#pragma warning (disable : 4306 )
-/* conditional expression is constant: introduced by FD_SET(..) */
-#pragma warning (disable : 4127)
-/* non-constant aggregate initializer: issued due to missing C99 support */
-#pragma warning (disable : 4204)
-#endif
-
-/* Disable WIN32_LEAN_AND_MEAN.
- This makes windows.h always include winsock2.h */
-#if defined(WIN32_LEAN_AND_MEAN)
-#undef WIN32_LEAN_AND_MEAN
-#endif
-
-#if defined USE_IPV6 && defined(_WIN32)
-#include <ws2tcpip.h>
-#endif
-
-#if defined(__SYMBIAN32__)
-#define NO_SSL /* SSL is not supported */
-#define NO_CGI /* CGI is not supported */
-#define PATH_MAX FILENAME_MAX
-#endif /* __SYMBIAN32__ */
-
-#ifndef IGNORE_UNUSED_RESULT
-#define IGNORE_UNUSED_RESULT(a) (void)((a) && 1)
-#endif
-
-#ifndef _WIN32_WCE /* Some ANSI #includes are not available on Windows CE */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <signal.h>
-#include <fcntl.h>
-#endif /* !_WIN32_WCE */
-
-#include <time.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <assert.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-#include <stddef.h>
-#include <stdio.h>
-
-#ifndef MAX_WORKER_THREADS
-#define MAX_WORKER_THREADS (1024*64)
-#endif
-
-#if defined(_WIN32) && !defined(__SYMBIAN32__) /* Windows specific */
-#if defined(_MSC_VER) && _MSC_VER <= 1400
-#undef _WIN32_WINNT
-#define _WIN32_WINNT 0x0400 /* To make it link in VS2005 */
-#endif
-#include <windows.h>
-typedef const char * SOCK_OPT_TYPE;
-
-#ifndef PATH_MAX
-#define PATH_MAX MAX_PATH
-#endif
-
-#ifndef _IN_PORT_T
-#ifndef in_port_t
-#define in_port_t u_short
-#endif
-#endif
-
-#ifndef _WIN32_WCE
-#include <process.h>
-#include <direct.h>
-#include <io.h>
-#else /* _WIN32_WCE */
-#define NO_CGI /* WinCE has no pipes */
-
-typedef long off_t;
-
-#define errno GetLastError()
-#define strerror(x) _ultoa(x, (char *) _alloca(sizeof(x) *3 ), 10)
-#endif /* _WIN32_WCE */
-
-#define MAKEUQUAD(lo, hi) ((uint64_t)(((uint32_t)(lo)) | \
- ((uint64_t)((uint32_t)(hi))) << 32))
-#define RATE_DIFF 10000000 /* 100 nsecs */
-#define EPOCH_DIFF MAKEUQUAD(0xd53e8000, 0x019db1de)
-#define SYS2UNIX_TIME(lo, hi) \
- (time_t) ((MAKEUQUAD((lo), (hi)) - EPOCH_DIFF) / RATE_DIFF)
-
-/* Visual Studio 6 does not know __func__ or __FUNCTION__
- The rest of MS compilers use __FUNCTION__, not C99 __func__
- Also use _strtoui64 on modern M$ compilers */
-#if defined(_MSC_VER) && _MSC_VER < 1300
-#define STRX(x) #x
-#define STR(x) STRX(x)
-#define __func__ __FILE__ ":" STR(__LINE__)
-#define strtoull(x, y, z) (unsigned __int64) _atoi64(x)
-#define strtoll(x, y, z) _atoi64(x)
-#else
-#define __func__ __FUNCTION__
-#define strtoull(x, y, z) _strtoui64(x, y, z)
-#define strtoll(x, y, z) _strtoi64(x, y, z)
-#endif /* _MSC_VER */
-
-#define ERRNO GetLastError()
-#define NO_SOCKLEN_T
-#define SSL_LIB "ssleay32.dll"
-#define CRYPTO_LIB "libeay32.dll"
-#define O_NONBLOCK 0
-#define W_OK (2) /* http://msdn.microsoft.com/en-us/library/1w06ktdy.aspx */
-#if !defined(EWOULDBLOCK)
-#define EWOULDBLOCK WSAEWOULDBLOCK
-#endif /* !EWOULDBLOCK */
-#define _POSIX_
-#define INT64_FMT "I64d"
-
-#define WINCDECL __cdecl
-#define SHUT_WR 1
-#define snprintf _snprintf
-#define vsnprintf _vsnprintf
-#define access _access
-#define mg_sleep(x) Sleep(x)
-
-#define pipe(x) _pipe(x, MG_BUF_LEN, _O_BINARY)
-#ifndef popen
-#define popen(x, y) _popen(x, y)
-#endif
-#ifndef pclose
-#define pclose(x) _pclose(x)
-#endif
-#define close(x) _close(x)
-#define dlsym(x,y) GetProcAddress((HINSTANCE) (x), (y))
-#define RTLD_LAZY 0
-#define fseeko(x, y, z) _lseeki64(_fileno(x), (y), (z))
-#define fdopen(x, y) _fdopen((x), (y))
-#define write(x, y, z) _write((x), (y), (unsigned) z)
-#define read(x, y, z) _read((x), (y), (unsigned) z)
-#define flockfile(x) EnterCriticalSection(&global_log_file_lock)
-#define funlockfile(x) LeaveCriticalSection(&global_log_file_lock)
-#define sleep(x) Sleep((x) * 1000)
-#define rmdir(x) _rmdir(x)
-
-#if defined(USE_LUA) && defined(USE_WEBSOCKET)
-#define USE_TIMERS
-#endif
-
-#if !defined(va_copy)
-#define va_copy(x, y) x = y
-#endif /* !va_copy MINGW #defines va_copy */
-
-#if !defined(fileno)
-#define fileno(x) _fileno(x)
-#endif /* !fileno MINGW #defines fileno */
-
-typedef HANDLE pthread_mutex_t;
-typedef DWORD pthread_key_t;
-typedef HANDLE pthread_t;
-typedef struct {
- CRITICAL_SECTION threadIdSec;
- int waitingthreadcount; /* The number of threads queued. */
- pthread_t *waitingthreadhdls; /* The thread handles. */
-} pthread_cond_t;
-
-#ifndef __clockid_t_defined
-typedef DWORD clockid_t;
-#endif
-#ifndef CLOCK_MONOTONIC
-#define CLOCK_MONOTONIC (1)
-#endif
-#ifndef CLOCK_REALTIME
-#define CLOCK_REALTIME (2)
-#endif
-
-#ifndef _TIMESPEC_DEFINED
-struct timespec {
- time_t tv_sec; /* seconds */
- long tv_nsec; /* nanoseconds */
-};
-#endif
-
-#define pid_t HANDLE /* MINGW typedefs pid_t to int. Using #define here. */
-
-static int pthread_mutex_lock(pthread_mutex_t *);
-static int pthread_mutex_unlock(pthread_mutex_t *);
-static void to_unicode(const char *path, wchar_t *wbuf, size_t wbuf_len);
-struct file;
-static char *mg_fgets(char *buf, size_t size, struct file *filep, char **p);
-
-#if defined(HAVE_STDINT)
-#include <stdint.h>
-#else
-typedef unsigned int uint32_t;
-typedef unsigned short uint16_t;
-typedef unsigned __int64 uint64_t;
-typedef __int64 int64_t;
-#define INT64_MAX 9223372036854775807
-#endif /* HAVE_STDINT */
-
-/* POSIX dirent interface */
-struct dirent {
- char d_name[PATH_MAX];
-};
-
-typedef struct DIR {
- HANDLE handle;
- WIN32_FIND_DATAW info;
- struct dirent result;
-} DIR;
-
-#if !defined(USE_IPV6) && defined(_WIN32)
-#ifndef HAVE_POLL
-struct pollfd {
- SOCKET fd;
- short events;
- short revents;
-};
-#define POLLIN 1
-#endif
-#endif
-
-/* Mark required libraries */
-#ifdef _MSC_VER
-#pragma comment(lib, "Ws2_32.lib")
-#endif
-
-#else /* UNIX specific */
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <sys/poll.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/time.h>
-#include <sys/utsname.h>
-#include <stdint.h>
-#include <inttypes.h>
-#include <netdb.h>
-typedef const void * SOCK_OPT_TYPE;
-
-//#if defined(ANDROID)
-typedef unsigned short int in_port_t;
-//#endif
-
-#include <pwd.h>
-#include <unistd.h>
-#include <dirent.h>
-#if !defined(NO_SSL_DL) && !defined(NO_SSL)
-#include <dlfcn.h>
-#endif
-#include <pthread.h>
-#if defined(__MACH__)
-#define SSL_LIB "libssl.dylib"
-#define CRYPTO_LIB "libcrypto.dylib"
-#else
-#if !defined(SSL_LIB)
-#define SSL_LIB "libssl.so"
-#endif
-#if !defined(CRYPTO_LIB)
-#define CRYPTO_LIB "libcrypto.so"
-#endif
-#endif
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif /* O_BINARY */
-#define closesocket(a) close(a)
-#define mg_mkdir(x, y) mkdir(x, y)
-#define mg_remove(x) remove(x)
-#define mg_sleep(x) usleep((x) * 1000)
-#define ERRNO errno
-#define INVALID_SOCKET (-1)
-#define INT64_FMT PRId64
-typedef int SOCKET;
-#define WINCDECL
-
-#endif /* End of Windows and UNIX specific includes */
-
-#ifdef _WIN32
-static CRITICAL_SECTION global_log_file_lock;
-static DWORD pthread_self(void)
-{
- return GetCurrentThreadId();
-}
-
-int pthread_key_create(pthread_key_t *key, void (*_must_be_zero)(void*) /* destructor function not supported for windows */)
-{
- assert(_must_be_zero == NULL);
- if ((key!=0) && (_must_be_zero == NULL)) {
- *key = TlsAlloc();
- return (*key != TLS_OUT_OF_INDEXES) ? 0 : -1;
- }
- return -2;
-}
-
-int pthread_key_delete(pthread_key_t key)
-{
- return TlsFree(key) ? 0 : 1;
-}
-
-int pthread_setspecific(pthread_key_t key, void * value)
-{
- return TlsSetValue(key, value) ? 0 : 1;
-}
-
-void *pthread_getspecific(pthread_key_t key)
-{
- return TlsGetValue(key);
-}
-#endif /* _WIN32 */
-
-
-#include "civetweb.h"
-
-#define PASSWORDS_FILE_NAME ".htpasswd"
-#define CGI_ENVIRONMENT_SIZE 4096
-#define MAX_CGI_ENVIR_VARS 64
-#define MG_BUF_LEN 8192
-#ifndef MAX_REQUEST_SIZE
-#define MAX_REQUEST_SIZE 16384
-#endif
-#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
-
-#if !defined(DEBUG_TRACE)
-#if defined(CWDEBUG)
-
-static void DEBUG_TRACE_FUNC(const char *func, unsigned line, PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(3, 4);
-
-static void DEBUG_TRACE_FUNC(const char *func, unsigned line, const char *fmt, ...) {
-
- va_list args;
- flockfile(stdout);
- printf("*** %lu.%p.%s.%u: ",
- (unsigned long) time(NULL), (void *) pthread_self(),
- func, line);
- va_start(args, fmt);
- vprintf(fmt, args);
- va_end(args);
- putchar('\n');
- fflush(stdout);
- funlockfile(stdout);
-}
-
-#define DEBUG_TRACE(fmt, ...) DEBUG_TRACE_FUNC(__func__, __LINE__, fmt, __VA_ARGS__)
-
-#else
-#define DEBUG_TRACE(fmt, ...)
-#endif /* CWDEBUG */
-#endif /* DEBUG_TRACE */
-
-#if defined(MEMORY_DEBUGGING)
-static unsigned long blockCount = 0;
-static unsigned long totalMemUsed = 0;
-
-static void * mg_malloc_ex(size_t size, const char * file, unsigned line) {
-
- void * data = malloc(size + sizeof(size_t));
- void * memory = 0;
- char mallocStr[256];
-
- if (data) {
- *(size_t*)data = size;
- totalMemUsed += size;
- blockCount++;
- memory = (void *)(((char*)data)+sizeof(size_t));
- }
-
- sprintf(mallocStr, "MEM: %p %5lu alloc %7lu %4lu --- %s:%u\n", memory, (unsigned long)size, totalMemUsed, blockCount, file, line);
-#if defined(_WIN32)
- OutputDebugStringA(mallocStr);
-#else
- DEBUG_TRACE("%s", mallocStr);
-#endif
-
- return memory;
-}
-
-static void * mg_calloc_ex(size_t count, size_t size, const char * file, unsigned line) {
-
- void * data = mg_malloc_ex(size*count, file, line);
- if (data) memset(data, 0, size);
-
- return data;
-}
-
-static void mg_free_ex(void * memory, const char * file, unsigned line) {
-
- char mallocStr[256];
- void * data = (void *)(((char*)memory)-sizeof(size_t));
- size_t size;
-
- if (memory) {
- size = *(size_t*)data;
- totalMemUsed -= size;
- blockCount--;
- sprintf(mallocStr, "MEM: %p %5lu free %7lu %4lu --- %s:%u\n", memory, (unsigned long)size, totalMemUsed, blockCount, file, line);
-#if defined(_WIN32)
- OutputDebugStringA(mallocStr);
-#else
- DEBUG_TRACE("%s", mallocStr);
-#endif
-
- free(data);
- }
-}
-
-static void * mg_realloc_ex(void * memory, size_t newsize, const char * file, unsigned line) {
-
- char mallocStr[256];
- void * data;
- void * _realloc;
- size_t oldsize;
-
- if (newsize) {
- if (memory) {
- data = (void *)(((char*)memory)-sizeof(size_t));
- oldsize = *(size_t*)data;
- _realloc = realloc(data, newsize+sizeof(size_t));
- if (_realloc) {
- data = _realloc;
- totalMemUsed -= oldsize;
- sprintf(mallocStr, "MEM: %p %5lu r-free %7lu %4lu --- %s:%u\n", memory, (unsigned long)oldsize, totalMemUsed, blockCount, file, line);
-#if defined(_WIN32)
- OutputDebugStringA(mallocStr);
-#else
- DEBUG_TRACE("%s", mallocStr);
-#endif
- totalMemUsed += newsize;
- sprintf(mallocStr, "MEM: %p %5lu r-alloc %7lu %4lu --- %s:%u\n", memory, (unsigned long)newsize, totalMemUsed, blockCount, file, line);
-#if defined(_WIN32)
- OutputDebugStringA(mallocStr);
-#else
- DEBUG_TRACE("%s", mallocStr);
-#endif
- *(size_t*)data = newsize;
- data = (void *)(((char*)data)+sizeof(size_t));
- } else {
-#if defined(_WIN32)
- OutputDebugStringA("MEM: realloc failed\n");
-#else
- DEBUG_TRACE("%s", "MEM: realloc failed\n");
-#endif
- return _realloc;
- }
- } else {
- data = mg_malloc_ex(newsize, file, line);
- }
- } else {
- data = 0;
- mg_free_ex(memory, file, line);
- }
-
- return data;
-}
-
-#define mg_malloc(a) mg_malloc_ex(a, __FILE__, __LINE__)
-#define mg_calloc(a,b) mg_calloc_ex(a, b, __FILE__, __LINE__)
-#define mg_realloc(a, b) mg_realloc_ex(a, b, __FILE__, __LINE__)
-#define mg_free(a) mg_free_ex(a, __FILE__, __LINE__)
-
-#else
-static __inline void * mg_malloc(size_t a) {return malloc(a);}
-static __inline void * mg_calloc(size_t a, size_t b) {return calloc(a, b);}
-static __inline void * mg_realloc(void * a, size_t b) {return realloc(a, b);}
-static __inline void mg_free(void * a) {free(a);}
-#endif
-
-/* This following lines are just meant as a reminder to use the mg-functions for memory management */
-#ifdef malloc
- #undef malloc
-#endif
-#ifdef calloc
- #undef calloc
-#endif
-#ifdef realloc
- #undef realloc
-#endif
-#ifdef free
- #undef free
-#endif
-#define malloc DO_NOT_USE_THIS_FUNCTION__USE_mg_malloc
-#define calloc DO_NOT_USE_THIS_FUNCTION__USE_mg_calloc
-#define realloc DO_NOT_USE_THIS_FUNCTION__USE_mg_realloc
-#define free DO_NOT_USE_THIS_FUNCTION__USE_mg_free
-
-
-#define MD5_STATIC static
-#include "md5.inl"
-
-/* Darwin prior to 7.0 and Win32 do not have socklen_t */
-#ifdef NO_SOCKLEN_T
-typedef int socklen_t;
-#endif /* NO_SOCKLEN_T */
-#define _DARWIN_UNLIMITED_SELECT
-
-#define IP_ADDR_STR_LEN 50 /* IPv6 hex string is 46 chars */
-
-#if !defined(MSG_NOSIGNAL)
-#define MSG_NOSIGNAL 0
-#endif
-
-#if !defined(SOMAXCONN)
-#define SOMAXCONN 100
-#endif
-
-#if !defined(PATH_MAX)
-#define PATH_MAX 4096
-#endif
-
-/* Size of the accepted socket queue */
-#if !defined(MGSQLEN)
-#define MGSQLEN 20
-#endif
-
-#if defined(NO_SSL_DL)
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#else
-/* SSL loaded dynamically from DLL.
- I put the prototypes here to be independent from OpenSSL source
- installation. */
-
-typedef struct ssl_st SSL;
-typedef struct ssl_method_st SSL_METHOD;
-typedef struct ssl_ctx_st SSL_CTX;
-
-struct ssl_func {
- const char *name; /* SSL function name */
- void (*ptr)(void); /* Function pointer */
-};
-
-#define SSL_free (* (void (*)(SSL *)) ssl_sw[0].ptr)
-#define SSL_accept (* (int (*)(SSL *)) ssl_sw[1].ptr)
-#define SSL_connect (* (int (*)(SSL *)) ssl_sw[2].ptr)
-#define SSL_read (* (int (*)(SSL *, void *, int)) ssl_sw[3].ptr)
-#define SSL_write (* (int (*)(SSL *, const void *,int)) ssl_sw[4].ptr)
-#define SSL_get_error (* (int (*)(SSL *, int)) ssl_sw[5].ptr)
-#define SSL_set_fd (* (int (*)(SSL *, SOCKET)) ssl_sw[6].ptr)
-#define SSL_new (* (SSL * (*)(SSL_CTX *)) ssl_sw[7].ptr)
-#define SSL_CTX_new (* (SSL_CTX * (*)(SSL_METHOD *)) ssl_sw[8].ptr)
-#define SSLv23_server_method (* (SSL_METHOD * (*)(void)) ssl_sw[9].ptr)
-#define SSL_library_init (* (int (*)(void)) ssl_sw[10].ptr)
-#define SSL_CTX_use_PrivateKey_file (* (int (*)(SSL_CTX *, \
- const char *, int)) ssl_sw[11].ptr)
-#define SSL_CTX_use_certificate_file (* (int (*)(SSL_CTX *, \
- const char *, int)) ssl_sw[12].ptr)
-#define SSL_CTX_set_default_passwd_cb \
- (* (void (*)(SSL_CTX *, mg_callback_t)) ssl_sw[13].ptr)
-#define SSL_CTX_free (* (void (*)(SSL_CTX *)) ssl_sw[14].ptr)
-#define SSL_load_error_strings (* (void (*)(void)) ssl_sw[15].ptr)
-#define SSL_CTX_use_certificate_chain_file \
- (* (int (*)(SSL_CTX *, const char *)) ssl_sw[16].ptr)
-#define SSLv23_client_method (* (SSL_METHOD * (*)(void)) ssl_sw[17].ptr)
-#define SSL_pending (* (int (*)(SSL *)) ssl_sw[18].ptr)
-#define SSL_CTX_set_verify (* (void (*)(SSL_CTX *, int, int)) ssl_sw[19].ptr)
-#define SSL_shutdown (* (int (*)(SSL *)) ssl_sw[20].ptr)
-
-#define CRYPTO_num_locks (* (int (*)(void)) crypto_sw[0].ptr)
-#define CRYPTO_set_locking_callback \
- (* (void (*)(void (*)(int, int, const char *, int))) crypto_sw[1].ptr)
-#define CRYPTO_set_id_callback \
- (* (void (*)(unsigned long (*)(void))) crypto_sw[2].ptr)
-#define ERR_get_error (* (unsigned long (*)(void)) crypto_sw[3].ptr)
-#define ERR_error_string (* (char * (*)(unsigned long,char *)) crypto_sw[4].ptr)
-
-/* set_ssl_option() function updates this array.
- It loads SSL library dynamically and changes NULLs to the actual addresses
- of respective functions. The macros above (like SSL_connect()) are really
- just calling these functions indirectly via the pointer. */
-static struct ssl_func ssl_sw[] = {
- {"SSL_free", NULL},
- {"SSL_accept", NULL},
- {"SSL_connect", NULL},
- {"SSL_read", NULL},
- {"SSL_write", NULL},
- {"SSL_get_error", NULL},
- {"SSL_set_fd", NULL},
- {"SSL_new", NULL},
- {"SSL_CTX_new", NULL},
- {"SSLv23_server_method", NULL},
- {"SSL_library_init", NULL},
- {"SSL_CTX_use_PrivateKey_file", NULL},
- {"SSL_CTX_use_certificate_file",NULL},
- {"SSL_CTX_set_default_passwd_cb",NULL},
- {"SSL_CTX_free", NULL},
- {"SSL_load_error_strings", NULL},
- {"SSL_CTX_use_certificate_chain_file", NULL},
- {"SSLv23_client_method", NULL},
- {"SSL_pending", NULL},
- {"SSL_CTX_set_verify", NULL},
- {"SSL_shutdown", NULL},
- {NULL, NULL}
-};
-
-/* Similar array as ssl_sw. These functions could be located in different
- lib. */
-#if !defined(NO_SSL)
-static struct ssl_func crypto_sw[] = {
- {"CRYPTO_num_locks", NULL},
- {"CRYPTO_set_locking_callback", NULL},
- {"CRYPTO_set_id_callback", NULL},
- {"ERR_get_error", NULL},
- {"ERR_error_string", NULL},
- {NULL, NULL}
-};
-#endif /* NO_SSL */
-#endif /* NO_SSL_DL */
-
-static const char *month_names[] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-
-/* Unified socket address. For IPv6 support, add IPv6 address structure
- in the union u. */
-union usa {
- struct sockaddr sa;
- struct sockaddr_in sin;
-#if defined(USE_IPV6)
- struct sockaddr_in6 sin6;
-#endif
-};
-
-/* Describes a string (chunk of memory). */
-struct vec {
- const char *ptr;
- size_t len;
-};
-
-struct file {
- int is_directory;
- time_t modification_time;
- int64_t size;
- FILE *fp;
- const char *membuf; /* Non-NULL if file data is in memory */
- /* set to 1 if the content is gzipped
- in which case we need a content-encoding: gzip header */
- int gzipped;
-};
-#define STRUCT_FILE_INITIALIZER {0, 0, 0, NULL, NULL, 0}
-
-/* Describes listening socket, or socket which was accept()-ed by the master
- thread and queued for future handling by the worker thread. */
-struct socket {
- SOCKET sock; /* Listening socket */
- union usa lsa; /* Local socket address */
- union usa rsa; /* Remote socket address */
- unsigned is_ssl:1; /* Is port SSL-ed */
- unsigned ssl_redir:1; /* Is port supposed to redirect everything to SSL
- port */
-};
-
-/* NOTE(lsm): this enum shoulds be in sync with the config_options below. */
-enum {
- CGI_EXTENSIONS, CGI_ENVIRONMENT, PUT_DELETE_PASSWORDS_FILE, CGI_INTERPRETER,
- PROTECT_URI, AUTHENTICATION_DOMAIN, SSI_EXTENSIONS, THROTTLE,
- ACCESS_LOG_FILE, ENABLE_DIRECTORY_LISTING, ERROR_LOG_FILE,
- GLOBAL_PASSWORDS_FILE, INDEX_FILES, ENABLE_KEEP_ALIVE, ACCESS_CONTROL_LIST,
- EXTRA_MIME_TYPES, LISTENING_PORTS, DOCUMENT_ROOT, SSL_CERTIFICATE,
- NUM_THREADS, RUN_AS_USER, REWRITE, HIDE_FILES, REQUEST_TIMEOUT,
- DECODE_URL,
-
-#if defined(USE_LUA)
- LUA_PRELOAD_FILE, LUA_SCRIPT_EXTENSIONS, LUA_SERVER_PAGE_EXTENSIONS,
-#endif
-#if defined(USE_WEBSOCKET)
- WEBSOCKET_ROOT,
-#endif
-#if defined(USE_LUA) && defined(USE_WEBSOCKET)
- LUA_WEBSOCKET_EXTENSIONS,
-#endif
- ACCESS_CONTROL_ALLOW_ORIGIN, ERROR_PAGES,
-
- NUM_OPTIONS
-};
-
-/* Config option name, config types, default value */
-static struct mg_option config_options[] = {
- {"cgi_pattern", CONFIG_TYPE_EXT_PATTERN, "**.cgi$|**.pl$|**.php$"},
- {"cgi_environment", CONFIG_TYPE_STRING, NULL},
- {"put_delete_auth_file", CONFIG_TYPE_FILE, NULL},
- {"cgi_interpreter", CONFIG_TYPE_FILE, NULL},
- {"protect_uri", CONFIG_TYPE_STRING, NULL},
- {"authentication_domain", CONFIG_TYPE_STRING, "mydomain.com"},
- {"ssi_pattern", CONFIG_TYPE_EXT_PATTERN, "**.shtml$|**.shtm$"},
- {"throttle", CONFIG_TYPE_STRING, NULL},
- {"access_log_file", CONFIG_TYPE_FILE, NULL},
- {"enable_directory_listing", CONFIG_TYPE_BOOLEAN, "yes"},
- {"error_log_file", CONFIG_TYPE_FILE, NULL},
- {"global_auth_file", CONFIG_TYPE_FILE, NULL},
- {"index_files", CONFIG_TYPE_STRING,
-#ifdef USE_LUA
- "index.xhtml,index.html,index.htm,index.lp,index.lsp,index.lua,index.cgi,index.shtml,index.php"},
-#else
- "index.xhtml,index.html,index.htm,index.cgi,index.shtml,index.php"},
-#endif
- {"enable_keep_alive", CONFIG_TYPE_BOOLEAN, "no"},
- {"access_control_list", CONFIG_TYPE_STRING, NULL},
- {"extra_mime_types", CONFIG_TYPE_STRING, NULL},
- {"listening_ports", CONFIG_TYPE_STRING, "8080"},
- {"document_root", CONFIG_TYPE_DIRECTORY, NULL},
- {"ssl_certificate", CONFIG_TYPE_FILE, NULL},
- {"num_threads", CONFIG_TYPE_NUMBER, "50"},
- {"run_as_user", CONFIG_TYPE_STRING, NULL},
- {"url_rewrite_patterns", CONFIG_TYPE_STRING, NULL},
- {"hide_files_patterns", CONFIG_TYPE_EXT_PATTERN, NULL},
- {"request_timeout_ms", CONFIG_TYPE_NUMBER, "30000"},
- {"decode_url", CONFIG_TYPE_BOOLEAN, "yes"},
-
-#if defined(USE_LUA)
- {"lua_preload_file", CONFIG_TYPE_FILE, NULL},
- {"lua_script_pattern", CONFIG_TYPE_EXT_PATTERN, "**.lua$"},
- {"lua_server_page_pattern", CONFIG_TYPE_EXT_PATTERN, "**.lp$|**.lsp$"},
-#endif
-#if defined(USE_WEBSOCKET)
- {"websocket_root", CONFIG_TYPE_DIRECTORY, NULL},
-#endif
-#if defined(USE_LUA) && defined(USE_WEBSOCKET)
- {"lua_websocket_pattern", CONFIG_TYPE_EXT_PATTERN, "**.lua$"},
-#endif
- {"access_control_allow_origin", CONFIG_TYPE_STRING, "*"},
- {"error_pages", CONFIG_TYPE_DIRECTORY, NULL},
-
- {NULL, CONFIG_TYPE_UNKNOWN, NULL}
-};
-
-struct mg_request_handler_info {
- char *uri;
- size_t uri_len;
- mg_request_handler handler;
-
- void *cbdata;
- struct mg_request_handler_info *next;
-};
-
-struct mg_context {
- volatile int stop_flag; /* Should we stop event loop */
- SSL_CTX *ssl_ctx; /* SSL context */
- char *config[NUM_OPTIONS]; /* Civetweb configuration parameters */
- struct mg_callbacks callbacks; /* User-defined callback function */
- void *user_data; /* User-defined data */
- int context_type; /* 1 = server context, 2 = client context */
-
- struct socket *listening_sockets;
- in_port_t *listening_ports;
- int num_listening_sockets;
-
- volatile int num_threads; /* Number of threads */
- pthread_mutex_t thread_mutex; /* Protects (max|num)_threads */
- pthread_cond_t thread_cond; /* Condvar for tracking workers terminations */
-
- struct socket queue[MGSQLEN]; /* Accepted sockets */
- volatile int sq_head; /* Head of the socket queue */
- volatile int sq_tail; /* Tail of the socket queue */
- pthread_cond_t sq_full; /* Signaled when socket is produced */
- pthread_cond_t sq_empty; /* Signaled when socket is consumed */
- pthread_t masterthreadid; /* The master thread ID */
- int workerthreadcount; /* The amount of worker threads. */
- pthread_t *workerthreadids; /* The worker thread IDs */
-
- unsigned long start_time; /* Server start time, used for authentication */
- pthread_mutex_t nonce_mutex; /* Protects nonce_count */
- unsigned long nonce_count; /* Used nonces, used for authentication */
-
- char *systemName; /* What operating system is running */
-
- /* linked list of uri handlers */
- struct mg_request_handler_info *request_handlers;
-
-#if defined(USE_LUA) && defined(USE_WEBSOCKET)
- /* linked list of shared lua websockets */
- struct mg_shared_lua_websocket_list *shared_lua_websockets;
-#endif
-
-#ifdef USE_TIMERS
- struct ttimers * timers;
-#endif
-};
-
-struct mg_connection {
- struct mg_request_info request_info;
- struct mg_context *ctx;
- SSL *ssl; /* SSL descriptor */
- SSL_CTX *client_ssl_ctx; /* SSL context for client connections */
- struct socket client; /* Connected client */
- time_t birth_time; /* Time when request was received */
- int64_t num_bytes_sent; /* Total bytes sent to client */
- int64_t content_len; /* Content-Length header value */
- int64_t consumed_content; /* How many bytes of content have been read */
- char *buf; /* Buffer for received data */
- char *path_info; /* PATH_INFO part of the URL */
- int must_close; /* 1 if connection must be closed */
- int in_error_handler; /* 1 if in handler for user defined error pages */
- int buf_size; /* Buffer size */
- int request_len; /* Size of the request + headers in a buffer */
- int data_len; /* Total size of data in a buffer */
- int status_code; /* HTTP reply status code, e.g. 200 */
- int throttle; /* Throttling, bytes/sec. <= 0 means no throttle */
- time_t last_throttle_time; /* Last time throttled data was sent */
- int64_t last_throttle_bytes; /* Bytes sent this second */
- pthread_mutex_t mutex; /* Used by mg_lock_connection/mg_unlock_connection to ensure atomic transmissions for websockets */
-#if defined(USE_LUA) && defined(USE_WEBSOCKET)
- void * lua_websocket_state; /* Lua_State for a websocket connection */
-#endif
-};
-
-static pthread_key_t sTlsKey; /* Thread local storage index */
-static int sTlsInit = 0;
-
-struct mg_workerTLS {
- int is_master;
-#if defined(_WIN32) && !defined(__SYMBIAN32__)
- HANDLE pthread_cond_helper_mutex;
-#endif
-};
-
-/* Directory entry */
-struct de {
- struct mg_connection *conn;
- char *file_name;
- struct file file;
-};
-
-#if defined(USE_WEBSOCKET)
-static int is_websocket_protocol(const struct mg_connection *conn);
-#else
-#define is_websocket_protocol(conn) (0)
-#endif
-
-int mg_atomic_inc(volatile int * addr)
-{
- int ret;
-#if defined(_WIN32) && !defined(__SYMBIAN32__)
- ret = InterlockedIncrement((volatile unsigned int *) addr);
-#elif defined(__GNUC__)
- ret = __sync_add_and_fetch(addr, 1);
-#else
- ret = (++(*addr));
-#endif
- return ret;
-}
-
-int mg_atomic_dec(volatile int * addr)
-{
- int ret;
-#if defined(_WIN32) && !defined(__SYMBIAN32__)
- ret = InterlockedDecrement((volatile unsigned int *) addr);
-#elif defined(__GNUC__)
- ret = __sync_sub_and_fetch(addr, 1);
-#else
- ret = (--(*addr));
-#endif
- return ret;
-}
-
-#if !defined(NO_THREAD_NAME)
-#if defined(_WIN32) && defined(_MSC_VER)
-/* Set the thread name for debugging purposes in Visual Studio
- http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
-*/
-#pragma pack(push,8)
-typedef struct tagTHREADNAME_INFO
-{
- DWORD dwType; /* Must be 0x1000. */
- LPCSTR szName; /* Pointer to name (in user addr space). */
- DWORD dwThreadID; /* Thread ID (-1=caller thread). */
- DWORD dwFlags; /* Reserved for future use, must be zero. */
-} THREADNAME_INFO;
-#pragma pack(pop)
-#elif defined(__linux__)
-#include <sys/prctl.h>
-#endif
-
-void mg_set_thread_name(const char* name)
-{
- char threadName[16]; /* Max. thread length in Linux/OSX/.. */
-
- if (snprintf(threadName, sizeof(threadName), "civetweb-%s", name)<0) return;
- threadName[sizeof(threadName)-1] = 0;
-
-#if defined(_WIN32)
-#if defined(_MSC_VER)
- /* Windows and Visual Studio Compiler */
- __try
- {
- THREADNAME_INFO info;
- info.dwType = 0x1000;
- info.szName = threadName;
- info.dwThreadID = -1;
- info.dwFlags = 0;
-
- RaiseException(0x406D1388, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info);
- }
- __except(EXCEPTION_EXECUTE_HANDLER)
- {
- }
-#elif defined(__MINGW32__)
- /* No option known to set thread name for MinGW */
-#endif
-#elif defined(__linux__)
- /* Linux */
- (void)prctl(PR_SET_NAME,threadName,0,0,0);
-#elif defined(__APPLE__) || defined(__MACH__)
- /* OS X (TODO: test) */
- (void)pthread_setname_np(threadName);
-#elif defined(BSD) || defined(__FreeBSD__) || defined(__OpenBSD__)
- /* BSD (TODO: test) */
- pthread_set_name_np(pthread_self(), threadName);
-#else
- /* POSIX */
- (void)pthread_setname_np(pthread_self(), threadName);
-#endif
-}
-#else /* !defined(NO_THREAD_NAME) */
-void mg_set_thread_name(const char* threadName) {}
-#endif
-
-#if defined(MG_LEGACY_INTERFACE)
-const char **mg_get_valid_option_names(void)
-{
- static const char * data[2 * sizeof(config_options) / sizeof(config_options[0])] = {0};
- int i;
-
- for (i=0; config_options[i].name != NULL; i++) {
- data[i * 2] = config_options[i].name;
- data[i * 2 + 1] = config_options[i].default_value;
- }
-
- return data;
-}
-#endif
-
-const struct mg_option *mg_get_valid_options(void)
-{
- return config_options;
-}
-
-
-static int is_file_in_memory(struct mg_connection *conn, const char *path,
- struct file *filep)
-{
- size_t size = 0;
- if ((filep->membuf = conn->ctx->callbacks.open_file == NULL ? NULL :
- conn->ctx->callbacks.open_file(conn, path, &size)) != NULL) {
- /* NOTE: override filep->size only on success. Otherwise, it might
- break constructs like if (!mg_stat() || !mg_fopen()) ... */
- filep->size = size;
- }
- return filep->membuf != NULL;
-}
-
-static int is_file_opened(const struct file *filep)
-{
- return filep->membuf != NULL || filep->fp != NULL;
-}
-
-static int mg_fopen(struct mg_connection *conn, const char *path,
- const char *mode, struct file *filep)
-{
- if (!is_file_in_memory(conn, path, filep)) {
-#ifdef _WIN32
- wchar_t wbuf[PATH_MAX], wmode[20];
- to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
- MultiByteToWideChar(CP_UTF8, 0, mode, -1, wmode, ARRAY_SIZE(wmode));
- filep->fp = _wfopen(wbuf, wmode);
-#else
- filep->fp = fopen(path, mode);
-#endif
- }
-
- return is_file_opened(filep);
-}
-
-static void mg_fclose(struct file *filep)
-{
- if (filep != NULL && filep->fp != NULL) {
- fclose(filep->fp);
- }
-}
-
-static void mg_strlcpy(register char *dst, register const char *src, size_t n)
-{
- for (; *src != '\0' && n > 1; n--) {
- *dst++ = *src++;
- }
- *dst = '\0';
-}
-
-static int lowercase(const char *s)
-{
- return tolower(* (const unsigned char *) s);
-}
-
-int mg_strncasecmp(const char *s1, const char *s2, size_t len)
-{
- int diff = 0;
-
- if (len > 0)
- do {
- diff = lowercase(s1++) - lowercase(s2++);
- } while (diff == 0 && s1[-1] != '\0' && --len > 0);
-
- return diff;
-}
-
-static int mg_strcasecmp(const char *s1, const char *s2)
-{
- int diff;
-
- do {
- diff = lowercase(s1++) - lowercase(s2++);
- } while (diff == 0 && s1[-1] != '\0');
-
- return diff;
-}
-
-static char * mg_strndup(const char *ptr, size_t len)
-{
- char *p;
-
- if ((p = (char *) mg_malloc(len + 1)) != NULL) {
- mg_strlcpy(p, ptr, len + 1);
- }
-
- return p;
-}
-
-static char * mg_strdup(const char *str)
-{
- return mg_strndup(str, strlen(str));
-}
-
-static const char *mg_strcasestr(const char *big_str, const char *small_str)
-{
- int i, big_len = (int)strlen(big_str), small_len = (int)strlen(small_str);
-
- for (i = 0; i <= big_len - small_len; i++) {
- if (mg_strncasecmp(big_str + i, small_str, small_len) == 0) {
- return big_str + i;
- }
- }
-
- return NULL;
-}
-
-/* Like snprintf(), but never returns negative value, or a value
- that is larger than a supplied buffer.
- Thanks to Adam Zeldis to pointing snprintf()-caused vulnerability
- in his audit report. */
-static int mg_vsnprintf(struct mg_connection *conn, char *buf, size_t buflen,
- const char *fmt, va_list ap)
-{
- int n;
-
- if (buflen == 0)
- return 0;
-
- n = vsnprintf(buf, buflen, fmt, ap);
-
- if (n < 0) {
- mg_cry(conn, "vsnprintf error");
- n = 0;
- } else if (n >= (int) buflen) {
- mg_cry(conn, "truncating vsnprintf buffer: [%.*s]",
- n > 200 ? 200 : n, buf);
- n = (int) buflen - 1;
- }
- buf[n] = '\0';
-
- return n;
-}
-
-static int mg_snprintf(struct mg_connection *conn, char *buf, size_t buflen,
- PRINTF_FORMAT_STRING(const char *fmt), ...)
-PRINTF_ARGS(4, 5);
-
-static int mg_snprintf(struct mg_connection *conn, char *buf, size_t buflen,
- const char *fmt, ...)
-{
- va_list ap;
- int n;
-
- va_start(ap, fmt);
- n = mg_vsnprintf(conn, buf, buflen, fmt, ap);
- va_end(ap);
-
- return n;
-}
-
-static int get_option_index(const char *name)
-{
- int i;
-
- for (i = 0; config_options[i].name != NULL; i++) {
- if (strcmp(config_options[i].name, name) == 0) {
- return i;
- }
- }
- return -1;
-}
-
-const char *mg_get_option(const struct mg_context *ctx, const char *name)
-{
- int i;
- if ((i = get_option_index(name)) == -1) {
- return NULL;
- } else if (ctx->config[i] == NULL) {
- return "";
- } else {
- return ctx->config[i];
- }
-}
-
-struct mg_context *mg_get_context(struct mg_connection * conn)
-{
- return (conn == NULL) ? (struct mg_context *)NULL : (conn->ctx);
-}
-
-void *mg_get_user_data(struct mg_context *ctx)
-{
- return (ctx == NULL) ? NULL : ctx->user_data;
-}
-
-size_t mg_get_ports(const struct mg_context *ctx, size_t size, int* ports, int* ssl)
-{
- size_t i;
- for (i = 0; i < size && i < (size_t)ctx->num_listening_sockets; i++)
- {
- ssl[i] = ctx->listening_sockets[i].is_ssl;
- ports[i] = ctx->listening_ports[i];
- }
- return i;
-}
-
-static void sockaddr_to_string(char *buf, size_t len,
- const union usa *usa)
-{
- buf[0] = '\0';
-#if defined(USE_IPV6)
- inet_ntop(usa->sa.sa_family, usa->sa.sa_family == AF_INET ?
- (void *) &usa->sin.sin_addr :
- (void *) &usa->sin6.sin6_addr, buf, len);
-#elif defined(_WIN32)
- /* Only Windows Vista (and newer) have inet_ntop() */
- mg_strlcpy(buf, inet_ntoa(usa->sin.sin_addr), len);
-#else
- inet_ntop(usa->sa.sa_family, (void *) &usa->sin.sin_addr, buf, len);
-#endif
-}
-
-/* Convert time_t to a string. According to RFC2616, Sec 14.18, this must be included in all responses other than 100, 101, 5xx. */
-static void gmt_time_string(char *buf, size_t buf_len, time_t *t)
-{
- struct tm *tm;
-
- tm = gmtime(t);
- if (tm != NULL) {
- strftime(buf, buf_len, "%a, %d %b %Y %H:%M:%S GMT", tm);
- } else {
- mg_strlcpy(buf, "Thu, 01 Jan 1970 00:00:00 GMT", buf_len);
- buf[buf_len - 1] = '\0';
- }
-}
-
-/* Print error message to the opened error log stream. */
-void mg_cry(struct mg_connection *conn, const char *fmt, ...)
-{
- char buf[MG_BUF_LEN], src_addr[IP_ADDR_STR_LEN];
- va_list ap;
- FILE *fp;
- time_t timestamp;
-
- va_start(ap, fmt);
- IGNORE_UNUSED_RESULT(vsnprintf(buf, sizeof(buf), fmt, ap));
- va_end(ap);
-
- /* Do not lock when getting the callback value, here and below.
- I suppose this is fine, since function cannot disappear in the
- same way string option can. */
- if (conn->ctx->callbacks.log_message == NULL ||
- conn->ctx->callbacks.log_message(conn, buf) == 0) {
- fp = conn->ctx->config[ERROR_LOG_FILE] == NULL ? NULL :
- fopen(conn->ctx->config[ERROR_LOG_FILE], "a+");
-
- if (fp != NULL) {
- flockfile(fp);
- timestamp = time(NULL);
-
- sockaddr_to_string(src_addr, sizeof(src_addr), &conn->client.rsa);
- fprintf(fp, "[%010lu] [error] [client %s] ", (unsigned long) timestamp,
- src_addr);
-
- if (conn->request_info.request_method != NULL) {
- fprintf(fp, "%s %s: ", conn->request_info.request_method,
- conn->request_info.uri);
- }
-
- fprintf(fp, "%s", buf);
- fputc('\n', fp);
- funlockfile(fp);
- fclose(fp);
- }
- }
-}
-
-/* Return fake connection structure. Used for logging, if connection
- is not applicable at the moment of logging. */
-static struct mg_connection *fc(struct mg_context *ctx)
-{
- static struct mg_connection fake_connection;
- fake_connection.ctx = ctx;
- return &fake_connection;
-}
-
-const char *mg_version(void)
-{
- return CIVETWEB_VERSION;
-}
-
-struct mg_request_info *mg_get_request_info(struct mg_connection *conn)
-{
- return &conn->request_info;
-}
-
-/* Skip the characters until one of the delimiters characters found.
- 0-terminate resulting word. Skip the delimiter and following whitespaces.
- Advance pointer to buffer to the next word. Return found 0-terminated word.
- Delimiters can be quoted with quotechar. */
-static char *skip_quoted(char **buf, const char *delimiters,
- const char *whitespace, char quotechar)
-{
- char *p, *begin_word, *end_word, *end_whitespace;
-
- begin_word = *buf;
- end_word = begin_word + strcspn(begin_word, delimiters);
-
- /* Check for quotechar */
- if (end_word > begin_word) {
- p = end_word - 1;
- while (*p == quotechar) {
- /* TODO (bel): it seems this code is never reached, so quotechar is actually
- not needed - check if this code may be droped */
-
- /* If there is anything beyond end_word, copy it */
- if (*end_word == '\0') {
- *p = '\0';
- break;
- } else {
- size_t end_off = strcspn(end_word + 1, delimiters);
- memmove (p, end_word, end_off + 1);
- p += end_off; /* p must correspond to end_word - 1 */
- end_word += end_off + 1;
- }
- }
- for (p++; p < end_word; p++) {
- *p = '\0';
- }
- }
-
- if (*end_word == '\0') {
- *buf = end_word;
- } else {
- end_whitespace = end_word + 1 + strspn(end_word + 1, whitespace);
-
- for (p = end_word; p < end_whitespace; p++) {
- *p = '\0';
- }
-
- *buf = end_whitespace;
- }
-
- return begin_word;
-}
-
-/* Simplified version of skip_quoted without quote char
- and whitespace == delimiters */
-static char *skip(char **buf, const char *delimiters)
-{
- return skip_quoted(buf, delimiters, delimiters, 0);
-}
-
-
-/* Return HTTP header value, or NULL if not found. */
-static const char *get_header(const struct mg_request_info *ri,
- const char *name)
-{
- int i;
-
- for (i = 0; i < ri->num_headers; i++)
- if (!mg_strcasecmp(name, ri->http_headers[i].name))
- return ri->http_headers[i].value;
-
- return NULL;
-}
-
-const char *mg_get_header(const struct mg_connection *conn, const char *name)
-{
- return get_header(&conn->request_info, name);
-}
-
-/* A helper function for traversing a comma separated list of values.
- It returns a list pointer shifted to the next value, or NULL if the end
- of the list found.
- Value is stored in val vector. If value has form "x=y", then eq_val
- vector is initialized to point to the "y" part, and val vector length
- is adjusted to point only to "x". */
-static const char *next_option(const char *list, struct vec *val,
- struct vec *eq_val)
-{
- if (list == NULL || *list == '\0') {
- /* End of the list */
- list = NULL;
- } else {
- val->ptr = list;
- if ((list = strchr(val->ptr, ',')) != NULL) {
- /* Comma found. Store length and shift the list ptr */
- val->len = list - val->ptr;
- list++;
- } else {
- /* This value is the last one */
- list = val->ptr + strlen(val->ptr);
- val->len = list - val->ptr;
- }
-
- if (eq_val != NULL) {
- /* Value has form "x=y", adjust pointers and lengths
- so that val points to "x", and eq_val points to "y". */
- eq_val->len = 0;
- eq_val->ptr = (const char *) memchr(val->ptr, '=', val->len);
- if (eq_val->ptr != NULL) {
- eq_val->ptr++; /* Skip over '=' character */
- eq_val->len = val->ptr + val->len - eq_val->ptr;
- val->len = (eq_val->ptr - val->ptr) - 1;
- }
- }
- }
-
- return list;
-}
-
-/* Perform case-insensitive match of string against pattern */
-static int match_prefix(const char *pattern, int pattern_len, const char *str)
-{
- const char *or_str;
- int i, j, len, res;
-
- if ((or_str = (const char *) memchr(pattern, '|', pattern_len)) != NULL) {
- res = match_prefix(pattern, (int)(or_str - pattern), str);
- return res > 0 ? res :
- match_prefix(or_str + 1, (int)((pattern + pattern_len) - (or_str + 1)), str);
- }
-
- i = j = 0;
- for (; i < pattern_len; i++, j++) {
- if (pattern[i] == '?' && str[j] != '\0') {
- continue;
- } else if (pattern[i] == '$') {
- return str[j] == '\0' ? j : -1;
- } else if (pattern[i] == '*') {
- i++;
- if (pattern[i] == '*') {
- i++;
- len = (int) strlen(str + j);
- } else {
- len = (int) strcspn(str + j, "/");
- }
- if (i == pattern_len) {
- return j + len;
- }
- do {
- res = match_prefix(pattern + i, pattern_len - i, str + j + len);
- } while (res == -1 && len-- > 0);
- return res == -1 ? -1 : j + res + len;
- } else if (lowercase(&pattern[i]) != lowercase(&str[j])) {
- return -1;
- }
- }
- return j;
-}
-
-/* HTTP 1.1 assumes keep alive if "Connection:" header is not set
- This function must tolerate situations when connection info is not
- set up, for example if request parsing failed. */
-static int should_keep_alive(const struct mg_connection *conn)
-{
- const char *http_version = conn->request_info.http_version;
- const char *header = mg_get_header(conn, "Connection");
- if (conn->must_close ||
- conn->status_code == 401 ||
- mg_strcasecmp(conn->ctx->config[ENABLE_KEEP_ALIVE], "yes") != 0 ||
- (header != NULL && mg_strcasecmp(header, "keep-alive") != 0) ||
- (header == NULL && http_version && 0!=strcmp(http_version, "1.1"))) {
- return 0;
- }
- return 1;
-}
-
-static int should_decode_url(const struct mg_connection *conn)
-{
- return (mg_strcasecmp(conn->ctx->config[DECODE_URL], "yes") == 0);
-}
-
-static const char *suggest_connection_header(const struct mg_connection *conn)
-{
- return should_keep_alive(conn) ? "keep-alive" : "close";
-}
-
-static void handle_file_based_request(struct mg_connection *conn, const char *path, struct file *filep);
-static int mg_stat(struct mg_connection *conn, const char *path, struct file *filep);
-
-static const char *mg_get_response_code_text(int response_code, struct mg_connection *conn)
-{
- switch (response_code)
- {
- /* RFC2616 Section 10.1 - Informational 1xx */
- case 100: return "Continue"; /* RFC2616 Section 10.1.1 */
- case 101: return "Switching Protocols"; /* RFC2616 Section 10.1.2 */
- case 102: return "Processing"; /* RFC2518 Section 10.1 */
-
- /* RFC2616 Section 10.2 - Successful 2xx */
- case 200: return "OK"; /* RFC2616 Section 10.2.1 */
- case 201: return "Created"; /* RFC2616 Section 10.2.2 */
- case 202: return "Accepted"; /* RFC2616 Section 10.2.3 */
- case 203: return "Non-Authoritative Information"; /* RFC2616 Section 10.2.4 */
- case 204: return "No Content"; /* RFC2616 Section 10.2.5 */
- case 205: return "Reset Content"; /* RFC2616 Section 10.2.6 */
- case 206: return "Partial Content"; /* RFC2616 Section 10.2.7 */
- case 207: return "Multi-Status"; /* RFC2518 Section 10.2, RFC4918 Section 11.1 */
-
- /* RFC2616 Section 10.3 - Redirection 3xx */
- case 300: return "Multiple Choices"; /* RFC2616 Section 10.3.1 */
- case 301: return "Moved Permanently"; /* RFC2616 Section 10.3.2 */
- case 302: return "Found"; /* RFC2616 Section 10.3.3 */
- case 303: return "See Other"; /* RFC2616 Section 10.3.4 */
- case 304: return "Not Modified"; /* RFC2616 Section 10.3.5 */
- case 305: return "Use Proxy"; /* RFC2616 Section 10.3.6 */
- case 307: return "Temporary Redirect"; /* RFC2616 Section 10.3.8 */
-
- /* RFC2616 Section 10.4 - Client Error 4xx */
- case 400: return "Bad Request"; /* RFC2616 Section 10.4.1 */
- case 401: return "Unauthorized"; /* RFC2616 Section 10.4.2 */
- case 402: return "Payment Required"; /* RFC2616 Section 10.4.3 */
- case 403: return "Forbidden"; /* RFC2616 Section 10.4.4 */
- case 404: return "Not Found"; /* RFC2616 Section 10.4.5 */
- case 405: return "Method Not Allowed"; /* RFC2616 Section 10.4.6 */
- case 406: return "Not Acceptable"; /* RFC2616 Section 10.4.7 */
- case 407: return "Proxy Authentication Required"; /* RFC2616 Section 10.4.8 */
- case 408: return "Request Time-out"; /* RFC2616 Section 10.4.9 */
- case 409: return "Conflict"; /* RFC2616 Section 10.4.10 */
- case 410: return "Gone"; /* RFC2616 Section 10.4.11 */
- case 411: return "Length Required"; /* RFC2616 Section 10.4.12 */
- case 412: return "Precondition Failed"; /* RFC2616 Section 10.4.13 */
- case 413: return "Request Entity Too Large"; /* RFC2616 Section 10.4.14 */
- case 414: return "Request-URI Too Large"; /* RFC2616 Section 10.4.15 */
- case 415: return "Unsupported Media Type"; /* RFC2616 Section 10.4.16 */
- case 416: return "Requested range not satisfiable"; /* RFC2616 Section 10.4.17 */
- case 417: return "Expectation Failed"; /* RFC2616 Section 10.4.18 */
- case 422: return "Unproccessable entity"; /* RFC2518 Section 10.3, RFC4918 Section 11.2 */
- case 423: return "Locked"; /* RFC2518 Section 10.4, RFC4918 Section 11.3 */
- case 424: return "Failed Dependency"; /* RFC2518 Section 10.5, RFC4918 Section 11.4 */
- case 428: return "Precondition Required"; /* RFC 6585, Section 3 */
- case 429: return "Too Many Requests"; /* RFC 6585, Section 4 */
- case 431: return "Request Header Fields Too Large"; /* RFC 6585, Section 5 */
-
- /* RFC2616 Section 10.5 - Server Error 5xx */
- case 500: return "Internal Server Error"; /* RFC2616 Section 10.5.1 */
- case 501: return "Not Implemented"; /* RFC2616 Section 10.5.2 */
- case 502: return "Bad Gateway"; /* RFC2616 Section 10.5.3 */
- case 503: return "Service Unavailable"; /* RFC2616 Section 10.5.4 */
- case 504: return "Gateway Time-out"; /* RFC2616 Section 10.5.5 */
- case 505: return "HTTP Version not supported"; /* RFC2616 Section 10.5.6 */
- case 507: return "Insufficient Storage"; /* RFC2518 Section 10.6, , RFC4918 Section 11.5 */
- case 511: return "Network Authentication Required"; /* RFC 6585, Section 6 */
-
- /* Other RFCs */
- case 426: return "Upgrade Required"; /* RFC 2817 */
-
- /* Return codes from non normative RFCs: */
- /* Informative and experimental RFCs, "de facto" standards due to common use, ... */
- case 208: return "Already Reported"; /* RFC5842 Section 7.1 */
- case 226: return "IM used"; /* RFC3229 Section 10.4.1 */
- case 308: return "Permanent Redirect"; /* RFC7238 Section 3 */
- case 418: return "I am a teapot"; /* RFC2324 Section 2.3.2 */
- case 419: return "Authentication Timeout"; /* common use */
- case 451: return "Unavailable For Legal Reasons"; /* draft-tbray-http-legally-restricted-status-05, Section 3 */
- case 506: return "Variant Also Negotiates"; /* RFC 2295, Section 8.1 */
- case 508: return "Loop Detected"; /* RFC5842 Section 7.1 */
- case 510: return "Not Extended"; /* RFC 2774, Section 7 */
-
- default:
- /* This error code is unknown. This should not happen. */
- if (conn) {
- mg_cry(conn, "Unknown HTTP response code: %u", response_code);
- }
-
- /* Return at least a category according to RFC 2616 Section 10. */
- if (response_code>=100 && response_code<200) {
- /* Unknown informational status code */
- return "Information";
- }
- if (response_code>=200 && response_code<300) {
- /* Unknown success code */
- return "Success";
- }
- if (response_code>=300 && response_code<400) {
- /* Unknown redirection code */
- return "Redirection";
- }
- if (response_code>=400 && response_code<500) {
- /* Unknown request error code */
- return "Client Error";
- }
- if (response_code>=500 && response_code<600) {
- /* Unknown server error code */
- return "Server Error";
- }
-
- /* Response code not even within reasonable range */
- return "";
- }
-}
-
-
-static void send_http_error(struct mg_connection *, int, const char *,
- PRINTF_FORMAT_STRING(const char *fmt), ...)
-PRINTF_ARGS(4, 5);
-
-
-static void send_http_error(struct mg_connection *conn, int status,
- const char *reason, const char *fmt, ...)
-{
- char buf[MG_BUF_LEN];
- va_list ap;
- int len = 0, i, page_handler_found, scope;
- char date[64];
- time_t curtime = time(NULL);
- const char *error_handler = NULL;
- struct file error_page_file = STRUCT_FILE_INITIALIZER;
- const char *error_page_file_ext, *tstr;
-
- if (!reason) {
- reason = mg_get_response_code_text(status, conn);
- }
-
- conn->status_code = status;
- if (conn->in_error_handler ||
- conn->ctx->callbacks.http_error == NULL ||
- conn->ctx->callbacks.http_error(conn, status)) {
-
- if (!conn->in_error_handler) {
- /* Send user defined error pages, if defined */
- error_handler = conn->ctx->config[ERROR_PAGES];
- error_page_file_ext = conn->ctx->config[INDEX_FILES];
- page_handler_found = 0;
- if (error_handler != NULL) {
- for (scope=1; (scope<=3) && !page_handler_found; scope++) {
- switch (scope) {
- case 1:
- len = mg_snprintf(conn, buf, sizeof(buf)-32, "%serror%03u.", error_handler, status);
- break;
- case 2:
- len = mg_snprintf(conn, buf, sizeof(buf)-32, "%serror%01uxx.", error_handler, status/100);
- break;
- default:
- len = mg_snprintf(conn, buf, sizeof(buf)-32, "%serror.", error_handler);
- break;
- }
- tstr = strchr(error_page_file_ext, '.');
- while (tstr) {
- for (i=1; i<32 && tstr[i]!=0 && tstr[i]!=','; i++) buf[len+i-1]=tstr[i];
- buf[len+i-1]=0;
- if (mg_stat(conn, buf, &error_page_file)) {
- page_handler_found = 1;
- break;
- }
- tstr = strchr(tstr+i, '.');
- }
- }
- }
-
- if (page_handler_found) {
- conn->in_error_handler = 1;
- handle_file_based_request(conn, buf, &error_page_file);
- conn->in_error_handler = 0;
- return;
- }
- }
-
- buf[0] = '\0';
- gmt_time_string(date, sizeof(date), &curtime);
-
- /* Errors 1xx, 204 and 304 MUST NOT send a body */
- if (status > 199 && status != 204 && status != 304) {
- len = mg_snprintf(conn, buf, sizeof(buf)-1, "Error %d: %s", status, reason);
- buf[len] = '\n';
- len++;
- buf[len] = 0;
-
- va_start(ap, fmt);
- len += mg_vsnprintf(conn, buf + len, sizeof(buf) - len, fmt, ap);
- va_end(ap);
- }
- DEBUG_TRACE("[%s]", buf);
-
- mg_printf(conn, "HTTP/1.1 %d %s\r\n"
- "Content-Length: %d\r\n"
- "Date: %s\r\n"
- "Connection: %s\r\n\r\n",
- status, reason, len, date,
- suggest_connection_header(conn));
- conn->num_bytes_sent += mg_printf(conn, "%s", buf);
- }
-}
-
-#if defined(_WIN32) && !defined(__SYMBIAN32__)
-static int pthread_mutex_init(pthread_mutex_t *mutex, void *unused)
-{
- (void) unused;
- *mutex = CreateMutex(NULL, FALSE, NULL);
- return *mutex == NULL ? -1 : 0;
-}
-
-static int pthread_mutex_destroy(pthread_mutex_t *mutex)
-{
- return CloseHandle(*mutex) == 0 ? -1 : 0;
-}
-
-static int pthread_mutex_lock(pthread_mutex_t *mutex)
-{
- return WaitForSingleObject(*mutex, INFINITE) == WAIT_OBJECT_0 ? 0 : -1;
-}
-
-static int pthread_mutex_trylock(pthread_mutex_t *mutex)
-{
- switch (WaitForSingleObject(*mutex, 0)) {
- case WAIT_OBJECT_0:
- return 0;
- case WAIT_TIMEOUT:
- return -2; /* EBUSY */
- }
- return -1;
-}
-
-static int pthread_mutex_unlock(pthread_mutex_t *mutex)
-{
- return ReleaseMutex(*mutex) == 0 ? -1 : 0;
-}
-
-#ifndef WIN_PTHREADS_TIME_H
-static int clock_gettime(clockid_t clk_id, struct timespec *tp)
-{
- FILETIME ft;
- ULARGE_INTEGER li;
- BOOL ok = FALSE;
- double d;
- static double perfcnt_per_sec = 0.0;
-
- if (tp) {
- if (clk_id == CLOCK_REALTIME) {
- GetSystemTimeAsFileTime(&ft);
- li.LowPart = ft.dwLowDateTime;
- li.HighPart = ft.dwHighDateTime;
- li.QuadPart -= 116444736000000000; /* 1.1.1970 in filedate */
- tp->tv_sec = (time_t)(li.QuadPart / 10000000);
- tp->tv_nsec = (long)(li.QuadPart % 10000000) * 100;
- ok = TRUE;
- } else if (clk_id == CLOCK_MONOTONIC) {
- if (perfcnt_per_sec == 0.0) {
- QueryPerformanceFrequency((LARGE_INTEGER *) &li);
- perfcnt_per_sec = 1.0 / li.QuadPart;
- }
- if (perfcnt_per_sec != 0.0) {
- QueryPerformanceCounter((LARGE_INTEGER *) &li);
- d = li.QuadPart * perfcnt_per_sec;
- tp->tv_sec = (time_t)d;
- d -= tp->tv_sec;
- tp->tv_nsec = (long)(d*1.0E9);
- ok = TRUE;
- }
- }
- }
-
- return ok ? 0 : -1;
-}
-#endif
-
-static int pthread_cond_init(pthread_cond_t *cv, const void *unused)
-{
- (void) unused;
- InitializeCriticalSection(&cv->threadIdSec);
- cv->waitingthreadcount = 0;
- cv->waitingthreadhdls = (pthread_t *) mg_calloc(MAX_WORKER_THREADS, sizeof(pthread_t));
- return (cv->waitingthreadhdls!=NULL) ? 0 : -1;
-}
-
-static int pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t *mutex, const struct timespec * abstime)
-{
- struct mg_workerTLS * tls = (struct mg_workerTLS *)TlsGetValue(sTlsKey);
- int ok;
- struct timespec tsnow;
- int64_t nsnow, nswaitabs, nswaitrel;
- DWORD mswaitrel;
-
- EnterCriticalSection(&cv->threadIdSec);
- assert(cv->waitingthreadcount < MAX_WORKER_THREADS);
- cv->waitingthreadhdls[cv->waitingthreadcount] = tls->pthread_cond_helper_mutex;
- cv->waitingthreadcount++;
- LeaveCriticalSection(&cv->threadIdSec);
-
- if (abstime) {
- clock_gettime(CLOCK_REALTIME, &tsnow);
- nsnow = (((uint64_t)tsnow.tv_sec)*1000000000) + tsnow.tv_nsec;
- nswaitabs = (((uint64_t)abstime->tv_sec)*1000000000) + abstime->tv_nsec;
- nswaitrel = nswaitabs - nsnow;
- if (nswaitrel<0) nswaitrel=0;
- mswaitrel = (DWORD)(nswaitrel / 1000000);
- } else {
- mswaitrel = INFINITE;
- }
-
- pthread_mutex_unlock(mutex);
- ok = (WAIT_OBJECT_0 == WaitForSingleObject(tls->pthread_cond_helper_mutex, mswaitrel));
- pthread_mutex_lock(mutex);
-
- return ok ? 0 : -1;
-}
-
-static int pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex)
-{
- return pthread_cond_timedwait(cv, mutex, NULL);
-}
-
-static int pthread_cond_signal(pthread_cond_t *cv)
-{
- int i;
- HANDLE wkup = NULL;
- BOOL ok = FALSE;
-
- EnterCriticalSection(&cv->threadIdSec);
- if (cv->waitingthreadcount) {
- wkup = cv->waitingthreadhdls[0];
- ok = SetEvent(wkup);
-
- for (i=1; i<cv->waitingthreadcount; i++) {
- cv->waitingthreadhdls[i-1] = cv->waitingthreadhdls[i];
- }
- cv->waitingthreadcount--;
-
- assert(ok);
- }
- LeaveCriticalSection(&cv->threadIdSec);
-
- return ok ? 0 : 1;
-}
-
-static int pthread_cond_broadcast(pthread_cond_t *cv)
-{
- EnterCriticalSection(&cv->threadIdSec);
- while (cv->waitingthreadcount) {
- pthread_cond_signal(cv);
- }
- LeaveCriticalSection(&cv->threadIdSec);
-
- return 0;
-}
-
-static int pthread_cond_destroy(pthread_cond_t *cv)
-{
- EnterCriticalSection(&cv->threadIdSec);
- assert(cv->waitingthreadcount==0);
- mg_free(cv->waitingthreadhdls);
- cv->waitingthreadhdls = 0;
- LeaveCriticalSection(&cv->threadIdSec);
- DeleteCriticalSection(&cv->threadIdSec);
-
- return 0;
-}
-
-/* For Windows, change all slashes to backslashes in path names. */
-static void change_slashes_to_backslashes(char *path)
-{
- int i;
-
- for (i = 0; path[i] != '\0'; i++) {
- if (path[i] == '/')
- path[i] = '\\';
- /* i > 0 check is to preserve UNC paths, like \\server\file.txt */
- if (path[i] == '\\' && i > 0)
- while (path[i + 1] == '\\' || path[i + 1] == '/')
- (void) memmove(path + i + 1,
- path + i + 2, strlen(path + i + 1));
- }
-}
-
-/* Encode 'path' which is assumed UTF-8 string, into UNICODE string.
- wbuf and wbuf_len is a target buffer and its length. */
-static void to_unicode(const char *path, wchar_t *wbuf, size_t wbuf_len)
-{
- char buf[PATH_MAX], buf2[PATH_MAX];
-
- mg_strlcpy(buf, path, sizeof(buf));
- change_slashes_to_backslashes(buf);
-
- /* Convert to Unicode and back. If doubly-converted string does not
- match the original, something is fishy, reject. */
- memset(wbuf, 0, wbuf_len * sizeof(wchar_t));
- MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, (int) wbuf_len);
- WideCharToMultiByte(CP_UTF8, 0, wbuf, (int) wbuf_len, buf2, sizeof(buf2),
- NULL, NULL);
- if (strcmp(buf, buf2) != 0) {
- wbuf[0] = L'\0';
- }
-}
-
-#if defined(_WIN32_WCE)
-static time_t time(time_t *ptime)
-{
- time_t t;
- SYSTEMTIME st;
- FILETIME ft;
-
- GetSystemTime(&st);
- SystemTimeToFileTime(&st, &ft);
- t = SYS2UNIX_TIME(ft.dwLowDateTime, ft.dwHighDateTime);
-
- if (ptime != NULL) {
- *ptime = t;
- }
-
- return t;
-}
-
-static struct tm *localtime(const time_t *ptime, struct tm *ptm)
-{
- int64_t t = ((int64_t) *ptime) * RATE_DIFF + EPOCH_DIFF;
- FILETIME ft, lft;
- SYSTEMTIME st;
- TIME_ZONE_INFORMATION tzinfo;
-
- if (ptm == NULL) {
- return NULL;
- }
-
- * (int64_t *) &ft = t;
- FileTimeToLocalFileTime(&ft, &lft);
- FileTimeToSystemTime(&lft, &st);
- ptm->tm_year = st.wYear - 1900;
- ptm->tm_mon = st.wMonth - 1;
- ptm->tm_wday = st.wDayOfWeek;
- ptm->tm_mday = st.wDay;
- ptm->tm_hour = st.wHour;
- ptm->tm_min = st.wMinute;
- ptm->tm_sec = st.wSecond;
- ptm->tm_yday = 0; /* hope nobody uses this */
- ptm->tm_isdst =
- GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_DAYLIGHT ? 1 : 0;
-
- return ptm;
-}
-
-static struct tm *gmtime(const time_t *ptime, struct tm *ptm)
-{
- /* FIXME(lsm): fix this. */
- return localtime(ptime, ptm);
-}
-
-static size_t strftime(char *dst, size_t dst_size, const char *fmt,
- const struct tm *tm)
-{
- (void) snprintf(dst, dst_size, "implement strftime() for WinCE");
- return 0;
-}
-#endif
-
-/* Windows happily opens files with some garbage at the end of file name.
- For example, fopen("a.cgi ", "r") on Windows successfully opens
- "a.cgi", despite one would expect an error back.
- This function returns non-0 if path ends with some garbage. */
-static int path_cannot_disclose_cgi(const char *path)
-{
- static const char *allowed_last_characters = "_-";
- int last = path[strlen(path) - 1];
- return isalnum(last) || strchr(allowed_last_characters, last) != NULL;
-}
-
-static int mg_stat(struct mg_connection *conn, const char *path, struct file *filep)
-{
- wchar_t wbuf[PATH_MAX];
- WIN32_FILE_ATTRIBUTE_DATA info;
-
- if (!is_file_in_memory(conn, path, filep)) {
- to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
- if (GetFileAttributesExW(wbuf, GetFileExInfoStandard, &info) != 0) {
- filep->size = MAKEUQUAD(info.nFileSizeLow, info.nFileSizeHigh);
- filep->modification_time = SYS2UNIX_TIME(
- info.ftLastWriteTime.dwLowDateTime,
- info.ftLastWriteTime.dwHighDateTime);
- filep->is_directory = info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
- /* If file name is fishy, reset the file structure and return
- error.
- Note it is important to reset, not just return the error, cause
- functions like is_file_opened() check the struct. */
- if (!filep->is_directory && !path_cannot_disclose_cgi(path)) {
- memset(filep, 0, sizeof(*filep));
- }
- }
- }
-
- return filep->membuf != NULL || filep->modification_time != 0;
-}
-
-static int mg_remove(const char *path)
-{
- wchar_t wbuf[PATH_MAX];
- to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
- return DeleteFileW(wbuf) ? 0 : -1;
-}
-
-static int mg_mkdir(const char *path, int mode)
-{
- char buf[PATH_MAX];
- wchar_t wbuf[PATH_MAX];
-
- (void) mode;
- mg_strlcpy(buf, path, sizeof(buf));
- change_slashes_to_backslashes(buf);
-
- (void) MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, ARRAY_SIZE(wbuf));
-
- return CreateDirectoryW(wbuf, NULL) ? 0 : -1;
-}
-
-/* Implementation of POSIX opendir/closedir/readdir for Windows. */
-static DIR * opendir(const char *name)
-{
- DIR *dir = NULL;
- wchar_t wpath[PATH_MAX];
- DWORD attrs;
-
- if (name == NULL) {
- SetLastError(ERROR_BAD_ARGUMENTS);
- } else if ((dir = (DIR *) mg_malloc(sizeof(*dir))) == NULL) {
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- } else {
- to_unicode(name, wpath, ARRAY_SIZE(wpath));
- attrs = GetFileAttributesW(wpath);
- if (attrs != 0xFFFFFFFF &&
- ((attrs & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)) {
- (void) wcscat(wpath, L"\\*");
- dir->handle = FindFirstFileW(wpath, &dir->info);
- dir->result.d_name[0] = '\0';
- } else {
- mg_free(dir);
- dir = NULL;
- }
- }
-
- return dir;
-}
-
-static int closedir(DIR *dir)
-{
- int result = 0;
-
- if (dir != NULL) {
- if (dir->handle != INVALID_HANDLE_VALUE)
- result = FindClose(dir->handle) ? 0 : -1;
-
- mg_free(dir);
- } else {
- result = -1;
- SetLastError(ERROR_BAD_ARGUMENTS);
- }
-
- return result;
-}
-
-static struct dirent *readdir(DIR *dir)
-{
- struct dirent *result = 0;
-
- if (dir) {
- if (dir->handle != INVALID_HANDLE_VALUE) {
- result = &dir->result;
- (void) WideCharToMultiByte(CP_UTF8, 0,
- dir->info.cFileName, -1, result->d_name,
- sizeof(result->d_name), NULL, NULL);
-
- if (!FindNextFileW(dir->handle, &dir->info)) {
- (void) FindClose(dir->handle);
- dir->handle = INVALID_HANDLE_VALUE;
- }
-
- } else {
- SetLastError(ERROR_FILE_NOT_FOUND);
- }
- } else {
- SetLastError(ERROR_BAD_ARGUMENTS);
- }
-
- return result;
-}
-
-#ifndef HAVE_POLL
-static int poll(struct pollfd *pfd, int n, int milliseconds)
-{
- struct timeval tv;
- fd_set set;
- int i, result;
- SOCKET maxfd = 0;
-
- tv.tv_sec = milliseconds / 1000;
- tv.tv_usec = (milliseconds % 1000) * 1000;
- FD_ZERO(&set);
-
- for (i = 0; i < n; i++) {
- FD_SET((SOCKET) pfd[i].fd, &set);
- pfd[i].revents = 0;
-
- if (pfd[i].fd > maxfd) {
- maxfd = pfd[i].fd;
- }
- }
-
- if ((result = select((int)maxfd + 1, &set, NULL, NULL, &tv)) > 0) {
- for (i = 0; i < n; i++) {
- if (FD_ISSET(pfd[i].fd, &set)) {
- pfd[i].revents = POLLIN;
- }
- }
- }
-
- return result;
-}
-#endif /* HAVE_POLL */
-
-static void set_close_on_exec(SOCKET sock, struct mg_connection *conn /* may be null */)
-{
- (void) conn; /* Unused. */
- (void) SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0);
-}
-
-int mg_start_thread(mg_thread_func_t f, void *p)
-{
-#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
- /* Compile-time option to control stack size, e.g. -DUSE_STACK_SIZE=16384 */
- return ((_beginthread((void (__cdecl *)(void *)) f, USE_STACK_SIZE, p) == ((uintptr_t)(-1L))) ? -1 : 0);
-#else
- return ((_beginthread((void (__cdecl *)(void *)) f, 0, p) == ((uintptr_t)(-1L))) ? -1 : 0);
-#endif /* defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1) */
-}
-
-/* Start a thread storing the thread context. */
-
-static int mg_start_thread_with_id(unsigned (__stdcall *f)(void *), void *p,
- pthread_t *threadidptr)
-{
- uintptr_t uip;
- HANDLE threadhandle;
- int result = -1;
-
- uip = _beginthreadex(NULL, 0, (unsigned (__stdcall *)(void *)) f, p, 0,
- NULL);
- threadhandle = (HANDLE) uip;
- if ((uip != (uintptr_t)(-1L)) && (threadidptr != NULL)) {
- *threadidptr = threadhandle;
- result = 0;
- }
-
- return result;
-}
-
-/* Wait for a thread to finish. */
-
-static int mg_join_thread(pthread_t threadid)
-{
- int result;
- DWORD dwevent;
-
- result = -1;
- dwevent = WaitForSingleObject(threadid, INFINITE);
- if (dwevent == WAIT_FAILED) {
- int err;
-
- err = GetLastError();
- DEBUG_TRACE("WaitForSingleObject() failed, error %d", err);
- } else {
- if (dwevent == WAIT_OBJECT_0) {
- CloseHandle(threadid);
- result = 0;
- }
- }
-
- return result;
-}
-
-static HANDLE dlopen(const char *dll_name, int flags)
-{
- wchar_t wbuf[PATH_MAX];
- (void) flags;
- to_unicode(dll_name, wbuf, ARRAY_SIZE(wbuf));
- return LoadLibraryW(wbuf);
-}
-
-static int dlclose(void *handle)
-{
- int result;
-
- if (FreeLibrary((HMODULE) handle) != 0) {
- result = 0;
- } else {
- result = -1;
- }
-
- return result;
-}
-
-#if !defined(NO_CGI)
-#define SIGKILL 0
-static int kill(pid_t pid, int sig_num)
-{
- (void) TerminateProcess(pid, sig_num);
- (void) CloseHandle(pid);
- return 0;
-}
-
-static void trim_trailing_whitespaces(char *s)
-{
- char *e = s + strlen(s) - 1;
- while (e > s && isspace(* (unsigned char *) e)) {
- *e-- = '\0';
- }
-}
-
-static pid_t spawn_process(struct mg_connection *conn, const char *prog,
- char *envblk, char *envp[], int fdin,
- int fdout, const char *dir)
-{
- HANDLE me;
- char *p, *interp, full_interp[PATH_MAX], full_dir[PATH_MAX],
- cmdline[PATH_MAX], buf[PATH_MAX];
- struct file file = STRUCT_FILE_INITIALIZER;
- STARTUPINFOA si;
- PROCESS_INFORMATION pi = { 0 };
-
- (void) envp;
-
- memset(&si, 0, sizeof(si));
- si.cb = sizeof(si);
-
- /* TODO(lsm): redirect CGI errors to the error log file */
- si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
- si.wShowWindow = SW_HIDE;
-
- me = GetCurrentProcess();
- DuplicateHandle(me, (HANDLE) _get_osfhandle(fdin), me,
- &si.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS);
- DuplicateHandle(me, (HANDLE) _get_osfhandle(fdout), me,
- &si.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS);
-
- /* If CGI file is a script, try to read the interpreter line */
- interp = conn->ctx->config[CGI_INTERPRETER];
- if (interp == NULL) {
- buf[0] = buf[1] = '\0';
-
- /* Read the first line of the script into the buffer */
- snprintf(cmdline, sizeof(cmdline), "%s%c%s", dir, '/', prog);
- if (mg_fopen(conn, cmdline, "r", &file)) {
- p = (char *) file.membuf;
- mg_fgets(buf, sizeof(buf), &file, &p);
- mg_fclose(&file);
- buf[sizeof(buf) - 1] = '\0';
- }
-
- if (buf[0] == '#' && buf[1] == '!') {
- trim_trailing_whitespaces(buf + 2);
- } else {
- buf[2] = '\0';
- }
- interp = buf + 2;
- }
-
- if (interp[0] != '\0') {
- GetFullPathNameA(interp, sizeof(full_interp), full_interp, NULL);
- interp = full_interp;
- }
- GetFullPathNameA(dir, sizeof(full_dir), full_dir, NULL);
-
- mg_snprintf(conn, cmdline, sizeof(cmdline), "%s%s\"%s\\%s\"",
- interp, interp[0] == '\0' ? "" : " ", full_dir, prog);
-
- DEBUG_TRACE("Running [%s]", cmdline);
- if (CreateProcessA(NULL, cmdline, NULL, NULL, TRUE,
- CREATE_NEW_PROCESS_GROUP, envblk, NULL, &si, &pi) == 0) {
- mg_cry(conn, "%s: CreateProcess(%s): %ld",
- __func__, cmdline, ERRNO);
- pi.hProcess = (pid_t) -1;
- }
-
- (void) CloseHandle(si.hStdOutput);
- (void) CloseHandle(si.hStdInput);
- if (pi.hThread != NULL)
- (void) CloseHandle(pi.hThread);
-
- return (pid_t) pi.hProcess;
-}
-#endif /* !NO_CGI */
-
-static int set_non_blocking_mode(SOCKET sock)
-{
- unsigned long on = 1;
- return ioctlsocket(sock, FIONBIO, &on);
-}
-
-#else
-static int mg_stat(struct mg_connection *conn, const char *path,
- struct file *filep)
-{
- struct stat st;
-
- if (!is_file_in_memory(conn, path, filep) && !stat(path, &st)) {
- filep->size = st.st_size;
- filep->modification_time = st.st_mtime;
- filep->is_directory = S_ISDIR(st.st_mode);
- } else {
- filep->modification_time = (time_t) 0;
- }
-
- return filep->membuf != NULL || filep->modification_time != (time_t) 0;
-}
-
-static void set_close_on_exec(int fd, struct mg_connection *conn /* may be null */)
-{
- if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) {
- if (conn) {
- mg_cry(conn, "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s", __func__, strerror(ERRNO));
- }
- }
-}
-
-int mg_start_thread(mg_thread_func_t func, void *param)
-{
- pthread_t thread_id;
- pthread_attr_t attr;
- int result;
-
- (void) pthread_attr_init(&attr);
- (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
-#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
- /* Compile-time option to control stack size,
- e.g. -DUSE_STACK_SIZE=16384 */
- (void) pthread_attr_setstacksize(&attr, USE_STACK_SIZE);
-#endif /* defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1) */
-
- result = pthread_create(&thread_id, &attr, func, param);
- pthread_attr_destroy(&attr);
-
- return result;
-}
-
-/* Start a thread storing the thread context. */
-
-static int mg_start_thread_with_id(mg_thread_func_t func, void *param, pthread_t *threadidptr)
-{
- pthread_t thread_id;
- pthread_attr_t attr;
- int result;
-
- (void) pthread_attr_init(&attr);
-
-#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
- /* Compile-time option to control stack size,
- e.g. -DUSE_STACK_SIZE=16384 */
- (void) pthread_attr_setstacksize(&attr, USE_STACK_SIZE);
-#endif /* defined(USE_STACK_SIZE) && USE_STACK_SIZE > 1 */
-
- result = pthread_create(&thread_id, &attr, func, param);
- pthread_attr_destroy(&attr);
- if ((result == 0) && (threadidptr != NULL)) {
- *threadidptr = thread_id;
- }
- return result;
-}
-
-/* Wait for a thread to finish. */
-
-static int mg_join_thread(pthread_t threadid)
-{
- int result;
-
- result = pthread_join(threadid, NULL);
- return result;
-}
-
-#ifndef NO_CGI
-static pid_t spawn_process(struct mg_connection *conn, const char *prog,
- char *envblk, char *envp[], int fdin,
- int fdout, const char *dir)
-{
- pid_t pid;
- const char *interp;
-
- (void) envblk;
-
- if ((pid = fork()) == -1) {
- /* Parent */
- send_http_error(conn, 500, NULL,
- "Error: Creating CGI process\nfork(): %s", strerror(ERRNO));
- } else if (pid == 0) {
- /* Child */
- if (chdir(dir) != 0) {
- mg_cry(conn, "%s: chdir(%s): %s", __func__, dir, strerror(ERRNO));
- } else if (dup2(fdin, 0) == -1) {
- mg_cry(conn, "%s: dup2(%d, 0): %s", __func__, fdin, strerror(ERRNO));
- } else if (dup2(fdout, 1) == -1) {
- mg_cry(conn, "%s: dup2(%d, 1): %s", __func__, fdout, strerror(ERRNO));
- } else {
- /* Not redirecting stderr to stdout, to avoid output being littered
- with the error messages. */
- (void) close(fdin);
- (void) close(fdout);
-
- /* After exec, all signal handlers are restored to their default
- values, with one exception of SIGCHLD. According to
- POSIX.1-2001 and Linux's implementation, SIGCHLD's handler will
- leave unchanged after exec if it was set to be ignored. Restore
- it to default action. */
- signal(SIGCHLD, SIG_DFL);
-
- interp = conn->ctx->config[CGI_INTERPRETER];
- if (interp == NULL) {
- (void) execle(prog, prog, NULL, envp);
- mg_cry(conn, "%s: execle(%s): %s", __func__, prog, strerror(ERRNO));
- } else {
- (void) execle(interp, interp, prog, NULL, envp);
- mg_cry(conn, "%s: execle(%s %s): %s", __func__, interp, prog,
- strerror(ERRNO));
- }
- }
- exit(EXIT_FAILURE);
- }
-
- return pid;
-}
-#endif /* !NO_CGI */
-
-static int set_non_blocking_mode(SOCKET sock)
-{
- int flags;
-
- flags = fcntl(sock, F_GETFL, 0);
- (void) fcntl(sock, F_SETFL, flags | O_NONBLOCK);
-
- return 0;
-}
-#endif /* _WIN32 */
-
-/* Write data to the IO channel - opened file descriptor, socket or SSL
- descriptor. Return number of bytes written. */
-static int64_t push(FILE *fp, SOCKET sock, SSL *ssl, const char *buf, int64_t len)
-{
- int64_t sent;
- int n, k;
-
- (void) ssl; /* Get rid of warning */
- sent = 0;
- while (sent < len) {
-
- /* How many bytes we send in this iteration */
- k = len - sent > INT_MAX ? INT_MAX : (int) (len - sent);
-
-#ifndef NO_SSL
- if (ssl != NULL) {
- n = SSL_write(ssl, buf + sent, k);
- } else
-#endif
- if (fp != NULL) {
- n = (int) fwrite(buf + sent, 1, (size_t) k, fp);
- if (ferror(fp))
- n = -1;
- } else {
- n = send(sock, buf + sent, (size_t) k, MSG_NOSIGNAL);
- }
-
- if (n <= 0)
- break;
-
- sent += n;
- }
-
- return sent;
-}
-
-/* Read from IO channel - opened file descriptor, socket, or SSL descriptor.
- Return negative value on error, or number of bytes read on success. */
-static int pull(FILE *fp, struct mg_connection *conn, char *buf, int len)
-{
- int nread;
-
- if (fp != NULL) {
- /* Use read() instead of fread(), because if we're reading from the
- CGI pipe, fread() may block until IO buffer is filled up. We cannot
- afford to block and must pass all read bytes immediately to the
- client. */
- nread = read(fileno(fp), buf, (size_t) len);
-#ifndef NO_SSL
- } else if (conn->ssl != NULL) {
- nread = SSL_read(conn->ssl, buf, len);
-#endif
- } else {
- nread = recv(conn->client.sock, buf, (size_t) len, 0);
- }
-
- return conn->ctx->stop_flag ? -1 : nread;
-}
-
-static int pull_all(FILE *fp, struct mg_connection *conn, char *buf, int len)
-{
- int n, nread = 0;
-
- while (len > 0 && conn->ctx->stop_flag == 0) {
- n = pull(fp, conn, buf + nread, len);
- if (n < 0) {
- nread = n; /* Propagate the error */
- break;
- } else if (n == 0) {
- break; /* No more data to read */
- } else {
- conn->consumed_content += n;
- nread += n;
- len -= n;
- }
- }
-
- return nread;
-}
-
-int mg_read(struct mg_connection *conn, void *buf, size_t len)
-{
- int64_t n, buffered_len, nread;
- int64_t len64 = (int64_t)(len > INT_MAX ? INT_MAX : len); /* since the return value is int, we may not read more bytes */
- const char *body;
-
- /* If Content-Length is not set for a PUT or POST request, read until socket is closed */
- if (conn->consumed_content == 0 && conn->content_len == -1) {
- conn->content_len = INT64_MAX;
- conn->must_close = 1;
- }
-
- nread = 0;
- if (conn->consumed_content < conn->content_len) {
- /* Adjust number of bytes to read. */
- int64_t left_to_read = conn->content_len - conn->consumed_content;
- if (left_to_read < len64) {
- /* Do not reade more than the total content length of the request. */
- len64 = left_to_read;
- }
-
- /* Return buffered data */
- buffered_len = (int64_t)(conn->data_len) - (int64_t)conn->request_len - conn->consumed_content;
- if (buffered_len > 0) {
- if (len64 < buffered_len) {
- buffered_len = len64;
- }
- body = conn->buf + conn->request_len + conn->consumed_content;
- memcpy(buf, body, (size_t) buffered_len);
- len64 -= buffered_len;
- conn->consumed_content += buffered_len;
- nread += buffered_len;
- buf = (char *) buf + buffered_len;
- }
-
- /* We have returned all buffered data. Read new data from the remote
- socket. */
- if ((n = pull_all(NULL, conn, (char *) buf, (int)len64)) >= 0) {
- nread += n;
- } else {
- nread = (nread > 0 ? nread : n);
- }
- }
- return (int)nread;
-}
-
-int mg_write(struct mg_connection *conn, const void *buf, size_t len)
-{
- time_t now;
- int64_t n, total, allowed;
-
- if (conn->throttle > 0) {
- if ((now = time(NULL)) != conn->last_throttle_time) {
- conn->last_throttle_time = now;
- conn->last_throttle_bytes = 0;
- }
- allowed = conn->throttle - conn->last_throttle_bytes;
- if (allowed > (int64_t) len) {
- allowed = len;
- }
- if ((total = push(NULL, conn->client.sock, conn->ssl, (const char *) buf,
- (int64_t) allowed)) == allowed) {
- buf = (char *) buf + total;
- conn->last_throttle_bytes += total;
- while (total < (int64_t) len && conn->ctx->stop_flag == 0) {
- allowed = conn->throttle > (int64_t) len - total ?
- (int64_t) len - total : conn->throttle;
- if ((n = push(NULL, conn->client.sock, conn->ssl, (const char *) buf,
- (int64_t) allowed)) != allowed) {
- break;
- }
- sleep(1);
- conn->last_throttle_bytes = allowed;
- conn->last_throttle_time = time(NULL);
- buf = (char *) buf + n;
- total += n;
- }
- }
- } else {
- total = push(NULL, conn->client.sock, conn->ssl, (const char *) buf,
- (int64_t) len);
- }
- return (int) total;
-}
-
-/* Alternative alloc_vprintf() for non-compliant C runtimes */
-static int alloc_vprintf2(char **buf, const char *fmt, va_list ap)
-{
- va_list ap_copy;
- int size = MG_BUF_LEN;
- int len = -1;
-
- *buf = NULL;
- while (len == -1) {
- if (*buf) mg_free(*buf);
- *buf = (char *)mg_malloc(size *= 4);
- if (!*buf) break;
- va_copy(ap_copy, ap);
- len = vsnprintf(*buf, size, fmt, ap_copy);
- va_end(ap_copy);
- }
-
- return len;
-}
-
-/* Print message to buffer. If buffer is large enough to hold the message,
- return buffer. If buffer is to small, allocate large enough buffer on heap,
- and return allocated buffer. */
-static int alloc_vprintf(char **buf, size_t size, const char *fmt, va_list ap)
-{
- va_list ap_copy;
- int len;
-
- /* Windows is not standard-compliant, and vsnprintf() returns -1 if
- buffer is too small. Also, older versions of msvcrt.dll do not have
- _vscprintf(). However, if size is 0, vsnprintf() behaves correctly.
- Therefore, we make two passes: on first pass, get required message
- length.
- On second pass, actually print the message. */
- va_copy(ap_copy, ap);
- len = vsnprintf(NULL, 0, fmt, ap_copy);
- va_end(ap_copy);
-
- if (len < 0) {
- /* C runtime is not standard compliant, vsnprintf() returned -1.
- Switch to alternative code path that uses incremental allocations.
- */
- va_copy(ap_copy, ap);
- len = alloc_vprintf2(buf, fmt, ap);
- va_end(ap_copy);
- } else if (len > (int) size &&
- (size = len + 1) > 0 &&
- (*buf = (char *) mg_malloc(size)) == NULL) {
- len = -1; /* Allocation failed, mark failure */
- } else {
- va_copy(ap_copy, ap);
- IGNORE_UNUSED_RESULT(vsnprintf(*buf, size, fmt, ap_copy));
- va_end(ap_copy);
- }
-
- return len;
-}
-
-int mg_vprintf(struct mg_connection *conn, const char *fmt, va_list ap)
-{
- char mem[MG_BUF_LEN], *buf = mem;
- int len;
-
- if ((len = alloc_vprintf(&buf, sizeof(mem), fmt, ap)) > 0) {
- len = mg_write(conn, buf, (size_t) len);
- }
- if (buf != mem && buf != NULL) {
- mg_free(buf);
- }
-
- return len;
-}
-
-int mg_printf(struct mg_connection *conn, const char *fmt, ...)
-{
- va_list ap;
- int result;
-
- va_start(ap, fmt);
- result = mg_vprintf(conn, fmt, ap);
- va_end(ap);
-
- return result;
-}
-
-int mg_url_decode(const char *src, int src_len, char *dst,
- int dst_len, int is_form_url_encoded)
-{
- int i, j, a, b;
-#define HEXTOI(x) (isdigit(x) ? x - '0' : x - 'W')
-
- for (i = j = 0; i < src_len && j < dst_len - 1; i++, j++) {
- if (i < src_len - 2 && src[i] == '%' &&
- isxdigit(* (const unsigned char *) (src + i + 1)) &&
- isxdigit(* (const unsigned char *) (src + i + 2))) {
- a = tolower(* (const unsigned char *) (src + i + 1));
- b = tolower(* (const unsigned char *) (src + i + 2));
- dst[j] = (char) ((HEXTOI(a) << 4) | HEXTOI(b));
- i += 2;
- } else if (is_form_url_encoded && src[i] == '+') {
- dst[j] = ' ';
- } else {
- dst[j] = src[i];
- }
- }
-
- dst[j] = '\0'; /* Null-terminate the destination */
-
- return i >= src_len ? j : -1;
-}
-
-int mg_get_var(const char *data, size_t data_len, const char *name,
- char *dst, size_t dst_len)
-{
- return mg_get_var2(data,data_len,name,dst,dst_len,0);
-}
-
-int mg_get_var2(const char *data, size_t data_len, const char *name,
- char *dst, size_t dst_len, size_t occurrence)
-{
- const char *p, *e, *s;
- size_t name_len;
- int len;
-
- if (dst == NULL || dst_len == 0) {
- len = -2;
- } else if (data == NULL || name == NULL || data_len == 0) {
- len = -1;
- dst[0] = '\0';
- } else {
- name_len = strlen(name);
- e = data + data_len;
- len = -1;
- dst[0] = '\0';
-
- /* data is "var1=val1&var2=val2...". Find variable first */
- for (p = data; p + name_len < e; p++) {
- if ((p == data || p[-1] == '&') && p[name_len] == '=' &&
- !mg_strncasecmp(name, p, name_len) && 0 == occurrence--) {
-
- /* Point p to variable value */
- p += name_len + 1;
-
- /* Point s to the end of the value */
- s = (const char *) memchr(p, '&', (size_t)(e - p));
- if (s == NULL) {
- s = e;
- }
- assert(s >= p);
-
- /* Decode variable into destination buffer */
- len = mg_url_decode(p, (int)(s - p), dst, (int)dst_len, 1);
-
- /* Redirect error code from -1 to -2 (destination buffer too
- small). */
- if (len == -1) {
- len = -2;
- }
- break;
- }
- }
- }
-
- return len;
-}
-
-int mg_get_cookie(const char *cookie_header, const char *var_name,
- char *dst, size_t dst_size)
-{
- const char *s, *p, *end;
- int name_len, len = -1;
-
- if (dst == NULL || dst_size == 0) {
- len = -2;
- } else if (var_name == NULL || (s = cookie_header) == NULL) {
- len = -1;
- dst[0] = '\0';
- } else {
- name_len = (int) strlen(var_name);
- end = s + strlen(s);
- dst[0] = '\0';
-
- for (; (s = mg_strcasestr(s, var_name)) != NULL; s += name_len) {
-
<TRUNCATED>
[46/54] [abbrv] celix git commit: CELIX-417: Adds initial
CelixConfig.cmake, export lib/exe target and exporting bundle target
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/cmake_celix/Dependencies.cmake
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/Dependencies.cmake b/cmake/cmake_celix/Dependencies.cmake
deleted file mode 100644
index c02db35..0000000
--- a/cmake/cmake_celix/Dependencies.cmake
+++ /dev/null
@@ -1,69 +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.
-
-MACRO(celix_subproject)
- set(ARGS "${ARGN}")
-
- list(GET ARGS 0 OPTION_NAME)
- list(REMOVE_AT ARGS 0)
-
- list(GET ARGS 0 OPTION_DESCRIPTION)
- list(REMOVE_AT ARGS 0)
-
- list(GET ARGS 0 OPTION_DEFAULT)
- list(REMOVE_AT ARGS 0)
-
- set(OPTIONS )
- set(ONE_VAL_ARGS )
- set(MULTI_VAL_ARGS DEPS)
- cmake_parse_arguments(OPTION "${OPTIONS}" "${ONE_VAL_ARGS}" "${MULTI_VAL_ARGS}" ${ARGS})
-
- string(TOUPPER ${OPTION_NAME} UC_OPTION_NAME)
- set(NAME "BUILD_${UC_OPTION_NAME}")
-
- option(${NAME} "${OPTION_DESCRIPTION}" ${OPTION_DEFAULT})
-
- get_property(BUILD GLOBAL PROPERTY ${NAME}_INTERNAL)
- if (NOT DEFINED BUILD)
- set(BUILD "OFF")
- endif (NOT DEFINED BUILD)
-
- IF (${NAME} OR ${BUILD})
- set(${OPTION_NAME} "ON")
- set_property(GLOBAL PROPERTY ${NAME}_INTERNAL "ON")
-
- FOREACH (DEP ${OPTION_DEPS})
- string(TOUPPER ${DEP} UC_DEP)
- set(DEP_NAME "BUILD_${UC_DEP}")
- set_property(GLOBAL PROPERTY ${DEP_NAME}_INTERNAL "ON")
- ENDFOREACH (DEP)
- ELSE (${NAME} OR ${BUILD})
- set(${OPTION_NAME} "OFF")
- ENDIF (${NAME} OR ${BUILD})
-ENDMACRO(celix_subproject)
-
-MACRO(is_enabled name)
- string(TOUPPER "BUILD_${name}_INTERNAL" OPTION)
-
- get_property(BUILD GLOBAL PROPERTY ${OPTION})
-
- if(BUILD)
- set(${name} "ON")
- else()
- set(${name} "OFF")
- endif()
-ENDMACRO(is_enabled)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/cmake_celix/DeployPackaging.cmake
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/DeployPackaging.cmake b/cmake/cmake_celix/DeployPackaging.cmake
index b7880f4..b22ee40 100644
--- a/cmake/cmake_celix/DeployPackaging.cmake
+++ b/cmake/cmake_celix/DeployPackaging.cmake
@@ -167,7 +167,7 @@ $<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_PROPERTIES>,
set(PROGRAM_NAME "${LAUNCHER}")
set(PROJECT_ATTR "${CMAKE_PROJECT_NAME}-build")
set(WORKING_DIRECTORY ${CONTAINER_LOC})
- include("${CELIX_CMAKE_DIRECTORY}/cmake_celix/RunConfig.in.cmake") #set VAR RUN_CONFIG_IN
+ include("${CELIX_CMAKE_DIRECTORY}/RunConfig.in.cmake") #set VAR RUN_CONFIG_IN
file(GENERATE
OUTPUT "${CONTAINER_ECLIPSE_LAUNCHER}"
CONTENT "${RUN_CONFIG_IN}"
@@ -233,15 +233,32 @@ function(celix_container_bundles_dir)
get_target_property(DEPS ${CONTAINER_TARGET} "CONTAINER_TARGET_DEPS")
foreach(BUNDLE IN ITEMS ${BD_BUNDLES})
+ set(HANDLED FALSE)
if (IS_ABSOLUTE ${BUNDLE} AND EXISTS ${BUNDLE})
get_filename_component(BUNDLE_FILENAME ${BUNDLE} NAME)
set(OUT "${CONTAINER_LOC}/${BD_DIR_NAME}/${BUNDLE_FILENAME}")
add_custom_command(OUTPUT ${OUT}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${BUNDLE} ${OUT}
- COMMENT "Copying bundle '${BUNDLE}' to '${CONTAINER_LOC}/${BD_DIR_NAME}'"
- DEPENDS ${BUNDLE}
+ COMMENT "Copying (file) bundle '${BUNDLE}' to '${CONTAINER_LOC}/${BD_DIR_NAME}'"
)
- else()
+ set(HANDLED TRUE)
+ elseif (TARGET ${BUNDLE})
+ get_target_property(IMP ${BUNDLE} BUNDLE_IMPORTED)
+ if (IMP) #An imported bundle target -> handle target without DEPENDS
+ string(MAKE_C_IDENTIFIER ${BUNDLE} BUNDLE_ID) #Create id with no special chars (e.g. for target like Celix::shell)
+ set(OUT "${CMAKE_BINARY_DIR}/celix/gen/${CONTAINER_TARGET}-copy-bundle-for-target-${BUNDLE_ID}.timestamp")
+ set(DEST "${CONTAINER_LOC}/${BD_DIR_NAME}/$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
+ add_custom_command(OUTPUT ${OUT}
+ COMMAND ${CMAKE_COMMAND} -E touch ${OUT}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${CONTAINER_LOC}/${BD_DIR_NAME}
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILE>" ${DEST}
+ COMMENT "Copying (imported) bundle '${BUNDLE}' to '${CONTAINER_LOC}/${BD_DIR_NAME}'"
+ )
+ set(HANDLED TRUE)
+ endif ()
+ endif ()
+
+ if (NOT HANDLED) #not a imported bundle target so (assuming) a future bundle target
string(MAKE_C_IDENTIFIER ${BUNDLE} BUNDLE_ID) #Create id with no special chars (e.g. for target like Celix::shell)
set(OUT "${CMAKE_BINARY_DIR}/celix/gen/${CONTAINER_TARGET}-copy-bundle-for-target-${BUNDLE_ID}.timestamp")
set(DEST "${CONTAINER_LOC}/${BD_DIR_NAME}/$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
@@ -249,7 +266,7 @@ function(celix_container_bundles_dir)
COMMAND ${CMAKE_COMMAND} -E touch ${OUT}
COMMAND ${CMAKE_COMMAND} -E make_directory ${CONTAINER_LOC}/${BD_DIR_NAME}
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILE>" ${DEST}
- COMMENT "Copying bundle '${BUNDLE}' to '${CONTAINER_LOC}/${BD_DIR_NAME}'"
+ COMMENT "Copying (target) bundle '${BUNDLE}' to '${CONTAINER_LOC}/${BD_DIR_NAME}'"
DEPENDS ${BUNDLE} $<TARGET_PROPERTY:${BUNDLE},BUNDLE_CREATE_BUNDLE_TARGET>
)
endif()
@@ -274,11 +291,22 @@ function(celix_container_bundles)
get_target_property(DEPS ${CONTAINER_TARGET} "CONTAINER_TARGET_DEPS")
foreach(BUNDLE IN ITEMS ${ARGN})
- if (IS_ABSOLUTE ${BUNDLE} AND EXISTS ${BUNDLE})
+ set(HANDLED FALSE)
+ if (IS_ABSOLUTE ${BUNDLE} AND EXISTS ${BUNDLE})
get_filename_component(BUNDLE_FILENAME ${BUNDLE} NAME)
set(COPY_LOC "bundles/${BUNDLE_FILENAME}")
set(ABS_LOC "${BUNDLE}")
- else () #assume target (could be a future target -> if (TARGET ...) not possible
+ set(HANDLED TRUE)
+ elseif (TARGET ${BUNDLE})
+ get_target_property(IMP ${BUNDLE} BUNDLE_IMPORTED)
+ if (IMP) #An imported bundle target -> handle target without DEPENDS
+ set(COPY_LOC "bundles/$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
+ set(ABS_LOC "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILE>")
+ set(HANDLED TRUE)
+ endif ()
+ endif ()
+
+ if (NOT HANDLED) #not a imported bundle target, so assuming a (future) bundle target
set(COPY_LOC "bundles/$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
set(ABS_LOC "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILE>")
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/cmake/cmake_celix/UseCelix.cmake
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/UseCelix.cmake b/cmake/cmake_celix/UseCelix.cmake
index db3f109..51290d3 100644
--- a/cmake/cmake_celix/UseCelix.cmake
+++ b/cmake/cmake_celix/UseCelix.cmake
@@ -15,8 +15,11 @@
# specific language governing permissions and limitations
# under the License.
-set(CELIX_CMAKE_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/..)
-include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/BundlePackaging.cmake)
-include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/DeployPackaging.cmake)
-include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/DockerPackaging.cmake)
-include(${CELIX_CMAKE_DIRECTORY}/cmake_celix/Runtimes.cmake)
+include(GNUInstallDirs)
+
+set(CELIX_CMAKE_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CELIX_CMAKE_DIRECTORY}/../Modules)
+include(${CELIX_CMAKE_DIRECTORY}/BundlePackaging.cmake)
+include(${CELIX_CMAKE_DIRECTORY}/DeployPackaging.cmake)
+include(${CELIX_CMAKE_DIRECTORY}/DockerPackaging.cmake)
+include(${CELIX_CMAKE_DIRECTORY}/Runtimes.cmake)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/dependency_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/dependency_manager/CMakeLists.txt b/dependency_manager/CMakeLists.txt
index f98701e..a9fa7bd 100644
--- a/dependency_manager/CMakeLists.txt
+++ b/dependency_manager/CMakeLists.txt
@@ -79,8 +79,8 @@ if (DEPENDENCY_MANAGER)
target_include_directories(dm_shell PRIVATE api src)
target_link_libraries(dm_shell PRIVATE Celix::shell_api)
- install_celix_bundle(dm_shell)
- install(TARGETS dependency_manager_so dependency_manager_static DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dependency_manager)
+ install_celix_bundle(dm_shell EXPORT celix)
+ install(TARGETS dependency_manager_so dependency_manager_static EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dependency_manager)
install(DIRECTORY api/ DESTINATION include/celix/dependency_manager COMPONENT dependency_manager)
unset(DM_COMP_OPT)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/dependency_manager_cxx/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/dependency_manager_cxx/CMakeLists.txt b/dependency_manager_cxx/CMakeLists.txt
index 5b7580a..63d0714 100644
--- a/dependency_manager_cxx/CMakeLists.txt
+++ b/dependency_manager_cxx/CMakeLists.txt
@@ -40,8 +40,8 @@ if (DEPENDENCY_MANAGER_CXX)
target_include_directories(dependency_manager_cxx_static PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/dependency_manager/api>
- $<INSTALL_INTERFACE:include/celix/dependency_manager_cxx>
$<INSTALL_INTERFACE:include/celix/dependency_manager>
+ $<INSTALL_INTERFACE:include/celix/dependency_manager_cxx>
)
target_include_directories(dependency_manager_cxx_static PRIVATE src)
target_compile_options(dependency_manager_cxx_static PRIVATE ${DM_COMP_OPT})
@@ -52,8 +52,8 @@ if (DEPENDENCY_MANAGER_CXX)
target_link_libraries(dependency_manager_cxx_static Celix::framework)
endif()
- install(TARGETS dependency_manager_cxx_static DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dependency_manager_cxx)
- install(DIRECTORY include DESTINATION include/celix/dependency_manager_cxx COMPONENT dependency_manager_cxx)
+ install(TARGETS dependency_manager_cxx_static EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dependency_manager_cxx)
+ install(DIRECTORY include/ DESTINATION include/celix/dependency_manager_cxx COMPONENT dependency_manager_cxx)
unset(DM_COMP_OPT)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/examples/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 93a648b..0937cc9 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -14,7 +14,12 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-celix_subproject(EXAMPLES "Option to enable building the Examples" ON DEPS FRAMEWORK LAUNCHER SHELL_TUI LOG_SERVICE LOG_WRITER)
+
+if (COMMAND celix_subproject)
+ celix_subproject(EXAMPLES "Option to enable building the Examples" ON DEPS FRAMEWORK LAUNCHER SHELL_TUI LOG_SERVICE LOG_WRITER)
+else ()
+ set(EXAMPLES true) #celix_subproject is only available in the celix project -> using examples dir in other project is also supported
+endif ()
if (EXAMPLES)
add_subdirectory(hello_world)
add_subdirectory(hello_world_test)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/examples/dm_example/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example/CMakeLists.txt b/examples/dm_example/CMakeLists.txt
index a2a2143..9759702 100644
--- a/examples/dm_example/CMakeLists.txt
+++ b/examples/dm_example/CMakeLists.txt
@@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-if (BUILD_DEPENDENCY_MANAGER)
+if (TARGET Celix::dependency_manager_static AND TARGET Celix::dm_shell)
add_subdirectory(api)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/examples/dm_example/phase3/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/CMakeLists.txt b/examples/dm_example/phase3/CMakeLists.txt
index 7cad101..7fae829 100644
--- a/examples/dm_example/phase3/CMakeLists.txt
+++ b/examples/dm_example/phase3/CMakeLists.txt
@@ -26,7 +26,7 @@ target_include_directories(dm_example_phase3 PRIVATE src)
target_link_libraries(dm_example_phase3 PRIVATE dm_example_api)
IF(APPLE)
- target_link_libraries(dm_example_phase3 PRIVATE -Wl,-all_load dependency_manager_static)
+ target_link_libraries(dm_example_phase3 PRIVATE -Wl,-all_load Celix::dependency_manager_static)
else()
if(ENABLE_ADDRESS_SANITIZER)
#With asan there can be undefined symbols
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/examples/dm_example_cxx/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/CMakeLists.txt b/examples/dm_example_cxx/CMakeLists.txt
index 3f37373..5f6832c 100644
--- a/examples/dm_example_cxx/CMakeLists.txt
+++ b/examples/dm_example_cxx/CMakeLists.txt
@@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-if (BUILD_DEPENDENCY_MANAGER_CXX)
+if (TARGET Celix::dependency_manager_cxx_static AND TARGET Celix::dm_shell)
add_subdirectory(api)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/examples/mongoose/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/mongoose/CMakeLists.txt b/examples/mongoose/CMakeLists.txt
index 7119aa7..d0e94ae 100644
--- a/examples/mongoose/CMakeLists.txt
+++ b/examples/mongoose/CMakeLists.txt
@@ -39,4 +39,4 @@ celix_bundle_files(mongoose ${CMAKE_CURRENT_LIST_DIR}/root)
target_link_libraries(mongoose PRIVATE mongooselib ${LIBS})
-add_celix_container("mongoose_deploy" BUNDLES Celix::shell Celix::shell_tui log_service mongoose)
+add_celix_container("mongoose_deploy" BUNDLES Celix::shell Celix::shell_tui Celix::log_service mongoose)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/framework/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt
index 1716a7d..483deee 100644
--- a/framework/CMakeLists.txt
+++ b/framework/CMakeLists.txt
@@ -58,10 +58,6 @@ target_link_libraries(framework PRIVATE ${UUID} ${ZLIB_LIBRARY} ${CURL_LIBRARIES
install(TARGETS framework EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT framework)
install(DIRECTORY include/ DESTINATION include/celix COMPONENT framework)
-install(DIRECTORY "${PROJECT_SOURCE_DIR}/cmake/" DESTINATION share/celix/cmake/modules COMPONENT framework
- PATTERN "CMakeCelix-local.cmake" EXCLUDE
-)
-
#Alias setup to match external usage
add_library(Celix::framework ALIAS framework)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/log_service/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/log_service/CMakeLists.txt b/log_service/CMakeLists.txt
index bd59961..ed737d9 100644
--- a/log_service/CMakeLists.txt
+++ b/log_service/CMakeLists.txt
@@ -55,6 +55,7 @@ if (LOG_SERVICE)
include/log_reader_service.h
include/log_listener.h
include/log_entry.h
+ EXPORT celix
)
target_include_directories(log_service PRIVATE src)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/log_writer/log_writer_stdout/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/log_writer/log_writer_stdout/CMakeLists.txt b/log_writer/log_writer_stdout/CMakeLists.txt
index 94effae..e4000dc 100644
--- a/log_writer/log_writer_stdout/CMakeLists.txt
+++ b/log_writer/log_writer_stdout/CMakeLists.txt
@@ -23,6 +23,6 @@ add_celix_bundle(log_writer_stdout
src/log_writer_stdout
)
-install_celix_bundle(log_writer_stdout)
+install_celix_bundle(log_writer_stdout EXPORT celix)
target_link_libraries(log_writer_stdout PRIVATE Celix::log_service_api log_writer_common)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/log_writer/log_writer_syslog/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/log_writer/log_writer_syslog/CMakeLists.txt b/log_writer/log_writer_syslog/CMakeLists.txt
index e2003d5..9ea3a68 100644
--- a/log_writer/log_writer_syslog/CMakeLists.txt
+++ b/log_writer/log_writer_syslog/CMakeLists.txt
@@ -26,7 +26,7 @@ if (LOG_WRITER_SYSLOG)
private/src/log_writer_syslog
)
- install_celix_bundle(log_writer_syslog)
+ install_celix_bundle(log_writer_syslog EXPORT celix)
target_link_libraries(log_writer_syslog PRIVATE log_writer_common)
endif (LOG_WRITER_SYSLOG)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/remote_services/topology_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/CMakeLists.txt b/remote_services/topology_manager/CMakeLists.txt
index 763067d..1e47c37 100644
--- a/remote_services/topology_manager/CMakeLists.txt
+++ b/remote_services/topology_manager/CMakeLists.txt
@@ -27,7 +27,7 @@ if (RSA_TOPOLOGY_MANAGER)
NAME "Apache Celix RS Topology Manager"
)
target_include_directories(rsa_topology_manager PRIVATE src)
- target_include_directories(rsa_topology_manager PUBLIC include)
+ target_include_directories(rsa_topology_manager PRIVATE include)
target_link_libraries(rsa_topology_manager PRIVATE Celix::log_helper Celix::rsa_spi)
install_celix_bundle(rsa_topology_manager)
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/shell/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt
index 93c066f..321a173 100644
--- a/shell/CMakeLists.txt
+++ b/shell/CMakeLists.txt
@@ -19,7 +19,12 @@ if (SHELL)
find_package(CURL REQUIRED)
add_library(shell_api INTERFACE)
- target_include_directories(shell_api INTERFACE include)
+ target_include_directories(shell_api INTERFACE
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
+ $<INSTALL_INTERFACE:include/celix/shell>
+ )
+ install(TARGETS shell_api EXPORT celix)
+ install(DIRECTORY include/ DESTINATION include/celix/shell COMPONENT shell)
add_celix_bundle(shell
SYMBOLIC_NAME "apache_celix_shell"
@@ -44,6 +49,7 @@ if (SHELL)
install_celix_bundle(shell
HEADERS
include/shell.h include/command.h include/shell_constants.h
+ EXPORT celix
)
#Setup target aliases to match external usage
http://git-wip-us.apache.org/repos/asf/celix/blob/ae8e2e3c/shell_tui/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/shell_tui/CMakeLists.txt b/shell_tui/CMakeLists.txt
index acfe439..a31645f 100644
--- a/shell_tui/CMakeLists.txt
+++ b/shell_tui/CMakeLists.txt
@@ -33,7 +33,7 @@ if (SHELL_TUI)
)
target_link_libraries(shell_tui PRIVATE Celix::shell_api)
- install_celix_bundle(shell_tui)
+ install_celix_bundle(shell_tui EXPORT celix)
#Alias setup to match external usage
add_library(Celix::shell_tui ALIAS shell_tui)
[15/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/src/pubsub_discovery_impl.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/src/pubsub_discovery_impl.c b/pubsub/pubsub_discovery/src/pubsub_discovery_impl.c
new file mode 100644
index 0000000..94a8e11
--- /dev/null
+++ b/pubsub/pubsub_discovery/src/pubsub_discovery_impl.c
@@ -0,0 +1,457 @@
+/**
+ *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.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdbool.h>
+#include <netdb.h>
+#include <netinet/in.h>
+
+#include "constants.h"
+#include "celix_threads.h"
+#include "bundle_context.h"
+#include "array_list.h"
+#include "utils.h"
+#include "celix_errno.h"
+#include "filter.h"
+#include "service_reference.h"
+#include "service_registration.h"
+
+#include "publisher_endpoint_announce.h"
+#include "etcd_common.h"
+#include "etcd_watcher.h"
+#include "etcd_writer.h"
+#include "pubsub_endpoint.h"
+#include "pubsub_discovery_impl.h"
+
+/* Discovery activator functions */
+celix_status_t pubsub_discovery_create(bundle_context_pt context, pubsub_discovery_pt *ps_discovery) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *ps_discovery = calloc(1, sizeof(**ps_discovery));
+
+ if (*ps_discovery == NULL) {
+ status = CELIX_ENOMEM;
+ }
+ else{
+ (*ps_discovery)->context = context;
+ (*ps_discovery)->discoveredPubs = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ (*ps_discovery)->listenerReferences = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
+ (*ps_discovery)->watchers = hashMap_create(utils_stringHash,NULL,utils_stringEquals, NULL);
+ celixThreadMutex_create(&(*ps_discovery)->listenerReferencesMutex, NULL);
+ celixThreadMutex_create(&(*ps_discovery)->discoveredPubsMutex, NULL);
+ celixThreadMutex_create(&(*ps_discovery)->watchersMutex, NULL);
+ }
+
+ return status;
+}
+
+celix_status_t pubsub_discovery_destroy(pubsub_discovery_pt ps_discovery) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ps_discovery->discoveredPubsMutex);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(ps_discovery->discoveredPubs);
+
+ while (hashMapIterator_hasNext(iter)) {
+ array_list_pt pubEP_list = (array_list_pt) hashMapIterator_nextValue(iter);
+
+ for(int i=0; i < arrayList_size(pubEP_list); i++) {
+ pubsubEndpoint_destroy(((pubsub_endpoint_pt)arrayList_get(pubEP_list,i)));
+ }
+ arrayList_destroy(pubEP_list);
+ }
+
+ hashMapIterator_destroy(iter);
+
+ hashMap_destroy(ps_discovery->discoveredPubs, true, false);
+ ps_discovery->discoveredPubs = NULL;
+
+ celixThreadMutex_unlock(&ps_discovery->discoveredPubsMutex);
+
+ celixThreadMutex_destroy(&ps_discovery->discoveredPubsMutex);
+
+
+ celixThreadMutex_lock(&ps_discovery->listenerReferencesMutex);
+
+ hashMap_destroy(ps_discovery->listenerReferences, false, false);
+ ps_discovery->listenerReferences = NULL;
+
+ celixThreadMutex_unlock(&ps_discovery->listenerReferencesMutex);
+
+ celixThreadMutex_destroy(&ps_discovery->listenerReferencesMutex);
+
+ free(ps_discovery);
+
+ return status;
+}
+
+celix_status_t pubsub_discovery_start(pubsub_discovery_pt ps_discovery) {
+ celix_status_t status = CELIX_SUCCESS;
+ status = etcdCommon_init(ps_discovery->context);
+ ps_discovery->writer = etcdWriter_create(ps_discovery);
+
+ return status;
+}
+
+celix_status_t pubsub_discovery_stop(pubsub_discovery_pt ps_discovery) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ const char* fwUUID = NULL;
+
+ bundleContext_getProperty(ps_discovery->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &fwUUID);
+ if (fwUUID == NULL) {
+ printf("PSD: Cannot retrieve fwUUID.\n");
+ return CELIX_INVALID_BUNDLE_CONTEXT;
+ }
+
+ celixThreadMutex_lock(&ps_discovery->watchersMutex);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(ps_discovery->watchers);
+ while (hashMapIterator_hasNext(iter)) {
+ struct watcher_info * wi = hashMapIterator_nextValue(iter);
+ etcdWatcher_stop(wi->watcher);
+ }
+ hashMapIterator_destroy(iter);
+
+ celixThreadMutex_lock(&ps_discovery->discoveredPubsMutex);
+
+ /* Unexport all publishers for the local framework, and also delete from ETCD publisher belonging to the local framework */
+
+ iter = hashMapIterator_create(ps_discovery->discoveredPubs);
+ while (hashMapIterator_hasNext(iter)) {
+ array_list_pt pubEP_list = (array_list_pt) hashMapIterator_nextValue(iter);
+
+ int i;
+ for (i = 0; i < arrayList_size(pubEP_list); i++) {
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt) arrayList_get(pubEP_list, i);
+ if (strcmp(pubEP->frameworkUUID, fwUUID) == 0) {
+ etcdWriter_deletePublisherEndpoint(ps_discovery->writer, pubEP);
+ } else {
+ pubsub_discovery_informPublishersListeners(ps_discovery, pubEP, false);
+ arrayList_remove(pubEP_list, i);
+ pubsubEndpoint_destroy(pubEP);
+ i--;
+ }
+ }
+ }
+
+ hashMapIterator_destroy(iter);
+
+ celixThreadMutex_unlock(&ps_discovery->discoveredPubsMutex);
+ etcdWriter_destroy(ps_discovery->writer);
+
+ iter = hashMapIterator_create(ps_discovery->watchers);
+ while (hashMapIterator_hasNext(iter)) {
+ struct watcher_info * wi = hashMapIterator_nextValue(iter);
+ etcdWatcher_destroy(wi->watcher);
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(ps_discovery->watchers, true, true);
+ celixThreadMutex_unlock(&ps_discovery->watchersMutex);
+ return status;
+}
+
+/* Functions called by the etcd_watcher */
+
+celix_status_t pubsub_discovery_addNode(pubsub_discovery_pt pubsub_discovery, pubsub_endpoint_pt pubEP) {
+ celix_status_t status = CELIX_SUCCESS;
+ bool inform=false;
+ celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex);
+
+ char *pubs_key = createScopeTopicKey(pubEP->scope, pubEP->topic);
+ array_list_pt pubEP_list = (array_list_pt)hashMap_get(pubsub_discovery->discoveredPubs,pubs_key);
+ if(pubEP_list==NULL){
+ arrayList_create(&pubEP_list);
+ arrayList_add(pubEP_list,pubEP);
+ hashMap_put(pubsub_discovery->discoveredPubs,strdup(pubs_key),pubEP_list);
+ inform=true;
+ }
+ else{
+ int i;
+ bool found = false;
+ for(i=0;i<arrayList_size(pubEP_list) && !found;i++){
+ found = pubsubEndpoint_equals(pubEP,(pubsub_endpoint_pt)arrayList_get(pubEP_list,i));
+ }
+ if(found){
+ pubsubEndpoint_destroy(pubEP);
+ }
+ else{
+ arrayList_add(pubEP_list,pubEP);
+ inform=true;
+ }
+ }
+ free(pubs_key);
+
+ celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex);
+
+ if(inform){
+ status = pubsub_discovery_informPublishersListeners(pubsub_discovery,pubEP,true);
+ }
+
+ return status;
+}
+
+celix_status_t pubsub_discovery_removeNode(pubsub_discovery_pt pubsub_discovery, pubsub_endpoint_pt pubEP) {
+ celix_status_t status = CELIX_SUCCESS;
+ pubsub_endpoint_pt p = NULL;
+ bool found = false;
+
+ celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex);
+ char *pubs_key = createScopeTopicKey(pubEP->scope, pubEP->topic);
+ array_list_pt pubEP_list = (array_list_pt) hashMap_get(pubsub_discovery->discoveredPubs, pubs_key);
+ free(pubs_key);
+ if (pubEP_list == NULL) {
+ printf("PSD: Cannot find any registered publisher for topic %s. Something is not consistent.\n", pubEP->topic);
+ status = CELIX_ILLEGAL_STATE;
+ } else {
+ int i;
+
+ for (i = 0; !found && i < arrayList_size(pubEP_list); i++) {
+ p = arrayList_get(pubEP_list, i);
+ found = pubsubEndpoint_equals(pubEP, p);
+ if (found) {
+ arrayList_remove(pubEP_list, i);
+ pubsubEndpoint_destroy(p);
+ }
+ }
+ }
+
+ celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex);
+ if (found) {
+ status = pubsub_discovery_informPublishersListeners(pubsub_discovery, pubEP, false);
+ }
+ pubsubEndpoint_destroy(pubEP);
+
+ return status;
+}
+
+/* Callback to the pubsub_topology_manager */
+celix_status_t pubsub_discovery_informPublishersListeners(pubsub_discovery_pt pubsub_discovery, pubsub_endpoint_pt pubEP, bool epAdded) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ // Inform listeners of new publisher endpoint
+ celixThreadMutex_lock(&pubsub_discovery->listenerReferencesMutex);
+
+ if (pubsub_discovery->listenerReferences != NULL) {
+ hash_map_iterator_pt iter = hashMapIterator_create(pubsub_discovery->listenerReferences);
+ while (hashMapIterator_hasNext(iter)) {
+ service_reference_pt reference = hashMapIterator_nextKey(iter);
+
+ publisher_endpoint_announce_pt listener = NULL;
+
+ bundleContext_getService(pubsub_discovery->context, reference, (void**) &listener);
+ if (epAdded) {
+ listener->announcePublisher(listener->handle, pubEP);
+ } else {
+ listener->removePublisher(listener->handle, pubEP);
+ }
+ bundleContext_ungetService(pubsub_discovery->context, reference, NULL);
+ }
+ hashMapIterator_destroy(iter);
+ }
+
+ celixThreadMutex_unlock(&pubsub_discovery->listenerReferencesMutex);
+
+ return status;
+}
+
+
+/* Service's functions implementation */
+celix_status_t pubsub_discovery_announcePublisher(void *handle, pubsub_endpoint_pt pubEP) {
+ celix_status_t status = CELIX_SUCCESS;
+ printf("pubsub_discovery_announcePublisher : %s / %s\n", pubEP->topic, pubEP->endpoint);
+ pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt) handle;
+
+ celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex);
+
+ char *pub_key = createScopeTopicKey(pubEP->scope,pubEP->topic);
+ array_list_pt pubEP_list = (array_list_pt)hashMap_get(pubsub_discovery->discoveredPubs,pub_key);
+
+ if(pubEP_list==NULL){
+ arrayList_create(&pubEP_list);
+ hashMap_put(pubsub_discovery->discoveredPubs,strdup(pub_key),pubEP_list);
+ }
+ free(pub_key);
+ pubsub_endpoint_pt p = NULL;
+ pubsubEndpoint_clone(pubEP, &p);
+
+ arrayList_add(pubEP_list,p);
+
+ status = etcdWriter_addPublisherEndpoint(pubsub_discovery->writer,p,true);
+
+ celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex);
+
+ return status;
+}
+
+celix_status_t pubsub_discovery_removePublisher(void *handle, pubsub_endpoint_pt pubEP) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt) handle;
+
+ celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex);
+
+ char *pub_key = createScopeTopicKey(pubEP->scope,pubEP->topic);
+ array_list_pt pubEP_list = (array_list_pt)hashMap_get(pubsub_discovery->discoveredPubs,pub_key);
+ free(pub_key);
+ if(pubEP_list==NULL){
+ printf("PSD: Cannot find any registered publisher for topic %s. Something is not consistent.\n",pubEP->topic);
+ status = CELIX_ILLEGAL_STATE;
+ }
+ else{
+
+ int i;
+ bool found = false;
+ pubsub_endpoint_pt p = NULL;
+
+ for(i=0;!found && i<arrayList_size(pubEP_list);i++){
+ p = (pubsub_endpoint_pt)arrayList_get(pubEP_list,i);
+ found = pubsubEndpoint_equals(pubEP,p);
+ }
+
+ if(!found){
+ printf("PSD: Trying to remove a not existing endpoint. Something is not consistent.\n");
+ status = CELIX_ILLEGAL_STATE;
+ }
+ else{
+
+ arrayList_removeElement(pubEP_list,p);
+
+ status = etcdWriter_deletePublisherEndpoint(pubsub_discovery->writer,p);
+
+ pubsubEndpoint_destroy(p);
+ }
+ }
+
+ celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex);
+
+ return status;
+}
+
+celix_status_t pubsub_discovery_interestedInTopic(void *handle, const char* scope, const char* topic) {
+ pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt) handle;
+
+ char *scope_topic_key = createScopeTopicKey(scope, topic);
+ celixThreadMutex_lock(&pubsub_discovery->watchersMutex);
+ struct watcher_info * wi = hashMap_get(pubsub_discovery->watchers, scope_topic_key);
+ if(wi) {
+ wi->nr_references++;
+ free(scope_topic_key);
+ } else {
+ wi = calloc(1, sizeof(*wi));
+ etcdWatcher_create(pubsub_discovery, pubsub_discovery->context, scope, topic, &wi->watcher);
+ wi->nr_references = 1;
+ hashMap_put(pubsub_discovery->watchers, scope_topic_key, wi);
+ }
+
+ celixThreadMutex_unlock(&pubsub_discovery->watchersMutex);
+
+ return CELIX_SUCCESS;
+}
+
+celix_status_t pubsub_discovery_uninterestedInTopic(void *handle, const char* scope, const char* topic) {
+ pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt) handle;
+
+ char *scope_topic_key = createScopeTopicKey(scope, topic);
+ celixThreadMutex_lock(&pubsub_discovery->watchersMutex);
+
+ hash_map_entry_pt entry = hashMap_getEntry(pubsub_discovery->watchers, scope_topic_key);
+ if(entry) {
+ struct watcher_info * wi = hashMapEntry_getValue(entry);
+ wi->nr_references--;
+ if(wi->nr_references == 0) {
+ char *key = hashMapEntry_getKey(entry);
+ hashMap_remove(pubsub_discovery->watchers, scope_topic_key);
+ free(key);
+ free(scope_topic_key);
+ etcdWatcher_stop(wi->watcher);
+ etcdWatcher_destroy(wi->watcher);
+ free(wi);
+ }
+ } else {
+ fprintf(stderr, "[DISC] Inconsistency error: Removing unknown topic %s\n", topic);
+ }
+ celixThreadMutex_unlock(&pubsub_discovery->watchersMutex);
+ return CELIX_SUCCESS;
+}
+
+/* pubsub_topology_manager tracker callbacks */
+
+celix_status_t pubsub_discovery_tmPublisherAnnounceAdded(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt)handle;
+ publisher_endpoint_announce_pt listener = (publisher_endpoint_announce_pt)service;
+
+ celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex);
+ celixThreadMutex_lock(&pubsub_discovery->listenerReferencesMutex);
+
+ /* Notify the PSTM about discovered publisher endpoints */
+ hash_map_iterator_pt iter = hashMapIterator_create(pubsub_discovery->discoveredPubs);
+ while(hashMapIterator_hasNext(iter)){
+ array_list_pt pubEP_list = (array_list_pt)hashMapIterator_nextValue(iter);
+ int i;
+ for(i=0;i<arrayList_size(pubEP_list);i++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pubEP_list,i);
+ status += listener->announcePublisher(listener->handle, pubEP);
+ }
+ }
+
+ hashMapIterator_destroy(iter);
+
+ hashMap_put(pubsub_discovery->listenerReferences, reference, NULL);
+
+ celixThreadMutex_unlock(&pubsub_discovery->listenerReferencesMutex);
+ celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex);
+
+ printf("PSD: pubsub_tm_announce_publisher added.\n");
+
+ return status;
+}
+
+celix_status_t pubsub_discovery_tmPublisherAnnounceModified(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ status = pubsub_discovery_tmPublisherAnnounceRemoved(handle, reference, service);
+ if (status == CELIX_SUCCESS) {
+ status = pubsub_discovery_tmPublisherAnnounceAdded(handle, reference, service);
+ }
+
+ return status;
+}
+
+celix_status_t pubsub_discovery_tmPublisherAnnounceRemoved(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+ pubsub_discovery_pt pubsub_discovery = handle;
+
+ celixThreadMutex_lock(&pubsub_discovery->listenerReferencesMutex);
+
+ if (pubsub_discovery->listenerReferences != NULL) {
+ if (hashMap_remove(pubsub_discovery->listenerReferences, reference)) {
+ printf("PSD: pubsub_tm_announce_publisher removed.\n");
+ }
+ }
+ celixThreadMutex_unlock(&pubsub_discovery->listenerReferencesMutex);
+
+ return status;
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_discovery/src/pubsub_discovery_impl.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/src/pubsub_discovery_impl.h b/pubsub/pubsub_discovery/src/pubsub_discovery_impl.h
new file mode 100644
index 0000000..676a6ab
--- /dev/null
+++ b/pubsub/pubsub_discovery/src/pubsub_discovery_impl.h
@@ -0,0 +1,72 @@
+/**
+ *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.
+ */
+
+#ifndef PUBSUB_DISCOVERY_IMPL_H_
+#define PUBSUB_DISCOVERY_IMPL_H_
+
+#include "bundle_context.h"
+#include "service_reference.h"
+
+#include "etcd_watcher.h"
+#include "etcd_writer.h"
+#include "pubsub_endpoint.h"
+
+#define FREE_MEM(ptr) if(ptr) {free(ptr); ptr = NULL;}
+
+struct watcher_info {
+ etcd_watcher_pt watcher;
+ int nr_references;
+};
+
+struct pubsub_discovery {
+ bundle_context_pt context;
+
+ celix_thread_mutex_t discoveredPubsMutex;
+ hash_map_pt discoveredPubs; //<topic,List<pubsub_endpoint_pt>>
+
+ celix_thread_mutex_t listenerReferencesMutex;
+ hash_map_pt listenerReferences; //key=serviceReference, value=nop
+
+ celix_thread_mutex_t watchersMutex;
+ hash_map_pt watchers; //key = topicname, value = struct watcher_info
+
+ etcd_writer_pt writer;
+};
+
+
+celix_status_t pubsub_discovery_create(bundle_context_pt context, pubsub_discovery_pt* node_discovery);
+celix_status_t pubsub_discovery_destroy(pubsub_discovery_pt node_discovery);
+celix_status_t pubsub_discovery_start(pubsub_discovery_pt node_discovery);
+celix_status_t pubsub_discovery_stop(pubsub_discovery_pt node_discovery);
+
+celix_status_t pubsub_discovery_addNode(pubsub_discovery_pt node_discovery, pubsub_endpoint_pt pubEP);
+celix_status_t pubsub_discovery_removeNode(pubsub_discovery_pt node_discovery, pubsub_endpoint_pt pubEP);
+
+celix_status_t pubsub_discovery_tmPublisherAnnounceAdded(void * handle, service_reference_pt reference, void * service);
+celix_status_t pubsub_discovery_tmPublisherAnnounceModified(void * handle, service_reference_pt reference, void * service);
+celix_status_t pubsub_discovery_tmPublisherAnnounceRemoved(void * handle, service_reference_pt reference, void * service);
+
+celix_status_t pubsub_discovery_announcePublisher(void *handle, pubsub_endpoint_pt pubEP);
+celix_status_t pubsub_discovery_removePublisher(void *handle, pubsub_endpoint_pt pubEP);
+celix_status_t pubsub_discovery_interestedInTopic(void *handle, const char* scope, const char* topic);
+celix_status_t pubsub_discovery_uninterestedInTopic(void *handle, const char* scope, const char* topic);
+
+celix_status_t pubsub_discovery_informPublishersListeners(pubsub_discovery_pt discovery, pubsub_endpoint_pt endpoint, bool endpointAdded);
+
+#endif /* PUBSUB_DISCOVERY_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_serializer_json/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_serializer_json/CMakeLists.txt b/pubsub/pubsub_serializer_json/CMakeLists.txt
index 147873a..b86f30e 100644
--- a/pubsub/pubsub_serializer_json/CMakeLists.txt
+++ b/pubsub/pubsub_serializer_json/CMakeLists.txt
@@ -17,27 +17,23 @@
find_package(Jansson REQUIRED)
-include_directories("private/include")
-include_directories("public/include")
-include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/dfi/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-include_directories("${JANSSON_INCLUDE_DIR}")
add_bundle(org.apache.celix.pubsub_serializer.PubSubSerializerJson
BUNDLE_SYMBOLICNAME "apache_celix_pubsub_serializer_json"
VERSION "1.0.0"
SOURCES
- private/src/ps_activator.c
- private/src/pubsub_serializer_impl.c
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
+ src/ps_activator.c
+ src/pubsub_serializer_impl.c
${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
)
+target_include_directories(org.apache.celix.pubsub_serializer.PubSubSerializerJson PRIVATE
+ src
+ ${JANSSON_INCLUDE_DIR}
+)
+
set_target_properties(org.apache.celix.pubsub_serializer.PubSubSerializerJson PROPERTIES INSTALL_RPATH "$ORIGIN")
-target_link_libraries(org.apache.celix.pubsub_serializer.PubSubSerializerJson celix_framework celix_utils celix_dfi ${JANSSON_LIBRARIES})
+target_link_libraries(org.apache.celix.pubsub_serializer.PubSubSerializerJson PRIVATE Celix::framework Celix::dfi ${JANSSON_LIBRARIES} Celix::log_helper)
install_bundle(org.apache.celix.pubsub_serializer.PubSubSerializerJson)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_serializer_json/private/include/pubsub_serializer_impl.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_serializer_json/private/include/pubsub_serializer_impl.h b/pubsub/pubsub_serializer_json/private/include/pubsub_serializer_impl.h
deleted file mode 100644
index c36f20e..0000000
--- a/pubsub/pubsub_serializer_json/private/include/pubsub_serializer_impl.h
+++ /dev/null
@@ -1,55 +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.
- */
-/*
- * pubsub_serializer_impl.h
- *
- * \date Mar 24, 2017
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PUBSUB_SERIALIZER_JSON_H_
-#define PUBSUB_SERIALIZER_JSON_H_
-
-#include "dyn_common.h"
-#include "dyn_type.h"
-#include "dyn_message.h"
-#include "log_helper.h"
-
-#include "pubsub_serializer.h"
-
-#define PUBSUB_SERIALIZER_TYPE "json"
-
-typedef struct pubsub_serializer {
- bundle_context_pt bundle_context;
- log_helper_pt loghelper;
-} pubsub_serializer_t;
-
-celix_status_t pubsubSerializer_create(bundle_context_pt context, pubsub_serializer_t* *serializer);
-celix_status_t pubsubSerializer_destroy(pubsub_serializer_t* serializer);
-
-celix_status_t pubsubSerializer_createSerializerMap(pubsub_serializer_t* serializer, bundle_pt bundle, hash_map_pt* serializerMap);
-celix_status_t pubsubSerializer_destroySerializerMap(pubsub_serializer_t*, hash_map_pt serializerMap);
-
-/* Start of serializer specific functions */
-celix_status_t pubsubMsgSerializer_serialize(pubsub_msg_serializer_t* msgSerializer, const void* msg, void** out, size_t *outLen);
-celix_status_t pubsubMsgSerializer_deserialize(pubsub_msg_serializer_t* msgSerializer, const void* input, size_t inputLen, void **out);
-void pubsubMsgSerializer_freeMsg(pubsub_msg_serializer_t* msgSerializer, void *msg);
-
-#endif /* PUBSUB_SERIALIZER_JSON_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_serializer_json/private/src/ps_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_serializer_json/private/src/ps_activator.c b/pubsub/pubsub_serializer_json/private/src/ps_activator.c
deleted file mode 100644
index fec5892..0000000
--- a/pubsub/pubsub_serializer_json/private/src/ps_activator.c
+++ /dev/null
@@ -1,107 +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.
- */
-/*
- * ps_activator.c
- *
- * \date Mar 24, 2017
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-
-#include "bundle_activator.h"
-#include "service_registration.h"
-
-#include "pubsub_serializer_impl.h"
-
-struct activator {
- pubsub_serializer_t* serializer;
- pubsub_serializer_service_t* serializerService;
- service_registration_pt registration;
-};
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator;
-
- activator = calloc(1, sizeof(*activator));
- if (!activator) {
- status = CELIX_ENOMEM;
- }
- else{
- *userData = activator;
- status = pubsubSerializer_create(context, &(activator->serializer));
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
- pubsub_serializer_service_t* pubsubSerializerSvc = calloc(1, sizeof(*pubsubSerializerSvc));
-
- if (!pubsubSerializerSvc) {
- status = CELIX_ENOMEM;
- }
- else{
- pubsubSerializerSvc->handle = activator->serializer;
-
- pubsubSerializerSvc->createSerializerMap = (void*)pubsubSerializer_createSerializerMap;
- pubsubSerializerSvc->destroySerializerMap = (void*)pubsubSerializer_destroySerializerMap;
- activator->serializerService = pubsubSerializerSvc;
-
- /* Set serializer type */
- properties_pt props = properties_create();
- properties_set(props,PUBSUB_SERIALIZER_TYPE_KEY,PUBSUB_SERIALIZER_TYPE);
-
- status = bundleContext_registerService(context, PUBSUB_SERIALIZER_SERVICE, pubsubSerializerSvc, props, &activator->registration);
-
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- serviceRegistration_unregister(activator->registration);
- activator->registration = NULL;
-
- free(activator->serializerService);
- activator->serializerService = NULL;
-
- return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- pubsubSerializer_destroy(activator->serializer);
- activator->serializer = NULL;
-
- free(activator);
-
- return status;
-}
-
-
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_serializer_json/private/src/pubsub_serializer_impl.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_serializer_json/private/src/pubsub_serializer_impl.c b/pubsub/pubsub_serializer_json/private/src/pubsub_serializer_impl.c
deleted file mode 100644
index 685d499..0000000
--- a/pubsub/pubsub_serializer_json/private/src/pubsub_serializer_impl.c
+++ /dev/null
@@ -1,295 +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.
- */
-/*
- * pubsub_serializer_impl.c
- *
- * \date Mar 24, 2017
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <inttypes.h>
-
-#include "utils.h"
-#include "hash_map.h"
-#include "bundle_context.h"
-
-#include "log_helper.h"
-
-#include "json_serializer.h"
-
-#include "pubsub_serializer_impl.h"
-
-#define SYSTEM_BUNDLE_ARCHIVE_PATH "CELIX_FRAMEWORK_EXTENDER_PATH"
-#define MAX_PATH_LEN 1024
-
-static char* pubsubSerializer_getMsgDescriptionDir(bundle_pt bundle);
-static void pubsubSerializer_addMsgSerializerFromBundle(const char *root, bundle_pt bundle, hash_map_pt msgTypesMap);
-static void pubsubSerializer_fillMsgSerializerMap(hash_map_pt msgTypesMap,bundle_pt bundle);
-
-celix_status_t pubsubSerializer_create(bundle_context_pt context, pubsub_serializer_t** serializer) {
- celix_status_t status = CELIX_SUCCESS;
-
- *serializer = calloc(1, sizeof(**serializer));
-
- if (!*serializer) {
- status = CELIX_ENOMEM;
- }
- else{
-
- (*serializer)->bundle_context= context;
-
- if (logHelper_create(context, &(*serializer)->loghelper) == CELIX_SUCCESS) {
- logHelper_start((*serializer)->loghelper);
- }
-
- }
-
- return status;
-}
-
-celix_status_t pubsubSerializer_destroy(pubsub_serializer_t* serializer) {
- celix_status_t status = CELIX_SUCCESS;
-
- logHelper_stop(serializer->loghelper);
- logHelper_destroy(&serializer->loghelper);
-
- free(serializer);
-
- return status;
-}
-
-celix_status_t pubsubSerializer_createSerializerMap(pubsub_serializer_t* serializer, bundle_pt bundle, hash_map_pt* serializerMap) {
- celix_status_t status = CELIX_SUCCESS;
-
- hash_map_pt map = hashMap_create(NULL, NULL, NULL, NULL);
-
- if (map != NULL) {
- pubsubSerializer_fillMsgSerializerMap(map, bundle);
- } else {
- logHelper_log(serializer->loghelper, OSGI_LOGSERVICE_ERROR, "Cannot allocate memory for msg map");
- status = CELIX_ENOMEM;
- }
-
- if (status == CELIX_SUCCESS) {
- *serializerMap = map;
- }
- return status;
-}
-
-celix_status_t pubsubSerializer_destroySerializerMap(pubsub_serializer_t* serializer, hash_map_pt serializerMap) {
- celix_status_t status = CELIX_SUCCESS;
- if (serializerMap == NULL) {
- return CELIX_ILLEGAL_ARGUMENT;
- }
-
- hash_map_iterator_t iter = hashMapIterator_construct(serializerMap);
- while (hashMapIterator_hasNext(&iter)) {
- pubsub_msg_serializer_t* msgSerializer = hashMapIterator_nextValue(&iter);
- dyn_message_type *dynMsg = (dyn_message_type*)msgSerializer->handle;
- dynMessage_destroy(dynMsg); //note msgSer->name and msgSer->version owned by dynType
- free(msgSerializer); //also contains the service struct.
- }
-
- hashMap_destroy(serializerMap, false, false);
-
- return status;
-}
-
-
-celix_status_t pubsubMsgSerializer_serialize(pubsub_msg_serializer_t* msgSerializer, const void* msg, void** out, size_t *outLen) {
- celix_status_t status = CELIX_SUCCESS;
-
- char *jsonOutput = NULL;
- dyn_type* dynType = NULL;
- dyn_message_type *dynMsg = (dyn_message_type*)msgSerializer->handle;
- dynMessage_getMessageType(dynMsg, &dynType);
-
- if (jsonSerializer_serialize(dynType, msg, &jsonOutput) != 0){
- status = CELIX_BUNDLE_EXCEPTION;
- }
-
- if (status == CELIX_SUCCESS) {
- *out = jsonOutput;
- *outLen = strlen(jsonOutput) + 1;
- }
-
- return status;
-}
-
-celix_status_t pubsubMsgSerializer_deserialize(pubsub_msg_serializer_t* msgSerializer, const void* input, size_t inputLen, void **out) {
-
- celix_status_t status = CELIX_SUCCESS;
- void *msg = NULL;
- dyn_type* dynType = NULL;
- dyn_message_type *dynMsg = (dyn_message_type*)msgSerializer->handle;
- dynMessage_getMessageType(dynMsg, &dynType);
-
- if (jsonSerializer_deserialize(dynType, (const char*)input, &msg) != 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- }
- else{
- *out = msg;
- }
-
- return status;
-}
-
-void pubsubMsgSerializer_freeMsg(pubsub_msg_serializer_t* msgSerializer, void *msg) {
- dyn_type* dynType = NULL;
- dyn_message_type *dynMsg = (dyn_message_type*)msgSerializer->handle;
- dynMessage_getMessageType(dynMsg, &dynType);
- if (dynType != NULL) {
- dynType_free(dynType, msg);
- }
-}
-
-
-static void pubsubSerializer_fillMsgSerializerMap(hash_map_pt msgSerializers, bundle_pt bundle) {
- char* root = NULL;
- char* metaInfPath = NULL;
-
- root = pubsubSerializer_getMsgDescriptionDir(bundle);
-
- if(root != NULL){
- asprintf(&metaInfPath, "%s/META-INF/descriptors", root);
-
- pubsubSerializer_addMsgSerializerFromBundle(root, bundle, msgSerializers);
- pubsubSerializer_addMsgSerializerFromBundle(metaInfPath, bundle, msgSerializers);
-
- free(metaInfPath);
- free(root);
- }
-}
-
-static char* pubsubSerializer_getMsgDescriptionDir(bundle_pt bundle)
-{
- char *root = NULL;
-
- bool isSystemBundle = false;
- bundle_isSystemBundle(bundle, &isSystemBundle);
-
- if(isSystemBundle == true) {
- bundle_context_pt context;
- bundle_getContext(bundle, &context);
-
- const char *prop = NULL;
-
- bundleContext_getProperty(context, SYSTEM_BUNDLE_ARCHIVE_PATH, &prop);
-
- if(prop != NULL) {
- root = strdup(prop);
- } else {
- root = getcwd(NULL, 0);
- }
- } else {
- bundle_getEntry(bundle, ".", &root);
- }
-
- return root;
-}
-
-
-static void pubsubSerializer_addMsgSerializerFromBundle(const char *root, bundle_pt bundle, hash_map_pt msgSerializers)
-{
- char path[MAX_PATH_LEN];
- struct dirent *entry = NULL;
- DIR *dir = opendir(root);
-
- if(dir) {
- entry = readdir(dir);
- }
-
- while (entry != NULL) {
-
- if (strstr(entry->d_name, ".descriptor") != NULL) {
-
- printf("DMU: Parsing entry '%s'\n", entry->d_name);
-
- snprintf(path, MAX_PATH_LEN, "%s/%s", root, entry->d_name);
- FILE *stream = fopen(path,"r");
-
- if (stream != NULL){
- dyn_message_type* msgType = NULL;
-
- int rc = dynMessage_parse(stream, &msgType);
- if (rc == 0 && msgType != NULL) {
-
- char* msgName = NULL;
- rc += dynMessage_getName(msgType,&msgName);
-
- version_pt msgVersion = NULL;
- rc += dynMessage_getVersion(msgType, &msgVersion);
-
- if(rc == 0 && msgName != NULL && msgVersion != NULL){
-
- unsigned int msgId = utils_stringHash(msgName);
-
- pubsub_msg_serializer_t *msgSerializer = calloc(1,sizeof(pubsub_msg_serializer_t));
-
- msgSerializer->handle = msgType;
- msgSerializer->msgId = msgId;
- msgSerializer->msgName = msgName;
- msgSerializer->msgVersion = msgVersion;
- msgSerializer->serialize = (void*) pubsubMsgSerializer_serialize;
- msgSerializer->deserialize = (void*) pubsubMsgSerializer_deserialize;
- msgSerializer->freeMsg = (void*) pubsubMsgSerializer_freeMsg;
-
- bool clash = hashMap_containsKey(msgSerializers, (void*)(uintptr_t)msgId);
- if (clash){
- printf("Cannot add msg %s. clash in msg id %d!!\n", msgName, msgId);
- free(msgSerializer);
- dynMessage_destroy(msgType);
- }
- else if (msgId != 0){
- printf("Adding %u : %s\n", msgId, msgName);
- hashMap_put(msgSerializers, (void*)(uintptr_t)msgId, msgSerializer);
- }
- else{
- printf("Error creating msg serializer\n");
- free(msgSerializer);
- dynMessage_destroy(msgType);
- }
-
- }
- else{
- printf("Cannot retrieve name and/or version from msg\n");
- }
-
- } else{
- printf("DMU: cannot parse message from descriptor %s\n.",path);
- }
- fclose(stream);
- }else{
- printf("DMU: cannot open descriptor file %s\n.",path);
- }
-
- }
- entry = readdir(dir);
- }
-
- if(dir) {
- closedir(dir);
- }
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_serializer_json/src/ps_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_serializer_json/src/ps_activator.c b/pubsub/pubsub_serializer_json/src/ps_activator.c
new file mode 100644
index 0000000..fec5892
--- /dev/null
+++ b/pubsub/pubsub_serializer_json/src/ps_activator.c
@@ -0,0 +1,107 @@
+/**
+ *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.
+ */
+/*
+ * ps_activator.c
+ *
+ * \date Mar 24, 2017
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+
+#include "bundle_activator.h"
+#include "service_registration.h"
+
+#include "pubsub_serializer_impl.h"
+
+struct activator {
+ pubsub_serializer_t* serializer;
+ pubsub_serializer_service_t* serializerService;
+ service_registration_pt registration;
+};
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator;
+
+ activator = calloc(1, sizeof(*activator));
+ if (!activator) {
+ status = CELIX_ENOMEM;
+ }
+ else{
+ *userData = activator;
+ status = pubsubSerializer_create(context, &(activator->serializer));
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+ pubsub_serializer_service_t* pubsubSerializerSvc = calloc(1, sizeof(*pubsubSerializerSvc));
+
+ if (!pubsubSerializerSvc) {
+ status = CELIX_ENOMEM;
+ }
+ else{
+ pubsubSerializerSvc->handle = activator->serializer;
+
+ pubsubSerializerSvc->createSerializerMap = (void*)pubsubSerializer_createSerializerMap;
+ pubsubSerializerSvc->destroySerializerMap = (void*)pubsubSerializer_destroySerializerMap;
+ activator->serializerService = pubsubSerializerSvc;
+
+ /* Set serializer type */
+ properties_pt props = properties_create();
+ properties_set(props,PUBSUB_SERIALIZER_TYPE_KEY,PUBSUB_SERIALIZER_TYPE);
+
+ status = bundleContext_registerService(context, PUBSUB_SERIALIZER_SERVICE, pubsubSerializerSvc, props, &activator->registration);
+
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ serviceRegistration_unregister(activator->registration);
+ activator->registration = NULL;
+
+ free(activator->serializerService);
+ activator->serializerService = NULL;
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ pubsubSerializer_destroy(activator->serializer);
+ activator->serializer = NULL;
+
+ free(activator);
+
+ return status;
+}
+
+
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_serializer_json/src/pubsub_serializer_impl.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_serializer_json/src/pubsub_serializer_impl.c b/pubsub/pubsub_serializer_json/src/pubsub_serializer_impl.c
new file mode 100644
index 0000000..685d499
--- /dev/null
+++ b/pubsub/pubsub_serializer_json/src/pubsub_serializer_impl.c
@@ -0,0 +1,295 @@
+/**
+ *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.
+ */
+/*
+ * pubsub_serializer_impl.c
+ *
+ * \date Mar 24, 2017
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <inttypes.h>
+
+#include "utils.h"
+#include "hash_map.h"
+#include "bundle_context.h"
+
+#include "log_helper.h"
+
+#include "json_serializer.h"
+
+#include "pubsub_serializer_impl.h"
+
+#define SYSTEM_BUNDLE_ARCHIVE_PATH "CELIX_FRAMEWORK_EXTENDER_PATH"
+#define MAX_PATH_LEN 1024
+
+static char* pubsubSerializer_getMsgDescriptionDir(bundle_pt bundle);
+static void pubsubSerializer_addMsgSerializerFromBundle(const char *root, bundle_pt bundle, hash_map_pt msgTypesMap);
+static void pubsubSerializer_fillMsgSerializerMap(hash_map_pt msgTypesMap,bundle_pt bundle);
+
+celix_status_t pubsubSerializer_create(bundle_context_pt context, pubsub_serializer_t** serializer) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *serializer = calloc(1, sizeof(**serializer));
+
+ if (!*serializer) {
+ status = CELIX_ENOMEM;
+ }
+ else{
+
+ (*serializer)->bundle_context= context;
+
+ if (logHelper_create(context, &(*serializer)->loghelper) == CELIX_SUCCESS) {
+ logHelper_start((*serializer)->loghelper);
+ }
+
+ }
+
+ return status;
+}
+
+celix_status_t pubsubSerializer_destroy(pubsub_serializer_t* serializer) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ logHelper_stop(serializer->loghelper);
+ logHelper_destroy(&serializer->loghelper);
+
+ free(serializer);
+
+ return status;
+}
+
+celix_status_t pubsubSerializer_createSerializerMap(pubsub_serializer_t* serializer, bundle_pt bundle, hash_map_pt* serializerMap) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ hash_map_pt map = hashMap_create(NULL, NULL, NULL, NULL);
+
+ if (map != NULL) {
+ pubsubSerializer_fillMsgSerializerMap(map, bundle);
+ } else {
+ logHelper_log(serializer->loghelper, OSGI_LOGSERVICE_ERROR, "Cannot allocate memory for msg map");
+ status = CELIX_ENOMEM;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *serializerMap = map;
+ }
+ return status;
+}
+
+celix_status_t pubsubSerializer_destroySerializerMap(pubsub_serializer_t* serializer, hash_map_pt serializerMap) {
+ celix_status_t status = CELIX_SUCCESS;
+ if (serializerMap == NULL) {
+ return CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ hash_map_iterator_t iter = hashMapIterator_construct(serializerMap);
+ while (hashMapIterator_hasNext(&iter)) {
+ pubsub_msg_serializer_t* msgSerializer = hashMapIterator_nextValue(&iter);
+ dyn_message_type *dynMsg = (dyn_message_type*)msgSerializer->handle;
+ dynMessage_destroy(dynMsg); //note msgSer->name and msgSer->version owned by dynType
+ free(msgSerializer); //also contains the service struct.
+ }
+
+ hashMap_destroy(serializerMap, false, false);
+
+ return status;
+}
+
+
+celix_status_t pubsubMsgSerializer_serialize(pubsub_msg_serializer_t* msgSerializer, const void* msg, void** out, size_t *outLen) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ char *jsonOutput = NULL;
+ dyn_type* dynType = NULL;
+ dyn_message_type *dynMsg = (dyn_message_type*)msgSerializer->handle;
+ dynMessage_getMessageType(dynMsg, &dynType);
+
+ if (jsonSerializer_serialize(dynType, msg, &jsonOutput) != 0){
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *out = jsonOutput;
+ *outLen = strlen(jsonOutput) + 1;
+ }
+
+ return status;
+}
+
+celix_status_t pubsubMsgSerializer_deserialize(pubsub_msg_serializer_t* msgSerializer, const void* input, size_t inputLen, void **out) {
+
+ celix_status_t status = CELIX_SUCCESS;
+ void *msg = NULL;
+ dyn_type* dynType = NULL;
+ dyn_message_type *dynMsg = (dyn_message_type*)msgSerializer->handle;
+ dynMessage_getMessageType(dynMsg, &dynType);
+
+ if (jsonSerializer_deserialize(dynType, (const char*)input, &msg) != 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+ else{
+ *out = msg;
+ }
+
+ return status;
+}
+
+void pubsubMsgSerializer_freeMsg(pubsub_msg_serializer_t* msgSerializer, void *msg) {
+ dyn_type* dynType = NULL;
+ dyn_message_type *dynMsg = (dyn_message_type*)msgSerializer->handle;
+ dynMessage_getMessageType(dynMsg, &dynType);
+ if (dynType != NULL) {
+ dynType_free(dynType, msg);
+ }
+}
+
+
+static void pubsubSerializer_fillMsgSerializerMap(hash_map_pt msgSerializers, bundle_pt bundle) {
+ char* root = NULL;
+ char* metaInfPath = NULL;
+
+ root = pubsubSerializer_getMsgDescriptionDir(bundle);
+
+ if(root != NULL){
+ asprintf(&metaInfPath, "%s/META-INF/descriptors", root);
+
+ pubsubSerializer_addMsgSerializerFromBundle(root, bundle, msgSerializers);
+ pubsubSerializer_addMsgSerializerFromBundle(metaInfPath, bundle, msgSerializers);
+
+ free(metaInfPath);
+ free(root);
+ }
+}
+
+static char* pubsubSerializer_getMsgDescriptionDir(bundle_pt bundle)
+{
+ char *root = NULL;
+
+ bool isSystemBundle = false;
+ bundle_isSystemBundle(bundle, &isSystemBundle);
+
+ if(isSystemBundle == true) {
+ bundle_context_pt context;
+ bundle_getContext(bundle, &context);
+
+ const char *prop = NULL;
+
+ bundleContext_getProperty(context, SYSTEM_BUNDLE_ARCHIVE_PATH, &prop);
+
+ if(prop != NULL) {
+ root = strdup(prop);
+ } else {
+ root = getcwd(NULL, 0);
+ }
+ } else {
+ bundle_getEntry(bundle, ".", &root);
+ }
+
+ return root;
+}
+
+
+static void pubsubSerializer_addMsgSerializerFromBundle(const char *root, bundle_pt bundle, hash_map_pt msgSerializers)
+{
+ char path[MAX_PATH_LEN];
+ struct dirent *entry = NULL;
+ DIR *dir = opendir(root);
+
+ if(dir) {
+ entry = readdir(dir);
+ }
+
+ while (entry != NULL) {
+
+ if (strstr(entry->d_name, ".descriptor") != NULL) {
+
+ printf("DMU: Parsing entry '%s'\n", entry->d_name);
+
+ snprintf(path, MAX_PATH_LEN, "%s/%s", root, entry->d_name);
+ FILE *stream = fopen(path,"r");
+
+ if (stream != NULL){
+ dyn_message_type* msgType = NULL;
+
+ int rc = dynMessage_parse(stream, &msgType);
+ if (rc == 0 && msgType != NULL) {
+
+ char* msgName = NULL;
+ rc += dynMessage_getName(msgType,&msgName);
+
+ version_pt msgVersion = NULL;
+ rc += dynMessage_getVersion(msgType, &msgVersion);
+
+ if(rc == 0 && msgName != NULL && msgVersion != NULL){
+
+ unsigned int msgId = utils_stringHash(msgName);
+
+ pubsub_msg_serializer_t *msgSerializer = calloc(1,sizeof(pubsub_msg_serializer_t));
+
+ msgSerializer->handle = msgType;
+ msgSerializer->msgId = msgId;
+ msgSerializer->msgName = msgName;
+ msgSerializer->msgVersion = msgVersion;
+ msgSerializer->serialize = (void*) pubsubMsgSerializer_serialize;
+ msgSerializer->deserialize = (void*) pubsubMsgSerializer_deserialize;
+ msgSerializer->freeMsg = (void*) pubsubMsgSerializer_freeMsg;
+
+ bool clash = hashMap_containsKey(msgSerializers, (void*)(uintptr_t)msgId);
+ if (clash){
+ printf("Cannot add msg %s. clash in msg id %d!!\n", msgName, msgId);
+ free(msgSerializer);
+ dynMessage_destroy(msgType);
+ }
+ else if (msgId != 0){
+ printf("Adding %u : %s\n", msgId, msgName);
+ hashMap_put(msgSerializers, (void*)(uintptr_t)msgId, msgSerializer);
+ }
+ else{
+ printf("Error creating msg serializer\n");
+ free(msgSerializer);
+ dynMessage_destroy(msgType);
+ }
+
+ }
+ else{
+ printf("Cannot retrieve name and/or version from msg\n");
+ }
+
+ } else{
+ printf("DMU: cannot parse message from descriptor %s\n.",path);
+ }
+ fclose(stream);
+ }else{
+ printf("DMU: cannot open descriptor file %s\n.",path);
+ }
+
+ }
+ entry = readdir(dir);
+ }
+
+ if(dir) {
+ closedir(dir);
+ }
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_serializer_json/src/pubsub_serializer_impl.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_serializer_json/src/pubsub_serializer_impl.h b/pubsub/pubsub_serializer_json/src/pubsub_serializer_impl.h
new file mode 100644
index 0000000..c36f20e
--- /dev/null
+++ b/pubsub/pubsub_serializer_json/src/pubsub_serializer_impl.h
@@ -0,0 +1,55 @@
+/**
+ *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.
+ */
+/*
+ * pubsub_serializer_impl.h
+ *
+ * \date Mar 24, 2017
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PUBSUB_SERIALIZER_JSON_H_
+#define PUBSUB_SERIALIZER_JSON_H_
+
+#include "dyn_common.h"
+#include "dyn_type.h"
+#include "dyn_message.h"
+#include "log_helper.h"
+
+#include "pubsub_serializer.h"
+
+#define PUBSUB_SERIALIZER_TYPE "json"
+
+typedef struct pubsub_serializer {
+ bundle_context_pt bundle_context;
+ log_helper_pt loghelper;
+} pubsub_serializer_t;
+
+celix_status_t pubsubSerializer_create(bundle_context_pt context, pubsub_serializer_t* *serializer);
+celix_status_t pubsubSerializer_destroy(pubsub_serializer_t* serializer);
+
+celix_status_t pubsubSerializer_createSerializerMap(pubsub_serializer_t* serializer, bundle_pt bundle, hash_map_pt* serializerMap);
+celix_status_t pubsubSerializer_destroySerializerMap(pubsub_serializer_t*, hash_map_pt serializerMap);
+
+/* Start of serializer specific functions */
+celix_status_t pubsubMsgSerializer_serialize(pubsub_msg_serializer_t* msgSerializer, const void* msg, void** out, size_t *outLen);
+celix_status_t pubsubMsgSerializer_deserialize(pubsub_msg_serializer_t* msgSerializer, const void* input, size_t inputLen, void **out);
+void pubsubMsgSerializer_freeMsg(pubsub_msg_serializer_t* msgSerializer, void *msg);
+
+#endif /* PUBSUB_SERIALIZER_JSON_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_topology_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_topology_manager/CMakeLists.txt b/pubsub/pubsub_topology_manager/CMakeLists.txt
index b6eb796..784ca21 100644
--- a/pubsub/pubsub_topology_manager/CMakeLists.txt
+++ b/pubsub/pubsub_topology_manager/CMakeLists.txt
@@ -15,21 +15,12 @@
# specific language governing permissions and limitations
# under the License.
-include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/pubsub_admin/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/pubsub/api/pubsub")
-include_directories("private/include")
-include_directories("public/include")
-
add_bundle(org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
BUNDLE_SYMBOLICNAME "apache_celix_pubsub_topology_manager"
VERSION "1.0.0"
SOURCES
private/src/pstm_activator.c
private/src/pubsub_topology_manager.c
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_endpoint.c
${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
)
@@ -38,7 +29,8 @@ bundle_files(org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/include/pubsub_topic_info.descriptor
DESTINATION "META-INF/descriptors/services"
)
+target_link_libraries(org.apache.celix.pubsub_topology_manager.PubSubTopologyManager PRIVATE Celix::framework Celix::log_helper)
+
-target_link_libraries(org.apache.celix.pubsub_topology_manager.PubSubTopologyManager celix_framework celix_utils)
install_bundle(org.apache.celix.pubsub_topology_manager.PubSubTopologyManager)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/test/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/test/CMakeLists.txt b/pubsub/test/CMakeLists.txt
index 8279c0c..65e22e5 100644
--- a/pubsub/test/CMakeLists.txt
+++ b/pubsub/test/CMakeLists.txt
@@ -31,7 +31,7 @@ add_bundle(pubsub_sut
test/sut_activator.c
VERSION 1.0.0
)
-target_link_libraries(pubsub_sut celix_framework celix_utils)
+target_link_libraries(pubsub_sut PRIVATE Celix::framework)
bundle_files(pubsub_sut
msg_descriptors/msg.descriptor
msg_descriptors/sync.descriptor
@@ -66,9 +66,9 @@ add_bundle(pubsub_tst
)
if (APPLE)
#Note that the launcher celix_test_runner is linked with CppuTest, not the bundle libs. Default libCppUTest.a is not compiled for relocation
- target_link_libraries(pubsub_tst celix_framework celix_utils -Wl,-undefined -Wl,dynamic_lookup)
+ target_link_libraries(pubsub_tst PRIVATE Celix::framework -Wl,-undefined -Wl,dynamic_lookup)
else ()
- target_link_libraries(pubsub_tst celix_framework celix_utils)
+ target_link_libraries(pubsub_tst PRIVATE Celix::framework)
endif ()
bundle_files(pubsub_tst
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/CMakeLists.txt b/remote_services/CMakeLists.txt
index 767ece7..7ca1c44 100644
--- a/remote_services/CMakeLists.txt
+++ b/remote_services/CMakeLists.txt
@@ -21,14 +21,16 @@ if (REMOTE_SERVICE_ADMIN)
add_subdirectory(examples)
add_subdirectory(topology_manager)
-
+
+ add_subdirectory(discovery_common)
add_subdirectory(discovery_configured)
add_subdirectory(discovery_etcd)
add_subdirectory(discovery_shm)
#TODO refactor shm rsa to use dfi
+ add_subdirectory(remote_service_admin_api)
+ add_subdirectory(remote_service_admin_common)
#add_subdirectory(remote_service_admin_shm)
- add_subdirectory(remote_service_admin)
add_subdirectory(remote_service_admin_dfi)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery/private/include/discovery.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/include/discovery.h b/remote_services/discovery/private/include/discovery.h
deleted file mode 100644
index ee79caf..0000000
--- a/remote_services/discovery/private/include/discovery.h
+++ /dev/null
@@ -1,67 +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.
- */
-/*
- * discovery.h
- *
- * \date Sep 29, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef DISCOVERY_H_
-#define DISCOVERY_H_
-
-#include "bundle_context.h"
-#include "service_reference.h"
-
-#include "endpoint_description.h"
-#include "endpoint_listener.h"
-
-#define DISCOVERY_SERVER_INTERFACE "DISCOVERY_CFG_SERVER_INTERFACE"
-#define DISCOVERY_SERVER_IP "DISCOVERY_CFG_SERVER_IP"
-#define DISCOVERY_SERVER_PORT "DISCOVERY_CFG_SERVER_PORT"
-#define DISCOVERY_SERVER_PATH "DISCOVERY_CFG_SERVER_PATH"
-#define DISCOVERY_POLL_ENDPOINTS "DISCOVERY_CFG_POLL_ENDPOINTS"
-#define DISCOVERY_SERVER_MAX_EP "DISCOVERY_CFG_SERVER_MAX_EP"
-
-typedef struct discovery *discovery_pt;
-
-
-/* those one could be put into a general discovery.h - file */
-celix_status_t discovery_create(bundle_context_pt context, discovery_pt *discovery);
-celix_status_t discovery_destroy(discovery_pt discovery);
-
-celix_status_t discovery_start(discovery_pt discovery);
-celix_status_t discovery_stop(discovery_pt discovery);
-
-celix_status_t discovery_endpointAdded(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
-celix_status_t discovery_endpointRemoved(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
-
-celix_status_t discovery_endpointListenerAdding(void * handle, service_reference_pt reference, void **service);
-celix_status_t discovery_endpointListenerAdded(void * handle, service_reference_pt reference, void * service);
-celix_status_t discovery_endpointListenerModified(void * handle, service_reference_pt reference, void * service);
-celix_status_t discovery_endpointListenerRemoved(void * handle, service_reference_pt reference, void * service);
-
-celix_status_t discovery_informEndpointListeners(discovery_pt discovery, endpoint_description_pt endpoint, bool endpointAdded);
-celix_status_t discovery_updateEndpointListener(discovery_pt discovery, service_reference_pt reference, endpoint_listener_pt service);
-
-celix_status_t discovery_addDiscoveredEndpoint(discovery_pt discovery, endpoint_description_pt endpoint);
-celix_status_t discovery_removeDiscoveredEndpoint(discovery_pt discovery, endpoint_description_pt endpoint);
-
-#endif /* DISCOVERY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery/private/include/endpoint_descriptor_common.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/include/endpoint_descriptor_common.h b/remote_services/discovery/private/include/endpoint_descriptor_common.h
deleted file mode 100644
index a186a18..0000000
--- a/remote_services/discovery/private/include/endpoint_descriptor_common.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.
- */
-/*
- * endpoint_descriptor_common.h
- *
- * \date Aug 8, 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef ENDPOINT_DESCRIPTOR_COMMON_H_
-#define ENDPOINT_DESCRIPTOR_COMMON_H_
-
-/*
- * Private constant & enum definitions for endpoint descriptor reader and writer, not needed for normal usage of the reader and writer.
- */
-
-typedef enum {
- VALUE_TYPE_STRING,
- VALUE_TYPE_LONG,
- VALUE_TYPE_DOUBLE,
- VALUE_TYPE_FLOAT,
- VALUE_TYPE_INTEGER,
- VALUE_TYPE_BYTE,
- VALUE_TYPE_CHAR,
- VALUE_TYPE_BOOLEAN,
- VALUE_TYPE_SHORT,
-} valueType;
-
-static const __attribute__((unused)) xmlChar* XML = (const xmlChar*) "xml";
-static const __attribute__((unused)) xmlChar* XMLNS = (const xmlChar*) "http://www.osgi.org/xmlns/rsa/v1.0.0";
-
-static const __attribute__((unused)) xmlChar* ENDPOINT_DESCRIPTIONS = (const xmlChar*) "endpoint-descriptions";
-static const xmlChar* ENDPOINT_DESCRIPTION = (const xmlChar*) "endpoint-description";
-
-static const xmlChar* ARRAY = (const xmlChar*) "array";
-static const __attribute__((unused)) xmlChar* LIST = (const xmlChar*) "list";
-static const __attribute__((unused)) xmlChar* SET = (const xmlChar*) "set";
-
-static const xmlChar* PROPERTY = (const xmlChar*) "property";
-static const xmlChar* NAME = (const xmlChar*) "name";
-static const xmlChar* VALUE = (const xmlChar*) "value";
-static const xmlChar* VALUE_TYPE = (const xmlChar*) "value-type";
-
-#endif /* ENDPOINT_DESCRIPTOR_COMMON_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery/private/include/endpoint_descriptor_reader.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/include/endpoint_descriptor_reader.h b/remote_services/discovery/private/include/endpoint_descriptor_reader.h
deleted file mode 100644
index 7a05d9e..0000000
--- a/remote_services/discovery/private/include/endpoint_descriptor_reader.h
+++ /dev/null
@@ -1,42 +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.
- */
-/*
- * endpoint_descriptor_reader.h
- *
- * \date 26 Jul 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef ENDPOINT_DESCRIPTOR_READER_H_
-#define ENDPOINT_DESCRIPTOR_READER_H_
-
-#include "endpoint_discovery_poller.h"
-#include "celix_errno.h"
-#include "array_list.h"
-
-typedef struct endpoint_descriptor_reader *endpoint_descriptor_reader_pt;
-
-celix_status_t endpointDescriptorReader_create(endpoint_discovery_poller_pt poller, endpoint_descriptor_reader_pt *reader);
-celix_status_t endpointDescriptorReader_destroy(endpoint_descriptor_reader_pt reader);
-
-celix_status_t endpointDescriptorReader_parseDocument(endpoint_descriptor_reader_pt reader, char *document, array_list_pt *endpoints);
-
-
-#endif /* ENDPOINT_DESCRIPTOR_READER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery/private/include/endpoint_descriptor_writer.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/include/endpoint_descriptor_writer.h b/remote_services/discovery/private/include/endpoint_descriptor_writer.h
deleted file mode 100644
index 3c5a9be..0000000
--- a/remote_services/discovery/private/include/endpoint_descriptor_writer.h
+++ /dev/null
@@ -1,39 +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.
- */
-/*
- * endpoint_descriptor_writer.h
- *
- * \date 26 Jul 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef ENDPOINT_DESCRIPTOR_WRITER_H_
-#define ENDPOINT_DESCRIPTOR_WRITER_H_
-
-#include "celix_errno.h"
-#include "array_list.h"
-
-typedef struct endpoint_descriptor_writer *endpoint_descriptor_writer_pt;
-
-celix_status_t endpointDescriptorWriter_create(endpoint_descriptor_writer_pt *writer);
-celix_status_t endpointDescriptorWriter_destroy(endpoint_descriptor_writer_pt writer);
-celix_status_t endpointDescriptorWriter_writeDocument(endpoint_descriptor_writer_pt writer, array_list_pt endpoints, char **document);
-
-#endif /* ENDPOINT_DESCRIPTOR_WRITER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery/private/include/endpoint_discovery_poller.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/include/endpoint_discovery_poller.h b/remote_services/discovery/private/include/endpoint_discovery_poller.h
deleted file mode 100644
index d344e55..0000000
--- a/remote_services/discovery/private/include/endpoint_discovery_poller.h
+++ /dev/null
@@ -1,56 +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.
- */
-/*
- * endpoint_discovery_poller.h
- *
- * \date 3 Jul 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef ENDPOINT_DISCOVERY_POLLER_H_
-#define ENDPOINT_DISCOVERY_POLLER_H_
-
-#include "celix_errno.h"
-#include "discovery.h"
-#include "log_helper.h"
-
-struct endpoint_discovery_poller {
- discovery_pt discovery;
- hash_map_pt entries;
- log_helper_pt* loghelper;
-
- celix_thread_mutex_t pollerLock;
- celix_thread_t pollerThread;
-
- unsigned int poll_interval;
- volatile bool running;
-};
-
-typedef struct endpoint_discovery_poller *endpoint_discovery_poller_pt;
-
-celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_poller_pt *poller);
-celix_status_t endpointDiscoveryPoller_destroy(endpoint_discovery_poller_pt poller);
-
-celix_status_t endpointDiscoveryPoller_addDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url);
-celix_status_t endpointDiscoveryPoller_removeDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url);
-
-celix_status_t endpointDiscoveryPoller_getDiscoveryEndpoints(endpoint_discovery_poller_pt poller, array_list_pt urls);
-
-#endif /* ENDPOINT_DISCOVERY_POLLER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery/private/include/endpoint_discovery_server.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/include/endpoint_discovery_server.h b/remote_services/discovery/private/include/endpoint_discovery_server.h
deleted file mode 100644
index 51082b5..0000000
--- a/remote_services/discovery/private/include/endpoint_discovery_server.h
+++ /dev/null
@@ -1,81 +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.
- */
-/*
- * endpoint_discovery_server.h
- *
- * \date Aug 12, 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef ENDPOINT_DISCOVERY_SERVER_H_
-#define ENDPOINT_DISCOVERY_SERVER_H_
-
-#include "celix_errno.h"
-#include "discovery.h"
-
-typedef struct endpoint_discovery_server *endpoint_discovery_server_pt;
-
-/**
- * Creates and starts a new instance of an endpoint discovery server.
- *
- * @param discovery [in] the discovery service itself;
- * @param context [in] the bundle context;
- * @param server [out] the pointer to the created instance.
- * @return CELIX_SUCCESS when successful.
- */
-celix_status_t endpointDiscoveryServer_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_server_pt *server);
-
-/**
- * Stops and destroys a given instance of an endpoint discovery server.
- *
- * @param server [in] the pointer to the instance to destroy.
- * @return CELIX_SUCCESS when successful.
- */
-celix_status_t endpointDiscoveryServer_destroy(endpoint_discovery_server_pt server);
-
-/**
- * Adds a given endpoint description to expose through the given discovery server.
- *
- * @param server [in] the endpoint discovery server to expose the endpoint through;
- * @param endpoint [in] the endpoint description to expose.
- * @return CELIX_SUCCESS when successful.
- */
-celix_status_t endpointDiscoveryServer_addEndpoint(endpoint_discovery_server_pt server, endpoint_description_pt endpoint);
-
-/**
- * Removes a given endpoint description from exposure through the given discovery server.
- *
- * @param server [in] the endpoint discovery server to remove the endpoint from;
- * @param endpoint [in] the endpoint description to remove.
- * @return CELIX_SUCCESS when successful.
- */
-celix_status_t endpointDiscoveryServer_removeEndpoint( endpoint_discovery_server_pt server, endpoint_description_pt endpoint);
-
-/**
- * Returns the url, which is used by the discovery server to announce the endpoints
- *
- * @param server [in] the endpoint discovery server to retrieve the url from
- * @param url [out] url which is used to announce the endpoints.
- * @return CELIX_SUCCESS when successful.
- */
-celix_status_t endpointDiscoveryServer_getUrl(endpoint_discovery_server_pt server, char* url);
-
-
-#endif /* ENDPOINT_DISCOVERY_SERVER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery/private/src/desc.xml
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/src/desc.xml b/remote_services/discovery/private/src/desc.xml
deleted file mode 100644
index 5998992..0000000
--- a/remote_services/discovery/private/src/desc.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- *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.
- -->
-<endpoint-descriptions xmlns="http://www.osgi.org/xmlns/rsa/v1.0.0">
- <endpoint-description>
- <property name="service.intents">
- <list>
- <value>SOAP</value>
- <value>HTTP</value>
- </list>
- </property>
- <property name="endpoint.id" value="http://ws.acme.com:9000/hello" />
- <property name="objectClass" value="com.acme.Foo" />
- <property name="endpoint.package.version.com.acme" value="4.2" />
- <property name="service.imported.configs" value="com.acme" />
- <property name="com.acme.ws.xml">
- <xml>
- <config xmlns="http://acme.com/defs">
- <port>1029</port>
- <host>www.acme.com</host>
- </config>
- </xml>
- </property>
- </endpoint-description>
-</endpoint-descriptions>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/discovery/private/src/discovery.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/src/discovery.c b/remote_services/discovery/private/src/discovery.c
deleted file mode 100644
index e40a887..0000000
--- a/remote_services/discovery/private/src/discovery.c
+++ /dev/null
@@ -1,233 +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.
- */
-/*
- * discovery.c
- *
- * \date Aug 8, 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdbool.h>
-#include <netdb.h>
-#include <string.h>
-
-#include "celix_threads.h"
-#include "bundle_context.h"
-#include "log_helper.h"
-#include "discovery.h"
-#include "discovery_impl.h"
-
-
-celix_status_t discovery_endpointAdded(void *handle, endpoint_description_pt endpoint, char *matchedFilter) {
- celix_status_t status;
- discovery_pt discovery = handle;
-
- logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "Endpoint for %s, with filter \"%s\" added...", endpoint->service, matchedFilter);
-
- status = endpointDiscoveryServer_addEndpoint(discovery->server, endpoint);
-
- return status;
-}
-
-celix_status_t discovery_endpointRemoved(void *handle, endpoint_description_pt endpoint, char *matchedFilter) {
- celix_status_t status;
- discovery_pt discovery = handle;
-
- logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "Endpoint for %s, with filter \"%s\" removed...", endpoint->service, matchedFilter);
-
- status = endpointDiscoveryServer_removeEndpoint(discovery->server, endpoint);
-
- return status;
-}
-
-celix_status_t discovery_endpointListenerAdding(void* handle, service_reference_pt reference, void** service) {
- celix_status_t status = CELIX_SUCCESS;
- discovery_pt discovery = handle;
-
- bundleContext_getService(discovery->context, reference, service);
-
- return status;
-}
-
-celix_status_t discovery_endpointListenerAdded(void* handle, service_reference_pt reference, void* service) {
- celix_status_t status = CELIX_SUCCESS;
- discovery_pt discovery = handle;
-
- const char *discoveryListener = NULL;
- serviceReference_getProperty(reference, "DISCOVERY", &discoveryListener);
- const char *scope = NULL;
- serviceReference_getProperty(reference, OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
-
- filter_pt filter = filter_create(scope);
-
- if (discoveryListener != NULL && strcmp(discoveryListener, "true") == 0) {
- logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "EndpointListener Ignored - Discovery listener");
- } else {
- celixThreadMutex_lock(&discovery->discoveredServicesMutex);
-
- hash_map_iterator_pt iter = hashMapIterator_create(discovery->discoveredServices);
- while (hashMapIterator_hasNext(iter)) {
- endpoint_description_pt endpoint = hashMapIterator_nextValue(iter);
-
- bool matchResult = false;
- filter_match(filter, endpoint->properties, &matchResult);
- if (matchResult) {
- endpoint_listener_pt listener = service;
-
- logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "EndpointListener Added - Add Scope");
-
- listener->endpointAdded(listener->handle, endpoint, NULL);
- }
- }
- hashMapIterator_destroy(iter);
-
- celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
-
- celixThreadMutex_lock(&discovery->listenerReferencesMutex);
-
- hashMap_put(discovery->listenerReferences, reference, NULL);
-
- celixThreadMutex_unlock(&discovery->listenerReferencesMutex);
- }
-
- filter_destroy(filter);
-
- return status;
-}
-
-celix_status_t discovery_endpointListenerModified(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status;
-
- status = discovery_endpointListenerRemoved(handle, reference, service);
- if (status == CELIX_SUCCESS) {
- status = discovery_endpointListenerAdded(handle, reference, service);
- }
-
- return status;
-}
-
-celix_status_t discovery_endpointListenerRemoved(void * handle, service_reference_pt reference, void * service) {
- celix_status_t status;
- discovery_pt discovery = handle;
-
- status = celixThreadMutex_lock(&discovery->listenerReferencesMutex);
-
- if (status == CELIX_SUCCESS) {
- if (discovery->listenerReferences != NULL) {
- if (hashMap_remove(discovery->listenerReferences, reference)) {
- logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "EndpointListener Removed");
- }
- }
-
- status = celixThreadMutex_unlock(&discovery->listenerReferencesMutex);
- }
-
- return status;
-}
-
-celix_status_t discovery_informEndpointListeners(discovery_pt discovery, endpoint_description_pt endpoint, bool endpointAdded) {
- celix_status_t status;
-
- // Inform listeners of new endpoint
- status = celixThreadMutex_lock(&discovery->listenerReferencesMutex);
-
- if (status == CELIX_SUCCESS) {
- if (discovery->listenerReferences != NULL) {
- hash_map_iterator_pt iter = hashMapIterator_create(discovery->listenerReferences);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
-
- service_reference_pt reference = hashMapEntry_getKey(entry);
- endpoint_listener_pt listener = NULL;
-
- const char* scope = NULL;
- serviceReference_getProperty(reference, OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
-
- filter_pt filter = filter_create(scope);
- bool matchResult = false;
-
- status = filter_match(filter, endpoint->properties, &matchResult);
- if (status == CELIX_SUCCESS) {
- if (matchResult) {
- bundleContext_getService(discovery->context, reference, (void **) &listener);
- if (endpointAdded) {
- logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "Adding service (%s)", endpoint->service);
-
- listener->endpointAdded(listener->handle, endpoint, (char*)scope);
- } else {
- logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "Removing service (%s)", endpoint->service);
-
- listener->endpointRemoved(listener->handle, endpoint, (char*)scope);
- }
- }
-
- filter_destroy(filter);
- }
- }
- hashMapIterator_destroy(iter);
- }
-
- status = celixThreadMutex_unlock(&discovery->listenerReferencesMutex);
- }
-
- return status;
-}
-
-celix_status_t discovery_addDiscoveredEndpoint(discovery_pt discovery, endpoint_description_pt endpoint) {
- celix_status_t status;
-
- status = celixThreadMutex_lock(&discovery->discoveredServicesMutex);
-
- if (status == CELIX_SUCCESS) {
- char *endpointId = endpoint->id;
- bool exists = hashMap_get(discovery->discoveredServices, endpointId) != NULL;
- if (!exists) {
- hashMap_put(discovery->discoveredServices, endpointId, endpoint);
- }
-
- status = celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
-
- if (!exists) {
- // notify our listeners that a new endpoint is available...
- discovery_informEndpointListeners(discovery, endpoint, true /* addingService */);
- }
- }
-
- return status;
-}
-
-celix_status_t discovery_removeDiscoveredEndpoint(discovery_pt discovery, endpoint_description_pt endpoint) {
- celix_status_t status;
-
- status = celixThreadMutex_lock(&discovery->discoveredServicesMutex);
-
- if (status == CELIX_SUCCESS) {
- char *endpointId = endpoint->id;
- void *oldValue = hashMap_remove(discovery->discoveredServices, endpointId);
-
- status = celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
-
- if (oldValue) {
- status = discovery_informEndpointListeners(discovery, endpoint, false /* removeService */);
- }
- }
-
- return status;
-}
[53/54] [abbrv] celix git commit: CELIX-417: Some cleanup for the
CelixConfig.cmake file
Posted by pn...@apache.org.
CELIX-417: Some cleanup for the CelixConfig.cmake file
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/481e7985
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/481e7985
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/481e7985
Branch: refs/heads/develop
Commit: 481e79850d21e8dcecf9f880158b4054fd3ded73
Parents: 83d77f4
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Jan 30 20:26:12 2018 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Jan 30 20:26:12 2018 +0100
----------------------------------------------------------------------
cmake/CelixConfig.cmake | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/481e7985/cmake/CelixConfig.cmake
----------------------------------------------------------------------
diff --git a/cmake/CelixConfig.cmake b/cmake/CelixConfig.cmake
index c2d73d7..364b856 100644
--- a/cmake/CelixConfig.cmake
+++ b/cmake/CelixConfig.cmake
@@ -22,22 +22,23 @@
# CELIX_LIBRARIES - libraries to link against
# CELIX_LAUNCHER - The Celix launcher
-set(REL_INSTALL_DIR "${CMAKE_CURRENT_LIST_DIR}/../../..") #from lib/Cmake/Celix
+# relative install dir from lib/CMake/Celix.
+get_filename_component(REL_INSTALL_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
+get_filename_component(REL_INSTALL_DIR "${REL_INSTALL_DIR}" PATH)
+get_filename_component(REL_INSTALL_DIR "${REL_INSTALL_DIR}" PATH)
+get_filename_component(REL_INSTALL_DIR "${REL_INSTALL_DIR}" PATH)
+include("${REL_INSTALL_DIR}/share/celix/cmake/cmake_celix/UseCelix.cmake") #adds celix commands (e.g. add_celix_bundle)
+include("${REL_INSTALL_DIR}/share/celix/cmake/CelixTargets.cmake") #imports lib and exe targets (e.g. Celix::framework)
+include("${REL_INSTALL_DIR}/share/celix/cmake/CelixBundleTargets.cmake") #imports bundle targets (e.g. Celix::shell)
+
+# The rest is added to ensure backwards compatiblity with project using the cmake lib/include var instead of targets.
set(CELIX_CMAKE_MODULES_DIR ${REL_INSTALL_DIR}/share/celix/cmake/Modules)
+
set(CELIX_FRAMEWORK_INCLUDE_DIR "${REL_INSTALL_DIR}/include/celix")
set(CELIX_UTILS_INCLUDE_DIR "${REL_INSTALL_DIR}/include/utils")
set(CELIX_DFI_INCLUDE_DIR "${REL_INSTALL_DIR}/include/dfi")
-include("${REL_INSTALL_DIR}/share/celix/cmake/cmake_celix/UseCelix.cmake")
-
-if(NOT TARGET Celix::framework)
- include("${REL_INSTALL_DIR}/share/celix/cmake/CelixTargets.cmake")
- include("${REL_INSTALL_DIR}/share/celix/cmake/CelixBundleTargets.cmake")
-endif()
-
-
-# The rest is added to ensure backwards compatiblity with project using the cmake lib/include var instead of targets.
set(CELIX_LIBRARIES Celix::framework Celix::utils Celix::dfi)
set(CELIX_INCLUDE_DIRS
$<TARGET_PROPERTY:Celix::framework,INTERFACE_INCLUDE_DIRECTORIES>
@@ -68,4 +69,4 @@ endif ()
set(CELIX_BUNDLES_DIR ${REL_INSTALL_DIR}/share/celix/bundles)
set(CELIX_SHELL_BUNDLE ${CELIX_BUNDLES_DIR}/shell.zip)
-set(CELIX_SHELL_TUI_BUNDLE ${CELIX_BUNDLES_DIR}/shell_tui.zip)
\ No newline at end of file
+set(CELIX_SHELL_TUI_BUNDLE ${CELIX_BUNDLES_DIR}/shell_tui.zip)
[17/54] [abbrv] celix git commit: CELIX-417: Refactor for CMake usage
in RSA, PSA and Docker. mostly trying to identify the api and common libraries
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/src/psa_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/src/psa_activator.c b/pubsub/pubsub_admin_udp_mc/src/psa_activator.c
new file mode 100644
index 0000000..cd4ee07
--- /dev/null
+++ b/pubsub/pubsub_admin_udp_mc/src/psa_activator.c
@@ -0,0 +1,141 @@
+/**
+ *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.
+ */
+/*
+ * psa_activator.c
+ *
+ * \date Sep 30, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+
+#include "bundle_activator.h"
+#include "service_registration.h"
+#include "service_tracker.h"
+
+#include "pubsub_admin_impl.h"
+
+struct activator {
+ pubsub_admin_pt admin;
+ pubsub_admin_service_pt adminService;
+ service_registration_pt registration;
+ service_tracker_pt serializerTracker;
+};
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator;
+
+ activator = calloc(1, sizeof(*activator));
+ if (!activator) {
+ status = CELIX_ENOMEM;
+ }
+ else{
+ *userData = activator;
+
+ status = pubsubAdmin_create(context, &(activator->admin));
+
+ if(status == CELIX_SUCCESS){
+ service_tracker_customizer_pt customizer = NULL;
+ status = serviceTrackerCustomizer_create(activator->admin,
+ NULL,
+ pubsubAdmin_serializerAdded,
+ NULL,
+ pubsubAdmin_serializerRemoved,
+ &customizer);
+ if(status == CELIX_SUCCESS){
+ status = serviceTracker_create(context, PUBSUB_SERIALIZER_SERVICE, customizer, &(activator->serializerTracker));
+ if(status != CELIX_SUCCESS){
+ serviceTrackerCustomizer_destroy(customizer);
+ pubsubAdmin_destroy(activator->admin);
+ }
+ }
+ else{
+ pubsubAdmin_destroy(activator->admin);
+ }
+ }
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+ pubsub_admin_service_pt pubsubAdminSvc = calloc(1, sizeof(*pubsubAdminSvc));
+
+ if (!pubsubAdminSvc) {
+ status = CELIX_ENOMEM;
+ }
+ else{
+ pubsubAdminSvc->admin = activator->admin;
+
+ pubsubAdminSvc->addPublication = pubsubAdmin_addPublication;
+ pubsubAdminSvc->removePublication = pubsubAdmin_removePublication;
+
+ pubsubAdminSvc->addSubscription = pubsubAdmin_addSubscription;
+ pubsubAdminSvc->removeSubscription = pubsubAdmin_removeSubscription;
+
+ pubsubAdminSvc->closeAllPublications = pubsubAdmin_closeAllPublications;
+ pubsubAdminSvc->closeAllSubscriptions = pubsubAdmin_closeAllSubscriptions;
+
+ pubsubAdminSvc->matchEndpoint = pubsubAdmin_matchEndpoint;
+
+ activator->adminService = pubsubAdminSvc;
+
+ status = bundleContext_registerService(context, PUBSUB_ADMIN_SERVICE, pubsubAdminSvc, NULL, &activator->registration);
+
+ status += serviceTracker_open(activator->serializerTracker);
+
+ }
+
+
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ status += serviceTracker_close(activator->serializerTracker);
+ status += serviceRegistration_unregister(activator->registration);
+
+ activator->registration = NULL;
+
+ free(activator->adminService);
+ activator->adminService = NULL;
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ serviceTracker_destroy(activator->serializerTracker);
+ pubsubAdmin_destroy(activator->admin);
+ activator->admin = NULL;
+
+ free(activator);
+
+ return status;
+}
+
+
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/src/pubsub_admin_impl.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/src/pubsub_admin_impl.c b/pubsub/pubsub_admin_udp_mc/src/pubsub_admin_impl.c
new file mode 100644
index 0000000..1fbdb08
--- /dev/null
+++ b/pubsub/pubsub_admin_udp_mc/src/pubsub_admin_impl.c
@@ -0,0 +1,1039 @@
+/**
+ *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.
+ */
+/*
+ * pubsub_admin_impl.c
+ *
+ * \date Sep 30, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifndef ANDROID
+#include <ifaddrs.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+
+#include "constants.h"
+#include "utils.h"
+#include "hash_map.h"
+#include "array_list.h"
+#include "bundle_context.h"
+#include "bundle.h"
+#include "service_reference.h"
+#include "service_registration.h"
+#include "log_helper.h"
+#include "log_service.h"
+#include "celix_threads.h"
+#include "service_factory.h"
+
+#include "pubsub_admin_impl.h"
+#include "topic_subscription.h"
+#include "topic_publication.h"
+#include "pubsub_endpoint.h"
+#include "subscriber.h"
+#include "pubsub_admin_match.h"
+
+static const char *DEFAULT_MC_IP = "224.100.1.1";
+static char *DEFAULT_MC_PREFIX = "224.100";
+
+static celix_status_t pubsubAdmin_getIpAddress(const char* interface, char** ip);
+static celix_status_t pubsubAdmin_addSubscriptionToPendingList(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
+static celix_status_t pubsubAdmin_addAnySubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
+
+static celix_status_t pubsubAdmin_getBestSerializer(pubsub_admin_pt admin,pubsub_endpoint_pt ep, pubsub_serializer_service_t **serSvc);
+static void connectTopicPubSubToSerializer(pubsub_admin_pt admin,pubsub_serializer_service_t *serializer,void *topicPubSub,bool isPublication);
+static void disconnectTopicPubSubFromSerializer(pubsub_admin_pt admin,void *topicPubSub,bool isPublication);
+
+celix_status_t pubsubAdmin_create(bundle_context_pt context, pubsub_admin_pt *admin) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *admin = calloc(1, sizeof(**admin));
+
+ if (!*admin) {
+ return CELIX_ENOMEM;
+ }
+
+ char *mc_ip = NULL;
+ char *if_ip = NULL;
+ int sendSocket = -1;
+
+ if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
+ logHelper_start((*admin)->loghelper);
+ }
+ const char *mc_ip_prop = NULL;
+ bundleContext_getProperty(context,PSA_IP , &mc_ip_prop);
+ if(mc_ip_prop) {
+ mc_ip = strdup(mc_ip_prop);
+ }
+
+#ifndef ANDROID
+ if (mc_ip == NULL) {
+ const char *mc_prefix = NULL;
+ const char *interface = NULL;
+ int b0 = 0, b1 = 0, b2 = 0, b3 = 0;
+ bundleContext_getProperty(context,PSA_MULTICAST_IP_PREFIX , &mc_prefix);
+ if(mc_prefix == NULL) {
+ mc_prefix = DEFAULT_MC_PREFIX;
+ }
+
+ bundleContext_getProperty(context, PSA_ITF, &interface);
+ if (pubsubAdmin_getIpAddress(interface, &if_ip) != CELIX_SUCCESS) {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "PSA_UDP_MC: Could not retrieve IP address for interface %s", interface);
+ }
+
+ printf("IP Detected : %s\n", if_ip);
+ if(if_ip && sscanf(if_ip, "%i.%i.%i.%i", &b0, &b1, &b2, &b3) != 4) {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "PSA_UDP_MC: Could not parse IP address %s", if_ip);
+ b2 = 1;
+ b3 = 1;
+ }
+
+ asprintf(&mc_ip, "%s.%d.%d",mc_prefix, b2, b3);
+
+ sendSocket = socket(AF_INET, SOCK_DGRAM, 0);
+ if(sendSocket == -1) {
+ perror("pubsubAdmin_create:socket");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+
+ if(status == CELIX_SUCCESS){
+ char loop = 1;
+ if(setsockopt(sendSocket, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)) != 0) {
+ perror("pubsubAdmin_create:setsockopt(IP_MULTICAST_LOOP)");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ }
+
+ if(status == CELIX_SUCCESS){
+ struct in_addr multicast_interface;
+ inet_aton(if_ip, &multicast_interface);
+ if(setsockopt(sendSocket, IPPROTO_IP, IP_MULTICAST_IF, &multicast_interface, sizeof(multicast_interface)) != 0) {
+ perror("pubsubAdmin_create:setsockopt(IP_MULTICAST_IF)");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ }
+
+ }
+
+
+ if(status != CELIX_SUCCESS){
+ logHelper_stop((*admin)->loghelper);
+ logHelper_destroy(&((*admin)->loghelper));
+ if(sendSocket >=0){
+ close(sendSocket);
+ }
+ if(if_ip != NULL){
+ free(if_ip);
+ }
+ if(mc_ip != NULL){
+ free(mc_ip);
+ }
+ return status;
+ }
+ else{
+ (*admin)->sendSocket = sendSocket;
+ }
+
+#endif
+
+ (*admin)->bundle_context= context;
+ (*admin)->localPublications = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ (*admin)->subscriptions = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ (*admin)->pendingSubscriptions = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ (*admin)->externalPublications = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ (*admin)->topicSubscriptionsPerSerializer = hashMap_create(NULL, NULL, NULL, NULL);
+ (*admin)->topicPublicationsPerSerializer = hashMap_create(NULL, NULL, NULL, NULL);
+ arrayList_create(&((*admin)->noSerializerSubscriptions));
+ arrayList_create(&((*admin)->noSerializerPublications));
+ arrayList_create(&((*admin)->serializerList));
+
+ celixThreadMutex_create(&(*admin)->localPublicationsLock, NULL);
+ celixThreadMutex_create(&(*admin)->subscriptionsLock, NULL);
+ celixThreadMutex_create(&(*admin)->externalPublicationsLock, NULL);
+ celixThreadMutex_create(&(*admin)->serializerListLock, NULL);
+ celixThreadMutex_create(&(*admin)->usedSerializersLock, NULL);
+
+ celixThreadMutexAttr_create(&(*admin)->noSerializerPendingsAttr);
+ celixThreadMutexAttr_settype(&(*admin)->noSerializerPendingsAttr, CELIX_THREAD_MUTEX_RECURSIVE);
+ celixThreadMutex_create(&(*admin)->noSerializerPendingsLock, &(*admin)->noSerializerPendingsAttr);
+
+ celixThreadMutexAttr_create(&(*admin)->pendingSubscriptionsAttr);
+ celixThreadMutexAttr_settype(&(*admin)->pendingSubscriptionsAttr, CELIX_THREAD_MUTEX_RECURSIVE);
+ celixThreadMutex_create(&(*admin)->pendingSubscriptionsLock, &(*admin)->pendingSubscriptionsAttr);
+
+ if (if_ip != NULL) {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "PSA_UDP_MC: Using %s as interface for multicast communication", if_ip);
+ (*admin)->ifIpAddress = if_ip;
+ } else {
+ (*admin)->ifIpAddress = strdup("127.0.0.1");
+ }
+
+ if (mc_ip != NULL) {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "PSA_UDP_MC: Using %s for service annunciation", mc_ip);
+ (*admin)->mcIpAddress = mc_ip;
+ }
+ else {
+ logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "PSA_UDP_MC: No IP address for service annunciation set. Using %s", DEFAULT_MC_IP);
+ (*admin)->mcIpAddress = strdup(DEFAULT_MC_IP);
+ }
+
+ return status;
+}
+
+
+celix_status_t pubsubAdmin_destroy(pubsub_admin_pt admin)
+{
+ celix_status_t status = CELIX_SUCCESS;
+
+ free(admin->mcIpAddress);
+ free(admin->ifIpAddress);
+
+ celixThreadMutex_lock(&admin->pendingSubscriptionsLock);
+ hash_map_iterator_pt iter = hashMapIterator_create(admin->pendingSubscriptions);
+ while(hashMapIterator_hasNext(iter)){
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ free((char*)hashMapEntry_getKey(entry));
+ arrayList_destroy((array_list_pt)hashMapEntry_getValue(entry));
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(admin->pendingSubscriptions,false,false);
+ celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);
+
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+ hashMap_destroy(admin->subscriptions,false,false);
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ hashMap_destroy(admin->localPublications,true,false);
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+ celixThreadMutex_lock(&admin->externalPublicationsLock);
+ iter = hashMapIterator_create(admin->externalPublications);
+ while(hashMapIterator_hasNext(iter)){
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ free((char*)hashMapEntry_getKey(entry));
+ arrayList_destroy((array_list_pt)hashMapEntry_getValue(entry));
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(admin->externalPublications,false,false);
+ celixThreadMutex_unlock(&admin->externalPublicationsLock);
+
+ celixThreadMutex_lock(&admin->serializerListLock);
+ arrayList_destroy(admin->serializerList);
+ celixThreadMutex_unlock(&admin->serializerListLock);
+
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_destroy(admin->noSerializerSubscriptions);
+ arrayList_destroy(admin->noSerializerPublications);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+
+ celixThreadMutex_lock(&admin->usedSerializersLock);
+
+ iter = hashMapIterator_create(admin->topicSubscriptionsPerSerializer);
+ while(hashMapIterator_hasNext(iter)){
+ arrayList_destroy((array_list_pt)hashMapIterator_nextValue(iter));
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(admin->topicSubscriptionsPerSerializer,false,false);
+
+ iter = hashMapIterator_create(admin->topicPublicationsPerSerializer);
+ while(hashMapIterator_hasNext(iter)){
+ arrayList_destroy((array_list_pt)hashMapIterator_nextValue(iter));
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(admin->topicPublicationsPerSerializer,false,false);
+
+ celixThreadMutex_unlock(&admin->usedSerializersLock);
+
+ celixThreadMutex_destroy(&admin->usedSerializersLock);
+ celixThreadMutex_destroy(&admin->serializerListLock);
+
+ celixThreadMutexAttr_destroy(&admin->noSerializerPendingsAttr);
+ celixThreadMutex_destroy(&admin->noSerializerPendingsLock);
+
+ celixThreadMutex_destroy(&admin->pendingSubscriptionsLock);
+ celixThreadMutexAttr_destroy(&admin->pendingSubscriptionsAttr);
+
+ celixThreadMutex_destroy(&admin->subscriptionsLock);
+ celixThreadMutex_destroy(&admin->localPublicationsLock);
+ celixThreadMutex_destroy(&admin->externalPublicationsLock);
+
+ logHelper_stop(admin->loghelper);
+
+ logHelper_destroy(&admin->loghelper);
+
+ free(admin);
+
+ return status;
+}
+
+static celix_status_t pubsubAdmin_addAnySubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+
+ topic_subscription_pt any_sub = hashMap_get(admin->subscriptions,PUBSUB_ANY_SUB_TOPIC);
+
+ if(any_sub==NULL){
+
+ int i;
+ pubsub_serializer_service_t *best_serializer = NULL;
+ if( (status=pubsubAdmin_getBestSerializer(admin, subEP, &best_serializer)) == CELIX_SUCCESS){
+ status = pubsub_topicSubscriptionCreate(admin->bundle_context, admin->ifIpAddress, PUBSUB_SUBSCRIBER_SCOPE_DEFAULT, PUBSUB_ANY_SUB_TOPIC, best_serializer, &any_sub);
+ }
+ else{
+ printf("PSA_UDP_MC: Cannot find a serializer for subscribing topic %s. Adding it to pending list.\n",subEP->topic);
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_add(admin->noSerializerSubscriptions,subEP);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+
+ if (status == CELIX_SUCCESS){
+
+ /* Connect all internal publishers */
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ hash_map_iterator_pt lp_iter =hashMapIterator_create(admin->localPublications);
+ while(hashMapIterator_hasNext(lp_iter)){
+ service_factory_pt factory = (service_factory_pt)hashMapIterator_nextValue(lp_iter);
+ topic_publication_pt topic_pubs = (topic_publication_pt)factory->handle;
+ array_list_pt topic_publishers = pubsub_topicPublicationGetPublisherList(topic_pubs);
+
+ if(topic_publishers!=NULL){
+ for(i=0;i<arrayList_size(topic_publishers);i++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(topic_publishers,i);
+ if(pubEP->endpoint !=NULL){
+ status += pubsub_topicSubscriptionConnectPublisher(any_sub,pubEP->endpoint);
+ }
+ }
+ arrayList_destroy(topic_publishers);
+ }
+ }
+ hashMapIterator_destroy(lp_iter);
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+ /* Connect also all external publishers */
+ celixThreadMutex_lock(&admin->externalPublicationsLock);
+ hash_map_iterator_pt extp_iter =hashMapIterator_create(admin->externalPublications);
+ while(hashMapIterator_hasNext(extp_iter)){
+ array_list_pt ext_pub_list = (array_list_pt)hashMapIterator_nextValue(extp_iter);
+ if(ext_pub_list!=NULL){
+ for(i=0;i<arrayList_size(ext_pub_list);i++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
+ if(pubEP->endpoint !=NULL){
+ status += pubsub_topicSubscriptionConnectPublisher(any_sub,pubEP->endpoint);
+ }
+ }
+ }
+ }
+ hashMapIterator_destroy(extp_iter);
+ celixThreadMutex_unlock(&admin->externalPublicationsLock);
+
+
+ pubsub_topicSubscriptionAddSubscriber(any_sub,subEP);
+
+ status += pubsub_topicSubscriptionStart(any_sub);
+
+ }
+
+ if (status == CELIX_SUCCESS){
+ hashMap_put(admin->subscriptions,strdup(PUBSUB_ANY_SUB_TOPIC),any_sub);
+ connectTopicPubSubToSerializer(admin, best_serializer, any_sub, false);
+ }
+
+ }
+
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ return status;
+}
+
+celix_status_t pubsubAdmin_addSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ printf("PSA_UDP_MC: Received subscription [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n",subEP->frameworkUUID,subEP->serviceID,subEP->scope,subEP->topic);
+
+ if(strcmp(subEP->topic,PUBSUB_ANY_SUB_TOPIC)==0){
+ return pubsubAdmin_addAnySubscription(admin,subEP);
+ }
+
+ /* Check if we already know some publisher about this topic, otherwise let's put the subscription in the pending hashmap */
+ celixThreadMutex_lock(&admin->pendingSubscriptionsLock);
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ celixThreadMutex_lock(&admin->externalPublicationsLock);
+
+ char* scope_topic = createScopeTopicKey(subEP->scope,subEP->topic);
+
+ service_factory_pt factory = (service_factory_pt)hashMap_get(admin->localPublications,scope_topic);
+ array_list_pt ext_pub_list = (array_list_pt)hashMap_get(admin->externalPublications,scope_topic);
+
+ if(factory==NULL && ext_pub_list==NULL){ //No (local or external) publishers yet for this topic
+ pubsubAdmin_addSubscriptionToPendingList(admin,subEP);
+ }
+ else{
+ int i;
+ topic_subscription_pt subscription = hashMap_get(admin->subscriptions, scope_topic);
+
+ if(subscription == NULL) {
+ pubsub_serializer_service_t *best_serializer = NULL;
+ if( (status=pubsubAdmin_getBestSerializer(admin, subEP, &best_serializer)) == CELIX_SUCCESS){
+ status += pubsub_topicSubscriptionCreate(admin->bundle_context,admin->ifIpAddress, subEP->scope, subEP->topic, best_serializer, &subscription);
+ }
+ else{
+ printf("PSA_UDP_MC: Cannot find a serializer for subscribing topic %s. Adding it to pending list.\n",subEP->topic);
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_add(admin->noSerializerSubscriptions,subEP);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+
+ if (status==CELIX_SUCCESS){
+
+ /* Try to connect internal publishers */
+ if(factory!=NULL){
+ topic_publication_pt topic_pubs = (topic_publication_pt)factory->handle;
+ array_list_pt topic_publishers = pubsub_topicPublicationGetPublisherList(topic_pubs);
+
+ if(topic_publishers!=NULL){
+ for(i=0;i<arrayList_size(topic_publishers);i++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(topic_publishers,i);
+ if(pubEP->endpoint !=NULL){
+ status += pubsub_topicSubscriptionConnectPublisher(subscription,pubEP->endpoint);
+ }
+ }
+ arrayList_destroy(topic_publishers);
+ }
+
+ }
+
+ /* Look also for external publishers */
+ if(ext_pub_list!=NULL){
+ for(i=0;i<arrayList_size(ext_pub_list);i++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
+ if(pubEP->endpoint !=NULL){
+ status += pubsub_topicSubscriptionConnectPublisher(subscription,pubEP->endpoint);
+ }
+ }
+ }
+
+ pubsub_topicSubscriptionAddSubscriber(subscription,subEP);
+
+ status += pubsub_topicSubscriptionStart(subscription);
+
+ }
+
+ if(status==CELIX_SUCCESS){
+
+ hashMap_put(admin->subscriptions,strdup(scope_topic),subscription);
+
+ connectTopicPubSubToSerializer(admin, best_serializer, subscription, false);
+ }
+ }
+
+ if (status == CELIX_SUCCESS){
+ pubsub_topicIncreaseNrSubscribers(subscription);
+ }
+ }
+
+ free(scope_topic);
+ celixThreadMutex_unlock(&admin->externalPublicationsLock);
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+ celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);
+
+ return status;
+
+}
+
+celix_status_t pubsubAdmin_removeSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ printf("PSA_UDP_MC: Removing subscription [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n",subEP->frameworkUUID,subEP->serviceID,subEP->scope, subEP->topic);
+
+ char* scope_topic = createScopeTopicKey(subEP->scope, subEP->topic);
+
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+ topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic);
+ if(sub!=NULL){
+ pubsub_topicDecreaseNrSubscribers(sub);
+ if(pubsub_topicGetNrSubscribers(sub) == 0) {
+ status = pubsub_topicSubscriptionRemoveSubscriber(sub,subEP);
+ }
+ }
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ if(sub==NULL){
+ /* Maybe the endpoint was pending */
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ if(!arrayList_removeElement(admin->noSerializerSubscriptions, subEP)){
+ status = CELIX_ILLEGAL_STATE;
+ }
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+
+ free(scope_topic);
+
+
+
+ return status;
+
+}
+
+celix_status_t pubsubAdmin_addPublication(pubsub_admin_pt admin,pubsub_endpoint_pt pubEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ printf("PSA_UDP_MC: Received publication [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n",pubEP->frameworkUUID,pubEP->serviceID,pubEP->scope, pubEP->topic);
+
+ const char* fwUUID = NULL;
+
+ bundleContext_getProperty(admin->bundle_context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
+ if(fwUUID==NULL){
+ printf("PSA_UDP_MC: Cannot retrieve fwUUID.\n");
+ return CELIX_INVALID_BUNDLE_CONTEXT;
+ }
+ char* scope_topic = createScopeTopicKey(pubEP->scope, pubEP->topic);
+
+ if ((strcmp(pubEP->frameworkUUID, fwUUID) == 0) && (pubEP->endpoint == NULL)) {
+
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+
+ service_factory_pt factory = (service_factory_pt) hashMap_get(admin->localPublications, scope_topic);
+
+ if (factory == NULL) {
+ topic_publication_pt pub = NULL;
+ pubsub_serializer_service_t *best_serializer = NULL;
+ if( (status=pubsubAdmin_getBestSerializer(admin, pubEP, &best_serializer)) == CELIX_SUCCESS){
+ status = pubsub_topicPublicationCreate(admin->sendSocket, pubEP, best_serializer, admin->mcIpAddress, &pub);
+ }
+ else{
+ printf("PSA_UDP_MC: Cannot find a serializer for publishing topic %s. Adding it to pending list.\n", pubEP->topic);
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_add(admin->noSerializerPublications,pubEP);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = pubsub_topicPublicationStart(admin->bundle_context, pub, &factory);
+ if (status == CELIX_SUCCESS && factory != NULL) {
+ hashMap_put(admin->localPublications, strdup(scope_topic), factory);
+ connectTopicPubSubToSerializer(admin, best_serializer, pub, true);
+ }
+ } else {
+ printf("PSA_UDP_MC: Cannot create a topicPublication for scope=%s, topic=%s (bundle %ld).\n", pubEP->scope, pubEP->topic, pubEP->serviceID);
+ }
+ } else {
+ //just add the new EP to the list
+ topic_publication_pt pub = (topic_publication_pt) factory->handle;
+ pubsub_topicPublicationAddPublisherEP(pub, pubEP);
+ }
+
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+ }
+ else{
+
+ celixThreadMutex_lock(&admin->externalPublicationsLock);
+ array_list_pt ext_pub_list = (array_list_pt) hashMap_get(admin->externalPublications, scope_topic);
+ if (ext_pub_list == NULL) {
+ arrayList_create(&ext_pub_list);
+ hashMap_put(admin->externalPublications, strdup(scope_topic), ext_pub_list);
+ }
+
+ arrayList_add(ext_pub_list, pubEP);
+
+ celixThreadMutex_unlock(&admin->externalPublicationsLock);
+ }
+
+ /* Re-evaluate the pending subscriptions */
+ celixThreadMutex_lock(&admin->pendingSubscriptionsLock);
+
+ hash_map_entry_pt pendingSub = hashMap_getEntry(admin->pendingSubscriptions, scope_topic);
+ if (pendingSub != NULL) { //There were pending subscription for the just published topic. Let's connect them.
+ char* topic = (char*) hashMapEntry_getKey(pendingSub);
+ array_list_pt pendingSubList = (array_list_pt) hashMapEntry_getValue(pendingSub);
+ int i;
+ for (i = 0; i < arrayList_size(pendingSubList); i++) {
+ pubsub_endpoint_pt subEP = (pubsub_endpoint_pt) arrayList_get(pendingSubList, i);
+ pubsubAdmin_addSubscription(admin, subEP);
+ }
+ hashMap_remove(admin->pendingSubscriptions, scope_topic);
+ arrayList_clear(pendingSubList);
+ arrayList_destroy(pendingSubList);
+ free(topic);
+ }
+
+ celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);
+
+ /* Connect the new publisher to the subscription for his topic, if there is any */
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+
+ topic_subscription_pt sub = (topic_subscription_pt) hashMap_get(admin->subscriptions, scope_topic);
+ if (sub != NULL && pubEP->endpoint != NULL) {
+ pubsub_topicSubscriptionAddConnectPublisherToPendingList(sub, pubEP->endpoint);
+ }
+
+ /* And check also for ANY subscription */
+ topic_subscription_pt any_sub = (topic_subscription_pt) hashMap_get(admin->subscriptions, PUBSUB_ANY_SUB_TOPIC);
+ if (any_sub != NULL && pubEP->endpoint != NULL) {
+ pubsub_topicSubscriptionAddConnectPublisherToPendingList(any_sub, pubEP->endpoint);
+ }
+
+ free(scope_topic);
+
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ return status;
+
+}
+
+celix_status_t pubsubAdmin_removePublication(pubsub_admin_pt admin,pubsub_endpoint_pt pubEP){
+ celix_status_t status = CELIX_SUCCESS;
+ int count = 0;
+
+ printf("PSA_UDP_MC: Removing publication [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n",pubEP->frameworkUUID,pubEP->serviceID,pubEP->scope, pubEP->topic);
+
+ const char* fwUUID = NULL;
+
+ bundleContext_getProperty(admin->bundle_context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
+ if(fwUUID==NULL){
+ printf("PSA_UDP_MC: Cannot retrieve fwUUID.\n");
+ return CELIX_INVALID_BUNDLE_CONTEXT;
+ }
+ char *scope_topic = createScopeTopicKey(pubEP->scope, pubEP->topic);
+
+ if(strcmp(pubEP->frameworkUUID,fwUUID)==0){
+
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ service_factory_pt factory = (service_factory_pt)hashMap_get(admin->localPublications,scope_topic);
+ if(factory!=NULL){
+ topic_publication_pt pub = (topic_publication_pt)factory->handle;
+ pubsub_topicPublicationRemovePublisherEP(pub,pubEP);
+ }
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+ if(factory==NULL){
+ /* Maybe the endpoint was pending */
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ if(!arrayList_removeElement(admin->noSerializerPublications, pubEP)){
+ status = CELIX_ILLEGAL_STATE;
+ }
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+
+ }
+ else{
+
+ celixThreadMutex_lock(&admin->externalPublicationsLock);
+ array_list_pt ext_pub_list = (array_list_pt)hashMap_get(admin->externalPublications,scope_topic);
+ if(ext_pub_list!=NULL){
+ int i;
+ bool found = false;
+ for(i=0;!found && i<arrayList_size(ext_pub_list);i++){
+ pubsub_endpoint_pt p = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
+ found = pubsubEndpoint_equals(pubEP,p);
+ if (found){
+ arrayList_remove(ext_pub_list,i);
+ }
+ }
+ // Check if there are more publishers on the same endpoint (happens when 1 celix-instance with multiple bundles publish in same topic)
+ for(i=0; i<arrayList_size(ext_pub_list);i++) {
+ pubsub_endpoint_pt p = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
+ if (strcmp(pubEP->endpoint,p->endpoint) == 0) {
+ count++;
+ }
+ }
+
+ if(arrayList_size(ext_pub_list)==0){
+ hash_map_entry_pt entry = hashMap_getEntry(admin->externalPublications,scope_topic);
+ char* topic = (char*)hashMapEntry_getKey(entry);
+ array_list_pt list = (array_list_pt)hashMapEntry_getValue(entry);
+ hashMap_remove(admin->externalPublications,topic);
+ arrayList_destroy(list);
+ free(topic);
+ }
+ }
+
+ celixThreadMutex_unlock(&admin->externalPublicationsLock);
+ }
+
+ /* Check if this publisher was connected to one of our subscribers*/
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+
+ topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic);
+ if(sub!=NULL && pubEP->endpoint!=NULL && count == 0){
+ pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(sub,pubEP->endpoint);
+ }
+
+ /* And check also for ANY subscription */
+ topic_subscription_pt any_sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,PUBSUB_ANY_SUB_TOPIC);
+ if(any_sub!=NULL && pubEP->endpoint!=NULL && count == 0){
+ pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(any_sub,pubEP->endpoint);
+ }
+
+ free(scope_topic);
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ return status;
+
+}
+
+celix_status_t pubsubAdmin_closeAllPublications(pubsub_admin_pt admin,char *scope, char* topic){
+ celix_status_t status = CELIX_SUCCESS;
+
+ printf("PSA_UDP_MC: Closing all publications for scope=%s,topic=%s\n", scope, topic);
+
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ char* scope_topic =createScopeTopicKey(scope, topic);
+ hash_map_entry_pt pubsvc_entry = (hash_map_entry_pt)hashMap_getEntry(admin->localPublications,scope_topic);
+ if(pubsvc_entry!=NULL){
+ char* key = (char*)hashMapEntry_getKey(pubsvc_entry);
+ service_factory_pt factory= (service_factory_pt)hashMapEntry_getValue(pubsvc_entry);
+ topic_publication_pt pub = (topic_publication_pt)factory->handle;
+ status += pubsub_topicPublicationStop(pub);
+ disconnectTopicPubSubFromSerializer(admin, pub, true);
+ status += pubsub_topicPublicationDestroy(pub);
+ hashMap_remove(admin->localPublications,scope_topic);
+ free(key);
+ free(factory);
+ }
+ free(scope_topic);
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+ return status;
+
+}
+
+celix_status_t pubsubAdmin_closeAllSubscriptions(pubsub_admin_pt admin,char *scope, char* topic){
+ celix_status_t status = CELIX_SUCCESS;
+
+ printf("PSA_UDP_MC: Closing all subscriptions\n");
+
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+ char* scope_topic =createScopeTopicKey(scope, topic);
+ hash_map_entry_pt sub_entry = (hash_map_entry_pt)hashMap_getEntry(admin->subscriptions,scope_topic);
+ if(sub_entry!=NULL){
+ char* topic = (char*)hashMapEntry_getKey(sub_entry);
+
+ topic_subscription_pt ts = (topic_subscription_pt)hashMapEntry_getValue(sub_entry);
+ status += pubsub_topicSubscriptionStop(ts);
+ disconnectTopicPubSubFromSerializer(admin, ts, false);
+ status += pubsub_topicSubscriptionDestroy(ts);
+ hashMap_remove(admin->subscriptions,topic);
+ free(topic);
+
+ }
+ free(scope_topic);
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ return status;
+
+}
+
+
+#ifndef ANDROID
+static celix_status_t pubsubAdmin_getIpAddress(const char* interface, char** ip) {
+ celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+
+ struct ifaddrs *ifaddr, *ifa;
+ char host[NI_MAXHOST];
+
+ if (getifaddrs(&ifaddr) != -1)
+ {
+ for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
+ {
+ if (ifa->ifa_addr == NULL)
+ continue;
+
+ if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
+ if (interface == NULL) {
+ *ip = strdup(host);
+ status = CELIX_SUCCESS;
+ }
+ else if (strcmp(ifa->ifa_name, interface) == 0) {
+ *ip = strdup(host);
+ status = CELIX_SUCCESS;
+ }
+ }
+ }
+
+ freeifaddrs(ifaddr);
+ }
+
+ return status;
+}
+#endif
+
+static celix_status_t pubsubAdmin_addSubscriptionToPendingList(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ char* scope_topic =createScopeTopicKey(subEP->scope, subEP->topic);
+ array_list_pt pendingListPerTopic = hashMap_get(admin->pendingSubscriptions,scope_topic);
+ if(pendingListPerTopic==NULL){
+ arrayList_create(&pendingListPerTopic);
+ hashMap_put(admin->pendingSubscriptions,strdup(scope_topic),pendingListPerTopic);
+ }
+ arrayList_add(pendingListPerTopic,subEP);
+ free(scope_topic);
+
+ return status;
+}
+
+
+celix_status_t pubsubAdmin_serializerAdded(void * handle, service_reference_pt reference, void * service){
+ /* Assumption: serializers are all available at startup.
+ * If a new (possibly better) serializer is installed and started, already created topic_publications/subscriptions will not be destroyed and recreated */
+
+ celix_status_t status = CELIX_SUCCESS;
+ int i=0;
+
+ const char *serType = NULL;
+ serviceReference_getProperty(reference, PUBSUB_SERIALIZER_TYPE_KEY,&serType);
+ if(serType == NULL){
+ printf("Serializer serviceReference %p has no pubsub_serializer.type property specified\n",reference);
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+ pubsub_admin_pt admin = (pubsub_admin_pt)handle;
+ celixThreadMutex_lock(&admin->serializerListLock);
+ arrayList_add(admin->serializerList, reference);
+ celixThreadMutex_unlock(&admin->serializerListLock);
+
+ /* Now let's re-evaluate the pending */
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+
+ for(i=0;i<arrayList_size(admin->noSerializerSubscriptions);i++){
+ pubsub_endpoint_pt ep = (pubsub_endpoint_pt)arrayList_get(admin->noSerializerSubscriptions,i);
+ pubsub_serializer_service_t *best_serializer = NULL;
+ pubsubAdmin_getBestSerializer(admin, ep, &best_serializer);
+ if(best_serializer != NULL){ /* Finally we have a valid serializer! */
+ pubsubAdmin_addSubscription(admin, ep);
+ }
+ }
+
+ for(i=0;i<arrayList_size(admin->noSerializerPublications);i++){
+ pubsub_endpoint_pt ep = (pubsub_endpoint_pt)arrayList_get(admin->noSerializerPublications,i);
+ pubsub_serializer_service_t *best_serializer = NULL;
+ pubsubAdmin_getBestSerializer(admin, ep, &best_serializer);
+ if(best_serializer != NULL){ /* Finally we have a valid serializer! */
+ pubsubAdmin_addPublication(admin, ep);
+ }
+ }
+
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+
+ printf("PSA_UDP_MC: %s serializer added\n",serType);
+
+ return status;
+}
+
+celix_status_t pubsubAdmin_serializerRemoved(void * handle, service_reference_pt reference, void * service){
+
+ pubsub_admin_pt admin = (pubsub_admin_pt)handle;
+ int i=0, j=0;
+ const char *serType = NULL;
+
+ serviceReference_getProperty(reference, PUBSUB_SERIALIZER_TYPE_KEY,&serType);
+ if(serType == NULL){
+ printf("Serializer serviceReference %p has no pubsub_serializer.type property specified\n",reference);
+ return CELIX_SERVICE_EXCEPTION;
+ }
+
+ celixThreadMutex_lock(&admin->serializerListLock);
+ /* Remove the serializer from the list */
+ arrayList_removeElement(admin->serializerList, reference);
+ celixThreadMutex_unlock(&admin->serializerListLock);
+
+ celixThreadMutex_lock(&admin->usedSerializersLock);
+ array_list_pt topicPubList = (array_list_pt)hashMap_remove(admin->topicPublicationsPerSerializer, service);
+ array_list_pt topicSubList = (array_list_pt)hashMap_remove(admin->topicSubscriptionsPerSerializer, service);
+ celixThreadMutex_unlock(&admin->usedSerializersLock);
+
+ /* Now destroy the topicPublications, but first put back the pubsub_endpoints back to the noSerializer pending list */
+ if(topicPubList!=NULL){
+ for(i=0;i<arrayList_size(topicPubList);i++){
+ topic_publication_pt topicPub = (topic_publication_pt)arrayList_get(topicPubList,i);
+ /* Stop the topic publication */
+ pubsub_topicPublicationStop(topicPub);
+ /* Get the endpoints that are going to be orphan */
+ array_list_pt pubList = pubsub_topicPublicationGetPublisherList(topicPub);
+ for(j=0;j<arrayList_size(pubList);j++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pubList,j);
+ /* Remove the publication */
+ pubsubAdmin_removePublication(admin, pubEP);
+ /* Reset the endpoint field, so that will be recreated from scratch when a new serializer will be found */
+ if(pubEP->endpoint!=NULL){
+ free(pubEP->endpoint);
+ pubEP->endpoint = NULL;
+ }
+ /* Add the orphan endpoint to the noSerializer pending list */
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_add(admin->noSerializerPublications,pubEP);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+ arrayList_destroy(pubList);
+
+ /* Cleanup also the localPublications hashmap*/
+ celixThreadMutex_lock(&admin->localPublicationsLock);
+ hash_map_iterator_pt iter = hashMapIterator_create(admin->localPublications);
+ char *key = NULL;
+ service_factory_pt factory = NULL;
+ while(hashMapIterator_hasNext(iter)){
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ factory = (service_factory_pt)hashMapEntry_getValue(entry);
+ topic_publication_pt pub = (topic_publication_pt)factory->handle;
+ if(pub==topicPub){
+ key = (char*)hashMapEntry_getKey(entry);
+ break;
+ }
+ }
+ hashMapIterator_destroy(iter);
+ if(key!=NULL){
+ hashMap_remove(admin->localPublications, key);
+ free(factory);
+ free(key);
+ }
+ celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+ /* Finally destroy the topicPublication */
+ pubsub_topicPublicationDestroy(topicPub);
+ }
+ arrayList_destroy(topicPubList);
+ }
+
+ /* Now destroy the topicSubscriptions, but first put back the pubsub_endpoints back to the noSerializer pending list */
+ if(topicSubList!=NULL){
+ for(i=0;i<arrayList_size(topicSubList);i++){
+ topic_subscription_pt topicSub = (topic_subscription_pt)arrayList_get(topicSubList,i);
+ /* Stop the topic subscription */
+ pubsub_topicSubscriptionStop(topicSub);
+ /* Get the endpoints that are going to be orphan */
+ array_list_pt subList = pubsub_topicSubscriptionGetSubscribersList(topicSub);
+ for(j=0;j<arrayList_size(subList);j++){
+ pubsub_endpoint_pt subEP = (pubsub_endpoint_pt)arrayList_get(subList,j);
+ /* Remove the subscription */
+ pubsubAdmin_removeSubscription(admin, subEP);
+ /* Reset the endpoint field, so that will be recreated from scratch when a new serializer will be found */
+ if(subEP->endpoint!=NULL){
+ free(subEP->endpoint);
+ subEP->endpoint = NULL;
+ }
+ /* Add the orphan endpoint to the noSerializer pending list */
+ celixThreadMutex_lock(&admin->noSerializerPendingsLock);
+ arrayList_add(admin->noSerializerSubscriptions,subEP);
+ celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
+ }
+
+ /* Cleanup also the subscriptions hashmap*/
+ celixThreadMutex_lock(&admin->subscriptionsLock);
+ hash_map_iterator_pt iter = hashMapIterator_create(admin->subscriptions);
+ char *key = NULL;
+ while(hashMapIterator_hasNext(iter)){
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ topic_subscription_pt sub = (topic_subscription_pt)hashMapEntry_getValue(entry);
+ if(sub==topicSub){
+ key = (char*)hashMapEntry_getKey(entry);
+ break;
+ }
+ }
+ hashMapIterator_destroy(iter);
+ if(key!=NULL){
+ hashMap_remove(admin->subscriptions, key);
+ free(key);
+ }
+ celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+ /* Finally destroy the topicSubscription */
+ pubsub_topicSubscriptionDestroy(topicSub);
+ }
+ arrayList_destroy(topicSubList);
+ }
+
+ printf("PSA_UDP_MC: %s serializer removed\n",serType);
+
+
+ return CELIX_SUCCESS;
+}
+
+celix_status_t pubsubAdmin_matchEndpoint(pubsub_admin_pt admin, pubsub_endpoint_pt endpoint, double* score){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&admin->serializerListLock);
+ status = pubsub_admin_match(endpoint->topic_props,PUBSUB_ADMIN_TYPE,admin->serializerList,score);
+ celixThreadMutex_unlock(&admin->serializerListLock);
+
+ return status;
+}
+
+/* This one recall the same logic as in the match function */
+static celix_status_t pubsubAdmin_getBestSerializer(pubsub_admin_pt admin,pubsub_endpoint_pt ep, pubsub_serializer_service_t **serSvc){
+
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&admin->serializerListLock);
+ status = pubsub_admin_get_best_serializer(ep->topic_props, admin->serializerList, serSvc);
+ celixThreadMutex_unlock(&admin->serializerListLock);
+
+ return status;
+
+}
+
+static void connectTopicPubSubToSerializer(pubsub_admin_pt admin,pubsub_serializer_service_t *serializer,void *topicPubSub,bool isPublication){
+
+ celixThreadMutex_lock(&admin->usedSerializersLock);
+
+ hash_map_pt map = isPublication?admin->topicPublicationsPerSerializer:admin->topicSubscriptionsPerSerializer;
+ array_list_pt list = (array_list_pt)hashMap_get(map,serializer);
+ if(list==NULL){
+ arrayList_create(&list);
+ hashMap_put(map,serializer,list);
+ }
+ arrayList_add(list,topicPubSub);
+
+ celixThreadMutex_unlock(&admin->usedSerializersLock);
+
+}
+
+static void disconnectTopicPubSubFromSerializer(pubsub_admin_pt admin,void *topicPubSub,bool isPublication){
+
+ celixThreadMutex_lock(&admin->usedSerializersLock);
+
+ hash_map_pt map = isPublication?admin->topicPublicationsPerSerializer:admin->topicSubscriptionsPerSerializer;
+ hash_map_iterator_pt iter = hashMapIterator_create(map);
+ while(hashMapIterator_hasNext(iter)){
+ array_list_pt list = (array_list_pt)hashMapIterator_nextValue(iter);
+ if(arrayList_removeElement(list, topicPubSub)){ //Found it!
+ break;
+ }
+ }
+ hashMapIterator_destroy(iter);
+
+ celixThreadMutex_unlock(&admin->usedSerializersLock);
+
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/src/pubsub_admin_impl.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/src/pubsub_admin_impl.h b/pubsub/pubsub_admin_udp_mc/src/pubsub_admin_impl.h
new file mode 100644
index 0000000..de4b813
--- /dev/null
+++ b/pubsub/pubsub_admin_udp_mc/src/pubsub_admin_impl.h
@@ -0,0 +1,93 @@
+/**
+ *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.
+ */
+/*
+ * pubsub_admin_impl.h
+ *
+ * \date Dec 5, 2013
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PUBSUB_ADMIN_UDP_MC_IMPL_H_
+#define PUBSUB_ADMIN_UDP_MC_IMPL_H_
+
+#include "pubsub_admin.h"
+#include "log_helper.h"
+
+#define PUBSUB_ADMIN_TYPE "udp_mc"
+
+struct pubsub_admin {
+
+ bundle_context_pt bundle_context;
+ log_helper_pt loghelper;
+
+ /* List of the available serializers */
+ celix_thread_mutex_t serializerListLock; // List<serializers>
+ array_list_pt serializerList;
+
+ celix_thread_mutex_t localPublicationsLock;
+ hash_map_pt localPublications;//<topic(string),service_factory_pt>
+
+ celix_thread_mutex_t externalPublicationsLock;
+ hash_map_pt externalPublications;//<topic(string),List<pubsub_ep>>
+
+ celix_thread_mutex_t subscriptionsLock;
+ hash_map_pt subscriptions; //<topic(string),topic_subscription>
+
+ celix_thread_mutex_t pendingSubscriptionsLock;
+ celix_thread_mutexattr_t pendingSubscriptionsAttr;
+ hash_map_pt pendingSubscriptions; //<topic(string),List<pubsub_ep>>
+
+ /* Those are used to keep track of valid subscriptions/publications that still have no valid serializer */
+ celix_thread_mutex_t noSerializerPendingsLock;
+ celix_thread_mutexattr_t noSerializerPendingsAttr;
+ array_list_pt noSerializerSubscriptions; // List<pubsub_ep>
+ array_list_pt noSerializerPublications; // List<pubsub_ep>
+
+ celix_thread_mutex_t usedSerializersLock;
+ hash_map_pt topicSubscriptionsPerSerializer; // <serializer,List<topicSubscription>>
+ hash_map_pt topicPublicationsPerSerializer; // <serializer,List<topicPublications>>
+
+ char* ifIpAddress; // The local interface which is used for multicast communication
+ char* mcIpAddress; // The multicast IP address
+
+ int sendSocket;
+ void* zmq_context; // to be removed
+
+};
+
+celix_status_t pubsubAdmin_create(bundle_context_pt context, pubsub_admin_pt *admin);
+celix_status_t pubsubAdmin_destroy(pubsub_admin_pt admin);
+
+celix_status_t pubsubAdmin_addSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
+celix_status_t pubsubAdmin_removeSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP);
+
+celix_status_t pubsubAdmin_addPublication(pubsub_admin_pt admin,pubsub_endpoint_pt pubEP);
+celix_status_t pubsubAdmin_removePublication(pubsub_admin_pt admin,pubsub_endpoint_pt pubEP);
+
+celix_status_t pubsubAdmin_closeAllPublications(pubsub_admin_pt admin,char* scope, char* topic);
+celix_status_t pubsubAdmin_closeAllSubscriptions(pubsub_admin_pt admin,char* scope, char* topic);
+
+celix_status_t pubsubAdmin_serializerAdded(void * handle, service_reference_pt reference, void * service);
+celix_status_t pubsubAdmin_serializerRemoved(void * handle, service_reference_pt reference, void * service);
+
+celix_status_t pubsubAdmin_matchEndpoint(pubsub_admin_pt admin, pubsub_endpoint_pt endpoint, double* score);
+
+
+#endif /* PUBSUB_ADMIN_UDP_MC_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/src/topic_publication.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/src/topic_publication.c b/pubsub/pubsub_admin_udp_mc/src/topic_publication.c
new file mode 100644
index 0000000..e43ec29
--- /dev/null
+++ b/pubsub/pubsub_admin_udp_mc/src/topic_publication.c
@@ -0,0 +1,444 @@
+/**
+ *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
+ *
+ * htPSA_UDP_MC_TP://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.
+ */
+/*
+ * topic_publication.c
+ *
+ * \date Sep 24, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "array_list.h"
+#include "celixbool.h"
+#include "service_registration.h"
+#include "utils.h"
+#include "service_factory.h"
+#include "version.h"
+
+#include "topic_publication.h"
+#include "pubsub_common.h"
+#include "publisher.h"
+#include "large_udp.h"
+
+#include "pubsub_serializer.h"
+
+#define EP_ADDRESS_LEN 32
+
+#define FIRST_SEND_DELAY 2
+
+struct topic_publication {
+ int sendSocket;
+ char* endpoint;
+ service_registration_pt svcFactoryReg;
+ array_list_pt pub_ep_list; //List<pubsub_endpoint>
+ hash_map_pt boundServices; //<bundle_pt,bound_service>
+ celix_thread_mutex_t tp_lock;
+ pubsub_serializer_service_t *serializer;
+ struct sockaddr_in destAddr;
+};
+
+typedef struct publish_bundle_bound_service {
+ topic_publication_pt parent;
+ pubsub_publisher_t service;
+ bundle_pt bundle;
+ char *scope;
+ char *topic;
+ hash_map_pt msgTypes;
+ unsigned short getCount;
+ celix_thread_mutex_t mp_lock;
+ largeUdp_pt largeUdpHandle;
+}* publish_bundle_bound_service_pt;
+
+
+typedef struct pubsub_msg{
+ pubsub_msg_header_pt header;
+ char* payload;
+ unsigned int payloadSize;
+} pubsub_msg_t;
+
+
+static unsigned int rand_range(unsigned int min, unsigned int max);
+
+static celix_status_t pubsub_topicPublicationGetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service);
+static celix_status_t pubsub_topicPublicationUngetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service);
+
+static publish_bundle_bound_service_pt pubsub_createPublishBundleBoundService(topic_publication_pt tp,bundle_pt bundle);
+static void pubsub_destroyPublishBundleBoundService(publish_bundle_bound_service_pt boundSvc);
+
+static int pubsub_topicPublicationSend(void* handle,unsigned int msgTypeId, const void *msg);
+
+static int pubsub_localMsgTypeIdForUUID(void* handle, const char* msgType, unsigned int* msgTypeId);
+
+
+static void delay_first_send_for_late_joiners(void);
+
+
+celix_status_t pubsub_topicPublicationCreate(int sendSocket, pubsub_endpoint_pt pubEP, pubsub_serializer_service_t *best_serializer, char* bindIP, topic_publication_pt *out){
+
+ char* ep = malloc(EP_ADDRESS_LEN);
+ memset(ep,0,EP_ADDRESS_LEN);
+ unsigned int port = pubEP->serviceID + rand_range(UDP_BASE_PORT+pubEP->serviceID+3, UDP_MAX_PORT);
+ snprintf(ep,EP_ADDRESS_LEN,"udp://%s:%u",bindIP,port);
+
+
+ topic_publication_pt pub = calloc(1,sizeof(*pub));
+
+ arrayList_create(&(pub->pub_ep_list));
+ pub->boundServices = hashMap_create(NULL,NULL,NULL,NULL);
+ celixThreadMutex_create(&(pub->tp_lock),NULL);
+
+ pub->endpoint = ep;
+ pub->sendSocket = sendSocket;
+ pub->destAddr.sin_family = AF_INET;
+ pub->destAddr.sin_addr.s_addr = inet_addr(bindIP);
+ pub->destAddr.sin_port = htons(port);
+
+ pub->serializer = best_serializer;
+
+ pubsub_topicPublicationAddPublisherEP(pub,pubEP);
+
+ *out = pub;
+
+ return CELIX_SUCCESS;
+}
+
+celix_status_t pubsub_topicPublicationDestroy(topic_publication_pt pub){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&(pub->tp_lock));
+
+ free(pub->endpoint);
+ arrayList_destroy(pub->pub_ep_list);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(pub->boundServices);
+ while(hashMapIterator_hasNext(iter)){
+ publish_bundle_bound_service_pt bound = hashMapIterator_nextValue(iter);
+ pubsub_destroyPublishBundleBoundService(bound);
+ }
+ hashMapIterator_destroy(iter);
+ hashMap_destroy(pub->boundServices,false,false);
+
+ pub->svcFactoryReg = NULL;
+ pub->serializer = NULL;
+
+ if(close(pub->sendSocket) != 0){
+ status = CELIX_FILE_IO_EXCEPTION;
+ }
+
+ celixThreadMutex_unlock(&(pub->tp_lock));
+
+ celixThreadMutex_destroy(&(pub->tp_lock));
+
+ free(pub);
+
+ return status;
+}
+
+celix_status_t pubsub_topicPublicationStart(bundle_context_pt bundle_context,topic_publication_pt pub,service_factory_pt* svcFactory){
+ celix_status_t status = CELIX_SUCCESS;
+
+ /* Let's register the new service */
+
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pub->pub_ep_list,0);
+
+ if(pubEP!=NULL){
+ service_factory_pt factory = calloc(1, sizeof(*factory));
+ factory->handle = pub;
+ factory->getService = pubsub_topicPublicationGetService;
+ factory->ungetService = pubsub_topicPublicationUngetService;
+
+ properties_pt props = properties_create();
+ properties_set(props,PUBSUB_PUBLISHER_SCOPE,pubEP->scope);
+ properties_set(props,PUBSUB_PUBLISHER_TOPIC,pubEP->topic);
+
+ status = bundleContext_registerServiceFactory(bundle_context,PUBSUB_PUBLISHER_SERVICE_NAME,factory,props,&(pub->svcFactoryReg));
+
+ if(status != CELIX_SUCCESS){
+ properties_destroy(props);
+ printf("PSA_UDP_MC_PSA_UDP_MC_TP: Cannot register ServiceFactory for topic %s, topic %s (bundle %ld).\n",pubEP->scope, pubEP->topic,pubEP->serviceID);
+ }
+ else{
+ *svcFactory = factory;
+ }
+ }
+ else{
+ printf("PSA_UDP_MC_PSA_UDP_MC_TP: Cannot find pubsub_endpoint after adding it...Should never happen!\n");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+
+ return status;
+}
+
+celix_status_t pubsub_topicPublicationStop(topic_publication_pt pub){
+ return serviceRegistration_unregister(pub->svcFactoryReg);
+}
+
+celix_status_t pubsub_topicPublicationAddPublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep){
+
+ celixThreadMutex_lock(&(pub->tp_lock));
+ ep->endpoint = strdup(pub->endpoint);
+ arrayList_add(pub->pub_ep_list,ep);
+ celixThreadMutex_unlock(&(pub->tp_lock));
+
+ return CELIX_SUCCESS;
+}
+
+celix_status_t pubsub_topicPublicationRemovePublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep){
+
+ celixThreadMutex_lock(&(pub->tp_lock));
+ arrayList_removeElement(pub->pub_ep_list,ep);
+ celixThreadMutex_unlock(&(pub->tp_lock));
+
+ return CELIX_SUCCESS;
+}
+
+array_list_pt pubsub_topicPublicationGetPublisherList(topic_publication_pt pub){
+ array_list_pt list = NULL;
+ celixThreadMutex_lock(&(pub->tp_lock));
+ list = arrayList_clone(pub->pub_ep_list);
+ celixThreadMutex_unlock(&(pub->tp_lock));
+ return list;
+}
+
+
+static celix_status_t pubsub_topicPublicationGetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ topic_publication_pt publish = (topic_publication_pt)handle;
+
+ celixThreadMutex_lock(&(publish->tp_lock));
+
+ publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt)hashMap_get(publish->boundServices,bundle);
+ if(bound==NULL){
+ bound = pubsub_createPublishBundleBoundService(publish,bundle);
+ if(bound!=NULL){
+ hashMap_put(publish->boundServices,bundle,bound);
+ }
+ }
+ else{
+ bound->getCount++;
+ }
+
+ if (bound != NULL) {
+ *service = &bound->service;
+ }
+
+ celixThreadMutex_unlock(&(publish->tp_lock));
+
+ return status;
+}
+
+static celix_status_t pubsub_topicPublicationUngetService(void* handle, bundle_pt bundle, service_registration_pt registration, void **service) {
+
+ topic_publication_pt publish = (topic_publication_pt)handle;
+
+ celixThreadMutex_lock(&(publish->tp_lock));
+
+ publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt)hashMap_get(publish->boundServices,bundle);
+ if(bound!=NULL){
+
+ bound->getCount--;
+ if(bound->getCount==0){
+ pubsub_destroyPublishBundleBoundService(bound);
+ hashMap_remove(publish->boundServices,bundle);
+ }
+
+ }
+ else{
+ long bundleId = -1;
+ bundle_getBundleId(bundle,&bundleId);
+ printf("PSA_UDP_MC_TP: Unexpected ungetService call for bundle %ld.\n", bundleId);
+ }
+
+ /* service should be never used for unget, so let's set the pointer to NULL */
+ *service = NULL;
+
+ celixThreadMutex_unlock(&(publish->tp_lock));
+
+ return CELIX_SUCCESS;
+}
+
+static bool send_pubsub_msg(publish_bundle_bound_service_pt bound, pubsub_msg_t* msg, bool last, pubsub_release_callback_t *releaseCallback){
+ const int iovec_len = 3; // header + size + payload
+ bool ret = true;
+
+ struct iovec msg_iovec[iovec_len];
+ msg_iovec[0].iov_base = msg->header;
+ msg_iovec[0].iov_len = sizeof(*msg->header);
+ msg_iovec[1].iov_base = &msg->payloadSize;
+ msg_iovec[1].iov_len = sizeof(msg->payloadSize);
+ msg_iovec[2].iov_base = msg->payload;
+ msg_iovec[2].iov_len = msg->payloadSize;
+
+ delay_first_send_for_late_joiners();
+
+ if(largeUdp_sendmsg(bound->largeUdpHandle, bound->parent->sendSocket, msg_iovec, iovec_len, 0, &bound->parent->destAddr, sizeof(bound->parent->destAddr)) == -1) {
+ perror("send_pubsub_msg:sendSocket");
+ ret = false;
+ }
+
+ if(releaseCallback) {
+ releaseCallback->release(msg->payload, bound);
+ }
+ return ret;
+
+}
+
+
+static int pubsub_topicPublicationSend(void* handle, unsigned int msgTypeId, const void *inMsg) {
+ int status = 0;
+ publish_bundle_bound_service_pt bound = (publish_bundle_bound_service_pt) handle;
+
+ celixThreadMutex_lock(&(bound->parent->tp_lock));
+ celixThreadMutex_lock(&(bound->mp_lock));
+
+ pubsub_msg_serializer_t* msgSer = (pubsub_msg_serializer_t*)hashMap_get(bound->msgTypes, (void*)(uintptr_t)msgTypeId);
+
+ if (msgSer != NULL) {
+ int major=0, minor=0;
+
+ pubsub_msg_header_pt msg_hdr = calloc(1,sizeof(struct pubsub_msg_header));
+ strncpy(msg_hdr->topic,bound->topic,MAX_TOPIC_LEN-1);
+ msg_hdr->type = msgTypeId;
+
+
+ if (msgSer->msgVersion != NULL){
+ version_getMajor(msgSer->msgVersion, &major);
+ version_getMinor(msgSer->msgVersion, &minor);
+ msg_hdr->major = major;
+ msg_hdr->minor = minor;
+ }
+
+ void* serializedOutput = NULL;
+ size_t serializedOutputLen = 0;
+ msgSer->serialize(msgSer,inMsg,&serializedOutput, &serializedOutputLen);
+
+ pubsub_msg_t *msg = calloc(1,sizeof(pubsub_msg_t));
+ msg->header = msg_hdr;
+ msg->payload = (char*)serializedOutput;
+ msg->payloadSize = serializedOutputLen;
+
+
+ if(send_pubsub_msg(bound, msg,true, NULL) == false) {
+ status = -1;
+ }
+ free(msg_hdr);
+ free(msg);
+ free(serializedOutput);
+
+
+ } else {
+ printf("PSA_UDP_MC_TP: No msg serializer available for msg type id %d\n", msgTypeId);
+ status=-1;
+ }
+
+ celixThreadMutex_unlock(&(bound->mp_lock));
+ celixThreadMutex_unlock(&(bound->parent->tp_lock));
+
+ return status;
+}
+
+static int pubsub_localMsgTypeIdForUUID(void* handle, const char* msgType, unsigned int* msgTypeId){
+ *msgTypeId = utils_stringHash(msgType);
+ return 0;
+}
+
+
+static unsigned int rand_range(unsigned int min, unsigned int max){
+
+ double scaled = (double)(((double)random())/((double)RAND_MAX));
+ return (max-min+1)*scaled + min;
+
+}
+
+static publish_bundle_bound_service_pt pubsub_createPublishBundleBoundService(topic_publication_pt tp,bundle_pt bundle){
+
+ publish_bundle_bound_service_pt bound = calloc(1, sizeof(*bound));
+
+ if (bound != NULL) {
+
+ bound->parent = tp;
+ bound->bundle = bundle;
+ bound->getCount = 1;
+ celixThreadMutex_create(&bound->mp_lock,NULL);
+
+ if(tp->serializer != NULL){
+ tp->serializer->createSerializerMap(tp->serializer->handle,bundle,&bound->msgTypes);
+ }
+
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(bound->parent->pub_ep_list,0);
+ bound->scope=strdup(pubEP->scope);
+ bound->topic=strdup(pubEP->topic);
+ bound->largeUdpHandle = largeUdp_create(1);
+
+ bound->service.handle = bound;
+ bound->service.localMsgTypeIdForMsgType = pubsub_localMsgTypeIdForUUID;
+ bound->service.send = pubsub_topicPublicationSend;
+ bound->service.sendMultipart = NULL; //Multipart not supported for UDP
+
+ }
+
+ return bound;
+}
+
+static void pubsub_destroyPublishBundleBoundService(publish_bundle_bound_service_pt boundSvc){
+
+ celixThreadMutex_lock(&boundSvc->mp_lock);
+
+ if(boundSvc->parent->serializer != NULL && boundSvc->msgTypes != NULL){
+ boundSvc->parent->serializer->destroySerializerMap(boundSvc->parent->serializer->handle, boundSvc->msgTypes);
+ }
+
+ if(boundSvc->scope!=NULL){
+ free(boundSvc->scope);
+ }
+
+ if(boundSvc->topic!=NULL){
+ free(boundSvc->topic);
+ }
+
+ largeUdp_destroy(boundSvc->largeUdpHandle);
+
+ celixThreadMutex_unlock(&boundSvc->mp_lock);
+ celixThreadMutex_destroy(&boundSvc->mp_lock);
+
+ free(boundSvc);
+
+}
+
+static void delay_first_send_for_late_joiners(){
+
+ static bool firstSend = true;
+
+ if(firstSend){
+ printf("PSA_UDP_MC_TP: Delaying first send for late joiners...\n");
+ sleep(FIRST_SEND_DELAY);
+ firstSend = false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/src/topic_publication.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/src/topic_publication.h b/pubsub/pubsub_admin_udp_mc/src/topic_publication.h
new file mode 100644
index 0000000..4363d71
--- /dev/null
+++ b/pubsub/pubsub_admin_udp_mc/src/topic_publication.h
@@ -0,0 +1,57 @@
+/**
+ *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.
+ */
+/*
+ * topic_publication.h
+ *
+ * \date Sep 24, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef TOPIC_PUBLICATION_H_
+#define TOPIC_PUBLICATION_H_
+
+#include "publisher.h"
+#include "pubsub_endpoint.h"
+#include "pubsub_common.h"
+
+#include "pubsub_serializer.h"
+
+#define UDP_BASE_PORT 49152
+#define UDP_MAX_PORT 65000
+
+typedef struct pubsub_udp_msg {
+ struct pubsub_msg_header header;
+ unsigned int payloadSize;
+ char payload[];
+} pubsub_udp_msg_t;
+
+typedef struct topic_publication *topic_publication_pt;
+celix_status_t pubsub_topicPublicationCreate(int sendSocket, pubsub_endpoint_pt pubEP, pubsub_serializer_service_t *best_serializer, char* bindIP, topic_publication_pt *out);
+celix_status_t pubsub_topicPublicationDestroy(topic_publication_pt pub);
+
+celix_status_t pubsub_topicPublicationAddPublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep);
+celix_status_t pubsub_topicPublicationRemovePublisherEP(topic_publication_pt pub,pubsub_endpoint_pt ep);
+
+celix_status_t pubsub_topicPublicationStart(bundle_context_pt bundle_context,topic_publication_pt pub,service_factory_pt* svcFactory);
+celix_status_t pubsub_topicPublicationStop(topic_publication_pt pub);
+
+array_list_pt pubsub_topicPublicationGetPublisherList(topic_publication_pt pub);
+
+#endif /* TOPIC_PUBLICATION_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/src/topic_subscription.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/src/topic_subscription.c b/pubsub/pubsub_admin_udp_mc/src/topic_subscription.c
new file mode 100644
index 0000000..d8e6f45
--- /dev/null
+++ b/pubsub/pubsub_admin_udp_mc/src/topic_subscription.c
@@ -0,0 +1,635 @@
+/**
+ *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.
+ */
+/*
+ * topic_subscription.c
+ *
+ * \date Oct 2, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/epoll.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "utils.h"
+#include "celix_errno.h"
+#include "constants.h"
+#include "version.h"
+
+#include "topic_subscription.h"
+#include "topic_publication.h"
+#include "subscriber.h"
+#include "publisher.h"
+#include "large_udp.h"
+
+#include "pubsub_serializer.h"
+
+#define MAX_EPOLL_EVENTS 10
+#define RECV_THREAD_TIMEOUT 5
+#define UDP_BUFFER_SIZE 65535
+#define MAX_UDP_SESSIONS 16
+
+struct topic_subscription{
+ char* ifIpAddress;
+ service_tracker_pt tracker;
+ array_list_pt sub_ep_list;
+ celix_thread_t recv_thread;
+ bool running;
+ celix_thread_mutex_t ts_lock;
+ bundle_context_pt context;
+
+ pubsub_serializer_service_t *serializer;
+
+ int topicEpollFd; // EPOLL filedescriptor where the sockets are registered.
+ hash_map_pt servicesMap; // key = service, value = msg types map
+ hash_map_pt socketMap; // key = URL, value = listen-socket
+ celix_thread_mutex_t socketMap_lock;
+
+ celix_thread_mutex_t pendingConnections_lock;
+ array_list_pt pendingConnections;
+
+ array_list_pt pendingDisconnections;
+ celix_thread_mutex_t pendingDisconnections_lock;
+
+ //array_list_pt rawServices;
+ unsigned int nrSubscribers;
+ largeUdp_pt largeUdpHandle;
+};
+
+typedef struct msg_map_entry{
+ bool retain;
+ void* msgInst;
+}* msg_map_entry_pt;
+
+static celix_status_t topicsub_subscriberTracked(void * handle, service_reference_pt reference, void * service);
+static celix_status_t topicsub_subscriberUntracked(void * handle, service_reference_pt reference, void * service);
+static void* udp_recv_thread_func(void* arg);
+static bool checkVersion(version_pt msgVersion,pubsub_msg_header_pt hdr);
+static void sigusr1_sighandler(int signo);
+static int pubsub_localMsgTypeIdForMsgType(void* handle, const char* msgType, unsigned int* msgTypeId);
+static void connectPendingPublishers(topic_subscription_pt sub);
+static void disconnectPendingPublishers(topic_subscription_pt sub);
+
+
+celix_status_t pubsub_topicSubscriptionCreate(bundle_context_pt bundle_context, char* ifIp,char* scope, char* topic ,pubsub_serializer_service_t *best_serializer, topic_subscription_pt* out){
+ celix_status_t status = CELIX_SUCCESS;
+
+ topic_subscription_pt ts = (topic_subscription_pt) calloc(1,sizeof(*ts));
+ ts->context = bundle_context;
+ ts->ifIpAddress = strdup(ifIp);
+#if defined(__APPLE__) && defined(__MACH__)
+ //TODO: Use kqueue for OSX
+#else
+ ts->topicEpollFd = epoll_create1(0);
+#endif
+ if(ts->topicEpollFd == -1) {
+ status += CELIX_SERVICE_EXCEPTION;
+ }
+
+ ts->running = false;
+ ts->nrSubscribers = 0;
+ ts->serializer = best_serializer;
+
+ celixThreadMutex_create(&ts->ts_lock,NULL);
+ arrayList_create(&ts->sub_ep_list);
+ ts->servicesMap = hashMap_create(NULL, NULL, NULL, NULL);
+ ts->socketMap = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+
+ arrayList_create(&ts->pendingConnections);
+ arrayList_create(&ts->pendingDisconnections);
+ celixThreadMutex_create(&ts->pendingConnections_lock, NULL);
+ celixThreadMutex_create(&ts->pendingDisconnections_lock, NULL);
+ celixThreadMutex_create(&ts->socketMap_lock, NULL);
+
+ ts->largeUdpHandle = largeUdp_create(MAX_UDP_SESSIONS);
+
+ char filter[128];
+ memset(filter,0,128);
+ if(strncmp(PUBSUB_SUBSCRIBER_SCOPE_DEFAULT, scope, strlen(PUBSUB_SUBSCRIBER_SCOPE_DEFAULT)) == 0) {
+ // default scope, means that subscriber has not defined a scope property
+ snprintf(filter, 128, "(&(%s=%s)(%s=%s))",
+ (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_SUBSCRIBER_SERVICE_NAME,
+ PUBSUB_SUBSCRIBER_TOPIC,topic);
+
+ } else {
+ snprintf(filter, 128, "(&(%s=%s)(%s=%s)(%s=%s))",
+ (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_SUBSCRIBER_SERVICE_NAME,
+ PUBSUB_SUBSCRIBER_TOPIC,topic,
+ PUBSUB_SUBSCRIBER_SCOPE,scope);
+ }
+
+ service_tracker_customizer_pt customizer = NULL;
+ status += serviceTrackerCustomizer_create(ts,NULL,topicsub_subscriberTracked,NULL,topicsub_subscriberUntracked,&customizer);
+ status += serviceTracker_createWithFilter(bundle_context, filter, customizer, &ts->tracker);
+
+ struct sigaction actions;
+ memset(&actions, 0, sizeof(actions));
+ sigemptyset(&actions.sa_mask);
+ actions.sa_flags = 0;
+ actions.sa_handler = sigusr1_sighandler;
+
+ sigaction(SIGUSR1,&actions,NULL);
+
+ if (status == CELIX_SUCCESS) {
+ *out=ts;
+ }
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionDestroy(topic_subscription_pt ts){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ ts->running = false;
+ free(ts->ifIpAddress);
+ serviceTracker_destroy(ts->tracker);
+ arrayList_clear(ts->sub_ep_list);
+ arrayList_destroy(ts->sub_ep_list);
+ hashMap_destroy(ts->servicesMap,false,false);
+
+ celixThreadMutex_lock(&ts->socketMap_lock);
+ hashMap_destroy(ts->socketMap,true,true);
+ celixThreadMutex_unlock(&ts->socketMap_lock);
+ celixThreadMutex_destroy(&ts->socketMap_lock);
+
+ celixThreadMutex_lock(&ts->pendingConnections_lock);
+ arrayList_destroy(ts->pendingConnections);
+ celixThreadMutex_unlock(&ts->pendingConnections_lock);
+ celixThreadMutex_destroy(&ts->pendingConnections_lock);
+
+ celixThreadMutex_lock(&ts->pendingDisconnections_lock);
+ arrayList_destroy(ts->pendingDisconnections);
+ celixThreadMutex_unlock(&ts->pendingDisconnections_lock);
+ celixThreadMutex_destroy(&ts->pendingDisconnections_lock);
+
+ largeUdp_destroy(ts->largeUdpHandle);
+#if defined(__APPLE__) && defined(__MACH__)
+ //TODO: Use kqueue for OSX
+#else
+ close(ts->topicEpollFd);
+#endif
+
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ celixThreadMutex_destroy(&ts->ts_lock);
+
+ free(ts);
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionStart(topic_subscription_pt ts){
+ celix_status_t status = CELIX_SUCCESS;
+
+ status = serviceTracker_open(ts->tracker);
+
+ ts->running = true;
+
+ if(status==CELIX_SUCCESS){
+ status=celixThread_create(&ts->recv_thread,NULL,udp_recv_thread_func,ts);
+ }
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionStop(topic_subscription_pt ts){
+ celix_status_t status = CELIX_SUCCESS;
+ struct epoll_event ev;
+ memset(&ev, 0, sizeof(ev));
+
+ ts->running = false;
+
+ pthread_kill(ts->recv_thread.thread,SIGUSR1);
+
+ celixThread_join(ts->recv_thread,NULL);
+
+ status = serviceTracker_close(ts->tracker);
+
+ celixThreadMutex_lock(&ts->socketMap_lock);
+ hash_map_iterator_pt it = hashMapIterator_create(ts->socketMap);
+ while(hashMapIterator_hasNext(it)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(it);
+ char *url = hashMapEntry_getKey(entry);
+ int *s = hashMapEntry_getValue(entry);
+ memset(&ev, 0, sizeof(ev));
+ if(epoll_ctl(ts->topicEpollFd, EPOLL_CTL_DEL, *s, &ev) == -1) {
+ printf("in if error()\n");
+ perror("epoll_ctl() EPOLL_CTL_DEL");
+ status += CELIX_SERVICE_EXCEPTION;
+ }
+ free(s);
+ free(url);
+ //hashMapIterator_remove(it);
+ }
+ hashMapIterator_destroy(it);
+ hashMap_clear(ts->socketMap, false, false);
+ celixThreadMutex_unlock(&ts->socketMap_lock);
+
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionConnectPublisher(topic_subscription_pt ts, char* pubURL) {
+
+ printf("pubsub_topicSubscriptionConnectPublisher : pubURL = %s\n", pubURL);
+
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->socketMap_lock);
+
+ if(!hashMap_containsKey(ts->socketMap, pubURL)){
+
+ int *recvSocket = calloc(sizeof(int), 1);
+ *recvSocket = socket(AF_INET, SOCK_DGRAM, 0);
+ if (*recvSocket < 0) {
+ perror("pubsub_topicSubscriptionCreate:socket");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+
+ if (status == CELIX_SUCCESS){
+ int reuse = 1;
+ if (setsockopt(*recvSocket, SOL_SOCKET, SO_REUSEADDR, (char*) &reuse, sizeof(reuse)) != 0) {
+ perror("setsockopt() SO_REUSEADDR");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ }
+
+ if(status == CELIX_SUCCESS){
+ // TODO Check if there is a better way to parse the URL to IP/Portnr
+ //replace ':' by spaces
+ char *url = strdup(pubURL);
+ char *pt = url;
+ while((pt=strchr(pt, ':')) != NULL) {
+ *pt = ' ';
+ }
+ char mcIp[100];
+ unsigned short mcPort;
+ sscanf(url, "udp //%s %hu", mcIp, &mcPort);
+ free(url);
+
+ printf("pubsub_topicSubscriptionConnectPublisher : IP = %s, Port = %hu\n", mcIp, mcPort);
+
+ struct ip_mreq mc_addr;
+ mc_addr.imr_multiaddr.s_addr = inet_addr(mcIp);
+ mc_addr.imr_interface.s_addr = inet_addr(ts->ifIpAddress);
+ printf("Adding MC %s at interface %s\n", mcIp, ts->ifIpAddress);
+ if (setsockopt(*recvSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*) &mc_addr, sizeof(mc_addr)) != 0) {
+ perror("setsockopt() IP_ADD_MEMBERSHIP");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+
+ if (status == CELIX_SUCCESS){
+ struct sockaddr_in mcListenAddr;
+ mcListenAddr.sin_family = AF_INET;
+ mcListenAddr.sin_addr.s_addr = INADDR_ANY;
+ mcListenAddr.sin_port = htons(mcPort);
+ if(bind(*recvSocket, (struct sockaddr*)&mcListenAddr, sizeof(mcListenAddr)) != 0) {
+ perror("bind()");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ }
+
+ if (status == CELIX_SUCCESS){
+#if defined(__APPLE__) && defined(__MACH__)
+ //TODO: Use kqueue for OSX
+#else
+ struct epoll_event ev;
+ memset(&ev, 0, sizeof(ev));
+ ev.events = EPOLLIN;
+ ev.data.fd = *recvSocket;
+ if(epoll_ctl(ts->topicEpollFd, EPOLL_CTL_ADD, *recvSocket, &ev) == -1) {
+ perror("epoll_ctl() EPOLL_CTL_ADD");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+#endif
+ }
+
+ }
+
+ if (status == CELIX_SUCCESS){
+ hashMap_put(ts->socketMap, strdup(pubURL), (void*)recvSocket);
+ }
+ else{
+ free(recvSocket);
+ }
+ }
+
+ celixThreadMutex_unlock(&ts->socketMap_lock);
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionAddConnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL) {
+ celix_status_t status = CELIX_SUCCESS;
+ char *url = strdup(pubURL);
+ celixThreadMutex_lock(&ts->pendingConnections_lock);
+ arrayList_add(ts->pendingConnections, url);
+ celixThreadMutex_unlock(&ts->pendingConnections_lock);
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL) {
+ celix_status_t status = CELIX_SUCCESS;
+ char *url = strdup(pubURL);
+ celixThreadMutex_lock(&ts->pendingDisconnections_lock);
+ arrayList_add(ts->pendingDisconnections, url);
+ celixThreadMutex_unlock(&ts->pendingDisconnections_lock);
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionDisconnectPublisher(topic_subscription_pt ts, char* pubURL){
+ printf("pubsub_topicSubscriptionDisconnectPublisher : pubURL = %s\n", pubURL);
+ celix_status_t status = CELIX_SUCCESS;
+ struct epoll_event ev;
+ memset(&ev, 0, sizeof(ev));
+
+ celixThreadMutex_lock(&ts->socketMap_lock);
+
+ if (hashMap_containsKey(ts->socketMap, pubURL)){
+
+#if defined(__APPLE__) && defined(__MACH__)
+ //TODO: Use kqueue for OSX
+#else
+ int *s = hashMap_remove(ts->socketMap, pubURL);
+ if(epoll_ctl(ts->topicEpollFd, EPOLL_CTL_DEL, *s, &ev) == -1) {
+ printf("in if error()\n");
+ perror("epoll_ctl() EPOLL_CTL_DEL");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ free(s);
+#endif
+
+ }
+
+ celixThreadMutex_unlock(&ts->socketMap_lock);
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionAddSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ arrayList_add(ts->sub_ep_list,subEP);
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+
+}
+
+celix_status_t pubsub_topicIncreaseNrSubscribers(topic_subscription_pt ts) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ ts->nrSubscribers++;
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+}
+
+celix_status_t pubsub_topicSubscriptionRemoveSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP){
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ arrayList_removeElement(ts->sub_ep_list,subEP);
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+}
+
+celix_status_t pubsub_topicDecreaseNrSubscribers(topic_subscription_pt ts) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ ts->nrSubscribers--;
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+}
+
+unsigned int pubsub_topicGetNrSubscribers(topic_subscription_pt ts) {
+ return ts->nrSubscribers;
+}
+
+array_list_pt pubsub_topicSubscriptionGetSubscribersList(topic_subscription_pt sub){
+ return sub->sub_ep_list;
+}
+
+
+static celix_status_t topicsub_subscriberTracked(void * handle, service_reference_pt reference, void * service){
+ celix_status_t status = CELIX_SUCCESS;
+ topic_subscription_pt ts = handle;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ if (!hashMap_containsKey(ts->servicesMap, service)) {
+ bundle_pt bundle = NULL;
+ hash_map_pt msgTypes = NULL;
+
+ serviceReference_getBundle(reference, &bundle);
+
+ if(ts->serializer != NULL && bundle!=NULL){
+ ts->serializer->createSerializerMap(ts->serializer->handle,bundle,&msgTypes);
+ if(msgTypes != NULL){
+ hashMap_put(ts->servicesMap, service, msgTypes);
+ printf("PSA_UDP_MC_TS: New subscriber registered.\n");
+ }
+ }
+ else{
+ printf("PSA_UDP_MC_TS: Cannot register new subscriber.\n");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ }
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ return status;
+
+}
+
+static celix_status_t topicsub_subscriberUntracked(void * handle, service_reference_pt reference, void * service){
+ celix_status_t status = CELIX_SUCCESS;
+ topic_subscription_pt ts = handle;
+
+ celixThreadMutex_lock(&ts->ts_lock);
+ if (hashMap_containsKey(ts->servicesMap, service)) {
+ hash_map_pt msgTypes = hashMap_remove(ts->servicesMap, service);
+ if(msgTypes!=NULL && ts->serializer!=NULL){
+ ts->serializer->destroySerializerMap(ts->serializer->handle,msgTypes);
+ printf("PSA_ZMQ_TS: Subscriber unregistered.\n");
+ }
+ else{
+ printf("PSA_ZMQ_TS: Cannot unregister subscriber.\n");
+ status = CELIX_SERVICE_EXCEPTION;
+ }
+ }
+ celixThreadMutex_unlock(&ts->ts_lock);
+
+ printf("PSA_UDP_MC_TS: Subscriber unregistered.\n");
+ return status;
+}
+
+
+static void process_msg(topic_subscription_pt sub,pubsub_udp_msg_t *msg){
+
+ celixThreadMutex_lock(&sub->ts_lock);
+ hash_map_iterator_pt iter = hashMapIterator_create(sub->servicesMap);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ pubsub_subscriber_pt subsvc = hashMapEntry_getKey(entry);
+ hash_map_pt msgTypes = hashMapEntry_getValue(entry);
+
+ pubsub_msg_serializer_t *msgSer = hashMap_get(msgTypes,(void*)(uintptr_t )msg->header.type);
+ if (msgSer == NULL) {
+ printf("PSA_UDP_MC_TS: Serializer not available for message %d.\n",msg->header.type);
+ }
+ else{
+ void *msgInst = NULL;
+ bool validVersion = checkVersion(msgSer->msgVersion,&msg->header);
+
+ if(validVersion){
+
+ celix_status_t status = msgSer->deserialize(msgSer, (const void *) msg->payload, 0, &msgInst);
+
+ if (status == CELIX_SUCCESS) {
+ bool release = true;
+ pubsub_multipart_callbacks_t mp_callbacks;
+ mp_callbacks.handle = sub;
+ mp_callbacks.localMsgTypeIdForMsgType = pubsub_localMsgTypeIdForMsgType;
+ mp_callbacks.getMultipart = NULL;
+
+ subsvc->receive(subsvc->handle, msgSer->msgName, msg->header.type, msgInst, &mp_callbacks, &release);
+
+ if(release){
+ msgSer->freeMsg(msgSer,msgInst);
+ }
+ }
+ else{
+ printf("PSA_UDP_MC_TS: Cannot deserialize msgType %s.\n",msgSer->msgName);
+ }
+
+ }
+ else{
+ int major=0,minor=0;
+ version_getMajor(msgSer->msgVersion,&major);
+ version_getMinor(msgSer->msgVersion,&minor);
+ printf("PSA_UDP_MC_TS: Version mismatch for primary message '%s' (have %d.%d, received %u.%u). NOT sending any part of the whole message.\n",
+ msgSer->msgName,major,minor,msg->header.major,msg->header.minor);
+ }
+
+ }
+ }
+ hashMapIterator_destroy(iter);
+ celixThreadMutex_unlock(&sub->ts_lock);
+}
+
+static void* udp_recv_thread_func(void * arg) {
+ topic_subscription_pt sub = (topic_subscription_pt) arg;
+
+#if defined(__APPLE__) && defined(__MACH__)
+ //TODO: use kqueue for OSX
+ //struct kevent events[MAX_EPOLL_EVENTS];
+ while (sub->running) {
+ int nfds = 0;
+ if(nfds > 0) {
+ pubsub_udp_msg_t* udpMsg = NULL;
+ process_msg(sub, udpMsg);
+ }
+ }
+#else
+ struct epoll_event events[MAX_EPOLL_EVENTS];
+
+ while (sub->running) {
+ int nfds = epoll_wait(sub->topicEpollFd, events, MAX_EPOLL_EVENTS, RECV_THREAD_TIMEOUT * 1000);
+ int i;
+ for(i = 0; i < nfds; i++ ) {
+ unsigned int index;
+ unsigned int size;
+ if(largeUdp_dataAvailable(sub->largeUdpHandle, events[i].data.fd, &index, &size) == true) {
+ // Handle data
+ pubsub_udp_msg_t *udpMsg = NULL;
+ if(largeUdp_read(sub->largeUdpHandle, index, (void**)&udpMsg, size) != 0) {
+ printf("PSA_UDP_MC_TS: ERROR largeUdp_read with index %d\n", index);
+ continue;
+ }
+
+ process_msg(sub, udpMsg);
+
+ free(udpMsg);
+ }
+ }
+ connectPendingPublishers(sub);
+ disconnectPendingPublishers(sub);
+ }
+#endif
+
+ return NULL;
+}
+
+static void connectPendingPublishers(topic_subscription_pt sub) {
+ celixThreadMutex_lock(&sub->pendingConnections_lock);
+ while(!arrayList_isEmpty(sub->pendingConnections)) {
+ char * pubEP = arrayList_remove(sub->pendingConnections, 0);
+ pubsub_topicSubscriptionConnectPublisher(sub, pubEP);
+ free(pubEP);
+ }
+ celixThreadMutex_unlock(&sub->pendingConnections_lock);
+}
+
+static void disconnectPendingPublishers(topic_subscription_pt sub) {
+ celixThreadMutex_lock(&sub->pendingDisconnections_lock);
+ while(!arrayList_isEmpty(sub->pendingDisconnections)) {
+ char * pubEP = arrayList_remove(sub->pendingDisconnections, 0);
+ pubsub_topicSubscriptionDisconnectPublisher(sub, pubEP);
+ free(pubEP);
+ }
+ celixThreadMutex_unlock(&sub->pendingDisconnections_lock);
+}
+
+static void sigusr1_sighandler(int signo){
+ printf("PSA_UDP_MC_TS: Topic subscription being shut down...\n");
+ return;
+}
+
+static bool checkVersion(version_pt msgVersion,pubsub_msg_header_pt hdr){
+ bool check=false;
+ int major=0,minor=0;
+
+ if(msgVersion!=NULL){
+ version_getMajor(msgVersion,&major);
+ version_getMinor(msgVersion,&minor);
+ if(hdr->major==((unsigned char)major)){ /* Different major means incompatible */
+ check = (hdr->minor>=((unsigned char)minor)); /* Compatible only if the provider has a minor equals or greater (means compatible update) */
+ }
+ }
+
+ return check;
+}
+
+static int pubsub_localMsgTypeIdForMsgType(void* handle, const char* msgType, unsigned int* msgTypeId){
+ *msgTypeId = utils_stringHash(msgType);
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_udp_mc/src/topic_subscription.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/src/topic_subscription.h b/pubsub/pubsub_admin_udp_mc/src/topic_subscription.h
new file mode 100644
index 0000000..475416a
--- /dev/null
+++ b/pubsub/pubsub_admin_udp_mc/src/topic_subscription.h
@@ -0,0 +1,60 @@
+/**
+ *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.
+ */
+/*
+ * topic_subscription.h
+ *
+ * \date Sep 22, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef TOPIC_SUBSCRIPTION_H_
+#define TOPIC_SUBSCRIPTION_H_
+
+#include "celix_threads.h"
+#include "array_list.h"
+#include "celixbool.h"
+#include "service_tracker.h"
+
+#include "pubsub_endpoint.h"
+#include "pubsub_common.h"
+#include "pubsub_serializer.h"
+
+typedef struct topic_subscription* topic_subscription_pt;
+
+celix_status_t pubsub_topicSubscriptionCreate(bundle_context_pt bundle_context, char* ifIp,char* scope, char* topic ,pubsub_serializer_service_t *best_serializer, topic_subscription_pt* out);
+celix_status_t pubsub_topicSubscriptionDestroy(topic_subscription_pt ts);
+celix_status_t pubsub_topicSubscriptionStart(topic_subscription_pt ts);
+celix_status_t pubsub_topicSubscriptionStop(topic_subscription_pt ts);
+
+celix_status_t pubsub_topicSubscriptionAddConnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL);
+celix_status_t pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(topic_subscription_pt ts, char* pubURL);
+
+celix_status_t pubsub_topicSubscriptionConnectPublisher(topic_subscription_pt ts, char* pubURL);
+celix_status_t pubsub_topicSubscriptionDisconnectPublisher(topic_subscription_pt ts, char* pubURL);
+
+celix_status_t pubsub_topicSubscriptionAddSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP);
+celix_status_t pubsub_topicSubscriptionRemoveSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP);
+
+array_list_pt pubsub_topicSubscriptionGetSubscribersList(topic_subscription_pt sub);
+celix_status_t pubsub_topicIncreaseNrSubscribers(topic_subscription_pt subscription);
+celix_status_t pubsub_topicDecreaseNrSubscribers(topic_subscription_pt subscription);
+unsigned int pubsub_topicGetNrSubscribers(topic_subscription_pt subscription);
+
+#endif /*TOPIC_SUBSCRIPTION_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/pubsub/pubsub_admin_zmq/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/CMakeLists.txt b/pubsub/pubsub_admin_zmq/CMakeLists.txt
index ab250f9..d71aedb 100644
--- a/pubsub/pubsub_admin_zmq/CMakeLists.txt
+++ b/pubsub/pubsub_admin_zmq/CMakeLists.txt
@@ -50,14 +50,15 @@ if (BUILD_PUBSUB_PSA_ZMQ)
private/src/topic_subscription.c
private/src/topic_publication.c
${ZMQ_CRYPTO_C}
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_endpoint.c
${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_utils.c
${PROJECT_SOURCE_DIR}/pubsub/pubsub_common/public/src/pubsub_admin_match.c
)
set_target_properties(org.apache.celix.pubsub_admin.PubSubAdminZmq PROPERTIES INSTALL_RPATH "$ORIGIN")
- target_link_libraries(org.apache.celix.pubsub_admin.PubSubAdminZmq celix_framework celix_utils celix_dfi ${ZMQ_LIBRARIES} ${CZMQ_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARY})
+ target_link_libraries(org.apache.celix.pubsub_admin.PubSubAdminZmq PRIVATE
+ Celix::framework Celix::dfi Celix::log_helper
+ ${ZMQ_LIBRARIES} ${CZMQ_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARY})
install_bundle(org.apache.celix.pubsub_admin.PubSubAdminZmq)
endif()
[36/54] [abbrv] celix git commit: CELIX-417: Refactors cmake usage of
pubsub and rsa. Started with installing exported targets
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_topology_manager/src/pstm_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_topology_manager/src/pstm_activator.c b/pubsub/pubsub_topology_manager/src/pstm_activator.c
new file mode 100644
index 0000000..eb874fe
--- /dev/null
+++ b/pubsub/pubsub_topology_manager/src/pstm_activator.c
@@ -0,0 +1,244 @@
+/**
+ *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.
+ */
+/*
+ * pstm_activator.c
+ *
+ * \date Sep 29, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "constants.h"
+#include "bundle_activator.h"
+#include "service_tracker.h"
+#include "service_registration.h"
+
+#include "listener_hook_service.h"
+#include "log_service.h"
+#include "log_helper.h"
+
+
+#include "pubsub_topology_manager.h"
+#include "publisher_endpoint_announce.h"
+
+struct activator {
+ bundle_context_pt context;
+
+ pubsub_topology_manager_pt manager;
+
+ service_tracker_pt pubsubDiscoveryTracker;
+ service_tracker_pt pubsubAdminTracker;
+ service_tracker_pt pubsubSubscribersTracker;
+
+ listener_hook_service_pt hookService;
+ service_registration_pt hook;
+
+ publisher_endpoint_announce_pt publisherEPDiscover;
+ service_registration_pt publisherEPDiscoverService;
+
+ log_helper_pt loghelper;
+};
+
+
+static celix_status_t bundleActivator_createPSDTracker(struct activator *activator, service_tracker_pt *tracker);
+static celix_status_t bundleActivator_createPSATracker(struct activator *activator, service_tracker_pt *tracker);
+static celix_status_t bundleActivator_createPSSubTracker(struct activator *activator, service_tracker_pt *tracker);
+
+
+static celix_status_t bundleActivator_createPSDTracker(struct activator *activator, service_tracker_pt *tracker) {
+ celix_status_t status;
+
+ service_tracker_customizer_pt customizer = NULL;
+
+ status = serviceTrackerCustomizer_create(activator->manager,
+ NULL,
+ pubsub_topologyManager_pubsubDiscoveryAdded,
+ pubsub_topologyManager_pubsubDiscoveryModified,
+ pubsub_topologyManager_pubsubDiscoveryRemoved,
+ &customizer);
+
+ if (status == CELIX_SUCCESS) {
+ status = serviceTracker_create(activator->context, (char *) PUBSUB_DISCOVERY_SERVICE, customizer, tracker);
+ }
+
+ return status;
+}
+
+static celix_status_t bundleActivator_createPSATracker(struct activator *activator, service_tracker_pt *tracker) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ service_tracker_customizer_pt customizer = NULL;
+
+ status = serviceTrackerCustomizer_create(activator->manager,
+ NULL,
+ pubsub_topologyManager_psaAdded,
+ pubsub_topologyManager_psaModified,
+ pubsub_topologyManager_psaRemoved,
+ &customizer);
+
+ if (status == CELIX_SUCCESS) {
+ status = serviceTracker_create(activator->context, PUBSUB_ADMIN_SERVICE, customizer, tracker);
+ }
+
+ return status;
+}
+
+static celix_status_t bundleActivator_createPSSubTracker(struct activator *activator, service_tracker_pt *tracker) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ service_tracker_customizer_pt customizer = NULL;
+
+ status = serviceTrackerCustomizer_create(activator->manager,
+ NULL,
+ pubsub_topologyManager_subscriberAdded,
+ pubsub_topologyManager_subscriberModified,
+ pubsub_topologyManager_subscriberRemoved,
+ &customizer);
+
+ if (status == CELIX_SUCCESS) {
+ status = serviceTracker_create(activator->context, PUBSUB_SUBSCRIBER_SERVICE_NAME, customizer, tracker);
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = NULL;
+
+ activator = calloc(1,sizeof(struct activator));
+
+ if (!activator) {
+ return CELIX_ENOMEM;
+ }
+
+ activator->context = context;
+
+ logHelper_create(context, &activator->loghelper);
+ logHelper_start(activator->loghelper);
+
+ status = pubsub_topologyManager_create(context, activator->loghelper, &activator->manager);
+ if (status == CELIX_SUCCESS) {
+ status = bundleActivator_createPSDTracker(activator, &activator->pubsubDiscoveryTracker);
+ if (status == CELIX_SUCCESS) {
+ status = bundleActivator_createPSATracker(activator, &activator->pubsubAdminTracker);
+ if (status == CELIX_SUCCESS) {
+ status = bundleActivator_createPSSubTracker(activator, &activator->pubsubSubscribersTracker);
+ if (status == CELIX_SUCCESS) {
+ *userData = activator;
+ }
+ }
+ }
+ }
+
+ if(status != CELIX_SUCCESS){
+ bundleActivator_destroy(activator, context);
+ }
+
+ return status;
+}
+
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ publisher_endpoint_announce_pt pubEPDiscover = calloc(1, sizeof(*pubEPDiscover));
+ pubEPDiscover->handle = activator->manager;
+ pubEPDiscover->announcePublisher = pubsub_topologyManager_announcePublisher;
+ pubEPDiscover->removePublisher = pubsub_topologyManager_removePublisher;
+ activator->publisherEPDiscover = pubEPDiscover;
+
+ status += bundleContext_registerService(context, (char *) PUBSUB_TM_ANNOUNCE_PUBLISHER_SERVICE, pubEPDiscover, NULL, &activator->publisherEPDiscoverService);
+
+
+ listener_hook_service_pt hookService = calloc(1,sizeof(*hookService));
+ hookService->handle = activator->manager;
+ hookService->added = pubsub_topologyManager_publisherTrackerAdded;
+ hookService->removed = pubsub_topologyManager_publisherTrackerRemoved;
+ activator->hookService = hookService;
+
+ status += bundleContext_registerService(context, (char *) OSGI_FRAMEWORK_LISTENER_HOOK_SERVICE_NAME, hookService, NULL, &activator->hook);
+
+ /* NOTE: Enable those line in order to remotely expose the topic_info service
+ properties_pt props = properties_create();
+ properties_set(props, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, (char *) PUBSUB_TOPIC_INFO_SERVICE);
+ status += bundleContext_registerService(context, (char *) PUBSUB_TOPIC_INFO_SERVICE, activator->topicInfo, props, &activator->topicInfoService);
+ */
+ status += serviceTracker_open(activator->pubsubAdminTracker);
+
+ status += serviceTracker_open(activator->pubsubDiscoveryTracker);
+
+ status += serviceTracker_open(activator->pubsubSubscribersTracker);
+
+
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ serviceTracker_close(activator->pubsubSubscribersTracker);
+ serviceTracker_close(activator->pubsubDiscoveryTracker);
+ serviceTracker_close(activator->pubsubAdminTracker);
+
+ serviceRegistration_unregister(activator->publisherEPDiscoverService);
+ free(activator->publisherEPDiscover);
+
+ serviceRegistration_unregister(activator->hook);
+ free(activator->hookService);
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ struct activator *activator = userData;
+ if (activator == NULL) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+
+ if(activator->pubsubSubscribersTracker!=NULL){
+ serviceTracker_destroy(activator->pubsubSubscribersTracker);
+ }
+ if(activator->pubsubDiscoveryTracker!=NULL){
+ serviceTracker_destroy(activator->pubsubDiscoveryTracker);
+ }
+ if(activator->pubsubAdminTracker!=NULL){
+ serviceTracker_destroy(activator->pubsubAdminTracker);
+ }
+
+ if(activator->manager!=NULL){
+ status = pubsub_topologyManager_destroy(activator->manager);
+ }
+
+ logHelper_stop(activator->loghelper);
+ logHelper_destroy(&activator->loghelper);
+
+ free(activator);
+ }
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.c b/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.c
new file mode 100644
index 0000000..2ac75c9
--- /dev/null
+++ b/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.c
@@ -0,0 +1,721 @@
+/**
+ *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.
+ */
+/*
+ * pubsub_topology_manager.c
+ *
+ * \date Sep 29, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include "hash_map.h"
+#include "array_list.h"
+#include "bundle_context.h"
+#include "constants.h"
+#include "module.h"
+#include "bundle.h"
+#include "filter.h"
+#include "listener_hook_service.h"
+#include "utils.h"
+#include "service_reference.h"
+#include "service_registration.h"
+#include "log_service.h"
+#include "log_helper.h"
+
+#include "publisher_endpoint_announce.h"
+#include "pubsub_topology_manager.h"
+#include "pubsub_endpoint.h"
+#include "pubsub_admin.h"
+#include "pubsub_utils.h"
+
+
+celix_status_t pubsub_topologyManager_create(bundle_context_pt context, log_helper_pt logHelper, pubsub_topology_manager_pt *manager) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *manager = calloc(1, sizeof(**manager));
+ if (!*manager) {
+ return CELIX_ENOMEM;
+ }
+
+ (*manager)->context = context;
+
+ celix_thread_mutexattr_t psaAttr;
+ celixThreadMutexAttr_create(&psaAttr);
+ celixThreadMutexAttr_settype(&psaAttr, CELIX_THREAD_MUTEX_RECURSIVE);
+ status = celixThreadMutex_create(&(*manager)->psaListLock, &psaAttr);
+ celixThreadMutexAttr_destroy(&psaAttr);
+
+ status = celixThreadMutex_create(&(*manager)->publicationsLock, NULL);
+ status = celixThreadMutex_create(&(*manager)->subscriptionsLock, NULL);
+ status = celixThreadMutex_create(&(*manager)->discoveryListLock, NULL);
+
+ arrayList_create(&(*manager)->psaList);
+
+ (*manager)->discoveryList = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
+ (*manager)->publications = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ (*manager)->subscriptions = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+
+ (*manager)->loghelper = logHelper;
+
+ return status;
+}
+
+celix_status_t pubsub_topologyManager_destroy(pubsub_topology_manager_pt manager) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ celixThreadMutex_lock(&manager->discoveryListLock);
+ hashMap_destroy(manager->discoveryList, false, false);
+ celixThreadMutex_unlock(&manager->discoveryListLock);
+ celixThreadMutex_destroy(&manager->discoveryListLock);
+
+ celixThreadMutex_lock(&manager->psaListLock);
+ arrayList_destroy(manager->psaList);
+ celixThreadMutex_unlock(&manager->psaListLock);
+ celixThreadMutex_destroy(&manager->psaListLock);
+
+ celixThreadMutex_lock(&manager->publicationsLock);
+ hash_map_iterator_pt pubit = hashMapIterator_create(manager->publications);
+ while(hashMapIterator_hasNext(pubit)){
+ array_list_pt l = (array_list_pt)hashMapIterator_nextValue(pubit);
+ int i;
+ for(i=0;i<arrayList_size(l);i++){
+ pubsubEndpoint_destroy((pubsub_endpoint_pt)arrayList_get(l,i));
+ }
+ arrayList_destroy(l);
+ }
+ hashMapIterator_destroy(pubit);
+ hashMap_destroy(manager->publications, true, false);
+ celixThreadMutex_unlock(&manager->publicationsLock);
+ celixThreadMutex_destroy(&manager->publicationsLock);
+
+ celixThreadMutex_lock(&manager->subscriptionsLock);
+ hash_map_iterator_pt subit = hashMapIterator_create(manager->subscriptions);
+ while(hashMapIterator_hasNext(subit)){
+ array_list_pt l = (array_list_pt)hashMapIterator_nextValue(subit);
+ int i;
+ for(i=0;i<arrayList_size(l);i++){
+ pubsubEndpoint_destroy((pubsub_endpoint_pt)arrayList_get(l,i));
+ }
+ arrayList_destroy(l);
+ }
+ hashMapIterator_destroy(subit);
+ hashMap_destroy(manager->subscriptions, true, false);
+ celixThreadMutex_unlock(&manager->subscriptionsLock);
+ celixThreadMutex_destroy(&manager->subscriptionsLock);
+
+ free(manager);
+
+ return status;
+}
+
+celix_status_t pubsub_topologyManager_psaAdded(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+ pubsub_topology_manager_pt manager = handle;
+ int i;
+
+ pubsub_admin_service_pt psa = (pubsub_admin_service_pt) service;
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "PSTM: Added PSA");
+
+ celixThreadMutex_lock(&manager->psaListLock);
+ arrayList_add(manager->psaList, psa);
+ celixThreadMutex_unlock(&manager->psaListLock);
+
+ // Add already detected subscriptions to new PSA
+ celixThreadMutex_lock(&manager->subscriptionsLock);
+ hash_map_iterator_pt subscriptionsIterator = hashMapIterator_create(manager->subscriptions);
+
+ while (hashMapIterator_hasNext(subscriptionsIterator)) {
+ array_list_pt sub_ep_list = hashMapIterator_nextValue(subscriptionsIterator);
+ for(i=0;i<arrayList_size(sub_ep_list);i++){
+ status += psa->addSubscription(psa->admin, (pubsub_endpoint_pt)arrayList_get(sub_ep_list,i));
+ }
+ }
+
+ hashMapIterator_destroy(subscriptionsIterator);
+
+ celixThreadMutex_unlock(&manager->subscriptionsLock);
+
+ // Add already detected publications to new PSA
+ status = celixThreadMutex_lock(&manager->publicationsLock);
+ hash_map_iterator_pt publicationsIterator = hashMapIterator_create(manager->publications);
+
+ while (hashMapIterator_hasNext(publicationsIterator)) {
+ array_list_pt pub_ep_list = hashMapIterator_nextValue(publicationsIterator);
+ for(i=0;i<arrayList_size(pub_ep_list);i++){
+ status += psa->addPublication(psa->admin, (pubsub_endpoint_pt)arrayList_get(pub_ep_list,i));
+ }
+ }
+
+ hashMapIterator_destroy(publicationsIterator);
+
+ celixThreadMutex_unlock(&manager->publicationsLock);
+
+ return status;
+}
+
+celix_status_t pubsub_topologyManager_psaModified(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ // Nop...
+
+ return status;
+}
+
+celix_status_t pubsub_topologyManager_psaRemoved(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+ pubsub_topology_manager_pt manager = handle;
+
+ pubsub_admin_service_pt psa = (pubsub_admin_service_pt) service;
+
+ /* Deactivate all publications */
+ celixThreadMutex_lock(&manager->publicationsLock);
+
+ hash_map_iterator_pt pubit = hashMapIterator_create(manager->publications);
+ while(hashMapIterator_hasNext(pubit)){
+ hash_map_entry_pt pub_entry = hashMapIterator_nextEntry(pubit);
+ char* scope_topic_key = (char*)hashMapEntry_getKey(pub_entry);
+ // Extract scope/topic name from key
+ char scope[MAX_SCOPE_LEN];
+ char topic[MAX_TOPIC_LEN];
+ sscanf(scope_topic_key, "%[^:]:%s", scope, topic );
+ array_list_pt pubEP_list = (array_list_pt)hashMapEntry_getValue(pub_entry);
+
+ status = psa->closeAllPublications(psa->admin,scope,topic);
+
+ if(status==CELIX_SUCCESS){
+ celixThreadMutex_lock(&manager->discoveryListLock);
+ hash_map_iterator_pt iter = hashMapIterator_create(manager->discoveryList);
+ while(hashMapIterator_hasNext(iter)){
+ service_reference_pt disc_sr = (service_reference_pt)hashMapIterator_nextKey(iter);
+ publisher_endpoint_announce_pt disc = NULL;
+ bundleContext_getService(manager->context, disc_sr, (void**) &disc);
+ const char* fwUUID = NULL;
+ bundleContext_getProperty(manager->context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
+ int i;
+ for(i=0;i<arrayList_size(pubEP_list);i++){
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pubEP_list,i);
+ if(strcmp(pubEP->frameworkUUID,fwUUID)==0){
+ disc->removePublisher(disc->handle,pubEP);
+ }
+ }
+ bundleContext_ungetService(manager->context, disc_sr, NULL);
+ }
+ hashMapIterator_destroy(iter);
+ celixThreadMutex_unlock(&manager->discoveryListLock);
+ }
+ }
+ hashMapIterator_destroy(pubit);
+
+ celixThreadMutex_unlock(&manager->publicationsLock);
+
+ /* Deactivate all subscriptions */
+ celixThreadMutex_lock(&manager->subscriptionsLock);
+ hash_map_iterator_pt subit = hashMapIterator_create(manager->subscriptions);
+ while(hashMapIterator_hasNext(subit)){
+ // TODO do some error checking
+ char* scope_topic = (char*)hashMapIterator_nextKey(subit);
+ char scope[MAX_TOPIC_LEN];
+ char topic[MAX_TOPIC_LEN];
+ memset(scope, 0 , MAX_TOPIC_LEN*sizeof(char));
+ memset(topic, 0 , MAX_TOPIC_LEN*sizeof(char));
+ sscanf(scope_topic, "%[^:]:%s", scope, topic );
+ status += psa->closeAllSubscriptions(psa->admin,scope, topic);
+ }
+ hashMapIterator_destroy(subit);
+ celixThreadMutex_unlock(&manager->subscriptionsLock);
+
+ celixThreadMutex_lock(&manager->psaListLock);
+ arrayList_removeElement(manager->psaList, psa);
+ celixThreadMutex_unlock(&manager->psaListLock);
+
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "PSTM: Removed PSA");
+
+ return status;
+}
+
+celix_status_t pubsub_topologyManager_subscriberAdded(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+ pubsub_topology_manager_pt manager = handle;
+ //subscriber_service_pt subscriber = (subscriber_service_pt)service;
+
+ pubsub_endpoint_pt sub = NULL;
+ if(pubsubEndpoint_createFromServiceReference(reference,&sub,false) == CELIX_SUCCESS){
+ celixThreadMutex_lock(&manager->subscriptionsLock);
+ char *sub_key = createScopeTopicKey(sub->scope, sub->topic);
+
+ array_list_pt sub_list_by_topic = hashMap_get(manager->subscriptions,sub_key);
+ if(sub_list_by_topic==NULL){
+ arrayList_create(&sub_list_by_topic);
+ hashMap_put(manager->subscriptions,strdup(sub_key),sub_list_by_topic);
+ }
+ free(sub_key);
+ arrayList_add(sub_list_by_topic,sub);
+
+ celixThreadMutex_unlock(&manager->subscriptionsLock);
+
+ int j;
+ double score = 0;
+ double best_score = 0;
+ pubsub_admin_service_pt best_psa = NULL;
+ celixThreadMutex_lock(&manager->psaListLock);
+ for(j=0;j<arrayList_size(manager->psaList);j++){
+ pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,j);
+ psa->matchEndpoint(psa->admin,sub,&score);
+ if(score>best_score){ /* We have a new winner! */
+ best_score = score;
+ best_psa = psa;
+ }
+ }
+
+ if(best_psa != NULL && best_score>0){
+ best_psa->addSubscription(best_psa->admin,sub);
+ }
+
+ // Inform discoveries for interest in the topic
+ celixThreadMutex_lock(&manager->discoveryListLock);
+ hash_map_iterator_pt iter = hashMapIterator_create(manager->discoveryList);
+ while(hashMapIterator_hasNext(iter)){
+ service_reference_pt disc_sr = (service_reference_pt)hashMapIterator_nextKey(iter);
+ publisher_endpoint_announce_pt disc = NULL;
+ bundleContext_getService(manager->context, disc_sr, (void**) &disc);
+ disc->interestedInTopic(disc->handle, sub->scope, sub->topic);
+ bundleContext_ungetService(manager->context, disc_sr, NULL);
+ }
+ hashMapIterator_destroy(iter);
+ celixThreadMutex_unlock(&manager->discoveryListLock);
+
+ celixThreadMutex_unlock(&manager->psaListLock);
+ }
+ else{
+ status=CELIX_INVALID_BUNDLE_CONTEXT;
+ }
+
+ return status;
+}
+
+celix_status_t pubsub_topologyManager_subscriberModified(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ // Nop...
+
+ return status;
+}
+
+celix_status_t pubsub_topologyManager_subscriberRemoved(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+ pubsub_topology_manager_pt manager = handle;
+
+ pubsub_endpoint_pt subcmp = NULL;
+ if(pubsubEndpoint_createFromServiceReference(reference,&subcmp,false) == CELIX_SUCCESS){
+
+ int j,k;
+
+ // Inform discoveries that we not interested in the topic any more
+ celixThreadMutex_lock(&manager->discoveryListLock);
+ hash_map_iterator_pt iter = hashMapIterator_create(manager->discoveryList);
+ while(hashMapIterator_hasNext(iter)){
+ service_reference_pt disc_sr = (service_reference_pt)hashMapIterator_nextKey(iter);
+ publisher_endpoint_announce_pt disc = NULL;
+ bundleContext_getService(manager->context, disc_sr, (void**) &disc);
+ disc->uninterestedInTopic(disc->handle, subcmp->scope, subcmp->topic);
+ bundleContext_ungetService(manager->context, disc_sr, NULL);
+ }
+ hashMapIterator_destroy(iter);
+ celixThreadMutex_unlock(&manager->discoveryListLock);
+
+ celixThreadMutex_lock(&manager->subscriptionsLock);
+ celixThreadMutex_lock(&manager->psaListLock);
+
+ char *sub_key = createScopeTopicKey(subcmp->scope,subcmp->topic);
+ array_list_pt sub_list_by_topic = hashMap_get(manager->subscriptions,sub_key);
+ free(sub_key);
+ if(sub_list_by_topic!=NULL){
+ for(j=0;j<arrayList_size(sub_list_by_topic);j++){
+ pubsub_endpoint_pt sub = arrayList_get(sub_list_by_topic,j);
+ if(pubsubEndpoint_equals(sub,subcmp)){
+ for(k=0;k<arrayList_size(manager->psaList);k++){
+ /* No problem with invoking removal on all psa's, only the one that manage this topic will do something */
+ pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,k);
+ psa->removeSubscription(psa->admin,sub);
+ }
+
+ }
+ arrayList_remove(sub_list_by_topic,j);
+
+ /* If it was the last subscriber for this topic, tell PSA to close the ZMQ socket */
+ if(arrayList_size(sub_list_by_topic)==0){
+ for(k=0;k<arrayList_size(manager->psaList);k++){
+ pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,k);
+ psa->closeAllSubscriptions(psa->admin,sub->scope, sub->topic);
+ }
+ }
+
+ pubsubEndpoint_destroy(sub);
+
+ }
+ }
+
+ celixThreadMutex_unlock(&manager->psaListLock);
+ celixThreadMutex_unlock(&manager->subscriptionsLock);
+
+ pubsubEndpoint_destroy(subcmp);
+
+ }
+ else{
+ status=CELIX_INVALID_BUNDLE_CONTEXT;
+ }
+
+ return status;
+
+}
+
+celix_status_t pubsub_topologyManager_pubsubDiscoveryAdded(void* handle, service_reference_pt reference, void* service) {
+ celix_status_t status = CELIX_SUCCESS;
+ pubsub_topology_manager_pt manager = (pubsub_topology_manager_pt)handle;
+ publisher_endpoint_announce_pt disc = (publisher_endpoint_announce_pt)service;
+
+ const char* fwUUID = NULL;
+
+ bundleContext_getProperty(manager->context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
+ if(fwUUID==NULL){
+ printf("PSD: ERRROR: Cannot retrieve fwUUID.\n");
+ return CELIX_INVALID_BUNDLE_CONTEXT;
+ }
+
+ celixThreadMutex_lock(&manager->publicationsLock);
+
+ celixThreadMutex_lock(&manager->discoveryListLock);
+ hashMap_put(manager->discoveryList, reference, NULL);
+ celixThreadMutex_unlock(&manager->discoveryListLock);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(manager->publications);
+ while(hashMapIterator_hasNext(iter)){
+ array_list_pt pubEP_list = (array_list_pt)hashMapIterator_nextValue(iter);
+ for(int i = 0; i < arrayList_size(pubEP_list); i++) {
+ pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pubEP_list,i);
+ if( (strcmp(pubEP->frameworkUUID,fwUUID)==0) && (pubEP->endpoint!=NULL)){
+ status += disc->announcePublisher(disc->handle,pubEP);
+ }
+ }
+ }
+ hashMapIterator_destroy(iter);
+
+ celixThreadMutex_unlock(&manager->publicationsLock);
+
+ celixThreadMutex_lock(&manager->subscriptionsLock);
+ iter = hashMapIterator_create(manager->subscriptions);
+
+ while(hashMapIterator_hasNext(iter)) {
+ array_list_pt l = (array_list_pt)hashMapIterator_nextValue(iter);
+ int i;
+ for(i=0;i<arrayList_size(l);i++){
+ pubsub_endpoint_pt subEp = (pubsub_endpoint_pt)arrayList_get(l,i);
+
+ disc->interestedInTopic(disc->handle, subEp->scope, subEp->topic);
+ }
+ }
+ hashMapIterator_destroy(iter);
+ celixThreadMutex_unlock(&manager->subscriptionsLock);
+
+ return status;
+}
+
+celix_status_t pubsub_topologyManager_pubsubDiscoveryModified(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ status = pubsub_topologyManager_pubsubDiscoveryRemoved(handle, reference, service);
+ if (status == CELIX_SUCCESS) {
+ status = pubsub_topologyManager_pubsubDiscoveryAdded(handle, reference, service);
+ }
+
+ return status;
+}
+
+celix_status_t pubsub_topologyManager_pubsubDiscoveryRemoved(void * handle, service_reference_pt reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pubsub_topology_manager_pt manager = handle;
+
+ celixThreadMutex_lock(&manager->discoveryListLock);
+
+
+ if (hashMap_remove(manager->discoveryList, reference)) {
+ logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "EndpointListener Removed");
+ }
+
+ celixThreadMutex_unlock(&manager->discoveryListLock);
+
+ return status;
+}
+
+
+celix_status_t pubsub_topologyManager_publisherTrackerAdded(void *handle, array_list_pt listeners) {
+
+ celix_status_t status = CELIX_SUCCESS;
+ pubsub_topology_manager_pt manager = handle;
+
+ int l_index;
+
+ for (l_index = 0; l_index < arrayList_size(listeners); l_index++) {
+
+ listener_hook_info_pt info = arrayList_get(listeners, l_index);
+
+ pubsub_endpoint_pt pub = NULL;
+ if(pubsubEndpoint_createFromListenerHookInfo(info, &pub, true) == CELIX_SUCCESS){
+
+ celixThreadMutex_lock(&manager->publicationsLock);
+ char *pub_key = createScopeTopicKey(pub->scope, pub->topic);
+ array_list_pt pub_list_by_topic = hashMap_get(manager->publications, pub_key);
+ if(pub_list_by_topic==NULL){
+ arrayList_create(&pub_list_by_topic);
+ hashMap_put(manager->publications,strdup(pub_key),pub_list_by_topic);
+ }
+ free(pub_key);
+ arrayList_add(pub_list_by_topic,pub);
+
+ celixThreadMutex_unlock(&manager->publicationsLock);
+
+ int j;
+ double score = 0;
+ double best_score = 0;
+ pubsub_admin_service_pt best_psa = NULL;
+ celixThreadMutex_lock(&manager->psaListLock);
+
+ for(j=0;j<arrayList_size(manager->psaList);j++){
+ pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,j);
+ psa->matchEndpoint(psa->admin,pub,&score);
+ if(score>best_score){ /* We have a new winner! */
+ best_score = score;
+ best_psa = psa;
+ }
+ }
+
+ if(best_psa != NULL && best_score>0){
+ status = best_psa->addPublication(best_psa->admin,pub);
+ if(status==CELIX_SUCCESS){
+ celixThreadMutex_lock(&manager->discoveryListLock);
+ hash_map_iterator_pt iter = hashMapIterator_create(manager->discoveryList);
+ while(hashMapIterator_hasNext(iter)){
+ service_reference_pt disc_sr = (service_reference_pt)hashMapIterator_nextKey(iter);
+ publisher_endpoint_announce_pt disc = NULL;
+ bundleContext_getService(manager->context, disc_sr, (void**) &disc);
+ disc->announcePublisher(disc->handle,pub);
+ bundleContext_ungetService(manager->context, disc_sr, NULL);
+ }
+ hashMapIterator_destroy(iter);
+ celixThreadMutex_unlock(&manager->discoveryListLock);
+ }
+ }
+
+ celixThreadMutex_unlock(&manager->psaListLock);
+
+ }
+
+ }
+
+ return status;
+
+}
+
+
+celix_status_t pubsub_topologyManager_publisherTrackerRemoved(void *handle, array_list_pt listeners) {
+ celix_status_t status = CELIX_SUCCESS;
+ pubsub_topology_manager_pt manager = handle;
+
+ int l_index;
+
+ for (l_index = 0; l_index < arrayList_size(listeners); l_index++) {
+
+ listener_hook_info_pt info = arrayList_get(listeners, l_index);
+
+ pubsub_endpoint_pt pubcmp = NULL;
+ if(pubsubEndpoint_createFromListenerHookInfo(info,&pubcmp,true) == CELIX_SUCCESS){
+
+
+ int j,k;
+ celixThreadMutex_lock(&manager->psaListLock);
+ celixThreadMutex_lock(&manager->publicationsLock);
+
+ char *pub_key = createScopeTopicKey(pubcmp->scope, pubcmp->topic);
+ array_list_pt pub_list_by_topic = hashMap_get(manager->publications,pub_key);
+ if(pub_list_by_topic!=NULL){
+ for(j=0;j<arrayList_size(pub_list_by_topic);j++){
+ pubsub_endpoint_pt pub = arrayList_get(pub_list_by_topic,j);
+ if(pubsubEndpoint_equals(pub,pubcmp)){
+ for(k=0;k<arrayList_size(manager->psaList);k++){
+ pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,k);
+ status = psa->removePublication(psa->admin,pub);
+ if(status==CELIX_SUCCESS){ /* We found the one that manages this endpoint */
+ celixThreadMutex_lock(&manager->discoveryListLock);
+ hash_map_iterator_pt iter = hashMapIterator_create(manager->discoveryList);
+ while(hashMapIterator_hasNext(iter)){
+ service_reference_pt disc_sr = (service_reference_pt)hashMapIterator_nextKey(iter);
+ publisher_endpoint_announce_pt disc = NULL;
+ bundleContext_getService(manager->context, disc_sr, (void**) &disc);
+ disc->removePublisher(disc->handle,pub);
+ bundleContext_ungetService(manager->context, disc_sr, NULL);
+ }
+ hashMapIterator_destroy(iter);
+ celixThreadMutex_unlock(&manager->discoveryListLock);
+ }
+ else if(status == CELIX_ILLEGAL_ARGUMENT){ /* Not a real error, just saying this psa does not handle this endpoint */
+ status = CELIX_SUCCESS;
+ }
+ }
+ //}
+ arrayList_remove(pub_list_by_topic,j);
+
+ /* If it was the last publisher for this topic, tell PSA to close the ZMQ socket and then inform the discovery */
+ if(arrayList_size(pub_list_by_topic)==0){
+ for(k=0;k<arrayList_size(manager->psaList);k++){
+ pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,k);
+ psa->closeAllPublications(psa->admin,pub->scope, pub->topic);
+ }
+ }
+
+ pubsubEndpoint_destroy(pub);
+ }
+
+ }
+ }
+
+ celixThreadMutex_unlock(&manager->publicationsLock);
+ celixThreadMutex_unlock(&manager->psaListLock);
+
+ free(pub_key);
+
+ pubsubEndpoint_destroy(pubcmp);
+
+ }
+
+ }
+
+ return status;
+}
+
+celix_status_t pubsub_topologyManager_announcePublisher(void *handle, pubsub_endpoint_pt pubEP){
+ celix_status_t status = CELIX_SUCCESS;
+ printf("PSTM: New publisher discovered for topic %s [fwUUID=%s, ep=%s]\n",pubEP->topic,pubEP->frameworkUUID,pubEP->endpoint);
+
+ pubsub_topology_manager_pt manager = handle;
+ celixThreadMutex_lock(&manager->psaListLock);
+ celixThreadMutex_lock(&manager->publicationsLock);
+
+ char *pub_key = createScopeTopicKey(pubEP->scope, pubEP->topic);
+
+ array_list_pt pub_list_by_topic = hashMap_get(manager->publications,pub_key);
+ if(pub_list_by_topic==NULL){
+ arrayList_create(&pub_list_by_topic);
+ hashMap_put(manager->publications,strdup(pub_key),pub_list_by_topic);
+ }
+ free(pub_key);
+
+ /* Shouldn't be any other duplicate, since it's filtered out by the discovery */
+ pubsub_endpoint_pt p = NULL;
+ pubsubEndpoint_clone(pubEP, &p);
+ arrayList_add(pub_list_by_topic,p);
+
+ int j;
+ double score = 0;
+ double best_score = 0;
+ pubsub_admin_service_pt best_psa = NULL;
+
+ for(j=0;j<arrayList_size(manager->psaList);j++){
+ pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,j);
+ psa->matchEndpoint(psa->admin,p,&score);
+ if(score>best_score){ /* We have a new winner! */
+ best_score = score;
+ best_psa = psa;
+ }
+ }
+
+ if(best_psa != NULL && best_score>0){
+ best_psa->addPublication(best_psa->admin,p);
+ }
+ else{
+ status = CELIX_ILLEGAL_STATE;
+ }
+
+ celixThreadMutex_unlock(&manager->publicationsLock);
+ celixThreadMutex_unlock(&manager->psaListLock);
+
+ return status;
+}
+
+celix_status_t pubsub_topologyManager_removePublisher(void *handle, pubsub_endpoint_pt pubEP){
+ celix_status_t status = CELIX_SUCCESS;
+ printf("PSTM: Publisher removed for topic %s [fwUUID=%s, ep=%s]\n",pubEP->topic,pubEP->frameworkUUID,pubEP->endpoint);
+
+ pubsub_topology_manager_pt manager = handle;
+ celixThreadMutex_lock(&manager->psaListLock);
+ celixThreadMutex_lock(&manager->publicationsLock);
+ int i;
+
+ char *pub_key = createScopeTopicKey(pubEP->scope, pubEP->topic);
+ array_list_pt pub_list_by_topic = hashMap_get(manager->publications,pub_key);
+ if(pub_list_by_topic==NULL){
+ printf("PSTM: ERROR: Cannot find topic for known endpoint [%s,%s,%s]. Something is inconsistent.\n",pub_key,pubEP->frameworkUUID,pubEP->endpoint);
+ status = CELIX_ILLEGAL_STATE;
+ }
+ else{
+
+ pubsub_endpoint_pt p = NULL;
+ bool found = false;
+
+ for(i=0;!found && i<arrayList_size(pub_list_by_topic);i++){
+ p = (pubsub_endpoint_pt)arrayList_get(pub_list_by_topic,i);
+ found = pubsubEndpoint_equals(p,pubEP);
+ }
+
+ if(found && p !=NULL){
+
+ for(i=0;i<arrayList_size(manager->psaList);i++){
+ pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,i);
+ /* No problem with invoking removal on all psa's, only the one that manage this topic will do something */
+ psa->removePublication(psa->admin,p);
+ }
+
+ arrayList_removeElement(pub_list_by_topic,p);
+
+ /* If it was the last publisher for this topic, tell PSA to close the ZMQ socket */
+ if(arrayList_size(pub_list_by_topic)==0){
+
+ for(i=0;i<arrayList_size(manager->psaList);i++){
+ pubsub_admin_service_pt psa = (pubsub_admin_service_pt)arrayList_get(manager->psaList,i);
+ psa->closeAllPublications(psa->admin,p->scope, p->topic);
+ }
+ }
+
+ pubsubEndpoint_destroy(p);
+ }
+
+
+ }
+ free(pub_key);
+ celixThreadMutex_unlock(&manager->publicationsLock);
+ celixThreadMutex_unlock(&manager->psaListLock);
+
+
+ return status;
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.h b/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.h
new file mode 100644
index 0000000..0074a75
--- /dev/null
+++ b/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.h
@@ -0,0 +1,82 @@
+/**
+ *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.
+ */
+/*
+ * pubsub_topology_manager.h
+ *
+ * \date Sep 29, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PUBSUB_TOPOLOGY_MANAGER_H_
+#define PUBSUB_TOPOLOGY_MANAGER_H_
+
+#include "service_reference.h"
+#include "bundle_context.h"
+#include "log_helper.h"
+
+#include "pubsub_common.h"
+#include "pubsub_endpoint.h"
+#include "pubsub/publisher.h"
+#include "pubsub/subscriber.h"
+
+
+struct pubsub_topology_manager {
+ bundle_context_pt context;
+
+ celix_thread_mutex_t psaListLock;
+ array_list_pt psaList;
+
+ celix_thread_mutex_t discoveryListLock;
+ hash_map_pt discoveryList; //<serviceReference,NULL>
+
+ celix_thread_mutex_t publicationsLock;
+ hash_map_pt publications; //<topic(string),list<pubsub_ep>>
+
+ celix_thread_mutex_t subscriptionsLock;
+ hash_map_pt subscriptions; //<topic(string),list<pubsub_ep>>
+
+ log_helper_pt loghelper;
+};
+
+typedef struct pubsub_topology_manager *pubsub_topology_manager_pt;
+
+celix_status_t pubsub_topologyManager_create(bundle_context_pt context, log_helper_pt logHelper, pubsub_topology_manager_pt *manager);
+celix_status_t pubsub_topologyManager_destroy(pubsub_topology_manager_pt manager);
+celix_status_t pubsub_topologyManager_closeImports(pubsub_topology_manager_pt manager);
+
+celix_status_t pubsub_topologyManager_psaAdded(void *handle, service_reference_pt reference, void *service);
+celix_status_t pubsub_topologyManager_psaModified(void *handle, service_reference_pt reference, void *service);
+celix_status_t pubsub_topologyManager_psaRemoved(void *handle, service_reference_pt reference, void *service);
+
+celix_status_t pubsub_topologyManager_pubsubDiscoveryAdded(void* handle, service_reference_pt reference, void* service);
+celix_status_t pubsub_topologyManager_pubsubDiscoveryModified(void * handle, service_reference_pt reference, void* service);
+celix_status_t pubsub_topologyManager_pubsubDiscoveryRemoved(void * handle, service_reference_pt reference, void* service);
+
+celix_status_t pubsub_topologyManager_subscriberAdded(void * handle, service_reference_pt reference, void * service);
+celix_status_t pubsub_topologyManager_subscriberModified(void * handle, service_reference_pt reference, void * service);
+celix_status_t pubsub_topologyManager_subscriberRemoved(void * handle, service_reference_pt reference, void * service);
+
+celix_status_t pubsub_topologyManager_publisherTrackerAdded(void *handle, array_list_pt listeners);
+celix_status_t pubsub_topologyManager_publisherTrackerRemoved(void *handle, array_list_pt listeners);
+
+celix_status_t pubsub_topologyManager_announcePublisher(void *handle, pubsub_endpoint_pt pubEP);
+celix_status_t pubsub_topologyManager_removePublisher(void *handle, pubsub_endpoint_pt pubEP);
+
+#endif /* PUBSUB_TOPOLOGY_MANAGER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/pubsub/test/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/test/CMakeLists.txt b/pubsub/test/CMakeLists.txt
index 65e22e5..9fd324e 100644
--- a/pubsub/test/CMakeLists.txt
+++ b/pubsub/test/CMakeLists.txt
@@ -20,23 +20,21 @@ find_program(ETCD_CMD NAMES etcd)
find_package(CppUTest REQUIRED)
include_directories(${CPPUTEST_INCLUDE_DIR})
-include_directories(
- ${CMAKE_SOURCE_DIR}/pubsub/api
- test
-)
-
add_bundle(pubsub_sut
#"Vanilla" bundle which is under test
SOURCES
test/sut_activator.c
VERSION 1.0.0
)
-target_link_libraries(pubsub_sut PRIVATE Celix::framework)
+target_include_directories(pubsub_sut PRIVATE test)
+target_link_libraries(pubsub_sut PRIVATE Celix::pubsub_spi)
+
bundle_files(pubsub_sut
msg_descriptors/msg.descriptor
msg_descriptors/sync.descriptor
DESTINATION "META-INF/descriptors/messages"
)
+
add_deploy(pubsub_udpmc_sut
NAME deploy_sut
BUNDLES
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/CMakeLists.txt b/remote_services/CMakeLists.txt
index bb45908..ae27849 100644
--- a/remote_services/CMakeLists.txt
+++ b/remote_services/CMakeLists.txt
@@ -18,23 +18,24 @@
celix_subproject(REMOTE_SERVICE_ADMIN "Option to enable building the Remote Service Admin Service bundles" OFF)
if (REMOTE_SERVICE_ADMIN)
- add_subdirectory(examples)
+ add_subdirectory(remote_services_api)
+ add_subdirectory(rsa_spi)
+ add_subdirectory(rsa_common)
+
+ add_subdirectory(civetweb)
add_subdirectory(topology_manager)
- add_subdirectory(civetweb)
add_subdirectory(discovery_common)
add_subdirectory(discovery_configured)
add_subdirectory(discovery_etcd)
add_subdirectory(discovery_shm)
#TODO refactor shm rsa to use dfi
- add_subdirectory(remote_service_admin_api)
- add_subdirectory(remote_service_admin_common)
#add_subdirectory(remote_service_admin_shm)
add_subdirectory(remote_service_admin_dfi)
-
+ add_subdirectory(examples)
endif (REMOTE_SERVICE_ADMIN)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/discovery_common/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/discovery_common/CMakeLists.txt b/remote_services/discovery_common/CMakeLists.txt
index c3242a6..114f485 100644
--- a/remote_services/discovery_common/CMakeLists.txt
+++ b/remote_services/discovery_common/CMakeLists.txt
@@ -31,7 +31,7 @@ target_include_directories(rsa_discovery_common PUBLIC
$<TARGET_PROPERTY:Celix::framework,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:Celix::utils,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:Celix::log_helper,INTERFACE_INCLUDE_DIRECTORIES>
- $<TARGET_PROPERTY:Celix::rsa_api,INTERFACE_INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:Celix::rsa_spi,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:civetweb,INCLUDE_DIRECTORIES>
${LIBXML2_INCLUDE_DIR})
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/examples/calculator_service/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/CMakeLists.txt b/remote_services/examples/calculator_service/CMakeLists.txt
index 5d97d16..167e705 100644
--- a/remote_services/examples/calculator_service/CMakeLists.txt
+++ b/remote_services/examples/calculator_service/CMakeLists.txt
@@ -23,7 +23,7 @@ add_bundle(calculator
VERSION 0.0.1
)
target_include_directories(calculator PRIVATE src)
-target_link_libraries(calculator PRIVATE Celix::rsa_api calculator_api)
+target_link_libraries(calculator PRIVATE Celix::rsa_spi calculator_api)
get_target_property(DESCR calculator_api INTERFACE_CALCULATOR_DESCRIPTOR)
bundle_files(calculator ${DESCR} DESTINATION .)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_api/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/CMakeLists.txt b/remote_services/remote_service_admin_api/CMakeLists.txt
deleted file mode 100644
index f665576..0000000
--- a/remote_services/remote_service_admin_api/CMakeLists.txt
+++ /dev/null
@@ -1,45 +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.
-
-add_library(rsa_api INTERFACE)
-target_include_directories(rsa_api INTERFACE include)
-
-install (FILES
- include/remote_endpoint_impl.h
- include/remote_endpoint.h
- include/remote_proxy.h
- include/remote_service_admin.h
- include/export_registration.h
- include/import_registration.h
- include/endpoint_description.h
- include/endpoint_listener.h
- include/remote_constants.h
- DESTINATION
- include/celix/remote_service_admin
- COMPONENT
- remote_service_admin
-)
-install (FILES
- public/include/endpoint_listener.h
- DESTINATION
- include/celix/endpoint_listener
- COMPONENT
- remote_service_admin
-)
-
-#Setup target aliases to match external usage
-add_library(Celix::rsa_api ALIAS rsa_api)
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_api/README.md
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/README.md b/remote_services/remote_service_admin_api/README.md
deleted file mode 100644
index 2e3d268..0000000
--- a/remote_services/remote_service_admin_api/README.md
+++ /dev/null
@@ -1,11 +0,0 @@
-# Remote Service Admin
-
-The Remote Service Admin (RSA) provides the mechanisms to import and export services when instructed to do so by the Topology Manager.
-
-To delegate method calls to the actual service implementation, the RSA_SHM and the RSA_HTTP are using "endpoint/proxy" bundles, which has all the knowledge about the marshalling and unmarshalling of data for the service. The RSA_DFI implementation combines a [foreign function interface](https://en.wikipedia.org/wiki/Foreign_function_interface) technique together with manualy created descriptors.
-
-Note that this folder contains code commonly used by the RSA implementations and therefore does not include any CMAKE configuration.
-
-## Properties
- ENDPOINTS defines the relative directory where endpoints and proxys can be found (default: endpoints)
- CELIX_FRAMEWORK_EXTENDER_PATH Used in RSA_DFI only. Can be used to define a path to use as an extender path point for the framework bundle. For normal bundles the bundle cache is used.
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_api/include/endpoint_description.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/endpoint_description.h b/remote_services/remote_service_admin_api/include/endpoint_description.h
deleted file mode 100644
index de27d2e..0000000
--- a/remote_services/remote_service_admin_api/include/endpoint_description.h
+++ /dev/null
@@ -1,50 +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.
- */
-/*
- * endpoint_description.h
- *
- * \date 25 Jul 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef ENDPOINT_DESCRIPTION_H_
-#define ENDPOINT_DESCRIPTION_H_
-
-#include "properties.h"
-#include "array_list.h"
-
-struct endpoint_description {
- char *frameworkUUID;
- char *id;
- // array_list_pt intents;
- char *service;
- // HASH_MAP packageVersions;
- properties_pt properties;
- unsigned long serviceId;
-};
-
-typedef struct endpoint_description endpoint_description_t;
-typedef endpoint_description_t* endpoint_description_pt;
-
-celix_status_t endpointDescription_create(properties_pt properties, endpoint_description_pt *endpointDescription);
-celix_status_t endpointDescription_destroy(endpoint_description_pt description);
-
-
-#endif /* ENDPOINT_DESCRIPTION_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_api/include/endpoint_listener.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/endpoint_listener.h b/remote_services/remote_service_admin_api/include/endpoint_listener.h
deleted file mode 100644
index 2e6359f..0000000
--- a/remote_services/remote_service_admin_api/include/endpoint_listener.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.
- */
-/*
- * endpoint_listener.h
- *
- * \date Sep 29, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef ENDPOINT_LISTENER_H_
-#define ENDPOINT_LISTENER_H_
-
-#include "array_list.h"
-#include "properties.h"
-
-#include "endpoint_description.h"
-
-static const char * const OSGI_ENDPOINT_LISTENER_SERVICE = "endpoint_listener";
-
-static const char * const OSGI_ENDPOINT_LISTENER_SCOPE = "endpoint.listener.scope";
-
-struct endpoint_listener {
- void *handle;
- celix_status_t (*endpointAdded)(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
- celix_status_t (*endpointRemoved)(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
-};
-
-typedef struct endpoint_listener endpoint_listener_t;
-typedef endpoint_listener_t *endpoint_listener_pt;
-
-
-#endif /* ENDPOINT_LISTENER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_api/include/export_registration.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/export_registration.h b/remote_services/remote_service_admin_api/include/export_registration.h
deleted file mode 100644
index dc3882b..0000000
--- a/remote_services/remote_service_admin_api/include/export_registration.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed under Apache License v2. See LICENSE for more information.
- */
-#ifndef CELIX_EXPORT_REGISTRATION_H
-#define CELIX_EXPORT_REGISTRATION_H
-
-#include "celix_errno.h"
-#include "endpoint_description.h"
-#include "service_reference.h"
-
-typedef struct export_registration *export_registration_pt;
-
-typedef struct export_reference *export_reference_pt;
-
-celix_status_t exportRegistration_close(export_registration_pt registration);
-celix_status_t exportRegistration_getException(export_registration_pt registration);
-celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *reference);
-
-celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint);
-celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service);
-
-#endif //CELIX_EXPORT_REGISTRATION_H
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_api/include/import_registration.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/import_registration.h b/remote_services/remote_service_admin_api/include/import_registration.h
deleted file mode 100644
index ef8193f..0000000
--- a/remote_services/remote_service_admin_api/include/import_registration.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed under Apache License v2. See LICENSE for more information.
- */
-#ifndef CELIX_IMPORT_REGISTRATION_H
-#define CELIX_IMPORT_REGISTRATION_H
-
-#include "celix_errno.h"
-#include "endpoint_description.h"
-#include "service_reference.h"
-
-typedef struct import_registration *import_registration_pt;
-
-typedef struct import_reference *import_reference_pt;
-
-celix_status_t importRegistration_close(import_registration_pt registration);
-celix_status_t importRegistration_getException(import_registration_pt registration);
-celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference);
-
-celix_status_t importReference_getImportedEndpoint(import_reference_pt reference);
-celix_status_t importReference_getImportedService(import_reference_pt reference);
-
-#endif //CELIX_IMPORT_REGISTRATION_H
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_api/include/remote_constants.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/remote_constants.h b/remote_services/remote_service_admin_api/include/remote_constants.h
deleted file mode 100644
index 0736685..0000000
--- a/remote_services/remote_service_admin_api/include/remote_constants.h
+++ /dev/null
@@ -1,38 +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.
- */
-/*
- * remote_constants.h
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_CONSTANTS_H_
-#define REMOTE_CONSTANTS_H_
-
-static const char * const OSGI_RSA_SERVICE_EXPORTED_INTERFACES = "service.exported.interfaces";
-static const char * const OSGI_RSA_ENDPOINT_FRAMEWORK_UUID = "endpoint.framework.uuid";
-static const char * const OSGI_RSA_ENDPOINT_SERVICE_ID = "endpoint.service.id";
-static const char * const OSGI_RSA_ENDPOINT_ID = "endpoint.id";
-static const char * const OSGI_RSA_SERVICE_IMPORTED = "service.imported";
-static const char * const OSGI_RSA_SERVICE_IMPORTED_CONFIGS = "service.imported.configs";
-static const char * const OSGI_RSA_SERVICE_LOCATION = "service.location";
-
-#endif /* REMOTE_CONSTANTS_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_api/include/remote_endpoint.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/remote_endpoint.h b/remote_services/remote_service_admin_api/include/remote_endpoint.h
deleted file mode 100644
index ab80abb..0000000
--- a/remote_services/remote_service_admin_api/include/remote_endpoint.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.
- */
-/*
- * remote_endpoint.h
- *
- * \date Oct 7, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_ENDPOINT_H_
-#define REMOTE_ENDPOINT_H_
-
-#define OSGI_RSA_REMOTE_ENDPOINT "remote_endpoint"
-
-typedef struct remote_endpoint remote_endpoint_t;
-typedef remote_endpoint_t* remote_endpoint_pt;
-
-struct remote_endpoint_service {
- remote_endpoint_pt endpoint;
- celix_status_t (*setService)(remote_endpoint_pt endpoint, void *service);
- celix_status_t (*handleRequest)(remote_endpoint_pt endpoint, char *data, char **reply);
-};
-
-typedef struct remote_endpoint_service *remote_endpoint_service_pt;
-
-
-#endif /* REMOTE_ENDPOINT_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_api/include/remote_endpoint_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/remote_endpoint_impl.h b/remote_services/remote_service_admin_api/include/remote_endpoint_impl.h
deleted file mode 100644
index 3782d62..0000000
--- a/remote_services/remote_service_admin_api/include/remote_endpoint_impl.h
+++ /dev/null
@@ -1,38 +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.
- */
-/*
- * remote_endpoint_impl.h
- *
- * \date Oct 11, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_ENDPOINT_IMPL_H_
-#define REMOTE_ENDPOINT_IMPL_H_
-
-#include "remote_endpoint.h"
-#include "celix_threads.h"
-
-struct remote_endpoint {
- celix_thread_mutex_t serviceLock;
- void *service;
-};
-
-#endif /* REMOTE_ENDPOINT_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_api/include/remote_proxy.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/remote_proxy.h b/remote_services/remote_service_admin_api/include/remote_proxy.h
deleted file mode 100644
index 4c3f5c3..0000000
--- a/remote_services/remote_service_admin_api/include/remote_proxy.h
+++ /dev/null
@@ -1,76 +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.
- */
-/*
- * remote_proxy.h
- *
- * \date Oct 13, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_PROXY_H_
-#define REMOTE_PROXY_H_
-
-#include "endpoint_listener.h"
-#include "remote_service_admin.h"
-
-#define OSGI_RSA_REMOTE_PROXY_FACTORY "remote_proxy_factory"
-#define OSGI_RSA_REMOTE_PROXY_TIMEOUT "remote_proxy_timeout"
-
-typedef celix_status_t (*sendToHandle)(remote_service_admin_pt remote_service_admin_ptr, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
-typedef celix_status_t (*createProxyService)(void *handle, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback, properties_pt properties, void **service);
-typedef celix_status_t (*destroyProxyService)(void *handle, void *service);
-
-typedef struct remote_proxy_factory *remote_proxy_factory_pt;
-typedef struct remote_proxy_factory_service *remote_proxy_factory_service_pt;
-
-struct remote_proxy_factory {
- bundle_context_pt context_ptr;
- char *service;
-
- remote_proxy_factory_service_pt remote_proxy_factory_service_ptr;
- properties_pt properties;
- service_registration_pt registration;
-
- hash_map_pt proxy_instances;
-
- void *handle;
-
- createProxyService create_proxy_service_ptr;
- destroyProxyService destroy_proxy_service_ptr;
-};
-
-struct remote_proxy_factory_service {
- remote_proxy_factory_pt factory;
- celix_status_t (*registerProxyService)(remote_proxy_factory_pt proxyFactoryService, endpoint_description_pt endpoint, remote_service_admin_pt remote_service_admin_ptr, sendToHandle callback);
- celix_status_t (*unregisterProxyService)(remote_proxy_factory_pt proxyFactoryService, endpoint_description_pt endpoint);
-};
-
-celix_status_t remoteProxyFactory_create(bundle_context_pt context, char *service, void *handle,
- createProxyService create, destroyProxyService destroy,
- remote_proxy_factory_pt *remote_proxy_factory_ptr);
-celix_status_t remoteProxyFactory_destroy(remote_proxy_factory_pt *remote_proxy_factory_ptr);
-
-celix_status_t remoteProxyFactory_register(remote_proxy_factory_pt remote_proxy_factory_ptr);
-celix_status_t remoteProxyFactory_unregister(remote_proxy_factory_pt remote_proxy_factory_ptr);
-
-
-
-
-#endif /* REMOTE_PROXY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_api/include/remote_service_admin.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_api/include/remote_service_admin.h b/remote_services/remote_service_admin_api/include/remote_service_admin.h
deleted file mode 100644
index cc7fd98..0000000
--- a/remote_services/remote_service_admin_api/include/remote_service_admin.h
+++ /dev/null
@@ -1,73 +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.
- */
-/*
- * remote_service_admin.h
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_SERVICE_ADMIN_H_
-#define REMOTE_SERVICE_ADMIN_H_
-
-#include "endpoint_listener.h"
-#include "service_reference.h"
-#include "export_registration.h"
-#include "import_registration.h"
-
-#define OSGI_RSA_REMOTE_SERVICE_ADMIN "remote_service_admin"
-
-typedef struct import_registration_factory import_registration_factory_t;
-typedef import_registration_factory_t* import_registration_factory_pt;
-
-typedef struct remote_service_admin remote_service_admin_t;
-typedef remote_service_admin_t* remote_service_admin_pt;
-
-struct remote_service_admin_service {
- remote_service_admin_pt admin;
- celix_status_t (*exportService)(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
- celix_status_t (*removeExportedService)(remote_service_admin_pt admin, export_registration_pt registration);
- celix_status_t (*getExportedServices)(remote_service_admin_pt admin, array_list_pt *services);
- celix_status_t (*getImportedEndpoints)(remote_service_admin_pt admin, array_list_pt *services);
- celix_status_t (*importService)(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
-
- celix_status_t (*exportReference_getExportedEndpoint)(export_reference_pt reference, endpoint_description_pt *endpoint);
- celix_status_t (*exportReference_getExportedService)(export_reference_pt reference, service_reference_pt *service);
-
- celix_status_t (*exportRegistration_close)(remote_service_admin_pt admin, export_registration_pt registration);
- celix_status_t (*exportRegistration_getException)(export_registration_pt registration);
- celix_status_t (*exportRegistration_getExportReference)(export_registration_pt registration, export_reference_pt *reference);
- celix_status_t (*exportRegistration_freeExportReference)(export_reference_pt *reference);
- celix_status_t (*exportRegistration_getEndpointDescription)(export_registration_pt registration, endpoint_description_pt endpointDescription);
-
- celix_status_t (*importReference_getImportedEndpoint)(import_reference_pt reference);
- celix_status_t (*importReference_getImportedService)(import_reference_pt reference);
-
- celix_status_t (*importRegistration_close)(remote_service_admin_pt admin, import_registration_pt registration);
- celix_status_t (*importRegistration_getException)(import_registration_pt registration);
- celix_status_t (*importRegistration_getImportReference)(import_registration_pt registration, import_reference_pt *reference);
-
-};
-
-typedef struct remote_service_admin_service remote_service_admin_service_t;
-typedef remote_service_admin_service_t* remote_service_admin_service_pt;
-
-
-#endif /* REMOTE_SERVICE_ADMIN_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_common/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/CMakeLists.txt b/remote_services/remote_service_admin_common/CMakeLists.txt
deleted file mode 100644
index 018d868..0000000
--- a/remote_services/remote_service_admin_common/CMakeLists.txt
+++ /dev/null
@@ -1,27 +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.
-
-add_library(rsa_common STATIC
- src/endpoint_description.c
- src/export_registration_impl.c
- src/import_registration_impl.c
-)
-target_include_directories(rsa_common PRIVATE src)
-target_link_libraries(rsa_common PUBLIC Celix::framework Celix::rsa_api Celix::log_helper)
-
-#Setup target aliases to match external usage
-add_library(Celix::rsa_common ALIAS rsa_common)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_common/src/endpoint_description.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/endpoint_description.c b/remote_services/remote_service_admin_common/src/endpoint_description.c
deleted file mode 100644
index 0d8b684..0000000
--- a/remote_services/remote_service_admin_common/src/endpoint_description.c
+++ /dev/null
@@ -1,89 +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.
- */
-/*
- * endpoint_description.c
- *
- * \date 25 Jul 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <string.h>
-
-#include "celix_errno.h"
-#include "celix_log.h"
-
-#include "endpoint_description.h"
-#include "remote_constants.h"
-#include "constants.h"
-
-static celix_status_t endpointDescription_verifyLongProperty(properties_pt properties, char *propertyName, unsigned long *longProperty);
-
-celix_status_t endpointDescription_create(properties_pt properties, endpoint_description_pt *endpointDescription) {
- celix_status_t status = CELIX_SUCCESS;
-
- unsigned long serviceId = 0UL;
- status = endpointDescription_verifyLongProperty(properties, (char *) OSGI_RSA_ENDPOINT_SERVICE_ID, &serviceId);
- if (status != CELIX_SUCCESS) {
- return status;
- }
-
- endpoint_description_pt ep = calloc(1,sizeof(*ep));
-
- ep->properties = properties;
- ep->frameworkUUID = (char*)properties_get(properties, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
- ep->id = (char*)properties_get(properties, OSGI_RSA_ENDPOINT_ID);
- ep->service = strndup(properties_get(properties, OSGI_FRAMEWORK_OBJECTCLASS), 1024*10);
- ep->serviceId = serviceId;
-
- if (!(ep->frameworkUUID) || !(ep->id) || !(ep->service) ) {
- fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "ENDPOINT_DESCRIPTION: incomplete description!.");
- status = CELIX_BUNDLE_EXCEPTION;
- }
-
- if(status == CELIX_SUCCESS){
- *endpointDescription = ep;
- }
- else{
- *endpointDescription = NULL;
- free(ep);
- }
-
- return status;
-}
-
-celix_status_t endpointDescription_destroy(endpoint_description_pt description) {
- properties_destroy(description->properties);
- free(description->service);
- free(description);
- return CELIX_SUCCESS;
-}
-
-static celix_status_t endpointDescription_verifyLongProperty(properties_pt properties, char *propertyName, unsigned long *longProperty) {
- celix_status_t status = CELIX_SUCCESS;
-
- const char *value = properties_get(properties, propertyName);
- if (value == NULL) {
- *longProperty = 0UL;
- } else {
- *longProperty = strtoul(value,NULL,10);
- }
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_common/src/export_registration_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/export_registration_impl.c b/remote_services/remote_service_admin_common/src/export_registration_impl.c
deleted file mode 100644
index 1c684e7..0000000
--- a/remote_services/remote_service_admin_common/src/export_registration_impl.c
+++ /dev/null
@@ -1,257 +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.
- */
-/*
- * export_registration_impl.c
- *
- * \date Oct 6, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-
-#include "constants.h"
-
-#include "celix_errno.h"
-
-#include "export_registration_impl.h"
-#include "remote_service_admin_impl.h"
-
-
-struct export_reference {
- endpoint_description_pt endpoint;
- service_reference_pt reference;
-};
-
-celix_status_t exportRegistration_endpointAdding(void * handle, service_reference_pt reference, void **service);
-celix_status_t exportRegistration_endpointAdded(void * handle, service_reference_pt reference, void *service);
-celix_status_t exportRegistration_endpointModified(void * handle, service_reference_pt reference, void *service);
-celix_status_t exportRegistration_endpointRemoved(void * handle, service_reference_pt reference, void *service);
-
-celix_status_t exportRegistration_createEndpointTracker(export_registration_pt registration, service_tracker_pt *tracker);
-
-celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, remote_service_admin_pt rsa, bundle_context_pt context, export_registration_pt *registration) {
- celix_status_t status = CELIX_SUCCESS;
-
- *registration = calloc(1, sizeof(**registration));
- if (!*registration) {
- status = CELIX_ENOMEM;
- } else {
- (*registration)->context = context;
- (*registration)->closed = false;
- (*registration)->endpointDescription = endpoint;
- (*registration)->reference = reference;
- (*registration)->rsa = rsa;
- (*registration)->tracker = NULL;
- (*registration)->endpoint = NULL;
- (*registration)->endpointTracker = NULL;
- (*registration)->exportReference = NULL;
- (*registration)->bundle = NULL;
- (*registration)->loghelper = helper;
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_destroy(export_registration_pt *registration) {
- celix_status_t status = CELIX_SUCCESS;
-
- remoteServiceAdmin_destroyEndpointDescription(&(*registration)->endpointDescription);
- free(*registration);
-
- return status;
-}
-
-celix_status_t exportRegistration_startTracking(export_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (registration->endpointTracker == NULL) {
- status = exportRegistration_createEndpointTracker(registration, ®istration->endpointTracker);
- if (status == CELIX_SUCCESS) {
- status = serviceTracker_open(registration->endpointTracker);
- }
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_stopTracking(export_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (registration->endpointTracker != NULL) {
- status = serviceTracker_close(registration->endpointTracker);
- if (status != CELIX_SUCCESS) {
- logHelper_log(registration->loghelper, OSGI_LOGSERVICE_ERROR, "EXPORT_REGISTRATION: Could not close endpoint tracker");
- }
- else {
- status = serviceTracker_destroy(registration->endpointTracker);
- }
- }
- if (registration->tracker != NULL) {
- status = serviceTracker_close(registration->tracker);
- if (status != CELIX_SUCCESS) {
- logHelper_log(registration->loghelper, OSGI_LOGSERVICE_ERROR, "EXPORT_REGISTRATION: Could not close service tracker");
- }
- else {
- status = serviceTracker_destroy(registration->tracker);
- }
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_createEndpointTracker(export_registration_pt registration, service_tracker_pt *tracker) {
- celix_status_t status;
-
- service_tracker_customizer_pt customizer = NULL;
-
- status = serviceTrackerCustomizer_create(registration, exportRegistration_endpointAdding,
- exportRegistration_endpointAdded, exportRegistration_endpointModified, exportRegistration_endpointRemoved, &customizer);
-
- if (status == CELIX_SUCCESS) {
- char filter[512];
-
- snprintf(filter, 512, "(&(%s=%s)(remote.interface=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, (char*) OSGI_RSA_REMOTE_ENDPOINT, registration->endpointDescription->service);
- status = serviceTracker_createWithFilter(registration->context, filter, customizer, tracker);
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_endpointAdding(void * handle, service_reference_pt reference, void **service) {
- celix_status_t status;
- export_registration_pt registration = handle;
-
- status = bundleContext_getService(registration->context, reference, service);
-
- return status;
-}
-
-celix_status_t exportRegistration_endpointAdded(void * handle, service_reference_pt reference, void *endpoint_service) {
- celix_status_t status = CELIX_SUCCESS;
- export_registration_pt registration = handle;
-
- remote_endpoint_service_pt endpoint = endpoint_service;
- if (registration->endpoint == NULL) {
- registration->endpoint = endpoint;
- void *service = NULL;
- status = bundleContext_getService(registration->context, registration->reference, &service);
- if (status == CELIX_SUCCESS) {
- endpoint->setService(endpoint->endpoint, service);
- }
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_endpointModified(void * handle, service_reference_pt reference, void *service) {
- celix_status_t status = CELIX_SUCCESS;
-
- return status;
-}
-
-celix_status_t exportRegistration_endpointRemoved(void * handle, service_reference_pt reference, void *service) {
- celix_status_t status = CELIX_SUCCESS;
- export_registration_pt registration = handle;
-
- remote_endpoint_service_pt endpoint = service;
- if (registration->endpoint != NULL) {
- endpoint->setService(endpoint->endpoint, NULL);
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_open(export_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- const char *bundleStore = NULL;
-
- bundleContext_getProperty(registration->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore);
-
- if (bundleStore == NULL) {
- bundleStore = DEFAULT_BUNDLE_STORE;
- }
- char name[256];
-
- snprintf(name, 256, "%s/%s_endpoint.zip", bundleStore, registration->endpointDescription->service);
-
- status = bundleContext_installBundle(registration->context, name, ®istration->bundle);
- if (status == CELIX_SUCCESS) {
- status = bundle_start(registration->bundle);
- if (status == CELIX_SUCCESS) {
- }
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_close(export_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
-
- exportRegistration_stopTracking(registration);
-
- bundle_uninstall(registration->bundle);
-
-
- return status;
-}
-
-celix_status_t exportRegistration_getException(export_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *reference) {
- celix_status_t status = CELIX_SUCCESS;
-
- registration->exportReference = calloc(1, sizeof(*registration->exportReference));
-
- if (registration->exportReference == NULL) {
- status = CELIX_ENOMEM;
- } else {
- registration->exportReference->endpoint = registration->endpointDescription;
- registration->exportReference->reference = registration->reference;
- }
-
- *reference = registration->exportReference;
-
- return status;
-}
-
-celix_status_t exportRegistration_setEndpointDescription(export_registration_pt registration, endpoint_description_pt endpointDescription) {
- celix_status_t status = CELIX_SUCCESS;
-
- registration->endpointDescription = endpointDescription;
-
- return status;
-}
-
-celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint) {
- celix_status_t status = CELIX_SUCCESS;
-
- *endpoint = reference->endpoint;
-
- return status;
-}
-
-celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service) {
- celix_status_t status = CELIX_SUCCESS;
- *service = reference->reference;
- return status;
-}
-
http://git-wip-us.apache.org/repos/asf/celix/blob/81804e00/remote_services/remote_service_admin_common/src/export_registration_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/export_registration_impl.h b/remote_services/remote_service_admin_common/src/export_registration_impl.h
deleted file mode 100644
index bb276f9..0000000
--- a/remote_services/remote_service_admin_common/src/export_registration_impl.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.
- */
-/*
- * export_registration_impl.h
- *
- * \date Oct 6, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef EXPORT_REGISTRATION_IMPL_H_
-#define EXPORT_REGISTRATION_IMPL_H_
-
-#include "remote_service_admin.h"
-#include "remote_endpoint.h"
-#include "service_tracker.h"
-#include "log_helper.h"
-
-struct export_registration {
- bundle_context_pt context;
- remote_service_admin_pt rsa;
- endpoint_description_pt endpointDescription;
- service_reference_pt reference;
- log_helper_pt loghelper;
-
- service_tracker_pt tracker;
- service_tracker_pt endpointTracker;
-
- remote_endpoint_service_pt endpoint;
-
- export_reference_pt exportReference;
- bundle_pt bundle;
-
- bool closed;
-};
-
-celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, remote_service_admin_pt rsa, bundle_context_pt context, export_registration_pt *registration);
-celix_status_t exportRegistration_destroy(export_registration_pt *registration);
-celix_status_t exportRegistration_open(export_registration_pt registration);
-
-celix_status_t exportRegistration_setEndpointDescription(export_registration_pt registration, endpoint_description_pt endpointDescription);
-celix_status_t exportRegistration_startTracking(export_registration_pt registration);
-celix_status_t exportRegistration_stopTracking(export_registration_pt registration);
-
-#endif /* EXPORT_REGISTRATION_IMPL_H_ */