connectivity/com.nokia.tcf/native/TCFNative/TCFProtOST/OSTProtocol.cpp
author Chad Peckham <chad.peckham@nokia.com>
Tue, 25 Aug 2009 09:44:48 -0500
changeset 458 70467d598794
parent 60 9d2210c8eed2
permissions -rw-r--r--
Fix for bug 9652
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
60
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     1
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     3
* All rights reserved.
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     4
* This component and the accompanying materials are made available
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     6
* which accompanies this distribution, and is available
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     8
*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     9
* Initial Contributors:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    11
*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    12
* Contributors:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    13
*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    14
* Description: 
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    15
*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    16
*/
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    17
// OSTProtocol.cpp: implementation of the COSTProtocol class.
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    18
//
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    19
//////////////////////////////////////////////////////////////////////
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    20
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    21
#include "stdafx.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    22
#include "OSTProtocol.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    23
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    24
//////////////////////////////////////////////////////////////////////
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    25
// Construction/Destruction
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    26
//////////////////////////////////////////////////////////////////////
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    27
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    28
COSTProtocol::COSTProtocol()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    29
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    30
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    31
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    32
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    33
COSTProtocol::~COSTProtocol()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    34
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    35
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    36
}
458
70467d598794 Fix for bug 9652
Chad Peckham <chad.peckham@nokia.com>
parents: 60
diff changeset
    37
int COSTProtocol::DecodeMessage(BYTE* fullMessage, DWORD& fullMessageLength, BYTE& msgId, BYTE*& rawMessage, DWORD& rawLength)
60
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    38
{
458
70467d598794 Fix for bug 9652
Chad Peckham <chad.peckham@nokia.com>
parents: 60
diff changeset
    39
	int result = DECODE_MESSAGE_NOT_FOUND;
60
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    40
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    41
	WORD msgLen = MAKEWORD(fullMessage[OST_LEN_BYTE_1+1], fullMessage[OST_LEN_BYTE_1]);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    42
	if (fullMessageLength >= (WORD)(msgLen + OST_HDR_LEN_1))
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    43
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    44
		msgId = fullMessage[OST_PROT_BYTE_1];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    45
		rawMessage = &fullMessage[OST_MSG_BYTE_1];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    46
		rawLength = msgLen;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    47
		fullMessageLength = msgLen+OST_HDR_LEN_1;
458
70467d598794 Fix for bug 9652
Chad Peckham <chad.peckham@nokia.com>
parents: 60
diff changeset
    48
		result = DECODE_MESSAGE_FOUND;
70467d598794 Fix for bug 9652
Chad Peckham <chad.peckham@nokia.com>
parents: 60
diff changeset
    49
	}
70467d598794 Fix for bug 9652
Chad Peckham <chad.peckham@nokia.com>
parents: 60
diff changeset
    50
	else
70467d598794 Fix for bug 9652
Chad Peckham <chad.peckham@nokia.com>
parents: 60
diff changeset
    51
	{
70467d598794 Fix for bug 9652
Chad Peckham <chad.peckham@nokia.com>
parents: 60
diff changeset
    52
		result = DECODE_NOT_ENOUGH_BYTES_TO_SEARCH;
60
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    53
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    54
458
70467d598794 Fix for bug 9652
Chad Peckham <chad.peckham@nokia.com>
parents: 60
diff changeset
    55
	return result;
60
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    56
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    57
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    58
DWORD COSTProtocol::EncodeMessage(BYTE* rawMessage, DWORD rawLength, BYTE protocolVersion, BYTE msgId, BYTE* fullMessage, DWORD maxFullLength)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    59
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    60
	DWORD outLength = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    61
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    62
	fullMessage[OST_VER_BYTE_1] = protocolVersion;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    63
	fullMessage[OST_PROT_BYTE_1] = msgId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    64
	fullMessage[OST_LEN_BYTE_1] = (BYTE)((rawLength >> 8) & 0xff);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    65
	fullMessage[OST_LEN_BYTE_1+1] = (BYTE)(rawLength & 0xff);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    66
	if (rawLength > 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    67
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    68
		memcpy(&fullMessage[OST_MSG_BYTE_1], rawMessage, rawLength);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    69
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    70
	outLength = rawLength + OST_HDR_LEN_1;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    71
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    72
	return outLength;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    73
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    74
}