1 /*
2  * Copyright (C) 2018 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 #pragma once
17 
18 #include <string>
19 
20 namespace cuttlefish {
21 
22 // Returns the instance number as obtained from the
23 // *kCuttlefishInstanceEnvVarName environment variable or the username.
24 int GetInstance();
25 
26 // Returns default Vsock CID, which is
27 // GetInstance() + 2
28 int GetDefaultVsockCid();
29 
30 // Calculates vsock server port number
31 // return base + (vsock_guest_cid - 3)
32 int GetVsockServerPort(const int base,
33                        const int vsock_guest_cid);
34 
35 // Returns a path where the launcher puts a link to the config file which makes
36 // it easily discoverable regardless of what vm manager is in use
37 std::string GetGlobalConfigFileLink();
38 
39 // These functions modify a given base value to make it different across
40 // different instances by appending the instance id in case of strings or adding
41 // it in case of integers.
42 std::string ForCurrentInstance(const char* prefix);
43 int ForCurrentInstance(int base);
44 
45 int InstanceFromString(std::string instance_str);
46 
47 // Returns a random serial number appended to a given prefix.
48 std::string RandomSerialNumber(const std::string& prefix);
49 
50 std::string DefaultHostArtifactsPath(const std::string& file);
51 std::string DefaultQemuBinaryDir();
52 std::string HostBinaryPath(const std::string& file);
53 std::string HostUsrSharePath(const std::string& file);
54 std::string HostQemuBiosPath();
55 std::string DefaultGuestImagePath(const std::string& file);
56 std::string DefaultEnvironmentPath(const char* environment_key,
57                                    const char* default_value,
58                                    const char* path);
59 
60 // Whether the host supports qemu
61 bool HostSupportsQemuCli();
62 
63 // Whether to use our local QEMU prebuilt
64 bool UseQemuPrebuilt();
65 }
66