/**
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is part of The iWear Framework.
 *
 * The iWear Framework is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the
 * Free Software Foundation as in version 2 of the License.

 * 
 * The iWear Framework is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * The iWear Framework; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __IWREMOTE_PROTOCOL_H
#define __IWREMOTE_PROTOCOL_H

#ifndef __IWEAR_BUILDPHASE
#include <iwear/buildphase.h>
#endif

#define RPC_PORT	4242

// Packet types (max. 255)
#define MSG_CODE_SSLSTARTUP	0x00 ///< This requests a ssl connection
#define MSG_CODE_ASSOCIATE	0x01
#define MSG_CODE_DEASSOCIATE	0x02
#define MSG_CODE_CALL_OBJECT	0x03
#define MSG_CODE_CALL_RETURN	0x04
#define MSG_CODE_CALL_ERROR	0x05
#define MSG_CODE_CALL_REJECT	0x06
#define MSG_CODE_ERROR		0x07
#define MSG_CODE_RETURN		0x08
#define MSG_CODE_ASS_RETURN	0x09
#define MSG_CODE_ASS_REJECT	0x0A
#define MSG_CODE_ASS_REDIRECT	0x0B
#define MSG_CODE_SSLDATA	0x30
#define MSG_CODE_PROXY		0x40
#define MSG_CODE_BEACON		0x41 ///< "Hey Im here!"
#define MSG_CODE_BCREQ		0x42 ///< "Anyone here?"
#define MSG_CODE_SUBPROTO	0xFF	///< Reserved

//Packet flags
#define MSG_FLAG_SSL		0x01		///< If the packet contains SSL encrypted data
#define MSG_FLAG_GZIP		0x02		///< If the packet is gzip compressed
#define MSG_FLAG_SEQ		0x04		///< If the packet is sequencced (i.e. field 4)
#define MSG_FLAG_DEFERRED	0x08		///< When the operation is deferred.
#define MSG_FLAG_RES2		0x10		///< Reserved for future use
#define MSG_FLAG_RES3		0x20		///< Reserved for future use
#define MSG_FLAG_RES4		0x40		///< Reserved for future use
#define MSG_FLAG_RES5		0x80		///< Reserved for future use

#define MSG_REASON_UNDEFINED	0x00000000
#define MSG_REASON_NOCID	0x00000001 // no such class id
#define MSG_REASON_NOUID	0x00000002 // no such uid
#define MSG_REASON_NOCUID	0x00000003 // no such uid+classid
#define MSG_REASON_NOCHAN	0x00000004 // Invalid channel
#define MSG_REASON_SECURITY	0x00000005
#define MSG_REASON_DEFECT	0x00000006 // The package had some defect
#define MSG_REASON_INTERNAL	0x00000007 // An internal error was detected
#define MSG_REASON_UNSUPPORTED	0x00000008 // Something is unsupported
#define MSG_REASON_BUFFER	0x00000009 // Not enough buffer space for operation
#define MSG_REASON_NOFUNC	0x0000000A // That function isnt served here
#define MSG_REASON_TIMEOUT	0x0000000B // Something timed out

namespace iwear {
class uid; // we need to keep this forward declaration otherwise the
// RemoteConnection would explod into our face right away.
    namespace net {    
// these typedefs are for iwear-rpc specific important typedefs

/**
 * A cid_t is the "Class ID" type, which is for specifying a unique identifier
 * for the class-interface that is implemented.
 */	
typedef uint32_t cid_t;

typedef uint16_t chanid_t;
/**
 * Although the ID for Object and Host are both uids, to distinguish the
 * semantics of parameters, returns and variables we mean "this is a uid for an
 * object"
 */
typedef iwear::uid oid_t;

/**
 * This means "I am a uid to specify a host"
 */
typedef iwear::uid hostid_t;
}
}

#define SIZE_CID (sizeof(cid_t))
///@todo FIXME These constants will probably be out of date in case we change the cid_t to 64Bit
#define SIZE_WORD (4)
#define SIZE_UID (16)
#define SIZE_HEADER (SIZE_WORD+SIZE_WORD+SIZE_WORD)
#define SIZE_SSLPREFIX (SIZE_WORD+SIZE_WORD)
#define SIZE_CALLHEADER (SIZE_HEADER+SIZE_UID+SIZE_UID+SIZE_WORD)
#define MAX_IWRPC_STRING 100000
/*
class 
{
private:
protected:
public:
};
*/

#endif
