Changeset 18208 in vbox for trunk/src/VBox/Main/include
- Timestamp:
- Mar 24, 2009 5:01:32 PM (16 years ago)
- Location:
- trunk/src/VBox/Main/include
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/DHCPServerImpl.h
r18023 r18208 77 77 STDMETHOD(SetConfiguration) (IN_BSTR aIPAddress, IN_BSTR aNetworkMask, IN_BSTR aFromIPAddress, IN_BSTR aToIPAddress); 78 78 79 STDMETHOD(Start) (IN_BSTR aNetworkName, IN_BSTR aTrunkName, IN_BSTR aTrunkType); 80 STDMETHOD(Stop) (); 81 79 82 // for VirtualBoxSupportErrorInfoImpl 80 83 static const wchar_t *getComponentName() { return L"DHCPServer"; } … … 95 98 Bstr upperIP; 96 99 BOOL enabled; 100 101 DHCPServerRunner dhcp; 97 102 } m; 98 103 -
trunk/src/VBox/Main/include/DHCPServerRunner.h
r18169 r18208 1 /* $Id : DHCPServerRunner.h 44622 2009-03-17 13:48:59Z misha$ */1 /* $Id$ */ 2 2 /** @file 3 3 * VirtualBox Main - interface for VBox DHCP server … … 23 23 #include <iprt/string.h> 24 24 #include <iprt/mem.h> 25 //#include <VBox/com/string.h>25 #include <VBox/com/string.h> 26 26 27 //using namespace com;28 27 typedef enum 29 28 { … … 50 49 #define TRUNKTYPE_NETADP "netadp" 51 50 #define TRUNKTYPE_SRVNAT "srvnat" 52 53 class Utf8Str54 {55 public:56 57 enum CaseSensitivity58 {59 CaseSensitive,60 CaseInsensitive61 };62 63 typedef char *String;64 typedef const char *ConstString;65 66 Utf8Str () : str (NULL) {}67 68 Utf8Str (const Utf8Str &that) : str (NULL) { raw_copy (str, that.str); }69 Utf8Str (const char *that) : str (NULL) { raw_copy (str, that); }70 71 /** Shortcut that calls #alloc(aSize) right after object creation. */72 Utf8Str (size_t aSize) : str (NULL) { alloc(aSize); }73 74 virtual ~Utf8Str () { setNull(); }75 76 Utf8Str &operator = (const Utf8Str &that) { safe_assign (that.str); return *this; }77 Utf8Str &operator = (const char *that) { safe_assign (that); return *this; }78 79 Utf8Str &setNull()80 {81 if (str)82 {83 ::RTStrFree (str);84 str = NULL;85 }86 return *this;87 }88 89 Utf8Str &setNullIfEmpty()90 {91 if (str && *str == 0)92 {93 ::RTStrFree (str);94 str = NULL;95 }96 return *this;97 }98 99 /**100 * Allocates memory for a string capable to store \a aSize - 1 bytes (not characters!);101 * in other words, aSize includes the terminating zero character. If \a aSize102 * is zero, or if a memory allocation error occurs, this object will become null.103 */104 Utf8Str &alloc (size_t aSize)105 {106 setNull();107 if (aSize)108 {109 #if !defined (VBOX_WITH_XPCOM)110 str = (char *) ::RTMemTmpAlloc (aSize);111 #else112 str = (char *) nsMemory::Alloc (aSize);113 #endif114 if (str)115 str [0] = 0;116 }117 return *this;118 }119 120 void append(const Utf8Str &that)121 {122 size_t cbThis = length();123 size_t cbThat = that.length();124 125 if (cbThat)126 {127 size_t cbBoth = cbThis + cbThat + 1;128 129 // @todo optimize with realloc() once the memory management is fixed130 char *pszTemp;131 pszTemp = (char*)::RTMemTmpAlloc(cbBoth);132 if (str)133 {134 memcpy(pszTemp, str, cbThis);135 setNull();136 }137 if (that.str)138 memcpy(pszTemp + cbThis, that.str, cbThat);139 pszTemp[cbThis + cbThat] = '\0';140 141 str = pszTemp;142 }143 }144 145 int compare (const char *pcsz, CaseSensitivity cs = CaseSensitive) const146 {147 if (str == pcsz)148 return 0;149 if (str == NULL)150 return -1;151 if (pcsz == NULL)152 return 1;153 154 if (cs == CaseSensitive)155 return ::RTStrCmp(str, pcsz);156 else157 return ::RTStrICmp(str, pcsz);158 }159 160 int compare (const Utf8Str &that, CaseSensitivity cs = CaseSensitive) const161 {162 return compare (that.str, cs);163 }164 165 bool operator == (const Utf8Str &that) const { return !compare (that); }166 bool operator != (const Utf8Str &that) const { return !!compare (that); }167 bool operator == (const char *that) const { return !compare (that); }168 bool operator != (const char *that) const { return !!compare (that); }169 bool operator < (const Utf8Str &that) const { return compare (that) < 0; }170 bool operator < (const char *that) const { return compare (that) < 0; }171 172 bool endsWith (const Utf8Str &that, CaseSensitivity cs = CaseSensitive) const173 {174 if (isNull() || that.isNull())175 return false;176 177 if (length() < that.length())178 return false;179 180 int l = length() - that.length();181 if (cs == CaseSensitive)182 return ::RTStrCmp(&str[l], that.str) == 0;183 else184 return ::RTStrICmp(&str[l], that.str) == 0;185 }186 187 bool startsWith (const Utf8Str &that, CaseSensitivity cs = CaseSensitive) const188 {189 if (isNull() || that.isNull())190 return false;191 192 if (length() < that.length())193 return false;194 195 if (cs == CaseSensitive)196 return ::RTStrNCmp(str, that.str, that.length()) == 0;197 else198 return ::RTStrNICmp(str, that.str, that.length()) == 0;199 }200 201 bool isNull() const { return str == NULL; }202 operator bool() const { return !isNull(); }203 204 bool isEmpty() const { return isNull() || *str == 0; }205 206 size_t length() const { return isNull() ? 0 : ::strlen (str); }207 208 /** Intended to to pass instances as input (|char *|) parameters to methods. */209 operator const char *() const { return str; }210 211 /** The same as operator const char *(), but for situations where the compiler212 cannot typecast implicitly (for example, in printf() argument list). */213 const char *raw() const { return str; }214 215 /** The same as operator const char *(), but for situations where the compiler216 cannot typecast implicitly (for example, in printf() argument list). */217 const char *c_str() const { return str; }218 219 /**220 * Returns a non-const raw pointer that allows to modify the string directly.221 * @warning222 * Be sure not to modify data beyond the allocated memory! The223 * guaranteed size of the allocated memory is at least #length()224 * bytes after creation and after every assignment operation.225 */226 char *mutableRaw() { return str; }227 228 /**229 * Intended to assign instances to |char *| out parameters from within the230 * interface method. Transfers the ownership of the duplicated string to the231 * caller.232 */233 const Utf8Str &cloneTo (char **pstr) const234 {235 if (pstr)236 {237 *pstr = NULL;238 raw_copy (*pstr, str);239 }240 return *this;241 }242 243 /**244 * Intended to assign instances to |char *| out parameters from within the245 * interface method. Transfers the ownership of the original string to the246 * caller and resets the instance to null.247 *248 * As opposed to cloneTo(), this method doesn't create a copy of the249 * string.250 */251 Utf8Str &detachTo (char **pstr)252 {253 *pstr = str;254 str = NULL;255 return *this;256 }257 258 static const size_t npos;259 260 /**261 * Intended to pass instances as out (|char **|) parameters to methods.262 * Takes the ownership of the returned data.263 */264 char **asOutParam() { setNull(); return &str; }265 266 /**267 * Static immutable null object. May be used for comparison purposes.268 */269 static const Utf8Str Null;270 271 protected:272 273 void safe_assign (const char *s)274 {275 if (str != s)276 {277 setNull();278 raw_copy (str, s);279 }280 }281 282 inline static void raw_copy (char *&ls, const char *rs)283 {284 if (rs)285 //#if !defined (VBOX_WITH_XPCOM)286 ::RTStrDupEx (&ls, rs);287 //#else288 // ls = (char *) nsMemory::Clone (rs, strlen (rs) + 1);289 //#endif290 }291 292 char *str;293 294 };295 51 296 52 class DHCPServerRunner … … 328 84 void detachFromServer(); 329 85 private: 330 Utf8Str mOptions[DHCPCFG_NOTOPT_MAXVAL];86 com::Utf8Str mOptions[DHCPCFG_NOTOPT_MAXVAL]; 331 87 RTPROCESS mProcess; 332 88 };
Note:
See TracChangeset
for help on using the changeset viewer.