source: trunk/ETSI-Testsuites/ETSI_auto_IOT/adapter/src/UpperTestAdapter/UpperTestAdapter.cpp @ 32

Last change on this file since 32 was 22, checked in by rings, 14 years ago
  • Property svn:executable set to *
File size: 10.1 KB
Line 
1#include "UpperTestAdapter.h"
2#include <utility>
3#include <iostream>
4
5#include "Logger/Logger.h"
6
7#include "Processors/Processor.h"
8
9using namespace t3devlib;
10using namespace boost;
11using namespace std;
12
13namespace UpperTestAdapter {
14
15using namespace Processors;
16
17UpperTestAdapter::UpperTestAdapter()
18{
19  std::clog << "UpperTestAdapter ctor() not implemented" << endl;
20}
21
22UpperTestAdapter::~UpperTestAdapter()
23{
24  stringstream ss;
25  Logger::Instance().LogDebug("UpperTestAdapter dtor()");
26 
27  // Delete not umapped ports.
28  for (map<const ComponentId *, pair<PortId *, shared_ptr<ProcessorsImpl> > >::iterator it = m_mapRegisteredPorts.begin(); it != m_mapRegisteredPorts.end(); ++it)
29  {
30    ss.str("");
31    ss << "UpperTestAdapter::~UpperTestAdapter: " << it->first;
32    Logger::Instance().LogInfo(ss.str());
33    (it->second).second.reset();
34  }
35  Logger::Instance().LogInfo("UpperTestAdapter::~UpperTestAdapter");
36  m_connectedComponents.clear();
37  m_mapRegisteredPorts.clear();
38}
39
40bool UpperTestAdapter::Initialize(boost::shared_ptr<GeneralConfigurationParams> configParams) throw(UpperTestAdapterException)
41{
42  stringstream ss;
43  Logger::Instance().LogDebug("UpperTestAdapter::Initialize");
44 
45  TriggerCommandsStrategy::Strategies strategy = TriggerCommandsStrategy::UEError;
46  if (configParams.get()->Mode() == ECaptureMode_Live)
47  {
48    Logger::Instance().LogDebug("UpperTestAdapter::Initialize: ECaptureMode_Live");
49    strategy = TriggerCommandsStrategy::UEUserGuide;
50    // Process te list of the EUT interfaces
51    if (configParams.get()->EutIpInterfaceList().size() == 0)
52    {
53      Logger::Instance().LogError("UpperTestAdapter::Initialize: Invalid Euts Ip Interface desciption");
54      throw UpperTestAdapterException("UpperTestAdapter::Initialize: Invalid Euts Ip Interface desciption");
55    }
56  }
57  else if (configParams.get()->Mode() == ECaptureMode_Offline)
58  {
59    Logger::Instance().LogDebug("UpperTestAdapter::Initialize: ECaptureMode_Offline");
60    strategy = TriggerCommandsStrategy::UEOffLine;
61  }
62  else
63  {
64    Logger::Instance().LogError("UpperTestAdapter::Initialize: Undefined strategy");
65    throw UpperTestAdapterException("UpperTestAdapter::Initialize: Undefined strategy");
66  }
67  // Set communication strategy.
68  ss.str("");
69  ss << "UpperTestAdapter::Initialize: m_mapRegisteredPorts size=" << m_mapRegisteredPorts.size();
70  Logger::Instance().LogDebug(ss.str());
71  ss.str("");
72  ss << "UpperTestAdapter::Initialize: EutIpInterfaceList=" << configParams.get()->EutIpInterfaceList().size();
73  Logger::Instance().LogDebug(ss.str());
74  if (m_mapRegisteredPorts.size() != 0)
75  {
76    vector<shared_ptr<EutIPInterface> >::iterator eutit = configParams.get()->EutIpInterfaceList().begin();
77    if (eutit != configParams.get()->EutIpInterfaceList().end())
78    {
79      list<const ComponentId *>::iterator componentItem = m_connectedComponents.begin();
80      for ( ; componentItem != m_connectedComponents.end(); ++componentItem)
81      {
82        // Find component into the registerd components map.
83        map<const ComponentId *, pair<PortId *, shared_ptr<ProcessorsImpl> > >::iterator it = m_mapRegisteredPorts.find(*componentItem);
84        if (it != m_mapRegisteredPorts.end())
85        {
86          // Commponent was found.
87          ss.str("");
88          ss << "UpperTestAdapter::Initialize: Process key =" << it->first << " - value = " << (it->second).first << "/" << (it->second).second.get();
89          Logger::Instance().LogDebug(ss.str());
90          // Set the strategy to apply
91          (it->second).second.get()->SetImplMode(strategy);
92          // Process the list of the EUT interfaces
93          /*
94           * Problem: I'm unable to retrieve the TTCN-3 name of the eaPort ("User A" and "User B"), worth, these port could be unnamed.
95           * As work-around I'll use the index, but the order should be respected in eutInfoList and mapping prot operations
96          string str = ((PortId *)it->second.first)->GetName();
97          clog << "UpperTestAdapter::Initialize: Port" << str << " - " << *((PortId *)it->second.first) << " - " << ((PortId *)it->second.first)->GetIndex() << endl;
98          clog << "UpperTestAdapter::Initialize: Component" <<  *(it->first) << " - " << *((it->first)->GetTriComponentId()) << endl;
99          if (eutIpInterfaceList.find(str) != eutIpInterfaceList.end())
100          {
101            (it->second).second.get()->SetEutIpInterface(eutIpInterfaceList[str]);
102          }
103          else
104          {
105            Logger::Instance().LogError("UpperTestAdapter::Initialize: EUT IP interface not registered");
106            throw UpperTestAdapterException("UpperTestAdapter::Initialize: EUT IP interface not registered");
107          }*/
108          (it->second).second.get()->SetEutIpInterface(*eutit);
109        }
110        else
111        {
112          // Commponent was not found.
113          ss.str("");
114          ss << "UpperTestAdapter::Initialize: Key =" << *componentItem << " not found";
115          Logger::Instance().LogError(ss.str());
116        }
117        eutit++;
118      } // 'for' loop.
119     
120      m_connectedComponents.clear();
121    }
122    else
123    {
124      Logger::Instance().LogInfo("UpperTestAdapter::Initialize: no EUT interface provided.");
125      map<const ComponentId *, pair<PortId *, shared_ptr<ProcessorsImpl> > >::iterator it = m_mapRegisteredPorts.begin();
126      for ( ; it != m_mapRegisteredPorts.end(); ++it)
127      {
128        ss.str("");
129        ss << "UpperTestAdapter::Initialize: Process key =" << it->first << " - value = " << (it->second).first << "/" << (it->second).second.get();
130        Logger::Instance().LogDebug(ss.str());
131        // Set the strategy to apply
132        (it->second).second.get()->SetImplMode(strategy);
133      }
134    }
135  }
136  else
137  {
138    Logger::Instance().LogInfo("UpperTestAdapter::Initialize: no EUT port registered.");
139  }
140 
141  return true;
142}
143
144void UpperTestAdapter::RegisterEquipmentAccessPort(PortId *pPort, const ComponentId *pComponent)
145{
146  stringstream ss;
147  ss << "UpperTestAdapter::RegisterEquipmentAccessPort: " << pComponent << "/" << pPort;
148  Logger::Instance().LogInfo(ss.str());
149
150  // Check if port is already registered.
151  map<const ComponentId *, pair<PortId *, shared_ptr<ProcessorsImpl> > >::iterator it = m_mapRegisteredPorts.find(pComponent);
152  if(it == m_mapRegisteredPorts.end())
153  {
154    // No, register it.
155    shared_ptr<ProcessorsImpl> ptr = shared_ptr<ProcessorsImpl>(new Processor);
156    m_mapRegisteredPorts.insert(
157        make_pair<const ComponentId *, pair<PortId *, shared_ptr<ProcessorsImpl> > >(
158          pComponent,
159          pair<PortId *, shared_ptr<ProcessorsImpl> >
160            (pPort, ptr)));
161    ss.str("");
162    ss << "UpperTestAdapter::RegisterEquipmentAccessPort: insert key=" << *pComponent << " - value = " << pPort << "/" << ptr;
163    Logger::Instance().LogDebug(ss.str());
164    // Add it into a temporary vector.
165    m_connectedComponents.push_back(pComponent);
166  }
167  else
168  {
169    // Yes, override it.
170    ss.str("");
171    ss << "UpperTestAdapter::RegisterEquipmentAccessPort: overriding registration port.";
172    Logger::Instance().LogError(ss.str());
173
174    m_mapRegisteredPorts[pComponent] = pair<PortId *, shared_ptr<ProcessorsImpl> >(pPort, (it->second).second);
175  }
176}
177
178PortId * UpperTestAdapter::GetEquipmentAccessPortIdFromComponent(const ComponentId& from)
179{
180  stringstream ss;
181  ss << "UpperTestAdapter::GetEquipmentAccessPortIdFromComponent: " << from << " - " << "UpperTestAdapter::GetEquipmentAccessPortIdFromComponent: " << &from;
182  Logger::Instance().LogInfo(ss.str());
183
184  map<const ComponentId *, pair<PortId *, shared_ptr<ProcessorsImpl> > >::iterator it = m_mapRegisteredPorts.find(&from);
185  if(it != m_mapRegisteredPorts.end())
186  {
187    ss.str("");
188    ss << "UpperTestAdapter::GetEquipmentAccessPortIdFromComponent: " << (it->second).first << " - " << *(it->second).first;
189    Logger::Instance().LogDebug(ss.str());
190    return (it->second).first;
191  }
192 
193  ss.str("");
194  ss << "UpperTestAdapter::GetEquipmentAccessPortIdFromComponent: Component not found - " << from << endl << "UpperTestAdapter::GetEquipmentAccessPortIdFromComponent: " << &from << endl;
195  Logger::Instance().LogError(ss.str());
196  return NULL;
197}
198
199int UpperTestAdapter::ProcessTriggerCommand(const ComponentId &from, const string &trigger, const vector<string> &parameterList)
200{
201  stringstream ss;
202  ss << "UpperTestAdapter::ProcessTriggerCommand: " << from << " - " << trigger;
203  Logger::Instance().LogInfo(ss.str());
204  ss.str("");
205  ss << "UpperTestAdapter::ProcessTriggerCommand: " << &from;
206  Logger::Instance().LogDebug(ss.str());
207
208  // Sanity check: Find component into the map.
209  map<const ComponentId *, pair<PortId *, shared_ptr<ProcessorsImpl> > >::iterator it = m_mapRegisteredPorts.find(&from);
210  if(it == m_mapRegisteredPorts.end())
211  {
212    ss.str("");
213    ss << "UpperTestAdapter::ProcessTriggerCommand: component " << from << " not found.";
214    Logger::Instance().LogError(ss.str());
215    return -1;
216  }
217
218  // Retrieve the message processor instance.
219  ss.str("");
220  ss << "UpperTestAdapter::ProcessTriggerCommand: key found: " << *(it->second).first << " - " << (it->second).second.get();
221  Logger::Instance().LogInfo(ss.str());
222  ProcessorsImpl *processor = (it->second).second.get();
223 
224  // Execute the TriggerCommand message.
225#ifndef __THREADED_MODE__
226  ss.str("");
227  ss << "UpperTestAdapter::ProcessTriggerCommand: Call Process for " << trigger;
228  Logger::Instance().LogDebug(ss.str());
229  int result = processor->Process(trigger, parameterList);
230  ss.str("");
231  ss << "UpperTestAdapter::RegisterEutConfigPort: return code: " << result;
232  Logger::Instance().LogError(ss.str());
233  return result;
234#else // __THREADED_MODE__
235  ss.str("");
236  ss << "UpperTestAdapter::ProcessTriggerCommand: Call BeginProcess for " << trigger;
237  Logger::Instance().LogDebug(ss.str());
238  if (!processor->BeginProcess(trigger, parameterList))
239  {
240    ss.str("");
241    ss << "UpperTestAdapter::RegisterEutConfigPort: Failed to process the message " << trigger << endl;
242    Logger::Instance().LogError(ss.str());
243    return -1;
244  }
245 
246  // Wait for the execution terminated.
247  Logger::Instance().LogDebug("UpperTestAdapter::ProcessTriggerCommand: Before Wait");
248  processor->Wait();
249  Logger::Instance().LogDebug("UpperTestAdapter::ProcessTriggerCommand: After Wait");
250#endif // __THREADED_MODE__
251
252  return result;
253}
254
255} // namespace
256
Note: See TracBrowser for help on using the repository browser.