Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 79520200D44 for ; Mon, 20 Nov 2017 21:33:03 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 7684E160C28; Mon, 20 Nov 2017 20:33:03 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C3B71160C16 for ; Mon, 20 Nov 2017 21:33:00 +0100 (CET) Received: (qmail 59898 invoked by uid 500); 20 Nov 2017 20:32:59 -0000 Mailing-List: contact commits-help@celix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@celix.apache.org Delivered-To: mailing list commits@celix.apache.org Received: (qmail 59302 invoked by uid 99); 20 Nov 2017 20:32:58 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Nov 2017 20:32:58 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 65F58F5F7C; Mon, 20 Nov 2017 20:32:58 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: pnoltes@apache.org To: commits@celix.apache.org Date: Mon, 20 Nov 2017 20:33:08 -0000 Message-Id: <223439a4913b441488e3914d2bbd165b@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [11/46] celix git commit: CELIX-417: Initial refactoring for CMake usage archived-at: Mon, 20 Nov 2017 20:33:03 -0000 http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/src/unzip.h ---------------------------------------------------------------------- diff --git a/framework/src/unzip.h b/framework/src/unzip.h new file mode 100644 index 0000000..3183968 --- /dev/null +++ b/framework/src/unzip.h @@ -0,0 +1,437 @@ +/* unzip.h -- IO for uncompress .zip files using zlib + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications of Unzip for Zip64 + Copyright (C) 2007-2008 Even Rouault + + Modifications for Zip64 support on both zip and unzip + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + --------------------------------------------------------------------------------- + + Condition of use and distribution are the same than zlib : + + 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. + + --------------------------------------------------------------------------------- + + Changes + + See header of unzip64.c + +*/ + +#ifndef _unz64_H +#define _unz64_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#ifndef _ZLIBIOAPI_H +#include "ioapi.h" +#endif + +#ifdef HAVE_BZIP2 +#include "bzlib.h" +#endif + +#define Z_BZIP2ED 12 + +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) +/* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ +typedef struct TagunzFile__ { int unused; } unzFile__; +typedef unzFile__ *unzFile; +#else +typedef voidp unzFile; +#endif + + +#define UNZ_OK (0) +#define UNZ_END_OF_LIST_OF_FILE (-100) +#define UNZ_ERRNO (Z_ERRNO) +#define UNZ_EOF (0) +#define UNZ_PARAMERROR (-102) +#define UNZ_BADZIPFILE (-103) +#define UNZ_INTERNALERROR (-104) +#define UNZ_CRCERROR (-105) + +/* tm_unz contain date/time info */ +typedef struct tm_unz_s +{ + uInt tm_sec; /* seconds after the minute - [0,59] */ + uInt tm_min; /* minutes after the hour - [0,59] */ + uInt tm_hour; /* hours since midnight - [0,23] */ + uInt tm_mday; /* day of the month - [1,31] */ + uInt tm_mon; /* months since January - [0,11] */ + uInt tm_year; /* years - [1980..2044] */ +} tm_unz; + +/* unz_global_info structure contain global data about the ZIPfile + These data comes from the end of central dir */ +typedef struct unz_global_info64_s +{ + ZPOS64_T number_entry; /* total number of entries in + the central dir on this disk */ + uLong size_comment; /* size of the global comment of the zipfile */ +} unz_global_info64; + +typedef struct unz_global_info_s +{ + uLong number_entry; /* total number of entries in + the central dir on this disk */ + uLong size_comment; /* size of the global comment of the zipfile */ +} unz_global_info; + +/* unz_file_info contain information about a file in the zipfile */ +typedef struct unz_file_info64_s +{ + uLong version; /* version made by 2 bytes */ + uLong version_needed; /* version needed to extract 2 bytes */ + uLong flag; /* general purpose bit flag 2 bytes */ + uLong compression_method; /* compression method 2 bytes */ + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ + uLong crc; /* crc-32 4 bytes */ + ZPOS64_T compressed_size; /* compressed size 8 bytes */ + ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */ + uLong size_filename; /* filename length 2 bytes */ + uLong size_file_extra; /* extra field length 2 bytes */ + uLong size_file_comment; /* file comment length 2 bytes */ + + uLong disk_num_start; /* disk number start 2 bytes */ + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ + + tm_unz tmu_date; +} unz_file_info64; + +typedef struct unz_file_info_s +{ + uLong version; /* version made by 2 bytes */ + uLong version_needed; /* version needed to extract 2 bytes */ + uLong flag; /* general purpose bit flag 2 bytes */ + uLong compression_method; /* compression method 2 bytes */ + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ + uLong crc; /* crc-32 4 bytes */ + uLong compressed_size; /* compressed size 4 bytes */ + uLong uncompressed_size; /* uncompressed size 4 bytes */ + uLong size_filename; /* filename length 2 bytes */ + uLong size_file_extra; /* extra field length 2 bytes */ + uLong size_file_comment; /* file comment length 2 bytes */ + + uLong disk_num_start; /* disk number start 2 bytes */ + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ + + tm_unz tmu_date; +} unz_file_info; + +extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, + const char* fileName2, + int iCaseSensitivity)); +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) +*/ + + +extern unzFile ZEXPORT unzOpen OF((const char *path)); +extern unzFile ZEXPORT unzOpen64 OF((const void *path)); +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer + "zlib/zlib113.zip". + If the zipfile cannot be opened (file don't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. + the "64" function take a const void* pointer, because the path is just the + value passed to the open64_file_func callback. + Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path + is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* + does not describe the reality +*/ + + +extern unzFile ZEXPORT unzOpen2 OF((const char *path, + zlib_filefunc_def* pzlib_filefunc_def)); +/* + Open a Zip file, like unzOpen, but provide a set of file low level API + for read/write the zip file (see ioapi.h) +*/ + +extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, + zlib_filefunc64_def* pzlib_filefunc_def)); +/* + Open a Zip file, like unz64Open, but provide a set of file low level API + for read/write the zip file (see ioapi.h) +*/ + +extern int ZEXPORT unzClose OF((unzFile file)); +/* + Close a ZipFile opened with unzipOpen. + If there is files inside the .Zip opened with unzOpenCurrentFile (see later), + these files MUST be closed with unzipCloseCurrentFile before call unzipClose. + return UNZ_OK if there is no problem. */ + +extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, + unz_global_info *pglobal_info)); + +extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, + unz_global_info64 *pglobal_info)); +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ + + +extern int ZEXPORT unzGetGlobalComment OF((unzFile file, + char *szComment, + uLong uSizeBuf)); +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ + + +/***************************************************************************/ +/* Unzip package allow you browse the directory of the zipfile */ + +extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ + +extern int ZEXPORT unzGoToNextFile OF((unzFile file)); +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ + +extern int ZEXPORT unzLocateFile OF((unzFile file, + const char *szFileName, + int iCaseSensitivity)); +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ + + +/* ****************************************** */ +/* Ryan supplied functions */ +/* unz_file_info contain information about a file in the zipfile */ +typedef struct unz_file_pos_s +{ + uLong pos_in_zip_directory; /* offset in zip file directory */ + uLong num_of_file; /* # of file */ +} unz_file_pos; + +extern int ZEXPORT unzGetFilePos( + unzFile file, + unz_file_pos* file_pos); + +extern int ZEXPORT unzGoToFilePos( + unzFile file, + unz_file_pos* file_pos); + +typedef struct unz64_file_pos_s +{ + ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */ + ZPOS64_T num_of_file; /* # of file */ +} unz64_file_pos; + +extern int ZEXPORT unzGetFilePos64( + unzFile file, + unz64_file_pos* file_pos); + +extern int ZEXPORT unzGoToFilePos64( + unzFile file, + const unz64_file_pos* file_pos); + +/* ****************************************** */ + +extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, + unz_file_info64 *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); + +extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, + unz_file_info *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); +/* + Get Info about the current file + if pfile_info!=NULL, the *pfile_info structure will contain somes info about + the current file + if szFileName!=NULL, the filemane string will be copied in szFileName + (fileNameBufferSize is the size of the buffer) + if extraField!=NULL, the extra field information will be copied in extraField + (extraFieldBufferSize is the size of the buffer). + This is the Central-header version of the extra field + if szComment!=NULL, the comment string of the file will be copied in szComment + (commentBufferSize is the size of the buffer) +*/ + + +/** Addition for GDAL : START */ + +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); + +/** Addition for GDAL : END */ + + +/***************************************************************************/ +/* for reading the content of the current zipfile, you can open it, read data + from it, and close it (you can close it before reading all the file) + */ + +extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); +/* + Open for reading data the current file in the zipfile. + If there is no error, the return value is UNZ_OK. +*/ + +extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, + const char* password)); +/* + Open for reading data the current file in the zipfile. + password is a crypting password + If there is no error, the return value is UNZ_OK. +*/ + +extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, + int* method, + int* level, + int raw)); +/* + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) + if raw==1 + *method will receive method of compression, *level will receive level of + compression + note : you can set level parameter as NULL (if you did not want known level, + but you CANNOT set method parameter as NULL +*/ + +extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, + int* method, + int* level, + int raw, + const char* password)); +/* + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) + if raw==1 + *method will receive method of compression, *level will receive level of + compression + note : you can set level parameter as NULL (if you did not want known level, + but you CANNOT set method parameter as NULL +*/ + + +extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); +/* + Close the file in zip opened with unzOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ + +extern int ZEXPORT unzReadCurrentFile OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read bytes from the current file (opened by unzOpenCurrentFile) + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ + +extern z_off_t ZEXPORT unztell OF((unzFile file)); + +extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); +/* + Give the current position in uncompressed data +*/ + +extern int ZEXPORT unzeof OF((unzFile file)); +/* + return 1 if the end of file was reached, 0 elsewhere +*/ + +extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ + +/***************************************************************************/ + +/* Get the current file offset */ +extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file); +extern uLong ZEXPORT unzGetOffset (unzFile file); + +/* Set the current file offset */ +extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos); +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); + + + +#ifdef __cplusplus +} +#endif + +#endif /* _unz64_H */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/src/wire.c ---------------------------------------------------------------------- diff --git a/framework/src/wire.c b/framework/src/wire.c new file mode 100644 index 0000000..508c865 --- /dev/null +++ b/framework/src/wire.c @@ -0,0 +1,87 @@ +/** + *Licensed to the Apache Software Foundation (ASF) under one + *or more contributor license agreements. See the NOTICE file + *distributed with this work for additional information + *regarding copyright ownership. The ASF licenses this file + *to you under the Apache License, Version 2.0 (the + *"License"); you may not use this file except in compliance + *with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + *Unless required by applicable law or agreed to in writing, + *software distributed under the License is distributed on an + *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + *specific language governing permissions and limitations + *under the License. + */ +/* + * wire.c + * + * \date Jul 19, 2010 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ +#include + +#include "wire.h" + +struct wire { + module_pt importer; + requirement_pt requirement; + module_pt exporter; + capability_pt capability; +}; + +celix_status_t wire_create(module_pt importer, requirement_pt requirement, + module_pt exporter, capability_pt capability, wire_pt *wire) { + celix_status_t status = CELIX_SUCCESS; + + if (*wire != NULL) { + status = CELIX_ILLEGAL_ARGUMENT; + } else { + (*wire) = (wire_pt) malloc(sizeof(**wire)); + if (!*wire) { + status = CELIX_ENOMEM; + } else { + (*wire)->importer = importer; + (*wire)->requirement = requirement; + (*wire)->exporter = exporter; + (*wire)->capability = capability; + } + } + + framework_logIfError(logger, status, NULL, "Cannot create wire"); + + return status; +} + +celix_status_t wire_destroy(wire_pt wire) { + wire->importer = NULL; + wire->requirement = NULL; + wire->exporter = NULL; + wire->capability = NULL; + free(wire); + return CELIX_SUCCESS; +} + +celix_status_t wire_getCapability(wire_pt wire, capability_pt *capability) { + *capability = wire->capability; + return CELIX_SUCCESS; +} + +celix_status_t wire_getRequirement(wire_pt wire, requirement_pt *requirement) { + *requirement = wire->requirement; + return CELIX_SUCCESS; +} + +celix_status_t wire_getImporter(wire_pt wire, module_pt *importer) { + *importer = wire->importer; + return CELIX_SUCCESS; +} + +celix_status_t wire_getExporter(wire_pt wire, module_pt *exporter) { + *exporter = wire->exporter; + return CELIX_SUCCESS; +} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/tst/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/framework/tst/CMakeLists.txt b/framework/tst/CMakeLists.txt index 672fd99..169e828 100644 --- a/framework/tst/CMakeLists.txt +++ b/framework/tst/CMakeLists.txt @@ -15,23 +15,13 @@ # specific language governing permissions and limitations # under the License. -include_directories( - ${PROJECT_SOURCE_DIR}/framework/public/include - ${PROJECT_SOURCE_DIR}/utils/public/include - ${PROJECT_SOURCE_DIR}/utils/public/include -) - - -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") add_executable(test_framework run_tests.cpp single_framework_test.cpp multiple_frameworks_test.cpp ) -target_link_libraries(test_framework celix_framework celix_utils ${CURL_LIBRARIES} ${CPPUTEST_LIBRARY}) +target_link_libraries(test_framework Celix::framework ${CURL_LIBRARIES} ${CPPUTEST_LIBRARY}) configure_file(config.properties.in config.properties @ONLY) configure_file(framework1.properties.in framework1.properties @ONLY) http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/launcher/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 8d4ba36..33e6e6e 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -21,36 +21,35 @@ if (LAUNCHER) include_directories(public/include) #celix launcher linked to libc - add_executable(celix - private/src/main.c + add_executable(launcher + src/main.c ) + set_target_properties(launcher PROPERTIES OUTPUT_NAME "celix") + set_target_properties(launcher PROPERTIES "INSTALL_RPATH" "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") + target_include_directories(launcher PRIVATE src) - set_target_properties(celix PROPERTIES "INSTALL_RPATH" "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") - - target_link_libraries(celix celix_framework ${CURL_LIBRARIES}) + target_link_libraries(launcher PRIVATE Celix::framework) if (NOT ANDROID) - target_link_libraries(celix celix_dfi) #note not strictly needed, but ensure libdfi is a dep for the framework, useful when create docker images + target_link_libraries(launcher PRIVATE Celix::dfi) #note not strictly needed, but ensure libdfi is a dep for the framework, useful when create docker images endif() - - include_directories("${PROJECT_SOURCE_DIR}/utils/public/include") - include_directories("${PROJECT_SOURCE_DIR}/framework/public/include") - include_directories("${CURL_INCLUDE_DIRS}") - install(TARGETS celix RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT framework) + install(TARGETS launcher RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT framework) + + #Setup target aliases to match external usage + add_executable(Celix::launcher ALIAS launcher) find_package(CppUTest QUIET) if (CPPUTEST_FOUND) #Test running which start celix and run CppUTest RUN_ALL_TESTS. #Using this test running it is possible to create bundles containing CppUTests. - include_directories(celix_test_runner) - include_directories(SYSTEM ${CPPUTEST_INCLUDE_DIRS}) + include_directories(celix_test_runner) + include_directories(SYSTEM ${CPPUTEST_INCLUDE_DIRS}) add_executable(celix_test_runner - private/src/celix_test_runner.cpp + src/celix_test_runner.cpp ) set_target_properties(celix_test_runner PROPERTIES "INSTALL_RPATH" "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") - target_link_libraries(celix_test_runner - celix_framework - ${CURL_LIBRARIES} + target_link_libraries(celix_test_runner PRIVATE + Celix::framework ${CPPUTEST_LIBRARIES} ${CPPUTEST_EXT_LIBRARIES} ) http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/launcher/private/src/celix_test_runner.cpp ---------------------------------------------------------------------- diff --git a/launcher/private/src/celix_test_runner.cpp b/launcher/private/src/celix_test_runner.cpp deleted file mode 100644 index 1855e9f..0000000 --- a/launcher/private/src/celix_test_runner.cpp +++ /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. - */ - - -#include - -#include "celix_launcher.h" - -#include - -static void shutdown_framework(int signal); -static void ignore(int signal); - -#define DEFAULT_CONFIG_FILE "config.properties" - -static framework_pt framework = NULL; - -int main(int argc, char *argv[]) { - // Perform some minimal command-line option parsing... - const char *cfg = DEFAULT_CONFIG_FILE; - - // Set signal handler - (void) signal(SIGINT, shutdown_framework); - (void) signal(SIGUSR1, ignore); - (void) signal(SIGUSR2, ignore); - - int rc = celixLauncher_launch(cfg, &framework); - if (rc != 0) { - printf("Error starting Celix\n"); - } - - if (rc == 0 && framework != NULL) { - rc = RUN_ALL_TESTS(argc, argv); - - celixLauncher_stop(framework); - celixLauncher_waitForShutdown(framework); - celixLauncher_destroy(framework); - } - - if (rc != 0) { - printf("*** FAILURE ***\n"); - } else { - printf("*** SUCCESS ***\n"); - } - - return rc; -} - -static void shutdown_framework(int __attribute__((unused)) signal) { - if (framework != NULL) { - celixLauncher_stop(framework); //NOTE main thread will destroy - } -} - -static void ignore(int __attribute__((unused)) signal) { - //ignoring for signal SIGUSR1, SIGUSR2. Can be used to interrupt sleep, etc -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/launcher/private/src/main.c ---------------------------------------------------------------------- diff --git a/launcher/private/src/main.c b/launcher/private/src/main.c deleted file mode 100644 index bd26e8b..0000000 --- a/launcher/private/src/main.c +++ /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/a1c30887/launcher/src/celix_test_runner.cpp ---------------------------------------------------------------------- diff --git a/launcher/src/celix_test_runner.cpp b/launcher/src/celix_test_runner.cpp new file mode 100644 index 0000000..1855e9f --- /dev/null +++ b/launcher/src/celix_test_runner.cpp @@ -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. + */ + + +#include + +#include "celix_launcher.h" + +#include + +static void shutdown_framework(int signal); +static void ignore(int signal); + +#define DEFAULT_CONFIG_FILE "config.properties" + +static framework_pt framework = NULL; + +int main(int argc, char *argv[]) { + // Perform some minimal command-line option parsing... + const char *cfg = DEFAULT_CONFIG_FILE; + + // Set signal handler + (void) signal(SIGINT, shutdown_framework); + (void) signal(SIGUSR1, ignore); + (void) signal(SIGUSR2, ignore); + + int rc = celixLauncher_launch(cfg, &framework); + if (rc != 0) { + printf("Error starting Celix\n"); + } + + if (rc == 0 && framework != NULL) { + rc = RUN_ALL_TESTS(argc, argv); + + celixLauncher_stop(framework); + celixLauncher_waitForShutdown(framework); + celixLauncher_destroy(framework); + } + + if (rc != 0) { + printf("*** FAILURE ***\n"); + } else { + printf("*** SUCCESS ***\n"); + } + + return rc; +} + +static void shutdown_framework(int __attribute__((unused)) signal) { + if (framework != NULL) { + celixLauncher_stop(framework); //NOTE main thread will destroy + } +} + +static void ignore(int __attribute__((unused)) signal) { + //ignoring for signal SIGUSR1, SIGUSR2. Can be used to interrupt sleep, etc +} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/launcher/src/main.c ---------------------------------------------------------------------- diff --git a/launcher/src/main.c b/launcher/src/main.c new file mode 100644 index 0000000..bd26e8b --- /dev/null +++ b/launcher/src/main.c @@ -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. + */ + +#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/a1c30887/log_service/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/log_service/CMakeLists.txt b/log_service/CMakeLists.txt index 131a986..b9af374 100644 --- a/log_service/CMakeLists.txt +++ b/log_service/CMakeLists.txt @@ -18,37 +18,40 @@ 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 include) + + add_library(log_helper STATIC src/log_helper.c) + target_include_directories(log_helper PUBLIC loghelper_include) + target_link_libraries(log_helper PUBLIC Celix::framework log_service_api) + #TODO install log helper + add_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 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/a1c30887/log_service/README.md ---------------------------------------------------------------------- diff --git a/log_service/README.md b/log_service/README.md index 32ee520..384a00e 100644 --- a/log_service/README.md +++ b/log_service/README.md @@ -1,12 +1,19 @@ -## Log Service +# Log Service The Celix Log Service realizes an adapted implementation of the OSGi Compendium Log Service. This is a very simple implementation which only stores the log in memory. It can be combined with one of the available Log Writers to forward the buffered entries to e.g. stdout or syslog. To ease the use of the Log Service, the [Log Helper](public/include/log_helper.h) can be used. It wraps and therefore simplifies the log service usage. -###### Properties +## Properties LOGHELPER_ENABLE_STDOUT_FALLBACK If set to any value and in case no Log Service is found the logs are still printed on stdout. -###### CMake option +## CMake option BUILD_LOG_SERVICE=ON + +## Using info + +If the Celix Log Service is installed The `FindCelix.cmake` will set: + - The `Celix::log_service_api` interface (i.e. header only) library target + - The `Celix::log_service` bundle target + - The `Celix::log_helper` static library target http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/log_service/include/log_entry.h ---------------------------------------------------------------------- diff --git a/log_service/include/log_entry.h b/log_service/include/log_entry.h new file mode 100644 index 0000000..e588774 --- /dev/null +++ b/log_service/include/log_entry.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. + */ +/* + * log_entry.h + * + * \date Jun 26, 2011 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ + +#ifndef LOG_ENTRY_H_ +#define LOG_ENTRY_H_ + +#include "log_service.h" + +struct log_entry { + int errorCode; + log_level_t level; + char *message; + time_t time; + + long bundleId; + char* bundleSymbolicName; +}; + +typedef struct log_entry * log_entry_pt; + +celix_status_t logEntry_create(long bundleId, const char* bundleSymbolicName , service_reference_pt reference, + log_level_t level, char *message, int errorCode, + log_entry_pt *entry); +celix_status_t logEntry_destroy(log_entry_pt *entry); +celix_status_t logEntry_getBundleSymbolicName(log_entry_pt entry, const char** bundleSymbolicName); +celix_status_t logEntry_getBundleId(log_entry_pt entry, long *bundleId); +celix_status_t logEntry_getErrorCode(log_entry_pt entry, int *errorCode); +celix_status_t logEntry_getLevel(log_entry_pt entry, log_level_t *level); +celix_status_t logEntry_getMessage(log_entry_pt entry, const char** message); +celix_status_t logEntry_getTime(log_entry_pt entry, time_t *time); + +#endif /* LOG_ENTRY_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/log_service/include/log_listener.h ---------------------------------------------------------------------- diff --git a/log_service/include/log_listener.h b/log_service/include/log_listener.h new file mode 100644 index 0000000..b726994 --- /dev/null +++ b/log_service/include/log_listener.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. + */ +/* + * log_listener.h + * + * \date Jul 4, 2011 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ + +#ifndef LOG_LISTENER_H_ +#define LOG_LISTENER_H_ + +#include "log_entry.h" +#include "celix_errno.h" + +struct log_listener { + void *handle; + celix_status_t (*logged)(struct log_listener *listener, log_entry_pt entry); +}; + +typedef struct log_listener log_listener_t; +typedef log_listener_t* log_listener_pt; + +celix_status_t logListener_logged(log_listener_pt listener, log_entry_pt entry); + +#endif /* LOG_LISTENER_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/log_service/include/log_reader_service.h ---------------------------------------------------------------------- diff --git a/log_service/include/log_reader_service.h b/log_service/include/log_reader_service.h new file mode 100644 index 0000000..6815123 --- /dev/null +++ b/log_service/include/log_reader_service.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. + */ +/* + * log_reader_service.h + * + * \date Jun 26, 2011 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ + +#ifndef LOG_READER_SERVICE_H_ +#define LOG_READER_SERVICE_H_ + + +#include "celix_errno.h" +#include "linked_list.h" +#include "log_listener.h" + +static const char * const OSGI_LOGSERVICE_READER_SERVICE_NAME = "log_reader_service"; + +typedef struct log_reader_data log_reader_data_t; +typedef log_reader_data_t* log_reader_data_pt; + +struct log_reader_service { + log_reader_data_pt reader; + celix_status_t (*getLog)(log_reader_data_pt reader, linked_list_pt *list); + celix_status_t (*addLogListener)(log_reader_data_pt reader, log_listener_pt listener); + celix_status_t (*removeLogListener)(log_reader_data_pt reader, log_listener_pt listener); + celix_status_t (*removeAllLogListener)(log_reader_data_pt reader); +}; + +typedef struct log_reader_service * log_reader_service_pt; + +#endif /* LOG_READER_SERVICE_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/log_service/include/log_service.h ---------------------------------------------------------------------- diff --git a/log_service/include/log_service.h b/log_service/include/log_service.h new file mode 100644 index 0000000..2691e35 --- /dev/null +++ b/log_service/include/log_service.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. + */ +/* + * log_service.h + * + * \date Jun 22, 2011 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ + +#ifndef LOG_SERVICE_H_ +#define LOG_SERVICE_H_ + +#include "celix_errno.h" +#include "service_reference.h" + +static const char * const OSGI_LOGSERVICE_NAME = "log_service"; + +typedef struct log_service_data *log_service_data_pt; + +enum log_level +{ + OSGI_LOGSERVICE_ERROR = 0x00000001, + OSGI_LOGSERVICE_WARNING = 0x00000002, + OSGI_LOGSERVICE_INFO = 0x00000003, + OSGI_LOGSERVICE_DEBUG = 0x00000004, +}; + +typedef enum log_level log_level_t; + +struct log_service { + log_service_data_pt logger; + celix_status_t (*log)(log_service_data_pt logger, log_level_t level, char * message); + celix_status_t (*logSr)(log_service_data_pt logger, service_reference_pt reference, log_level_t level, char * message); +}; + +typedef struct log_service log_service_t; +typedef log_service_t* log_service_pt; + + + +#endif /* LOG_SERVICE_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/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 new file mode 100644 index 0000000..04e4bb2 --- /dev/null +++ b/log_service/loghelper_include/log_helper.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 LOGHELPER_H_ +#define LOGHELPER_H_ + +#include "bundle_context.h" +#include "log_service.h" + +typedef struct log_helper* log_helper_pt; + +celix_status_t logHelper_create(bundle_context_pt context, log_helper_pt* log_helper); +celix_status_t logHelper_start(log_helper_pt loghelper); +celix_status_t logHelper_stop(log_helper_pt loghelper); +celix_status_t logHelper_destroy(log_helper_pt* loghelper); +celix_status_t logHelper_log(log_helper_pt loghelper, log_level_t level, char* message, ... ); + +#endif /* LOGHELPER_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/log_service/private/include/log.h ---------------------------------------------------------------------- diff --git a/log_service/private/include/log.h b/log_service/private/include/log.h deleted file mode 100644 index e0d7b87..0000000 --- a/log_service/private/include/log.h +++ /dev/null @@ -1,48 +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. - */ -/* - * log.h - * - * \date Jun 26, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef LOG_H_ -#define LOG_H_ - -#include "linked_list.h" -#include "log_entry.h" -#include "log_listener.h" - -typedef struct log * log_pt; - -celix_status_t log_create(int max_size, bool store_debug, log_pt *logger); -celix_status_t log_destroy(log_pt logger); -celix_status_t log_addEntry(log_pt log, log_entry_pt entry); -celix_status_t log_getEntries(log_pt log, linked_list_pt *list); - -celix_status_t log_bundleChanged(void *listener, bundle_event_pt event); -celix_status_t log_frameworkEvent(void *listener, framework_event_pt event); - -celix_status_t log_addLogListener(log_pt logger, log_listener_pt listener); -celix_status_t log_removeLogListener(log_pt logger, log_listener_pt listener); -celix_status_t log_removeAllLogListener(log_pt logger); - -#endif /* LOG_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/log_service/private/include/log_factory.h ---------------------------------------------------------------------- diff --git a/log_service/private/include/log_factory.h b/log_service/private/include/log_factory.h deleted file mode 100644 index 8ebe5f8..0000000 --- a/log_service/private/include/log_factory.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. - */ -/* - * log_factory.h - * - * \date Jun 26, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef LOG_FACTORY_H_ -#define LOG_FACTORY_H_ - -#include "log.h" - -typedef struct log_service_factory * log_service_factory_pt; - -celix_status_t logFactory_create(log_pt log, service_factory_pt *factory); -celix_status_t logFactory_destroy(service_factory_pt *factory); -celix_status_t logFactory_getService(void *factory, bundle_pt bundle, service_registration_pt registration, void **service); -celix_status_t logFactory_ungetService(void *factory, bundle_pt bundle, service_registration_pt registration, void **service); - - -#endif /* LOG_FACTORY_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/log_service/private/include/log_reader_service_impl.h ---------------------------------------------------------------------- diff --git a/log_service/private/include/log_reader_service_impl.h b/log_service/private/include/log_reader_service_impl.h deleted file mode 100644 index 71829f2..0000000 --- a/log_service/private/include/log_reader_service_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. - */ -/* - * log_reader_service_impl.h - * - * \date Jun 26, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef LOG_READER_SERVICE_IMPL_H_ -#define LOG_READER_SERVICE_IMPL_H_ - -#include "log_reader_service.h" -#include "log.h" - -celix_status_t logReaderService_create(log_pt log, log_reader_data_pt *reader); -celix_status_t logReaderService_destroy(log_reader_data_pt *reader); - -celix_status_t logReaderService_getLog(log_reader_data_pt reader, linked_list_pt *list); - -celix_status_t logReaderService_addLogListener(log_reader_data_pt reader, log_listener_pt listener); -celix_status_t logReaderService_removeLogListener(log_reader_data_pt reader, log_listener_pt listener); -celix_status_t logReaderService_removeAllLogListener(log_reader_data_pt reader); - - -#endif /* LOG_READER_SERVICE_IMPL_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/log_service/private/include/log_service_impl.h ---------------------------------------------------------------------- diff --git a/log_service/private/include/log_service_impl.h b/log_service/private/include/log_service_impl.h deleted file mode 100644 index 04c986e..0000000 --- a/log_service/private/include/log_service_impl.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. - */ -/* - * log_service_impl.h - * - * \date Jun 22, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef LOG_SERVICE_IMPL_H_ -#define LOG_SERVICE_IMPL_H_ - -#include "log_service.h" -#include "log.h" - -celix_status_t logService_create(log_pt log, bundle_pt bundle, log_service_data_pt *logger); -celix_status_t logService_destroy(log_service_data_pt *logger); -celix_status_t logService_log(log_service_data_pt logger, log_level_t level, char * message); -celix_status_t logService_logSr(log_service_data_pt logger, service_reference_pt reference, log_level_t level, char * message); - - -#endif /* LOG_SERVICE_IMPL_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/log_service/private/src/log.c ---------------------------------------------------------------------- diff --git a/log_service/private/src/log.c b/log_service/private/src/log.c deleted file mode 100644 index 5b29318..0000000 --- a/log_service/private/src/log.c +++ /dev/null @@ -1,375 +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. - */ -/* - * log.c - * - * \date Jun 26, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ -#include - -#include "log.h" -#include "linked_list_iterator.h" -#include "array_list.h" - -struct log { - linked_list_pt entries; - celix_thread_mutex_t lock; - - array_list_pt listeners; - array_list_pt listenerEntries; - - celix_thread_t listenerThread; - bool running; - - celix_thread_cond_t entriesToDeliver; - celix_thread_mutex_t deliverLock; - celix_thread_mutex_t listenerLock; - - int max_size; - bool store_debug; -}; - -static celix_status_t log_startListenerThread(log_pt logger); -static celix_status_t log_stopListenerThread(log_pt logger); - - -static void *log_listenerThread(void *data); - -celix_status_t log_create(int max_size, bool store_debug, log_pt *logger) { - celix_status_t status = CELIX_ENOMEM; - - *logger = calloc(1, sizeof(**logger)); - - if (*logger != NULL) { - linkedList_create(&(*logger)->entries); - - status = celixThreadMutex_create(&(*logger)->lock, NULL); - - (*logger)->listeners = NULL; - (*logger)->listenerEntries = NULL; - (*logger)->listenerThread = celix_thread_default; - (*logger)->running = false; - - (*logger)->max_size = max_size; - (*logger)->store_debug = store_debug; - - arrayList_create(&(*logger)->listeners); - arrayList_create(&(*logger)->listenerEntries); - - if (celixThreadCondition_init(&(*logger)->entriesToDeliver, NULL) != CELIX_SUCCESS) { - status = CELIX_INVALID_SYNTAX; - } - else if (celixThreadMutex_create(&(*logger)->deliverLock, NULL) != CELIX_SUCCESS) { - status = CELIX_INVALID_SYNTAX; - } - else if (celixThreadMutex_create(&(*logger)->listenerLock, NULL) != CELIX_SUCCESS) { - status = CELIX_INVALID_SYNTAX; - } - else { - status = CELIX_SUCCESS; - } - } - - return status; -} - -celix_status_t log_destroy(log_pt logger) { - celix_status_t status = CELIX_SUCCESS; - - celixThreadMutex_destroy(&logger->listenerLock); - celixThreadMutex_destroy(&logger->deliverLock); - celixThreadCondition_destroy(&logger->entriesToDeliver); - - arrayList_destroy(logger->listeners); - linked_list_iterator_pt iter = linkedListIterator_create(logger->entries, 0); - while (linkedListIterator_hasNext(iter)) { - log_entry_pt entry = linkedListIterator_next(iter); - if (arrayList_contains(logger->listenerEntries, entry)) { - arrayList_removeElement(logger->listenerEntries, entry); - } - logEntry_destroy(&entry); - } - linkedListIterator_destroy(iter); - - array_list_iterator_pt entryIter = arrayListIterator_create(logger->listenerEntries); - - while (arrayListIterator_hasNext(entryIter)) { - log_entry_pt entry = arrayListIterator_next(entryIter); - logEntry_destroy(&entry); - } - arrayListIterator_destroy(entryIter); - - arrayList_destroy(logger->listenerEntries); - linkedList_destroy(logger->entries); - - celixThreadMutex_destroy(&logger->lock); - - free(logger); - - return status; -} - -celix_status_t log_addEntry(log_pt log, log_entry_pt entry) { - celixThreadMutex_lock(&log->lock); - - if (log->max_size != 0) { - if (log->store_debug || entry->level != OSGI_LOGSERVICE_DEBUG) { - linkedList_addElement(log->entries, entry); - } - } - - celixThreadMutex_lock(&log->deliverLock); - arrayList_add(log->listenerEntries, entry); - celixThreadMutex_unlock(&log->deliverLock); - - celixThreadCondition_signal(&log->entriesToDeliver); - - if (log->max_size != 0) { - if (log->max_size != -1) { - if (linkedList_size(log->entries) > log->max_size) { - log_entry_pt rentry = linkedList_removeFirst(log->entries); - if (rentry) { - celixThreadMutex_lock(&log->deliverLock); - arrayList_removeElement(log->listenerEntries, rentry); - logEntry_destroy(&rentry); - celixThreadMutex_unlock(&log->deliverLock); - } - } - } - } - - celixThreadMutex_unlock(&log->lock); - - return CELIX_SUCCESS; -} - -celix_status_t log_getEntries(log_pt log, linked_list_pt *list) { - linked_list_pt entries = NULL; - if (linkedList_create(&entries) == CELIX_SUCCESS) { - linked_list_iterator_pt iter = NULL; - - celixThreadMutex_lock(&log->lock); - - iter = linkedListIterator_create(log->entries, 0); - while (linkedListIterator_hasNext(iter)) { - linkedList_addElement(entries, linkedListIterator_next(iter)); - } - linkedListIterator_destroy(iter); - - *list = entries; - - celixThreadMutex_unlock(&log->lock); - - return CELIX_SUCCESS; - } else { - return CELIX_ENOMEM; - } -} - -celix_status_t log_bundleChanged(void *listener, bundle_event_pt event) { - celix_status_t status = CELIX_SUCCESS; - log_pt logger = ((bundle_listener_pt) listener)->handle; - log_entry_pt entry = NULL; - - int messagesLength = 10; - char *messages[] = { - "BUNDLE_EVENT_INSTALLED", - "BUNDLE_EVENT_STARTED", - "BUNDLE_EVENT_STOPPED", - "BUNDLE_EVENT_UPDATED", - "BUNDLE_EVENT_UNINSTALLED", - "BUNDLE_EVENT_RESOLVED", - "BUNDLE_EVENT_UNRESOLVED", - "BUNDLE_EVENT_STARTING", - "BUNDLE_EVENT_STOPPING", - "BUNDLE_EVENT_LAZY_ACTIVATION" - }; - - char *message = NULL; - int i = 0; - for (i = 0; i < messagesLength; i++) { - if (event->type >> i == 1) { - message = messages[i]; - } - } - - if (message != NULL) { - status = logEntry_create(event->bundleId, event->bundleSymbolicName, NULL, OSGI_LOGSERVICE_INFO, message, 0, &entry); - if (status == CELIX_SUCCESS) { - status = log_addEntry(logger, entry); - } - } - - return status; -} - -celix_status_t log_frameworkEvent(void *listener, framework_event_pt event) { - celix_status_t status; - log_pt logger = ((framework_listener_pt) listener)->handle; - log_entry_pt entry = NULL; - - status = logEntry_create(event->bundleId, event->bundleSymbolicName, NULL, (event->type == OSGI_FRAMEWORK_EVENT_ERROR) ? OSGI_LOGSERVICE_ERROR : OSGI_LOGSERVICE_INFO, event->error, event->errorCode, &entry); - if (status == CELIX_SUCCESS) { - status = log_addEntry(logger, entry); - } - - return status; -} - -celix_status_t log_addLogListener(log_pt logger, log_listener_pt listener) { - celix_status_t status; - - status = celixThreadMutex_lock(&logger->listenerLock); - - if (status == CELIX_SUCCESS) { - arrayList_add(logger->listeners, listener); - log_startListenerThread(logger); - - status = celixThreadMutex_unlock(&logger->listenerLock); - } - - return status; -} - -celix_status_t log_removeLogListener(log_pt logger, log_listener_pt listener) { - celix_status_t status = CELIX_SUCCESS; - - status += celixThreadMutex_lock(&logger->deliverLock); - status += celixThreadMutex_lock(&logger->listenerLock); - - if (status == CELIX_SUCCESS) { - bool last = false; - - arrayList_removeElement(logger->listeners, listener); - if (arrayList_size(logger->listeners) == 0) { - status = log_stopListenerThread(logger); - last = true; - } - - status += celixThreadMutex_unlock(&logger->listenerLock); - status += celixThreadMutex_unlock(&logger->deliverLock); - - if (last) { - status += celixThread_join(logger->listenerThread, NULL); - } - } - - if (status != CELIX_SUCCESS) { - status = CELIX_SERVICE_EXCEPTION; - } - - return status; -} - -celix_status_t log_removeAllLogListener(log_pt logger) { - celix_status_t status; - - status = celixThreadMutex_lock(&logger->listenerLock); - - if (status == CELIX_SUCCESS) { - arrayList_clear(logger->listeners); - - status = celixThreadMutex_unlock(&logger->listenerLock); - } - - return status; -} - -static celix_status_t log_startListenerThread(log_pt logger) { - celix_status_t status; - - logger->running = true; - logger->running = true; - status = celixThread_create(&logger->listenerThread, NULL, log_listenerThread, logger); - - return status; -} - -static celix_status_t log_stopListenerThread(log_pt logger) { - celix_status_t status; - - logger->running = false; - - status = celixThreadCondition_signal(&logger->entriesToDeliver); - - return status; -} - -static void * log_listenerThread(void *data) { - celix_status_t status = CELIX_SUCCESS; - - log_pt logger = data; - - while (logger->running) { - - status = celixThreadMutex_lock(&logger->deliverLock); - - if ( status != CELIX_SUCCESS) { - logger->running = false; - } - else { - if (!arrayList_isEmpty(logger->listenerEntries)) { - log_entry_pt entry = (log_entry_pt) arrayList_remove(logger->listenerEntries, 0); - - if (entry) { - status = celixThreadMutex_lock(&logger->listenerLock); - if (status != CELIX_SUCCESS) { - logger->running = false; - break; - } else { - array_list_iterator_pt it = arrayListIterator_create(logger->listeners); - while (arrayListIterator_hasNext(it)) { - log_listener_pt listener = arrayListIterator_next(it); - listener->logged(listener, entry); - } - arrayListIterator_destroy(it); - - // destroy not-stored entries - if (!(logger->store_debug || entry->level != OSGI_LOGSERVICE_DEBUG)) { - logEntry_destroy(&entry); - } - - status = celixThreadMutex_unlock(&logger->listenerLock); - if (status != CELIX_SUCCESS) { - logger->running = false; - break; - } - } - } - } - - if (arrayList_isEmpty(logger->listenerEntries) && logger->running) { - celixThreadCondition_wait(&logger->entriesToDeliver, &logger->deliverLock); - } - - status = celixThreadMutex_unlock(&logger->deliverLock); - - if (status != CELIX_SUCCESS) { - logger->running = false; - break; - } - } - - } - - celixThread_exit(NULL); - return NULL; -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/log_service/private/src/log_entry.c ---------------------------------------------------------------------- diff --git a/log_service/private/src/log_entry.c b/log_service/private/src/log_entry.c deleted file mode 100644 index 3a8603a..0000000 --- a/log_service/private/src/log_entry.c +++ /dev/null @@ -1,94 +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. - */ -/* - * log_entry.c - * - * \date Jun 26, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include -#include -#include - -#include "celix_errno.h" -#include "log_service.h" -#include "log_entry.h" - -celix_status_t logEntry_create(long bundleId, const char* bundleSymbolicName , service_reference_pt reference, - log_level_t level, char *message, int errorCode, - log_entry_pt *entry) { - celix_status_t status = CELIX_SUCCESS; - - *entry = malloc(sizeof(**entry)); - if (*entry == NULL) { - status = CELIX_ENOMEM; - } else { - (*entry)->level = level; - (*entry)->message = strdup(message); - (*entry)->errorCode = errorCode; - (*entry)->time = time(NULL); - - (*entry)->bundleSymbolicName = strdup(bundleSymbolicName); - (*entry)->bundleId = bundleId; - } - - return status; -} - -celix_status_t logEntry_destroy(log_entry_pt *entry) { - if (*entry) { - free((*entry)->bundleSymbolicName); - free((*entry)->message); - free(*entry); - *entry = NULL; - } - return CELIX_SUCCESS; -} - -celix_status_t logEntry_getBundleSymbolicName(log_entry_pt entry, const char** bundleSymbolicName) { - *bundleSymbolicName = entry->bundleSymbolicName; - return CELIX_SUCCESS; -} - -celix_status_t logEntry_getBundleId(log_entry_pt entry, long *bundleId) { - *bundleId = entry->bundleId; - return CELIX_SUCCESS; -} - -celix_status_t logEntry_getErrorCode(log_entry_pt entry, int *errorCode) { - *errorCode = entry->errorCode; - return CELIX_SUCCESS; -} - -celix_status_t logEntry_getLevel(log_entry_pt entry, log_level_t *level) { - *level = entry->level; - return CELIX_SUCCESS; -} - -celix_status_t logEntry_getMessage(log_entry_pt entry, const char **message) { - *message = entry->message; - return CELIX_SUCCESS; -} - -celix_status_t logEntry_getTime(log_entry_pt entry, time_t *time) { - *time = entry->time; - return CELIX_SUCCESS; -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/log_service/private/src/log_factory.c ---------------------------------------------------------------------- diff --git a/log_service/private/src/log_factory.c b/log_service/private/src/log_factory.c deleted file mode 100644 index 1c0a17a..0000000 --- a/log_service/private/src/log_factory.c +++ /dev/null @@ -1,100 +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. - */ -/* - * log_factory.c - * - * \date Jun 26, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include -#include - - -#include "service_factory.h" -#include "log_factory.h" -#include "log_service_impl.h" - -struct log_service_factory { - log_pt log; -}; - -celix_status_t logFactory_create(log_pt log, service_factory_pt *factory) { - celix_status_t status = CELIX_SUCCESS; - - *factory = calloc(1, sizeof(**factory)); - if (*factory == NULL) { - status = CELIX_ENOMEM; - } else { - log_service_factory_pt factoryData = calloc(1, sizeof(*factoryData)); - if (factoryData == NULL) { - status = CELIX_ENOMEM; - } else { - factoryData->log = log; - - (*factory)->handle = factoryData; - (*factory)->getService = logFactory_getService; - (*factory)->ungetService = logFactory_ungetService; - } - } - - return status; -} - -celix_status_t logFactory_destroy(service_factory_pt *factory) { - celix_status_t status = CELIX_SUCCESS; - - - free((*factory)->handle); - free(*factory); - - factory = NULL; - - return status; -} - - -celix_status_t logFactory_getService(void *factory, bundle_pt bundle, service_registration_pt registration, void **service) { - log_service_factory_pt log_factory = factory; - log_service_pt log_service = NULL; - log_service_data_pt log_service_data = NULL; - - logService_create(log_factory->log, bundle, &log_service_data); - - log_service = calloc(1, sizeof(*log_service)); - log_service->logger = log_service_data; - log_service->log = logService_log; - // log_service->logSr = logService_logSr; - - (*service) = log_service; - - return CELIX_SUCCESS; -} - -celix_status_t logFactory_ungetService(void *factory, bundle_pt bundle, service_registration_pt registration, void **service) { - log_service_pt log_service = *service; - - logService_destroy(&log_service->logger); - - free(*service); - *service = NULL; - - return CELIX_SUCCESS; -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/log_service/private/src/log_reader_service_impl.c ---------------------------------------------------------------------- diff --git a/log_service/private/src/log_reader_service_impl.c b/log_service/private/src/log_reader_service_impl.c deleted file mode 100644 index 2a46ea7..0000000 --- a/log_service/private/src/log_reader_service_impl.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. - */ - /* - * log_reader_service_impl.c - * - * \date Jun 26, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include -#include - -#include "log_reader_service_impl.h" -#include "celixbool.h" - -struct log_reader_data { - log_pt log; -}; - -celix_status_t logReaderService_create(log_pt log, log_reader_data_pt *reader) { - celix_status_t status = CELIX_SUCCESS; - - *reader = (log_reader_data_pt) calloc(1, sizeof(**reader)); - - if (*reader == NULL) { - status = CELIX_ENOMEM; - } else { - (*reader)->log = log; - } - - return status; -} - -celix_status_t logReaderService_destroy(log_reader_data_pt *reader) { - celix_status_t status = CELIX_SUCCESS; - - free(*reader); - reader = NULL; - - return status; -} - - - -celix_status_t logReaderService_getLog(log_reader_data_pt reader, linked_list_pt *list) { - celix_status_t status = CELIX_SUCCESS; - - status = log_getEntries(reader->log, list); - - return status; -} - -celix_status_t logReaderService_addLogListener(log_reader_data_pt reader, log_listener_pt listener) { - return log_addLogListener(reader->log, listener); -} - -celix_status_t logReaderService_removeLogListener(log_reader_data_pt reader, log_listener_pt listener) { - return log_removeLogListener(reader->log, listener); -} - -celix_status_t logReaderService_removeAllLogListener(log_reader_data_pt reader) { - return log_removeAllLogListener(reader->log); -} - - http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/log_service/private/src/log_service_activator.c ---------------------------------------------------------------------- diff --git a/log_service/private/src/log_service_activator.c b/log_service/private/src/log_service_activator.c deleted file mode 100644 index 8c72fb1..0000000 --- a/log_service/private/src/log_service_activator.c +++ /dev/null @@ -1,198 +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. - */ -/* - * log_service_activator.c - * - * \date Jun 25, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include -#include -#include - -#include "bundle_activator.h" -#include "log_service_impl.h" -#include "service_factory.h" -#include "log_factory.h" -#include "log.h" -#include "log_reader_service_impl.h" -#include "service_registration.h" - -#define DEFAULT_MAX_SIZE 100 -#define DEFAULT_STORE_DEBUG false - -#define MAX_SIZE_PROPERTY "CELIX_LOG_MAX_SIZE" -#define STORE_DEBUG_PROPERTY "CELIX_LOG_STORE_DEBUG" - -struct logActivator { - bundle_context_pt bundleContext; - service_registration_pt logServiceFactoryReg; - service_registration_pt logReaderServiceReg; - - bundle_listener_pt bundleListener; - framework_listener_pt frameworkListener; - - log_pt logger; - service_factory_pt factory; - log_reader_data_pt reader; - log_reader_service_pt reader_service; -}; - -static celix_status_t bundleActivator_getMaxSize(struct logActivator *activator, int *max_size); -static celix_status_t bundleActivator_getStoreDebug(struct logActivator *activator, bool *store_debug); - -celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) { - celix_status_t status = CELIX_SUCCESS; - struct logActivator * activator = NULL; - - activator = (struct logActivator *) calloc(1, sizeof(struct logActivator)); - - if (activator == NULL) { - status = CELIX_ENOMEM; - } else { - activator->bundleContext = context; - activator->logServiceFactoryReg = NULL; - activator->logReaderServiceReg = NULL; - - activator->logger = NULL; - activator->factory = NULL; - activator->reader = NULL; - activator->reader_service = NULL; - - *userData = activator; - } - - return status; -} - -celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { - struct logActivator * activator = (struct logActivator *) userData; - celix_status_t status = CELIX_SUCCESS; - - int max_size = 0; - bool store_debug = false; - - bundleActivator_getMaxSize(activator, &max_size); - bundleActivator_getStoreDebug(activator, &store_debug); - - log_create(max_size, store_debug, &activator->logger); - - // Add logger as Bundle- and FrameworkEvent listener - activator->bundleListener = calloc(1, sizeof(*activator->bundleListener)); - activator->bundleListener->handle = activator->logger; - activator->bundleListener->bundleChanged = log_bundleChanged; - bundleContext_addBundleListener(context, activator->bundleListener); - - activator->frameworkListener = calloc(1, sizeof(*activator->frameworkListener)); - activator->frameworkListener->handle = activator->logger; - activator->frameworkListener->frameworkEvent = log_frameworkEvent; - bundleContext_addFrameworkListener(context, activator->frameworkListener); - - logFactory_create(activator->logger, &activator->factory); - - properties_pt props = properties_create(); - properties_set(props, CELIX_FRAMEWORK_SERVICE_LANGUAGE, CELIX_FRAMEWORK_SERVICE_C_LANGUAGE); - - - bundleContext_registerServiceFactory(context, (char *) OSGI_LOGSERVICE_NAME, activator->factory, props, &activator->logServiceFactoryReg); - - logReaderService_create(activator->logger, &activator->reader); - - activator->reader_service = calloc(1, sizeof(*activator->reader_service)); - activator->reader_service->reader = activator->reader; - activator->reader_service->getLog = logReaderService_getLog; - activator->reader_service->addLogListener = logReaderService_addLogListener; - activator->reader_service->removeLogListener = logReaderService_removeLogListener; - activator->reader_service->removeAllLogListener = logReaderService_removeAllLogListener; - - props = properties_create(); - properties_set(props, CELIX_FRAMEWORK_SERVICE_LANGUAGE, CELIX_FRAMEWORK_SERVICE_C_LANGUAGE); - - bundleContext_registerService(context, (char *) OSGI_LOGSERVICE_READER_SERVICE_NAME, activator->reader_service, props, &activator->logReaderServiceReg); - - return status; -} - -celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) { - struct logActivator * activator = (struct logActivator *) userData; - - serviceRegistration_unregister(activator->logReaderServiceReg); - activator->logReaderServiceReg = NULL; - serviceRegistration_unregister(activator->logServiceFactoryReg); - activator->logServiceFactoryReg = NULL; - - logReaderService_destroy(&activator->reader); - free(activator->reader_service); - - logFactory_destroy(&activator->factory); - - bundleContext_removeBundleListener(context, activator->bundleListener); - bundleContext_removeFrameworkListener(context, activator->frameworkListener); - - free(activator->bundleListener); - free(activator->frameworkListener); - - log_destroy(activator->logger); - - return CELIX_SUCCESS; -} - -celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) { - struct logActivator * activator = (struct logActivator *) userData; - - free(activator); - - return CELIX_SUCCESS; -} - -static celix_status_t bundleActivator_getMaxSize(struct logActivator *activator, int *max_size) { - celix_status_t status = CELIX_SUCCESS; - - const char *max_size_str = NULL; - - *max_size = DEFAULT_MAX_SIZE; - - bundleContext_getProperty(activator->bundleContext, MAX_SIZE_PROPERTY, &max_size_str); - if (max_size_str) { - *max_size = atoi(max_size_str); - } - - return status; -} - -static celix_status_t bundleActivator_getStoreDebug(struct logActivator *activator, bool *store_debug) { - celix_status_t status = CELIX_SUCCESS; - - const char *store_debug_str = NULL; - - *store_debug = DEFAULT_STORE_DEBUG; - - bundleContext_getProperty(activator->bundleContext, STORE_DEBUG_PROPERTY, &store_debug_str); - if (store_debug_str) { - if (strcasecmp(store_debug_str, "true") == 0) { - *store_debug = true; - } else if (strcasecmp(store_debug_str, "false") == 0) { - *store_debug = false; - } - } - - return status; -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/log_service/private/src/log_service_impl.c ---------------------------------------------------------------------- diff --git a/log_service/private/src/log_service_impl.c b/log_service/private/src/log_service_impl.c deleted file mode 100644 index a77e9ad..0000000 --- a/log_service/private/src/log_service_impl.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. - */ -/* - * log_service_impl.c - * - * \date Jun 22, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ -#include - -#include "log_service_impl.h" -#include "module.h" -#include "bundle.h" - -struct log_service_data { - log_pt log; - bundle_pt bundle; -}; - -celix_status_t logService_create(log_pt log, bundle_pt bundle, log_service_data_pt *logger) { - celix_status_t status = CELIX_SUCCESS; - *logger = calloc(1, sizeof(struct log_service_data)); - if (*logger == NULL) { - status = CELIX_ENOMEM; - } else { - (*logger)->bundle = bundle; - (*logger)->log = log; - } - - return status; -} - -celix_status_t logService_destroy(log_service_data_pt *logger) { - celix_status_t status = CELIX_SUCCESS; - - free(*logger); - logger = NULL; - - return status; -} - -celix_status_t logService_log(log_service_data_pt logger, log_level_t level, char * message) { - return logService_logSr(logger, NULL, level, message); -} - -celix_status_t logService_logSr(log_service_data_pt logger, service_reference_pt reference, log_level_t level, char * message) { - celix_status_t status; - log_entry_pt entry = NULL; - bundle_pt bundle = logger->bundle; - bundle_archive_pt archive = NULL; - module_pt module = NULL; - const char *symbolicName = NULL; - long bundleId = -1; - - if (reference != NULL) { - serviceReference_getBundle(reference, &bundle); - } - - status = bundle_getArchive(bundle, &archive); - - if (status == CELIX_SUCCESS) { - status = bundleArchive_getId(archive, &bundleId); - } - - if (status == CELIX_SUCCESS) { - status = bundle_getCurrentModule(bundle, &module); - - if (status == CELIX_SUCCESS) { - status = module_getSymbolicName(module, &symbolicName); - } - } - - if(status == CELIX_SUCCESS && symbolicName != NULL && message != NULL){ - status = logEntry_create(bundleId, symbolicName, reference, level, message, 0, &entry); - log_addEntry(logger->log, entry); - } - - return status; -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/log_service/public/include/log_entry.h ---------------------------------------------------------------------- diff --git a/log_service/public/include/log_entry.h b/log_service/public/include/log_entry.h deleted file mode 100644 index e588774..0000000 --- a/log_service/public/include/log_entry.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. - */ -/* - * log_entry.h - * - * \date Jun 26, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef LOG_ENTRY_H_ -#define LOG_ENTRY_H_ - -#include "log_service.h" - -struct log_entry { - int errorCode; - log_level_t level; - char *message; - time_t time; - - long bundleId; - char* bundleSymbolicName; -}; - -typedef struct log_entry * log_entry_pt; - -celix_status_t logEntry_create(long bundleId, const char* bundleSymbolicName , service_reference_pt reference, - log_level_t level, char *message, int errorCode, - log_entry_pt *entry); -celix_status_t logEntry_destroy(log_entry_pt *entry); -celix_status_t logEntry_getBundleSymbolicName(log_entry_pt entry, const char** bundleSymbolicName); -celix_status_t logEntry_getBundleId(log_entry_pt entry, long *bundleId); -celix_status_t logEntry_getErrorCode(log_entry_pt entry, int *errorCode); -celix_status_t logEntry_getLevel(log_entry_pt entry, log_level_t *level); -celix_status_t logEntry_getMessage(log_entry_pt entry, const char** message); -celix_status_t logEntry_getTime(log_entry_pt entry, time_t *time); - -#endif /* LOG_ENTRY_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/log_service/public/include/log_helper.h ---------------------------------------------------------------------- diff --git a/log_service/public/include/log_helper.h b/log_service/public/include/log_helper.h deleted file mode 100644 index 04e4bb2..0000000 --- a/log_service/public/include/log_helper.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 LOGHELPER_H_ -#define LOGHELPER_H_ - -#include "bundle_context.h" -#include "log_service.h" - -typedef struct log_helper* log_helper_pt; - -celix_status_t logHelper_create(bundle_context_pt context, log_helper_pt* log_helper); -celix_status_t logHelper_start(log_helper_pt loghelper); -celix_status_t logHelper_stop(log_helper_pt loghelper); -celix_status_t logHelper_destroy(log_helper_pt* loghelper); -celix_status_t logHelper_log(log_helper_pt loghelper, log_level_t level, char* message, ... ); - -#endif /* LOGHELPER_H_ */