Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
DeviceList.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Cascoda Ltd.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef POSIX_APP_CHILICTL_COMMON_DEVICELIST_HPP_
30 #define POSIX_APP_CHILICTL_COMMON_DEVICELIST_HPP_
31 
32 #include <string>
33 #include <vector>
34 
35 #include "common/DeviceInfo.hpp"
36 
37 namespace ca {
38 
40 {
41  friend class DeviceList;
42 
43 public:
48  : mAvailableFilter()
49  , mExtFlashAvailableFilter()
50  , mSerialNoFilter()
51  , mAvailableFilterEnabled()
52  , mExtFlashAvailableFilterEnabled()
53  {
54  }
55 
60  void SetAvailable(bool aTarget)
61  {
62  mAvailableFilter = aTarget;
63  mAvailableFilterEnabled = true;
64  }
65 
70  void SetExtFlashAvailable(bool aTarget)
71  {
72  mExtFlashAvailableFilter = aTarget;
73  mExtFlashAvailableFilterEnabled = true;
74  }
75 
79  void ClearAvailable() { mAvailableFilterEnabled = false; }
80 
86  void AddSerialNo(const char *aSerialNo) { mSerialNoFilter.push_back(aSerialNo); }
87 
92  void SetAppName(const char *aAppName) { mAppNameFilter = aAppName; }
93 
94  void SetMinVersion(const char *aMinVersion) { mMinVersionFilter = aMinVersion; }
95 
101  bool IsFilterPass(const DeviceInfo &aDeviceInfo) const;
102 
103 private:
104  bool mAvailableFilter;
105  bool mExtFlashAvailableFilter;
106  std::vector<std::string> mSerialNoFilter;
107  std::string mAppNameFilter;
108  std::string mMinVersionFilter;
109 
110  bool mAvailableFilterEnabled;
111  bool mExtFlashAvailableFilterEnabled;
112  bool mEnumerateUartDevicesEnabled;
113 
114  static const DeviceListFilter sEmpty;
115 };
116 
121 {
122 public:
127  : mDevices()
128  {
129  }
130 
134  void Refresh(const DeviceListFilter &aFilter = DeviceListFilter::sEmpty, bool enumerate_uart = false);
135 
140  const std::vector<DeviceInfo> &Get() { return mDevices; }
141 
142 private:
143  std::vector<DeviceInfo> mDevices;
144 };
145 
146 } /* namespace ca */
147 
148 #endif /* POSIX_APP_CHILICTL_COMMON_DEVICELIST_HPP_ */
C++ wrapper for the C ca_device_info struct, which owns its own memory.
Definition: DeviceInfo.hpp:40
Definition: DeviceList.hpp:40
void SetAppName(const char *aAppName)
Set the app name filter.
Definition: DeviceList.hpp:92
DeviceListFilter()
Default constructor.
Definition: DeviceList.hpp:47
void SetExtFlashAvailable(bool aTarget)
Enable the 'ext-flash-available' filter and set the parameters.
Definition: DeviceList.hpp:70
void SetMinVersion(const char *aMinVersion)
Definition: DeviceList.hpp:94
void ClearAvailable()
Disable the available filter.
Definition: DeviceList.hpp:79
void SetAvailable(bool aTarget)
Enable the 'available' filter and set the parameters.
Definition: DeviceList.hpp:60
bool IsFilterPass(const DeviceInfo &aDeviceInfo) const
Run the filter on the given DeviceInfo.
Definition: DeviceList.cpp:36
void AddSerialNo(const char *aSerialNo)
Add serial number to filter.
Definition: DeviceList.hpp:86
Class to assist in obtaining a list of connected ca821x devices, filtering as required.
Definition: DeviceList.hpp:121
void Refresh(const DeviceListFilter &aFilter=DeviceListFilter::sEmpty, bool enumerate_uart=false)
Refresh the internal list of devices.
Definition: DeviceList.cpp:71
DeviceList()
Default constructor.
Definition: DeviceList.hpp:126
const std::vector< DeviceInfo > & Get()
Get the list of discovered devices as a vector.
Definition: DeviceList.hpp:140
Definition: Args.cpp:34