libm2k
Loading...
Searching...
No Matches
contextbuilder.hpp
1/*
2 * Copyright (c) 2019 Analog Devices Inc.
3 *
4 * This file is part of libm2k
5 * (see http://www.github.com/analogdevicesinc/libm2k).
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 2.1 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef DEVICEBUILDER_HPP
23#define DEVICEBUILDER_HPP
24
25#include <vector>
26#include <string>
27#include <libm2k/m2kglobal.hpp>
28#include <libm2k/context.hpp>
29#include <libm2k/enums.hpp>
30#include <unordered_set>
31#include <map>
32
33enum ContextTypes {
34 CtxFMCOMMS,
35 CtxM2K,
36 Other
37};
38
39namespace libm2k {
40
41
42namespace context {
43
47class LIBM2K_API ContextBuilder {
48 static std::vector<Context*> s_connectedDevices;
49public:
53 explicit ContextBuilder();
57 ~ContextBuilder();
61 static std::vector<struct libm2k::CONTEXT_INFO*> getContextsInfo();
65 static std::vector<std::string> getAllContexts();
69 static Context* contextOpen(const char*);
73 static Context* contextOpen(struct iio_context*, const char*);
77 static Context* contextOpen();
81 static M2k* m2kOpen(const char*);
85 static M2k* m2kOpen(struct iio_context*, const char*);
89 static M2k* m2kOpen();
93 static void contextClose(Context*, bool deinit = true);
94
95 static void contextCloseAll();
96
97 static std::string getVersion();
98
102 static void enableLogging(bool enable);
103
104private:
105 static std::map<ContextTypes, std::vector<std::string>> m_dev_map;
106 static std::map<ContextTypes, std::string> m_dev_name_map;
107 // std::shared_ptr<M2KImpl> m_pimpl;
108 static ContextTypes identifyContext(iio_context *ctx);
109 static Context* buildContext(ContextTypes type,
110 std::string uri,
111 struct iio_context *ctx,
112 bool sync,
113 bool ownsContext = false);
114 static bool m_disable_logging;
115
116 static std::map<std::string, int> reference_count;
117 static void incrementReferenceCount(std::string uri);
118 static void decrementReferenceCount(std::string uri);
119 static bool checkLastReference(std::string uri);
120 static Context* searchInConnectedDevices(std::string uri);
121};
122
135LIBM2K_API Context* contextOpen();
136
137
141LIBM2K_API Context* contextOpen(const char* uri);
142
143
147LIBM2K_API Context* contextOpen(struct iio_context* ctx, const char* uri);
148
149
158LIBM2K_API M2k* m2kOpen(const char* uri);
159
160
170LIBM2K_API M2k* m2kOpen(struct iio_context* ctx, const char* uri);
171
172
179LIBM2K_API M2k* m2kOpen();
180
181
186LIBM2K_API std::vector<struct libm2k::CONTEXT_INFO*> getContextsInfo();
187
188
193LIBM2K_API std::vector<std::string> getAllContexts();
194
195
201LIBM2K_API void contextClose(Context* ctx, bool deinit = true);
202
203
207LIBM2K_API void contextCloseAll();
208
209
214LIBM2K_API std::string getVersion();
215
216
221LIBM2K_API void enableLogging(bool enable);
222
223
228}
229}
230#endif //M2K_H
Controls the IIO context.
Definition context.hpp:52
Controls the ADALM2000.
Definition m2k.hpp:55
Generic M2K enumerations.
LIBM2K_API std::vector< std::string > getAllContexts()
List all available contexts.
LIBM2K_API void enableLogging(bool enable)
Enable/disable the logging system.
LIBM2K_API M2k * m2kOpen()
Open an ADALM2000.
LIBM2K_API void contextClose(Context *ctx, bool deinit=true)
Destroy the given context.
LIBM2K_API std::vector< struct libm2k::CONTEXT_INFO * > getContextsInfo()
List the information about all available contexts.
LIBM2K_API M2k * m2kOpen(const char *uri)
Open an ADALM2000 based on a given uri.
LIBM2K_API void contextCloseAll()
Close all the devices.
LIBM2K_API std::string getVersion()
Get library version.