From a5fdebc5f6375078ec1763850a4ca23ec7fe6458 Mon Sep 17 00:00:00 2001 From: levine Date: Mon, 21 Oct 1996 21:41:34 +0000 Subject: Initial revision --- ace/Stream.h | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 ace/Stream.h (limited to 'ace/Stream.h') diff --git a/ace/Stream.h b/ace/Stream.h new file mode 100644 index 00000000000..0eeac5fc837 --- /dev/null +++ b/ace/Stream.h @@ -0,0 +1,185 @@ +/* -*- C++ -*- */ +// $Id$ + + +// ============================================================================ +// +// = LIBRARY +// ace +// +// = FILENAME +// Stream.h +// +// = AUTHOR +// Doug Schmidt +// +// ============================================================================ + +#if !defined (ACE_STREAM_H) +#define ACE_STREAM_H + +//#include "ace/Multiplexor.h" + +#include "ace/ACE.h" +#include "ace/IO_Cntl_Msg.h" +#include "ace/Message_Block.h" +#include "ace/Time_Value.h" +#include "ace/Module.h" + +// Forward decls. +template class ACE_Stream_Iterator; +//template class ACE_Module; + +template +class ACE_Stream + // = TITLE + // This class is the primary abstraction for the ASX framework. + // It is moduled after System V Stream. + // + // = DESCRIPTION + // A Stream consists of a stack of , each of which + // contains two . +{ +friend class ACE_Stream_Iterator; +public: + enum + { + M_DELETE = 1 + // Indicates that close() deletes the Tasks. Don't change this + // value without updating the same enum in class ACE_Module... + }; + + // = Initializatation and termination methods. + ACE_Stream (void *arg = 0, + ACE_Module *head = 0, + ACE_Module *tail = 0); + // Create a Stream consisting of and as the Stream + // head and Stream tail, respectively. If these are 0 then the + // and are used, respectively. + // is the value past in to the open() methods of the tasks. + + int open (void *arg, + ACE_Module *head = 0, + ACE_Module *tail = 0); + // Create a Stream consisting of and as the Stream + // head and Stream tail, respectively. If these are 0 then the + // and are used, respectively. + // is the value past in to the open() methods of the tasks. + + int close (u_long flags = M_DELETE); + // Close down the stream and release all the resources. + + ~ACE_Stream (void); + // Close down the stream and release all the resources. + + // = ACE_Stream plumbing operations + + int push (ACE_Module *mod); + // Add a new module right below the Stream head. + + int pop (u_long flags = M_DELETE); + // Remove the right below the Stream head and close it down. + + int top (ACE_Module *&mod); + // Return the top module on the stream (right below the stream + // head). + + int remove (const char *mod, u_long flags = M_DELETE); + // Remove the named module from the stream. This bypasses the + // strict LIFO ordering of push() and pop(). + + ACE_Module *head (void); + // Return current stream head. + + ACE_Module *tail (void); + // Return current stream tail. + + ACE_Module *find (const char *mod); + // Find a particular ACE_Module. + + int link (ACE_Stream &); + // Create a pipe between two Streams. + + int unlink (void); + // Remove a pipe formed between two Streams. + + // = Blocking data transfer operations + int put (ACE_Message_Block *mb, ACE_Time_Value *timeout); + // Send the message down the stream, starting at the Module + // below the Stream head. Wait for upto amount of time + // for the operation to complete (or block forever if == + // 0). + + int get (ACE_Message_Block *&mb, ACE_Time_Value *timeout); + // Read the message that is stored in the the stream head. + // Wait for upto amount of time for the operation to + // complete (or block forever if == 0). + + int control (ACE_IO_Cntl_Msg::ACE_IO_Cntl_Cmds cmd, void *args); + // Send control message down the stream. + + int wait (void); + // Synchronize with the final close of the stream. + + void dump (void) const; + // Dump the state of an object. + + ACE_ALLOC_HOOK_DECLARE; + // Declare the dynamic allocation hooks. + +private: + int unlink_i (void); + // Actually perform the unlinking of two Streams (must be called + // with locks held). + + int link_i (ACE_Stream &); + // Actually perform the linking of two Streams (must be called with + // locks held). + + int push_module (ACE_Module *, + ACE_Module * = 0, + ACE_Module * = 0); + // Must a new module onto the Stream. + + ACE_Module *stream_head_; + // Pointer to the head of the stream. + + ACE_Module *stream_tail_; + // Pointer to the tail of the stream. + + ACE_Stream *linked_us_; + // Pointer to an adjoining linked stream. + + // = Synchronization objects used for thread-safe streams. + ACE_SYNCH_MUTEX lock_; + // Protect the stream against race conditions. + + ACE_SYNCH_CONDITION final_close_; + // Use to tell all threads waiting on the close that we are done. +}; + +template +class ACE_Stream_Iterator +{ +public: + ACE_Stream_Iterator (const ACE_Stream &sr); + int next (const ACE_Module *&mo); + int advance (void); + +private: + ACE_Module *next_; +}; + +#if defined (__ACE_INLINE__) +#include "ace/Stream.i" +#endif /* __ACE_INLINE__ */ + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "ace/Stream.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("Stream.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#endif /* ACE_STREAM_H */ -- cgit v1.2.1