Skip to content

Commit

Permalink
dbus/object: Split PropertyType into PropertyTypeBase and Properytype
Browse files Browse the repository at this point in the history
This allows specialisation of the template. Also change the pointer to
a reference be a bit more C++ like.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
  • Loading branch information
schwabe authored and dsommers committed Sep 24, 2018
1 parent f7b2da7 commit 227b876
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
18 changes: 9 additions & 9 deletions src/configmgr/configmgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,15 @@ class ConfigurationObject : public DBusObject,
// contains files
valid = true;

properties.AddBinding(new PropertyType<std::time_t>(this, "import_timestamp", "t", "read", false, &import_tstamp));
properties.AddBinding(new PropertyType<std::time_t>(this, "last_used_timestamp", "t", "read", false, &last_use_tstamp));
properties.AddBinding(new PropertyType<bool>(this, "locked_down", "b", "readwrite", false, &locked_down));
properties.AddBinding(new PropertyType<bool>(this, "persistent", "b", "read", false, &persistent));
properties.AddBinding(new PropertyType<bool>(this, "persist_tun", "b", "readwrite", true, &persist_tun));
properties.AddBinding(new PropertyType<bool>(this, "readonly", "b", "read", false, &readonly));
properties.AddBinding(new PropertyType<bool>(this, "single_use", "b", "read", false, &single_use));
properties.AddBinding(new PropertyType<unsigned int>(this, "used_count", "u", "read", false, &used_count));
properties.AddBinding(new PropertyType<bool>(this, "valid", "b", "read", false, &valid));
properties.AddBinding(new PropertyType<std::time_t>(this, "import_timestamp", "t", "read", false, import_tstamp));
properties.AddBinding(new PropertyType<std::time_t>(this, "last_used_timestamp", "t", "read", false, last_use_tstamp));
properties.AddBinding(new PropertyType<bool>(this, "locked_down", "b", "readwrite", false, locked_down));
properties.AddBinding(new PropertyType<bool>(this, "persistent", "b", "read", false, persistent));
properties.AddBinding(new PropertyType<bool>(this, "persist_tun", "b", "readwrite", true, persist_tun));
properties.AddBinding(new PropertyType<bool>(this, "readonly", "b", "read", false, readonly));
properties.AddBinding(new PropertyType<bool>(this, "single_use", "b", "read", false, single_use));
properties.AddBinding(new PropertyType<unsigned int>(this, "used_count", "u", "read", false, used_count));
properties.AddBinding(new PropertyType<bool>(this, "valid", "b", "read", false, valid));

std::string introsp_xml ="<node name='" + objpath + "'>"
" <interface name='net.openvpn.v3.configuration'>"
Expand Down
47 changes: 31 additions & 16 deletions src/dbus/object-property.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ class Property : public RC<thread_safe_refcount>


template <typename T>
class PropertyType : public Property
class PropertyTypeBase : public Property
{
public:
PropertyType(DBusObject *obj_arg, std::string name_arg, std::string
PropertyTypeBase(DBusObject *obj_arg, std::string name_arg, std::string
dbus_type_arg, std::string dbus_acl_arg, bool allow_root_arg,
T * value_arg)
T & value_arg)
: obj(obj_arg),
name(name_arg),
dbus_type(dbus_type_arg),
Expand All @@ -68,29 +68,44 @@ class PropertyType : public Property
return allow_root;
}

virtual GVariant *GetValue() const override
{
return g_variant_new(dbus_type.c_str(), *value);
}

virtual GVariantBuilder *SetValue(GVariant *value_arg) override
{
g_variant_get(value_arg, dbus_type.c_str(), value);
return obj->build_set_property_response(name, *value);
}

virtual std::string GetName() const override
{
return name;
}

private:
protected:
DBusObject *obj;
std::string name;
std::string dbus_type;
std::string dbus_acl;
bool allow_root;
T *value = nullptr;
T& value;
};


template <typename T>
class PropertyType : public PropertyTypeBase<T>
{
public:
PropertyType(DBusObject *obj_arg, std::string name_arg, std::string
dbus_type_arg, std::string dbus_acl_arg, bool allow_root_arg,
T& value_arg) :
PropertyTypeBase<T>(obj_arg, name_arg, dbus_type_arg,
dbus_acl_arg, allow_root_arg, value_arg)
{

}

virtual GVariant *GetValue() const override
{
return g_variant_new(PropertyTypeBase<T>::dbus_type.c_str(), PropertyTypeBase<T>::value);
}

virtual GVariantBuilder *SetValue(GVariant *value_arg) override
{
g_variant_get(value_arg, PropertyTypeBase<T>::dbus_type.c_str(), &(PropertyTypeBase<T>::value));
return PropertyTypeBase<T>::obj->build_set_property_response(PropertyTypeBase<T>::name, PropertyTypeBase<T>::value);
}
};


Expand Down

0 comments on commit 227b876

Please sign in to comment.