* 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
This commit is contained in:
parent
bf5d40704e
commit
e6cec9839d
@ -16,7 +16,7 @@
|
||||
#include <String.h>
|
||||
|
||||
|
||||
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;
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user