connectivity/com.nokia.tcf/native/TCFNative/TCFServer/MessageFile.h
changeset 60 9d2210c8eed2
equal deleted inserted replaced
59:c892c53c664e 60:9d2210c8eed2
       
     1 /*
       
     2 * Copyright (c) 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 the License "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 // MessageFile.h: interface for the CMessageFile class.
       
    18 //
       
    19 // One per client
       
    20 //////////////////////////////////////////////////////////////////////
       
    21 
       
    22 #if !defined(AFX_MESSAGEFILE_H__1049F760_2A8A_491F_A868_B063D52B18E8__INCLUDED_)
       
    23 #define AFX_MESSAGEFILE_H__1049F760_2A8A_491F_A868_B063D52B18E8__INCLUDED_
       
    24 
       
    25 #include <share.h>
       
    26 #include "stdio.h"
       
    27 #include "mutex.h"
       
    28 //#include "ServerClient.h"
       
    29 
       
    30 #if _MSC_VER > 1000
       
    31 #pragma once
       
    32 #endif // _MSC_VER > 1000
       
    33 
       
    34 
       
    35 //----------------------------------
       
    36 // Message File Mutex
       
    37 //----------------------------------
       
    38 // Mutex name is basename + clientID
       
    39 #define MESSAGEFILE_MUTEX_BASENAME		"TCFMessageFileMutex"
       
    40 #define MESSAGEFILE_MUTEX_TIMEOUT		(60000L)
       
    41 
       
    42 class CMessageFile  
       
    43 {
       
    44 public:
       
    45 	CMessageFile(CHAR* pFilePath, long inClientID);
       
    46 	virtual ~CMessageFile();
       
    47 
       
    48 
       
    49 	long Open();
       
    50 	long Close();
       
    51 	long AddMessage(DWORD inLength, BYTE* inMessage);
       
    52 	void UnLockMessageFile() { ReleaseAccess(); }
       
    53 
       
    54 	BOOL WaitForAccess() { if (m_FileLocked) return TRUE; else { m_FileLocked = TRUE; return m_Mutex.Wait();} };
       
    55 	BOOL ReleaseAccess() { if (m_FileLocked) { m_FileLocked = FALSE; return m_Mutex.Release();} else return TRUE; };
       
    56 	BOOL isOpen() { return m_Open; }
       
    57 	long ClearFile();
       
    58 	void FlushFile(BOOL numberTimeOut = FALSE);
       
    59 
       
    60 	long m_ClientID;
       
    61 	BOOL m_Open;
       
    62 	Mutex m_Mutex;
       
    63 	CHAR m_FilePath[MAX_FILEPATH];
       
    64 	BOOL m_FileLocked;
       
    65 	FILE* m_hFile;
       
    66 	DWORD m_numWritten;		// total number written
       
    67 	DWORD m_numWrittenSinceLastFlush;	// number written and not flushed yet
       
    68 
       
    69 	// logging performance
       
    70 // for performance - independent of debug logging
       
    71 //#define LOG_FILE_PERFORMANCE
       
    72 #ifdef LOG_FILE_PERFORMANCE
       
    73 	char* perfFileName;
       
    74 	FILE *fpLog;
       
    75 	int numLogged;
       
    76 	void logPerf(char* msg);
       
    77 	void openPerf();
       
    78 	void closePerf();
       
    79 #define OPENFILEPERF() openPerf()
       
    80 #define LOGFILEPERF(s) logPerf(s)
       
    81 #define CLOSEFILEPERF() closePerf()
       
    82 #else
       
    83 #define OPENFILEPERF()
       
    84 #define LOGFILEPERF(s)
       
    85 #define CLOSEFILEPERF()
       
    86 #endif
       
    87 
       
    88 
       
    89 
       
    90 };
       
    91 
       
    92 #endif // !defined(AFX_MESSAGEFILE_H__1049F760_2A8A_491F_A868_B063D52B18E8__INCLUDED_)