John Park | 398c74a | 2018-10-20 21:17:39 -0700 | [diff] [blame] | 1 | #ifndef AOS_CONFIGURATION_H_ |
| 2 | #define AOS_CONFIGURATION_H_ |
Brian Silverman | 66f079a | 2013-08-26 16:24:30 -0700 | [diff] [blame] | 3 | |
| 4 | #include <stdint.h> |
| 5 | #include <sys/socket.h> |
| 6 | #include <netinet/in.h> |
| 7 | #include <arpa/inet.h> |
| 8 | |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame^] | 9 | #include "absl/strings/string_view.h" |
| 10 | #include "aos/configuration_generated.h" |
| 11 | #include "aos/flatbuffers.h" |
| 12 | |
Brian Silverman | 66f079a | 2013-08-26 16:24:30 -0700 | [diff] [blame] | 13 | namespace aos { |
| 14 | |
| 15 | // Holds global configuration data. All of the functions are safe to call |
| 16 | // from wherever. |
| 17 | namespace configuration { |
| 18 | |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame^] | 19 | // Reads a json configuration. This includes all imports and merges. Note: |
| 20 | // duplicate imports will result in a CHECK. |
| 21 | Flatbuffer<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. |
| 27 | const 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 Silverman | 66f079a | 2013-08-26 16:24:30 -0700 | [diff] [blame] | 32 | // Returns "our" IP address. |
| 33 | const 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. |
| 39 | const 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. |
| 43 | const char *GetLoggingDirectory(); |
| 44 | |
| 45 | } // namespace configuration |
| 46 | } // namespace aos |
| 47 | |
John Park | 398c74a | 2018-10-20 21:17:39 -0700 | [diff] [blame] | 48 | #endif // AOS_CONFIGURATION_H_ |