80 lines
2.7 KiB
C++

//----------------------------------------------------------------------------
//
// Copyright (C) Intel Corporation, 2006 - 2007.
//
// File: ProtocolBasicMessage.h
//
// Contents: Handles basic messages in the APF (Intel(R) AMT Port
// Forwarding protocol).
//
// Notes: Version 1.0
//----------------------------------------------------------------------------
#ifndef _PROTOCOL_BASIC_MESSAGE_H__
#define _PROTOCOL_BASIC_MESSAGE_H__
//===================================================
// INCLUDES
//===================================================
#include <ace/ACE.h>
#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
#include "global.h"
#include <ace/SOCK_Stream.h>
#include <ace/Message_Block.h>
#include <ace/SString.h>
//===================================================
// Sockets IO macros
//===================================================
// Read basic type from the socket
#define READ_LEN(STREAM,X) (Protocol_BasicMessage::read((STREAM), (X)))
// Read basic type from the socket and return error if needed
#define READ_ERROR(STREAM,X) \
do { \
if (READ_LEN((STREAM),(X)) <= 0) \
return STATUS_NETWORK_ERROR; \
} while (0)
// Read basic type from the socket, return error if needed or if X > L
#define READ_MAX_ERROR(STREAM,X,L) \
do { \
int res = READ_LEN((STREAM),(X)); \
if ((res <= 0) || (res > (L))) \
return STATUS_NETWORK_ERROR; \
} while (0)
// Read string from the socket
#define READ_STR_LEN(STREAM, S,L) (Protocol_BasicMessage::read((STREAM), (S), (L)) <=0)
// Read string from the socket, and return error if needed
#define READ_STR_ERROR(STREAM, S,L) \
do { \
if (READ_STR_LEN((STREAM),(S),(L))) \
return STATUS_NETWORK_ERROR; \
} while (0)
// Basic APF message class contain the basic type serialization/deserialization
class Protocol_BasicMessage {
public:
virtual STATUS read (ACE_SOCK_Stream &stream) = 0;
virtual void write (ACE_Message_Block *&mb)= 0;
int read (ACE_SOCK_Stream &stream, ACE_UINT8 &byte);
int read (ACE_SOCK_Stream &stream, ACE_UINT16 &word);
int read (ACE_SOCK_Stream &stream, ACE_UINT32 &dword);
int read (ACE_SOCK_Stream &stream, ACE_CString &str, ACE_UINT32 len);
int read (ACE_SOCK_Stream &stream, ACE_Message_Block *&mb, ACE_UINT32 len);
void write (ACE_Message_Block* mb , ACE_UINT8 byte);
void write (ACE_Message_Block* mb , ACE_UINT16 byte);
void write (ACE_Message_Block* mb , ACE_UINT32 byte);
void write (ACE_Message_Block* mb , ACE_CString &str, ACE_UINT32 len);
void write (ACE_Message_Block* mb , ACE_Message_Block* src_mb, ACE_UINT32 len);
virtual size_t size() = 0;
virtual unsigned int maxSize() =0;
};
#endif //_PROTOCOL_BASIC_MESSAGE_H__