1 | /* $Id: NetworkServiceRunner.h 48107 2013-08-27 22:15:13Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Main - interface for VBox DHCP server.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2010 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 | #include <iprt/err.h>
|
---|
19 | #include <iprt/types.h>
|
---|
20 | #include <iprt/string.h>
|
---|
21 | #include <iprt/mem.h>
|
---|
22 | #include <VBox/com/string.h>
|
---|
23 |
|
---|
24 | typedef enum
|
---|
25 | {
|
---|
26 | NETCFG_NAME = 1,
|
---|
27 | NETCFG_NETNAME,
|
---|
28 | NETCFG_TRUNKTYPE,
|
---|
29 | NETCFG_TRUNKNAME,
|
---|
30 | NETCFG_MACADDRESS,
|
---|
31 | NETCFG_IPADDRESS,
|
---|
32 | NETCFG_NETMASK,
|
---|
33 | NETCFG_VERBOSE,
|
---|
34 | NETCFG_NOTOPT_MAXVAL
|
---|
35 | } NETCFG;
|
---|
36 |
|
---|
37 | #define TRUNKTYPE_WHATEVER "whatever"
|
---|
38 | #define TRUNKTYPE_NETFLT "netflt"
|
---|
39 | #define TRUNKTYPE_NETADP "netadp"
|
---|
40 | #define TRUNKTYPE_SRVNAT "srvnat"
|
---|
41 |
|
---|
42 | class NetworkServiceRunner
|
---|
43 | {
|
---|
44 | public:
|
---|
45 | NetworkServiceRunner(const char *aProcName)
|
---|
46 | : mProcName(aProcName)
|
---|
47 | , mProcess(NIL_RTPROCESS)
|
---|
48 | {
|
---|
49 | RT_ZERO(mOptionEnabled);
|
---|
50 | };
|
---|
51 | ~NetworkServiceRunner()
|
---|
52 | {
|
---|
53 | stop(); /* don't leave abandoned servers */
|
---|
54 | }
|
---|
55 |
|
---|
56 | int setOption(NETCFG opt, const char *val, bool enabled)
|
---|
57 | {
|
---|
58 | if (opt == 0 || opt >= NETCFG_NOTOPT_MAXVAL)
|
---|
59 | return VERR_INVALID_PARAMETER;
|
---|
60 | if (isRunning())
|
---|
61 | return VERR_INVALID_STATE;
|
---|
62 |
|
---|
63 | mOptions[opt] = val;
|
---|
64 | mOptionEnabled[opt] = enabled;
|
---|
65 | return VINF_SUCCESS;
|
---|
66 | }
|
---|
67 |
|
---|
68 | int setOption(NETCFG opt, const com::Utf8Str &val, bool enabled)
|
---|
69 | {
|
---|
70 | return setOption(opt, val.c_str(), enabled);
|
---|
71 | }
|
---|
72 |
|
---|
73 | int start();
|
---|
74 | int stop();
|
---|
75 | bool isRunning();
|
---|
76 |
|
---|
77 | void detachFromServer();
|
---|
78 | private:
|
---|
79 | com::Utf8Str mOptions[NETCFG_NOTOPT_MAXVAL];
|
---|
80 | bool mOptionEnabled[NETCFG_NOTOPT_MAXVAL];
|
---|
81 | const char *mProcName;
|
---|
82 | RTPROCESS mProcess;
|
---|
83 | };
|
---|
84 |
|
---|