Replies: 2 comments 3 replies
-
What exactly do you mean? Can you provide an example?
|
Beta Was this translation helpful? Give feedback.
-
Yes, yes, I'm aware of that. But this is what I don't understand or not seeing something obvious here. In my mind I should be able to inherit from generated adaptor, overwrite virtual methods which would be my API. This in turn could be totally independent from who ever is calling my API. Something like: In library /* the_lib_header.hpp */
#include "generated_lib_interface.hpp"
class feature1 : public feature_interface
{
public:
void Param(const X a&) overwrite;
X ParamX() overwrite;
void doSomethingOnFeature1() overwrite;
};
class the_lib_class : public lib_interface {
public:
void ParamA(const T1 a&) overwrite;
T1 ParamA() overwrite;
void doSomethingOnCore() overwrite;
private:
feature1 ft1;
feature2 ft2;
}; /* generated_lib_interface.hpp */
// No need to include sdbus headers here. */
#include <...>
class feature_interface {
public:
virtual void ParamX(const X a&) = 0;
virtual X ParamX() = 0;
void doSomethingOnFeature1() = 0;
};
class lib_interface {
public:
virtual void ParamA(const T1 a&) = 0
virtual T1 ParamA() = 0;
virtual void doSomething() = 0;
}; /* generated_lib_adaptors.hpp */
#include <sdbus-c++/sdbus-c++.h>
#include <string>
#include <tuple>
#include "generated_lib_interface.hpp"
// Put here whatever you need here in SDBUS CPP */
class feature_adaptor : public sdbus::AdaptorInterfaces {
public:
static constexpr const char* INTERFACE_NAME = "the.lib.feature";
void feature_adaptor(sdbus::IConnection& connection, app_interface &interface) :
AdaptorInterfaces(connection, path)
{
/* register stuff. */
getObject().registerMethod("ParamX"). ...;
...;
}
};
class lib_adaptor : public sdbus::AdaptorInterfaces {
public:
static constexpr const char* INTERFACE_NAME = "the.lib";
void lib_adaptor(sdbus::IConnection& connection, std::string path, lib_interface &interface) :
AdaptorInterfaces(connection, path)
{
/* register stuff. */
getObject().registerMethod("ParamA"). ...;
...;
}
}; Then in my main.c #include "the_lib_header.hpp"
#include "generated_lib_adaptors.hpp"
void main()
{
the_app_class app {...};
auto conn = sdbu::createConnection();
conn.enterEventLoop();
lib_adaptor appAdaptor (conn, APP_PATH, app);
feature_adaptor feature1Adaptor (conn, APP_F1_PATH, app.f1);
feature_adaptor feature2Adaptor (conn, APP_F2_PATH, app.f2);
...;
} This is simple example, but in my case I have the project where core functionality is separated into own library and can be linked into application that does not use DBUS at all. So If I don't want tightly couple my internal classes to the sdbus-cpp (like you have in your concatenator example) I need to implement virtual methods in adaptor classes and re-write a lot of stuff what the I could also be totally wrong and there is already other possible way achieve this separation using current version of the library :) |
Beta Was this translation helpful? Give feedback.
-
I'm currently forced to store new objects in
std::uint_ptr
which in turn are stored instd::vector
. If there would be move constructor available then it would enablestd::vector<foo_adaptor>
instead ofstd::vector<std::uint_ptr<foo_adaptor>>
. Additionally if there would be default constructor available then separating construction from initialization would be possible.Why generated adaptors don't have default and move constructor?
I know the obvious answear, but is there any obstacle in changing library to hold pointers (maybe shared ones) instead of references?
Beta Was this translation helpful? Give feedback.
All reactions