0
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
#ifndef STATTRANSPORT_H
|
|
22 |
#define STATTRANSPORT_H
|
|
23 |
|
|
24 |
#include <stdio.h>
|
|
25 |
#include <stdarg.h>
|
|
26 |
#include <memory.h>
|
|
27 |
#include "CSTATReturnCodes.h"
|
|
28 |
|
|
29 |
|
|
30 |
// abstract transport class
|
|
31 |
class CSTATTransport
|
|
32 |
{
|
|
33 |
public:
|
|
34 |
CSTATTransport();
|
|
35 |
~CSTATTransport() {}
|
|
36 |
|
|
37 |
// these must be derived for selected transport
|
|
38 |
virtual int Initialise(void) = 0;
|
|
39 |
virtual int Connect(const char *pAddress = NULL) = 0;
|
|
40 |
virtual int Send(const char cIdentifier, const char *pData = NULL, const unsigned long ulLength = 0) = 0;
|
|
41 |
virtual int Receive(char *cIdentifier, char **ppData = NULL, unsigned long *pLength = NULL) = 0;
|
|
42 |
virtual int Disconnect(void) = 0;
|
|
43 |
virtual int Release(void) = 0;
|
|
44 |
virtual char * Error(void);
|
|
45 |
virtual unsigned int GetMaxPacketSize(void) const = 0;
|
|
46 |
|
|
47 |
protected:
|
|
48 |
void SetError(const char *pText, ...);
|
|
49 |
|
|
50 |
private:
|
|
51 |
char szError[STAT_MAX_ERRORLEN + 1];
|
|
52 |
};
|
|
53 |
|
|
54 |
|
|
55 |
////////////////////////////////////////////////////////////////////////////////////////
|
|
56 |
// Constructor
|
|
57 |
inline CSTATTransport::CSTATTransport(void)
|
|
58 |
{
|
|
59 |
memset(&szError, 0, sizeof(szError));
|
|
60 |
}
|
|
61 |
|
|
62 |
|
|
63 |
////////////////////////////////////////////////////////////////////////////////////////
|
|
64 |
// Return error text
|
|
65 |
inline char * CSTATTransport::Error(void)
|
|
66 |
{
|
|
67 |
return szError;
|
|
68 |
}
|
|
69 |
|
|
70 |
|
|
71 |
////////////////////////////////////////////////////////////////////////////////////////
|
|
72 |
// Set error text
|
|
73 |
inline void CSTATTransport::SetError(const char *pText, ...)
|
|
74 |
{
|
|
75 |
memset(&szError, 0, sizeof(szError));
|
|
76 |
|
|
77 |
va_list pCurrent = (va_list)0;
|
|
78 |
va_start (pCurrent, pText);
|
|
79 |
vsprintf (szError, pText, pCurrent);
|
|
80 |
va_end (pCurrent);
|
|
81 |
|
|
82 |
char szExtra[20] = {0};
|
|
83 |
sprintf(szExtra, " (%d)", GetLastError());
|
|
84 |
strcat (szError, szExtra);
|
|
85 |
}
|
|
86 |
|
|
87 |
|
|
88 |
#endif
|