1 | /* $Id: VBoxNetBaseService.h 76576 2019-01-01 06:05:25Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxNetUDP - IntNet Client Library.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef VBOX_INCLUDED_SRC_NetLib_VBoxNetBaseService_h
|
---|
19 | #define VBOX_INCLUDED_SRC_NetLib_VBoxNetBaseService_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include <iprt/critsect.h>
|
---|
25 |
|
---|
26 |
|
---|
27 | class VBoxNetHlpUDPService
|
---|
28 | {
|
---|
29 | public:
|
---|
30 | virtual int hlpUDPBroadcast(unsigned uSrcPort, unsigned uDstPort,
|
---|
31 | void const *pvData, size_t cbData) const = 0;
|
---|
32 | };
|
---|
33 |
|
---|
34 |
|
---|
35 | class VBoxNetLockee
|
---|
36 | {
|
---|
37 | public:
|
---|
38 | virtual int syncEnter() = 0;
|
---|
39 | virtual int syncLeave() = 0;
|
---|
40 | };
|
---|
41 |
|
---|
42 |
|
---|
43 | class VBoxNetALock
|
---|
44 | {
|
---|
45 | public:
|
---|
46 | VBoxNetALock(VBoxNetLockee *a_lck):m_lck(a_lck)
|
---|
47 | {
|
---|
48 | if (m_lck)
|
---|
49 | m_lck->syncEnter();
|
---|
50 | }
|
---|
51 |
|
---|
52 | ~VBoxNetALock()
|
---|
53 | {
|
---|
54 | if (m_lck)
|
---|
55 | m_lck->syncLeave();
|
---|
56 | }
|
---|
57 |
|
---|
58 | private:
|
---|
59 | VBoxNetLockee *m_lck;
|
---|
60 | };
|
---|
61 |
|
---|
62 | # ifndef BASE_SERVICES_ONLY
|
---|
63 | class VBoxNetBaseService: public VBoxNetHlpUDPService, public VBoxNetLockee
|
---|
64 | {
|
---|
65 | public:
|
---|
66 | VBoxNetBaseService(const std::string& aName, const std::string& aNetworkName);
|
---|
67 | virtual ~VBoxNetBaseService();
|
---|
68 | int parseArgs(int argc, char **argv);
|
---|
69 | int tryGoOnline(void);
|
---|
70 | void shutdown(void);
|
---|
71 | int syncEnter();
|
---|
72 | int syncLeave();
|
---|
73 | int waitForIntNetEvent(int cMillis);
|
---|
74 | int abortWait();
|
---|
75 | int sendBufferOnWire(PCINTNETSEG paSegs, size_t cSegs, size_t cbBuffer);
|
---|
76 | void flushWire();
|
---|
77 |
|
---|
78 | virtual int hlpUDPBroadcast(unsigned uSrcPort, unsigned uDstPort,
|
---|
79 | void const *pvData, size_t cbData) const;
|
---|
80 | virtual void usage(void) = 0;
|
---|
81 | virtual int parseOpt(int rc, const RTGETOPTUNION& getOptVal) = 0;
|
---|
82 | virtual int processFrame(void *, size_t) = 0;
|
---|
83 | virtual int processGSO(PCPDMNETWORKGSO, size_t) = 0;
|
---|
84 | virtual int processUDP(void *, size_t) = 0;
|
---|
85 |
|
---|
86 |
|
---|
87 | virtual int init(void);
|
---|
88 | virtual int run(void);
|
---|
89 | virtual bool isMainNeeded() const;
|
---|
90 |
|
---|
91 | protected:
|
---|
92 | const std::string getServiceName() const;
|
---|
93 | void setServiceName(const std::string&);
|
---|
94 |
|
---|
95 | const std::string getNetworkName() const;
|
---|
96 | void setNetworkName(const std::string&);
|
---|
97 |
|
---|
98 | const RTMAC getMacAddress() const;
|
---|
99 | void setMacAddress(const RTMAC&);
|
---|
100 |
|
---|
101 | const RTNETADDRIPV4 getIpv4Address() const;
|
---|
102 | void setIpv4Address(const RTNETADDRIPV4&);
|
---|
103 |
|
---|
104 | const RTNETADDRIPV4 getIpv4Netmask() const;
|
---|
105 | void setIpv4Netmask(const RTNETADDRIPV4&);
|
---|
106 |
|
---|
107 | uint32_t getSendBufSize() const;
|
---|
108 | void setSendBufSize(uint32_t);
|
---|
109 |
|
---|
110 | uint32_t getRecvBufSize() const;
|
---|
111 | void setRecvBufSize(uint32_t);
|
---|
112 |
|
---|
113 | int32_t getVerbosityLevel() const;
|
---|
114 | void setVerbosityLevel(int32_t);
|
---|
115 |
|
---|
116 | void addCommandLineOption(const PRTGETOPTDEF);
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * Print debug message depending on the m_cVerbosity level.
|
---|
120 | *
|
---|
121 | * @param iMinLevel The minimum m_cVerbosity level for this message.
|
---|
122 | * @param fMsg Whether to dump parts for the current DHCP message.
|
---|
123 | * @param pszFmt The message format string.
|
---|
124 | * @param ... Optional arguments.
|
---|
125 | */
|
---|
126 | void debugPrint(int32_t iMinLevel, bool fMsg, const char *pszFmt, ...) const;
|
---|
127 | virtual void debugPrintV(int32_t iMinLevel, bool fMsg, const char *pszFmt, va_list va) const;
|
---|
128 |
|
---|
129 | private:
|
---|
130 | void doReceiveLoop();
|
---|
131 |
|
---|
132 | /** starts receiving thread and enter event polling loop. */
|
---|
133 | int startReceiveThreadAndEnterEventLoop();
|
---|
134 |
|
---|
135 | protected:
|
---|
136 | /* VirtualBox instance */
|
---|
137 | ComPtr<IVirtualBox> virtualbox;
|
---|
138 | ComPtr<IVirtualBoxClient> virtualboxClient;
|
---|
139 |
|
---|
140 | private:
|
---|
141 | struct Data;
|
---|
142 | Data *m;
|
---|
143 |
|
---|
144 | private:
|
---|
145 | PRTGETOPTDEF getOptionsPtr();
|
---|
146 | };
|
---|
147 | # endif
|
---|
148 | #endif /* !VBOX_INCLUDED_SRC_NetLib_VBoxNetBaseService_h */
|
---|