blob: 8e4bfd6dbe9ef3185f4b134f031ae7e410be9a0b [file] [log] [blame]
Alex Vakulenkob04936f2014-09-19 14:53:58 -07001// Copyright 2014 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BUFFET_UTILS_H_
6#define BUFFET_UTILS_H_
7
8#include <memory>
Alex Vakulenko9e2f8cd2015-04-07 16:28:09 -07009#include <string>
Alex Vakulenkob04936f2014-09-19 14:53:58 -070010
11#include <base/values.h>
12#include <base/files/file_path.h>
13#include <chromeos/errors/error.h>
14
15namespace buffet {
16
Alex Vakulenko07216fe2014-09-19 15:31:09 -070017// Buffet-wide errors.
18// TODO(avakulenko): This should be consolidated into errors::<domain> namespace
19// See crbug.com/417274
Alex Vakulenkob04936f2014-09-19 14:53:58 -070020extern const char kErrorDomainBuffet[];
21extern const char kFileReadError[];
Alex Vakulenko07216fe2014-09-19 15:31:09 -070022extern const char kInvalidCategoryError[];
23extern const char kInvalidPackageError[];
24
25// kDefaultCategory represents a default state property category for standard
26// properties from "base" package which are provided by buffet and not any of
27// the daemons running on the device.
28const char kDefaultCategory[] = "";
Alex Vakulenkob04936f2014-09-19 14:53:58 -070029
30// Helper function to load a JSON file that is expected to be
31// an object/dictionary. In case of error, returns empty unique ptr and fills
32// in error details in |error|.
Vitaly Buka207c1cb2015-05-14 17:06:18 -070033std::unique_ptr<base::DictionaryValue> LoadJsonDict(
34 const base::FilePath& json_file_path,
35 chromeos::ErrorPtr* error);
Alex Vakulenkob04936f2014-09-19 14:53:58 -070036
Alex Vakulenko9e2f8cd2015-04-07 16:28:09 -070037// Helper function to load a JSON dictionary from a string.
Vitaly Buka207c1cb2015-05-14 17:06:18 -070038std::unique_ptr<base::DictionaryValue> LoadJsonDict(
39 const std::string& json_string,
40 chromeos::ErrorPtr* error);
Alex Vakulenko9e2f8cd2015-04-07 16:28:09 -070041
Alex Vakulenkoeedf3be2015-05-13 17:52:02 -070042// Synchronously resolves the |host| and connects a socket to the resolved
43// address/port.
44// Returns the connected socket file descriptor or -1 if failed.
45int ConnectSocket(const std::string& host, uint16_t port);
46
Alex Vakulenkob04936f2014-09-19 14:53:58 -070047} // namespace buffet
48
49#endif // BUFFET_UTILS_H_