From e6cec9839d45710cd9cb276212804b68ac39d7c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 29 Nov 2010 20:29:37 +0000 Subject: [PATCH] * BNetworkAddress isn't really BArchivable material, switched to BFlattenable instead. * Also actually implemented the serializing functionality this time, as usual completely untested, though :-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39677 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/net/NetworkAddress.h | 15 ++-- headers/os/support/TypeConstants.h | 3 +- src/kits/network/libnetapi/NetworkAddress.cpp | 77 +++++++++++++------ 3 files changed, 64 insertions(+), 31 deletions(-) diff --git a/headers/os/net/NetworkAddress.h b/headers/os/net/NetworkAddress.h index ab045666f1..177fd85c8d 100644 --- a/headers/os/net/NetworkAddress.h +++ b/headers/os/net/NetworkAddress.h @@ -16,7 +16,7 @@ #include -class BNetworkAddress : public BArchivable { +class BNetworkAddress : public BFlattenable { public: BNetworkAddress(); BNetworkAddress(const char* address, @@ -38,7 +38,6 @@ public: BNetworkAddress(const in6_addr& address, uint16 port = 0); BNetworkAddress(const BNetworkAddress& other); - BNetworkAddress(BMessage* archive); virtual ~BNetworkAddress(); status_t InitCheck() const; @@ -117,12 +116,18 @@ public: BString HostName() const; BString ServiceName() const; - virtual status_t Archive(BMessage* into, bool deep = true) const; - static BArchivable* Instantiate(BMessage* archive); - bool Equals(const BNetworkAddress& other, bool includePort = true) const; + // BFlattenable implementation + virtual bool IsFixedSize() const; + virtual type_code TypeCode() const; + virtual ssize_t FlattenedSize() const; + + virtual status_t Flatten(void* buffer, ssize_t size) const; + virtual status_t Unflatten(type_code code, const void* buffer, + ssize_t size); + BNetworkAddress& operator=(const BNetworkAddress& other); bool operator==(const BNetworkAddress& other) const; diff --git a/headers/os/support/TypeConstants.h b/headers/os/support/TypeConstants.h index f8502d8f85..7b9eb9935a 100644 --- a/headers/os/support/TypeConstants.h +++ b/headers/os/support/TypeConstants.h @@ -1,5 +1,5 @@ /* - * Copyright 2005-2009, Haiku, Inc. All Rights Reserved. + * Copyright 2005-2010, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Author: @@ -59,6 +59,7 @@ enum { B_UINT8_TYPE = 'UBYT', B_VECTOR_ICON_TYPE = 'VICN', B_XATTR_TYPE = 'XATR', + B_NETWORK_ADDRESS_TYPE = 'NWAD', // deprecated, do not use B_ASCII_TYPE = 'TEXT' // use B_STRING_TYPE instead diff --git a/src/kits/network/libnetapi/NetworkAddress.cpp b/src/kits/network/libnetapi/NetworkAddress.cpp index f495b3938a..45236f2fad 100644 --- a/src/kits/network/libnetapi/NetworkAddress.cpp +++ b/src/kits/network/libnetapi/NetworkAddress.cpp @@ -93,13 +93,6 @@ BNetworkAddress::BNetworkAddress(const BNetworkAddress& other) } -BNetworkAddress::BNetworkAddress(BMessage* archive) -{ - // TODO: implement me - fStatus = B_NO_INIT; -} - - BNetworkAddress::BNetworkAddress() { Unset(); @@ -921,24 +914,6 @@ BNetworkAddress::ServiceName() const } -status_t -BNetworkAddress::Archive(BMessage* into, bool deep) const -{ - // TODO: implement me! - return B_ERROR; -} - - -/*static*/ BArchivable* -BNetworkAddress::Instantiate(BMessage* archive) -{ - if (archive != NULL) - return new BNetworkAddress(archive); - - return NULL; -} - - bool BNetworkAddress::Equals(const BNetworkAddress& other, bool includePort) const { @@ -975,6 +950,58 @@ BNetworkAddress::Equals(const BNetworkAddress& other, bool includePort) const } +// #pragma mark - BFlattenable implementation + + +bool +BNetworkAddress::IsFixedSize() const +{ + return false; +} + + +type_code +BNetworkAddress::TypeCode() const +{ + return B_NETWORK_ADDRESS_TYPE; +} + + +ssize_t +BNetworkAddress::FlattenedSize() const +{ + return Length(); +} + + +status_t +BNetworkAddress::Flatten(void* buffer, ssize_t size) const +{ + if (buffer == NULL || size < FlattenedSize()) + return B_BAD_VALUE; + + memcpy(buffer, &fAddress, Length()); + return B_OK; +} + + +status_t +BNetworkAddress::Unflatten(type_code code, const void* buffer, ssize_t size) +{ + // 2 bytes minimum for family, and length + if (buffer == NULL || size < 2) + return fStatus = B_BAD_VALUE; + if (!AllowsTypeCode(code)) + return fStatus = B_BAD_TYPE; + + memcpy(&fAddress, buffer, min_c(size, (ssize_t)sizeof(fAddress))); + return fStatus = B_OK; +} + + +// #pragma mark - operators + + BNetworkAddress& BNetworkAddress::operator=(const BNetworkAddress& other) {