3 //=============================================================================
5 * @file Callback_Handler.h
7 * Header file for the Web_Server::AMI_CallbackHandler
10 * @author Ossama Othman <ossama@uci.edu>
12 //=============================================================================
15 #ifndef CALLBACK_HANDLER_H
16 #define CALLBACK_HANDLER_H
18 #include "ace/FILE_Addr.h"
19 #include "ace/FILE_IO.h"
20 #include "Push_Web_ServerS.h"
22 #if !defined (ACE_LACKS_PRAGMA_ONCE)
24 #endif /* ACE_LACKS_PRAGMA_ONCE */
26 class Callback_Handler
27 : public virtual POA_Web_Server::AMI_CallbackHandler
30 // Class that asynchronously sends chunks of data to the
31 // client-side <Callback> object, and handles all asynchronous
32 // replies emanating from it.
35 // The <Push_Iterator_Factory_i> object in the Content Server
36 // creates a <Callback_Handler> instance for each requested file,
37 // and executes the run() method in that instance (in this
38 // class). To allow the Content Server to service other requests
39 // without having to wait for the requested file to be completely
40 // sent to the client, the run() method in this class issues the
41 // next_chunk() method, which reads the first chunk of data and
42 // sends it asynchronously to the client-side <Callback> object
43 // by issuing a sendc_next_chunk() call.
45 // This may seem a bit odd since the next_chunk() method in this
46 // class is actually the reply handler method for the
47 // sendc_next_chunk() method. The next_chunk() method is
48 // initially invoked as a means to bootstrap the process of
49 // asynchronously sending chunks of data to the client-side
50 // <Callback> object. However, since the next_chunk() method
51 // actually invokes sendc_next_chunk(), all subsequent calls will
52 // be performed asynchronously. This design also guarantees that
53 // the client-side <Callback> object will receive all chunks of
54 // data in the proper order since the next chunk of data will not
55 // be sent until this <Callback_Handler> receives the asynchronous
56 // reply from the client-side <Callback> object. Again, that
57 // asynchronous reply is handled by the next_chunk() method, at
58 // which point the entire cycle is started again until the last
59 // chunk of data is sent.
61 // Notice that no threads are explicitly created at the
62 // application level, yet concurrency is achieved due to the fact
63 // that all operations are performed asynchronously.
65 /// Dummy friend class declaration to quiet down a warning.
66 friend class Callback_Handler_Friend
;
69 /// Constructor that creates a content iterator corresponding to the
70 /// name of the file being retrieved from the web server.
71 Callback_Handler (const char *pathname
,
72 Web_Server::Callback_ptr callback
);
74 /// The callback for this reply handler.
75 virtual void next_chunk ();
77 virtual void next_chunk_excep (::Messaging::ExceptionHolder
*);
80 * Activate and run this Reply Handler. The contents (not the
81 * pointer itself) of the <request_count> parameter will be
82 * incremented when file retrieval begins, and decremented when file
83 * retrieval completes.
88 /// Destructor (private to ensure that Callback_Handler is allocated
92 /// Open the file to be uploaded to the client callback.
95 /// Deactivate this reply handler.
99 /// The Addr corresponding to the retrieved file.
102 /// The object that provides all file related IO operations
103 /// (e.g. read, write, etc).
104 ACE_FILE_IO file_io_
;
106 /// The iterator used to obtain individual chunks of data from the
108 Web_Server::Callback_var callback_
;
110 /// Reference to this Reply Handler's self.
111 Web_Server::AMI_CallbackHandler_var ami_handler_
;
113 /// The chunk of data that is sent to the client callback during each
114 /// callback invocation.
115 Web_Server::Chunk_Type_var chunk_
;
117 /// The number of the current chunk of data being sent. (Used only
118 /// for debugging purposes.)
119 CORBA::ULong chunk_index_
;
121 /// Flag that indicates all chunks of data have been sent.
125 #endif /* CALLBACK_HANDLER_H */