blob: b30a2b30b1df531dd56e8808b82cf8eaa4d71248 [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.
21Flatbuffer<Configuration> ReadConfig(const absl::string_view path);
22
23// Returns the resolved location for a name, type, and application name.
24//
25// If the application name is empty, it is ignored. Maps are processed in
26// reverse order, and application specific first.
27const Location *GetLocation(const Flatbuffer<Configuration> &config,
28 const absl::string_view name,
29 const absl::string_view type,
30 const absl::string_view application_name);
31
Brian Silverman66f079a2013-08-26 16:24:30 -070032// Returns "our" IP address.
33const in_addr &GetOwnIPAddress();
34
35// Returns the "root directory" for this run. Under linux, this is the
36// directory where the executable is located (from /proc/self/exe)
37// The return value will always be to a static string, so no freeing is
38// necessary.
39const char *GetRootDirectory();
40// Returns the directory where logs get written. Relative to GetRootDirectory().
41// The return value will always be to a static string, so no freeing is
42// necessary.
43const char *GetLoggingDirectory();
44
45} // namespace configuration
46} // namespace aos
47
John Park398c74a2018-10-20 21:17:39 -070048#endif // AOS_CONFIGURATION_H_