/*
 * Execute an extrinsic method
 */
wbem::framework::UINT32 wbem::pmem_config::PersistentMemoryCapabilitiesFactory::executeMethod(
		wbem::framework::UINT32 &wbemRc,
		const std::string method,
		wbem::framework::ObjectPath &object,
		wbem::framework::attributes_t &inParms,
		wbem::framework::attributes_t &outParms)
{
	framework::UINT32 httpRc = framework::MOF_ERR_SUCCESS;
	wbemRc = framework::MOF_ERR_SUCCESS;
	struct pool *pPool = NULL;

	COMMON_LOG_ENTRY_PARAMS("methodName: %s, number of in params: %d", method.c_str(), (int)(inParms.size()));

	try
	{
		if (method == PMCAP_GETBLOCKSIZES)
		{
			// get the supported block sizes for this pool
			wbem::framework::UINT64_LIST blockSizes;
			pPool = getPool(object);
			// if pool is block capable, then retrieve supported block sizes, else empty
			if (pPool->type == POOL_TYPE_PERSISTENT)
			{
				// get system supported block sizes
				getSupportedBlockSizes(blockSizes);
			}
			// return in outParams
			outParms[PMCAP_BLOCKSIZES_PARAMNAME] = framework::Attribute(blockSizes, false);
		}
		else
		{
			httpRc = framework::CIM_ERR_METHOD_NOT_AVAILABLE;
		}
	}
	catch (framework::ExceptionBadParameter &)
	{
		wbemRc = PMCAP_ERR_INVALID_PARAMETER;
	}
	catch(exception::NvmExceptionLibError &e)
	{
		wbemRc = getReturnCodeFromLibException(e);
	}
	catch(framework::Exception &)
	{
		wbemRc = PMCAP_ERR_UNKNOWN;
	}
	if (pPool)
	{
		delete pPool;
	}

	COMMON_LOG_EXIT_RETURN("httpRc: %u, wbemRc: %u", httpRc, wbemRc);
	return httpRc;
}
wbem::framework::UINT32 wbem::support::DiagnosticLogFactory::executeMethod(
		wbem::framework::UINT32 &wbemRc,
		const std::string method,
		wbem::framework::ObjectPath &object,
		wbem::framework::attributes_t &inParms,
		wbem::framework::attributes_t &outParms)
{
	framework::UINT32 httpRc = framework::MOF_ERR_SUCCESS;
	wbemRc = framework::MOF_ERR_SUCCESS;

	COMMON_LOG_ENTRY_PARAMS("methodName: %s, number of in params: %d", method.c_str(), (int)(inParms.size()));

	try
	{
		if (method == DIAGNOSTICLOG_CLEARLOG)
		{
			clearDiagnosticLog();
		}
		else
		{
			httpRc = framework::CIM_ERR_METHOD_NOT_AVAILABLE;
		}
	}
	catch(exception::NvmExceptionLibError &)
	{
		wbemRc = DIAGNOSTICLOG_ERR_FAILED;
	}
	catch(framework::Exception &)
	{
		wbemRc = DIAGNOSTICLOG_ERR_FAILED;
	}

	COMMON_LOG_EXIT_RETURN("httpRc: %u, wbemRc: %u", httpRc, wbemRc);
	return httpRc;
}
wbem::framework::UINT32 wbem::support::SupportDataServiceFactory::executeMethod(
		wbem::framework::UINT32 &wbemRc,
		const std::string method,
		wbem::framework::ObjectPath &object,
		wbem::framework::attributes_t &inParms,
		wbem::framework::attributes_t &outParms)
{
	framework::UINT32 httpRc = framework::MOF_ERR_SUCCESS;
	wbemRc = framework::MOF_ERR_SUCCESS;

	COMMON_LOG_ENTRY_PARAMS("methodName: %s, number of in params: %d", method.c_str(), (int)(inParms.size()));

	try
	{
		if (method == SUPPORTDATASERVICE_EXPORTTOURI)
		{
			// verify host
			std::string hostName;
			try
			{
				hostName = wbem::server::getHostName();
			}
			// eat the exception
			catch (exception::NvmExceptionLibError&)
			{
				httpRc = framework::CIM_ERR_FAILED;
			}

			if (std::string::npos == inParms[SUPPORTDATASERVICE_OMD_OBJPATH].stringValue().find(hostName))
			{
				// not looking for this host
				httpRc = framework::CIM_ERR_INVALID_PARAMETER;
			}
			else
			{
				// call ExportToUri
				exportToUri(inParms[SUPPORTDATASERVICE_EXPORTTOURI].stringValue());
			}
		}
		else if (method == SUPPORTDATASERVICE_CREATE)
		{
			framework::ObjectPath opaqueManagementData;
			create(inParms[SUPPORTDATASERVICE_ELEMNAME].stringValue(), opaqueManagementData);
			outParms[SUPPORTDATASERVICE_OMD_OBJPATH] =
					framework::Attribute(opaqueManagementData.asString(false),false);
		}
		else if (method == SUPPORTDATASERVICE_CLEAR)
		{
			clear();
		}
		else
		{
			httpRc = framework::CIM_ERR_METHOD_NOT_AVAILABLE;
		}
	}
	catch(wbem::framework::ExceptionBadParameter &)
	{
		httpRc = framework::CIM_ERR_INVALID_PARAMETER;
	}
	catch(exception::NvmExceptionLibError &)
	{
		wbemRc = SUPPORTDATASERVICE_ERR_UNKNOWN;
	}
	catch(framework::Exception &)
	{
		wbemRc = SUPPORTDATASERVICE_ERR_UNKNOWN;
	}

	COMMON_LOG_EXIT_RETURN("httpRc: %u, wbemRc: %u", httpRc, wbemRc);
	return httpRc;
}