* 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:
@@ -16,7 +16,7 @@
|
|||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
class BNetworkAddress : public BArchivable {
|
class BNetworkAddress : public BFlattenable {
|
||||||
public:
|
public:
|
||||||
BNetworkAddress();
|
BNetworkAddress();
|
||||||
BNetworkAddress(const char* address,
|
BNetworkAddress(const char* address,
|
||||||
@@ -38,7 +38,6 @@ public:
|
|||||||
BNetworkAddress(const in6_addr& address,
|
BNetworkAddress(const in6_addr& address,
|
||||||
uint16 port = 0);
|
uint16 port = 0);
|
||||||
BNetworkAddress(const BNetworkAddress& other);
|
BNetworkAddress(const BNetworkAddress& other);
|
||||||
BNetworkAddress(BMessage* archive);
|
|
||||||
virtual ~BNetworkAddress();
|
virtual ~BNetworkAddress();
|
||||||
|
|
||||||
status_t InitCheck() const;
|
status_t InitCheck() const;
|
||||||
@@ -117,12 +116,18 @@ public:
|
|||||||
BString HostName() const;
|
BString HostName() const;
|
||||||
BString ServiceName() 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 Equals(const BNetworkAddress& other,
|
||||||
bool includePort = true) const;
|
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);
|
BNetworkAddress& operator=(const BNetworkAddress& other);
|
||||||
|
|
||||||
bool operator==(const BNetworkAddress& other) const;
|
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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Author:
|
* Author:
|
||||||
@@ -59,6 +59,7 @@ enum {
|
|||||||
B_UINT8_TYPE = 'UBYT',
|
B_UINT8_TYPE = 'UBYT',
|
||||||
B_VECTOR_ICON_TYPE = 'VICN',
|
B_VECTOR_ICON_TYPE = 'VICN',
|
||||||
B_XATTR_TYPE = 'XATR',
|
B_XATTR_TYPE = 'XATR',
|
||||||
|
B_NETWORK_ADDRESS_TYPE = 'NWAD',
|
||||||
|
|
||||||
// deprecated, do not use
|
// deprecated, do not use
|
||||||
B_ASCII_TYPE = 'TEXT' // use B_STRING_TYPE instead
|
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()
|
BNetworkAddress::BNetworkAddress()
|
||||||
{
|
{
|
||||||
Unset();
|
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
|
bool
|
||||||
BNetworkAddress::Equals(const BNetworkAddress& other, bool includePort) const
|
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&
|
||||||
BNetworkAddress::operator=(const BNetworkAddress& other)
|
BNetworkAddress::operator=(const BNetworkAddress& other)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user