#define DALI_INTERNAL_ADAPTOR_CLIENT_SEND_DATA_INTERFACE_H
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
*/
+#include <dali/public-api/signals/callback.h>
+
namespace Dali
{
namespace Internal
{
public:
/**
+ * Trigger the main thread automation callback
+ */
+ virtual void TriggerMainThreadAutomation(CallbackBase* callback) = 0;
+
+ /**
* @brief Sends data to the client
* @param[in] data pointer to some data
* @param[in] bufferSizeInBytes how big the buffer is in bytes
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// this needs to be run on the main thread, use the trigger event....
AutomationCallback* callback = new AutomationCallback(clientId, sendDataInterface);
lambda(callback);
-
- // create a trigger event that automatically deletes itself after the callback has run in the main thread
- TriggerEventInterface* interface = TriggerEventFactory::CreateTriggerEvent(callback, TriggerEventInterface::DELETE_AFTER_TRIGGER);
-
- // asynchronous call, the call back will be run sometime later on the main thread
- interface->Trigger();
+ sendDataInterface.TriggerMainThreadAutomation(callback);
}
} // unnamed namespace
if(mConsoleClient)
{
// write out the time stamp
- char *buffer;
- double usec = marker.GetTimeStamp().microseconds;
- int size = asprintf(&buffer, "%.6f (seconds), %s\n", usec * MICROSECONDS_TO_SECOND, description);
- auto retVal = mSocket->Write(buffer, size);
+ char* buffer;
+ double usec = marker.GetTimeStamp().microseconds;
+ int size = asprintf(&buffer, "%.6f (seconds), %s\n", usec * MICROSECONDS_TO_SECOND, description);
+ auto retVal = mSocket->Write(buffer, size);
free(buffer);
return retVal;
}
case PerformanceProtocol::DUMP_SCENE_GRAPH:
{
- TriggerOnMainThread(mClientId, mSendDataInterface, [&](AutomationCallback* callback){callback->AssignDumpSceneCommand();});
+ TriggerOnMainThread(mClientId, mSendDataInterface, [&](AutomationCallback* callback) { callback->AssignDumpSceneCommand(); });
break;
}
case PerformanceProtocol::SET_PROPERTIES:
{
- TriggerOnMainThread(mClientId, mSendDataInterface, [&](AutomationCallback* callback){callback->AssignSetPropertyCommand(stringParam);});
+ TriggerOnMainThread(mClientId, mSendDataInterface, [&](AutomationCallback* callback) { callback->AssignSetPropertyCommand(stringParam); });
response = "Completed";
break;
}
case PerformanceProtocol::CUSTOM_COMMAND:
{
- TriggerOnMainThread(mClientId, mSendDataInterface, [&](AutomationCallback* callback){callback->AssignCustomCommand(std::move(stringParam));});
+ TriggerOnMainThread(mClientId, mSendDataInterface, [&](AutomationCallback* callback) { callback->AssignCustomCommand(std::move(stringParam)); });
response = "Completed";
break;
}
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
NetworkPerformanceServer::NetworkPerformanceServer(AdaptorInternalServices& adaptorServices,
const EnvironmentOptions& logOptions)
: mSocketFactory(adaptorServices.GetSocketFactoryInterface()),
+ mTrigger(new EventThreadCallback(MakeCallback(this, &NetworkPerformanceServer::AutomationCallback))),
mLogOptions(logOptions),
mServerThread(0),
mListeningSocket(NULL),
}
}
+void NetworkPerformanceServer::TriggerMainThreadAutomation(CallbackBase* callback)
+{
+ // Called from client thread.
+ mClientCallback = callback;
+ mTrigger->Trigger();
+}
+
+void NetworkPerformanceServer::AutomationCallback()
+{
+ if(mClientCallback)
+ {
+ Dali::CallbackBase::Execute(*mClientCallback);
+ }
+}
+
void NetworkPerformanceServer::StopClients()
{
// prevent clients been added / deleted while stopping all clients
#define DALI_INTERNAL_ADAPTOR_NETWORK_PERFORMANCE_SERVER_H
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <pthread.h>
// INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/event-thread-callback.h>
#include <dali/internal/adaptor/common/adaptor-internal-services.h>
#include <dali/internal/network/common/network-performance-client.h>
#include <dali/internal/system/common/environment-options.h>
protected: // ClientSendDataInterface
/**
+ * @copydoc ClientSendDataInterface::TriggerMainThreadAutomation()
+ */
+ void TriggerMainThreadAutomation(CallbackBase* callback) override;
+
+ /**
* @copydoc ClientSendDataInterface::ClientSendDataInterface()
*/
void SendData(const char* const data, unsigned int bufferSizeInBytes, unsigned int clientId) override;
+ void AutomationCallback();
+
private:
/**
* Helper for the thread calling the entry function.
NetworkPerformanceServer(const NetworkPerformanceServer&); ///< undefined copy constructor
NetworkPerformanceServer& operator=(const NetworkPerformanceServer&); ///< undefined assignment operator
- SocketFactoryInterface& mSocketFactory; ///< used to create sockets
+ SocketFactoryInterface& mSocketFactory; ///< used to create sockets
+ std::unique_ptr<EventThreadCallback> mTrigger; ///< For waking up main thread
+ CallbackBase* mClientCallback; ///< Wrong thread callback!
+
const EnvironmentOptions& mLogOptions; ///< log options
Dali::Vector<NetworkPerformanceClient*> mClients; ///< list of connected clients
pthread_t mServerThread; ///< thread that listens for new connections