Cleanup ACE_HAS_PTHREAD_SIGMASK_PROTOTYPE, all platforms support it so far as I can...
[ACE_TAO.git] / TAO / examples / Content_Server / AMI_Observer / Callback_Handler.h
blob7166c1fc5cbed55872a51aba35b7e3b12af6af55
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Callback_Handler.h
7 * Header file for the Web_Server::AMI_CallbackHandler
8 * implementation.
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)
23 # pragma once
24 #endif /* ACE_LACKS_PRAGMA_ONCE */
26 class Callback_Handler
27 : public virtual POA_Web_Server::AMI_CallbackHandler
29 // = TITLE
30 // Class that asynchronously sends chunks of data to the
31 // client-side <Callback> object, and handles all asynchronous
32 // replies emanating from it.
34 // = DESCRIPTION
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;
68 public:
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 *);
79 /**
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.
85 void run ();
87 private:
88 /// Destructor (private to ensure that Callback_Handler is allocated
89 /// on the heap).
90 ~Callback_Handler ();
92 /// Open the file to be uploaded to the client callback.
93 void open_file ();
95 /// Deactivate this reply handler.
96 void deactivate ();
98 private:
99 /// The Addr corresponding to the retrieved file.
100 ACE_FILE_Addr 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
107 /// web server.
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.
122 int last_chunk_;
125 #endif /* CALLBACK_HANDLER_H */