Friendly LWM2M client
WppClient.h
Go to the documentation of this file.
1 /*
2  * WppManager.h
3  *
4  * Created on: 20 Jul 2023
5  * Author: valentin
6  */
7 
8 #ifndef WPP_CLIENT_H_
9 #define WPP_CLIENT_H_
10 
11 #include <string>
12 #include <functional>
13 
14 #include "liblwm2m.h"
15 #include "WppTypes.h"
16 #include "WppRegistry.h"
17 #include "WppConnection.h"
18 #include "WppGuard.h"
19 
20 #define WPP_CLIENT_MAX_SLEEP_TIME_S 60
21 
22 namespace wpp {
23 
37 class WppClient {
38 public:
43  struct ClientInfo {
44  std::string endpointName;
45  std::string msisdn;
46  std::string altPath;
47  };
48 
49  using WppErrHandler = std::function<void(WppClient &client, int errCode)>;
50 
51 private:
56  WppClient(WppConnection &connection, WppErrHandler errHandler = NULL);
57 
61  WppClient(const WppClient&) = delete;
62  WppClient(WppClient&&) = delete;
63  WppClient& operator=(const WppClient&) = delete;
64  WppClient& operator=(WppClient&&) = delete;
65 
66 public:
67  ~WppClient();
68 
69  /* ------------- WppClient management ------------- */
70 
77  static bool create(const ClientInfo &info, WppConnection &connection, WppErrHandler errHandler = NULL);
78 
82  static void remove();
83 
88  static bool isCreated();
89 
94  static WppClient* takeOwnership();
95 
101 
105  void giveOwnership();
106 
107  /* ------------- WppClient components ------------- */
108 
114 
119  WppRegistry & registry();
120 
121  /* ------------- Wakaama core state processing ------------- */
122 
127  lwm2m_client_state_t getState();
128 
133  lwm2m_context_t & getContext();
134 
141  time_t loop();
142 
143  /* ------------- WppClient server operations ------------- */
144 
148  void deregister();
149 
150  #if defined(LWM2M_SUPPORT_SENML_JSON) && RES_1_23
159  bool send(const DataLink &link);
160  #endif // LWM2M_SUPPORT_SENML_JSON && RES_1_23
161 
162 private:
163  /* ------------- Wakaama client initialisation ------------- */
164 
169  bool lwm2mContextOpen();
170 
174  void lwm2mContextClose();
175 
183  bool lwm2mConfigure(const std::string &endpointName, const std::string &msisdn, const std::string &altPath);
184 
185 private:
186  static WppGuard _clientGuard;
187  static WppClient *_client;
188 
189  WppConnection &_connection;
190  WppRegistry *_registry;
191  WppErrHandler _errHandler;
192  lwm2m_context_t *_lwm2m_context;
193 };
194 
195 } /* namespace wpp */
196 #endif /* WPP_CLIENT_H_ */
Represents a client interface for Wpp library.
Definition: WppClient.h:37
static WppClient * takeOwnership()
Takes ownership of the WppClient.
Definition: WppClient.cpp:66
lwm2m_context_t & getContext()
Gets the LwM2M context associated with the WppClient.
Definition: WppClient.cpp:102
void giveOwnership()
Gives up ownership of the WppClient.
Definition: WppClient.cpp:81
static void remove()
Removes the WppClient.
Definition: WppClient.cpp:54
time_t loop()
Processes the state of the Wakaama core. This function performs the necessary work by the Wakaama cor...
Definition: WppClient.cpp:106
WppConnection & connection()
Gets the WppConnection associated with the WppClient.
Definition: WppClient.cpp:89
lwm2m_client_state_t getState()
Gets the state of the Wakaama client.
Definition: WppClient.cpp:98
static bool isCreated()
Checks if the WppClient is created.
Definition: WppClient.cpp:62
static WppClient * takeOwnershipBlocking()
Takes ownership of the WppClient, blocking until it becomes available.
Definition: WppClient.cpp:73
static bool create(const ClientInfo &info, WppConnection &connection, WppErrHandler errHandler=NULL)
Creates a WppClient with the specified client information, connection, and maximum sleep time.
Definition: WppClient.cpp:39
std::function< void(WppClient &client, int errCode)> WppErrHandler
Definition: WppClient.h:49
void deregister()
Deregisters the client from the servers.
Definition: WppClient.cpp:139
WppRegistry & registry()
Gets the WppRegistry associated with the WppClient.
Definition: WppClient.cpp:93
The WppGuard class provides a linker callback class that must be implemented by the user.
Definition: WppGuard.h:14
The WppRegistry class represents a registry for managing LWM2M objects.
Definition: WppRegistry.h:53
The WppConnection class represents a connection interface for the Wpp library.
Definition: WppClient.cpp:14
Represents the information required to create a WppClient.
Definition: WppClient.h:43
std::string endpointName
Definition: WppClient.h:44