home *** CD-ROM | disk | FTP | other *** search
- #ifndef _IRESLOCK_
- #define _IRESLOCK_
- /*******************************************************************************
- * FILE NAME: ireslock.hpp *
- * *
- * DESCRIPTION: *
- * Declaration of the class(es): *
- * IResource - The base resource definition class. *
- * IPrivateResource - Private non-shared resource class. *
- * ISharedResource - Resource capable of being shared across processes. *
- * IResourceLock - *
- * *
- * COPYRIGHT: *
- * (C) Copyright IBM Corporation 1992 *
- * All Rights Reserved *
- * Licensed Materials * Property of IBM *
- * *
- * HISTORY: *
- * $Log: R:/ibmclass/ibase/vcs/ireslock.hpv $
- //
- // Rev 1.1 26 Oct 1992 18:23:44 BOBLOVE
- //Update for External Beta
- * *
- *******************************************************************************/
- #ifndef _IVBASE_
- #include <ivbase.hpp>
- #endif
-
- #ifndef _ISTRING_
- #include <istring.hpp>
- #endif
-
-
- class IResource : public IVBase
- {
- /*******************************************************************************
- * This class is the base resource class. *
- * *
- *******************************************************************************/
- friend class IResourceLock;
- public:
- /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------------
- | Instances of this class cannot be created. |
- ------------------------------------------------------------------------------*/
- IResource();
- ~IResource();
- /*------------------------ RESOURCE LOCKING ------------------------------------
- | lock - Acquire a semaphore for this resource. |
- | unlock - Release the semaphore for this resource. |
- ------------------------------------------------------------------------------*/
- IResource
- &lock(long lTimeOut = -1),
- &unlock();
-
-
- protected:
- /*------------------------ IMPLEMENTATION --------------------------------------
- | handle - Return the handle for the semaphore. |
- ------------------------------------------------------------------------------*/
- virtual unsigned long
- &handle() = 0;
-
-
- long
- lClReferenceCount;
-
- IResourceLock
- *reslockGate;
-
- };
-
- class IPrivateResource : public IResource
- {
- /*******************************************************************************
- * This class is used to define a resource that is used within a single *
- * process. *
- * *
- *******************************************************************************/
- friend class IResourceLock;
- public:
- /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------------
- | There is one way to create instances of this class: |
- | 1. The default with no parameters. |
- ------------------------------------------------------------------------------*/
- IPrivateResource();
- virtual
- ~IPrivateResource();
-
- protected:
- /*------------------------ IMPLEMENTATION --------------------------------------
- | handle - Return the handle for the semaphore. |
- ------------------------------------------------------------------------------*/
- unsigned long
- &handle();
-
- private:
-
- unsigned long
- ulClHandle;
-
- };
-
-
- class ISharedResource : public IResource
- {
- /*******************************************************************************
- * This class is used to define a resource that can be shared across multiple *
- * processes using a name provide on construction. *
- * *
- *******************************************************************************/
- friend class IResourceLock;
-
- public:
- /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------------
- | There is one way to create instances of this class: |
- | 1. By proving an a character string identifying the resource to be shared. |
- ------------------------------------------------------------------------------*/
- ISharedResource(const char* pszKeyname);
- virtual
- ~ISharedResource();
-
- IString
- keyName();
-
- protected:
-
- unsigned long
- &handle();
-
- private:
-
- unsigned long
- ulClHandle;
- IString
- strClKeyName;
- };
-
- class IResourceLock : public IBase
- {
- /*******************************************************************************
- * This class locks a resource for a specified timeout. The easiest use of *
- * the class is to declare a stack instance that is in scope for the period *
- * of time that the resource needs to be locked. If the timeout is reached *
- * before the smeaphore can be acquired, an IResourceExhausted exception *
- * is thrown. *
- * *
- * EXAMPLE: *
- * *
- * static IPrivateResource collectionResource; *
- * *
- * addElement() *
- * { *
- * // Lock the resource *
- * IResourceLock collectionLock(collectionResource); *
- * *
- * // Lock is removed on function exit *
- * } *
- * *
- *******************************************************************************/
- friend class IResource;
- public:
-
- /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------------
- | There is one way to create instances of this class: |
- | 1. By proving an IResource reference and an optional timeout value. The |
- | timeout value is specified in milliseconds with -1 indicating an |
- | indefinate wait and zero requesting an immediate return. |
- ------------------------------------------------------------------------------*/
- IResourceLock(IResource& res, long lTimeOut = -1);
-
- ~IResourceLock();
-
- protected:
- /*----------------------------- IMPLEMENTATION ---------------------------------
- | The following functions are used to implement the class. |
- | setLock - Acquires the semaphore. |
- | clearLock - Releases the semaphore. |
- ------------------------------------------------------------------------------*/
- IResourceLock
- &setLock(IResource& res, long lTimeOut = -1),
- &clearLock(IResource& res);
-
- private:
- IResource* presCl;
-
-
- };
-
-
- /* INLINES */
- inline IResource :: IResource()
- {lClReferenceCount=0; reslockGate=0;} // rsr was -1
-
-
- inline unsigned long& IPrivateResource :: handle()
- { return ulClHandle; }
-
- inline unsigned long& ISharedResource :: handle()
- { return ulClHandle; }
-
- #endif