Topics
:Overview
Block Diagram
Conditional Directive
VbDeviceTypes Enumeration
Device Cache Functions
Device Bucket Cache Functions
Device Cache Pointer Functions
The VBS device cache consist of series of cooperating classes used to buffer raw data as it moved to and from input and output devices, such as disk files, stream sockets, datagram sockets, serial ports, etc. It was specifically designed to handle large data transfers in the form of continuous streams or controlled bursts. The Device Cache works through multiple inheritance with three primary classes comprising the user interface: the vbDeviceCache class, the vbDeviceBucketCache class, and the vbDeviceCachePtr class.
The vbDeviceCache class is an abstract base class used to define the methods needed to interface a device with the memory cache. The derived class determines the type of device the cache will be linked to. The derived class is also responsible for defining the methods used to read and write to and from the device as well as keep track of the device status. The device cache will buffer a stream of binary data as is it is written to or read from the device the derived class is using to perform I/O operations.
The vbDeviceBucketCache class is responsible for the allocation and de-allocation of a fixed number of cache buckets and incorporates functions used to handle requests for memory-based I/O buffers. The cache must determine whether an I/O buffer is already loaded. If the buffer is not loaded the cache reserves a bucket and loads the buffer into memory. This cache design uses cache pointers to reference cache buckets directly, with each cache pointer being initialized after the bucket is reserved. Cache buckets are organized into a doubly linked list with the number of buckets determined when a vbDeviceBucketCache object is constructed.
The vbDeviceCachePointer class is used to access cache buckets directly, which allows the user to load and unload I/O buffers as needed. Cache pointers are used to work in conjunction with the cache buckets. Each cache pointer stores a pointer to the bucket containing the I/O memory buffer and a pointer to the cache the cache pointer is connected to.
This cache design supports both variable length and fixed length cache buckets. In order to support multiple bucket types the MBTYPE definition is used to define the bucket data type. The bucket data type is set by a conditional directive that allows the device cache classes to use variable or fixed length buffers. Each type must be determined at compile time and only one type can be used for each compile. NOTE: Variable length cache buckets will be used by default. The following conditional directives can be used to support the following bucket data types:
__SMEMORY_BLOCK__ - Fixed length memory (static) blocks using the MemoryBlock type.
__VMEMORY_BUFFER__ - Variable length memory buffers using the MemoryBuffer type.
This vbDeviceTypes enumeration is used to define the various devices types used by the VBS communications library.
enum vbDeviceTypes { vbDEVICE_VOID = 0, // Not pointing to any valid device vbDEVICE_CONSOLE, // Using the console for I/O operations vbDEVICE_DATAGRAM_SOCKET, // Using a datagram socket for I/O vbDEVICE_DISK_FILE, // Using a disk file for I/O operations vbDEVICE_MEMORY_BUFFER, // Using a memory buffer for I/O operations vbDEVICE_NULL, // Dump I/O into the bit bucket vbDEVICE_SERIAL_PORT, // Using a serial port for I/O operations vbDEVICE_STREAM_SOCKET // Using a stream socket for I/O operations };
vbDeviceCache::vbDeviceCache()
vbDeviceCache::~vbDeviceCache()
vbDeviceCache::IsOK()
vbDeviceCache::Read()
vbDeviceCache::ReadyForReading()
vbDeviceCache::ReadyForWriting()
vbDeviceCache::Write()
vbDeviceCache::vbDeviceCache()
- Default class constructor.virtual vbDeviceCache::~vbDeviceCache()
- Class destructor provided for virtuality. - Public member function used by the device cache classes to determine the status of an I/O device used by the derived class.virtual void vbDeviceCache::Read(void *buf, unsigned Bytes, vbDeviceTypes dev)
-Pure virtual member function used by the device cache classes to read a specified number of bytes from an input device. The "dev" variable is used to map the input device and must correspond to one of the integer constants defined in the vbDeviceTypes enumeration.int vbDeviceCache::ReadyForReading()
- Public member function used by the device cache classes to determine if an input device is ready for to be read.int vbDeviceCache::ReadyForWriting()
- Public member function used by the device cache classes to determine if an output device is can be written to.virtual void vbDeviceCache::Write(const void *buf, unsigned Bytes, vbDeviceTypes dev)
- Pure virtual member function used by the device cache classes to write a specified number of bytes to an output device. The "dev" variable is used to map the output device and must correspond to one of the integer constants defined in the vbDeviceTypes enumeration.vbDeviceBucketCache::vbDeviceBucketCache()
vbDeviceBucketCache::~vbDeviceBucketCache()
vbDeviceBucketCacheb::BucketsInUse()
vbDeviceBucketCacheb::Clear()
vbDeviceBucketCacheb::Connect()
vbDeviceBucketCacheb::Disconnect()
vbDeviceBucketCacheb::Flush()
vbDeviceBucketCacheb::GetBuckets()
vbDeviceBucketCacheb::GetHead()
vbDeviceBucketCacheb::ReserveBkt()
vbDeviceBucketCacheb::rFlush()
vbDeviceBucketCache::vbDeviceBucketCache(int n)
- Class constructor responsible for allocating "n" number of cache buckets and organizing the buckets in a circular doubly linked list.virtual vbDeviceBucketCache::~vbDeviceBucketCache()
- Class destructor responsible for flushing the cache and de-allocating the cache buckets.unsigned vbDeviceBucketCacheb::BucketsInUse()
- Public member function use to obtain the total number of cache buckets currently in use.void vbDeviceBucketCacheb::Clear()
- Public member function used to flush all the cache buckets and then null them out.void vbDeviceBucketCacheb::Connect(vbDeviceCache *dev)
- Public member function used to connect the cache to an I/O device. NOTE: This function will clear the cache if previously connected.void vbDeviceBucketCacheb::Disconnect()
- Public member function used to clear and disconnect the cache from a previously connected I/O device.int vbDeviceBucketCacheb::Flush(int empty_bkts = 0)
- Public member function used to flush all the buckets in the cache and null the buckets if "empty_bkts" variable is true. Will return a non-zero value if a bucket is being referenced by more then one cache pointer. Returns zero to indicate a successful flush operation.int vbDeviceBucketCacheb::GetBuckets()
- Public member function that returns the total number of cache buckets that have been allocated.vbDeviceBucketb *vbDeviceBucketCacheb::GetHead()
- Public member function that returns the head of the list. - Public member function used to reserve a cache bucket and pass back a pointer to the bucket or zero if an error occurred. If the "ensure_loaded" variable equals 1, the data will be read from the input device and loaded in the bucket. The "bytes" variable is used to set the length of the memory buffer the bucket is connected to during read operations. The "i_dev" and "o_dev" variables are used to map the I/O device and must correspond to one of the integer constants defined in the vbDeviceTypes enumeration.int vbDeviceBucketCacheb::rFlush(int empty_bkts = 0)
- Public member function used to flush all the cache buckets in reverse order and null the buckets if "empty_bkts" variable is true. Will return a non-zero value if a bucket is being referenced by more then one cache pointer. Returns zero to indicate a successful reverse flush operation.Device Cache Pointer Functions
vbDeviceCachePtr::vbDeviceCachePtr()
vbDeviceCachePtr::Alloc()
vbDeviceBucket &vbDeviceCachePtr::operator*()
vbDeviceBucket *vbDeviceCachePtr::operator->()
vbDeviceCachePtrb::GetInputDevice()
vbDeviceCachePtrb::GetOutputDevice()
vbDeviceCachePtrb::Grab()
vbDeviceCachePtrb::Release()
vbDeviceCachePtrb::SetInputDevice()
vbDeviceCachePtrb::SetOutputDevice()
vbDeviceCachePtr::vbDeviceCachePtr(vbDeviceBucketCache &c, vbDeviceTypes o_dev,vbDeviceTypes i_dev)
- Class constructor used to connect the pointer to a previously constructed cache. The "i_dev" and "o_dev" variables are used to map the I/O device and must correspond to one of the integer constants defined in the vbDeviceTypes enumeration.MBTYPE *vbDeviceCachePtr::Alloc()
- Public member function used to reserve a cache bucket for this cache pointer without loading any data in the cache bucket. The calling function must load the bucket after this function reserves the bucket. The "MBTYPE" type definition is set by one of the Device Cache conditional directives.MBTYPE *vbDeviceCachePtr::Alloc(unsigned bytes)
- Public member function used to reserve a cache bucket for this cache pointer and automatically load a specified number of bytes into the bucket from the input device the bucket is connected to. The "MBTYPE" type definition is set by one of the Device Cache conditional directives.vbDeviceBucket &vbDeviceCachePtr::operator*()
- Overloaded indirection operator used to dereference cache pointers like ordinary pointers.vbDeviceBucket *vbDeviceCachePtr::operator->()
- Overloaded arrow operator used to reference cache pointers like ordinary pointers.vbDeviceTypes vbDeviceCachePtrb::GetInputDevice()
- Public member function used to retrieve the current input device. Returns an integer constant defined in the vbDeviceTypes enumeration.vbDeviceTypes vbDeviceCachePtrb::GetOutputDevice()
- Public member function used to retrieve the current output device. Returns an integer constant defined in the vbDeviceTypes enumeration.void vbDeviceCachePtrb::Grab()
- Public member function used to bind a cache pointer to a bucket.void vbDeviceCachePtrb::Release()
- Public member function used to unbind a cache pointer from a bucket.void vbDeviceCachePtrb::SetInputDevice(vbDeviceTypes dev)
- Public member function used to set the input device. The "dev" variable is used to set the input device and must correspond to one of the integer constants defined in the vbDeviceTypes enumeration.void vbDeviceCachePtrb::SetOutputDevice(vbDeviceTypes dev)
- Public member function used to set the output device. The "dev" variable is used to set the output device and must correspond to one of the integer constants defined in the vbDeviceTypes enumeration.
End Of Document |