From 6d20a0665d8f9030a0dd8094899ed9232460ef0e Mon Sep 17 00:00:00 2001 From: canpadawan Date: Wed, 15 Jun 2016 18:25:58 +0200 Subject: [PATCH] add a factory for the different connection types --- connections/canconfactory.cpp | 15 ++++++++++++++- connections/canconfactory.h | 6 ++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/connections/canconfactory.cpp b/connections/canconfactory.cpp index 54095ab..93b618e 100644 --- a/connections/canconfactory.cpp +++ b/connections/canconfactory.cpp @@ -1,6 +1,19 @@ +#include #include "canconfactory.h" +#include "socketcan.h" +#include "gvretserial.h" -CanConFactory::CanConFactory() +using namespace CANCon; + +CANConnection* CanConFactory::create(type pType, QString pPortName) { + switch(pType) { + case SOCKETCAN: + return new SocketCanConnection(pPortName); + case GVRET_SERIAL: + return new GVRetSerial(pPortName); + default: {} + } + return NULL; } diff --git a/connections/canconfactory.h b/connections/canconfactory.h index a2d8cbc..2b482f5 100644 --- a/connections/canconfactory.h +++ b/connections/canconfactory.h @@ -1,11 +1,13 @@ #ifndef CANCONFACTORY_H #define CANCONFACTORY_H +#include "canconconst.h" +#include "canconnection.h" class CanConFactory { public: - CanConFactory(); + static CANConnection* create(CANCon::type, QString pPortName); }; -#endif // CANCONFACTORY_H \ No newline at end of file +#endif // CANCONFACTORY_H