Dali 3D User Interface Engine
network-performance-protocol.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 // INTERNAL INCLUDES
19 
20 // CLASS HEADER
22 
23 // EXTERNAL INCLUDES
24 #include <string.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 
28 namespace Dali
29 {
30 
31 namespace PerformanceProtocol
32 {
33 
34 namespace
35 {
36 
41 {
45 };
46 
51 {
55 };
56 
61 {
62  { HELP_MESSAGE , "help" ,NO_PARAMS },
63  { ENABLE_METRIC , "enable_metric" ,UNSIGNED_INT },
64  { DISABLE_METRIC , "disable_metric" ,UNSIGNED_INT },
65  { LIST_METRICS_AVAILABLE , "list_metrics" ,NO_PARAMS },
66  { ENABLE_TIME_MARKER_BIT_MASK, "set_marker", UNSIGNED_INT },
67  { DUMP_SCENE_GRAPH , "dump_scene" ,NO_PARAMS },
68  { SET_PROPERTIES , "set_properties" ,STRING },
69  { UNKNOWN_COMMAND , "unknown" ,NO_PARAMS }
70 };
71 const unsigned int CommandLookupLength = sizeof( CommandLookup ) /sizeof( CommandInfo );
72 
73 #define GREEN "\033[01;32m"
74 #define NORMAL "\e[m"
75 #define PARAM "\033[22;32m"
76 #define YELLOW "\033[01;33m"
77 
78 const char* const helpMsg =
79  YELLOW
80  "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
81  " Dali performance console \n"
82  "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" NORMAL
83  GREEN " list_metrics " NORMAL " - list available metrics\n"
84  GREEN " enable_metric " PARAM " metricId" NORMAL " - enable a metric \n"
85  GREEN " disable_metric "PARAM " metricId" NORMAL " - disable a metric\n\n"
86  GREEN " set_marker " PARAM " value " NORMAL "-output Dali markers\n"
87  " : Bit 0 = V_SYNC (1)\n"
88  " : Bit 1 = Update task (2)\n"
89  " : Bit 2 = Render task (4) \n"
90  " : Bit 3 = Event Processing task (8)\n"
91  " : Bit 4 = SwapBuffers (16)\n"
92  " : Bit 5 = Life cycle events (32)\n"
93  " : Bit 6 = Resource event (64)\n"
94  "\n"
95  GREEN" set_properties "NORMAL " - set an actor property command. Format:\n\n"
96  GREEN" set_properties "PARAM"|ActorIndex;Property;Value|" NORMAL ", e.g: \n"
97  GREEN" set_properties " PARAM "|178;Size;[ 144.0, 144.0, 144.0 ]|178;Color;[ 1.0, 1,0, 1.0 ]|\n"
98  "\n"
99  GREEN " dump_scene" NORMAL " - dump the current scene in json format\n";
100 
101 } // un-named namespace
102 
103 bool GetCommandId( const char* const commandString, unsigned int lengthInBytes, CommandId& commandId, unsigned int& intParam, std::string& stringParam )
104 {
105  commandId = UNKNOWN_COMMAND;
106  intParam = 0;
107 
108  // the command list is small so just do a O(n) search for the commandID.
109  for( unsigned int i = 0 ; i < CommandLookupLength; ++i )
110  {
111  if( strncmp( commandString, CommandLookup[i].cmdString ,strlen(CommandLookup[i].cmdString )) == 0 )
112  {
113  commandId = CommandLookup[i].cmdId;
114 
115  // if the command has a parameter read it
116  if( CommandLookup[i].paramType == UNSIGNED_INT)
117  {
118  int count = sscanf(commandString,"%*s %d",&intParam);
119  if( count != 1 )
120  {
121  // missing parameter
122  return false;
123  }
124  }
125  else if (CommandLookup[i].paramType == STRING )
126  {
127  char* charParam( NULL );
128  // allocates the character array
129  int count = sscanf(commandString,"%*s %ms",&charParam);
130  if( count != 1 )
131  {
132  // missing parameter
133  return false;
134  }
135  stringParam = std::string( charParam);
136  free(charParam);
137  }
138  return true;
139  }
140  }
141  // not found
142  return false;
143 }
144 
145 bool GetCommandString( CommandId commandId, CommandString& commandString )
146 {
147  for( unsigned int i = 0; i < CommandLookupLength; ++i)
148  {
149  if( CommandLookup[ i ].cmdId == commandId )
150  {
151  strncpy( commandString, CommandLookup[ i ].cmdString, strlen(CommandLookup[ i ].cmdString) );
152  return true;
153  }
154  }
155  strncpy( commandString, CommandLookup[ UNKNOWN_COMMAND ].cmdString, MAX_COMMAND_STRING_LENGTH);
156  return false;
157 }
158 
159 const char* const GetHelpMessage()
160 {
161  return helpMsg;
162 }
163 
164 
165 } // namespace PerformanceProtocol
166 
167 } // namespace Dali
Dali Docs Home
Read more about Dali