1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef SRC_JSVM_HOST_PORT_H_ 17 #define SRC_JSVM_HOST_PORT_H_ 18 19 #include "jsvm_dfx.h" 20 #include "jsvm_mutex.h" 21 #include "jsvm_util.h" 22 23 namespace jsvm { 24 25 class HostPort { 26 public: hostName(hostName)27 HostPort(const std::string& hostName, int port, int pid = -1) : hostName(hostName), port(port), pid(pid) {} 28 HostPort(const HostPort&) = default; 29 HostPort& operator=(const HostPort&) = default; 30 HostPort(HostPort&&) = default; 31 HostPort& operator=(HostPort&&) = default; 32 SetHost(const std::string & host)33 void SetHost(const std::string& host) 34 { 35 hostName = host; 36 } 37 SetPort(int portParam)38 void SetPort(int portParam) 39 { 40 port = portParam; 41 } 42 GetHost()43 const std::string& GetHost() const 44 { 45 return hostName; 46 } 47 GetPort()48 int GetPort() const 49 { 50 CHECK_GE(port, 0); 51 return port; 52 } 53 GetPid()54 int GetPid() const 55 { 56 return pid; 57 } 58 Update(const HostPort & other)59 void Update(const HostPort& other) 60 { 61 if (!other.hostName.empty()) { 62 hostName = other.hostName; 63 } 64 if (other.port >= 0) { 65 port = other.port; 66 } 67 } 68 69 private: 70 std::string hostName; 71 int port; 72 int pid; 73 }; 74 75 struct InspectPublishUid { 76 bool console; 77 bool http; 78 }; 79 80 } // namespace jsvm 81 82 #endif // SRC_JSVM_HOST_PORT_H_ 83