2 * Copyright (c) 2015 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 "network-performance-protocol.h"
31 namespace PerformanceProtocol
38 * Command parameter type
48 * Command information structure
53 CommandString cmdString;
54 PARAMETER_TYPE paramType;
58 * Command lookup table
60 CommandInfo CommandLookup[]=
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 }
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"
78 const char* const helpMsg =
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"
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"
99 GREEN " dump_scene" NORMAL " - dump the current scene in json format\n";
101 } // un-named namespace
103 bool GetCommandId( const char* const commandString, unsigned int lengthInBytes, CommandId& commandId, unsigned int& intParam, std::string& stringParam )
105 commandId = UNKNOWN_COMMAND;
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 )
111 if( strncmp( commandString, CommandLookup[i].cmdString ,strlen(CommandLookup[i].cmdString )) == 0 )
113 commandId = CommandLookup[i].cmdId;
115 // if the command has a parameter read it
116 if( CommandLookup[i].paramType == UNSIGNED_INT)
118 int count = sscanf(commandString,"%*s %d",&intParam);
125 else if (CommandLookup[i].paramType == STRING )
127 char* charParam( NULL );
128 // allocates the character array
129 int count = sscanf(commandString,"%*s %ms",&charParam);
135 stringParam = std::string( charParam);
145 bool GetCommandString( CommandId commandId, CommandString& commandString )
147 for( unsigned int i = 0; i < CommandLookupLength; ++i)
149 if( CommandLookup[ i ].cmdId == commandId )
151 strncpy( commandString, CommandLookup[ i ].cmdString, strlen(CommandLookup[ i ].cmdString) );
155 strncpy( commandString, CommandLookup[ UNKNOWN_COMMAND ].cmdString, MAX_COMMAND_STRING_LENGTH);
159 const char* const GetHelpMessage()
165 } // namespace PerformanceProtocol