blob: e777f4132377cb89d64683a3f12c8382c7321feb [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
Alex Perrycb7da4b2019-08-28 19:35:56 -070024// Sorts and merges entries in a config.
25FlatbufferDetachedBuffer<Configuration> MergeConfiguration(
26 const Flatbuffer<Configuration> &config);
27
28// Adds schema definitions to a sorted and merged config from the provided
29// schema list.
30FlatbufferDetachedBuffer<Configuration> MergeConfiguration(
31 const Flatbuffer<Configuration> &config,
32 const std::vector<aos::FlatbufferString<reflection::Schema>> &schemas);
33
Austin Schuh40485ed2019-10-26 21:51:44 -070034// Returns the resolved location for a name, type, and application name. Returns
35// nullptr if none is found.
Austin Schuhcb108412019-10-13 16:09:54 -070036//
37// If the application name is empty, it is ignored. Maps are processed in
38// reverse order, and application specific first.
Austin Schuh40485ed2019-10-26 21:51:44 -070039const Channel *GetChannel(const Configuration *config,
40 const absl::string_view name,
41 const absl::string_view type,
42 const absl::string_view application_name);
43inline const Channel *GetChannel(const Flatbuffer<Configuration> &config,
44 const absl::string_view name,
45 const absl::string_view type,
46 const absl::string_view application_name) {
47 return GetChannel(&config.message(), name, type, application_name);
48}
Austin Schuhcb108412019-10-13 16:09:54 -070049
Alex Perrycb7da4b2019-08-28 19:35:56 -070050// TODO(austin): GetSchema<T>(const Flatbuffer<Configuration> &config);
51
Brian Silverman66f079a2013-08-26 16:24:30 -070052// Returns "our" IP address.
53const in_addr &GetOwnIPAddress();
54
55// Returns the "root directory" for this run. Under linux, this is the
56// directory where the executable is located (from /proc/self/exe)
57// The return value will always be to a static string, so no freeing is
58// necessary.
59const char *GetRootDirectory();
60// Returns the directory where logs get written. Relative to GetRootDirectory().
61// The return value will always be to a static string, so no freeing is
62// necessary.
63const char *GetLoggingDirectory();
64
65} // namespace configuration
Alex Perrycb7da4b2019-08-28 19:35:56 -070066
67// Compare and equality operators for Channel. Note: these only check the name
68// and type for equality.
69bool operator<(const FlatbufferDetachedBuffer<Channel> &lhs,
70 const FlatbufferDetachedBuffer<Channel> &rhs);
71bool operator==(const FlatbufferDetachedBuffer<Channel> &lhs,
72 const FlatbufferDetachedBuffer<Channel> &rhs);
Brian Silverman66f079a2013-08-26 16:24:30 -070073} // namespace aos
74
John Park398c74a2018-10-20 21:17:39 -070075#endif // AOS_CONFIGURATION_H_