1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-05 09:17:41 +03:00
one/include/RequestManagerAllocateDB.h
Valentyn Bohdan c1725ddfbb
M #-: Replace raw pointers with references/smart pointers. (#3285)
* M #-: Replace raw pointers with references/smart pointers.
- Change PoolSQL::allocate method's signature to accept reference instead of pointer and fix all method calls.
- Remove some of the error-handling goto, to be able initialize some variables during declaration.

Signed-off-by: Valentyn Bohdan <vbohdan@opennebula.io>
2024-11-21 13:19:12 +01:00

119 lines
4.0 KiB
C++

/* -------------------------------------------------------------------------- */
/* Copyright 2002-2024, OpenNebula Project, OpenNebula Systems */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#ifndef REQUEST_MANAGER_ALLOCATE_DB_H
#define REQUEST_MANAGER_ALLOCATE_DB_H
#include "Request.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class RequestManagerAllocateDB: public Request
{
protected:
RequestManagerAllocateDB(const std::string& name): Request(name, "A:ss",
"Allocates a new object from its template representation")
{
auth_op = AuthRequest::MANAGE;
};
~RequestManagerAllocateDB() {};
virtual PoolObjectSQL * create(const std::string& xml) = 0;
/* -------------------------------------------------------------------- */
void request_execute(xmlrpc_c::paramList const& pl, RequestAttributes& att) override
{
std::string xml = xmlrpc_c::value_string(pl.getString(1));
if (!att.is_oneadmin())
{
failure_response(AUTHORIZATION, att);
return;
}
auto obj = std::unique_ptr<PoolObjectSQL>(create(xml));
int rc = pool->allocate(*obj, att.resp_msg);
if ( rc == -1 )
{
failure_response(INTERNAL, att);
return;
}
success_response(rc, att);
return;
}
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class MarketPlaceAppAllocateDB: public RequestManagerAllocateDB
{
public:
MarketPlaceAppAllocateDB():RequestManagerAllocateDB("one.marketapp.allocatedb")
{
auth_object = PoolObjectSQL::MARKETPLACEAPP;
pool = Nebula::instance().get_apppool();
};
~MarketPlaceAppAllocateDB() {};
/* -------------------------------------------------------------------- */
PoolObjectSQL * create(const std::string& xml) override
{
PoolObjectSQL * app = static_cast<MarketPlaceAppPool *>(pool)->create();
app->from_xml(xml);
return app;
}
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class MarketPlaceAllocateDB: public RequestManagerAllocateDB
{
public:
MarketPlaceAllocateDB(): RequestManagerAllocateDB("one.market.allocatedb")
{
auth_object = PoolObjectSQL::MARKETPLACE;
pool = Nebula::instance().get_marketpool();
};
~MarketPlaceAllocateDB() {};
/* -------------------------------------------------------------------- */
PoolObjectSQL * create(const std::string& xml) override
{
PoolObjectSQL * mp = static_cast<MarketPlacePool *>(pool)->create();
mp->from_xml(xml);
return mp;
}
};
#endif /* REQUEST_MANAGER_ALLOCATE_DB_H */