-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiinterface.h
More file actions
51 lines (38 loc) · 1.3 KB
/
iinterface.h
File metadata and controls
51 lines (38 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//This is an open source non-commercial project. Dear PVS-Studio, please check it.
#ifndef ABSTRACT_INTERFACE_H
#define ABSTRACT_INTERFACE_H
#include "iparams.h"
#include <memory>
#if __cplusplus==201103L
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
template<typename T>
std::unique_ptr<T> make_unique()
{
return std::unique_ptr<T>(new T());
}
#endif
class IInterface;
using TypeInterface = std::shared_ptr<IInterface>;
//! Интерфейсный класс унифицированной библиотеки канальных частей
class IInterface
{
public:
IInterface(TypeParams p): params(p) {}
virtual ~IInterface() = default;
//! Получить название интерфейса (например: RS, Ethernet и т.д.)
virtual const std::string name() = 0;
virtual const std::string getDevName() { return params->getDevPath(); }
virtual bool open() = 0;
virtual bool close() = 0;
virtual int read(char *data, int size, int timeout) = 0;
virtual int write(const char *data, int size) = 0;
virtual bool bind() { return true; }
private:
//! All inferfaces have params refference
TypeParams params;
};
#endif // ABSTRACT_INTERFACE_H