summaryrefslogtreecommitdiffstats
path: root/src/software-dbus/LMI_SoftwareMethodResultProvider.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/software-dbus/LMI_SoftwareMethodResultProvider.c')
-rw-r--r--src/software-dbus/LMI_SoftwareMethodResultProvider.c141
1 files changed, 134 insertions, 7 deletions
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",