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 // This function modifies 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 
44 int InstanceFromString(std::string instance_str);
45 
46 // Returns a random serial number appended to a given prefix.
47 std::string RandomSerialNumber(const std::string& prefix);
48 
49 std::string DefaultHostArtifactsPath(const std::string& file);
50 std::string DefaultQemuBinaryDir();
51 std::string HostBinaryPath(const std::string& file);
52 std::string HostUsrSharePath(const std::string& file);
53 std::string HostQemuBiosPath();
54 std::string DefaultGuestImagePath(const std::string& file);
55 std::string DefaultEnvironmentPath(const char* environment_key,
56                                    const char* default_value,
57                                    const char* path);
58 
59 // Whether the host supports qemu
60 bool HostSupportsQemuCli();
61 
62 // Whether to use our local QEMU prebuilt
63 bool UseQemuPrebuilt();
64 }
65