Remove mxs::Closer<json_t*>
As std::unique_ptr can now be used with a json_t, there's no need for the closer.
This commit is contained in:
parent
0a0623003e
commit
02ed338afa
@ -21,7 +21,6 @@
|
||||
#include <maxbase/jansson.h>
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/debug.h>
|
||||
#include <maxscale/utils.hh>
|
||||
|
||||
namespace std
|
||||
{
|
||||
@ -40,28 +39,6 @@ struct default_delete<json_t>
|
||||
namespace maxscale
|
||||
{
|
||||
|
||||
/**
|
||||
* @class CloserTraits<json_t*> jansson.hh <maxscale/jansson.hh>
|
||||
*
|
||||
* Specialization of @c CloserTraits for @c json_t*.
|
||||
*/
|
||||
template<>
|
||||
struct CloserTraits<json_t*>
|
||||
{
|
||||
static void close_if(json_t* pJson)
|
||||
{
|
||||
if (pJson)
|
||||
{
|
||||
json_decref(pJson);
|
||||
}
|
||||
}
|
||||
|
||||
static void reset(json_t*& pJson)
|
||||
{
|
||||
pJson = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Convenience function for dumping JSON into a string
|
||||
*
|
||||
@ -83,11 +60,6 @@ static inline std::string json_dump(const json_t* json, int flags = 0)
|
||||
return rval;
|
||||
}
|
||||
|
||||
static inline std::string json_dump(const Closer<json_t*>& json, int flags = 0)
|
||||
{
|
||||
return json_dump(json.get(), flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert JSON to string
|
||||
*
|
||||
|
@ -154,7 +154,10 @@ struct CloserTraits
|
||||
*
|
||||
* @param t Close the resource *if* it has not been closed already.
|
||||
*/
|
||||
static void close_if(T t);
|
||||
static void close_if(T t)
|
||||
{
|
||||
static_assert(sizeof(T) != sizeof(T), "The base closer should never be used");
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets a reference to a resource. After the call, the value of t should
|
||||
|
@ -1721,7 +1721,7 @@ bool server_to_object_relations(SERVER* server, json_t* old_json, json_t* new_js
|
||||
bool runtime_alter_server_from_json(SERVER* server, json_t* new_json)
|
||||
{
|
||||
bool rval = false;
|
||||
mxs::Closer<json_t*> old_json(server_to_json(server, ""));
|
||||
std::unique_ptr<json_t> old_json(server_to_json(server, ""));
|
||||
ss_dassert(old_json.get());
|
||||
|
||||
if (is_valid_resource_body(new_json) &&
|
||||
@ -1781,14 +1781,14 @@ static bool is_valid_relationship_body(json_t* json)
|
||||
bool runtime_alter_server_relationships_from_json(SERVER* server, const char* type, json_t* json)
|
||||
{
|
||||
bool rval = false;
|
||||
mxs::Closer<json_t*> old_json(server_to_json(server, ""));
|
||||
std::unique_ptr<json_t> old_json(server_to_json(server, ""));
|
||||
ss_dassert(old_json.get());
|
||||
|
||||
if (is_valid_relationship_body(json))
|
||||
{
|
||||
mxs::Closer<json_t*> j(json_pack("{s: {s: {s: {s: O}}}}", "data",
|
||||
"relationships", type, "data",
|
||||
json_object_get(json, "data")));
|
||||
std::unique_ptr<json_t> j(json_pack("{s: {s: {s: {s: O}}}}", "data",
|
||||
"relationships", type, "data",
|
||||
json_object_get(json, "data")));
|
||||
|
||||
if (server_to_object_relations(server, old_json.get(), j.get()))
|
||||
{
|
||||
@ -2067,7 +2067,7 @@ bool service_to_filter_relations(Service* service, json_t* old_json, json_t* new
|
||||
bool runtime_alter_monitor_from_json(MXS_MONITOR* monitor, json_t* new_json)
|
||||
{
|
||||
bool rval = false;
|
||||
mxs::Closer<json_t*> old_json(monitor_to_json(monitor, ""));
|
||||
std::unique_ptr<json_t> old_json(monitor_to_json(monitor, ""));
|
||||
ss_dassert(old_json.get());
|
||||
|
||||
if (is_valid_resource_body(new_json) &&
|
||||
@ -2119,14 +2119,14 @@ bool runtime_alter_monitor_from_json(MXS_MONITOR* monitor, json_t* new_json)
|
||||
bool runtime_alter_monitor_relationships_from_json(MXS_MONITOR* monitor, json_t* json)
|
||||
{
|
||||
bool rval = false;
|
||||
mxs::Closer<json_t*> old_json(monitor_to_json(monitor, ""));
|
||||
std::unique_ptr<json_t> old_json(monitor_to_json(monitor, ""));
|
||||
ss_dassert(old_json.get());
|
||||
|
||||
if (is_valid_relationship_body(json))
|
||||
{
|
||||
mxs::Closer<json_t*> j(json_pack("{s: {s: {s: {s: O}}}}", "data",
|
||||
"relationships", "servers", "data",
|
||||
json_object_get(json, "data")));
|
||||
std::unique_ptr<json_t> j(json_pack("{s: {s: {s: {s: O}}}}", "data",
|
||||
"relationships", "servers", "data",
|
||||
json_object_get(json, "data")));
|
||||
|
||||
if (object_to_server_relations(monitor->name, old_json.get(), j.get()))
|
||||
{
|
||||
@ -2140,14 +2140,14 @@ bool runtime_alter_monitor_relationships_from_json(MXS_MONITOR* monitor, json_t*
|
||||
bool runtime_alter_service_relationships_from_json(Service* service, const char* type, json_t* json)
|
||||
{
|
||||
bool rval = false;
|
||||
mxs::Closer<json_t*> old_json(service_to_json(service, ""));
|
||||
std::unique_ptr<json_t> old_json(service_to_json(service, ""));
|
||||
ss_dassert(old_json.get());
|
||||
|
||||
if (is_valid_relationship_body(json))
|
||||
{
|
||||
mxs::Closer<json_t*> j(json_pack("{s: {s: {s: {s: O}}}}", "data",
|
||||
"relationships", type, "data",
|
||||
json_object_get(json, "data")));
|
||||
std::unique_ptr<json_t> j(json_pack("{s: {s: {s: {s: O}}}}", "data",
|
||||
"relationships", type, "data",
|
||||
json_object_get(json, "data")));
|
||||
|
||||
if (strcmp(type, CN_SERVERS) == 0)
|
||||
{
|
||||
@ -2179,7 +2179,7 @@ static bool is_dynamic_param(const std::string& key)
|
||||
bool runtime_alter_service_from_json(Service* service, json_t* new_json)
|
||||
{
|
||||
bool rval = false;
|
||||
mxs::Closer<json_t*> old_json(service_to_json(service, ""));
|
||||
std::unique_ptr<json_t> old_json(service_to_json(service, ""));
|
||||
ss_dassert(old_json.get());
|
||||
|
||||
if (is_valid_resource_body(new_json) &&
|
||||
|
@ -286,7 +286,7 @@ private:
|
||||
static const std::string HTTPS_PREFIX;
|
||||
|
||||
std::map<std::string, std::string> m_options; /**< Request options */
|
||||
mxs::Closer<json_t*> m_json; /**< Request body */
|
||||
std::unique_ptr<json_t> m_json; /**< Request body */
|
||||
std::string m_json_string; /**< String version of @c m_json */
|
||||
std::string m_resource; /**< Requested resource */
|
||||
std::deque<std::string> m_resource_parts; /**< @c m_resource split into parts */
|
||||
|
@ -1331,7 +1331,7 @@ auto_ptr<MaskingRules> MaskingRules::load(const char* zPath)
|
||||
|
||||
if (pRoot)
|
||||
{
|
||||
Closer<json_t*> root(pRoot);
|
||||
std::unique_ptr<json_t> root(pRoot);
|
||||
|
||||
sRules = create_from(root.get());
|
||||
}
|
||||
@ -1360,7 +1360,7 @@ auto_ptr<MaskingRules> MaskingRules::parse(const char* zJson)
|
||||
|
||||
if (pRoot)
|
||||
{
|
||||
Closer<json_t*> root(pRoot);
|
||||
std::unique_ptr<json_t> root(pRoot);
|
||||
|
||||
sRules = create_from(root.get());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user