This queue is designed to be used with character sources such as a serial port, or a IrDA port. There is only one interface so that the queue can be added between the character source and the using code at any time, even after the code is debugged. All that is added is a buffer queue.
Although it would not be difficult to make the length of the array variable, I chose not to for this implementation. There are some advantages to this approach, particularly in a system which has limited memory and no memory compaction algorithm (such as Windows CE). Under these conditions, if a variable size queue were used, then the queue memory would have to be allocated dynamically, which could fragment the memory. In some cases, this fragmentation has cause CE devices to fail after a period of time.
I wrote the interface description in the interface definition language supplied by Microsoft. This has the advantage of being able to generate the header files, etc. automatically. While I added comments to this file to indicate what is going on, this file will add more detailed comments.
This is intended documentation for the interface to the queue only, not to the implementation. The person reading this document should be able to write code to use the queue, but does not need to understand the circular queue mechanism that is used to implement the queue. In fact, I might write some other implementations against this same interface in the future it I feel inspired.
The queue object is created as any other COM object is created. There may be any number of instances of queues in existance at any time. The Class Identifier for the object is "AFB0FF7B-487E-11D6-A9A4-00606772164E".
If I write other implementations in the future, they will have different class identifiers.
In order to be a queue object, the IGet interface must be exported. In addition, this implemention exports the IQueue interface. The former is a general interface that allow serial communication. The latter exports methods that are particular to the circular implementation, such as a test to see how many characters are free in the queue. (In a linked implementation, this would have no meaning.)
The IGet interface exports all the methods which are needed for serial communication. Any use of the queue implemented here has to have an implementation of the IGet interface. (As the test program demonstrates, however, this interface does not have to be part of a COM object.)
There are five methods: Get, Available, Clear, Interrupt, and Used. Get is used to actually get data. Available is used to wait until the number of characters desired becomes available. Clear is used to clear all characters currently coming down the serial channel. Interrupt is used to cause the Get or Available methods (which can wait) to return immediately. Used is used to find out how many characters are in the queue. It is really equivilent to setting the time out time to zero, and the length argument to a very large value in Available.
Last Updated September 06, 2009. Queue index page