TTEthernet Model for INET Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
TTEAPIApplicationBase.cc
Go to the documentation of this file.
1 //
2 // This program is free software: you can redistribute it and/or modify
3 // it under the terms of the GNU Lesser General Public License as published by
4 // the Free Software Foundation, either version 3 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public License
13 // along with this program. If not, see http://www.gnu.org/licenses/.
14 //
15 
16 #include "TTEAPIApplicationBase.h"
17 #include "EtherMACFullDuplex.h"
18 #include "Incoming.h"
19 #include "TTIncoming.h"
20 #include "RCIncoming.h"
21 #include "TTBuffer.h"
22 #include "RCBuffer.h"
23 #include "BGBuffer.h"
24 #include "APIPayload_m.h"
25 #include "Task.h"
26 #include "TTEScheduler.h"
27 #include "SyncNotification_m.h"
28 #include "CTFrame.h"
29 
30 #include "Ethernet.h"
31 
32 namespace TTEthernetModel {
33 
34 Define_Module(TTEAPIApplicationBase);
35 
36 
38 {
39  scheduleAt(simTime(), new cMessage("Start Application", START_APPLICATION));
40 }
41 
43 {
44  if(msg->isSelfMessage() && msg->getKind() == START_APPLICATION){
46  delete msg;
47  }
48  if(msg->arrivedOn("schedulerIn")){
49  Task *task = (Task*)msg->par("task").pointerValue();
50  task->executeTask();
51  //Reregister scheduler
52  TTEScheduler *tteScheduler = (TTEScheduler*) getParentModule()->getSubmodule("tteScheduler");
53  tteScheduler->registerEvent((SchedulerEvent *) msg);
54  }
55  if(msg->arrivedOn("syncIn")){
56  SyncNotification *notification = (SyncNotification*)msg;
57  if(notification->getKind()==SYNC){
58  synchronized=true;
59  }
60  else{
61  synchronized=false;
62  }
63  }
64 }
65 
67  ev << "TTEAPIApplicationBase::startApplication() not implemented" << endl;
68  throw;
69 }
70 
71 void TTEAPIApplicationBase::registerTask(unsigned int actionTime, void (*functionPointer)(void*), void *setFunctionArg){
72  Task *task = new Task();
73  task->setFunctionPointer(functionPointer);
74  task->setFunctionArg(setFunctionArg);
75 
76  //Register Event
77  TTEScheduler *tteScheduler = (TTEScheduler*) getParentModule()->getSubmodule("tteScheduler");
78  SchedulerActionTimeEvent *event = new SchedulerActionTimeEvent("API Scheduler Task Event", ACTION_TIME_EVENT);
79 
80  event->addPar("task").setPointerValue(task);
81 
82  event->setAction_time(actionTime);
83  event->setDestinationGate(gate("schedulerIn"));
84  tteScheduler->registerEvent(event);
85 }
86 
87 int32_t TTEAPIApplicationBase::tte_get_ct_output_buf(const uint8_t ctrl_id,
88  const uint16_t ct_id,
89  tte_buffer_t * const buf){
90  Enter_Method_Silent();
91  std::map<uint16, std::list<Buffer *> >::iterator bufferList = buffers.find(ct_id);
92  if (bufferList != buffers.end())
93  {
94  //Currently we use only the first entry!
95  std::list<Buffer*>::iterator buffer = bufferList->second.begin();
96 
97  buf->ctrl_id=0;
98  buf->direction= TTE_DIR_OUTPUT;
99  if(dynamic_cast<TTBuffer*>(*buffer) != NULL){
100  buf->traffic_type= TTE_TT_TRAFFIC;
101  }
102  else if(dynamic_cast<RCBuffer*>(*buffer) != NULL){
103  buf->traffic_type= TTE_CT_TRAFFIC;
104  }
105  else{
106  buf->traffic_type= TTE_BG_TRAFFIC;
107  }
108  buf->channel=0;
109  buf->ct_id=ct_id;
110  buf->shared=0;
111 
112  TTEAPIPriv *priv = new TTEAPIPriv();
113  priv->buffer = (*buffer);
114 
115  buf->priv=priv;
116  return ETT_SUCCESS;
117 
118  }
119  else
120  {
121  return ETT_INVMSGID;
122  }
123 }
124 
125 int32_t TTEAPIApplicationBase::tte_get_bg_output_buf(const uint8_t ctrl_id, const uint8_t channel,
126  tte_buffer_t * const buf){
127  Enter_Method_Silent();
128  Buffer *buffer = dynamic_cast<Buffer*>(getParentModule()->getSubmodule("bgOut"));
129 
130  buf->ctrl_id=0;
131  buf->direction= TTE_DIR_OUTPUT;
132  buf->traffic_type= TTE_BG_TRAFFIC;
133 
134  buf->channel=0;
135  buf->shared=1;
136 
137  TTEAPIPriv *priv = new TTEAPIPriv();
138  priv->buffer = buffer;
139 
140  buf->priv=priv;
141  return ETT_SUCCESS;
142 }
143 
144 int32_t TTEAPIApplicationBase::tte_get_bg_input_buf(const uint8_t ctrl_id, const uint8_t channel,
145  tte_buffer_t * const buf){
146  Enter_Method_Silent();
147  Buffer *buffer = dynamic_cast<Buffer*>(getParentModule()->getSubmodule("bgIn"));
148 
149  buf->ctrl_id=0;
150  buf->direction= TTE_DIR_INPUT;
151  buf->traffic_type= TTE_BG_TRAFFIC;
152 
153  buf->channel=0;
154  buf->shared=1;
155 
156  TTEAPIPriv *priv = new TTEAPIPriv();
157  priv->buffer = buffer;
158 
159  buf->priv=priv;
160  return ETT_SUCCESS;
161 }
162 
163 int32_t TTEAPIApplicationBase::tte_get_ct_input_buf(const uint8_t ctrl_id,
164  const uint16_t ct_id,
165  tte_buffer_t * const buf){
166  Enter_Method_Silent();
167  std::map<uint16, std::list<Buffer *> >::iterator bufferList = buffers.find(ct_id);
168  if (bufferList != buffers.end())
169  {
170  //Currently we use only the first entry!
171  std::list<Buffer*>::iterator buffer = bufferList->second.begin();
172 
173  buf->ctrl_id=0;
174  buf->direction= TTE_DIR_INPUT;
175  if(dynamic_cast<TTBuffer*>(*buffer) != NULL){
176  buf->traffic_type= TTE_TT_TRAFFIC;
177  }
178  else if(dynamic_cast<RCBuffer*>(*buffer) != NULL){
179  buf->traffic_type= TTE_CT_TRAFFIC;
180  }
181  else{
182  buf->traffic_type= TTE_BG_TRAFFIC;
183  }
184  buf->channel=0;
185  buf->ct_id=ct_id;
186  buf->shared=0;
187 
188  TTEAPIPriv *priv = new TTEAPIPriv();
189  priv->buffer = (*buffer);
190 
191  buf->priv=priv;
192  return ETT_SUCCESS;
193 
194  }
195  else
196  {
197  return ETT_INVMSGID;
198  }
199 }
200 
201 int32_t TTEAPIApplicationBase::tte_get_var(const uint8_t ctrl_id,
202  const tte_var_id_t var_id,
203  const uint32_t var_size,
204  void * const value){
205  Enter_Method_Silent();
206  switch(var_id){
207  case TTE_VAR_LINK_STATUS:{
208  cModule *phy = getParentModule()->getSubmodule("phy", 0);
209  if(phy){
210  for(int i=0;i<phy->getVectorSize();i++){
211  EtherMACFullDuplex *mac = (EtherMACFullDuplex*)getParentModule()->getSubmodule("phy", i)->getSubmodule("mac");
212  if(mac->gate("phys")->isConnected())
213  *((uint8_t*)value) = *((uint8_t*)value)<<1 | 1;
214  else
215  *((uint8_t*)value) = *((uint8_t*)value)<<1;
216  }
217  }
218  else{
219  *((uint8_t*)value) = 0;
220  return ETT_NULLPTR;
221  }
222  break;
223  }
224  case TTE_VAR_CTRL_STATUS:{
225  *((uint32_t*)value) = TTE_STAT_CONFIGURED | TTE_STAT_RUNNING;
226  if(synchronized){
227  *((uint32_t*)value) |= TTE_STAT_SYNCHRONIZED;
228  }
229  break;
230  }
231  case TTE_VAR_CTRL_COUNT:{
232  *((uint8_t*)value) = 1;
233  break;
234  }
235  case TTE_VAR_CHANNEL_COUNT:{
236  cModule *phy = getParentModule()->getSubmodule("phy", 0);
237  if(phy){
238  *((uint8_t*)value) = phy->getVectorSize();
239  }
240  else{
241  *((uint8_t*)value) = 0;
242  return ETT_NULLPTR;
243  }
244  break;
245  }
246  case TTE_VAR_TIME_RESOLUTION:{
247  cModule *scheduler = getParentModule()->getSubmodule("tteScheduler", -1);
248  if(scheduler){
249  *((tte_time_t*)value) = scheduler->par("tick").doubleValue();
250  }
251  else{
252  *((tte_time_t*)value) = 0;
253  return ETT_NULLPTR;
254  }
255  break;
256  }
257  case TTE_VAR_API_VERSION:{
258  *((uint32_t*)value) = TTE_API_VER;
259  break;
260  }
261  case TTE_VAR_THREAD_SAFE:{
262  //TODO: CHECK WHETHER IT IS POSSIBLE TO SET TO TRUE (1)
263  *((uint8_t*)value) = 0;
264  break;
265  }
266  case TTE_VAR_MAC_ADDRESS:{
267  uint8_t *valueArr= (uint8_t *)value;
268  cModule *phy = getParentModule()->getSubmodule("phy", 0);
269  if(phy){
270  EtherMACFullDuplex *mac = (EtherMACFullDuplex*)phy->getSubmodule("mac");
271  MACAddress macAddress = mac->getMACAddress();
272  //Change order
273  valueArr[5] = macAddress.getAddressByte(0);
274  valueArr[4] = macAddress.getAddressByte(1);
275  valueArr[3] = macAddress.getAddressByte(2);
276  valueArr[2] = macAddress.getAddressByte(3);
277  valueArr[1] = macAddress.getAddressByte(4);
278  valueArr[0] = macAddress.getAddressByte(5);
279  }
280  else{
281  valueArr[0] = valueArr[1] = valueArr[2] = valueArr[3] = valueArr[4] = valueArr[5] = 0;
282  return ETT_NULLPTR;
283  }
284  break;
285  }
286  default:
287  return ETT_NOTSUPPORTED;
288  }
289  return ETT_SUCCESS;
290 }
291 
292 int32_t TTEAPIApplicationBase::tte_open_output_buf(tte_buffer_t * const buf,
293  tte_frame_t * const frame){
294  Enter_Method_Silent();
295  TTEAPIPriv *priv = (TTEAPIPriv*)buf->priv;
296 
297  //Now we create a frame that can be accessed later
298  //TODO Divide TT and RC frames in separate types?
299  if(buf->traffic_type==TTE_BG_TRAFFIC){
300  priv->frame = new EtherFrame("BG-Traffic Ethernet Frame", IEEE802CTRL_DATA);
301  }
302  else{
303  std::stringstream frameNameStream;
304  frameNameStream << "CT-ID: " << buf->ct_id;
305  std::string frameName = frameNameStream.str();
306  priv->frame = new CTFrame(frameName.c_str(), IEEE802CTRL_DATA);
307  }
308  priv->frame->setByteLength(ETHER_MAC_FRAME_BYTES);
309 
310  MACAddress dest;
311  dest.setAddressByte(5, frame->eth_hdr.dst_mac[0]);
312  dest.setAddressByte(4, frame->eth_hdr.dst_mac[1]);
313  dest.setAddressByte(3, frame->eth_hdr.dst_mac[2]);
314  dest.setAddressByte(2, frame->eth_hdr.dst_mac[3]);
315  dest.setAddressByte(1, frame->eth_hdr.dst_mac[4]);
316  dest.setAddressByte(0, frame->eth_hdr.dst_mac[5]);
317  priv->frame->setDest(dest);
318  MACAddress src;
319  src.setAddressByte(5, frame->eth_hdr.src_mac[0]);
320  src.setAddressByte(4, frame->eth_hdr.src_mac[1]);
321  src.setAddressByte(3, frame->eth_hdr.src_mac[2]);
322  src.setAddressByte(2, frame->eth_hdr.src_mac[3]);
323  src.setAddressByte(1, frame->eth_hdr.src_mac[4]);
324  src.setAddressByte(0, frame->eth_hdr.src_mac[5]);
325  priv->frame->setSrc(src);
326 
327  APIPayload *payload = new APIPayload("TTEthernet API Payload");
328  payload->setByteLength(frame->length);
329  payload->setDataArraySize(frame->length);
330  priv->frame->encapsulate(payload);
331 
332  frame->data = (uint8_t*)malloc(frame->length);
333  if(!frame->data)
334  return ETT_NOMEM;
335  priv->data = frame->data;
336  return ETT_SUCCESS;
337 }
338 
339 
340 int32_t TTEAPIApplicationBase::tte_open_input_buf(tte_buffer_t * const buf,
341  tte_frame_t * const frame,
342  tte_buf_status_t * const status){
343  Enter_Method_Silent();
344  TTEAPIPriv *priv = (TTEAPIPriv*)buf->priv;
345 
346 
347  EtherFrame *msg = priv->buffer->getFrame();
348  APIPayload *payload = dynamic_cast<APIPayload*>(msg->decapsulate());
349  if(buf->traffic_type==TTE_CT_TRAFFIC){
350  frame->ct_id = dynamic_cast<CTFrame*>(msg)->getCtID();
351  }
352  frame->length = payload->getByteLength();
353  frame->data = (uint8_t*)malloc(payload->getByteLength());
354  priv->data = frame->data;
355  MACAddress dest= msg->getDest();
356  frame->eth_hdr.dst_mac[0] = dest.getAddressByte(5);
357  frame->eth_hdr.dst_mac[1] = dest.getAddressByte(4);
358  frame->eth_hdr.dst_mac[2] = dest.getAddressByte(3);
359  frame->eth_hdr.dst_mac[3] = dest.getAddressByte(2);
360  frame->eth_hdr.dst_mac[4] = dest.getAddressByte(1);
361  frame->eth_hdr.dst_mac[5] = dest.getAddressByte(0);
362  MACAddress src= msg->getSrc();
363  frame->eth_hdr.src_mac[0] = src.getAddressByte(5);
364  frame->eth_hdr.src_mac[1] = src.getAddressByte(4);
365  frame->eth_hdr.src_mac[2] = src.getAddressByte(3);
366  frame->eth_hdr.src_mac[3] = src.getAddressByte(2);
367  frame->eth_hdr.src_mac[4] = src.getAddressByte(1);
368  frame->eth_hdr.src_mac[5] = src.getAddressByte(0);
369 
370  for(unsigned int i=0;i<payload->getDataArraySize();i++){
371  frame->data[i] = payload->getData(i);
372  }
373 
374  delete payload;
375  delete msg;
376 
377  return ETT_SUCCESS;
378 }
379 
380 int32_t TTEAPIApplicationBase::tte_close_output_buf(tte_buffer_t * const buf){
381  Enter_Method_Silent();
382  TTEAPIPriv *priv = (TTEAPIPriv *)buf->priv;
383  //Copy frame data and free memory
384  APIPayload *payload = (APIPayload*)priv->frame->getEncapsulatedPacket();
385  for(unsigned int i=0;i<payload->getDataArraySize();i++){
386  payload->setData(i, ((unsigned char *)priv->data)[i]);
387  }
388  //Send to CTC
389  if(priv->buffer)
390  if(priv->buffer->gate("in"))
391  if(priv->buffer->gate("in")->getPathStartGate())
392  if((cModule *)priv->buffer->gate("in")->getPathStartGate()->getOwner())
393  if(((cModule *)priv->buffer->gate("in")->getPathStartGate()->getOwner())->gate("in")){
394  sendDirect(priv->frame, ((cModule *)priv->buffer->gate("in")->getPathStartGate()->getOwner())->gate("in"));
395  }
396 
397  if(priv->data){
398  free(priv->data);
399  priv->data = NULL;
400  }
401  if(priv){
402  delete priv;
403  buf->priv=NULL;
404  }
405  return ETT_SUCCESS;
406 }
407 
408 int32_t TTEAPIApplicationBase::tte_close_input_buf(tte_buffer_t * const buf){
409  Enter_Method_Silent();
410  TTEAPIPriv *priv = (TTEAPIPriv *)buf->priv;
411  //Free memory
412  if(priv->data){
413  //free(priv->data);
414  priv->data = NULL;
415  }
416  if(priv){
417  delete priv;
418  buf->priv=NULL;
419  }
420  return ETT_SUCCESS;
421 }
422 
423 int32_t TTEAPIApplicationBase::tte_set_buf_var(tte_buffer_t * const buf,
424  const tte_buf_var_id_t var_id,
425  const uint32_t var_size,
426  const void * const value){
427  Enter_Method_Silent();
428  TTEAPIPriv *priv = (TTEAPIPriv*)buf->priv;
429  switch(var_id){
430  case TTE_BUFVAR_RECEIVE_CB:{
431  APICallback *cb = dynamic_cast<APICallback*>(priv->buffer->getReceiveCallback(this));
432  if(cb == NULL){
433  cb = new APICallback(priv->buffer);
434  priv->buffer->addReceiveCallback(cb, this);
435  }
436  cb->setFunctionPointer((void(*)(void *))value);
437  break;
438  }
439  case TTE_BUFVAR_TRANSMIT_CB:{
440  APICallback *cb = dynamic_cast<APICallback*>(priv->buffer->getTransmitCallback(this));
441  if(cb == NULL){
442  cb = new APICallback(priv->buffer);
443  priv->buffer->addTransmitCallback(cb, this);
444  }
445  cb->setFunctionPointer((void(*)(void *))value);
446  break;
447  }
448  case TTE_BUFVAR_CB_ARG:{
449  APICallback *cb = dynamic_cast<APICallback*>(priv->buffer->getReceiveCallback(this));
450  if(cb == NULL){
451  cb = dynamic_cast<APICallback*>(priv->buffer->getTransmitCallback(this));
452  if(cb == NULL){
453  return ETT_NULLPTR;
454  }
455  cb->setFunctionArg((void*)value);
456  }
457  else{
458  cb->setFunctionArg((void*)value);
459  }
460  break;
461  }
462  default:
463  return ETT_NOTSUPPORTED;
464  }
465  return ETT_SUCCESS;
466 }
467 
468 int32_t TTEAPIApplicationBase::tte_get_buf_var(const tte_buffer_t * const buf,
469  const tte_buf_var_id_t var_id,
470  const uint32_t var_size,
471  void * const value){
472  Enter_Method_Silent();
473  TTEAPIPriv *priv = (TTEAPIPriv*)buf->priv;
474  switch(var_id){
475  case TTE_BUFVAR_RECEIVE_CB:{
476  APICallback *cb = dynamic_cast<APICallback*>(priv->buffer->getReceiveCallback(this));
477  if(cb == NULL){
478  return ETT_NULLPTR;
479  }
480  void (*func)(void *) = cb->getFunctionPointer();
481  memcpy(value, &func, sizeof(void (*)(void *)));
482  break;
483  }
484  case TTE_BUFVAR_TRANSMIT_CB:{
485  APICallback *cb = dynamic_cast<APICallback*>(priv->buffer->getTransmitCallback(this));
486  if(cb == NULL){
487  return ETT_NULLPTR;
488  }
489  void (*func)(void *) = cb->getFunctionPointer();
490  memcpy(value, &func, sizeof(void (*)(void *)));
491  break;
492  }
493  case TTE_BUFVAR_CB_ARG:{
494  APICallback *cb = dynamic_cast<APICallback*>(priv->buffer->getReceiveCallback(this));
495  if(cb == NULL){
496  APICallback *cb = dynamic_cast<APICallback*>(priv->buffer->getTransmitCallback(this));
497  if(cb == NULL){
498  return ETT_NULLPTR;
499  }
500  void * arg=cb->getFunctionArg();
501  memcpy(value, &arg, sizeof(void *));
502  }
503  else{
504  void * arg=cb->getFunctionArg();
505  memcpy(value, &arg, sizeof(void *));
506  }
507  break;
508  }
509  default:
510  return ETT_NOTSUPPORTED;
511  }
512  return ETT_SUCCESS;
513 }
514 
515 extern "C" int32_t tte_init(void){
516  return ETT_NOTSUPPORTED;
517 }
518 
519 
520 extern "C" int32_t tte_start(const uint8_t ctrl_id){
521  return ETT_NOTSUPPORTED;
522 }
523 
524 extern "C" int32_t tte_stop(const uint8_t ctrl_id){
525  return ETT_NOTSUPPORTED;
526 }
527 
528 
529 extern "C" int32_t tte_exit(void){
530  return ETT_NOTSUPPORTED;
531 }
532 
533 extern "C" int32_t tte_configure(const uint8_t ctrl_id,
534  const tte_conf_t * const conf){
535  return ETT_NOTSUPPORTED;
536 }
537 
538 extern "C" int32_t tte_set_var(const uint8_t ctrl_id,
539  const tte_var_id_t var_id,
540  const uint32_t var_size,
541  const void * const value){
542  return ETT_NOTSUPPORTED;
543 }
544 
545 extern "C" int32_t tte_get_var(const uint8_t ctrl_id,
546  const tte_var_id_t var_id,
547  const uint32_t var_size,
548  void * const value){
549  TTEAPIApplicationBase *app = dynamic_cast<TTEAPIApplicationBase*>(cSimulation::getActiveSimulation()->getContext());
550  if(app != NULL)
551  return app->tte_get_var(ctrl_id, var_id, var_size, value);
552  return ETT_NULLPTR;
553 }
554 
555 extern "C" int32_t tte_get_ct_input_buf(const uint8_t ctrl_id,
556  const uint16_t ct_id,
557  tte_buffer_t * const buf){
558  TTEAPIApplicationBase *app = dynamic_cast<TTEAPIApplicationBase*>(cSimulation::getActiveSimulation()->getContext());
559  if(app != NULL)
560  return app->tte_get_ct_input_buf(ctrl_id, ct_id, buf);
561  return ETT_NULLPTR;
562 }
563 
564 extern "C" int32_t tte_get_ct_output_buf(const uint8_t ctrl_id,
565  const uint16_t ct_id,
566  tte_buffer_t * const buf){
567  TTEAPIApplicationBase *app = dynamic_cast<TTEAPIApplicationBase*>(cSimulation::getActiveSimulation()->getContext());
568  if(app != NULL)
569  return app->tte_get_ct_output_buf(ctrl_id, ct_id, buf);
570  return ETT_NULLPTR;
571 }
572 
573 extern "C" int32_t tte_get_bg_input_buf(const uint8_t ctrl_id,
574  const uint8_t channel,
575  tte_buffer_t * const buf){
576  TTEAPIApplicationBase *app = dynamic_cast<TTEAPIApplicationBase*>(cSimulation::getActiveSimulation()->getContext());
577  if(app != NULL)
578  return app->tte_get_bg_input_buf(ctrl_id, channel, buf);
579  return ETT_NULLPTR;
580 }
581 
582 extern "C" int32_t tte_get_bg_output_buf(const uint8_t ctrl_id,
583  const uint8_t channel,
584  tte_buffer_t * const buf){
585  TTEAPIApplicationBase *app = dynamic_cast<TTEAPIApplicationBase*>(cSimulation::getActiveSimulation()->getContext());
586  if(app != NULL)
587  return app->tte_get_bg_output_buf(ctrl_id, channel, buf);
588  return ETT_NULLPTR;
589 }
590 
591 extern "C" int32_t tte_write_output_buf(tte_buffer_t * const buf,
592  tte_frame_t * const frame){
593  //TODO High prio
594  return ETT_NOTSUPPORTED;
595 }
596 
597 extern "C" int32_t tte_read_input_buf(tte_buffer_t * const buf,
598  tte_frame_t * const frame,
599  tte_buf_status_t * const status){
600  //TODO High prio
601  return ETT_NOTSUPPORTED;
602 }
603 
604 extern "C" int32_t tte_open_input_buf(tte_buffer_t * const buf,
605  tte_frame_t * const frame,
606  tte_buf_status_t * const status){
607  TTEAPIApplicationBase *app = dynamic_cast<TTEAPIApplicationBase*>(cSimulation::getActiveSimulation()->getContext());
608  if(app != NULL)
609  return app->tte_open_input_buf(buf, frame, status);
610  return ETT_NULLPTR;
611 }
612 
613 extern "C" int32_t tte_close_input_buf(tte_buffer_t * const buf){
614  TTEAPIApplicationBase *app = dynamic_cast<TTEAPIApplicationBase*>(cSimulation::getActiveSimulation()->getContext());
615  if(app != NULL)
616  return app->tte_close_input_buf(buf);
617  return ETT_NULLPTR;
618 }
619 
620 extern "C" int32_t tte_open_output_buf(tte_buffer_t * const buf,
621  tte_frame_t * const frame){
622  TTEAPIApplicationBase *app = dynamic_cast<TTEAPIApplicationBase*>(cSimulation::getActiveSimulation()->getContext());
623  if(app != NULL)
624  return app->tte_open_output_buf(buf, frame);
625  return ETT_NULLPTR;
626 }
627 
628 extern "C" int32_t tte_close_output_buf(tte_buffer_t * const buf){
629  TTEAPIApplicationBase *app = dynamic_cast<TTEAPIApplicationBase*>(cSimulation::getActiveSimulation()->getContext());
630  if(app != NULL)
631  return app->tte_close_output_buf(buf);
632  return ETT_NULLPTR;
633 }
634 
635 extern "C" int32_t tte_get_buf_var(const tte_buffer_t * const buf,
636  const tte_buf_var_id_t var_id,
637  const uint32_t var_size,
638  void * const value){
639  TTEAPIApplicationBase *app = dynamic_cast<TTEAPIApplicationBase*>(cSimulation::getActiveSimulation()->getContext());
640  if(app != NULL)
641  return app->tte_get_buf_var(buf, var_id, var_size, value);
642  return ETT_NULLPTR;
643 }
644 
645 extern "C" int32_t tte_set_buf_var(tte_buffer_t * const buf,
646  const tte_buf_var_id_t var_id,
647  const uint32_t var_size,
648  const void * const value){
649  TTEAPIApplicationBase *app = dynamic_cast<TTEAPIApplicationBase*>(cSimulation::getActiveSimulation()->getContext());
650  if(app != NULL)
651  return app->tte_set_buf_var(buf, var_id, var_size, value);
652  return ETT_NULLPTR;
653 }
654 
655 extern "C" int32_t tte_flush_buffers(const uint8_t ctrl_id){
656  return ETT_NOTSUPPORTED;
657 }
658 
659 extern "C" int32_t tte_flush_tt_buffers(const uint8_t ctrl_id){
660  return ETT_NOTSUPPORTED;
661 }
662 
663 extern "C" int32_t tte_flush_bg_buffers(const uint8_t ctrl_id, const uint8_t channel){
664  return ETT_NOTSUPPORTED;
665 }
666 
667 
668 
669 } //namespace