Loading...
Searching...
No Matches
contextbuilder.hpp
/*
* Copyright (c) 2019 Analog Devices Inc.
*
* This file is part of libm2k
* (see http://www.github.com/analogdevicesinc/libm2k).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef DEVICEBUILDER_HPP
#define DEVICEBUILDER_HPP
#include <vector>
#include <string>
#include <libm2k/m2kglobal.hpp>
#include <libm2k/context.hpp>
#include <libm2k/enums.hpp>
#include <unordered_set>
#include <map>
enum ContextTypes {
CtxFMCOMMS,
CtxM2K,
Other
};
namespace libm2k {
namespace context {
class LIBM2K_API ContextBuilder {
static std::vector<Context*> s_connectedDevices;
public:
explicit ContextBuilder();
~ContextBuilder();
static std::vector<struct libm2k::CONTEXT_INFO*> getContextsInfo();
static std::vector<std::string> getAllContexts();
static Context* contextOpen(const char*);
static Context* contextOpen(struct iio_context*, const char*);
static Context* contextOpen();
static M2k* m2kOpen(const char*);
static M2k* m2kOpen(struct iio_context*, const char*);
static M2k* m2kOpen();
static void contextClose(Context*, bool deinit = true);
static void contextCloseAll();
static std::string getVersion();
static void enableLogging(bool enable);
private:
static std::map<ContextTypes, std::vector<std::string>> m_dev_map;
static std::map<ContextTypes, std::string> m_dev_name_map;
// std::shared_ptr<M2KImpl> m_pimpl;
static ContextTypes identifyContext(iio_context *ctx);
static Context* buildContext(ContextTypes type,
std::string uri,
struct iio_context *ctx,
bool sync,
bool ownsContext = false);
static bool m_disable_logging;
static std::map<std::string, int> reference_count;
static void incrementReferenceCount(std::string uri);
static void decrementReferenceCount(std::string uri);
static bool checkLastReference(std::string uri);
static Context* searchInConnectedDevices(std::string uri);
};
LIBM2K_API Context* contextOpen();
LIBM2K_API Context* contextOpen(const char* uri);
LIBM2K_API Context* contextOpen(struct iio_context* ctx, const char* uri);
LIBM2K_API M2k* m2kOpen(const char* uri);
LIBM2K_API M2k* m2kOpen(struct iio_context* ctx, const char* uri);
LIBM2K_API M2k* m2kOpen();
LIBM2K_API std::vector<struct libm2k::CONTEXT_INFO*> getContextsInfo();
LIBM2K_API std::vector<std::string> getAllContexts();
LIBM2K_API void contextClose(Context* ctx, bool deinit = true);
LIBM2K_API void contextCloseAll();
LIBM2K_API std::string getVersion();
LIBM2K_API void enableLogging(bool enable);
}
}
#endif //M2K_H
libm2k::context::Context
Controls the IIO context.
Definition context.hpp:52
libm2k::context::M2k
Controls the ADALM2000.
Definition m2k.hpp:55
enums.hpp
Generic M2K enumerations.
libm2k::context::getAllContexts
LIBM2K_API std::vector< std::string > getAllContexts()
List all available contexts.
libm2k::context::enableLogging
LIBM2K_API void enableLogging(bool enable)
Enable/disable the logging system.
libm2k::context::m2kOpen
LIBM2K_API M2k * m2kOpen()
Open an ADALM2000.
libm2k::context::contextClose
LIBM2K_API void contextClose(Context *ctx, bool deinit=true)
Destroy the given context.
libm2k::context::getContextsInfo
LIBM2K_API std::vector< struct libm2k::CONTEXT_INFO * > getContextsInfo()
List the information about all available contexts.
libm2k::context::m2kOpen
LIBM2K_API M2k * m2kOpen(const char *uri)
Open an ADALM2000 based on a given uri.
libm2k::context::contextCloseAll
LIBM2K_API void contextCloseAll()
Close all the devices.
libm2k::context::getVersion
LIBM2K_API std::string getVersion()
Get library version.