Move integration-api folder from adaptors to adaptor-framework
[platform/core/uifw/dali-adaptor.git] / dali / internal / network / common / network-performance-client.h
1 #ifndef DALI_INTERNAL_ADAPTOR_NETWORK_PERFORMANCE_CLIENT_H
2 #define DALI_INTERNAL_ADAPTOR_NETWORK_PERFORMANCE_CLIENT_H
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <pthread.h>
23
24 // INTERNAL INCLUDES
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>
29
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace Adaptor
38 {
39
40 /**
41  *  @brief Network Performance client
42  *
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).
46  *
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.
52  *  E.g.
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.
56  *
57  */
58 class NetworkPerformanceClient
59 {
60 public:
61
62   /**
63    * @brief Constructor
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
70    */
71   NetworkPerformanceClient( pthread_t* thread,
72                             SocketInterface *socket,
73                             unsigned int clientId,
74                             TriggerEventFactoryInterface& triggerEventFactory,
75                             ClientSendDataInterface& sendDataInterface,
76                             SocketFactoryInterface& socketFactory );
77
78   /**
79    * @brief Destructor
80    */
81   ~NetworkPerformanceClient();
82
83   /**
84    * @return client unique id
85    */
86   unsigned int GetId() const;
87
88   /**
89    * @return socket interface
90    */
91   SocketInterface& GetSocket();
92
93   /**
94    * @brief Write data to a socket. Can be called from any thread
95    * @copydoc Dali::SocketInterface::Send
96    */
97   bool WriteSocket( const void* buffer, unsigned int bufferSizeInBytes );
98
99   /**
100    * @brief Process a command
101    * @param buffer pointer to command data
102    * @param bufferSizeInBytes how big the buffer is in bytes
103    */
104   void ProcessCommand( char* buffer, unsigned int bufferSizeInBytes );
105
106   /**
107    * @brief Write a marker to the socket, if this client is filtering this marker.
108    * @param marker
109    */
110   bool TransmitMarker( const PerformanceMarker& marker, const char* const description );
111
112   /**
113    * @brief If the client is waiting inside a select statement, this will cause it
114    * to break out.
115    */
116   void ExitSelect();
117
118   /**
119    * @brief get the thread running the client
120    * @return thread pointer
121    */
122   pthread_t* GetThread();
123
124 private:
125
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.
134
135 };
136
137
138 } // namespace Internal
139
140 } // namespace Adaptor
141
142 } // namespace Dali
143
144 #endif // DALI_INTERNAL_ADAPTOR_NETWORK_PERFORMANCE_CLIENT_H