blob: 3cee8e73704cc380a1012df93f73bd4ba53d43f9 [file] [log] [blame]
John Park398c74a2018-10-20 21:17:39 -07001#ifndef AOS_CONFIGURATION_H_
2#define AOS_CONFIGURATION_H_
Brian Silverman66f079a2013-08-26 16:24:30 -07003
4#include <stdint.h>
5#include <sys/socket.h>
6#include <netinet/in.h>
7#include <arpa/inet.h>
8
Austin Schuhcb108412019-10-13 16:09:54 -07009#include "absl/strings/string_view.h"
10#include "aos/configuration_generated.h"
11#include "aos/flatbuffers.h"
12
Brian Silverman66f079a2013-08-26 16:24:30 -070013namespace aos {
14
15// Holds global configuration data. All of the functions are safe to call
16// from wherever.
17namespace configuration {
18
Austin Schuhcb108412019-10-13 16:09:54 -070019// Reads a json configuration. This includes all imports and merges. Note:
20// duplicate imports will result in a CHECK.
Austin Schuh40485ed2019-10-26 21:51:44 -070021FlatbufferDetachedBuffer<Configuration> ReadConfig(
22 const absl::string_view path);
Austin Schuhcb108412019-10-13 16:09:54 -070023
Austin Schuh40485ed2019-10-26 21:51:44 -070024// Returns the resolved location for a name, type, and application name. Returns
25// nullptr if none is found.
Austin Schuhcb108412019-10-13 16:09:54 -070026//
27// If the application name is empty, it is ignored. Maps are processed in
28// reverse order, and application specific first.
Austin Schuh40485ed2019-10-26 21:51:44 -070029const Channel *GetChannel(const Configuration *config,
30 const absl::string_view name,
31 const absl::string_view type,
32 const absl::string_view application_name);
33inline const Channel *GetChannel(const Flatbuffer<Configuration> &config,
34 const absl::string_view name,
35 const absl::string_view type,
36 const absl::string_view application_name) {
37 return GetChannel(&config.message(), name, type, application_name);
38}
Austin Schuhcb108412019-10-13 16:09:54 -070039
Brian Silverman66f079a2013-08-26 16:24:30 -070040// Returns "our" IP address.
41const in_addr &GetOwnIPAddress();
42
43// Returns the "root directory" for this run. Under linux, this is the
44// directory where the executable is located (from /proc/self/exe)
45// The return value will always be to a static string, so no freeing is
46// necessary.
47const char *GetRootDirectory();
48// Returns the directory where logs get written. Relative to GetRootDirectory().
49// The return value will always be to a static string, so no freeing is
50// necessary.
51const char *GetLoggingDirectory();
52
53} // namespace configuration
54} // namespace aos
55
John Park398c74a2018-10-20 21:17:39 -070056#endif // AOS_CONFIGURATION_H_