Android-cuttlefish cvd tool
utils.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
20#include "json/json.h"
21
22#include <optional>
23#include <string>
24
27#include "request.h"
28
29namespace cuttlefish {
30
31constexpr char kDefaultLocation[] =
32 "/var/run/cuttlefish/cuttlefish_allocd.sock";
33
34// Default flags for send and receive.
35static constexpr int kSendFlags = 0;
36static constexpr int kRecvFlags = 0;
37
42bool SendJsonMsg(cuttlefish::SharedFD client_socket, const Json::Value& resp);
43
48std::optional<Json::Value> RecvJsonMsg(cuttlefish::SharedFD client_socket);
49
50// Helper functions mapping between Enum types and std::string
51
52RequestType StrToReqTy(const std::string& req);
53
54std::string ReqTyToStr(RequestType req_ty);
55
56IfaceType StrToIfaceTy(const std::string& iface);
57
58std::string IfaceTyToStr(IfaceType iface);
59
60RequestStatus StrToStatus(const std::string& st);
61
62std::string StatusToStr(RequestStatus st);
63
64} // namespace cuttlefish
Definition: shared_fd.h:129
Definition: alloc_utils.cpp:23
RequestType
Defines operations supported by allocd.
Definition: request.h:34
constexpr char kDefaultLocation[]
Definition: utils.h:31
std::string IfaceTyToStr(IfaceType iface)
Definition: utils.cpp:162
std::optional< Json::Value > RecvJsonMsg(SharedFD client_socket)
Definition: utils.cpp:98
RequestType StrToReqTy(const std::string &req)
Definition: utils.cpp:131
RequestStatus
Definition: request.h:54
std::string ReqTyToStr(RequestType req_ty)
Definition: utils.cpp:114
IfaceType
Defines interface types supported by allocd.
Definition: request.h:44
bool SendJsonMsg(SharedFD client_socket, const Json::Value &resp)
Definition: utils.cpp:81
IfaceType StrToIfaceTy(const std::string &iface)
Definition: utils.cpp:181
static constexpr int kSendFlags
Definition: utils.h:35
RequestStatus StrToStatus(const std::string &st)
Definition: utils.cpp:140
static constexpr int kRecvFlags
Definition: utils.h:36
std::string StatusToStr(RequestStatus st)
Definition: utils.cpp:149