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_i.h
blob4ea944f7467e67e2478f55088c1c55b541002aee
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Callback_i.h
7 * Header file for the Web_Server::Callback implementation.
9 * @author Ossama Othman <ossama@uci.edu>
11 //=============================================================================
14 #ifndef CALLBACK_I_H
15 #define CALLBACK_I_H
17 #include "ace/FILE_Addr.h"
18 #include "ace/FILE_IO.h"
19 #include "Push_Web_ServerS.h"
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 # pragma once
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 // Implement the Web_Server::Callback interface.
26 class Callback_i :
27 public virtual POA_Web_Server::Callback
29 // = TITLE
30 // Implement the Web_Server::Callback interface.
32 // = DESCRIPTION
33 // A <Callback> object implements the Observer pattern. It
34 // simply "watches" while the Content Server pushes chunks of
35 // data to itself. Once the Content Server pushes the last chunk
36 // of data, the <Callback> object spawns an external viewer to
37 // display the pushed data based on the data content type
38 // returned by the Iterator_Factory::register_callback() method.
40 // Since the server pushes data to the <Callback> object
41 // asynchronously, and since instances of this <Callback> class
42 // are registered with the Content Server asynchronously, there
43 // is no guarantee that the metadata containing the content type
44 // will arrive before the content of the file. As such, this
45 // class atomically sets and checks the flags that provide the
46 // current condition of the metadata and content, in case two
47 // concurrently running threads attempt to update the state
48 // contained within a given <Callback> object.
50 /// Dummy friend class declaration to quiet down a warning.
51 friend class Callback_i_Friend;
53 public:
54 /// Constructor
55 Callback_i (int *request_count);
57 /// This operation returns the next <chunk> of the file starting at
58 /// <offset>. If there are no more bindings, false is returned.
59 virtual void next_chunk (const Web_Server::Chunk_Type &chunk,
60 CORBA::Boolean last_chunk);
62 /// Set metadata associated with received data.
63 void metadata (const Web_Server::Metadata_Type &metadata);
65 private:
66 /// Destructor must be private to ensure that this object is
67 /// allocated on the heap.
68 ~Callback_i ();
70 /// Returns one if the metadata was received, and zero otherwise.
71 int metadata_received ();
73 /// Returns one if the entire content was received, and zero
74 /// otherwise.
75 int content_received ();
77 /// Get the name of the viewer associated with the file being
78 /// retrieved.
79 int get_viewer (char *viewer, size_t length);
81 /// Spawn an external view to display the retrieved file.
82 int spawn_viewer ();
84 private:
85 /// Deactivate this Callback servant.
86 void deactivate ();
88 private:
89 /// The Addr corresponding to the retrieved file.
90 ACE_FILE_Addr file_;
92 /// The object that provides all file related IO operations
93 /// (e.g. read, write, etc).
94 ACE_FILE_IO file_io_;
96 /// Reference to this Reply Handler's self.
97 Web_Server::AMI_CallbackHandler_var ami_handler_;
99 /// The metadata associated with the file being retrieved from the
100 /// web server.
101 Web_Server::Metadata_Type metadata_;
103 /// Flag that indicates entire data content has been received.
104 int last_chunk_;
106 /// Lock used to prevent race conditions when checking to see if
107 /// metadata or entire content has been received.
108 TAO_SYNCH_MUTEX lock_;
111 * Pointer to external status monitoring variable. The contents (not
112 * the pointer itself) of the <pending_data> parameter will be
113 * decremented when file retrieval has completed.
115 int *request_count_;
118 #endif /* CALLBACK_I_H */