Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PClient.cpp

Go to the documentation of this file.
00001 // PClient.cpp: implementation of the PClient class.
00004 
00005 
00006 #include "StdAfx.h"
00007 #include "PClient.h"
00008 #include "errorCodes.h"
00009 
00011 // Construction/Destruction
00013 
00020 PClient::PClient(const TString &name, const bool isOut)
00021 : Pipe( name, isOut )
00022 {
00023     hPipe = INVALID_HANDLE_VALUE;
00024 }
00025 
00029 PClient::~PClient()
00030 {
00031     disconnect();
00032 }
00033 
00035 // Member Functions
00037 
00042 void PClient::disconnect()
00043 {   
00044     if(hPipe != INVALID_HANDLE_VALUE){
00045         CloseHandle(hPipe);
00046         hPipe = INVALID_HANDLE_VALUE;
00047     }
00048     ResetEvent(serverStayConnected);
00049 }
00050 
00054 DWORD PClient::connect()
00055 {
00056     if( isConnected() )
00057         return PC_ALREADY_CONNECTED;
00058     
00059     if( WaitForSingleObject(clientStayConnected, 0) == WAIT_OBJECT_0 ){
00060         return PC_NOT_RESET;    // Server yet to process disconnect event
00061     }
00062 
00063     hPipe = CreateFile( 
00064         pipeName,           // pipe name 
00065         isOutbound ? GENERIC_WRITE : GENERIC_READ,  // read and write access 
00066         0,                  // no sharing 
00067         NULL,               // no security attributes
00068         OPEN_EXISTING,      // opens existing pipe 
00069         0,                  // default attributes 
00070         NULL);              // no template file 
00071     
00072     if (hPipe == INVALID_HANDLE_VALUE){ 
00073         if (GetLastError() == ERROR_PIPE_BUSY) 
00074             return PC_BUSY;
00075         else
00076             return PC_FAILED;
00077     } else
00078         return PC_CONNECTED;
00079 }
00080 
00088 bool PClient::isConnected()
00089 {
00090     if( WaitForSingleObject(serverStayConnected, 0) == WAIT_OBJECT_0 ){
00091         this->disconnect();
00092     }
00093 
00094     return  hPipe != INVALID_HANDLE_VALUE;
00095 }

Generated on Mon Mar 25 06:29:59 2002 for Window Dressing by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001