forked from Kistler-Group/sdbus-cpp
Emulate sync D-Bus method call with async implementation underneath to avoid poll race condition
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -50,20 +50,6 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
int32_t doSignalEmission() override
|
||||
{
|
||||
static int32_t counter = 0;
|
||||
emitSimpleSignal();
|
||||
printf("First simple signal thrown\n");
|
||||
counter++;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
//emitSimpleSignal();
|
||||
//printf("Second simple signal thrown\n");
|
||||
counter++;
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
void noArgNoReturn() const
|
||||
{
|
||||
}
|
||||
@@ -211,6 +197,13 @@ protected:
|
||||
throw sdbus::createError(1, "A test error occurred");
|
||||
}
|
||||
|
||||
|
||||
void emitTwoSimpleSignals() override
|
||||
{
|
||||
emitSimpleSignal();
|
||||
emitSignalWithMap({});
|
||||
}
|
||||
|
||||
std::string state()
|
||||
{
|
||||
return m_state;
|
||||
|
||||
@@ -61,7 +61,6 @@ protected:
|
||||
void onSimpleSignal() override
|
||||
{
|
||||
m_gotSimpleSignal = true;
|
||||
printf("Thread %d: Got simple signal\n", gettid());
|
||||
}
|
||||
|
||||
void onSignalWithMap(const std::map<int32_t, std::string>& m) override
|
||||
@@ -113,6 +112,7 @@ protected:
|
||||
|
||||
//private:
|
||||
public: // for tests
|
||||
int m_SimpleSignals = 0;
|
||||
std::atomic<bool> m_gotSimpleSignal{false};
|
||||
std::atomic<bool> m_gotSignalWithMap{false};
|
||||
std::map<int32_t, std::string> m_mapFromSignal;
|
||||
|
||||
@@ -59,8 +59,6 @@ protected:
|
||||
{
|
||||
object_.setInterfaceFlags(INTERFACE_NAME).markAsDeprecated().withPropertyUpdateBehavior(sdbus::Flags::EMITS_NO_SIGNAL);
|
||||
|
||||
object_.registerMethod("doSignalEmission").onInterface(INTERFACE_NAME).implementedAs([this](){ return this->doSignalEmission(); });
|
||||
|
||||
object_.registerMethod("noArgNoReturn").onInterface(INTERFACE_NAME).implementedAs([this](){ return this->noArgNoReturn(); });
|
||||
object_.registerMethod("getInt").onInterface(INTERFACE_NAME).implementedAs([this](){ return this->getInt(); });
|
||||
object_.registerMethod("getTuple").onInterface(INTERFACE_NAME).implementedAs([this](){ return this->getTuple(); });
|
||||
@@ -108,6 +106,8 @@ protected:
|
||||
|
||||
object_.registerMethod("doPrivilegedStuff").onInterface(INTERFACE_NAME).implementedAs([](){}).markAsPrivileged();
|
||||
|
||||
object_.registerMethod("emitTwoSimpleSignals").onInterface(INTERFACE_NAME).implementedAs([this](){ this->emitTwoSimpleSignals(); });
|
||||
|
||||
// registration of signals is optional, it is useful because of introspection
|
||||
object_.registerSignal("simpleSignal").onInterface(INTERFACE_NAME).markAsDeprecated();
|
||||
object_.registerSignal("signalWithMap").onInterface(INTERFACE_NAME).withParameters<std::map<int32_t, std::string>>();
|
||||
@@ -152,7 +152,6 @@ private:
|
||||
|
||||
protected:
|
||||
|
||||
virtual int32_t doSignalEmission() = 0;
|
||||
virtual void noArgNoReturn() const = 0;
|
||||
virtual int32_t getInt() const = 0;
|
||||
virtual std::tuple<uint32_t, std::string> getTuple() const = 0;
|
||||
@@ -171,6 +170,7 @@ protected:
|
||||
virtual sdbus::UnixFd getUnixFd() const = 0;
|
||||
virtual ComplexType getComplex() const = 0;
|
||||
virtual void throwError() const = 0;
|
||||
virtual void emitTwoSimpleSignals() = 0;
|
||||
|
||||
virtual std::string state() = 0;
|
||||
virtual uint32_t action() = 0;
|
||||
|
||||
@@ -56,12 +56,9 @@ protected:
|
||||
virtual void onDoOperationReply(uint32_t returnValue, const sdbus::Error* error) = 0;
|
||||
|
||||
public:
|
||||
int32_t doSignalEmission()
|
||||
void emitTwoSimpleSignals()
|
||||
{
|
||||
int32_t result;
|
||||
object_.callMethod("doSignalEmission").onInterface(INTERFACE_NAME).storeResultsTo(result);
|
||||
//object_.callMethodAsync("doSignalEmission").onInterface(INTERFACE_NAME).uponReplyInvoke([this](const sdbus::Error* error, int32_t returnValue){ printf("Async reply handler\n"); });
|
||||
return result;
|
||||
object_.callMethod("emitTwoSimpleSignals").onInterface(INTERFACE_NAME);
|
||||
}
|
||||
|
||||
void noArgNoReturn()
|
||||
@@ -180,6 +177,19 @@ public:
|
||||
});
|
||||
}
|
||||
|
||||
void doOperationClientSideAsyncWith500msTimeout(uint32_t param)
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
object_.callMethodAsync("doOperation")
|
||||
.onInterface(INTERFACE_NAME)
|
||||
.withTimeout(500000us)
|
||||
.withArguments(param)
|
||||
.uponReplyInvoke([this](const sdbus::Error* error, uint32_t returnValue)
|
||||
{
|
||||
this->onDoOperationReply(returnValue, error);
|
||||
});
|
||||
}
|
||||
|
||||
sdbus::Signature getSignature()
|
||||
{
|
||||
sdbus::Signature result;
|
||||
|
||||
Reference in New Issue
Block a user