URpcDecoderCommon.cpp 10.1 KB
Newer Older
1
2
3
4
5
6
7
8
#ifndef URpcDecoderCommon_CPP
#define URpcDecoderCommon_CPP

#include "../../Deploy/Include/rdk_cpp_initdll.h"
#include "../../Deploy/Include/rdk_rpc.h"
#include "../../Deploy/Include/myrdk.h"
#include "URpcDecoderCommon.h"
#include "URpcCommandInternal.h"
9
#include "UApplication.h"
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

namespace RDK {

// --------------------------
//   
// --------------------------
URpcDecoderCommon::URpcDecoderCommon(void)
{

}

URpcDecoderCommon::~URpcDecoderCommon(void)
{

}
// --------------------------

// --------------------------
//   
// --------------------------
///    
URpcDecoderCommon* URpcDecoderCommon::New(void)
{
 return new URpcDecoderCommon;
}

/// ,    
/// ,        false
bool URpcDecoderCommon::IsCmdSupported(const UEPtr<URpcCommand> &command) const
{
 if(!command || !command->IsDecoded)
  return false;

 std::string cmd=command->FunctionName;
 if(cmd == "RpcPing")
 {
  return true;
 }
 else
 if(cmd == "SetNumChannels")
 {
  return true;
 }
 else
 if(cmd == "GetNumChannels")
 {
  return true;
 }
 else
 if(cmd == "GetServerName")
 {
  return true;
 }
 else
 if(cmd == "GetServerId")
 {
  return true;
 }
 else
 if(cmd == "GetChannelName")
 {
  return true;
 }
 else
 if(cmd == "SetChannelName")
 {
  return true;
 }
 else
 if(cmd == "GetChannelVideoSource")
 {
  return true;
 }
 else
 if(cmd == "SetChannelVideoSource")
 {
  return true;
 }
 else
 if(cmd == "CheckChannelVideoSourceConnection")
 {
  return true;
 }
 else
 if(cmd == "GetChannelBroacaster")
 {
  return true;
 }
 else
 if(cmd == "SetChannelBroadcaster")
 {
  return true;
 }
 else
 if(cmd == "ResetChannel")
 {
  return true;
 }
 else
 if(cmd == "StartChannel")
 {
  return true;
 }
 else
 if(cmd == "StopChannel")
 {
  return true;
 }
 else
 if(cmd == "RegisterMetadataReceiver")
 {
  return true;
 }
 else
 if(cmd == "UnRegisterMetadataReceiver")
 {
  return true;
 }
 else
 if(cmd == "LoadProject")
 {
131
  return true;
132
133
134
135
 }
 else
 if(cmd == "SaveProject")
 {
136
  return true;
137
138
139
140
141
142
143
144
145
146
147
148
 }
 else
 if(cmd == "ReadImageFromVideoSource")
 {
  return true;
 }
 else
 if(cmd == "StartVideoSource")
 {
  return true;
 }
 else
149
150
151
152
153
154
155
156
157
 if(cmd == "DeployProject")
 {
  return true;
 }
 else
 if(cmd == "GetDeploymentState")
 {
  return true;
 }
158
159
160
161
162
 else
 if(cmd == "GetLastError")
 {
  return true;
 }
Aivan_2008's avatar
Aivan_2008 committed
163
 else
Aivan_2008's avatar
Aivan_2008 committed
164
165
166
167
168
169
 if(cmd == "PrepareProject")
 {
  return true;
 }
 else
 if(cmd == "OpenPreparedProject")
Aivan_2008's avatar
Aivan_2008 committed
170
171
172
 {
  return true;
 }
173
174
175
176
177
178
179
180
181
182
183
 /*else
 if(cmd == "GetDeploymentStageMax")
 {
  return true;
 }
 else
 if(cmd == "GetDeploymentStagePosition")
 {
  return true;
 }*/
 else
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
 if(cmd == "StopVideoSource")
  return true;

 return false;
}

///        
///  false    
bool URpcDecoderCommon::AProcessCommand(const UEPtr<URpcCommand> &command)
{
 if(!command)
 {
  //  -   
  return false;
 }

 UEPtr<URpcCommandInternal> cmd=dynamic_pointer_cast<URpcCommandInternal>(command);
 if(!cmd)
 {
  //  -    
204
  MLog_LogMessage(command->ChannelIndex, RDK_EX_WARNING, (std::string("RPC Common Decoder : Command internal structure not supported. CmdId=")+sntoa(command->GetCmdId())+std::string(" Command=")+command->FunctionName).c_str());
205
206
207
208
209
210
211
212
213
214
215
216
217
218
  return false;
 }

 const char* response=RemoteCall(cmd->Request.c_str(), cmd->ResponseStatus, cmd->ChannelIndex);

 if(response)
  cmd->Response=response;
 else
  cmd->Response=RDK::sntoa(cmd->ResponseStatus);

 MEngine_FreeBufString(cmd->ChannelIndex, response);

 if(cmd->ResponseStatus == 2001)
 {
219
  MLog_LogMessage(command->ChannelIndex, RDK_EX_WARNING, (std::string("RPC Common Decoder: Unknown command. CmdId=")+sntoa(command->GetCmdId())+std::string(" Command=")+command->FunctionName).c_str());
220
221
222
223
224
225
226
  return false;
 }

 cmd->IsProcessed=true;
 return true;
}

227
const char* URpcDecoderCommon::RemoteCall(const char *request, int &return_value, int &res_channel_index)
228
229
230
231
232
233
234
{
 return_value=INT_MAX;

 RDK::USerStorageXML xml,xml_data;

 xml.Load(request,"RpcRequest");

235
 int channel_index=-1;
236
237
 std::string cmd;
 std::string component_name;
238
 res_channel_index=0;
239
240
241
242
243
244
245
246


 if(!ExtractCmd(xml,cmd) || cmd.empty())
 {
  return_value=2000;
  return 0;
 }

247
 if(!ExtractCC(xml,channel_index,component_name))
248
 {
249
  ExtractChannel(xml,channel_index);
250
251
252
  ExtractComponent(xml,component_name);
 }
  /*
253
 if((channel_index < 0 || channel_index >= GetNumEngines()) &&
254
255
256
257
258
259
	(cmd != "GetNumChannels" && cmd !="SetNumChannels"))
 {
  return_value=2001;
  return 0;
 }  */

260
 res_channel_index=channel_index;
261
262
263
264
265
266
267
268
269
270
271
 std::string response,temp;
 std::string name;

 RDK::USerStorageXML result;
 result.Create("RpcResponse");
 result.WriteString("Id", xml.ReadString("Id",""));
// if(cmd == "EngineInit")
// {
// }
// else
// {
272
 response=ARemoteCall(cmd,xml,component_name, channel_index, return_value);
273
274
275
276
277
278
279
280
281
 if(return_value == 2001)
 {
  if(cmd == "RpcPing")
  {
   return_value=0;
  }
  else
  if(cmd == "SetNumChannels")
  {
282
283
   int num_engines=xml.ReadInteger("NumChannels",Core_GetNumChannels());
   if(GetApplication()->SetNumChannels(num_engines))
284
285
286
287
288
289
290
	return_value=0;//UServerControlForm->SetNumChannels(num_engines);
   else
	return_value=112112;//UServerControlForm->SetNumChannels(num_engines);
  }
  else
  if(cmd == "GetNumChannels")
  {
291
   response=RDK::sntoa(GetApplication()->GetNumChannels());
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
   return_value=0;
  }
  else
  if(cmd == "GetServerName")
  {
   response=GetApplication()->GetServerControl()->GetServerName();
   return_value=0;
  }
  else
  if(cmd == "GetServerId")
  {
   response=GetApplication()->GetServerControl()->GetServerId();
   return_value=0;
  }
  else
  if(cmd == "GetChannelName")
  {
309
   response=GetApplication()->GetProjectConfig().ChannelsConfig[channel_index].ChannelName;
310
311
312
313
314
315
316
317
   return_value=0;
  }
  else
  if(cmd == "SetChannelName")
  {
   std::string ch_name=xml.ReadString("Name","");
   if(!ch_name.empty())
   {
Aleksandr Bakhshiev's avatar
Aleksandr Bakhshiev committed
318
	TProjectConfig config=GetApplication()->GetProjectConfig();
319
	config.ChannelsConfig[channel_index].ChannelName=ch_name;
Aleksandr Bakhshiev's avatar
Aleksandr Bakhshiev committed
320
	GetApplication()->SetProjectConfig(config);
321
322
323
324
325
326
   }
   return_value=0;
  }
  else
  if(cmd == "ResetChannel")
  {
327
   GetApplication()->ResetChannel(channel_index);
328
329
330
331
332
   return_value=0;
  }
  else
  if(cmd == "StartChannel")
  {
333
   GetApplication()->StartChannel(channel_index);
334
335
336
337
338
   return_value=0;
  }
  else
  if(cmd == "StopChannel")
  {
339
   GetApplication()->PauseChannel(channel_index);
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
   return_value=0;
  }
  else
  if(cmd == "RegisterMetadataReceiver")
  {
   string address=xml.ReadString("Address","");
   int port=xml.ReadInteger("Port",8888);
   return_value=GetApplication()->GetServerControl()->RegisterMetadataReceiver(address, port);
  }
  else
  if(cmd == "UnRegisterMetadataReceiver")
  {
   string address=xml.ReadString("Address","");
   int port=xml.ReadInteger("Port",1000);
   return_value=GetApplication()->GetServerControl()->UnRegisterMetadataReceiver(address, port);
  }
  else
  if(cmd == "LoadProject")
  {
   std::string file_name=xml.ReadString("FileName","");
   if(!file_name.empty())
   {
362
363
364
       GetApplication()->OpenProject(file_name);
       RDK::UIVisualControllerStorage::UpdateInterface(true);
       return_value=0;//UServerControlForm->LoadProject(channel_index,file_name);
365
366
367
368
369
   }
  }
  else
  if(cmd == "SaveProject")
  {
370
371
   GetApplication()->SaveProject();
   return_value=0;//UServerControlForm->SaveProject();
372
  }
373
374
375
376
377
378
379
380
381
382
383
384
385
386
  else
  if(cmd == "DeployProject")
  {
   int task_id=xml.ReadInteger("TaskId",-1);
   int resp = GetApplication()->GetProjectDeployer()->StartProjectDeployment(task_id);
   std::stringstream ss;
   ss<<resp;
   response = ss.str();
   return_value=0;
  }
  else
  if(cmd == "GetDeploymentState")
  {
   //GetApplication()->SaveProject();
387
   int d_state = GetApplication()->GetProjectDeployer()->GetDeploymentState();
388
389
390
391
   int stage_max = GetApplication()->GetProjectDeployer()->GetStageCap();
   int stage_pos = GetApplication()->GetProjectDeployer()->GetStageProgress();

   std::stringstream ss;
392
   ss<<d_state<<" "<<stage_pos<<" "<<stage_max;
393
394
395
   response=ss.str();
   return_value=0;//UServerControlForm->SaveProject();
  }
396
397
398
399
  else
  if(cmd == "GetLastError")
  {
   std::string last_error=GetApplication()->GetProjectDeployer()->GetLastError();
Aivan_2008's avatar
Aivan_2008 committed
400
401
402
403
   response=last_error;
   return_value=0;
  }
  else
Aivan_2008's avatar
Aivan_2008 committed
404
  if(cmd == "PrepareProject")
Aivan_2008's avatar
Aivan_2008 committed
405
  {
Aivan_2008's avatar
Aivan_2008 committed
406
407
408
409
410
411
412
413
414
415
416
417
    std::string resp="";
    int rs = GetApplication()->GetProjectDeployer()->PrepareProject(resp="");
    response=resp;
    return_value=0;
  }
  else
  if(cmd=="OpenPreparedProject")
  {
    std::string resp="";
    int rs = GetApplication()->GetProjectDeployer()->OpenPreparedProject(resp);
    response=resp;
    return_value=0;
418
  }
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
/*
  else
  if(cmd == "GetDeploymentStageMax")
  {
   //GetApplication()->SaveProject();

   std::stringstream ss;
   ss<<stage_max;
   response=ss.str();
   return_value=0;//UServerControlForm->SaveProject();
  }
  else
  if(cmd == "GetDeploymentStagePosition")
  {
   //GetApplication()->SaveProject();
   int stage_pos = GetApplication()->GetProjectDeployer()->GetStageProgress();
   std::stringstream ss;
   ss<<stage_pos;
   response=ss.str();
   return_value=0;//UServerControlForm->SaveProject();
  }
*/
441
442
443
444
445
446
447
 }
// }

 result.SelectRoot();
 if(!response.empty())
 {
  result.WriteString("Data",response);
448
//  MEngine_FreeBufString(channel_index,response);
449
450
451
452
 }
 else
  result.WriteString("Data","");
 result.WriteInteger("Res",return_value);
453
 MCore_LockChannel(0);
454
455
 std::string &buffer=GetEngine(0)->CreateTempString();
 result.Save(buffer);
456
 MCore_UnLockChannel(0);
457
458
459
460

 return buffer.c_str();
}

461
std::string URpcDecoderCommon::ARemoteCall(const std::string &cmd, RDK::USerStorageXML &xml, const std::string &component_name, int channel_index, int &return_value)
462
463
464
465
466
467
468
469
470
{
 return_value=2001;
 return "";
}
// --------------------------

}
#endif