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
52
53
54
55
56
57
58
59
60
/**
@file ConnectionManager.h
@author Lime Microsystems (www.limemicro.com)
@brief Class for managing connection to devices
*/
#ifndef LMS_CONNECTION_MANAGER_H
#define LMS_CONNECTION_MANAGER_H
#include "IConnection.h"
#include <map>
class ConnectionManager
{
public:
struct DeviceInfo
{
std::string name;
IConnection::eConnectionType port;
int portIndex;
};
ConnectionManager(const IConnection::eConnectionType port_type);
~ConnectionManager();
bool IsOpen();
bool Open();
int Open(unsigned i);
void Close();
int RefreshDeviceList();
int GetOpenedIndex();
std::vector<std::string> GetDeviceList(){return mDeviceList;};
int Write(const unsigned char *buffer, int length, int timeout_ms = 0);
int Read(unsigned char *buffer, int length, int timeout_ms = 0);
int WriteStream(const char *buffer, int length);
int ReadStream(char *buffer, int length, unsigned int timeout_ms);
int BeginDataReading(char *buffer, long length);
int WaitForReading(int contextHandle, unsigned int timeout_ms);
int FinishDataReading(char *buffer, long &length, int contextHandle);
void AbortReading();
int BeginDataSending(const char *buffer, long length);
int WaitForSending(int contextHandle, unsigned int timeout_ms);
int FinishDataSending(const char *buffer, long &length, int contextHandle);
void AbortSending();
protected:
bool mLogData;
/// Port used for communication.
IConnection *activeControlPort;
std::vector<DeviceInfo> mDevices;
std::vector<std::string> mDeviceList;
int mOpenedDevice;
std::map<IConnection::eConnectionType, IConnection*> m_connections;
};
#endif // LMS_CONNECTION_MANAGER_H