Skip to content

Commit

Permalink
add pdk::io::Buffer testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
zzusoftboy committed Apr 8, 2018
1 parent a0e86a1 commit e6804be
Show file tree
Hide file tree
Showing 5 changed files with 483 additions and 14 deletions.
2 changes: 1 addition & 1 deletion include/pdk/base/io/Buffer.h
Expand Up @@ -65,7 +65,7 @@ class PDK_CORE_EXPORT Buffer : public IoDevice
void disconnectNotify(pdk::puint32 signal) override;
pdk::pint64 readData(char *data, pdk::pint64 maxlen) override;
pdk::pint64 writeData(const char *data, pdk::pint64 len) override;

void emitSignals();
private:
PDK_DECLARE_PRIVATE(Buffer);
PDK_DISABLE_COPY(Buffer);
Expand Down
2 changes: 2 additions & 0 deletions include/pdk/kernel/CallableInvoker.h
Expand Up @@ -55,6 +55,8 @@ class PDK_CORE_EXPORT CallableInvoker
static void invokeAsync(pdk::kernel::Object *receiver, RetType Class::* memberFunc, ArgTypes... args)
{
CoreApplication::postEvent(receiver, new internal::MetaCallEvent([=](){
Class *target = dynamic_cast<Class *>(receiver);
PDK_ASSERT(target != nullptr);
(dynamic_cast<Class *>(receiver)->*memberFunc)(args...);
}));
}
Expand Down
8 changes: 7 additions & 1 deletion src/modules/base/io/Buffer.cpp
Expand Up @@ -246,11 +246,17 @@ pdk::pint64 Buffer::writeData(const char *data, pdk::pint64 len)
// @TODO need workaround that signal been block
if (implPtr->m_signalConnectionCount && !implPtr->m_signalsEmitted) {
implPtr->m_signalsEmitted = true;
CallableInvoker::invokeAsync(this, &BufferPrivate::emitSignals);
CallableInvoker::invokeAsync(this, &Buffer::emitSignals);
}
return len;
}

void Buffer::emitSignals()
{
PDK_D(Buffer);
implPtr->emitSignals();
}

void Buffer::connectNotify(pdk::puint32 signal)
{
SignalType signalEnum = SignalType(signal);
Expand Down
2 changes: 1 addition & 1 deletion testlib/pdktest/TestGlobal.h
Expand Up @@ -88,7 +88,7 @@ do { \
#define PDKTEST_DECLARE_APP_STARTUP_ARGS() extern int sg_argc;\
extern char **sg_argv
#define PDKTEST_BEGIN_APP_CONTEXT() pdk::kernel::CoreApplication app(sg_argc, sg_argv);\
pdk::kernel::CallableInvoker::invokeAsync([](){
pdk::kernel::CallableInvoker::invokeAsync([&](){
#define PDKTEST_END_APP_CONTEXT() \
PDK_RETRIEVE_APP_INSTANCE()->quit();\
}, &app);\
Expand Down

0 comments on commit e6804be

Please sign in to comment.