summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Schiffer <pschiffe@redhat.com>2013-06-20 18:13:20 +0200
committerPeter Schiffer <pschiffe@redhat.com>2013-06-20 18:13:20 +0200
commit7aa75594f3beb92248e21bd19c9f8a75746707e1 (patch)
treeb8f1e05b707d7672fc952321a2a5c2ec2dfd5fd3
parent7057f8c9ed6f51044a853710defde4ef14f2a340 (diff)
downloadopenlmi-providers-7aa75594f3beb92248e21bd19c9f8a75746707e1.tar.gz
openlmi-providers-7aa75594f3beb92248e21bd19c9f8a75746707e1.tar.xz
openlmi-providers-7aa75594f3beb92248e21bd19c9f8a75746707e1.zip
Hardware: Added pointing device provider
New provider: * LMI_PointingDeviceProvider It currently represents pointing devices on chassis, such as touch pad or track point.
-rw-r--r--mof/60_LMI_Hardware.mof5
-rw-r--r--src/hardware/LMI_Hardware.h1
-rw-r--r--src/hardware/LMI_PointingDeviceProvider.c343
-rw-r--r--src/hardware/dmidecode.c142
-rw-r--r--src/hardware/dmidecode.h22
5 files changed, 513 insertions, 0 deletions
diff --git a/mof/60_LMI_Hardware.mof b/mof/60_LMI_Hardware.mof
index f4bc764..e22da2c 100644
--- a/mof/60_LMI_Hardware.mof
+++ b/mof/60_LMI_Hardware.mof
@@ -310,6 +310,11 @@ class LMI_SystemSlotContainer: CIM_Container
LMI_SystemSlot REF PartComponent;
};
+[ Provider("cmpi:cmpiLMI_PointingDevice") ]
+class LMI_PointingDevice: CIM_PointingDevice
+{
+};
+
/******************************************************************************
* PCI Devices
*/
diff --git a/src/hardware/LMI_Hardware.h b/src/hardware/LMI_Hardware.h
index 81881f5..f88e6b6 100644
--- a/src/hardware/LMI_Hardware.h
+++ b/src/hardware/LMI_Hardware.h
@@ -36,5 +36,6 @@
#define MEMORY_PHYS_PKG_CLASS_NAME "MemoryPhysicalPackage"
#define PORT_PHYS_CONN_CLASS_NAME "PortPhysicalConnector"
#define SYSTEM_SLOT_CLASS_NAME "SystemSlot"
+#define POINTING_DEVICE_CLASS_NAME "PointingDevice"
#endif /* LMI_HARDWARE_H_ */
diff --git a/src/hardware/LMI_PointingDeviceProvider.c b/src/hardware/LMI_PointingDeviceProvider.c
new file mode 100644
index 0000000..f3c89d6
--- /dev/null
+++ b/src/hardware/LMI_PointingDeviceProvider.c
@@ -0,0 +1,343 @@
+/*
+ * Copyright (C) 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: Peter Schiffer <pschiffe@redhat.com>
+ */
+
+#include <konkret/konkret.h>
+#include "LMI_PointingDevice.h"
+#include "LMI_Hardware.h"
+#include "globals.h"
+#include "dmidecode.h"
+
+CMPIUint16 get_pointingtype(const char *dmi_val);
+
+static const CMPIBroker* _cb = NULL;
+
+static void LMI_PointingDeviceInitialize()
+{
+}
+
+static CMPIStatus LMI_PointingDeviceCleanup(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_PointingDeviceEnumInstanceNames(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ return KDefaultEnumerateInstanceNames(
+ _cb, mi, cc, cr, cop);
+}
+
+static CMPIStatus LMI_PointingDeviceEnumInstances(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ LMI_PointingDevice lmi_dev;
+ const char *ns = KNameSpace(cop);
+ //CMPIUint16 conn_layout, maxlinkwidth;
+ char instance_id[INSTANCE_ID_LEN];
+ unsigned i;
+ DmiPointingDevice *dmi_dev = NULL;
+ unsigned dmi_dev_nb = 0;
+
+ if (dmi_get_pointing_devices(&dmi_dev, &dmi_dev_nb) != 0 || dmi_dev_nb < 1) {
+ goto done;
+ }
+
+ for (i = 0; i < dmi_dev_nb; i++) {
+ LMI_PointingDevice_Init(&lmi_dev, _cb, ns);
+
+ LMI_PointingDevice_Set_SystemCreationClassName(&lmi_dev,
+ get_system_creation_class_name());
+ LMI_PointingDevice_Set_SystemName(&lmi_dev, get_system_name());
+ LMI_PointingDevice_Set_CreationClassName(&lmi_dev,
+ ORGID "_" POINTING_DEVICE_CLASS_NAME);
+ LMI_PointingDevice_Set_Caption(&lmi_dev, "Pointing Device");
+ LMI_PointingDevice_Set_Description(&lmi_dev,
+ "This object represents one pointing device.");
+
+ snprintf(instance_id, INSTANCE_ID_LEN,
+ ORGID ":" ORGID "_" POINTING_DEVICE_CLASS_NAME ":%s",
+ dmi_dev[i].type);
+
+ LMI_PointingDevice_Set_DeviceID(&lmi_dev, dmi_dev[i].type);
+ LMI_PointingDevice_Set_NumberOfButtons(&lmi_dev, dmi_dev[i].buttons);
+ LMI_PointingDevice_Set_PointingType(&lmi_dev,
+ get_pointingtype(dmi_dev[i].type));
+ LMI_PointingDevice_Set_ElementName(&lmi_dev, dmi_dev[i].type);
+ LMI_PointingDevice_Set_Name(&lmi_dev, dmi_dev[i].type);
+ LMI_PointingDevice_Set_InstanceID(&lmi_dev, instance_id);
+
+ KReturnInstance(cr, lmi_dev);
+ }
+
+done:
+ dmi_free_pointing_devices(&dmi_dev, &dmi_dev_nb);
+
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_PointingDeviceGetInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ return KDefaultGetInstance(
+ _cb, mi, cc, cr, cop, properties);
+}
+
+static CMPIStatus LMI_PointingDeviceCreateInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_PointingDeviceModifyInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci,
+ const char** properties)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_PointingDeviceDeleteInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_PointingDeviceExecQuery(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* lang,
+ const char* query)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+CMInstanceMIStub(
+ LMI_PointingDevice,
+ LMI_PointingDevice,
+ _cb,
+ LMI_PointingDeviceInitialize())
+
+static CMPIStatus LMI_PointingDeviceMethodCleanup(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_PointingDeviceInvokeMethod(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* meth,
+ const CMPIArgs* in,
+ CMPIArgs* out)
+{
+ return LMI_PointingDevice_DispatchMethod(
+ _cb, mi, cc, cr, cop, meth, in, out);
+}
+
+CMMethodMIStub(
+ LMI_PointingDevice,
+ LMI_PointingDevice,
+ _cb,
+ LMI_PointingDeviceInitialize())
+
+KUint32 LMI_PointingDevice_RequestStateChange(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PointingDeviceRef* self,
+ const KUint16* RequestedState,
+ KRef* Job,
+ const KDateTime* TimeoutPeriod,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PointingDevice_SetPowerState(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PointingDeviceRef* self,
+ const KUint16* PowerState,
+ const KDateTime* Time,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PointingDevice_Reset(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PointingDeviceRef* self,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PointingDevice_EnableDevice(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PointingDeviceRef* self,
+ const KBoolean* Enabled,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PointingDevice_OnlineDevice(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PointingDeviceRef* self,
+ const KBoolean* Online,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PointingDevice_QuiesceDevice(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PointingDeviceRef* self,
+ const KBoolean* Quiesce,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PointingDevice_SaveProperties(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PointingDeviceRef* self,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PointingDevice_RestoreProperties(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PointingDeviceRef* self,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+/*
+ * Get pointing type according to the dmidecode.
+ * @param dmi_val from dmidecode
+ * @return CIM id of pointing type
+ */
+CMPIUint16 get_pointingtype(const char *dmi_val)
+{
+ if (!dmi_val || !strlen(dmi_val)) {
+ return 2; /* Unknown */
+ }
+
+ static struct {
+ CMPIUint16 cim_val; /* CIM value */
+ char *dmi_val; /* dmidecode value */
+ } values[] = {
+ {1, "Other"},
+ {2, "Unknown"},
+ {3, "Mouse"},
+ {4, "Track Ball"},
+ {5, "Track Point"},
+ {6, "Glide Point"},
+ {7, "Touch Pad"},
+ {8, "Touch Screen"},
+ {9, "Optical Sensor"},
+ };
+
+ size_t i, val_length = sizeof(values) / sizeof(values[0]);
+
+ for (i = 0; i < val_length; i++) {
+ if (strcmp(dmi_val, values[i].dmi_val) == 0) {
+ return values[i].cim_val;
+ }
+ }
+
+ return 1; /* Other */
+}
+
+KONKRET_REGISTRATION(
+ "root/cimv2",
+ "LMI_PointingDevice",
+ "LMI_PointingDevice",
+ "instance method")
diff --git a/src/hardware/dmidecode.c b/src/hardware/dmidecode.c
index f29596f..d989a09 100644
--- a/src/hardware/dmidecode.c
+++ b/src/hardware/dmidecode.c
@@ -1859,3 +1859,145 @@ void dmi_free_system_slots(DmiSystemSlot **slots, unsigned *slots_nb)
*slots_nb = 0;
*slots = NULL;
}
+
+
+/******************************************************************************
+ * DmiPointingDevice
+ */
+
+/*
+ * Initialize DmiPointingDevice attributes.
+ * @param dev
+ */
+void init_dmipointingdev_struct(DmiPointingDevice *dev)
+{
+ dev->type = NULL;
+ dev->buttons = 0;
+}
+
+/*
+ * Check attributes of poiting device structure and fill in defaults if needed.
+ * @param dev
+ * @return 0 if success, negative value otherwise
+ */
+short check_dmipointingdev_attributes(DmiPointingDevice *dev)
+{
+ short ret = -1;
+
+ if (!dev->type) {
+ if (!(dev->type = strdup("Unknown"))) {
+ ret = -2;
+ goto done;
+ }
+ }
+
+ ret = 0;
+
+done:
+ if (ret != 0) {
+ warn("Failed to allocate memory.");
+ }
+
+ return ret;
+}
+
+short dmi_get_pointing_devices(DmiPointingDevice **devices, unsigned *devices_nb)
+{
+ short ret = -1;
+ int curr_dev = -1;
+ unsigned i, buffer_size = 0;
+ char **buffer = NULL, *buf;
+
+ *devices_nb = 0;
+
+ /* get dmidecode output */
+ if (run_command("dmidecode -t 21", &buffer, &buffer_size) != 0) {
+ ret = -2;
+ goto done;
+ }
+
+ /* count pointing devices */
+ for (i = 0; i < buffer_size; i++) {
+ if (strncmp(buffer[i], "Handle 0x", 9) == 0) {
+ (*devices_nb)++;
+ }
+ }
+
+ /* if no slot was found */
+ if (*devices_nb < 1) {
+ warn("Dmidecode didn't recognize any pointing device.");
+ ret = -3;
+ goto done;
+ }
+
+ /* allocate memory for pointing devices */
+ *devices = (DmiPointingDevice *)calloc(*devices_nb, sizeof(DmiPointingDevice));
+ if (!(*devices)) {
+ warn("Failed to allocate memory.");
+ ret = -4;
+ goto done;
+ }
+
+ /* parse information about slots */
+ for (i = 0; i < buffer_size; i++) {
+ if (strncmp(buffer[i], "Handle 0x", 9) == 0) {
+ curr_dev++;
+ init_dmipointingdev_struct(&(*devices)[curr_dev]);
+ continue;
+ }
+ /* ignore first useless lines */
+ if (curr_dev < 0) {
+ continue;
+ }
+ /* Type */
+ buf = copy_string_part_after_delim(buffer[i], "Type: ");
+ if (buf) {
+ (*devices)[curr_dev].type = buf;
+ buf = NULL;
+ continue;
+ }
+ /* Buttons */
+ buf = copy_string_part_after_delim(buffer[i], "Buttons: ");
+ if (buf) {
+ sscanf(buf, "%u", &(*devices)[curr_dev].buttons);
+ free(buf);
+ buf = NULL;
+ continue;
+ }
+ }
+
+ /* fill in default attributes if needed */
+ for (i = 0; i < *devices_nb; i++) {
+ if (check_dmipointingdev_attributes(&(*devices)[i]) != 0) {
+ ret = -8;
+ goto done;
+ }
+ }
+
+ ret = 0;
+
+done:
+ free_2d_buffer(&buffer, &buffer_size);
+
+ if (ret != 0) {
+ dmi_free_pointing_devices(devices, devices_nb);
+ }
+
+ return ret;
+}
+
+void dmi_free_pointing_devices(DmiPointingDevice **devices, unsigned *devices_nb)
+{
+ unsigned i;
+
+ if (*devices_nb > 0) {
+ for (i = 0; i < *devices_nb; i++) {
+ free((*devices)[i].type);
+ (*devices)[i].type = NULL;
+ }
+ free(*devices);
+ }
+
+ *devices_nb = 0;
+ *devices = NULL;
+}
diff --git a/src/hardware/dmidecode.h b/src/hardware/dmidecode.h
index 76627af..34bfd47 100644
--- a/src/hardware/dmidecode.h
+++ b/src/hardware/dmidecode.h
@@ -135,6 +135,12 @@ typedef struct _DmiSystemSlot {
short supports_hotplug; /* Supports slot hotplug? */
} DmiSystemSlot;
+/* Pointing Device from dmidecode. */
+typedef struct _DmiPointingDevice {
+ char *type; /* Type */
+ unsigned buttons; /* Number of buttons */
+} DmiPointingDevice;
+
/*
* Get array of processors according to the dmidecode program.
* @param cpu array of cpus, this function will allocate necessary memory,
@@ -241,5 +247,21 @@ short dmi_get_system_slots(DmiSystemSlot **slots, unsigned *slots_nb);
*/
void dmi_free_system_slots(DmiSystemSlot **slots, unsigned *slots_nb);
+/*
+ * Get array of pointing devices according to the dmidecode program.
+ * @param devices array of devices, this function will allocate necessary memory,
+ * but caller is responsible for freeing it
+ * @param devices_nb number of devices
+ * @return 0 if success, negative value otherwise
+ */
+short dmi_get_pointing_devices(DmiPointingDevice **devices, unsigned *devices_nb);
+
+/*
+ * Free array of pointing device structures.
+ * @param devices array of pointing devices
+ * @param devices_nb number of pointing devices
+ */
+void dmi_free_pointing_devices(DmiPointingDevice **devices, unsigned *devices_nb);
+
#endif /* DMIDECODE_H_ */