summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--cmake/modules/FindOpenLMI.cmake21
-rw-r--r--src/CMakeLists.txt16
-rw-r--r--src/fan/LMI_FanAssociatedSensorProvider.c2
-rw-r--r--src/fan/LMI_FanSensorProvider.c2
-rw-r--r--src/globals.h19
-rw-r--r--src/hardware/cpuinfo.h1
-rw-r--r--src/hardware/dmidecode.h1
-rw-r--r--src/hardware/lscpu.h1
-rw-r--r--src/hardware/sysfs.h1
-rw-r--r--src/openlmi.c (renamed from src/globals.c)69
-rw-r--r--src/openlmi.h80
-rw-r--r--src/openlmi.pc.in10
13 files changed, 189 insertions, 35 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 230ed26..b42debc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,3 +39,4 @@ install(PROGRAMS openlmi-register-pegasus DESTINATION libexec)
install(FILES cmake/modules/OpenLMIMacros.cmake DESTINATION share/cmake/Modules)
install(FILES cmake/modules/FindCMPI.cmake DESTINATION share/cmake/Modules)
install(FILES cmake/modules/FindKonkretCMPI.cmake DESTINATION share/cmake/Modules)
+install(FILES cmake/modules/FindOpenLMI.cmake DESTINATION share/cmake/Modules)
diff --git a/cmake/modules/FindOpenLMI.cmake b/cmake/modules/FindOpenLMI.cmake
new file mode 100644
index 0000000..d4338ca
--- /dev/null
+++ b/cmake/modules/FindOpenLMI.cmake
@@ -0,0 +1,21 @@
+
+find_path(OPENLMI_INCLUDE_DIR
+ NAMES openlmi.h
+ HINTS $ENV{OPENLMI_INCLUDE_DIR}
+ PATH_SUFFIXES include/openlmi
+ PATHS /usr /usr/local
+)
+
+find_library(OPENLMICOMMON_LIBRARY
+ NAMES openlmicommon
+ HINTS $ENV{OPENLMI_LIB_DIR}
+ PATH_SUFFIXES lib64 lib
+ PATHS /usr /usr/local
+)
+
+set(OPENLMI_LIBRARIES ${OPENLMICOMMON_LIBRARY})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(OPENLMI DEFAULT_MSG OPENLMI_LIBRARIES OPENLMI_INCLUDE_DIR)
+
+mark_as_advanced(OPENLMI_INCLUDE_DIR OPENLMI_LIBRARIES)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7318911..d5335a6 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,13 +1,21 @@
-include_directories(.)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMPI_INCLUDE_DIR})
add_library(openlmicommon SHARED
- globals.c
+ openlmi.c
)
-set_target_properties(openlmicommon PROPERTIES SOVERSION 0.0.1)
+set(OPENLMICOMMON_VERSION_MAJOR 0)
+set(OPENLMICOMMON_VERSION_MINOR 0)
+set(OPENLMICOMMON_VERSION_PATCH 1)
+set(OPENLMICOMMON_VERSION "${OPENLMICOMMON_VERSION_MAJOR}.${OPENLMICOMMON_VERSION_MINOR}.${OPENLMICOMMON_VERSION_PATCH}")
+
+set_target_properties(openlmicommon PROPERTIES VERSION ${OPENLMICOMMON_VERSION})
+set_target_properties(openlmicommon PROPERTIES SOVERSION ${OPENLMICOMMON_VERSION_MAJOR})
install(TARGETS openlmicommon DESTINATION lib${LIB_SUFFIX})
-install(FILES globals.h DESTINATION include/openlmi)
+install(FILES openlmi.h DESTINATION include/openlmi)
+configure_file(openlmi.pc.in openlmi.pc @ONLY)
+install(FILES openlmi.pc DESTINATION lib${LIB_SUFFIX}/pkgconfig)
if (WITH-FAN)
add_subdirectory(fan)
diff --git a/src/fan/LMI_FanAssociatedSensorProvider.c b/src/fan/LMI_FanAssociatedSensorProvider.c
index d75bf5c..b462e83 100644
--- a/src/fan/LMI_FanAssociatedSensorProvider.c
+++ b/src/fan/LMI_FanAssociatedSensorProvider.c
@@ -21,7 +21,7 @@
#include <konkret/konkret.h>
#include "LMI_FanAssociatedSensor.h"
#include "fan.h"
-#include <globals.h>
+#include "globals.h"
static const CMPIBroker* _cb;
diff --git a/src/fan/LMI_FanSensorProvider.c b/src/fan/LMI_FanSensorProvider.c
index 47bd9d5..e63d266 100644
--- a/src/fan/LMI_FanSensorProvider.c
+++ b/src/fan/LMI_FanSensorProvider.c
@@ -22,7 +22,7 @@
#include <konkret/konkret.h>
#include "LMI_FanSensor.h"
#include "fan.h"
-#include <globals.h>
+#include "globals.h"
static const CMPIBroker* _cb = NULL;
diff --git a/src/globals.h b/src/globals.h
index a1cb18c..094602f 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -21,19 +21,16 @@
#ifndef GLOBALS_H
#define GLOBALS_H
-const char *get_system_name();
+#include "openlmi.h"
-const char *get_system_creation_class_name();
-
-int log_level(void);
-void set_log_level(int level);
-
-enum { NONE=0, ERROR, WARN, DEBUG };
-void _debug(int level, const char *file, int line, const char *format, ...);
-#define debug(...) _debug(DEBUG, __FILE__, __LINE__, __VA_ARGS__)
-#define warn(...) _debug(WARN, __FILE__, __LINE__, __VA_ARGS__)
-#define error(...) _debug(ERROR, __FILE__, __LINE__, __VA_ARGS__)
+// Shortcuts for functions and macros from openlmicommon library
+#define get_system_creation_class_name lmi_get_system_creation_class_name
+#define get_system_name lmi_get_system_name
+#define debug lmi_debug
+#define warn lmi_warn
+#define error lmi_error
#define ORGID "LMI"
+
#endif
diff --git a/src/hardware/cpuinfo.h b/src/hardware/cpuinfo.h
index 5ec5dd5..0b2f9ab 100644
--- a/src/hardware/cpuinfo.h
+++ b/src/hardware/cpuinfo.h
@@ -24,7 +24,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "globals.h"
#include "utils.h"
diff --git a/src/hardware/dmidecode.h b/src/hardware/dmidecode.h
index 9190ea4..a627553 100644
--- a/src/hardware/dmidecode.h
+++ b/src/hardware/dmidecode.h
@@ -24,7 +24,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "globals.h"
#include "utils.h"
diff --git a/src/hardware/lscpu.h b/src/hardware/lscpu.h
index 5dc5bd5..39c85b6 100644
--- a/src/hardware/lscpu.h
+++ b/src/hardware/lscpu.h
@@ -24,7 +24,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "globals.h"
#include "utils.h"
diff --git a/src/hardware/sysfs.h b/src/hardware/sysfs.h
index 0e0b523..028b559 100644
--- a/src/hardware/sysfs.h
+++ b/src/hardware/sysfs.h
@@ -27,7 +27,6 @@
#include <dirent.h>
#include <errno.h>
#include <limits.h>
-#include "globals.h"
#include "utils.h"
#define SYSFS_CPU_PATH "/sys/devices/system/cpu"
diff --git a/src/globals.c b/src/openlmi.c
index 7e58817..786bdd2 100644
--- a/src/globals.c
+++ b/src/openlmi.c
@@ -18,7 +18,7 @@
* Authors: Radek Novacek <rnovacek@redhat.com>
*/
-#include "globals.h"
+#include "openlmi.h"
#include <stdlib.h>
#include <stdarg.h>
@@ -27,11 +27,14 @@
#include <string.h>
#include <netdb.h>
#include <stdio.h>
+#include <cmpimacs.h>
static char *_fqdn = NULL;
-static int _log_level = DEBUG;
+static int _log_level = _LMI_DEBUG_DEBUG;
+static const CMPIBroker *_cb = NULL;
+static char *_log_id = NULL;
-char *getFQDN(void)
+static char *getFQDN(void)
{
struct utsname uts;
if ((uname(&uts) > 0) && (uts.nodename != NULL)) {
@@ -66,7 +69,7 @@ char *getFQDN(void)
return strdup(hostname);
}
-const char *get_system_name()
+const char *lmi_get_system_name()
{
if (_fqdn == NULL) {
_fqdn = getFQDN();
@@ -74,25 +77,63 @@ const char *get_system_name()
return _fqdn;
}
-const char *get_system_creation_class_name()
+const char *lmi_get_system_creation_class_name()
{
return "Linux_ComputerSystem";
}
-void _debug(int level, const char *file, int line, const char *format, ...)
+void lmi_init_logging(const char *log_id, const CMPIBroker *cb)
{
- if (level > _log_level) {
- return;
+ if (_log_id != NULL) {
+ free(_log_id);
+ }
+ _log_id = strdup(log_id);
+ _cb = cb;
+}
+
+int lmi_log_level(void)
+{
+ return _log_level;
+}
+
+void lmi_set_log_level(int level)
+{
+ _log_level = level;
+}
+
+void _lmi_debug(int level, const char *file, int line, const char *format, ...)
+{
+ const char *lvl[] = { "NONE", "ERROR", "INFO", "WARNING", "DEBUG" };
+ if (level > 4) {
+ level = 4;
+ }
+ if (level < 1) {
+ level = 1;
}
- FILE *trace_file = stderr;
- const char *lvl[] = { "NONE", "ERROR", "WARNING", "DEBUG" };
- // TODO: use logger from sfcbd and pegasus
- fprintf(trace_file, "[%s] %s:%d\t", lvl[level], file, line);
+ char *message, *text;
va_list args;
va_start(args, format);
- vfprintf(stderr, format, args);
+ vasprintf(&message, format, args);
va_end(args);
+ asprintf(&text, "[%s] %s:%d\t%s", lvl[level], file, line, message);
+ free(message);
+
+ CMPIStatus rc;
+ rc.rc = CMPI_RC_OK;
+ if (_cb != NULL) {
+ // try to use standard CMPI logging
+ rc = _cb->eft->trace(_cb, CMPI_LEV_INFO, _log_id, text, NULL);
+ }
+
+ if (_cb == NULL || rc.rc != CMPI_RC_OK) {
+ // Fallback to stderr
+ if (level > _log_level) {
+ free(text);
+ return;
+ }
- fprintf(stderr, "\n");
+ fprintf(stderr, "%s\n", text);
+ }
+ free(text);
}
diff --git a/src/openlmi.h b/src/openlmi.h
new file mode 100644
index 0000000..9b27d07
--- /dev/null
+++ b/src/openlmi.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2012-2013 Red Hat, Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Radek Novacek <rnovacek@redhat.com>
+ */
+
+#ifndef OPENLMI_H
+#define OPENLMI_H
+
+#include <cmpidt.h>
+
+/**
+ * This function returns FQDN (fully qualified domain name) of the machine
+ *
+ * @note Use this in the SystemName property of all provider created instances.
+ *
+ * @return The scoping System's Name.
+ */
+const char *lmi_get_system_name();
+
+/**
+ * This function returns system creation class name
+ *
+ * @note Use this in the SystemCreationClassName property of all provider
+ * created instances.
+ *
+ * @return The scoping System's Creation class name.
+ */
+const char *lmi_get_system_creation_class_name();
+
+/**
+ * To use standard CIMOM logging facility, broker must be assigned. Without
+ * calling this function, logging will go to stderr.
+ *
+ * \p log_id Identification of log messages
+ * \p cb CMPIBroker
+ */
+void lmi_init_logging(const char *log_id, const CMPIBroker *cb);
+
+/**
+ * Get currently set logging level
+ *
+ * @return logging level
+ */
+int lmi_log_level(void);
+
+/**
+ * Set logging level
+ *
+ * @param level new logging level
+ */
+void lmi_set_log_level(int level);
+
+enum {
+ _LMI_DEBUG_NONE=0, _LMI_DEBUG_ERROR, _LMI_DEBUG_WARN,
+ _LMI_DEBUG_INFO, _LMI_DEBUG_DEBUG
+};
+
+void _lmi_debug(int level, const char *file, int line, const char *format, ...);
+
+#define lmi_debug(...) _lmi_debug(_LMI_DEBUG_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
+#define lmi_info(...) _lmi_debug(_LMI_DEBUG_INFO, __FILE__, __LINE__, __VA_ARGS__)
+#define lmi_warn(...) _lmi_debug(_LMI_DEBUG_WARN, __FILE__, __LINE__, __VA_ARGS__)
+#define lmi_error(...) _lmi_debug(_LMI_DEBUG_ERROR, __FILE__, __LINE__, __VA_ARGS__)
+
+#endif
diff --git a/src/openlmi.pc.in b/src/openlmi.pc.in
new file mode 100644
index 0000000..939d672
--- /dev/null
+++ b/src/openlmi.pc.in
@@ -0,0 +1,10 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=${prefix}
+includedir=${prefix}/include
+libdir=${exec_prefix}/lib@LIB_SUFFIX@
+
+Name: openlmi
+Description: OpenLMI provider support
+Version: @OPENLMICOMMON_VERSION@
+Libs: -L${libdir} -lopenlmicommon
+CFlags: -I${includedir}/openlmi