summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Minar <miminar@redhat.com>2014-06-24 13:28:16 +0200
committerMichal Minar <miminar@redhat.com>2014-07-01 15:40:57 +0200
commit900e296bd9c3f12273186b562db73c03d6139005 (patch)
tree62a1e283465fabcc22abb569aea446ee9fbfcd06
parent55cb42ff2a328dfb025df72626fe5b2e891fad4e (diff)
downloadopenlmi-providers-900e296bd9c3f12273186b562db73c03d6139005.tar.gz
openlmi-providers-900e296bd9c3f12273186b562db73c03d6139005.tar.xz
openlmi-providers-900e296bd9c3f12273186b562db73c03d6139005.zip
software-dbus: implemented LMI_SoftwareMethodResult
-rw-r--r--mof/30_LMI_Jobs.mof2
-rw-r--r--mof/60_LMI_Software.mof17
-rw-r--r--src/software-dbus/LMI_SoftwareMethodResultProvider.c141
-rw-r--r--src/software-dbus/sw-utils.h4
4 files changed, 157 insertions, 7 deletions
diff --git a/mof/30_LMI_Jobs.mof b/mof/30_LMI_Jobs.mof
index 2bdb526..9592e92 100644
--- a/mof/30_LMI_Jobs.mof
+++ b/mof/30_LMI_Jobs.mof
@@ -38,6 +38,8 @@ class LMI_OwningJobElement : CIM_OwningJobElement
[ Version("0.2.0") ]
class LMI_MethodResult : CIM_MethodResult
{
+ [ Implemented(true), Override("InstanceID") ]
+ string InstanceID;
};
[ Version("0.2.0") ]
diff --git a/mof/60_LMI_Software.mof b/mof/60_LMI_Software.mof
index 3ba1163..4cd98d8 100644
--- a/mof/60_LMI_Software.mof
+++ b/mof/60_LMI_Software.mof
@@ -708,6 +708,23 @@ class LMI_SoftwareInstallationServiceCapabilities :
[Version("0.2.0")]
class LMI_SoftwareMethodResult : LMI_MethodResult {
+
+ [Implemented(true), Override("Caption")]
+ string Caption;
+
+ [Implemented(true), Override("Description")]
+ string Description;
+
+ [Implemented(true), Override("ElementName")]
+ string ElementName;
+
+ /* FIXME: find out, why overriding following properties fails
+
+ [ Implemented(true), Override("PreCallIndication") ]
+ string PreCallIndication;
+ [ Implemented(true), Override("PostCallIndication") ]
+ string PostCallIndication;
+ */
};
/******************************************************************************
diff --git a/src/software-dbus/LMI_SoftwareMethodResultProvider.c b/src/software-dbus/LMI_SoftwareMethodResultProvider.c
index 16830f6..009daac 100644
--- a/src/software-dbus/LMI_SoftwareMethodResultProvider.c
+++ b/src/software-dbus/LMI_SoftwareMethodResultProvider.c
@@ -1,10 +1,34 @@
+/*
+ * Copyright (C) 2013-2014 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: Michal Minar <miminar@redhat.com>
+ */
+
#include <konkret/konkret.h>
#include "LMI_SoftwareMethodResult.h"
+#include "lmi_job.h"
+#include "job_manager.h"
+#include "sw-utils.h"
static const CMPIBroker* _cb = NULL;
-static void LMI_SoftwareMethodResultInitialize()
+static void LMI_SoftwareMethodResultInitialize(const CMPIContext *ctx)
{
+ software_init(provider_name, _cb, ctx, provider_config_defaults);
}
static CMPIStatus LMI_SoftwareMethodResultCleanup(
@@ -12,7 +36,7 @@ static CMPIStatus LMI_SoftwareMethodResultCleanup(
const CMPIContext* cc,
CMPIBoolean term)
{
- CMReturn(CMPI_RC_OK);
+ return software_cleanup();
}
static CMPIStatus LMI_SoftwareMethodResultEnumInstanceNames(
@@ -32,7 +56,41 @@ static CMPIStatus LMI_SoftwareMethodResultEnumInstances(
const CMPIObjectPath* cop,
const char** properties)
{
- CMReturn(CMPI_RC_OK);
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+ LmiJob *job;
+ CMPIInstance *inst;
+ guint *jobnum;
+ guint *jobnums = jobmgr_get_job_numbers(NULL);
+
+ if (jobnums == NULL)
+ CMReturn(CMPI_RC_ERR_FAILED);
+
+ for (jobnum = jobnums; *jobnum != 0; ++jobnum) {
+ job = jobmgr_get_job_by_number(*jobnum);
+ if (!job)
+ // job may have been deleted since numbers query
+ continue;
+
+ status = jobmgr_job_to_method_result_instance(job, NULL, &inst);
+ if (status.rc) {
+ gchar *jobid = lmi_job_get_jobid(job);
+ if (status.msg) {
+ lmi_warn("Failed to make method result instance out of job"
+ " \"%s\": %s", jobid, CMGetCharsPtr(status.msg, NULL));
+ } else {
+ lmi_warn("Failed to make method result instance out of job"
+ " \"%s\"", jobid);
+ }
+ g_free(jobid);
+ } else {
+ CMReturnInstance(cr, inst);
+ }
+ g_clear_object(&job);
+ }
+
+ g_free(jobnums);
+
+ return status;
}
static CMPIStatus LMI_SoftwareMethodResultGetInstance(
@@ -42,8 +100,77 @@ static CMPIStatus LMI_SoftwareMethodResultGetInstance(
const CMPIObjectPath* cop,
const char** properties)
{
- return KDefaultGetInstance(
- _cb, mi, cc, cr, cop, properties);
+ LmiJob *job = NULL;
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst;
+ guint64 number;
+ gchar *endptr;
+ gchar errbuf[BUFLEN] = "";
+ LMI_SoftwareMethodResultRef smrop;
+
+ LMI_SoftwareMethodResultRef_InitFromObjectPath(&smrop, _cb, cop);
+ if (!KHasValue(&smrop.InstanceID)) {
+ g_snprintf(errbuf, BUFLEN, "Missing InstanceID key property!");
+ goto err;
+ }
+
+ if (g_ascii_strncasecmp(SW_METHOD_RESULT_INSTANCE_ID_PREFIX,
+ smrop.InstanceID.chars,
+ SW_METHOD_RESULT_INSTANCE_ID_PREFIX_LEN))
+ {
+ g_snprintf(errbuf, BUFLEN, "Unexpected prefix \"%s\" in InstanceID!",
+ smrop.InstanceID.chars);
+ goto err;
+ }
+
+ number = g_ascii_strtoull(smrop.InstanceID.chars
+ + SW_METHOD_RESULT_INSTANCE_ID_PREFIX_LEN, &endptr, 10);
+ if (number == G_MAXUINT64 || number == 0 || number > (guint64) G_MAXINT32) {
+ g_snprintf(errbuf, BUFLEN, "Missing or invalid method result number in"
+ " InstanceID \"%s\"!", smrop.InstanceID.chars);
+ goto err;
+ }
+
+ if (*endptr != '\0') {
+ g_snprintf(errbuf, BUFLEN,
+ "Junk after job number in method result's InstanceID \"%s\"!",
+ smrop.InstanceID.chars);
+ goto err;
+ }
+
+ if ((job = jobmgr_get_job_by_number(number)) == NULL) {
+ g_snprintf(errbuf, BUFLEN, "Job #%u does not exist.", (guint32) number);
+ goto err;
+ }
+
+ status = jobmgr_job_to_method_result_instance(job, NULL, &inst);
+ if (status.rc) {
+ gchar *jobid = lmi_job_get_jobid(job);
+ if (status.msg) {
+ g_snprintf(errbuf, BUFLEN, "Failed to make method result instance"
+ " out of job \"%s\": %s", jobid,
+ CMGetCharsPtr(status.msg, NULL));
+ } else {
+ g_snprintf(errbuf, BUFLEN, "Failed to make method result instance"
+ " out of job \"%s\"", jobid);
+ }
+ g_free(jobid);
+ goto err;
+ }
+ g_object_unref(job);
+ CMReturnInstance(cr, inst);
+ return status;
+
+err:
+ g_clear_object(&job);
+ if (errbuf[0]) {
+ lmi_error(errbuf);
+ if (!status.rc)
+ KSetStatus2(_cb, &status, ERR_NOT_FOUND, errbuf);
+ } else if (!status.rc) {
+ KSetStatus(&status, ERR_NOT_FOUND);
+ }
+ return status;
}
static CMPIStatus LMI_SoftwareMethodResultCreateInstance(
@@ -91,7 +218,7 @@ CMInstanceMIStub(
LMI_SoftwareMethodResult,
LMI_SoftwareMethodResult,
_cb,
- LMI_SoftwareMethodResultInitialize())
+ LMI_SoftwareMethodResultInitialize(ctx))
static CMPIStatus LMI_SoftwareMethodResultMethodCleanup(
CMPIMethodMI* mi,
@@ -118,7 +245,7 @@ CMMethodMIStub(
LMI_SoftwareMethodResult,
LMI_SoftwareMethodResult,
_cb,
- LMI_SoftwareMethodResultInitialize())
+ LMI_SoftwareMethodResultInitialize(ctx))
KONKRET_REGISTRATION(
"root/cimv2",
diff --git a/src/software-dbus/sw-utils.h b/src/software-dbus/sw-utils.h
index 94a3ff1..7e0f5dc 100644
--- a/src/software-dbus/sw-utils.h
+++ b/src/software-dbus/sw-utils.h
@@ -38,6 +38,10 @@
#define SW_IDENTITY_INSTANCE_ID_PREFIX LMI_ORGID ":" LMI_SoftwareIdentity_ClassName ":"
#define SW_IDENTITY_INSTANCE_ID_PREFIX_LEN 25
+#define SW_METHOD_RESULT_INSTANCE_ID_PREFIX \
+ LMI_ORGID ":" LMI_SoftwareMethodResult_ClassName ":"
+#define SW_METHOD_RESULT_INSTANCE_ID_PREFIX_LEN 29
+
#define get_sw_pkg_from_sw_identity_op(cop, sw_pkg) \
create_sw_package_from_elem_name(get_elem_name_from_instance_id(\
lmi_get_string_property_from_objectpath(cop, "InstanceID")), sw_pkg)