1 #ifndef __DALI_INTERNAL_ADAPTOR_NETWORK_PERFORMANCE_CLIENT_H__
2 #define __DALI_INTERNAL_ADAPTOR_NETWORK_PERFORMANCE_CLIENT_H__
5 * Copyright (c) 2015 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.
22 #include <base/performance-logging/performance-marker.h>
23 #include <trigger-event-factory-interface.h>
24 #include <base/performance-logging/networking/client-send-data-interface.h>
25 #include <base/interfaces/socket-factory-interface.h>
42 * @brief Network Performance client
44 * Every time a client connects to Dali, a NetworkPerformanceClient object is created.
45 * It is responsible for processing incoming commands, and storing the client state
46 * (e.g. what performance markers it wants).
48 * Certain commands such as dump-scene need to be run on the main Dali event thread.
49 * To achieve this, a trigger event is used which executes a function on the main thread.
50 * The sendDataInterface is then used with the client id to transmit the data to the client.
51 * The reason for using a client id is because the client
52 * can be deleted in between receiving a command and sending a response.
54 * NetworkPerformanceClient (own thread, id 5) <--- Dump Scene Command
55 * delete NetworkPerformanceClient <--- Connection closed
56 * MainThread. Send scene data to client 5. Client 5 has been deleted so don't send the data.
59 class NetworkPerformanceClient
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( SocketInterface *socket,
72 unsigned int clientId,
73 TriggerEventFactoryInterface& triggerEventFactory,
74 ClientSendDataInterface& sendDataInterface,
75 SocketFactoryInterface& socketFactory );
80 ~NetworkPerformanceClient();
83 * @return client unique id
85 unsigned int GetId() const;
88 * @return socket interface
90 SocketInterface& GetSocket();
93 * @brief Write data to a socket. Can be called from any thread
94 * @copydoc Dali::SocketInterface::Send
96 bool WriteSocket( const void* buffer, unsigned int bufferSizeInBytes );
99 * @brief Process a command
100 * @param buffer pointer to command data
101 * @param bufferSizeInBytes how big the buffer is in bytes
103 void ProcessCommand( char* buffer, unsigned int bufferSizeInBytes );
106 * @brief Write a marker to the socket, if this client is filtering this marker.
109 bool TransmitMarker( const PerformanceMarker& marker, const char* const description );
112 * @brief If the client is waiting inside a select statement, this will cause it
119 SocketInterface* mSocket; ///< socket interface
120 PerformanceMarker::MarkerFilter mMarkerBitmask; ///< What markers are currently filtered
121 TriggerEventFactoryInterface& mTriggerEventFactory; ///< Trigger event factory
122 ClientSendDataInterface& mSendDataInterface; ///< used to send data to a client from the main event thread
123 SocketFactoryInterface& mSocketFactoryInterface; ///< used to delete the socket
124 unsigned int mClientId; ///< unique client id
125 bool mConsoleClient; ///< if connected via a console then all responses are in ASCII, not binary packed data.
130 } // namespace Internal
132 } // namespace Adaptor