VirtualBox

source: vbox/trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.h

Last change on this file was 106061, checked in by vboxsync, 8 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/* $Id: VBoxNetBaseService.h 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VBoxNetUDP - IntNet Client Library.
4 */
5
6/*
7 * Copyright (C) 2009-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef VBOX_INCLUDED_SRC_NetLib_VBoxNetBaseService_h
29#define VBOX_INCLUDED_SRC_NetLib_VBoxNetBaseService_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34#include <iprt/critsect.h>
35
36
37class VBoxNetHlpUDPService
38{
39public:
40 virtual ~VBoxNetHlpUDPService() { /* Make VC++ 19.2 happy. */ }
41 virtual int hlpUDPBroadcast(unsigned uSrcPort, unsigned uDstPort, void const *pvData, size_t cbData) const = 0;
42};
43
44
45class VBoxNetLockee
46{
47public:
48 virtual ~VBoxNetLockee() { /* Make VC++ 19.2 happy. */ }
49 virtual int syncEnter() = 0;
50 virtual int syncLeave() = 0;
51};
52
53
54class VBoxNetALock
55{
56public:
57 VBoxNetALock(VBoxNetLockee *a_lck) : m_lck(a_lck)
58 {
59 if (m_lck)
60 m_lck->syncEnter();
61 }
62
63 ~VBoxNetALock()
64 {
65 if (m_lck)
66 m_lck->syncLeave();
67 }
68
69private:
70 VBoxNetLockee *m_lck;
71};
72
73# ifndef BASE_SERVICES_ONLY
74class VBoxNetBaseService : public VBoxNetHlpUDPService, public VBoxNetLockee
75{
76public:
77 VBoxNetBaseService(const std::string& aName, const std::string& aNetworkName);
78 virtual ~VBoxNetBaseService();
79 int parseArgs(int argc, char **argv);
80 int tryGoOnline(void);
81 void shutdown(void);
82 int syncEnter();
83 int syncLeave();
84 int waitForIntNetEvent(int cMillis);
85 int abortWait();
86 int sendBufferOnWire(PCINTNETSEG paSegs, size_t cSegs, size_t cbBuffer);
87 void flushWire();
88
89 virtual int hlpUDPBroadcast(unsigned uSrcPort, unsigned uDstPort,
90 void const *pvData, size_t cbData) const;
91 virtual void usage(void) = 0;
92 virtual int parseOpt(int rc, const RTGETOPTUNION& getOptVal) = 0;
93 virtual int processFrame(void *, size_t) = 0;
94 virtual int processGSO(PCPDMNETWORKGSO, size_t) = 0;
95 virtual int processUDP(void *, size_t) = 0;
96
97
98 virtual int init(void);
99 virtual int run(void);
100 virtual bool isMainNeeded() const;
101
102protected:
103 const std::string getServiceName() const;
104 void setServiceName(const std::string&);
105
106 const std::string getNetworkName() const;
107 void setNetworkName(const std::string&);
108
109 const RTMAC getMacAddress() const;
110 void setMacAddress(const RTMAC&);
111
112 const RTNETADDRIPV4 getIpv4Address() const;
113 void setIpv4Address(const RTNETADDRIPV4&);
114
115 const RTNETADDRIPV4 getIpv4Netmask() const;
116 void setIpv4Netmask(const RTNETADDRIPV4&);
117
118 uint32_t getSendBufSize() const;
119 void setSendBufSize(uint32_t);
120
121 uint32_t getRecvBufSize() const;
122 void setRecvBufSize(uint32_t);
123
124 int32_t getVerbosityLevel() const;
125 void setVerbosityLevel(int32_t);
126
127 void addCommandLineOption(PCRTGETOPTDEF);
128
129 /**
130 * Print debug message depending on the m_cVerbosity level.
131 *
132 * @param iMinLevel The minimum m_cVerbosity level for this message.
133 * @param fMsg Whether to dump parts for the current DHCP message.
134 * @param pszFmt The message format string.
135 * @param ... Optional arguments.
136 */
137 void debugPrint(int32_t iMinLevel, bool fMsg, const char *pszFmt, ...) const;
138 virtual void debugPrintV(int32_t iMinLevel, bool fMsg, const char *pszFmt, va_list va) const;
139
140 private:
141 void doReceiveLoop();
142
143 /** starts receiving thread and enter event polling loop. */
144 int startReceiveThreadAndEnterEventLoop();
145
146 protected:
147 /* VirtualBox instance */
148 ComPtr<IVirtualBox> virtualbox;
149 ComPtr<IVirtualBoxClient> virtualboxClient;
150
151 private:
152 struct Data;
153 Data *m;
154
155 private:
156 PRTGETOPTDEF getOptionsPtr();
157};
158# endif
159#endif /* !VBOX_INCLUDED_SRC_NetLib_VBoxNetBaseService_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette