|
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 STATENGINE_H |
|
22 #define STATENGINE_H |
|
23 |
|
24 #include <statcommon.h> |
|
25 #include <CSTATLogfile.h> |
|
26 #include <CSTATDataFormatConverter.h> |
|
27 #include <CSTATImageVerify.h> |
|
28 #include <statcomms.h> |
|
29 #include <statscriptdecoder.h> |
|
30 #include <ini.h> |
|
31 |
|
32 #include "ScriptProgressMonitor.h" |
|
33 #include <winsock2.h> |
|
34 |
|
35 #define DOTTED_LINE "--------------------------------------------------------------------------------------------------------------" |
|
36 |
|
37 class CSTATEngine |
|
38 { |
|
39 public: |
|
40 CSTATEngine(); |
|
41 ~CSTATEngine(); |
|
42 int Initialise(const STATCONNECTTYPE eConnect, const char *pAddress = NULL); // start everything |
|
43 void SetCommandDelay(int iMillisecondDelay); // set delay between commands |
|
44 int SetLogging(const CString& logfilename, const char* prefix, |
|
45 bool append, bool bMessages, bool bFile, MessageReporter *const aMessageReporter); // set a log message |
|
46 int GetCommandCount(CString file, int *pCount); // get amount of commands in script |
|
47 int OpenScriptFile(CString file, bool bIsFile); // load the script |
|
48 int RunScript(ScriptProgressMonitor *const monitor); // run the script |
|
49 int Release(void); // release all resources |
|
50 const char* GetErrorText(int iCode) { return pLog->Text(iCode); } // convert an error code into a text message |
|
51 const char* GetReceivedData(void); |
|
52 int GetDeviceReturnCode() { return iDeviceCode; } // get device return code |
|
53 void SetMultithreaded(bool bState = true) { bMultithreaded = bState; } // set multithreaded check |
|
54 |
|
55 static LPTSTR ToUnicode(const char *string); // convert ANSI to Unicode |
|
56 static char * ToAnsi(LPCTSTR string); // convert Unicode to ANSI |
|
57 static void CreateAllDirectories(CString &fullpath); // create sub folders |
|
58 |
|
59 CSTATDataFormatConverter *pConverter; // bitmap conversion |
|
60 CSTATImageVerify *pImageVerify; // image verification |
|
61 STAT_STATE eStopProcessing; // flag to pause/stop processing |
|
62 int iCurrentCommand; // index of the current command being processed |
|
63 char *pDeviceInfo; // pointer to device information |
|
64 char *iTEFSharedData; // pointer to TEF shared data information |
|
65 int iMaxTimeLimit; // max time to wait for a command |
|
66 |
|
67 private: |
|
68 |
|
69 |
|
70 |
|
71 void SetScreenshotDirectory(const char *szScreenshotDir) { cScreenshotDirectory = szScreenshotDir; } |
|
72 int SetScreenshotDefaultDirectory(void); |
|
73 int SendCommand(CSTATScriptCommand *pCommand, CSTATScriptCommand **ppRecvCommand); |
|
74 int SendSingleCommand(CSTATScriptCommand *pCommand, CSTATScriptCommand **ppRecvCommand); |
|
75 int ReadTransferFile(const char *pFile, CSTATScriptCommand *pCommand); |
|
76 int SaveTransferFile(const char *pFile, char *pContents, unsigned long ulLength); |
|
77 void LogDetails(const char *prefix, CSTATScriptCommand *pCommand); |
|
78 int ConvertAndSaveScreeenshot(CString &file, const char *pContents, const unsigned long ulLength); |
|
79 int SaveTheFile(CString path, const char *pContents, const unsigned long ulLength); |
|
80 void Message(const char *pMsg, ...); |
|
81 bool StopProcessing(); |
|
82 bool RemoveLeftoverMBMFiles(); |
|
83 void AppendCommandToSTATLog(char *heading, char *log, unsigned long length); |
|
84 void StoreData( char* aData, unsigned long aLength, char*& aOutputPtr ); |
|
85 CString GetConnection(STATCONNECTTYPE eConnectType); |
|
86 |
|
87 CSTATScriptCommand oRecvCommand; // last received command |
|
88 STATComms *pComms; // transport |
|
89 CSTATScriptDecoder *pDecoder; // script decoder |
|
90 CSTATLogFile *pLog; // log file |
|
91 CString cScreenshotDirectory; // screenshot location |
|
92 int iDelay; // command delay |
|
93 const int minimumdelay; |
|
94 const int maximumdelay; |
|
95 char szAddress[256]; // the name of the port we are using |
|
96 STATCONNECTTYPE eConnectType; // current connection type |
|
97 int iDeviceCode; // device return code |
|
98 bool bMultithreaded; // flag if operating in multithreaded environment |
|
99 CStatIniFile statIniFile; // ini file reader |
|
100 CString receivedData; |
|
101 |
|
102 void WriteToSocket(const char *data, int *length); |
|
103 void ReadFromSocket(char *data, int *length); |
|
104 int SetSocket(const char *ip, const int port); |
|
105 int ReleaseSocket(); |
|
106 |
|
107 bool settingSocket; |
|
108 SOCKET dataSocket; |
|
109 WSADATA wsaData; |
|
110 |
|
111 }; |
|
112 |
|
113 inline const char* CSTATEngine::GetReceivedData(void) |
|
114 { |
|
115 return ( receivedData.operator LPCTSTR( ) ); |
|
116 } |
|
117 |
|
118 |
|
119 |
|
120 //---------------------------------------------------------------------------- |
|
121 // our thread-safe mechanism - this must be defined, initialised and destroyed by |
|
122 // the code using CSTATEngine. See STATMember.cpp for an example |
|
123 extern CRITICAL_SECTION CriticalSection; |
|
124 //---------------------------------------------------------------------------- |
|
125 |
|
126 #endif |