source: trunk/ETSI-Testsuites/ETSI_auto_IOT/adapter/src/UpperTestAdapter/TriggerCommandsGUI/UEUserGuideClient.cpp

Last change on this file was 22, checked in by rings, 14 years ago
  • Property svn:executable set to *
File size: 2.0 KB
RevLine 
[22]1#include "UEUserGuideClient.h"
2#include <sstream>
3#include <iostream>
4
5#include "Logger/Logger.h"
6
7#include "Processors/TriggerCommandsStrategy.h"
8
9using namespace std;
10
11namespace UpperTestAdapter {
12 
13namespace Processors {
14 
15namespace TriggerCommandsGUI {
16 
17int UEUserGuideClient::SendCommand(boost::shared_ptr<EutIPInterface> eutIface, const std::string &trigger, const std::vector<std::string> &parameterList)
18{
19  stringstream ss;
20  ss << "UEUserGuideClient::SendCommand: " << trigger << " - " << eutIface.get()->Eut() << " - " << eutIface.get()->EutAddress() << " - " << eutIface.get()->EutPort();
21  Logger::Instance().LogInfo(ss.str());
22
23  // Encode the request.
24  UEUserGuideClientRequest req;
25  req.SetTriggerCommand(trigger, parameterList);
26  // Place the connection.
27  try
28  {
29    m_client = boost::shared_ptr<SocketClient>(new SocketClient(eutIface.get()->EutAddress(), eutIface.get()->EutPort()));
30    // Send message.
31    m_client.get()->Send(req.GetEncodedMessage(), req.GetEncodedDataLength());
32    // Wait the response.
33    char buffer[64] = {0};
34    int readBytes = m_client.get()->Receive(64, buffer);
35    ss.str("");
36    ss << "UEUserGuideClient::SendCommand: received " << readBytes << " bytes";
37    Logger::Instance().LogInfo(ss.str());
38    // Disconnect.
39    m_client.reset();
40  // Process the result.
41  if (readBytes != 2)
42  {
43    return -1;
44  }
45 
46    ss.str("");
47    ss << "UEUserGuideClient::SendCommand: return " << static_cast<int>((buffer[0] << 4) & 0xf0 | buffer[1] & 0x0f);
48    Logger::Instance().LogInfo(ss.str());
49    int result = 1;
50    switch (static_cast<int>((buffer[0] << 4) & 0xf0 | buffer[1] & 0x0f))
51    {
52      case TriggerCommandsStrategy::ButtonYes: // Button Yes
53      case TriggerCommandsStrategy::ButtonOk: // Button Ok
54        result = 0;
55        break;
56    }
57 
58    return result;
59  }
60  catch (string & e)
61  {
62    Logger::Instance().LogError(e);
63    return -1;
64  }
65}
66
67} } } // namespaces
Note: See TracBrowser for help on using the repository browser.