OpcUaCanOpen
CANopen OPC-UA server
CanLibLoader.cpp
Go to the documentation of this file.
1 
23 #include "CanLibLoader.h"
24 #include "LogIt.h"
25 #include <string>
26 #include <stdexcept>
27 #ifdef _WIN32
28 #include "CanLibLoaderWin.h"
29 #else
30 #include "CanLibLoaderLin.h"
31 #endif
32 
33 namespace CanModule
34 {
35 
39  }
40 
42 
44  CanLibLoader* ret;
45 #ifdef WIN32
46  ret = new CanLibLoaderWin(libName);
47 #else
48  ret = new CanLibLoaderLin(libName);
49 #endif
50  return ret;
51  }
52 
54  LOG(Log::DBG, lh ) << __FUNCTION__<< " Canbus name to be deleted: " << cInter->getBusName();
55  delete cInter; // dtor calls stopBus()
56  }
57 
58  CCanAccess* CanLibLoader::openCanBus(string name, string parameters) {
59  LOG(Log::DBG, lh ) << __FUNCTION__ << " Creating CCanAccess: name= " << name << " parameters= " << parameters;
60  CCanAccess *tcca = createCanAccess();
61 
62  if ( !tcca ){
63  LOG(Log::ERR, lh ) << __FUNCTION__ << " failed to create CCanAccess name= " << name << " parameters= " << parameters;
64  exit(-1);
65  } else {
66  LOG(Log::DBG, lh ) << __FUNCTION__ << " created CCanAccess name= " << name << " parameters= " << parameters;
67  }
68 
69  //The Logit instance of the executable is handled to the DLL at this point, so the instance is shared.
70  LogItInstance *logInstance = LogItInstance::getInstance() ;
71  tcca->initialiseLogging( logInstance );
73 
74  LOG(Log::DBG, lh ) << __FUNCTION__ << " calling createBus. name= " << name << " parameters= " << parameters;
81  bool c = tcca->createBus(name, parameters);
82  if (c) {
83  LOG(Log::DBG, lh ) << __FUNCTION__ << " OK: createBus Adding CCanAccess to the map for: " << name;
84  return tcca;
85  } else {
86  LOG(Log::ERR, lh ) << __FUNCTION__ << " createBus Problem opening canBus for: " << name;
87  throw std::runtime_error("CanLibLoader::openCanBus: createBus Problem when opening canBus. stop." );
88  }
89  return 0;
90  }
91 }