testtoolsconn/stat/desktop/testsource/dlltester/inc/utils.h
changeset 0 3da2a79470a7
equal deleted inserted replaced
-1:000000000000 0:3da2a79470a7
       
     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 // Utils.h : main header file for the basic utilities class
       
    22 //
       
    23 
       
    24 #ifndef UTILS_H
       
    25 #define UTILS_H
       
    26 
       
    27 #include <windows.h>
       
    28 #include <stdio.h>
       
    29 #include <winsvc.h>
       
    30 
       
    31 // service requests
       
    32 #define REQ_START 1
       
    33 #define REQ_STOP  2
       
    34 
       
    35 // file requests
       
    36 #define DELETEALL 1
       
    37 #define DELETEFILESONLY 2
       
    38 #define REMOVEALLATTRIBUTES 4
       
    39 
       
    40 
       
    41 class CUtils
       
    42 {
       
    43 	SC_HANDLE hSCM;
       
    44 	HANDLE m_hMutex;
       
    45 	WIN32_FIND_DATA ffd;
       
    46 	unsigned int iFileCommand;
       
    47 	unsigned int iFileCount;
       
    48 	TCHAR szError[2048];
       
    49 	unsigned long retCode;
       
    50 
       
    51 	bool Validate(SC_HANDLE hSCM, const char *szServiceName, DWORD dwState, bool bDisplayOnly = false);
       
    52 	void Recurse(const char * rootDir);
       
    53 	void DealWithDependentServices(const char *szServiceName, const unsigned int iRequest);
       
    54 	void _GetWindowsError();
       
    55 
       
    56 public:
       
    57 	CUtils();
       
    58 	~CUtils();
       
    59 
       
    60 	bool AlreadyRunning(LPCTSTR szAppName);
       
    61 	bool CallProcessAndWait(LPCTSTR szApplication, LPTSTR szCommandLine, LPCTSTR szDirectory, bool bRunMinimised = false);
       
    62 	bool CallProcess(LPCTSTR szApplication, LPTSTR szCommandLine, LPCTSTR szDirectory);
       
    63 	bool ServiceRequest(const char *szServiceName, const unsigned int iRequest);
       
    64 	bool ListServices(DWORD dwState);
       
    65 	unsigned int RecurseDir(const char *szDirectory, const unsigned int iCommand);
       
    66 	void AddSlash(char *szPath);
       
    67 	int TrimBufferToFirstEOL(HANDLE mmphndl, char *szBuffer, bool bIncludeCR = true);
       
    68 	void TrimBufferToLastEOL(HANDLE mmphndl, char *szBuffer);
       
    69 	void TrimTabsCRAndWhitespace(char *szBuffer);
       
    70 	char *GetWindowsError();
       
    71 	char *GetWindowsErrorNow();
       
    72 	unsigned long GetReturnCode() {return retCode;}
       
    73 	unsigned long GetReturnCodeNow() {return GetLastError();}
       
    74 };
       
    75 
       
    76 #endif