summaryrefslogtreecommitdiffstats
path: root/src/hardware/LMI_BatteryPhysicalPackageProvider.c
diff options
context:
space:
mode:
authorPeter Schiffer <pschiffe@redhat.com>2013-06-27 11:54:39 +0200
committerPeter Schiffer <pschiffe@redhat.com>2013-06-27 11:54:39 +0200
commitc6d97a2d474ba80e6c7449f5127635f8f5663830 (patch)
tree1ac3e6abb0d5d80efdabd7e3274acf4a0b468604 /src/hardware/LMI_BatteryPhysicalPackageProvider.c
parente7cee30c0f2ff6a63e78c48e6b56755c84a96788 (diff)
downloadopenlmi-providers-c6d97a2d474ba80e6c7449f5127635f8f5663830.tar.gz
openlmi-providers-c6d97a2d474ba80e6c7449f5127635f8f5663830.tar.xz
openlmi-providers-c6d97a2d474ba80e6c7449f5127635f8f5663830.zip
Hardware: Added battery providers
New providers: * LMI_BatteryProvider * LMI_BatteryPhysicalPackageProvider * LMI_PhysicalBatteryContainerProvider * LMI_PhysicalBatteryRealizesProvider
Diffstat (limited to 'src/hardware/LMI_BatteryPhysicalPackageProvider.c')
-rw-r--r--src/hardware/LMI_BatteryPhysicalPackageProvider.c217
1 files changed, 217 insertions, 0 deletions
diff --git a/src/hardware/LMI_BatteryPhysicalPackageProvider.c b/src/hardware/LMI_BatteryPhysicalPackageProvider.c
new file mode 100644
index 0000000..fbd4888
--- /dev/null
+++ b/src/hardware/LMI_BatteryPhysicalPackageProvider.c
@@ -0,0 +1,217 @@
+/*
+ * 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 <time.h>
+#include <konkret/konkret.h>
+#include "LMI_BatteryPhysicalPackage.h"
+#include "LMI_Hardware.h"
+#include "globals.h"
+#include "dmidecode.h"
+
+static const CMPIBroker* _cb = NULL;
+
+static void LMI_BatteryPhysicalPackageInitialize()
+{
+}
+
+static CMPIStatus LMI_BatteryPhysicalPackageCleanup(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_BatteryPhysicalPackageEnumInstanceNames(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ return KDefaultEnumerateInstanceNames(
+ _cb, mi, cc, cr, cop);
+}
+
+static CMPIStatus LMI_BatteryPhysicalPackageEnumInstances(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ LMI_BatteryPhysicalPackage lmi_batt_phys;
+ const char *ns = KNameSpace(cop);
+ char instance_id[INSTANCE_ID_LEN];
+ struct tm tm;
+ unsigned i;
+ DmiBattery *dmi_batt = NULL;
+ unsigned dmi_batt_nb = 0;
+
+ if (dmi_get_batteries(&dmi_batt, &dmi_batt_nb) != 0 || dmi_batt_nb < 1) {
+ goto done;
+ }
+
+ for (i = 0; i < dmi_batt_nb; i++) {
+ LMI_BatteryPhysicalPackage_Init(&lmi_batt_phys, _cb, ns);
+
+ LMI_BatteryPhysicalPackage_Set_CreationClassName(&lmi_batt_phys,
+ ORGID "_" BATTERY_PHYS_PKG_CLASS_NAME);
+ LMI_BatteryPhysicalPackage_Set_PackageType(&lmi_batt_phys,
+ LMI_BatteryPhysicalPackage_PackageType_Battery);
+ LMI_BatteryPhysicalPackage_Set_Caption(&lmi_batt_phys,
+ "Physical Battery Package");
+ LMI_BatteryPhysicalPackage_Set_Description(&lmi_batt_phys,
+ "This object represents one physical battery package in system.");
+
+ snprintf(instance_id, INSTANCE_ID_LEN,
+ ORGID ":" ORGID "_" BATTERY_PHYS_PKG_CLASS_NAME ":%s",
+ dmi_batt[i].name);
+
+ LMI_BatteryPhysicalPackage_Set_Tag(&lmi_batt_phys, dmi_batt[i].name);
+ LMI_BatteryPhysicalPackage_Set_ElementName(&lmi_batt_phys,
+ dmi_batt[i].name);
+ LMI_BatteryPhysicalPackage_Set_Name(&lmi_batt_phys, dmi_batt[i].name);
+ LMI_BatteryPhysicalPackage_Set_Manufacturer(&lmi_batt_phys,
+ dmi_batt[i].manufacturer);
+ LMI_BatteryPhysicalPackage_Set_SerialNumber(&lmi_batt_phys,
+ dmi_batt[i].serial_number);
+ LMI_BatteryPhysicalPackage_Set_Version(&lmi_batt_phys,
+ dmi_batt[i].version);
+ LMI_BatteryPhysicalPackage_Set_InstanceID(&lmi_batt_phys, instance_id);
+
+ memset(&tm, 0, sizeof(struct tm));
+ if (strptime(dmi_batt[i].manufacture_date, "%F", &tm)) {
+ LMI_BatteryPhysicalPackage_Set_ManufactureDate(&lmi_batt_phys,
+ CMNewDateTimeFromBinary(_cb, mktime(&tm) * 1000000, 0, NULL));
+ }
+
+ KReturnInstance(cr, lmi_batt_phys);
+ }
+
+done:
+ dmi_free_batteries(&dmi_batt, &dmi_batt_nb);
+
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_BatteryPhysicalPackageGetInstance(
+ 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_BatteryPhysicalPackageCreateInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_BatteryPhysicalPackageModifyInstance(
+ 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_BatteryPhysicalPackageDeleteInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_BatteryPhysicalPackageExecQuery(
+ 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_BatteryPhysicalPackage,
+ LMI_BatteryPhysicalPackage,
+ _cb,
+ LMI_BatteryPhysicalPackageInitialize())
+
+static CMPIStatus LMI_BatteryPhysicalPackageMethodCleanup(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_BatteryPhysicalPackageInvokeMethod(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* meth,
+ const CMPIArgs* in,
+ CMPIArgs* out)
+{
+ return LMI_BatteryPhysicalPackage_DispatchMethod(
+ _cb, mi, cc, cr, cop, meth, in, out);
+}
+
+CMMethodMIStub(
+ LMI_BatteryPhysicalPackage,
+ LMI_BatteryPhysicalPackage,
+ _cb,
+ LMI_BatteryPhysicalPackageInitialize())
+
+KUint32 LMI_BatteryPhysicalPackage_IsCompatible(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_BatteryPhysicalPackageRef* self,
+ const KRef* ElementToCheck,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KONKRET_REGISTRATION(
+ "root/cimv2",
+ "LMI_BatteryPhysicalPackage",
+ "LMI_BatteryPhysicalPackage",
+ "instance method")