Add dummy plugin and build environment 70/213070/2
authorKichan Kwon <k_c.kwon@samsung.com>
Fri, 30 Aug 2019 01:01:14 +0000 (10:01 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Fri, 30 Aug 2019 04:43:59 +0000 (13:43 +0900)
Change-Id: Ic22e74ad0d60de9100d13c3ce64b3822ee0bdb81
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
CMakeLists.txt [new file with mode: 0644]
LICENSE [new file with mode: 0644]
NOTICE [new file with mode: 0644]
packaging/batterymonitor-plugins.manifest [new file with mode: 0644]
packaging/batterymonitor-plugins.spec [new file with mode: 0644]
plugin/dummy/CMakeLists.txt [new file with mode: 0644]
plugin/dummy/include/bm_dummy_plugin.h [new file with mode: 0644]
plugin/dummy/include/bm_dummy_util.h [new file with mode: 0644]
plugin/dummy/include/bm_log.h [new file with mode: 0644]
plugin/dummy/include/bm_plugin_interface.h [new file with mode: 0644]
plugin/dummy/src/bm_dummy_plugin.c [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..da6c9b1
--- /dev/null
@@ -0,0 +1,3 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+ADD_SUBDIRECTORY(plugin/dummy)
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..7ae2595
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,204 @@
+Copyright (c) 2015 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   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.
+
diff --git a/NOTICE b/NOTICE
new file mode 100644 (file)
index 0000000..ccdad52
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,3 @@
+Copyright (c) Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Apache License, Version 2.
+Please, see the LICENSE file for Apache License terms and conditions.
diff --git a/packaging/batterymonitor-plugins.manifest b/packaging/batterymonitor-plugins.manifest
new file mode 100644 (file)
index 0000000..97e8c31
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+       <request>
+               <domain name="_"/>
+       </request>
+</manifest>
diff --git a/packaging/batterymonitor-plugins.spec b/packaging/batterymonitor-plugins.spec
new file mode 100644 (file)
index 0000000..7e7ed39
--- /dev/null
@@ -0,0 +1,55 @@
+Name:       batterymonitor-plugins
+Summary:    Battery-Monitor plugins
+Version:    0.1
+Release:    1
+Group:      Service/Battery
+License:    Apache-2.0
+Source0:    %{name}-%{version}.tar.gz
+Source1001: %{name}.manifest
+
+BuildRequires:  cmake
+BuildRequires:  pkgconfig(aul)
+BuildRequires:  pkgconfig(dlog)
+BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(libtzplatform-config)
+
+Requires(post):  /sbin/ldconfig
+Requires(postun):  /sbin/ldconfig
+
+%define BATTERY_MONITOR_LIBDIR %{_libdir}/batterymonitor/plugins
+
+%description
+Battery-Monitor plugins
+
+%package dummy
+Summary:  Battery-Monitor dummy plugin
+
+%description dummy
+Dummy plugin for Battery-Monitor
+
+%prep
+%setup -q
+cp %{SOURCE1001} .
+
+%build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+cmake .        \
+       -DFULLVER=%{version}    \
+       -DMAJORVER=${MAJORVER}  \
+       -DBATTERY_MONITOR_LIBDIR=%{BATTERY_MONITOR_LIBDIR}
+
+make %{?jobs:-j%jobs}
+
+%install
+mkdir -p %{buildroot}%{BATTERY_MONITOR_LIBDIR}
+%make_install
+
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+%files dummy
+%manifest %{name}.manifest
+%license LICENSE
+%{BATTERY_MONITOR_LIBDIR}/lib%{name}-dummy*
diff --git a/plugin/dummy/CMakeLists.txt b/plugin/dummy/CMakeLists.txt
new file mode 100644 (file)
index 0000000..80305fc
--- /dev/null
@@ -0,0 +1,33 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT("batterymonitor-plugins-dummy" C)
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(PKG_MODULES
+       aul
+       dlog
+       glib-2.0
+)
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${PROJECT_NAME} REQUIRED ${PKG_MODULES})
+
+FOREACH(flag ${${PROJECT_NAME}_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror -fvisibility=hidden")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+SET(SOURCES
+       src/bm_dummy_plugin.c
+)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SOURCES})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${${PROJECT_NAME}_LDFLAGS})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES
+               VERSION ${FULLVER} SOVERSION ${MAJORVER} CLEAN_DIRECT_OUTPUT 1)
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BATTERY_MONITOR_LIBDIR})
diff --git a/plugin/dummy/include/bm_dummy_plugin.h b/plugin/dummy/include/bm_dummy_plugin.h
new file mode 100644 (file)
index 0000000..1a5f6e2
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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 __BM_DUMMY_PLUGIN_H__
+#define __BM_DUMMY_PLUGIN_H__
+
+#include <gmodule.h>
+#include <time.h>
+#include <bm_plugin_interface.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * battery-monitor data handle
+ */
+typedef void *bm_display_data_h;
+
+#ifdef ENABLE /* these structures are defined in common plugin interface */
+/*
+ * alias for long data types
+ */
+typedef unsigned int           uint;
+typedef unsigned char          uchar;
+
+/*
+ * structure for application time map.
+ */
+typedef struct {
+       char *app_id;                   /* application id */
+       uint time;                      /* total duration for which application as active */
+} app_time_map_st1;
+
+/*
+ * structure for "display" feature data.
+ */
+typedef struct {
+       uint high;                      /* time in milliseconds during which brightness intensity was high */
+       uint low;                       /* time in milliseconds during which brightness intensity was low */
+       uint med;                       /* time in milliseconds during which brightness intensity was medium */
+       time_t start;                   /* start time of feature data collection session */
+       time_t stop;                    /* stop time of feature data collection session */
+       GSList *atm_list;               /* application time map('app_time_map_st') list for all active applications between start & stop */
+       GSList *display_list;           /* list of nodes of 'bm_display_st' for next consecutive sessions */
+} bm_display_st;
+#endif /* end ENABLE */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BM_DUMMY_PLUGIN_H__ */
+
+
diff --git a/plugin/dummy/include/bm_dummy_util.h b/plugin/dummy/include/bm_dummy_util.h
new file mode 100644 (file)
index 0000000..136006b
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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 __BM_DUMMY_UTIL_H__
+#define __BM_DUMMY_UTIL_H__
+
+#include <stdlib.h>
+#include <tizen.h>
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NAME           "dummy_plugin"
+#define AUTHOR         "SAMSUNG"
+#define VERSION                "0.1"
+
+#define BUFFER_SZ      200
+
+#define STATUS_SUCCESS         1
+#define STATUS_FAILURE         0
+
+
+#define BMP_RETURN_VAL(eval, expr, ret_val, X) \
+       if (!(eval)) { \
+               expr; \
+               return ret_val; \
+       } else {}
+
+#define BMP_SNPRINTF(dest, size, format, arg...) \
+       do { \
+               snprintf(dest, size-1, format, ##arg); \
+       } while (0)
+
+#define BMP_MEMSET(dest, value, size) \
+       do { \
+               memset(dest, value, size); \
+       } while (0)
+
+#define BMP_CATCH_ERROR(eval, expr, error_val, X) \
+       if (!(eval)) { \
+               expr; \
+               error_code = (error_val); \
+               goto CATCH; \
+       } else {}
+
+#define BMP_CATCH_ERROR_P(eval, expr, error_val, X) \
+       if (!(eval)) { \
+               expr; \
+               *error_code = (error_val); \
+               goto CATCH; \
+       } else { }
+
+#define BMP_FREE(ptr)ptr \
+       if (ptr != NULL) { \
+               free(ptr); \
+               ptr = NULL; \
+       } \
+
+#define BMP_GFREE(ptr)ptr \
+       if (ptr != NULL) { \
+               g_free(ptr); \
+               ptr = NULL; \
+       } \
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BM_DUMMY_UTIL_H__ */
+
+
diff --git a/plugin/dummy/include/bm_log.h b/plugin/dummy/include/bm_log.h
new file mode 100644 (file)
index 0000000..c497fa7
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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 __BM_LOG_H__
+#define __BM_LOG_H__
+
+#include <dlog.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "BM_DUMMY"
+
+#ifndef _BME
+#define _E(fmt, args...) LOGE("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)
+#endif
+
+#ifndef _BMD
+#define _D(fmt, args...) LOGD("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)
+#endif
+
+#ifndef _BMI
+#define _I(fmt, args...) LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)
+#endif
+
+#ifndef _BMW
+#define _W(fmt, args...) LOGW("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)
+#endif
+
+#define ENTER dlog_print(DLOG_DEBUG, LOG_TAG, "%s : %s(%d) >>>>>>>> called", rindex(__FILE__, '/') + 1, __func__, __LINE__)
+#define EXIT  dlog_print(DLOG_DEBUG, LOG_TAG, "%s : %s(%d) <<<<<<<< ended", rindex(__FILE__, '/') + 1, __func__, __LINE__)
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BM_LOG_H__ */
+
+
diff --git a/plugin/dummy/include/bm_plugin_interface.h b/plugin/dummy/include/bm_plugin_interface.h
new file mode 100644 (file)
index 0000000..a722542
--- /dev/null
@@ -0,0 +1,286 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved.
+ *
+ * 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 __BM_PLUGIN_INTERFACE_H__
+#define __BM_PLUGIN_INTERFACE_H__
+
+#include <stdio.h>
+#include <gmodule.h>
+#include <time.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef unsigned int   uint;
+typedef unsigned char  uchar;
+
+#define BM_DATA_TYPE_MAX (BM_DATA_TYPE_BATTERY + 1)
+#define BM_PLUGIN_ID_MAX (BM_PLUGIN_ID_BATTERY + 1)
+#define BM_DURATION_TYPE_MAX (BM_DURATION_TYPE_1WEEK + 1)
+
+typedef enum {
+       BM_PLUGIN_ERROR_NONE = TIZEN_ERROR_NONE,                                /**< Successful */
+       BM_PLUGIN_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA,                          /**< No data */
+       BM_PLUGIN_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,      /**< Invalid parameter */
+       BM_PLUGIN_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,              /**< Out of memory */
+       BM_PLUGIN_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED,              /**< Not supported */
+       BM_PLUGIN_ERROR_SERVICE_UNAVAILABLE = TIZEN_ERROR_UNKNOWN - 1           /**< Service unavailable */
+} bm_plugin_error_e;
+
+/*
+ * enum for plugin identifier
+ */
+typedef enum {
+       BM_PLUGIN_ID_BLE=0,             /**< Bluetooth Low Energy */
+       BM_PLUGIN_ID_WIFI,              /**< Wi-Fi */
+       BM_PLUGIN_ID_CPU,               /**< CPU */
+       BM_PLUGIN_ID_DISPLAY,           /**< Display */
+       BM_PLUGIN_ID_DEVICE_NETWORK,    /**< Network */
+       BM_PLUGIN_ID_GPS_SENSOR,        /**< GPS */
+       BM_PLUGIN_ID_HRM_SENSOR,        /**< Heart Rate Monitor */
+       BM_PLUGIN_ID_BATTERY            /**< Battery */
+} bm_plugin_id_e;
+
+/*
+ * enum for feature data collection period
+ */
+typedef enum {
+       BM_DURATION_TYPE_1DAY = 0,      /**< Set the period from a day ago to now */
+       BM_DURATION_TYPE_1WEEK          /**< Set the period from a week ago to now */
+} bm_duration_type_e;
+
+/*
+ * enum for feature data type
+ */
+typedef enum {
+       BM_DATA_TYPE_BLE=0,             /**< Bluetooth Low Energy */
+       BM_DATA_TYPE_WIFI,              /**< Wi-Fi */
+       BM_DATA_TYPE_CPU,               /**< CPU */
+       BM_DATA_TYPE_DISPLAY,           /**< Display */
+       BM_DATA_TYPE_DEVICE_NETWORK,    /**< Network */
+       BM_DATA_TYPE_GPS_SENSOR,        /**< GPS */
+       BM_DATA_TYPE_HRM_SENSOR,        /**< Heart Rate Monitor */
+       BM_DATA_TYPE_BATTERY            /**< Battery */
+} bm_plugin_data_type_e;
+
+/*
+ * common structure for application time map.
+ */
+typedef struct {
+       char *app_id;           /**< application id */
+       uint time;              /**< total duration for which application as active */
+} app_time_map_st1;
+
+typedef struct {
+       char *app_id;           /**< application id */
+       uint time;              /**< total duration for which application as active */
+       uint rx;                /**< Total Bytes received by the application during runtime */
+       uint tx;                /**< Total Bytes transmitted by the application during runtime */
+} app_time_map_st2;
+
+/*
+ * structure for "display" feature data.
+ */
+typedef struct {
+       uint high;                      /**< total time in milliseconds during which brightness intensity was high */
+       uint low;                       /**< total time in milliseconds during which brightness intensity was low */
+       uint med;                       /**< total time in milliseconds during which brightness intensity was medium */
+       time_t start;                   /**< start time of feature data collection session */
+       time_t stop;                    /**< stop time of feature data collection session */
+       GSList *atm_list;               /**< application time map('app_time_map_st1') list for all active applications between start & stop */
+       GSList *display_list;           /**< list of nodes of 'bm_display_st' for next consecutive sessions */
+} bm_display_st;
+
+/*
+ * structure for "cpu" feature data.
+ */
+typedef struct {
+       uint cpuTicks;                  /**< CPU Usage during the session */
+       uint cpuTimeBackground;         /**< Time spent in Background State average operating frequency will be used to calculate the power */
+       uint cpuTimeForeground;         /**< Time spent in Foreground state average operating frequency will be used to calculate the power */
+       GSList *atm_list;               /**< application time map('app_time_map_st1') list for all active applications between start & stop */
+       GSList *cpu_data_list;          /**< list of nodes of 'bm_cpu_st' for next consecutive sessions */
+} bm_cpu_st;
+
+/*
+ * structure for "device_network" feature data.
+ */
+typedef struct {
+       uint time_level_0;              /**< Total time in milliseconds during which signal_strength was on level 0 */
+       uint time_level_1;              /**< Total time in milliseconds during which signal_strength was on level 1 */
+       uint time_level_2;              /**< Total time in milliseconds during which signal_strength was on level 2 */
+       uint time_level_3;              /**< Total time in milliseconds during which signal_strength was on level 3 */
+       uint time_level_4;              /**< Total time in milliseconds during which signal_strength was on level 4 */
+       uint time_level_5;              /**< Total time in milliseconds during which signal_strength was on level 5 */
+       uint time_level_6;              /**< Total time in milliseconds during which signal_strength was on level 6 */
+       GSList *atm_list;               /**< application time map('app_time_map_st2') list for all active applications between start & stop */
+       GSList *dn_data_list;           /**< list of nodes of 'bm_device_network_st' for next consecutive sessions */
+} bm_device_network_st;
+
+/*
+ * structure for "Wi-Fi" feature data.
+ */
+typedef struct {
+       uint time_level_0;              /**< Total time in milliseconds during which rssi was on level 0 */
+       uint time_level_1;              /**< Total time in milliseconds during which rssi was on level 1 */
+       uint time_level_2;              /**< Total time in milliseconds during which rssi was on level 2 */
+       uint time_level_3;              /**< Total time in milliseconds during which rssi was on level 3 */
+       uint time_level_4;              /**< Total time in milliseconds during which rssi was on level 4 */
+       time_t startTime;               /**< start time of feature data collection session */
+       time_t endTime;                 /**< end time of feature data collection session */
+       uint scanTime;                  /**< Total time spent by the resource in (scan) mode during the session */
+       GSList *atm_list;               /**< application time map('app_time_map_st2') list for all active applications between start & stop */
+       GSList *wifi_data_list;         /**< list of nodes of 'bm_wifi_st' for next consecutive sessions */
+} bm_wifi_st;
+
+/*
+ * structure for "bluetooth" feature data.
+ */
+typedef struct {
+       uint scanTime;                  /**< Total time spent by the resource in (scan) mode during the session */
+       uint connectedTime;             /**< Total time spent by the resource in (connected) mode during the session */
+       time_t startTime;               /**< start time of feature data collection session */
+       time_t stopTime;                /**< stop time of feature data collection session */
+       GSList *atm_list;               /**< application time map('app_time_map_st2') list for all active applications between start & stop */
+       GSList *bt_data_list;           /**< list of nodes of 'bm_bluetooth_st' for next consecutive sessions */
+} bm_bluetooth_st;
+
+/*
+ * structure for "gps" feature data.
+ */
+typedef struct {
+       time_t connStartTime;           /**< start time of feature data collection session */
+       time_t connStopTime;            /**< stop time of feature data collection session */
+       GSList *atm_list;               /**< application time map('app_time_map_st1') list for all active applications between start & stop */
+       GSList *gps_data_list;          /**< list of nodes of 'bm_gps_st' for next consecutive sessions */
+} bm_gps_st;
+
+/*
+ * structure for "hrm-sensor" feature data.
+ */
+typedef struct {
+       uint sensor_hub_wakeup_time;    /**< wake-up time of sensor-hub */
+       uint sensor_hub_wakeup_count;   /**< wake-up count of sensor-hub */
+       uint sensor_wakeup_time;        /**< sensor wake-up time */
+       uint sensor_wakeup_count;       /**< sensor wake-up count */
+       GSList *atm_list;               /**< application time map('app_time_map_st1') list for all active applications between start & stop */
+       GSList *hrm_data_list;          /**< list of nodes of 'bm_hrm_sensor_st' for next consecutive sessions */
+} bm_hrm_sensor_st;
+
+/*
+ * structure for "battery" feature data.
+ */
+typedef struct {
+       uint battery_percent;           /**< Battery percent */
+       uint is_charging;               /**< State of charging */
+} bm_battery_st;
+
+/* ========================================================================== */
+
+/*
+ * battery-monitor data handle
+ */
+typedef void *bm_data_h;
+
+/*
+ * Callback to be invoked when service is going OFF
+ *
+ * [Param] handle - handle through which service will provide data
+ *        to battery-monitor service daemon.
+ *
+ * [Param] result - the result of callback operation
+ */
+typedef void (*bm_data_callback)(bm_plugin_error_e result, bm_data_h *handle);
+
+/*
+ * battery-monitor callback structure
+ */
+typedef struct {
+       bm_data_callback provide_feature_data;
+} bm_callbacks_st;
+
+/*
+ * structure for plugin API's
+ */
+typedef struct {
+       /*
+       * [Sync API] To initialize plugin
+       */
+       int (*init)(const bm_callbacks_st *callbacks);
+       /*
+       * [Sync API] To deinitialize plugin
+       */
+       int (*deinit)(void);
+       /*
+       * [Sync API] To get feature data from plugin
+       *
+       * [Param] handle - battery-monitor data handle through which plugin
+       *       will provide data to the manager. This handle will be passed
+       *       as reference, plugin will assign a valid object which will be
+       *       set free by the manager; battery-monitor manager will typecast
+       *       the object provided through handle for each plugin and will use
+       *       it for further calculation.
+       *
+       * [Param] data_type - type of data like - BLE, WiFi, CPU etc.
+       */
+       int (*get_feature_data)(bm_data_h *handle, bm_plugin_data_type_e data_type);
+} bm_api_st;
+
+/*
+ * structure for plugin information
+ */
+typedef struct {
+       /*
+       * Respective "identifier" of Plugin
+       */
+       int id;
+       /*
+       * Respective "name" of Plugin
+       */
+       const char *name;
+       /*
+       * Respective "author" of Plugin
+       */
+       const char *author;
+       /*
+       * Respective "version" of Plugin
+       */
+       const char *version;
+       /*
+       * Plugin init function
+       */
+       int (*init)(bm_api_st **api);
+       /*
+       * Plugin de-init function
+       */
+       int (*deinit)(void);
+} bm_plugin_st;
+
+
+/*
+ *  macro for adding plugin
+ */
+#define BM_PLUGIN_ADD(id, name, author, version, init, deinit) \
+               bm_plugin_st bm_plugin = { id, name, author, version, init, deinit };
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BM_PLUGIN_INTERFACE_H__ */
diff --git a/plugin/dummy/src/bm_dummy_plugin.c b/plugin/dummy/src/bm_dummy_plugin.c
new file mode 100644 (file)
index 0000000..8d62cfc
--- /dev/null
@@ -0,0 +1,253 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <aul.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "bm_dummy_plugin.h"
+#include "bm_dummy_util.h"
+#include "bm_log.h"
+
+#ifdef FOR_ON_DEMAND_SERVICES
+const bm_callbacks_st *cb;
+#endif
+
+/*
+ * To get AppID from PID - Needs to be handled by the respective framework owners:
+ * The PID might become outdated by the time data is read, which will create problems in mapping the application.
+ * Sample API's and fucntion is provided below to get app-id based on available pid.
+ *     char *strAppId = NULL;
+ *     pid_t nProcessId = getpid();
+ *     app_manager_get_app_id(nProcessId, &strAppId);
+ */
+static char* get_current_appid(int pid, uid_t uid)
+{
+       ENTER;
+       _I("getting caller appid with pid=[%d], uid=[%d]", pid, uid);
+
+       int ret = 0;
+       char appid[128] = {0, };
+       char *appid_ret = NULL;
+
+       ret = aul_app_get_appid_bypid_for_uid(pid, appid, sizeof(appid), uid);
+
+       if (ret < 0)
+               _E("fail to get current appid ret=[%d], appid=%s\n", ret, appid);
+
+       appid_ret = strdup(appid);
+       if (appid_ret == NULL)
+               _E("Memory Allocation Failed");
+
+       EXIT;
+       return appid_ret;
+}
+
+
+static int get_record_count()
+{
+       ENTER;
+
+/*     implementation for getting record count from db-storage/buffer */
+
+       EXIT;
+       return 0;
+}
+
+static int get_app_count()
+{
+       ENTER;
+
+/*     implementation for getting application count from db-storage/buffer */
+
+       EXIT;
+       return 0;
+}
+
+#ifdef FOR_ON_DEMAND_SERVICES
+static int on_service_closing()
+{
+       ENTER;
+
+       /* create data handle */
+       bm_display_st *data_h = calloc(1, sizeof(bm_display_st));
+       if (data_h == NULL) {
+               _E("memory allocation failed");
+               return -1;
+       }
+
+       // populate data node here with data & the call the function - provide_feature_data()
+       // this function's handler is implemented at battery-monitor server.
+
+       if (cb != NULL && cb->provide_feature_data)
+               cb->provide_feature_data(BM_PLUGIN_ERROR_NONE, (void *)data_h);
+
+       // the memory provided to 'data_h' will be set free by server.
+
+       EXIT;
+       return 0;
+}
+#endif /* FOR_ON_DEMAND_SERVICES end */
+
+int init(const bm_callbacks_st *callbacks)
+{
+       ENTER;
+
+       if (!callbacks) {
+               _E("invalid input param");
+               return -1;
+       }
+
+/*     Initialize the necessary paramters and callbacks if required */
+
+#ifdef FOR_ON_DEMAND_SERVICES
+/*     handle callbacks */
+       cb = callbacks;
+#endif
+
+       EXIT;
+       return STATUS_SUCCESS;
+}
+
+int deinit()
+{
+       ENTER;
+
+/*     De-initialize callbacks & parameters */
+
+       EXIT;
+       return STATUS_SUCCESS;
+}
+
+int get_feature_data(bm_data_h *handle, bm_plugin_data_type_e type)
+{
+       ENTER;
+
+/*################################################# SAMPLE APPROACH #####################################################################*/
+#if 0
+>-----Fill in the details of the resource into the handle
+
+       There are two list:
+                       1) Comprising of the resource usage parameters between a certain start/stop time pair.
+                       2) Comprising of the application using that resource along with the usage time, nested under the (1) list.
+
+       Populating the structures by making the linked list of the below common structures
+
+       FOR EXAMPLE:
+               Structure for "display" feature data.
+
+               typedef struct {
+                       uint high;              /* Total time in milliseconds during which brightness intensity was high */
+                       uint low;               /* Total time in milliseconds during which brightness intensity was low */
+                       uint med;               /* Total time in milliseconds during which brightness intensity was medium */
+                       time_t start;           /* Start time of feature data collection session */
+                       time_t stop;            /* Stop time of feature data collection session */
+                       GSList *atm_list;       /* Application time map('app_time_map_st1') list for all active applications between start & stop */
+                       GSList *display_list;   /* List of nodes of 'bm_display_st' for next consecutive sessions */
+               } bm_display_st;
+
+
+       Common structures for application time map.
+
+               typedef struct {
+                       char *app_id;           /* Application Id */
+                       uint time;              /* Total duration for which application as active */
+               } app_time_map_st1;
+#endif
+
+       int uid = 0;
+       char *app_id = get_current_appid(getpid(), uid);
+       if (!app_id) {
+               _E("failed to get app_id\n");
+               return 0;
+       }
+
+       _I("current app_id = %s\n", app_id);
+
+       GSList *display_list = NULL;
+       bm_display_st *display_record = NULL;
+       app_time_map_st1 *app_record = NULL;
+
+       /* Number of record entries for the resource */
+       int rec_count = get_record_count();
+
+       for(int i=0; i<rec_count; i++) {
+
+               display_record = (bm_display_st*)calloc(1,sizeof(bm_display_st));
+               if(display_record == NULL) {
+                       _E("Calloc Failed");
+                       break;
+               }
+
+               /* Fill display record with the values of the bm_display_st */
+               display_list = g_slist_append(display_list, display_record);
+
+               GSList *app_list = NULL;
+               app_list = display_record->atm_list;
+
+               /* Number of apps in the "atm_list" */
+               int app_count = get_app_count();
+
+               for(int j=0; j<app_count; j++) {
+
+                       app_record = (app_time_map_st1*)calloc(1,sizeof(app_time_map_st1));
+                       if(app_record == NULL) {
+                               _E("Calloc Failed");
+                               break;
+                       }
+
+                       /* populate application record here with usage values */
+
+                       /* Fill the app_record with the values of the app_time_map_st1 */
+                       app_list = g_slist_append(app_list, app_record);
+               }
+       }
+
+       *handle = display_list;
+
+       EXIT;
+       return STATUS_SUCCESS;
+}
+
+static bm_api_st display_api = {
+       .init = init,
+       .deinit = deinit,
+       .get_feature_data = get_feature_data
+};
+
+int plugin_init(bm_api_st ** api)
+{
+       ENTER;
+
+       *api = &display_api;
+
+       EXIT;
+       return 0;
+}
+
+int plugin_deinit(void)
+{
+       ENTER;
+
+       EXIT;
+       return 0;
+}
+
+BM_PLUGIN_ADD(BM_PLUGIN_ID_DISPLAY, NAME, AUTHOR, VERSION, plugin_init, plugin_deinit);