1 /*
2  * Copyright (c) 2023 David Corbeil
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_LOG_BACKEND_NET_H_
8 #define ZEPHYR_LOG_BACKEND_NET_H_
9 
10 #include <stdbool.h>
11 #include <zephyr/net/net_ip.h>
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /**
18  * @brief Allows user to set a server IP address, provided as string, at runtime
19  *
20  * @details This function allows the user to set an IPv4 or IPv6 address at runtime. It can be
21  *          called either before or after the backend has been initialized. If it gets called when
22  *          the net logger backend context is running, it'll release it and create another one with
23  *          the new address next time process() gets called.
24  *
25  * @param addr     String that contains the IP address.
26  *
27  * @return True if parsing could be done, false otherwise.
28  */
29 bool log_backend_net_set_addr(const char *addr);
30 
31 /**
32  * @brief Allows user to set a server IP address, provided as sockaddr structure, at runtime
33  *
34  * @details This function allows the user to set an IPv4 or IPv6 address at runtime. It can be
35  *          called either before or after the backend has been initialized. If it gets called when
36  *          the net logger backend context is running, it'll release it and create another one with
37  *          the new address next time process() gets called.
38  *
39  * @param addr     Pointer to the sockaddr structure that contains the IP address.
40  *
41  * @return True if address could be set, false otherwise.
42  */
43 bool log_backend_net_set_ip(const struct sockaddr *addr);
44 
45 /**
46  * @brief update the hostname
47  *
48  * @details This function allows to update the hostname displayed by the logging backend. It will be
49  *          called by the network stack if the hostname is set with net_hostname_set().
50  *
51  * @param hostname new hostname as char array.
52  * @param len Length of the hostname array.
53  */
54 #if defined(CONFIG_NET_HOSTNAME_ENABLE)
55 void log_backend_net_hostname_set(char *hostname, size_t len);
56 #else
log_backend_net_hostname_set(const char * hostname,size_t len)57 static inline void log_backend_net_hostname_set(const char *hostname, size_t len)
58 {
59 	ARG_UNUSED(hostname);
60 	ARG_UNUSED(len);
61 }
62 #endif
63 
64 /**
65  * @brief Get the net logger backend
66  *
67  * @details This function returns the net logger backend.
68  *
69  * @return Pointer to the net logger backend.
70  */
71 const struct log_backend *log_backend_net_get(void);
72 
73 /**
74  * @brief Start the net logger backend
75  *
76  * @details This function starts the net logger backend.
77  */
78 void log_backend_net_start(void);
79 
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif /* ZEPHYR_LOG_BACKEND_NET_H_ */
85