1 #ifndef DALI_INTERNAL_ADAPTOR_NETWORK_PERFORMANCE_CLIENT_H
2 #define DALI_INTERNAL_ADAPTOR_NETWORK_PERFORMANCE_CLIENT_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
25 #include <dali/internal/system/common/performance-marker.h>
26 #include <dali/internal/network/common/client-send-data-interface.h>
27 #include <dali/internal/network/common/socket-factory-interface.h>
28 #include <dali/integration-api/adaptor-framework/trigger-event-factory-interface.h>
41 * @brief Network Performance client
43 * Every time a client connects to Dali, a NetworkPerformanceClient object is created.
44 * It is responsible for processing incoming commands, and storing the client state
45 * (e.g. what performance markers it wants).
47 * Certain commands such as dump-scene need to be run on the main Dali event thread.
48 * To achieve this, a trigger event is used which executes a function on the main thread.
49 * The sendDataInterface is then used with the client id to transmit the data to the client.
50 * The reason for using a client id is because the client
51 * can be deleted in between receiving a command and sending a response.
53 * NetworkPerformanceClient (own thread, id 5) <--- Dump Scene Command
54 * delete NetworkPerformanceClient <--- Connection closed
55 * MainThread. Send scene data to client 5. Client 5 has been deleted so don't send the data.
58 class NetworkPerformanceClient
64 * @param thread thread pointer
65 * @param socket socket interface
66 * @param clientId unique client id
67 * @param triggerEventFactory used to create trigger events
68 * @param sendDataInterface used to send data to the socket from main thread
69 * @param SocketFactoryInterface used to delete the socket when the client is destroyed
71 NetworkPerformanceClient( pthread_t* thread,
72 SocketInterface *socket,
73 unsigned int clientId,
74 TriggerEventFactoryInterface& triggerEventFactory,
75 ClientSendDataInterface& sendDataInterface,
76 SocketFactoryInterface& socketFactory );
81 ~NetworkPerformanceClient();
84 * @return client unique id
86 unsigned int GetId() const;
89 * @return socket interface
91 SocketInterface& GetSocket();
94 * @brief Write data to a socket. Can be called from any thread
95 * @copydoc Dali::SocketInterface::Send
97 bool WriteSocket( const void* buffer, unsigned int bufferSizeInBytes );
100 * @brief Process a command
101 * @param buffer pointer to command data
102 * @param bufferSizeInBytes how big the buffer is in bytes
104 void ProcessCommand( char* buffer, unsigned int bufferSizeInBytes );
107 * @brief Write a marker to the socket, if this client is filtering this marker.
110 bool TransmitMarker( const PerformanceMarker& marker, const char* const description );
113 * @brief If the client is waiting inside a select statement, this will cause it
119 * @brief get the thread running the client
120 * @return thread pointer
122 pthread_t* GetThread();
126 pthread_t* mThread; ///< thread for the client
127 SocketInterface* mSocket; ///< socket interface
128 PerformanceMarker::MarkerFilter mMarkerBitmask; ///< What markers are currently filtered
129 TriggerEventFactoryInterface& mTriggerEventFactory; ///< Trigger event factory
130 ClientSendDataInterface& mSendDataInterface; ///< used to send data to a client from the main event thread
131 SocketFactoryInterface& mSocketFactoryInterface; ///< used to delete the socket
132 unsigned int mClientId; ///< unique client id
133 bool mConsoleClient; ///< if connected via a console then all responses are in ASCII, not binary packed data.
138 } // namespace Internal
140 } // namespace Adaptor
144 #endif // DALI_INTERNAL_ADAPTOR_NETWORK_PERFORMANCE_CLIENT_H