INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/lib)
SET(PKG_MODULES
dlog
INSTALL(FILES ${CMAKE_SOURCE_DIR}/systemd/org.tizen.system.pass.service DESTINATION /usr/share/dbus-1/system-services)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/systemd/org.tizen.system.thermal.service DESTINATION /usr/share/dbus-1/system-services)
-CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/packaging/${PROJECT_NAME}.pc.in
- ${CMAKE_CURRENT_SOURCE_DIR}/packaging/${PROJECT_NAME}.pc
- @ONLY)
-INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/packaging/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/systemd/ DESTINATION lib/systemd/system
FILES_MATCHING
PATTERN "*.service"
)
ADD_SUBDIRECTORY(unittest)
+ADD_SUBDIRECTORY(lib)
+++ /dev/null
-/*
- * PASS (Power Aware System Service) - Header file of Unified Resource Monitor
- *
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
-
-/**
- * @file monitor.h
- * @brief Define the data structure for Unified Resource Monitor
- * @ingroup COM_POWER_MGNT
- */
-
-#include <hal/hal-power.h>
-
-#ifndef __MONITOR_INTERNAL__
-#define __MONITOR_INTERNAL__
-
-#define BIT(x) (1ULL << x)
-#define RESOURCE_ATTR_MASK (ULLONG_MAX)
-#define RESOURCE_ATTR_INDEX(id) (63 - __builtin_clzll(id))
-
-enum monitor_data_type {
- DATA_TYPE_UNKNOWN = 0,
- DATA_TYPE_INT,
- DATA_TYPE_DOUBLE,
- DATA_TYPE_STRING,
- DATA_TYPE_ARRAY,
-
- DATA_TYPE_NUM
-};
-
-/* CPU attributes */
-#define CPU_CUR_FREQ BIT(0)
-#define CPU_MIN_FREQ BIT(1)
-#define CPU_MAX_FREQ BIT(2)
-#define CPU_AVAILABLE_MIN_FREQ BIT(3)
-#define CPU_AVAILABLE_MAX_FREQ BIT(4)
-#define CPU_CUR_GOVERNOR BIT(5)
-#define CPU_ONLINE_CPU BIT(6)
-#define CPU_TEMPERATURE BIT(7)
-
-/* BUS attributes */
-#define BUS_CUR_FREQ BIT(0)
-#define BUS_MIN_FREQ BIT(1)
-#define BUS_MAX_FREQ BIT(2)
-#define BUS_AVAILABLE_MIN_FREQ BIT(3)
-#define BUS_AVAILABLE_MAX_FREQ BIT(4)
-#define BUS_CUR_GOVERNOR BIT(5)
-
-/* GPU attributes */
-#define GPU_CUR_FREQ BIT(0)
-#define GPU_MIN_FREQ BIT(1)
-#define GPU_MAX_FREQ BIT(2)
-#define GPU_AVAILABLE_MIN_FREQ BIT(3)
-#define GPU_AVAILABLE_MAX_FREQ BIT(4)
-#define GPU_CUR_GOVERNOR BIT(5)
-#define GPU_TEMPERATURE BIT(6)
-
-/* MEMORY attributes */
-#define MEMORY_TOTAL BIT(0)
-#define MEMORY_AVAILABLE BIT(1)
-#define MEMORY_FREE BIT(2)
-#define MEMORY_FAULT_AROUND_BYTES BIT(3)
-
-/* BATTERY attributes */
-#define BATTERY_CAPACITY BIT(0)
-#define BATTERY_CHARGING_STATUS BIT(1)
-#define BATTERY_TEMPERATURE BIT(2)
-
-#endif /* __MONITOR_INTERNAL__ */
#include <glib.h>
#include "common.h"
+enum monitor_data_type {
+ DATA_TYPE_UNKNOWN = 0,
+ DATA_TYPE_INT,
+ DATA_TYPE_DOUBLE,
+ DATA_TYPE_STRING,
+ DATA_TYPE_ARRAY,
+
+ DATA_TYPE_NUM
+};
+
struct resource;
struct resource_attribute;
--- /dev/null
+PROJECT(libpass C)
+
+SET(NAME pass)
+SET(VERSION_MAJOR 0)
+SET(VERSION "${VERSION_MAJOR}.1.0")
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "${PREFIX}/bin")
+SET(INCLUDEDIR "${PREFIX}/include")
+SET(LIBDIR ${CMAKE_LIBDIR_PREFIX})
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
+
+SET(PKG_MODULES
+ dlog
+ gio-2.0
+ glib-2.0
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED ${PKG_MODULES})
+
+FOREACH(flag ${pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIC")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -lrt")
+SET(CMAKE_EXE_LINKER_FLAGS "-pie")
+
+SET(SRCS ./tmonitor/tmonitor.c)
+
+ADD_LIBRARY( ${PROJECT_NAME} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${pkgs_LDFLAGS} -ldl -Wl,-z,nodelete,--no-undefined)
+SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES VERSION ${VERSION})
+SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${NAME})
+
+CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/packaging/${NAME}.pc.in
+ ${CMAKE_SOURCE_DIR}/packaging/${NAME}.pc
+ @ONLY)
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIBDIR})
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tmonitor/
+ DESTINATION ${INCLUDEDIR}/${NAME}/
+ FILES_MATCHING PATTERN "*.h")
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/packaging/${NAME}.pc
+ DESTINATION ${LIBDIR}/pkgconfig)
--- /dev/null
+/*
+ * PASS (Power Aware System Service) - Tizen Monitor Library
+ *
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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 <glib.h>
+
+#define _GNU_SOURCE
+#include <errno.h>
+
+extern char *program_invocation_name;
+
+#ifndef EXPORT
+#define EXPORT __attribute__ ((visibility("default")))
+#endif
+
+EXPORT
+int tmonitor_init(int period, int (*func)(void *data, void* user_data), void *user_data)
+{
+ /* TODO */
+ return 0;
+}
+
+EXPORT
+void tmonitor_exit(int id)
+{
+ /* TODO */
+}
+
+EXPORT
+int tmonitor_set_attrs(int id, int resource_type, u_int64_t attr_mask)
+{
+ /* TODO */
+ return 0;
+}
+
+EXPORT
+int tmonitor_get_available_attrs(int id, int resource_type,
+ int *available_attrs[], int *num_attrs)
+{
+ /* TODO */
+ return 0;
+}
+
+EXPORT
+int tmonitor_start(int id)
+{
+ /* TODO */
+ return 0;
+}
+
+EXPORT
+void tmonitor_stop(int id)
+{
+ /* TODO */
+}
+
+EXPORT
+int tmonitor_update(int id)
+{
+ /* TODO */
+ return 0;
+}
+
+EXPORT
+int tmonitor_get_value_int(int id, int resource_type, u_int64_t attr)
+{
+ /* TODO */
+ return 0;
+}
+
+EXPORT
+int tmonitor_get_resource_num(int id, int resource_type)
+{
+ /* TODO */
+ return 0;
+}
--- /dev/null
+/*
+ * PASS (Power Aware System Service) - Tizen Monitor Header File
+ *
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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 __TMONITOR__
+#define __TMONITOR__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define BIT(x) (1ULL << x)
+
+/**
+ * @brief Define the supported resource type for monitoring
+ */
+#define RESOURCE_TYPE_UNKNOWN 0
+#define RESOURCE_TYPE_CPU 1
+#define RESOURCE_TYPE_BUS 2
+#define RESOURCE_TYPE_GPU 3
+#define RESOURCE_TYPE_MEMORY 4
+#define RESOURCE_TYPE_BATTERY 5
+#define RESOURCE_TYPE_PROCESS 6
+#define RESOURCE_TYPE_NONSTANDARD 99
+
+/**
+ * @brief Define the supported attributes according to resource type
+ */
+#define CPU_CUR_FREQ BIT(0)
+#define CPU_MIN_FREQ BIT(1)
+#define CPU_MAX_FREQ BIT(2)
+#define CPU_AVAILABLE_MIN_FREQ BIT(3)
+#define CPU_AVAILABLE_MAX_FREQ BIT(4)
+#define CPU_CUR_GOVERNOR BIT(5)
+#define CPU_ONLINE_CPU BIT(6)
+#define CPU_TEMPERATURE BIT(7)
+
+#define BUS_CUR_FREQ BIT(0)
+#define BUS_MIN_FREQ BIT(1)
+#define BUS_MAX_FREQ BIT(2)
+#define BUS_AVAILABLE_MIN_FREQ BIT(3)
+#define BUS_AVAILABLE_MAX_FREQ BIT(4)
+#define BUS_CUR_GOVERNOR BIT(5)
+
+#define GPU_CUR_FREQ BIT(0)
+#define GPU_MIN_FREQ BIT(1)
+#define GPU_MAX_FREQ BIT(2)
+#define GPU_AVAILABLE_MIN_FREQ BIT(3)
+#define GPU_AVAILABLE_MAX_FREQ BIT(4)
+#define GPU_CUR_GOVERNOR BIT(5)
+#define GPU_TEMPERATURE BIT(6)
+
+#define MEMORY_TOTAL BIT(0)
+#define MEMORY_AVAILABLE BIT(1)
+#define MEMORY_FREE BIT(2)
+#define MEMORY_FAULT_AROUND_BYTES BIT(3)
+
+#define BATTERY_CAPACITY BIT(0)
+#define BATTERY_CHARGING_STATUS BIT(1)
+#define BATTERY_TEMPERATURE BIT(2)
+
+/**
+ * @brief Initialize the tizen monitor
+ * @param[in] Timer period (unit: millisecond, minimum value is 100ms)
+ * @param[in] Timer callback function
+ * @param[in] User data be passed to timer callback function
+ * @return @c positive integer on success, otherwise a negative error value
+ */
+int tmonitor_init(int period, int (*func)(void *data, void* user_data), void *user_data);
+
+/**
+ * @brief Exit the tizem monitor
+ * @param[in] Unique id of tizen monitor which be returnted by tmonitor_init
+ */
+void tmonitor_exit(int id);
+
+/**
+ * @brief Set the interested attributes for monitoring
+ * @param[in] Unique id of tizen monitor
+ * @param[in] Resource type
+ * @param[in] Attribute mask including the various attributes
+ * @return @c 0 on success, otherwise a negative error value
+ */
+int tmonitor_set_attrs(int id, int resource_type, u_int64_t attr_mask);
+
+/**
+ * @brief Get the available attribute list according to resource type
+ * @param[in] Unique id of tizen monitor
+ * @param[in] Resource type
+ * @param[out] List of available attribute list
+ * @param[out] Number of available attributes
+ * @return @c 0 on success, otherwise a negative error value
+ */
+int tmonitor_get_available_attrs(int id, int resource_type,
+ int *available_attrs[], int *num_attrs);
+
+/**
+ * @brief Start tizen monitor with asynchronous method
+ * @param[in] Unique id of tizen monitor
+ * @return @c 0 on success, otherwise a negative error value
+ */
+int tmonitor_start(int id);
+
+/**
+ * @brief Stop tizen monitor
+ * @param[in] Unique id of tizen monitor
+ */
+void tmonitor_stop(int id);
+
+/**
+ * @brief Update value of the interested attributes by tmonitor_set_attrs()
+ * @param[in] Unique id of tizen monitor
+ * @return @c 0 on success, otherwise a negative error value
+ */
+int tmonitor_update(int id);
+
+/**
+ * @brief Get integer value of resource attribute
+ * @param[in] Unique id of tizen monitor
+ * @param[in] Resource type
+ * @param[in] Resoruce attribute id
+ * @return @c positive integer value, otherwise a negative error value
+ */
+int tmonitor_get_value_int(int id, int resource_type, u_int64_t attr);
+
+/**
+ * @brief Get the supported resource number
+ * @param[in] Unique id of tizen monitor
+ * @param[in] Resource type
+ * @return @c positive integer value, otherwise a negative error value
+ */
+int tmonitor_get_resource_num(int id, int resource_type);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __TMONITOR__ */
%define daemon_name pass
%define haltest_name pass-haltests
%define unittest_name pass-unittest
+%define libpass_name libpass
Name: %{daemon_name}
Summary: Power Aware System Service
%description -n %{unittest_name}
PASS unit test package with gtest
+%package -n %{libpass_name}
+Summary: Tizen Monitor Library package
+Group: Development/Libraries
+Requires: pass = %{version}-%{release}
+
+%description -n %{libpass_name}
+Tizen Monitor Library package
+
+%package -n %{libpass_name}-devel
+Summary: Tizen Monitor Headler Files
+Group: Development/Libraries
+Requires: pass = %{version}-%{release}
+
+%description -n %{libpass_name}-devel
+Tizen Monitor Headler Files
+
%prep
%setup -q
%files -n %{unittest_name}
%defattr(-,root,root,-)
%{_bindir}/pass-unittests
+
+%files -n %{libpass_name}
+%license LICENSE
+%manifest %{name}.manifest
+%defattr(-,root,root,-)
+%{_libdir}/*.so*
+
+%files -n %{libpass_name}-devel
+%defattr(-,root,root,-)
+%{_includedir}/%{name}/*.h
+%{_libdir}/pkgconfig/%{name}.pc
#include <util/log.h>
#include <util/resource.h>
-#include <monitor/monitor-internal.h>
+#include <tmonitor/tmonitor.h>
static int bus_get_cur_freq(const struct resource *res,
const struct resource_attribute *attr,
static const struct resource_driver bus_resource_driver = {
.name = "Memory Bus",
- .type = PASS_RESOURCE_BUS_ID,
+ .type = RESOURCE_TYPE_BUS,
.attrs = bus_attrs,
.num_attrs = ARRAY_SIZE(bus_attrs),
};
#include <util/log.h>
#include <util/resource.h>
-#include <monitor/monitor-internal.h>
+#include <tmonitor/tmonitor.h>
static int cpu_get_cur_freq(const struct resource *res,
const struct resource_attribute *attr,
static const struct resource_driver cpu_resource_driver = {
.name = "CPU",
- .type = PASS_RESOURCE_CPU_ID,
+ .type = RESOURCE_TYPE_CPU,
.attrs = cpu_attrs,
.num_attrs = ARRAY_SIZE(cpu_attrs),
};
#include <util/log.h>
#include <util/resource.h>
-#include <monitor/monitor-internal.h>
+#include <tmonitor/tmonitor.h>
static int gpu_get_cur_freq(const struct resource *res,
const struct resource_attribute *attr,
static const struct resource_driver gpu_resource_driver = {
.name = "GPU",
- .type = PASS_RESOURCE_GPU_ID,
+ .type = RESOURCE_TYPE_GPU,
.attrs = gpu_attrs,
.num_attrs = ARRAY_SIZE(gpu_attrs),
};
#include <util/log.h>
#include <util/resource.h>
-#include <monitor/monitor-internal.h>
+#include <tmonitor/tmonitor.h>
#define PROC_MEM_INFO_PATH "/proc/meminfo"
#define PROC_MEM_INFO_MEM_TOTAL "MemTotal"
static const struct resource_driver cpu_resource_driver = {
.name = "MEMORY",
- .type = PASS_RESOURCE_MEMORY_ID,
+ .type = RESOURCE_TYPE_MEMORY,
.attrs = memory_attrs,
.num_attrs = ARRAY_SIZE(memory_attrs),
};
#include <util/resource.h>
#include <util/log.h>
-#include <monitor/monitor-internal.h>
+#define RESOURCE_ATTR_MASK (ULLONG_MAX)
+#define RESOURCE_ATTR_INDEX(id) (63 - __builtin_clzll(id))
static GList *g_resource_driver_head;