2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/internal/network/common/network-performance-protocol.h>
30 namespace PerformanceProtocol
35 * Command parameter type
45 * Command information structure
50 CommandString cmdString;
51 PARAMETER_TYPE paramType;
55 * Command lookup table
58 CommandInfo CommandLookup[]=
60 {HELP_MESSAGE, "help", NO_PARAMS },
61 {ENABLE_METRIC, "enable_metric", UNSIGNED_INT},
62 {DISABLE_METRIC, "disable_metric", UNSIGNED_INT},
63 {LIST_METRICS_AVAILABLE, "list_metrics", NO_PARAMS },
64 {ENABLE_TIME_MARKER_BIT_MASK, "set_marker", UNSIGNED_INT},
65 {DUMP_SCENE_GRAPH, "dump_scene", NO_PARAMS },
66 {SET_PROPERTIES, "set_properties", STRING },
67 {CUSTOM_COMMAND, "custom_command", STRING },
68 {UNKNOWN_COMMAND, "unknown", NO_PARAMS }
71 const unsigned int CommandLookupLength = sizeof(CommandLookup) / sizeof(CommandInfo);
73 #define GREEN "\033[01;32m"
75 #define PARAM "\033[22;32m"
76 #define YELLOW "\033[01;33m"
79 const char* const helpMsg =
81 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
82 " Dali performance console \n"
83 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" NORMAL
84 GREEN " list_metrics " NORMAL " - list available metrics\n"
85 GREEN " enable_metric " PARAM " metricId" NORMAL " - enable a metric \n"
86 GREEN " disable_metric " PARAM " metricId" NORMAL " - disable a metric\n\n"
87 GREEN " set_marker " PARAM " value " NORMAL "-output Dali markers\n"
88 " : Bit 0 = V_SYNC (1)\n"
89 " : Bit 1 = Update task (2)\n"
90 " : Bit 2 = Render task (4) \n"
91 " : Bit 3 = Event Processing task (8)\n"
92 " : Bit 4 = SwapBuffers (16)\n"
93 " : Bit 5 = Life cycle events (32)\n"
94 " : Bit 6 = Resource event (64)\n"
96 GREEN " set_properties " NORMAL " - set an actor property command. Format:\n\n"
97 GREEN " set_properties " PARAM "|ActorIndex;Property;Value|" NORMAL ", e.g: \n"
98 GREEN " set_properties " PARAM "|178;Size;[ 144.0, 144.0, 144.0 ]|178;Color;[ 1.0, 1,0, 1.0 ]|\n"
100 GREEN " custom_command " NORMAL " - A custom command for an application. Format:\n\n"
101 GREEN " custom_command " PARAM "ANY_STRING" NORMAL "\n"
103 GREEN " dump_scene" NORMAL " - dump the current scene in json format\n";
105 } // un-named namespace
107 bool GetCommandId( const char* const commandString, unsigned int lengthInBytes, CommandId& commandId, unsigned int& intParam, std::string& stringParam )
109 commandId = UNKNOWN_COMMAND;
112 // the command list is small so just do a O(n) search for the commandID.
113 for( unsigned int i = 0 ; i < CommandLookupLength; ++i )
115 if( strncmp( commandString, CommandLookup[i].cmdString ,strlen(CommandLookup[i].cmdString )) == 0 )
117 commandId = CommandLookup[i].cmdId;
119 // if the command has a parameter read it
120 if( CommandLookup[i].paramType == UNSIGNED_INT)
122 int count = sscanf(commandString,"%*s %d",&intParam);
129 else if (CommandLookup[i].paramType == STRING )
131 char* charParam( NULL );
132 // allocates the character array
133 int count = sscanf(commandString,"%*s %ms",&charParam);
139 stringParam = std::string( charParam);
149 bool GetCommandString( CommandId commandId, CommandString& commandString )
151 for( unsigned int i = 0; i < CommandLookupLength; ++i)
153 if( CommandLookup[ i ].cmdId == commandId )
155 strncpy( commandString, CommandLookup[ i ].cmdString, strlen(CommandLookup[ i ].cmdString) );
159 strncpy( commandString, CommandLookup[ UNKNOWN_COMMAND ].cmdString, MAX_COMMAND_STRING_LENGTH);
163 const char* const GetHelpMessage()
169 } // namespace PerformanceProtocol