summaryrefslogtreecommitdiff
path: root/ivi-layermanagement-examples
diff options
context:
space:
mode:
authorNobuhiko Tanibata <NOBUHIKO_TANIBATA@denso.co.jp>2013-11-27 14:57:46 +0900
committerTimo Lotterbach <timo.lotterbach@bmw-carit.de>2013-11-27 20:59:35 +0100
commit0ca066389f0c7db4c5ceba10a3f01bc4174dc879 (patch)
treed5bd68c162a65aef3f537eb61cf2bb310f80bfe3 /ivi-layermanagement-examples
parent66b6f8b3e91a12696f7713b82ddee275e165096e (diff)
downloadwayland-ivi-extension-0ca066389f0c7db4c5ceba10a3f01bc4174dc879.tar.gz
LayerManagerUtils: Add LayerManagerUtils as examples
Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@denso.co.jp>
Diffstat (limited to 'ivi-layermanagement-examples')
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/CMakeLists.txt84
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/include/Bitmap.h26
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/include/IlmMatrix.h107
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/include/IpcModule.h107
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/include/IpcModuleLoader.h75
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/include/Log.h132
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/include/LogMessageBuffer.h126
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/include/ThreadBase.h55
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/src/Bitmap.cpp102
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/src/IlmMatrix.cpp257
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/src/IpcModuleLoader.cpp189
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/src/Log.cpp268
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/src/LogMessageBuffer.cpp189
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/src/ThreadBase.cpp231
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/tests/BitmapTest.cpp71
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/tests/CMakeLists.txt52
-rw-r--r--ivi-layermanagement-examples/LayerManagerUtils/tests/LogTest.cpp134
17 files changed, 2205 insertions, 0 deletions
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/CMakeLists.txt b/ivi-layermanagement-examples/LayerManagerUtils/CMakeLists.txt
new file mode 100644
index 0000000..12521c3
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/CMakeLists.txt
@@ -0,0 +1,84 @@
+############################################################################
+#
+# Copyright 2010, 2011 BMW Car IT GmbH
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+############################################################################
+
+cmake_minimum_required (VERSION 2.6)
+
+project(LayerManagerUtils)
+project_type(CORE)
+
+find_package (Threads)
+
+add_library(${PROJECT_NAME} STATIC
+ src/Bitmap.cpp
+ src/IlmMatrix.cpp
+ src/Log.cpp
+ src/LogMessageBuffer.cpp
+ src/ThreadBase.cpp
+ src/IpcModuleLoader.cpp
+)
+
+set(INCLUDE_DIRS
+ "include"
+ "${CMAKE_SOURCE_DIR}/config"
+ "${CMAKE_SOURCE_DIR}/ivi-layermanagement-api/ilmCommon/include"
+)
+
+set(LIBS
+ ${LIBS}
+ ${CMAKE_THREAD_LIBS_INIT}
+ dl
+)
+
+if (WITH_DLT)
+
+ find_package(AutomotiveDlt REQUIRED)
+
+ set(INCLUDE_DIRS
+ ${INCLUDE_DIRS}
+ ${DLT_INCLUDE_DIR}
+ )
+
+ set(LIBS
+ ${LIBS}
+ ${DLT_LIBRARY}
+ )
+
+ target_link_libraries(${PROJECT_NAME} ${LIBS})
+
+endif (WITH_DLT)
+
+include_directories(${INCLUDE_DIRS})
+
+install(FILES
+ include/Log.h
+ include/LogMessageBuffer.h
+ include/IlmMatrix.h
+ include/Bitmap.h
+ include/IpcModuleLoader.h
+ DESTINATION
+ include/layermanager
+)
+
+install(TARGETS
+ ${PROJECT_NAME}
+ DESTINATION
+ lib/layermanager/static
+)
+
+add_subdirectory(tests)
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/include/Bitmap.h b/ivi-layermanagement-examples/LayerManagerUtils/include/Bitmap.h
new file mode 100644
index 0000000..ec6a1d7
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/include/Bitmap.h
@@ -0,0 +1,26 @@
+/***************************************************************************
+*
+* Copyright 2010,2011 BMW Car IT GmbH
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+****************************************************************************/
+#ifndef _BITMAP_H_
+#define _BITMAP_H_
+
+#include <string>
+
+void writeBitmap(std::string FileName, char* imagedataRGB, int width, int height);
+
+#endif /*_BITMAP_H_ */
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/include/IlmMatrix.h b/ivi-layermanagement-examples/LayerManagerUtils/include/IlmMatrix.h
new file mode 100644
index 0000000..e0c606f
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/include/IlmMatrix.h
@@ -0,0 +1,107 @@
+/***************************************************************************
+*
+* Copyright 2010,2011 BMW Car IT GmbH
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* This file incorporates work covered by the following copyright and
+* permission notice:
+*
+* Oolong Engine for the iPhone / iPod touch
+* Copyright (c) 2007-2008 Wolfgang Engel http://code.google.com/p/oolongengine/
+*
+* 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.
+****************************************************************************/
+
+#ifndef _ILMMATRIX_H_
+#define _ILMMATRIX_H_
+
+#define MAT00 0
+#define MAT01 1
+#define MAT02 2
+#define MAT03 3
+#define MAT10 4
+#define MAT11 5
+#define MAT12 6
+#define MAT13 7
+#define MAT20 8
+#define MAT21 9
+#define MAT22 10
+#define MAT23 11
+#define MAT30 12
+#define MAT31 13
+#define MAT32 14
+#define MAT33 15
+
+typedef struct
+{
+ float x;
+ float y;
+} IlmVector2f;
+
+typedef struct
+{
+ float x;
+ float y;
+ float z;
+} IlmVector3f;
+
+typedef struct
+{
+ float x;
+ float y;
+ float z;
+ float w;
+} IlmVector4f;
+
+class IlmMatrix
+{
+public:
+ float* operator [] (const int row)
+ {
+ return &f[row<<2];
+ }
+
+ float f[16];
+};
+
+void IlmMatrixIdentity(IlmMatrix &mOut);
+
+void IlmMatrixMultiply(IlmMatrix &mOut, const IlmMatrix &mA, const IlmMatrix &mB);
+
+void IlmMatrixTranslation(IlmMatrix &mOut, const float X, const float Y, const float Z);
+
+void IlmMatrixScaling(IlmMatrix &mOut, const float X, const float Y, const float Z);
+
+void IlmMatrixRotateX(IlmMatrix &mOut, const float angle);
+
+void IlmMatrixRotateY(IlmMatrix &mOut, const float angle);
+
+void IlmMatrixRotateZ(IlmMatrix &mOut, const float angle);
+
+void IlmMatrixProjection(IlmMatrix &mOut, const float fov, const float near, const float far, const float aspectRatio);
+
+
+#endif /* _ILMMATRIX_H_*/
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/include/IpcModule.h b/ivi-layermanagement-examples/LayerManagerUtils/include/IpcModule.h
new file mode 100644
index 0000000..ff0e959
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/include/IpcModule.h
@@ -0,0 +1,107 @@
+/***************************************************************************
+*
+* Copyright 2012 BMW Car IT GmbH
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+****************************************************************************/
+#ifndef __IPCMODULE_H__
+#define __IPCMODULE_H__
+
+#include "ilm_types.h"
+
+/*
+=============================================================================
+ initialization
+=============================================================================
+*/
+t_ilm_bool initClientMode();
+t_ilm_bool initServiceMode();
+
+/*
+=============================================================================
+ create new messages
+=============================================================================
+*/
+t_ilm_message createMessage(t_ilm_const_string);
+t_ilm_message createResponse(t_ilm_message);
+t_ilm_message createErrorResponse(t_ilm_message);
+t_ilm_message createNotification(t_ilm_const_string);
+
+/*
+=============================================================================
+ add content to message
+=============================================================================
+*/
+t_ilm_bool appendBool(t_ilm_message, const t_ilm_bool);
+t_ilm_bool appendDouble(t_ilm_message, const double);
+t_ilm_bool appendString(t_ilm_message, const char*);
+t_ilm_bool appendInt(t_ilm_message, const int);
+t_ilm_bool appendIntArray(t_ilm_message, const int*, int);
+t_ilm_bool appendUint(t_ilm_message, const unsigned int);
+t_ilm_bool appendUintArray(t_ilm_message, const unsigned int*, int);
+
+/*
+=============================================================================
+ send message
+=============================================================================
+*/
+t_ilm_bool sendToClients(t_ilm_message, t_ilm_client_handle*, int);
+t_ilm_bool sendToService(t_ilm_message);
+
+/*
+=============================================================================
+ receive message
+=============================================================================
+*/
+t_ilm_message receive(t_ilm_int); /* timeout in ms*/
+
+/*
+=============================================================================
+ get message information
+=============================================================================
+*/
+t_ilm_const_string getMessageName(t_ilm_message);
+t_ilm_message_type getMessageType(t_ilm_message);
+t_ilm_const_string getSenderName(t_ilm_message);
+t_ilm_client_handle getSenderHandle(t_ilm_message);
+
+/*
+=============================================================================
+ get content of message
+=============================================================================
+*/
+t_ilm_bool getBool(t_ilm_message, t_ilm_bool*);
+t_ilm_bool getDouble(t_ilm_message, double*);
+t_ilm_bool getString(t_ilm_message, char*);
+t_ilm_bool getInt(t_ilm_message, int*);
+t_ilm_bool getIntArray(t_ilm_message, int**, int*);
+t_ilm_bool getUint(t_ilm_message, unsigned int*);
+t_ilm_bool getUintArray(t_ilm_message, unsigned int**, int*);
+
+/*
+=============================================================================
+ destroy message
+=============================================================================
+*/
+t_ilm_bool destroyMessage(t_ilm_message);
+
+/*
+=============================================================================
+ shutdown
+=============================================================================
+*/
+t_ilm_bool destroy();
+
+#endif /* __IPCMODULE_H__*/
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/include/IpcModuleLoader.h b/ivi-layermanagement-examples/LayerManagerUtils/include/IpcModuleLoader.h
new file mode 100644
index 0000000..0e1952e
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/include/IpcModuleLoader.h
@@ -0,0 +1,75 @@
+/**************************************************************************
+ *
+ * Copyright 2012 BMW Car IT GmbH
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
+#ifndef __IPCMODULELOADER_H_
+#define __IPCMODULELOADER_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus*/
+
+#include "ilm_types.h"
+
+struct IpcModule
+{
+ t_ilm_bool (*initClientMode)();
+ t_ilm_bool (*initServiceMode)();
+
+ t_ilm_message (*createMessage)(t_ilm_const_string);
+ t_ilm_message (*createResponse)(t_ilm_message);
+ t_ilm_message (*createErrorResponse)(t_ilm_message);
+ t_ilm_message (*createNotification)(t_ilm_const_string);
+
+ t_ilm_bool (*appendBool)(t_ilm_message, const t_ilm_bool);
+ t_ilm_bool (*appendDouble)(t_ilm_message, const double);
+ t_ilm_bool (*appendString)(t_ilm_message, const char*);
+ t_ilm_bool (*appendInt)(t_ilm_message, const int);
+ t_ilm_bool (*appendIntArray)(t_ilm_message, const int*, int);
+ t_ilm_bool (*appendUint)(t_ilm_message, const unsigned int);
+ t_ilm_bool (*appendUintArray)(t_ilm_message, const unsigned int*, int);
+
+ t_ilm_bool (*sendToClients)(t_ilm_message, t_ilm_client_handle*, int);
+ t_ilm_bool (*sendToService)(t_ilm_message);
+
+ t_ilm_message (*receive)(t_ilm_int); /* timeout in ms*/
+
+ t_ilm_const_string (*getMessageName)(t_ilm_message);
+ t_ilm_message_type (*getMessageType)(t_ilm_message);
+ t_ilm_const_string (*getSenderName)(t_ilm_message);
+ t_ilm_client_handle (*getSenderHandle)(t_ilm_message);
+
+ t_ilm_bool (*getBool)(t_ilm_message, t_ilm_bool*);
+ t_ilm_bool (*getDouble)(t_ilm_message, double*);
+ t_ilm_bool (*getString)(t_ilm_message, char*);
+ t_ilm_bool (*getInt)(t_ilm_message, int*);
+ t_ilm_bool (*getIntArray)(t_ilm_message, int**, int*);
+ t_ilm_bool (*getUint)(t_ilm_message, unsigned int*);
+ t_ilm_bool (*getUintArray)(t_ilm_message, unsigned int**, int*);
+
+ t_ilm_bool (*destroyMessage)(t_ilm_message);
+
+ t_ilm_bool (*destroy)();
+};
+
+t_ilm_bool loadIpcModule(struct IpcModule* communicator);
+
+#ifdef __cplusplus
+} /* extern "C"*/
+#endif /* __cplusplus*/
+
+#endif /* __IPCMODULELOADER_H_*/
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/include/Log.h b/ivi-layermanagement-examples/LayerManagerUtils/include/Log.h
new file mode 100644
index 0000000..3d96d30
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/include/Log.h
@@ -0,0 +1,132 @@
+/***************************************************************************
+* Copyright (C) 2011 BMW Car IT GmbH.
+* Author: Michael Schuldt (michael.schuldt@bmw-carit.de)
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* This file incorporates work covered by the following copyright and
+* permission notice:
+* Apache log4cxx
+* Copyright 2004-2007 The Apache Software Foundation
+*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT 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 _LOG_H_
+#define _LOG_H_
+#include "LogMessageBuffer.h"
+#include <iostream>
+#include <fstream>
+#include <pthread.h>
+#include <map>
+typedef enum
+{
+ LOG_DISABLED = 0,
+ LOG_ERROR = 1,
+ LOG_INFO = 2,
+ LOG_WARNING = 3,
+ LOG_DEBUG = 4,
+ LOG_MAX_LEVEL
+} LOG_MODES;
+
+/*The log context content is configuration dependend. Due
+ to the fact that we don't want to share the config file
+ in development headers, the real context is established
+ during the compiliation phase*/
+typedef void* LogContext;
+
+/* Diagnostic Injection Callback function to wrap dlt_injections for usage with c++ class names */
+typedef void (*diagnosticInjectionCallback)(unsigned int module_id, void *data, unsigned int length, void* userdata);
+
+class Log
+{
+public:
+
+ typedef struct diagnosticCallbackData_t
+ {
+ unsigned int module_id;
+ void *userdata;
+ diagnosticInjectionCallback diagFunc;
+ } diagnosticCallbackData;
+
+ typedef std::map<unsigned int, diagnosticCallbackData*> DiagnosticCallbackMap;
+
+ virtual ~Log();
+ static LOG_MODES fileLogLevel;
+ static LOG_MODES consoleLogLevel;
+ static LOG_MODES dltLogLevel;
+ static Log* getInstance();
+ static DiagnosticCallbackMap* getDiagnosticCallbackMap()
+ {
+ return getInstance()->m_diagnosticCallbackMap;
+ }
+ void warning(LogContext logContext, const std::string& moduleName, const std::basic_string<char>& output);
+ void info(LogContext logContext, const std::string& moduleName, const std::basic_string<char>& output);
+ void error(LogContext logContext, const std::string& moduleName, const std::basic_string<char>& output);
+ void debug(LogContext logContext, const std::string& moduleName, const std::basic_string<char>& output);
+ void log(LogContext logContext, LOG_MODES logMode, const std::string& moduleName, const std::basic_string<char>& output);
+ void registerDiagnosticInjectionCallback(unsigned int module_id, diagnosticInjectionCallback diagFunc, void* userdata);
+ void unregisterDiagnosticInjectionCallback(unsigned int module_id);
+ LogContext getLogContext();
+ static void closeInstance();
+private:
+ Log();
+ void LogToFile(std::string logMode, const std::string& moduleName, const std::basic_string<char>& output);
+ void LogToConsole(std::string logMode, const std::string& moduleName, const std::basic_string<char>& output);
+ void LogToDltDaemon(LogContext logContext, LOG_MODES logMode, const std::string& moduleName, const std::basic_string<char>& output);
+
+private:
+ std::ofstream* m_fileStream;
+ pthread_mutex_t m_LogBufferMutex;
+ LogContext m_logContext;
+ static DiagnosticCallbackMap* m_diagnosticCallbackMap;
+
+ static Log* m_instance;
+};
+
+//#define LOG_ERROR(logcontext,module, message)
+
+#define LOG_ERROR(module, message) { \
+ LogMessageBuffer oss_; \
+ Log::getInstance()->error(Log::getInstance()->getLogContext(), module, oss_.str(oss_<< message)); }
+
+//#define LOG_INFO(logcontext,module, message)
+
+#define LOG_INFO(module, message) { \
+ LogMessageBuffer oss_; \
+ Log::getInstance()->info(Log::getInstance()->getLogContext(), module, oss_.str(oss_<< message)); }
+
+//#define LOG_DEBUG(logcontext,module, message)
+
+#define LOG_DEBUG(module, message) { \
+ LogMessageBuffer oss_; \
+ Log::getInstance()->debug(Log::getInstance()->getLogContext(), module, oss_.str(oss_<< message)); }
+
+//#define LOG_WARNING(logcontext,module, message)
+
+#define LOG_WARNING(module, message) { \
+ LogMessageBuffer oss_; \
+ Log::getInstance()->warning(Log::getInstance()->getLogContext(), module, oss_.str(oss_<< message)); }
+#endif /* _LOG_H_ */
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/include/LogMessageBuffer.h b/ivi-layermanagement-examples/LayerManagerUtils/include/LogMessageBuffer.h
new file mode 100644
index 0000000..aca6166
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/include/LogMessageBuffer.h
@@ -0,0 +1,126 @@
+/***************************************************************************
+* Copyright (C) 2011 BMW Car IT GmbH.
+* Author: Michael Schuldt (michael.schuldt@bmw-carit.de)
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* This file incorporates work covered by the following copyright and
+* permission notice:
+* Apache log4cxx
+* Copyright 2004-2007 The Apache Software Foundation
+*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT 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 _LOGMESSAGEBUFFER_H_
+#define _LOGMESSAGEBUFFER_H_
+
+#include <sstream>
+#include <pthread.h>
+typedef std::ios_base& (*ios_base_manip)(std::ios_base&);
+
+class LogMessageBuffer
+{
+public:
+ /**
+ * Creates a new instance.
+ */
+ LogMessageBuffer();
+ /**
+ * Destructor.
+ */
+ ~LogMessageBuffer();
+
+ LogMessageBuffer& operator<<(const std::basic_string<char>& msg);
+
+ LogMessageBuffer& operator<<(const char* msg);
+
+ LogMessageBuffer& operator<<(char* msg);
+
+ LogMessageBuffer& operator<<(const char msg);
+
+ std::ostream& operator<<(ios_base_manip manip);
+
+ std::ostream& operator<<(bool val);
+
+ std::ostream& operator<<(short val);
+
+ std::ostream& operator<<(int val);
+
+ std::ostream& operator<<(unsigned int val);
+
+ std::ostream& operator<<(long val);
+
+ std::ostream& operator<<(unsigned long val);
+
+ std::ostream& operator<<(float val);
+
+ std::ostream& operator<<(double val);
+
+ std::ostream& operator<<(long double val);
+
+ std::ostream& operator<<(void* val);
+
+ /**
+ * Cast to ostream.
+ */
+ operator std::basic_ostream<char>&();
+
+ const std::basic_string<char>& str(std::basic_ostream<char>& os);
+
+ const std::basic_string<char>& str() const;
+
+ bool hasStream() const;
+
+private:
+ /**
+ * No default copy constructor.
+ */
+ LogMessageBuffer(const LogMessageBuffer&);
+
+ /**
+ * No assignment operator.
+ */
+ LogMessageBuffer& operator=(const LogMessageBuffer&);
+
+ /**
+ * Encapsulated std::string.
+ */
+ std::basic_string<char> buf;
+
+ /**
+ * Encapsulated stream, created on demand.
+ */
+ std::basic_ostringstream<char>* stream;
+};
+
+template<class V>
+std::basic_ostream<char>& operator<<(LogMessageBuffer& os, const V& val)
+{
+ return ((std::basic_ostream<char>&) os) << val;
+}
+
+#endif /* _LOGMESSAGEBUFFER_H_ */
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/include/ThreadBase.h b/ivi-layermanagement-examples/LayerManagerUtils/include/ThreadBase.h
new file mode 100644
index 0000000..77cc7b5
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/include/ThreadBase.h
@@ -0,0 +1,55 @@
+/***************************************************************************
+ *
+ * Copyright 2010,2011 BMW Car IT GmbH
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __THREADBASE_H__
+#define __THREADBASE_H__
+
+#include "ilm_types.h"
+#include <pthread.h>
+
+class ThreadBase
+{
+public:
+ ThreadBase();
+ virtual ~ThreadBase();
+
+ t_ilm_bool threadCreate();
+ t_ilm_bool threadInit();
+ t_ilm_bool threadStart();
+ t_ilm_bool threadStop();
+
+ pthread_t threadGetId() const;
+ t_ilm_bool threadIsRunning();
+
+ // override in inheriting class if required
+ virtual t_ilm_bool threadInitInThreadContext();
+ virtual t_ilm_bool threadDestroyInThreadContext();
+
+ // implement in inheriting class
+ virtual t_ilm_bool threadMainLoop() = 0;
+
+private:
+ static unsigned int mGlobalThreadCount;
+ pthread_t mThreadId;
+ pthread_mutex_t mInitLock;
+ pthread_mutex_t mRunLock;
+ t_ilm_bool mRunning;
+};
+
+#endif // __THREADBASE_H__
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/src/Bitmap.cpp b/ivi-layermanagement-examples/LayerManagerUtils/src/Bitmap.cpp
new file mode 100644
index 0000000..e0910ab
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/src/Bitmap.cpp
@@ -0,0 +1,102 @@
+/***************************************************************************
+*
+* Copyright 2010,2011 BMW Car IT GmbH
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+****************************************************************************/
+#include "Bitmap.h"
+#include "Log.h"
+#include <stdint.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <string>
+#include <stdlib.h>
+
+typedef struct BMPHeaderStruct
+{
+ uint32_t size; // filesize
+ uint16_t a;
+ uint16_t b;
+ uint32_t offset; // offset
+} BMPHeader;
+
+typedef struct headerStruct
+{
+ uint32_t headersize;
+ int32_t width;
+ int32_t height;
+ uint16_t planes;
+ uint16_t bits;
+ uint32_t compress;
+ uint32_t imagesize;
+ int32_t xresolution;
+ int32_t yresolution;
+ uint32_t color1;
+ uint32_t color2;
+} InfoHeader;
+
+void writeBitmap(std::string FileName, char* imagedataRGB, int width, int height)
+{
+ LOG_DEBUG("Bitmap", "writing Bitmap to file:" << FileName);
+
+ BMPHeader bmpHeader;
+ InfoHeader header;
+ int imagebytes = width*height*3;
+ char firstbytes[2];
+ firstbytes[0] = 'B';
+ firstbytes[1] = 'M';
+ bmpHeader.size = 2 + sizeof(BMPHeader) + sizeof(header) + imagebytes;
+ bmpHeader.a = 0;
+ bmpHeader.b = 0;
+ bmpHeader.offset = 2 + sizeof(BMPHeader) + sizeof(header);
+ header.headersize = sizeof(header);
+ header.width = width;
+ header.height = height;
+ header.planes = 1;
+ header.bits = 24; // bitmap does not do alpha
+ header.compress = 0;
+ header.imagesize = imagebytes;
+ header.xresolution = 2835; // because of dpi
+ header.yresolution = 2835;
+ header.color1 = 0;
+ header.color2 = 0;
+
+ // make sure parent directory exists
+ std::size_t currentPos = 0;
+ std::size_t lastPos = FileName.find_first_of("/", currentPos);
+ while (lastPos != std::string::npos)
+ {
+ std::string directory = FileName.substr(0, lastPos);
+ LOG_DEBUG("Bitmap", "Creating directory " << directory);
+ mkdir(directory.c_str(), 0755);
+ currentPos = lastPos;
+ lastPos = FileName.find_first_of("/", currentPos + 1);
+ }
+
+ FILE* file = fopen(FileName.c_str(), "wb");
+
+ if (file)
+ {
+ fwrite(firstbytes, 2, 1, file);
+ fwrite((void*)&bmpHeader, sizeof(BMPHeader), 1, file);
+ fwrite((void*)&header, sizeof(header), 1, file);
+ fwrite(imagedataRGB, header.imagesize, 1, file);
+ fclose(file);
+ }
+ else
+ {
+ LOG_DEBUG("Bitmap", "File could not be opened for writing");
+ }
+}
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/src/IlmMatrix.cpp b/ivi-layermanagement-examples/LayerManagerUtils/src/IlmMatrix.cpp
new file mode 100644
index 0000000..5e50b6c
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/src/IlmMatrix.cpp
@@ -0,0 +1,257 @@
+/***************************************************************************
+*
+* Copyright 2010,2011 BMW Car IT GmbH
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* This file incorporates work covered by the following copyright and
+* permission notice:
+*
+* Oolong Engine for the iPhone / iPod touch
+* Copyright (c) 2007-2008 Wolfgang Engel http://code.google.com/p/oolongengine/
+*
+* 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.
+****************************************************************************/
+#include "IlmMatrix.h"
+#include <math.h>
+
+#define ILM_PI 3.14159265
+
+#define degToRad(deg) ((deg) * ILM_PI / 180.0f)
+#define radToDeg(rad) ((rad) * 180.0f / ILM_PI)
+
+void IlmMatrixIdentity(IlmMatrix &mOut)
+{
+ mOut.f[0] = 1.0f;
+ mOut.f[1] = 0.0f;
+ mOut.f[2] = 0.0f;
+ mOut.f[3] = 0.0f;
+
+ mOut.f[4] = 0.0f;
+ mOut.f[5] = 1.0f;
+ mOut.f[6] = 0.0f;
+ mOut.f[7] = 0.0f;
+
+ mOut.f[8] = 0.0f;
+ mOut.f[9] = 0.0f;
+ mOut.f[10] = 1.0f;
+ mOut.f[11] = 0.0f;
+
+ mOut.f[12] = 0.0f;
+ mOut.f[13] = 0.0f;
+ mOut.f[14] = 0.0f;
+ mOut.f[15] = 1.0f;
+}
+
+void IlmMatrixMultiply(IlmMatrix &mOut, const IlmMatrix &mA, const IlmMatrix &mB)
+{
+ IlmMatrix mRet;
+
+ mRet.f[0] = mA.f[0] * mB.f[0] + mA.f[1] * mB.f[4] + mA.f[2] * mB.f[8] + mA.f[3] * mB.f[12];
+ mRet.f[1] = mA.f[0] * mB.f[1] + mA.f[1] * mB.f[5] + mA.f[2] * mB.f[9] + mA.f[3] * mB.f[13];
+ mRet.f[2] = mA.f[0] * mB.f[2] + mA.f[1] * mB.f[6] + mA.f[2] * mB.f[10] + mA.f[3] * mB.f[14];
+ mRet.f[3] = mA.f[0] * mB.f[3] + mA.f[1] * mB.f[7] + mA.f[2] * mB.f[11] + mA.f[3] * mB.f[15];
+
+ mRet.f[4] = mA.f[4] * mB.f[0] + mA.f[5] * mB.f[4] + mA.f[6] * mB.f[8] + mA.f[7] * mB.f[12];
+ mRet.f[5] = mA.f[4] * mB.f[1] + mA.f[5] * mB.f[5] + mA.f[6] * mB.f[9] + mA.f[7] * mB.f[13];
+ mRet.f[6] = mA.f[4] * mB.f[2] + mA.f[5] * mB.f[6] + mA.f[6] * mB.f[10] + mA.f[7] * mB.f[14];
+ mRet.f[7] = mA.f[4] * mB.f[3] + mA.f[5] * mB.f[7] + mA.f[6] * mB.f[11] + mA.f[7] * mB.f[15];
+
+ mRet.f[8] = mA.f[8] * mB.f[0] + mA.f[9] * mB.f[4] + mA.f[10] * mB.f[8] + mA.f[11] * mB.f[12];
+ mRet.f[9] = mA.f[8] * mB.f[1] + mA.f[9] * mB.f[5] + mA.f[10] * mB.f[9] + mA.f[11] * mB.f[13];
+ mRet.f[10] = mA.f[8] * mB.f[2] + mA.f[9] * mB.f[6] + mA.f[10] * mB.f[10] + mA.f[11] * mB.f[14];
+ mRet.f[11] = mA.f[8] * mB.f[3] + mA.f[9] * mB.f[7] + mA.f[10] * mB.f[11] + mA.f[11] * mB.f[15];
+
+ mRet.f[12] = mA.f[12] * mB.f[0] + mA.f[13] * mB.f[4] + mA.f[14] * mB.f[8] + mA.f[15] * mB.f[12];
+ mRet.f[13] = mA.f[12] * mB.f[1] + mA.f[13] * mB.f[5] + mA.f[14] * mB.f[9] + mA.f[15] * mB.f[13];
+ mRet.f[14] = mA.f[12] * mB.f[2] + mA.f[13] * mB.f[6] + mA.f[14] * mB.f[10] + mA.f[15] * mB.f[14];
+ mRet.f[15] = mA.f[12] * mB.f[3] + mA.f[13] * mB.f[7] + mA.f[14] * mB.f[11] + mA.f[15] * mB.f[15];
+
+ mOut = mRet;
+}
+
+void IlmMatrixTranslation(IlmMatrix &mOut, const float X, const float Y, const float Z)
+{
+ mOut.f[0] = 1.0f;
+ mOut.f[1] = 0.0f;
+ mOut.f[2] = 0.0f;
+ mOut.f[3] = 0.0f;
+
+ mOut.f[4] = 0.0f;
+ mOut.f[5] = 1.0f;
+ mOut.f[6] = 0.0f;
+ mOut.f[7] = 0.0f;
+
+ mOut.f[8] = 0.0f;
+ mOut.f[9] = 0.0f;
+ mOut.f[10] = 1.0f;
+ mOut.f[11] = 0.0f;
+
+ mOut.f[12] = X;
+ mOut.f[13] = Y;
+ mOut.f[14] = Z;
+ mOut.f[15] = 1.0f;
+}
+
+void IlmMatrixScaling(IlmMatrix &mOut, const float X, const float Y, const float Z)
+{
+ mOut.f[0] = X;
+ mOut.f[1] = 0.0f;
+ mOut.f[2] = 0.0f;
+ mOut.f[3] = 0.0f;
+
+ mOut.f[4] = 0.0f;
+ mOut.f[5] = Y;
+ mOut.f[6] = 0.0f;
+ mOut.f[7] = 0.0f;
+
+ mOut.f[8] = 0.0f;
+ mOut.f[9] = 0.0f;
+ mOut.f[10] = Z;
+ mOut.f[11] = 0.0f;
+
+ mOut.f[12] = 0.0f;
+ mOut.f[13] = 0.0f;
+ mOut.f[14] = 0.0f;
+ mOut.f[15] = 1.0f;
+}
+
+void IlmMatrixRotateX(IlmMatrix &mOut, const float angle)
+{
+ // Precompute cos and sin
+ float fCosine = (float)cos(degToRad(angle));
+ float fSine = (float)sin(degToRad(angle));
+
+ // Create the trigonometric matrix corresponding to X Rotation
+ mOut.f[0] = 1.0f;
+ mOut.f[1] = 0.0f;
+ mOut.f[2] = 0.0f;
+ mOut.f[3] = 0.0f;
+
+ mOut.f[4] = 0.0f;
+ mOut.f[5] = fCosine;
+ mOut.f[6] = -fSine;
+ mOut.f[7] = 0.0f;
+
+ mOut.f[8] = 0.0f;
+ mOut.f[9] = fSine;
+ mOut.f[10] = fCosine;
+ mOut.f[11] = 0.0f;
+
+ mOut.f[12] = 0.0f;
+ mOut.f[13] = 0.0f;
+ mOut.f[14] = 0.0f;
+ mOut.f[15] = 1.0f;
+}
+
+void IlmMatrixRotateY(IlmMatrix &mOut, const float angle)
+{
+ // Precompute cos and sin
+ float fCosine = (float)cos(degToRad(angle));
+ float fSine = (float)sin(degToRad(angle));
+
+ // Create the trigonometric matrix corresponding to Y Rotation
+ mOut.f[0] = fCosine;
+ mOut.f[1] = 0.0f;
+ mOut.f[2] = fSine;
+ mOut.f[3] = 0.0f;
+
+ mOut.f[4] = 0.0f;
+ mOut.f[5] = 1.0f;
+ mOut.f[6] = 0.0f;
+ mOut.f[7] = 0.0f;
+
+ mOut.f[8] = -fSine;
+ mOut.f[9] = 0.0f;
+ mOut.f[10] = fCosine;
+ mOut.f[11] = 0.0f;
+
+ mOut.f[12] = 0.0f;
+ mOut.f[13] = 0.0f;
+ mOut.f[14] = 0.0f;
+ mOut.f[15] = 1.0f;
+}
+
+void IlmMatrixRotateZ(IlmMatrix &mOut, const float angle)
+{
+ // Precompute cos and sin
+ float fCosine = (float)cos(degToRad(angle));
+ float fSine = (float)sin(degToRad(angle));
+
+ // Create the trigonometric matrix corresponding to Z Rotation
+ mOut.f[0] = fCosine;
+ mOut.f[1] = -fSine;
+ mOut.f[2] = 0.0f;
+ mOut.f[3] = 0.0f;
+
+ mOut.f[4] = fSine;
+ mOut.f[5] = fCosine;
+ mOut.f[6] = 0.0f;
+ mOut.f[7] = 0.0f;
+
+ mOut.f[8] = 0.0f;
+ mOut.f[9] = 0.0f;
+ mOut.f[10] = 1.0f;
+ mOut.f[11] = 0.0f;
+
+ mOut.f[12] = 0.0f;
+ mOut.f[13] = 0.0f;
+ mOut.f[14] = 0.0f;
+ mOut.f[15] = 1.0f;
+}
+
+void IlmMatrixProjection(IlmMatrix &mOut, const float fov, const float near, const float far, const float aspect)
+{
+ // Precompute borders for projection
+ float range = near * tan(degToRad(fov) / 2.0);
+ float left = -range * aspect;
+ float right = range * aspect;
+ float bottom = -range;
+ float top = range;
+
+ // Column 1
+ mOut.f[0] = 2 * near / (right - left);
+ mOut.f[1] = 0.0;
+ mOut.f[2] = 0.0;
+ mOut.f[3] = 0.0;
+
+ // Column 2
+ mOut.f[4] = 0.0;
+ mOut.f[5] = 2 * near / (top - bottom);
+ mOut.f[6] = 0.0;
+ mOut.f[7] = 0.0;
+
+ // Column 3
+ mOut.f[8] = 0.0;
+ mOut.f[9] = 0.0;
+ mOut.f[10] = -(far + near) / (far - near);
+ mOut.f[11] = -1;
+
+ // Column 4
+ mOut.f[12] = 0.0;
+ mOut.f[13] = 0.0;
+ mOut.f[14] = -(2 * far * near) / (far - near);
+ mOut.f[15] = 0.0;
+}
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/src/IpcModuleLoader.cpp b/ivi-layermanagement-examples/LayerManagerUtils/src/IpcModuleLoader.cpp
new file mode 100644
index 0000000..c5bf8dd
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/src/IpcModuleLoader.cpp
@@ -0,0 +1,189 @@
+/**************************************************************************
+ *
+ * Copyright 2012 BMW Car IT GmbH
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
+#include "IpcModuleLoader.h"
+#include "IpcModule.h"
+#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+#include <errno.h>
+#include <dirent.h> /* DIR*/
+#include <string.h> /* strcpy, strcat, strstr*/
+
+/*
+=============================================================================
+ global variables
+=============================================================================
+*/
+const char* gDefaultPluginLookupPath = CMAKE_INSTALL_PREFIX"/lib/layermanager";
+const char* gCommunicatorPluginDirectory = "ipcmodules";
+
+/*
+=============================================================================
+ plugin loading
+=============================================================================
+*/
+t_ilm_bool loadSymbolTable(struct IpcModule* ipcModule, char* path, char* file)
+{
+ struct ApiFunction
+ {
+ const char* name;
+ void** funcPtr;
+ };
+
+ struct ApiFunction ApiFunctionTable[] =
+ {
+ { "initClientMode", (void**)&ipcModule->initClientMode },
+ { "initServiceMode", (void**)&ipcModule->initServiceMode },
+
+ { "createMessage", (void**)&ipcModule->createMessage },
+ { "createResponse", (void**)&ipcModule->createResponse },
+ { "createErrorResponse", (void**)&ipcModule->createErrorResponse },
+ { "createNotification", (void**)&ipcModule->createNotification },
+
+ { "appendBool", (void**)&ipcModule->appendBool },
+ { "appendDouble", (void**)&ipcModule->appendDouble },
+ { "appendString", (void**)&ipcModule->appendString },
+ { "appendInt", (void**)&ipcModule->appendInt },
+ { "appendIntArray", (void**)&ipcModule->appendIntArray },
+ { "appendUint", (void**)&ipcModule->appendUint },
+ { "appendUintArray", (void**)&ipcModule->appendUintArray },
+
+ { "sendToClients", (void**)&ipcModule->sendToClients },
+ { "sendToService", (void**)&ipcModule->sendToService },
+
+ { "receive", (void**)&ipcModule->receive },
+
+ { "getMessageName", (void**)&ipcModule->getMessageName },
+ { "getMessageType", (void**)&ipcModule->getMessageType },
+ { "getSenderName", (void**)&ipcModule->getSenderName },
+ { "getSenderHandle", (void**)&ipcModule->getSenderHandle },
+
+ { "getBool", (void**)&ipcModule->getBool },
+ { "getDouble", (void**)&ipcModule->getDouble },
+ { "getString", (void**)&ipcModule->getString },
+ { "getInt", (void**)&ipcModule->getInt },
+ { "getIntArray", (void**)&ipcModule->getIntArray },
+ { "getUint", (void**)&ipcModule->getUint },
+ { "getUintArray", (void**)&ipcModule->getUintArray },
+
+ { "destroyMessage", (void**)&ipcModule->destroyMessage },
+
+ { "destroy", (void**)&ipcModule->destroy }
+ };
+
+ const unsigned int apiFunctionCount = sizeof(ApiFunctionTable) / sizeof(struct ApiFunction);
+ unsigned int symbolCount = 0;
+ t_ilm_bool returnValue = ILM_FALSE;
+ void* pluginLibHandle = 0;
+ char fullFilePath[1024];
+ fullFilePath[0] = '\0';
+
+ snprintf(fullFilePath, sizeof(fullFilePath), "%s/%s", path, file);
+
+ pluginLibHandle = dlopen(fullFilePath, RTLD_LAZY);
+
+ if (pluginLibHandle)
+ {
+ unsigned int i = 0;
+ for (i = 0; i < apiFunctionCount; ++i)
+ {
+ struct ApiFunction* func = &ApiFunctionTable[i];
+
+ *func->funcPtr = dlsym(pluginLibHandle, func->name);
+ if (*func->funcPtr)
+ {
+ symbolCount++;
+ /*printf("[ OK ] symbol %s\n", func->name);*/
+ }
+ else
+ {
+ /*printf("[FAIL] symbol %s\n", func->name);*/
+ }
+ }
+ }
+
+ if (symbolCount == apiFunctionCount)
+ {
+ returnValue = ILM_TRUE;
+ }
+ else
+ {
+ printf("Error in %s: found %d symbols, expected %d symbols.\n", fullFilePath, symbolCount, apiFunctionCount);
+ if (0 != errno)
+ {
+ printf("--> error: %s\n", strerror(errno));
+ }
+ printf("--> not a valid ipc module\n");
+ if (pluginLibHandle)
+ {
+ dlclose(pluginLibHandle);
+ }
+ }
+
+ /*
+ * Note: will break plugin. must be done during shutdown,
+ * but currently there is no unloadIpcModule
+ * dlclose(pluginLibHandle);
+ */
+
+ return returnValue;
+}
+
+t_ilm_bool loadIpcModule(struct IpcModule* communicator)
+{
+ t_ilm_bool result = ILM_FALSE;
+ char path[1024];
+ DIR *directory;
+
+ /* find communicator client plugin*/
+ char* pluginLookupPath = getenv("LM_PLUGIN_PATH");
+ if (pluginLookupPath)
+ {
+ gDefaultPluginLookupPath = pluginLookupPath;
+ }
+
+ snprintf(path, sizeof(path), "%s/%s", gDefaultPluginLookupPath,
+ gCommunicatorPluginDirectory);
+
+ /* open directory*/
+ directory = opendir(path);
+ if (directory)
+ {
+ /* iterate content of directory*/
+ struct dirent *itemInDirectory = 0;
+ while ((itemInDirectory = readdir(directory)) && !result)
+ {
+ char* fileName = itemInDirectory->d_name;
+
+ if (strstr(fileName, ".so"))
+ {
+ result = loadSymbolTable(communicator, path, fileName);
+ }
+ }
+
+ closedir(directory);
+ }
+ else
+ {
+ printf("IpcModuleLoader: Error opening plugin dir %s\n", path);
+ }
+
+ return result;
+}
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/src/Log.cpp b/ivi-layermanagement-examples/LayerManagerUtils/src/Log.cpp
new file mode 100644
index 0000000..7528849
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/src/Log.cpp
@@ -0,0 +1,268 @@
+/***************************************************************************
+* Copyright (C) 2011 BMW Car IT GmbH.
+* Author: Michael Schuldt (michael.schuldt@bmw-carit.de)
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* This file incorporates work covered by the following copyright and
+* permission notice:
+* Apache log4cxx
+* Copyright 2004-2007 The Apache Software Foundation
+*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT 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 "Log.h"
+#include <iomanip>
+#include "config.h"
+#ifdef WITH_DLT
+#include <dlt/dlt.h>
+#endif
+
+Log* Log::m_instance = NULL;
+Log::DiagnosticCallbackMap* Log::m_diagnosticCallbackMap = NULL;
+LOG_MODES Log::fileLogLevel = LOG_DISABLED;
+LOG_MODES Log::consoleLogLevel = LOG_INFO;
+#ifdef WITH_DLT
+LOG_MODES Log::dltLogLevel = LOG_DEBUG;
+#else
+LOG_MODES Log::dltLogLevel = LOG_DISABLED;
+#endif
+
+
+Log::Log()
+{
+ // TODO Auto-generated constructor stub
+ m_fileStream = new std::ofstream("/tmp/LayerManagerService.log");
+ pthread_mutex_init(&m_LogBufferMutex, NULL);
+ Log::m_diagnosticCallbackMap = new Log::DiagnosticCallbackMap;
+#ifdef WITH_DLT
+ m_logContext = new DltContext;
+ DLT_REGISTER_APP("LMSA", "LayerManagerService");
+ DLT_REGISTER_CONTEXT(*((DltContext*)m_logContext), "LMSC", "LayerManagerService");
+ DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_VERBOSE, DLT_TRACE_STATUS_DEFAULT);
+#else
+ m_logContext = NULL;
+#endif
+}
+
+Log* Log::getInstance()
+{
+ if (m_instance == NULL)
+ {
+ m_instance = new Log();
+ }
+ return m_instance;
+}
+
+void Log::closeInstance()
+{
+ delete m_instance;
+ m_instance = NULL;
+}
+
+Log::~Log()
+{
+ // TODO Auto-generated destructor stub
+ m_fileStream->close();
+ pthread_mutex_destroy(&m_LogBufferMutex);
+ Log::m_instance = NULL;
+#ifdef WITH_DLT
+ DLT_UNREGISTER_CONTEXT(*((DltContext*)m_logContext));
+ delete((DltContext*)m_logContext);
+ DLT_UNREGISTER_APP();
+#endif
+ delete m_diagnosticCallbackMap;
+ m_diagnosticCallbackMap = NULL;
+ m_logContext = NULL;
+}
+
+void Log::warning(LogContext logContext, const std::string& moduleName, const std::basic_string<char>& output)
+{
+ log(logContext, LOG_WARNING, moduleName, output);
+}
+
+void Log::info(LogContext logContext, const std::string& moduleName, const std::basic_string<char>& output)
+{
+ log(logContext, LOG_INFO, moduleName, output);
+}
+
+void Log::error(LogContext logContext, const std::string& moduleName, const std::basic_string<char>& output)
+{
+ log(logContext, LOG_ERROR, moduleName, output);
+}
+
+void Log::debug(LogContext logContext, const std::string& moduleName, const std::basic_string<char>& output)
+{
+ log(logContext, LOG_DEBUG, moduleName, output);
+}
+
+void Log::log(LogContext logContext, LOG_MODES logMode, const std::string& moduleName, const std::basic_string<char>& output)
+{
+ (void)logContext;
+
+ std::string logString[LOG_MAX_LEVEL] = {"", "ERROR", "INFO", "WARNING", "DEBUG"};
+ std::string logOutLevelString = logString[LOG_INFO];
+ pthread_mutex_lock(&m_LogBufferMutex);
+ if (logMode < LOG_MAX_LEVEL)
+ {
+ logOutLevelString = logString[logMode];
+ }
+ if (consoleLogLevel >= logMode)
+ {
+ LogToConsole(logOutLevelString, moduleName, output);
+ }
+ if (fileLogLevel >= logMode)
+ {
+ LogToFile(logOutLevelString, moduleName, output);
+ }
+#ifdef WITH_DLT
+ if (dltLogLevel >= logMode)
+ {
+ LogToDltDaemon(logContext, logMode, moduleName, output);
+ }
+#endif
+ pthread_mutex_unlock(&m_LogBufferMutex);
+}
+
+void Log::LogToFile(std::string logMode, const std::string& moduleName, const std::basic_string<char>& output)
+{
+ static unsigned int maxLengthModuleName = 0;
+ static unsigned int maxLengthLogModeName = 0;
+
+ if (moduleName.length() > maxLengthModuleName)
+ {
+ maxLengthModuleName = moduleName.length();
+ }
+
+ if (logMode.length() > maxLengthLogModeName)
+ {
+ maxLengthLogModeName = logMode.length();
+ }
+
+ *m_fileStream << std::setw(maxLengthModuleName) << std::left << moduleName << " | "
+ << std::setw(maxLengthLogModeName) << std::left << logMode << " | "
+ << output << std::endl;
+}
+
+void Log::LogToConsole(std::string logMode, const std::string& moduleName, const std::basic_string<char>& output)
+{
+ static unsigned int maxLengthModuleName = 0;
+ static unsigned int maxLengthLogModeName = 0;
+
+ if (moduleName.length() > maxLengthModuleName)
+ {
+ maxLengthModuleName = moduleName.length();
+ }
+
+ if (logMode.length() > maxLengthLogModeName)
+ {
+ maxLengthLogModeName = logMode.length();
+ }
+
+ std::cout << std::setw(maxLengthModuleName) << std::left << moduleName << " | "
+ << std::setw(maxLengthLogModeName) << std::left << logMode << " | "
+ << output << std::endl;
+}
+
+LogContext Log::getLogContext()
+{
+ return m_logContext;
+}
+
+#ifdef WITH_DLT
+int dlt_injection_callback(unsigned int module_id, void *data, unsigned int length)
+{
+ LOG_DEBUG("LOG", "Injection for service " << module_id << " called");
+ Log::diagnosticCallbackData *cbData = (*Log::getDiagnosticCallbackMap())[module_id];
+ if (cbData)
+ {
+ cbData->diagFunc(module_id, data, length, cbData->userdata);
+ }
+ return 0;
+}
+#endif
+
+void Log::registerDiagnosticInjectionCallback(unsigned int module_id, diagnosticInjectionCallback diagFunc, void* userdata)
+{
+ Log::diagnosticCallbackData *cbData = new Log::diagnosticCallbackData;
+ cbData->module_id = module_id;
+ cbData->userdata = userdata;
+ cbData->diagFunc = diagFunc;
+ (*m_diagnosticCallbackMap)[module_id] = cbData;
+#ifdef WITH_DLT
+ DLT_REGISTER_INJECTION_CALLBACK(*(DltContext*)m_logContext, module_id, dlt_injection_callback);
+#endif
+}
+
+void Log::unregisterDiagnosticInjectionCallback(unsigned int module_id)
+{
+ m_diagnosticCallbackMap->erase(module_id);
+}
+
+#ifdef WITH_DLT
+
+// DLT macros will fail using -pedantic with
+// warning: ISO C++ forbids braced-groups within expressions
+#pragma GCC diagnostic ignored "-pedantic"
+
+void Log::LogToDltDaemon(LogContext logContext, LOG_MODES logMode, const std::string& moduleName, const std::basic_string<char>& output)
+{
+ std::stringstream oss;
+ std::string dltString;
+ static unsigned int maxLengthModuleName = 0;
+
+ if (moduleName.length() > maxLengthModuleName)
+ {
+ maxLengthModuleName = moduleName.length();
+ }
+ oss << std::setw(maxLengthModuleName) << std::left << moduleName << " | "
+ << output << std::endl;
+ dltString = oss.str();
+
+ switch (logMode)
+ {
+ case LOG_INFO:
+ DLT_LOG(*((DltContext*)logContext), DLT_LOG_INFO, DLT_STRING(dltString.c_str()));
+ break;
+
+ case LOG_ERROR:
+ DLT_LOG(*((DltContext*)logContext), DLT_LOG_ERROR, DLT_STRING(dltString.c_str()));
+ break;
+
+ case LOG_DEBUG:
+ DLT_LOG(*((DltContext*)logContext), DLT_LOG_DEBUG, DLT_STRING(dltString.c_str()));
+ break;
+
+ case LOG_WARNING:
+ DLT_LOG(*((DltContext*)logContext), DLT_LOG_WARN, DLT_STRING(dltString.c_str()));
+ break;
+
+ default:
+ DLT_LOG(*((DltContext*)logContext), DLT_LOG_INFO, DLT_STRING(dltString.c_str()));
+ }
+}
+#endif
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/src/LogMessageBuffer.cpp b/ivi-layermanagement-examples/LayerManagerUtils/src/LogMessageBuffer.cpp
new file mode 100644
index 0000000..e1b07f5
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/src/LogMessageBuffer.cpp
@@ -0,0 +1,189 @@
+/***************************************************************************
+* Copyright (C) 2011 BMW Car IT GmbH.
+* Author: Michael Schuldt (michael.schuldt@bmw-carit.de)
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* This file incorporates work covered by the following copyright and
+* permission notice:
+* Apache log4cxx
+* Copyright 2004-2007 The Apache Software Foundation
+*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT 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 "LogMessageBuffer.h"
+
+LogMessageBuffer::LogMessageBuffer()
+: stream(0)
+{
+}
+
+LogMessageBuffer::~LogMessageBuffer()
+{
+ if (stream)
+ {
+ delete stream;
+ }
+}
+
+LogMessageBuffer& LogMessageBuffer::operator<<(const std::basic_string<char>& msg)
+{
+ if (stream)
+ {
+ *stream << msg;
+ }
+ else
+ {
+ buf.append(msg);
+ }
+ return *this;
+}
+
+LogMessageBuffer& LogMessageBuffer::operator<<(const char* msg)
+{
+ const char* actualMsg = msg;
+ if (!actualMsg)
+ {
+ actualMsg = "null";
+ }
+
+ if (stream)
+ {
+ *stream << actualMsg;
+ }
+ else
+ {
+ buf.append(actualMsg);
+ }
+ return *this;
+}
+
+LogMessageBuffer& LogMessageBuffer::operator<<(char* msg)
+{
+ return operator<<((const char*) msg);
+}
+
+LogMessageBuffer& LogMessageBuffer::operator<<(const char msg)
+{
+ if (stream)
+ {
+ buf.assign(1, msg);
+ *stream << buf;
+ }
+ else
+ {
+ buf.append(1, msg);
+ }
+ return *this;
+}
+
+LogMessageBuffer::operator std::basic_ostream<char>&()
+{
+ if (!stream)
+ {
+ stream = new std::basic_ostringstream<char>();
+
+ if (!buf.empty())
+ {
+ *stream << buf;
+ }
+ }
+ return *stream;
+}
+
+const std::basic_string<char>& LogMessageBuffer::str(std::basic_ostream<char>&)
+{
+ buf = stream->str();
+ return buf;
+}
+
+const std::basic_string<char>& LogMessageBuffer::str() const
+{
+ return buf;
+}
+
+bool LogMessageBuffer::hasStream() const
+{
+ return (stream != 0);
+}
+
+std::ostream& LogMessageBuffer::operator<<(ios_base_manip manip)
+{
+ std::ostream& s = *this;
+ (*manip)(s);
+ return s;
+}
+
+std::ostream& LogMessageBuffer::operator<<(bool val)
+{
+ return ((std::ostream&) *this).operator<<(val);
+}
+
+std::ostream& LogMessageBuffer::operator<<(short val)
+{
+ return ((std::ostream&) *this).operator<<(val);
+}
+
+std::ostream& LogMessageBuffer::operator<<(int val)
+{
+ return ((std::ostream&) *this).operator<<(val);
+}
+
+std::ostream& LogMessageBuffer::operator<<(unsigned int val)
+{
+ return ((std::ostream&) *this).operator<<(val);
+}
+
+std::ostream& LogMessageBuffer::operator<<(long val)
+{
+ return ((std::ostream&) *this).operator<<(val);
+}
+
+std::ostream& LogMessageBuffer::operator<<(unsigned long val)
+{
+ return ((std::ostream&) *this).operator<<(val);
+}
+
+std::ostream& LogMessageBuffer::operator<<(float val)
+{
+ return ((std::ostream&) *this).operator<<(val);
+}
+
+std::ostream& LogMessageBuffer::operator<<(double val)
+{
+ return ((std::ostream&) *this).operator<<(val);
+}
+
+std::ostream& LogMessageBuffer::operator<<(long double val)
+{
+ return ((std::ostream&) *this).operator<<(val);
+}
+
+std::ostream& LogMessageBuffer::operator<<(void* val)
+{
+ return ((std::ostream&) *this).operator<<(val);
+}
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/src/ThreadBase.cpp b/ivi-layermanagement-examples/LayerManagerUtils/src/ThreadBase.cpp
new file mode 100644
index 0000000..202fd28
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/src/ThreadBase.cpp
@@ -0,0 +1,231 @@
+/***************************************************************************
+ *
+ * Copyright 2010,2011 BMW Car IT GmbH
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
+
+#include "ThreadBase.h"
+#include "Log.h"
+#include <stdlib.h>
+#include <pthread.h>
+#include <signal.h>
+
+//===========================================================================
+// internal data structures
+//===========================================================================
+struct ThreadArgument
+{
+ ThreadBase* obj;
+ pthread_mutex_t* initLock;
+ pthread_mutex_t* runLock;
+ t_ilm_bool* running;
+};
+
+//===========================================================================
+// static member initialization
+//===========================================================================
+unsigned int ThreadBase::mGlobalThreadCount = 1; // main thread already running
+
+//===========================================================================
+// global thread cleanup function (automatically called on thread shutwon)
+//===========================================================================
+static void threadBaseMainLoopCleanup(void* arg)
+{
+ // destroy in thread context
+ ((ThreadArgument*)arg)->obj->threadDestroyInThreadContext();
+ pthread_mutex_unlock(((ThreadArgument*)arg)->runLock);
+ *(((ThreadArgument*)arg)->running) = ILM_FALSE;
+ delete((ThreadArgument*)arg);
+}
+
+//===========================================================================
+// global thread loop function
+//===========================================================================
+static void* threadBaseMainLoop(void* arg)
+{
+ if (!arg)
+ {
+ LOG_ERROR("ThreadBase", "invalid thread argument (arg)");
+ return NULL;
+ }
+
+ if (!((ThreadArgument*)arg)->obj)
+ {
+ LOG_ERROR("ThreadBase", "invalid thread argument (obj)");
+ return NULL;
+ }
+
+ if (!((ThreadArgument*)arg)->running)
+ {
+ LOG_ERROR("ThreadBase", "invalid thread argument (running)");
+ return NULL;
+ }
+
+ // register cleanup function
+ pthread_cleanup_push(threadBaseMainLoopCleanup, arg);
+
+ // init in thread context
+ *(((ThreadArgument*)arg)->running) = ((ThreadArgument*)arg)->obj->threadInitInThreadContext();
+
+ // indicate initialization complete
+ pthread_mutex_unlock(((ThreadArgument*)arg)->initLock);
+
+ // wait for start permit
+ pthread_mutex_lock(((ThreadArgument*)arg)->runLock);
+
+ // run thread
+ while (*(((ThreadArgument*)arg)->running))
+ {
+ *(((ThreadArgument*)arg)->running) = ((ThreadArgument*)arg)->obj->threadMainLoop();
+ }
+
+ // execute cleanup handlers
+ pthread_cleanup_pop(1);
+
+ return NULL;
+}
+
+//===========================================================================
+// class implementation
+//===========================================================================
+ThreadBase::ThreadBase()
+: mThreadId(0)
+, mRunning(ILM_FALSE)
+{
+ pthread_mutex_init(&mRunLock, NULL);
+ pthread_mutex_lock(&mRunLock);
+
+ pthread_mutex_init(&mInitLock, NULL);
+ pthread_mutex_lock(&mInitLock);
+}
+
+ThreadBase::~ThreadBase()
+{
+ pthread_mutex_unlock(&mInitLock);
+ pthread_mutex_destroy(&mInitLock);
+
+ pthread_mutex_unlock(&mRunLock);
+ pthread_mutex_destroy(&mRunLock);
+}
+
+pthread_t ThreadBase::threadGetId() const
+{
+ return mThreadId;
+}
+
+t_ilm_bool ThreadBase::threadIsRunning()
+{
+ if (0 == pthread_mutex_trylock(&mRunLock))
+ {
+ pthread_mutex_unlock(&mRunLock);
+ mRunning = ILM_FALSE;
+ }
+ if (0 != pthread_kill(mThreadId, 0))
+ {
+ mRunning = ILM_FALSE;
+ }
+ return mRunning;
+}
+
+t_ilm_bool ThreadBase::threadCreate()
+{
+ pthread_attr_t notificationThreadAttributes;
+ pthread_attr_init(&notificationThreadAttributes);
+ pthread_attr_setdetachstate(&notificationThreadAttributes,
+ PTHREAD_CREATE_JOINABLE);
+
+ ThreadArgument* arg = new ThreadArgument();
+ arg->obj = this;
+ arg->runLock = &mRunLock;
+ arg->initLock = &mInitLock;
+ arg->running = &mRunning;
+
+ int ret = pthread_create(&mThreadId,
+ &notificationThreadAttributes,
+ threadBaseMainLoop,
+ (void*)arg);
+ if (0 != ret)
+ {
+ LOG_ERROR("ThreadBase", "Failed to start thread.");
+ }
+ else
+ {
+ ++mGlobalThreadCount;
+ LOG_DEBUG("ThreadBase", "Started thread (now " << mGlobalThreadCount << ")");
+ mRunning = ILM_TRUE;
+ }
+
+ return threadIsRunning();
+}
+
+t_ilm_bool ThreadBase::threadInit()
+{
+ return (0 == pthread_mutex_lock(&mInitLock)) ? ILM_TRUE : ILM_FALSE;
+}
+
+t_ilm_bool ThreadBase::threadStart()
+{
+ return (0 == pthread_mutex_unlock(&mRunLock)) ? ILM_TRUE : ILM_FALSE;
+}
+
+t_ilm_bool ThreadBase::threadStop()
+{
+ t_ilm_bool result = ILM_TRUE;
+
+ mRunning = threadIsRunning();
+
+ if (mRunning)
+ {
+ LOG_INFO("ThreadBase", "pthread_cancel");
+ if (0 != pthread_cancel(mThreadId))
+ {
+ LOG_ERROR("ThreadBase", "Stopping thread failed (cancel)");
+ result = ILM_FALSE;
+ }
+ else
+ {
+ LOG_INFO("ThreadBase", "pthread_join");
+ if (0 != pthread_join(mThreadId, NULL))
+ {
+ LOG_ERROR("ThreadBase", "Stopping thread failed (join)");
+ result = ILM_FALSE;
+ }
+ }
+ }
+
+ if (result)
+ {
+ --mGlobalThreadCount;
+ LOG_DEBUG("ThreadBase", "Stopped thread (now " << mGlobalThreadCount << ")");
+ }
+
+ return result;
+}
+
+//=====================================================================================
+// base implementation for overriding in inheriting classes
+//=====================================================================================
+t_ilm_bool ThreadBase::threadInitInThreadContext()
+{
+ LOG_DEBUG("ThreadBase", "threadInitInThreadContext (default implementation)");
+ return ILM_TRUE;
+}
+
+t_ilm_bool ThreadBase::threadDestroyInThreadContext()
+{
+ LOG_DEBUG("ThreadBase", "threadDestroyInThreadContext (default implementation)");
+ return ILM_TRUE;
+}
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/tests/BitmapTest.cpp b/ivi-layermanagement-examples/LayerManagerUtils/tests/BitmapTest.cpp
new file mode 100644
index 0000000..a02ee4f
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/tests/BitmapTest.cpp
@@ -0,0 +1,71 @@
+/***************************************************************************
+ *
+ * Copyright 2010,2011 BMW Car IT GmbH
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
+
+
+#include <gtest/gtest.h>
+#include <stdio.h>
+
+#include "Bitmap.h"
+
+#define WIDTH 1
+#define HEIGHT 1
+
+char* imageData = new char[3];
+
+bool fileExists(std::string filename)
+{
+ struct stat stFileInfo;
+ int status = stat(filename.c_str(),&stFileInfo);
+ return status == 0;
+}
+
+TEST(BitmapTest, WriteBitmapIntoCurrentDirectory) {
+ const char* filename = "test.bmp";
+ writeBitmap(filename, imageData, WIDTH, HEIGHT);
+
+ ASSERT_TRUE(fileExists(filename));
+}
+
+TEST(BitmapTest, WriteBitmapIntoAbsoluteDirectory) {
+ const char* filename = "/tmp/test2.bmp";
+ writeBitmap(filename, imageData, WIDTH, HEIGHT);
+
+ ASSERT_TRUE(fileExists(filename));
+}
+
+TEST(BitmapTest, WriteBitmapIntoNonExistingRelativeDirectory) {
+ const char* filename = "./testa/testb/testc/test2.bmp";
+ writeBitmap(filename, imageData, WIDTH, HEIGHT);
+
+ ASSERT_TRUE(fileExists(filename));
+}
+
+TEST(BitmapTest, WriteBitmapIntoNonExistingAbsoluteDirectory) {
+ const char* filename = "/tmp/testa/testb/test2.bmp";
+ writeBitmap(filename, imageData, WIDTH, HEIGHT);
+
+ ASSERT_TRUE(fileExists(filename));
+}
+
+TEST(BitmapTest, WriteToFileOrDirectoryNotAllowed) {
+ const char* invalidFile = "//invalid";
+ writeBitmap(invalidFile, imageData, 1, 1);
+
+ // this test ensures that if the bitmap is not writeable nothing else happens
+}
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/tests/CMakeLists.txt b/ivi-layermanagement-examples/LayerManagerUtils/tests/CMakeLists.txt
new file mode 100644
index 0000000..aaccf48
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/tests/CMakeLists.txt
@@ -0,0 +1,52 @@
+############################################################################
+#
+# Copyright 2010, 2011 BMW Car IT GmbH
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+############################################################################
+
+cmake_minimum_required (VERSION 2.6)
+
+if (WITH_TESTS)
+
+ enable_testing()
+
+ project(LayerManagerUtils_Test)
+ project_type(TEST)
+
+ set(LIBS
+ ${LIBS}
+ ${CMAKE_THREAD_LIBS_INIT}
+ LayerManagerUtils
+ dl
+ gtest
+ )
+
+ include_directories(${INCLUDE_DIRS})
+
+ add_executable(${PROJECT_NAME}
+ BitmapTest.cpp
+ LogTest.cpp
+ )
+
+ target_link_libraries(${PROJECT_NAME} ${LIBS})
+
+ install(TARGETS ${PROJECT_NAME}
+ DESTINATION bin
+ )
+
+ add_test(LayerManagerUtils ${PROJECT_NAME})
+
+endif(WITH_TESTS)
diff --git a/ivi-layermanagement-examples/LayerManagerUtils/tests/LogTest.cpp b/ivi-layermanagement-examples/LayerManagerUtils/tests/LogTest.cpp
new file mode 100644
index 0000000..013901c
--- /dev/null
+++ b/ivi-layermanagement-examples/LayerManagerUtils/tests/LogTest.cpp
@@ -0,0 +1,134 @@
+/***************************************************************************
+ *
+ * Copyright 2010,2011 BMW Car IT GmbH
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
+
+
+#include <gtest/gtest.h>
+#include <stdio.h>
+
+#include "Log.h"
+
+#define WIDTH 1
+#define HEIGHT 1
+
+std::string moduleName = "TheModuleName";
+std::string logFileName = "/tmp/LayerManagerService.log";
+int i=0;
+
+bool checkLogFileForMessage(std::string message)
+{
+ std::string line;
+ std::ifstream logFile(logFileName.c_str());
+
+ if (logFile.is_open())
+ {
+ while ( logFile.good() )
+ {
+ getline (logFile,line);
+ int position = line.find(message);
+ if (position >0)
+ return true;
+ }
+ logFile.close();
+ }
+ // did not find the message in any line of the logfile
+ return false;
+}
+
+
+TEST(LogTest, writeAWarning) {
+ Log::getInstance()->fileLogLevel = LOG_MAX_LEVEL;
+ LOG_WARNING(moduleName, "writeAWarning");
+
+ ASSERT_TRUE(checkLogFileForMessage("writeAWarning"));
+}
+
+TEST(LogTest, writeAnError) {
+ Log::getInstance()->fileLogLevel = LOG_INFO;
+ LOG_ERROR(moduleName, "writeAnError");
+
+ ASSERT_TRUE(checkLogFileForMessage("writeAnError"));
+}
+
+TEST(LogTest, writeAnInformation) {
+ Log::getInstance()->fileLogLevel = LOG_INFO;
+ LOG_INFO(moduleName, "writeAnInformation");
+
+ ASSERT_TRUE(checkLogFileForMessage("writeAnInformation"));
+}
+
+
+TEST(LogTest, logSomethingWithLowerLogLevel) {
+
+ // when disabled, nothing should ever be logged
+ Log::getInstance()->fileLogLevel = LOG_DISABLED;
+ LOG_ERROR(moduleName, "err1");
+ ASSERT_FALSE(checkLogFileForMessage("err1"));
+
+ LOG_DEBUG(moduleName, "debug1");
+ ASSERT_FALSE(checkLogFileForMessage("debug1"));
+
+ LOG_WARNING(moduleName, "warn1");
+ ASSERT_FALSE(checkLogFileForMessage("warn1"));
+
+ LOG_INFO(moduleName, "info1");
+ ASSERT_FALSE(checkLogFileForMessage("info1"));
+
+ // when error is set, only higher levels may be logged
+ Log::getInstance()->fileLogLevel = LOG_ERROR;
+ LOG_ERROR(moduleName, "err2");
+ ASSERT_TRUE(checkLogFileForMessage("err2"));
+
+ LOG_DEBUG(moduleName, "debug2");
+ ASSERT_FALSE(checkLogFileForMessage("debug2"));
+
+ LOG_WARNING(moduleName, "warn2");
+ ASSERT_FALSE(checkLogFileForMessage("warn2"));
+
+ LOG_INFO(moduleName, "info2");
+ ASSERT_FALSE(checkLogFileForMessage("info2"));
+
+ // when debug is set, only higher levels may be logged
+ Log::getInstance()->fileLogLevel = LOG_DEBUG;
+ LOG_ERROR(moduleName, "err3");
+ ASSERT_TRUE(checkLogFileForMessage("err3"));
+
+ LOG_DEBUG(moduleName, "debug3");
+ ASSERT_TRUE(checkLogFileForMessage("debug3"));
+
+ LOG_WARNING(moduleName, "warn3");
+ ASSERT_TRUE(checkLogFileForMessage("warn3"));
+
+ LOG_INFO(moduleName, "info3");
+ ASSERT_TRUE(checkLogFileForMessage("info3"));
+
+ // when info is set, only higher levels may be logged
+ Log::getInstance()->fileLogLevel = LOG_INFO;
+ LOG_ERROR(moduleName, "err4");
+ ASSERT_TRUE(checkLogFileForMessage("err4"));
+
+ LOG_DEBUG(moduleName, "debug4");
+ ASSERT_FALSE(checkLogFileForMessage("debug4"));
+
+ LOG_WARNING(moduleName, "warn4");
+ ASSERT_FALSE(checkLogFileForMessage("warn4"));
+
+ LOG_INFO(moduleName, "info4");
+ ASSERT_TRUE(checkLogFileForMessage("info4"));
+
+}