diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-11-10 21:33:25 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-11-10 21:33:25 +0000 |
commit | 8957225d74555060d1a83a4c240f1e602cc82d4a (patch) | |
tree | fc8c311055b97bfa1b5d2efbbd68d8705481660d | |
parent | 922a655a3a371b2d749f59761843297c408a9d1a (diff) | |
download | ATCD-8957225d74555060d1a83a4c240f1e602cc82d4a.tar.gz |
.
43 files changed, 3455 insertions, 3 deletions
diff --git a/docs/ACE-tutorials.html b/docs/ACE-tutorials.html index 9c48f67409b..26177ced78d 100644 --- a/docs/ACE-tutorials.html +++ b/docs/ACE-tutorials.html @@ -21,14 +21,21 @@ ACE programmers guide <A HREF="http://www.cs.wustl.edu/~schmidt/PDF/ACE-tutorial.pdf.gz">[pdf]</A><A HREF="http://www.cs.wustl.edu/~schmidt/ACE-tutorial.ps.gz">[ps]</A> <DT> <img alt="o" src="http://www.cs.wustl.edu/~schmidt/gifs/misc/redball.gif"> - <A HREF="http://www.cs.wustl.edu/~schmidt/ACE_wrappers/docs/tutorials/">Introductory online tutorials</A> + <A + HREF="http://www.cs.wustl.edu/~schmidt/ACE_wrappers/docs/tutorials/guide-tutorials.html">Online examples from the ACE programmers guide</A> <DT> <img alt="o" src="http://www.cs.wustl.edu/~schmidt/gifs/misc/redball.gif"> - <A HREF="http://www.cs.wustl.edu/~schmidt/ACE_wrappers/docs/tutorials/new-tutorials.html">Developing New Tutorials</A> + <A + HREF="http://www.cs.wustl.edu/~schmidt/ACE_wrappers/docs/tutorials/online-tutorials.html">Introductory online ACE tutorials</A> + + <DT> <img alt="o" src="http://www.cs.wustl.edu/~schmidt/gifs/misc/redball.gif"> + <A HREF="http://www.cs.wustl.edu/~schmidt/ACE_wrappers/docs/tutorials/new-tutorials.html">Developing new tutorials</A> <!-- Bob's original can always be found at: http://dox.netwrench.com/acedox/fmm/ --> <DT> <img alt="o" src="http://www.cs.wustl.edu/~schmidt/gifs/misc/redball.gif"> - <A HREF="http://www.cs.wustl.edu/~schmidt/ACE_wrappers/docs/ACE-FMM.html">Frequently Made Mistakes (FMM)</A> + <A + HREF="http://www.cs.wustl.edu/~schmidt/ACE_wrappers/docs/ACE-FMM.html">ACE +``frequently made mistakes'' (FMM)</A> </DL> </TD> diff --git a/docs/tutorials/Chap_2/Chap_2.zip b/docs/tutorials/Chap_2/Chap_2.zip Binary files differnew file mode 100644 index 00000000000..e9201ef1925 --- /dev/null +++ b/docs/tutorials/Chap_2/Chap_2.zip diff --git a/docs/tutorials/Chap_2/ex01.html b/docs/tutorials/Chap_2/ex01.html new file mode 100644 index 00000000000..0de2788c3cf --- /dev/null +++ b/docs/tutorials/Chap_2/ex01.html @@ -0,0 +1,106 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "IPC SAP" (Interprocess Communication +Mechanisms in ACE).</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#FF0000">//Example 1</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/SOCK_Acceptor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/SOCK_Stream.h"</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">SIZE_DATA +18</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">SIZE_BUF +1024</FONT> + +<P>class Server{ + +<P>public: +<BR>Server (int port): +<BR> server_addr_(port),peer_acceptor_(server_addr_){ +<BR> data_buf_= new char[SIZE_BUF]; +<BR> } + +<P><FONT COLOR="#FF0000">//Handle the connection once it has been established.</FONT> +<BR><FONT COLOR="#FF0000">//Here the connection is handled by reading SIZE_DATA +amount of data</FONT> +<BR><FONT COLOR="#FF0000">//from the remote and then closing the connection</FONT> +<BR><FONT COLOR="#FF0000">//stream down.</FONT> +<BR>int handle_connection(){ +<BR> <FONT COLOR="#FF0000"> // Read data from client</FONT> +<BR> if(new_stream_.recv_n (data_buf_, SIZE_DATA, 0)==-1) +<BR> ACE_ERROR ((LM_ERROR, "%p\n", "Error in recv")); +<BR> + +<P> ACE_DEBUG((LM_DEBUG,"Server recieved %s \n",data_buf_)); +<BR> +<BR> <FONT COLOR="#FF0000">// Close new endpoint</FONT> +<BR> if (new_stream_.close () == -1) +<BR> ACE_ERROR ((LM_ERROR, "%p\n", "close")); +<BR> return 0; +<BR>} +<BR><FONT COLOR="#FF0000">//Use the acceptor component peer_acceptor_ to +accept the connection</FONT> +<BR><FONT COLOR="#FF0000">//into the underlying stream new_stream_. After +the connection has been</FONT> +<BR><FONT COLOR="#FF0000">//established call the handle_connenction() method.</FONT> +<BR>int accept_connections (){ +<BR> if (peer_acceptor_.get_local_addr (server_addr_) == -1) +<BR> ACE_ERROR_RETURN ((LM_ERROR,"%p\n","Error in get_local_addr"),1); + +<P> ACE_DEBUG ((LM_DEBUG,"Starting server at port %d\n", +<BR> server_addr_.get_port_number ())); +<BR> + +<P> <FONT COLOR="#FF0000">// Performs the iterative server activities.</FONT> +<BR> while(1){ +<BR> ACE_Time_Value timeout (ACE_DEFAULT_TIMEOUT); +<BR> if (peer_acceptor_.accept +<BR> (new_stream_, &client_addr_, &timeout)== +-1){ +<BR> ACE_ERROR ((LM_ERROR, "%p\n", "accept")); +<BR> continue; +<BR> } +<BR> else +<BR> ACE_DEBUG((LM_DEBUG, +<BR> "Connection established with remote %s:%d\n", +<BR> client_addr_.get_host_name(),client_addr_.get_port_number())); +<BR> <FONT COLOR="#FF0000">//Handle the connection</FONT> +<BR> handle_connection(); +<BR> } +<BR> } +<BR> +<BR> + +<P>private: +<BR> char *data_buf_; +<BR> ACE_INET_Addr server_addr_; +<BR> ACE_INET_Addr client_addr_; +<BR> ACE_SOCK_Acceptor peer_acceptor_; +<BR> ACE_SOCK_Stream new_stream_; +<BR> ACE_HANDLE newhandle; +<BR>}; + +<P>int main (int argc, char *argv[]){ +<BR> if(argc<2){ +<BR> ACE_ERROR((LM_ERROR,"Usage egX <port_num>")); +<BR> ACE_OS::exit(1); +<BR> } +<BR> Server server(ACE_OS::atoi(argv[1])); +<BR> server.accept_connections(); +<BR>} + +<P> <A HREF="ex02.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_2/ex02.html b/docs/tutorials/Chap_2/ex02.html new file mode 100644 index 00000000000..69891f26f1e --- /dev/null +++ b/docs/tutorials/Chap_2/ex02.html @@ -0,0 +1,95 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 2</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "IPC SAP" (Interprocess +Communication Mechanisms in ACE).</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT><FONT COLOR="#FF0000"></FONT> + +<P><FONT COLOR="#FF0000">//</FONT><FONT COLOR="#CC0000">Example 2</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/SOCK_Connector.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/INET_Addr.h"</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">SIZE_BUF +128</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">NO_ITERATIONS +5</FONT> + +<P>class Client{ +<BR>public: +<BR>Client(char *hostname, int port):remote_addr_(hostname){ +<BR> remote_addr_.set_port_number(port); +<BR> data_buf_=new char[SIZE_BUF]; +<BR> } + +<P><FONT COLOR="#FF0000">//Uses a connector component connector_ to connect +to a remote machine</FONT> +<BR><FONT COLOR="#FF0000">//and pass the connection into a stream component +client_stream_</FONT> +<BR>int connect_to_server(){ +<BR> <FONT COLOR="#FF0000">// Initiate blocking connection with server.</FONT> +<BR> ACE_DEBUG ((LM_DEBUG, "(%P|%t) Starting connect to %s:%d\n", +<BR> remote_addr_.get_host_name(),remote_addr_.get_port_number())); +<BR> if (connector_.connect (client_stream_, remote_addr_) == -1) +<BR> ACE_ERROR_RETURN ((LM_ERROR,"(%P|%t) %p\n","connection +failed"),-1); +<BR> else +<BR> ACE_DEBUG ((LM_DEBUG,"(%P|%t) connected to %s\n", +<BR> remote_addr_.get_host_name ())); +<BR> return 0; +<BR> } + +<P><FONT COLOR="#FF0000">//Uses a stream component to send data to the +remote host.</FONT> +<BR>int send_to_server(){ +<BR> <FONT COLOR="#FF0000"> // Send data to server</FONT> +<BR> ACE_OS::sprintf(data_buf_,"Hello from Client"); +<BR> for(int i=0;i<NO_ITERATIONS; i++){ +<BR> if (client_stream_.send_n +<BR> (data_buf_, ACE_OS::strlen(data_buf_), 0) == -1){ +<BR> ACE_ERROR_RETURN ((LM_ERROR,"(%P|%t) %p\n","send_n"),0); +<BR> break; +<BR> } +<BR> } +<BR> <FONT COLOR="#FF0000">//Close down the connection</FONT> +<BR> close(); +<BR>} + +<P><FONT COLOR="#FF0000">//Close down the connection properly.</FONT> +<BR>int close(){ +<BR> if (client_stream_.close () == -1) +<BR> ACE_ERROR_RETURN ((LM_ERROR,"(%P|%t) %p\n","close"),-1); +<BR> else +<BR> return 0; +<BR> } + +<P>private: +<BR> ACE_SOCK_Stream client_stream_; +<BR> ACE_INET_Addr remote_addr_; +<BR> ACE_SOCK_Connector connector_; +<BR> char *data_buf_; +<BR>}; + +<P>int main (int argc, char *argv[]){ +<BR> if(argc<3){ +<BR> ACE_DEBUG((LM_DEBUG,?Usage egX <hostname> <port_number>\n?)); +<BR> ACE_OS::exit(1); +<BR> } +<BR> Client client(argv[1],ACE_OS::atoi(argv[2])); +<BR> client.connect_to_server(); +<BR> client.send_to_server(); +<BR>} + +<P> <A HREF="ex03.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_2/ex03.html b/docs/tutorials/Chap_2/ex03.html new file mode 100644 index 00000000000..838eedcc81c --- /dev/null +++ b/docs/tutorials/Chap_2/ex03.html @@ -0,0 +1,81 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 3</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "IPC SAP" (Interprocess +Communication Mechanisms in ACE).</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT><FONT COLOR="#FF0000"></FONT> + +<P><FONT COLOR="#CC0000">// Example 3</FONT><FONT COLOR="#FF0000"></FONT> + +<P><FONT COLOR="#FF0000">//Server</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/OS.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/SOCK_Dgram.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/INET_Addr.h"</FONT> + +<P><FONT COLOR="#000099">#define </FONT><FONT COLOR="#663366">DATA_BUFFER_SIZE +1024</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">SIZE_DATA +18</FONT> + +<P>class Server{ +<BR>public: +<BR>Server(int local_port) +<BR> :local_addr_(local_port),local_(local_addr_){ +<BR> data_buf = new char[DATA_BUFFER_SIZE]; +<BR> } +<BR><FONT COLOR="#FF0000">//Expect data to arrive from the remote machine. +Accept it and display it.</FONT> +<BR><FONT COLOR="#FF0000">// After recieveing data immediately send some +data back to the remote.</FONT> +<BR>int accept_data(){ +<BR> while(local_.recv(data_buf,SIZE_DATA,remote_addr_)!=-1){ +<BR> ACE_DEBUG((LM_DEBUG, "Data received from remote %s was %s \n" +<BR> ,remote_addr_.get_host_name(), data_buf)); +<BR> ACE_OS::sleep(1); +<BR> if(send_data()==-1) break; +<BR> } +<BR> return -1; +<BR> } +<BR> +<BR> + +<P><FONT COLOR="#FF0000">//Method used to send data to the remote using +the datagram component local_</FONT> +<BR>int send_data(){ +<BR> ACE_DEBUG((LM_DEBUG,"Preparing to send reply to client %s:%d\n", +<BR> remote_addr_.get_host_name(),remote_addr_.get_port_number())); +<BR> ACE_OS::sprintf(data_buf,"Server says hello to you too"); +<BR> if( +<BR> local_.send(data_buf, ACE_OS::strlen(data_buf),remote_addr_)==-1) +<BR> return -1; +<BR> else +<BR> return 0; +<BR> } + +<P>private: +<BR> char *data_buf; +<BR> ACE_INET_Addr remote_addr_; +<BR> ACE_INET_Addr local_addr_; +<BR> ACE_SOCK_Dgram local_; +<BR>}; + +<P>int main(int argc, char *argv[]){ +<BR> Server server(ACE_OS::atoi(argv[1])); +<BR> server.accept_data(); +<BR>} + +<P> <A HREF="ex04.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_2/ex04.html b/docs/tutorials/Chap_2/ex04.html new file mode 100644 index 00000000000..41cf78188bd --- /dev/null +++ b/docs/tutorials/Chap_2/ex04.html @@ -0,0 +1,87 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 4</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "IPC SAP" (Interprocess Communication +Mechanisms in ACE).</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 4</FONT> +<BR><FONT COLOR="#FF0000">//Client</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/OS.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/SOCK_Dgram.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/INET_Addr.h"</FONT> + +<P><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">DATA_BUFFER_SIZE +1024</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">SIZE_DATA +28</FONT> +<BR>class Client{ +<BR>public: +<BR>Client(char * remote_addr,int port) +<BR> :remote_addr_(remote_addr), +<BR> local_addr_((u_short)0),local_(local_addr_){ +<BR> data_buf = new char[DATA_BUFFER_SIZE]; +<BR> remote_addr_.set_port_number(port); +<BR> } +<BR> +<BR><FONT COLOR="#FF0000">//Accept data from the remote host using the +datgram component local_</FONT> +<BR>int accept_data(){ +<BR> if(local_.recv(data_buf,SIZE_DATA,remote_addr_)!=-1){ +<BR> ACE_DEBUG((LM_DEBUG, "Data received from remote server %s +<BR> was: %s \n" ,remote_addr_.get_host_name(), +data_buf)); +<BR> return 0; +<BR> } +<BR> else +<BR> return -1; +<BR> } + +<P><FONT COLOR="#FF0000">//Send data to the remote. Once data has been +sent wait for a reply from</FONT> +<BR><FONT COLOR="#FF0000">//the server.</FONT> +<BR>int send_data(){ +<BR> ACE_DEBUG((LM_DEBUG,"Preparing to send data to server %s:%d\n", +<BR> remote_addr_.get_host_name(),remote_addr_.get_port_number())); +<BR> ACE_OS::sprintf(data_buf,"Client says hello"); +<BR> +<BR> while(local_.send +<BR> (data_buf,ACE_OS::strlen(data_buf),remote_addr_)!=-1){ +<BR> ACE_OS::sleep(1); +<BR> if(accept_data()==-1) +<BR> break; +<BR> } +<BR> return -1; +<BR> } + +<P>private: +<BR> char *data_buf; +<BR> ACE_INET_Addr remote_addr_; +<BR> ACE_INET_Addr local_addr_; +<BR> ACE_SOCK_Dgram local_; +<BR>}; + +<P>int main(int argc, char *argv[]){ +<BR>if(argc<3){ +<BR> ACE_OS::printf("Usage: Client hostname port_number \n"); +<BR> ACE_OS::exit(1); +<BR> } +<BR>Client client(argv[1],ACE_OS::atoi(argv[2])); +<BR>client.send_data(); +<BR>} +<BR> +<BR> <A HREF="ex05.htm">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_2/ex05.htm b/docs/tutorials/Chap_2/ex05.htm new file mode 100644 index 00000000000..1a88e7c8dbd --- /dev/null +++ b/docs/tutorials/Chap_2/ex05.htm @@ -0,0 +1,87 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 5</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "IPC SAP" (Interprocess Communication +Mechanisms in ACE).</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 5</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/SOCK_Dgram_Mcast.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/OS.h"</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">DEFAULT_MULTICAST_ADDR +"224.9.9.2"</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">TIMEOUT +5</FONT> + +<P>class Reciever_Multicast{ + +<P>public: +<BR>Reciever_Multicast(int port): +<BR> mcast_addr_(port,DEFAULT_MULTICAST_ADDR),remote_addr_((u_short)0){ +<BR> <FONT COLOR="#FF0000"> // Subscribe to multicast address.</FONT> +<BR> if (mcast_dgram_.subscribe (mcast_addr_) == -1){ +<BR> ACE_DEBUG((LM_DEBUG,"Error in subscribing to Multicast address +\n")); +<BR> exit(-1); +<BR> } +<BR>} + +<P>~Reciever_Multicast(){ +<BR> if(mcast_dgram_.unsubscribe()==-1) +<BR> ACE_DEBUG((LM_ERROR,?Error in unsubscribing from Mcast group\n?)); +<BR> } +<BR> +<BR> +<BR> + +<P><FONT COLOR="#FF0000">//Receive data from someone who is sending data +on the multicast group</FONT> +<BR><FONT COLOR="#FF0000">//address to do so it must use the multicast +datagram component</FONT> +<BR><FONT COLOR="#FF0000">//mcast_dgram_.</FONT> +<BR>int recv_multicast(){ +<BR><FONT COLOR="#FF0000"> //get ready to recieve data from the sender.</FONT> +<BR> if(mcast_dgram_.recv +<BR> (&mcast_info,sizeof (mcast_info),remote_addr_)==-1) +<BR> return -1; +<BR> ACE_DEBUG ((LM_DEBUG, "(%P|%t) Received multicast from %s:%d.\n", +<BR> remote_addr_.get_host_name(), remote_addr_.get_port_number())); +<BR> ACE_DEBUG((LM_DEBUG,"Successfully receieved %d\n", mcast_info)); +<BR> return 0; +<BR> } + +<P>private: +<BR> ACE_INET_Addr mcast_addr_; +<BR> ACE_INET_Addr remote_addr_; +<BR> ACE_SOCK_Dgram_Mcast mcast_dgram_; +<BR> int mcast_info; +<BR>}; +<BR> +<BR> +<BR>int main(int argc, char*argv[]){ +<BR> Reciever_Multicast m(2000); +<BR> <FONT COLOR="#FF0000">//Will run forever</FONT> +<BR> while(m.recv_multicast()!=-1) { +<BR> ACE_DEBUG((LM_DEBUG,"Multicaster succesful \n")); +<BR> } +<BR> +<BR> ACE_DEBUG((LM_ERROR,"Multicaster failed \n")); +<BR> exit(-1); +<BR>} + +<P> <A HREF="ex06.html">Next Example</A> +<BR> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_2/ex06.html b/docs/tutorials/Chap_2/ex06.html new file mode 100644 index 00000000000..94f40443766 --- /dev/null +++ b/docs/tutorials/Chap_2/ex06.html @@ -0,0 +1,76 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 6</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "IPC SAP" (Interprocess Communication +Mechanisms in ACE).</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 6</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">DEFAULT_MULTICAST_ADDR +"224.9.9.2"</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">TIMEOUT +5</FONT> +<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/SOCK_Dgram_Mcast.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/OS.h"</FONT> + +<P>class Sender_Multicast{ +<BR>public: +<BR>Sender_Multicast(int port): +<BR> local_addr_((u_short)0),dgram_(local_addr_), +<BR> multicast_addr_(port,DEFAULT_MULTICAST_ADDR){} + +<P><FONT COLOR="#FF0000">//Method which uses a simple datagram component +to send data to the multicast group.</FONT> +<BR>int send_to_multicast_group(){ +<BR> <FONT COLOR="#FF0000">//Convert the information we wish +to send into network byte order</FONT> +<BR> mcast_info= htons (1000); + +<P><FONT COLOR="#FF0000"> // Send multicast</FONT> +<BR> if(dgram_.send +<BR> (&mcast_info, sizeof (mcast_info), multicast_addr_)==-1) +<BR> return -1; + +<P> ACE_DEBUG ((LM_DEBUG, +<BR> +"%s; Sent multicast to group. Number sent is %d.\n", +<BR> +__FILE__, +<BR> +mcast_info)); +<BR> return 0; +<BR>} + +<P>private: +<BR> ACE_INET_Addr multicast_addr_; +<BR> ACE_INET_Addr local_addr_; +<BR> ACE_SOCK_Dgram dgram_; +<BR> int mcast_info; +<BR>}; +<BR> + +<P>int main(int argc, char*argv[]){ +<BR>Sender_Multicast m(2000); +<BR>if(m.send_to_multicast_group()==-1) { +<BR> ACE_DEBUG((LM_ERROR,"Send to Multicast group failed \n")); +<BR> exit(-1); +<BR> } +<BR>else +<BR> ACE_DEBUG((LM_DEBUG,"Send to Multicast group succesful \n")); +<BR>} + +<P> <A HREF="../Chap_3/ex01.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_3/Chap_3.zip b/docs/tutorials/Chap_3/Chap_3.zip Binary files differnew file mode 100644 index 00000000000..c99463d18d9 --- /dev/null +++ b/docs/tutorials/Chap_3/Chap_3.zip diff --git a/docs/tutorials/Chap_3/ex01.html b/docs/tutorials/Chap_3/ex01.html new file mode 100644 index 00000000000..a722e9a9b6d --- /dev/null +++ b/docs/tutorials/Chap_3/ex01.html @@ -0,0 +1,107 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 1</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "Memory Management"</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 1 </FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Malloc.h"</FONT> +<BR><FONT COLOR="#FF0000">//A chunk of size 1K is created</FONT> +<BR><FONT COLOR="#000099">typedef</FONT> <FONT COLOR="#993300">char</FONT><FONT COLOR="#666600"> +MEMORY_BLOCK[1024];</FONT> +<BR> +<BR> + +<P><FONT COLOR="#FF0000">//Create an ACE_Cached_Allocator which is passed +in the type of the</FONT> +<BR><FONT COLOR="#FF0000">//chunk that it must pre-allocate and assign +on the free</FONT> +<BR><FONT COLOR="#FF0000">//list</FONT> +<BR><FONT COLOR="#000000">typedef ACE_Cached_Allocator<MEMORY_BLOCK,ACE_SYNCH_MUTEX> +Allocator;</FONT> +<BR> +<BR>class MessageManager{ +<BR>public: +<BR><FONT COLOR="#FF0000">//The constructor is passed the number of chunks +that the allocator should pre-allocate //and maintain on its free list.</FONT> +<BR>MessageManager(int n_blocks): +<BR> allocator_(n_blocks),message_count_(0){} + +<P><FONT COLOR="#FF0000">//Allocate memory for a message using the Allocator</FONT> +<BR>void allocate_msg(const char *msg){ +<BR> mesg_array_[message_count_]= +<BR> (char*)allocator_.malloc(ACE_OS::strlen(msg)); +<BR> ACE_OS::strcpy(mesg_array_[message_count_],msg); +<BR> message_count_++; +<BR> } + +<P><FONT COLOR="#FF0000">//Free all memory allocated. This will cause the +chunks to be returned</FONT> +<BR><FONT COLOR="#FF0000">//to the allocators internal free list and NOT +to the OS.</FONT> +<BR>void free_all_msg(){ +<BR> for(int i=0;i<message_count_;i++) +<BR> allocator_.free(mesg_array_[i]); +<BR> message_count_=0; +<BR> } +<BR>void display_all_msg(){ +<BR> for(int i=0;i<message_count_;i++) +<BR> ACE_OS::printf("%s\n",mesg_array_[i]); +<BR> } +<BR> +<BR>private: +<BR> char *mesg_array_[20]; +<BR> Allocator allocator_; +<BR> int message_count_; +<BR>}; +<BR> + +<P>int main(int argc, char* argv[]){ + +<P>if(argc<2){ +<BR> ACE_OS::printf("Usage: egXX <Number of blocks>\n"); +<BR> exit(1); +<BR> } +<BR> +<BR><FONT COLOR="#FF0000">//Instatiate the Memory Manager class</FONT> +<BR>int n_blocks=ACE_OS::atoi(argv[1]); +<BR>MessageManager mm(n_blocks); +<BR> + +<P><FONT COLOR="#FF0000">//Use the Memory Manager class to assign messages +and free them.</FONT> <FONT COLOR="#FF0000">Run this in your</FONT> +<BR><FONT COLOR="#FF0000">//debug environment and you will notice that +//the</FONT> <FONT COLOR="#FF0000">amount of memory your program uses</FONT> +<BR><FONT COLOR="#FF0000">//after Memory Manager has been</FONT> <FONT COLOR="#FF0000">instantiated +remains the same. That means the</FONT> +<BR><FONT COLOR="#FF0000">//Cached Allocator</FONT> <FONT COLOR="#FF0000">controls +or manages all the memory for the application.</FONT> + +<P><FONT COLOR="#FF0000">//Do forever.</FONT> +<BR>while(1){ +<BR> <FONT COLOR="#FF0000">//allocate the messages somewhere</FONT> +<BR> for(int i=0; i<n_blocks;i++) +<BR> mm.allocate_msg("Hi there"); +<BR> <FONT COLOR="#FF0000">//show the messages</FONT> +<BR> mm.display_all_msg(); +<BR> +<BR> for( i=0;i<n_blocks;i++) +<BR> mm.free_all_msg(); +<BR> } +<BR>} + +<P> <A HREF="ex02.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_3/ex02.html b/docs/tutorials/Chap_3/ex02.html new file mode 100644 index 00000000000..b425bfb9565 --- /dev/null +++ b/docs/tutorials/Chap_3/ex02.html @@ -0,0 +1,135 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 2</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "Memory Management"</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 2</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Shared_Memory_MM.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Malloc.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Malloc_T.h"</FONT> +<BR><FONT COLOR="#000099">#define </FONT><FONT COLOR="#663366">DATA_SIZE +100</FONT> +<BR><FONT COLOR="#000099">#define</FONT><FONT COLOR="#663366"> MESSAGE1 +"Hiya over there client process"</FONT> +<BR><FONT COLOR="#000099">#define </FONT><FONT COLOR="#663366">MESSAGE2 +"Did you hear me the first time?"</FONT> +<BR>LPCTSTR poolname="My_Pool"; + +<P><FONT COLOR="#000000">typedef ACE_Malloc<ACE_SHARED_MEMORY_POOL,ACE_Null_Mutex> +Malloc_Allocator;</FONT> + +<P>static void +<BR>server (void){ +<BR> <FONT COLOR="#FF0000">//Create the memory allocator passing it +the shared memory</FONT> +<BR> <FONT COLOR="#FF0000">//pool that you want to use</FONT> +<BR> Malloc_Allocator shm_allocator(poolname); + +<P> <FONT COLOR="#FF0000">//Create a message, allocate memory for +it and bind it with</FONT> +<BR><FONT COLOR="#FF0000"> //a name so that the client can the find +it in the memory</FONT> +<BR><FONT COLOR="#FF0000"> //pool</FONT> +<BR> char* Message1=(char*)shm_allocator.malloc(strlen(MESSAGE1)); +<BR> ACE_OS::strcpy(Message1,MESSAGE1); +<BR> shm_allocator.bind("FirstMessage",Message1); +<BR> ACE_DEBUG((LM_DEBUG,"<<%s\n",Message1)); +<BR> +<BR><FONT COLOR="#FF0000"> //How about a second message</FONT> +<BR> char* Message2=(char*)shm_allocator.malloc(strlen(MESSAGE2)); +<BR> ACE_OS::strcpy(Message2,MESSAGE2); +<BR> shm_allocator.bind("SecondMessage",Message2); +<BR> ACE_DEBUG((LM_DEBUG,"<<%s\n",Message2)); +<BR> +<BR> <FONT COLOR="#FF0000">//Set the Server to go to sleep for a while +so that the client has</FONT> +<BR><FONT COLOR="#FF0000"> //a chance to do its stuff</FONT> +<BR> ACE_DEBUG((LM_DEBUG, +<BR> "Server done writing.. going to sleep zzz..\n\n\n")); +<BR> ACE_OS::sleep(2); +<BR> +<BR><FONT COLOR="#FF0000"> //Get rid of all resources allocated by +the server. In other</FONT> +<BR><FONT COLOR="#FF0000"> //words get rid of the shared memory pool +that had been</FONT> +<BR><FONT COLOR="#FF0000"> //previously allocated</FONT> +<BR> shm_allocator.remove(); +<BR> +<BR>} +<BR> + +<P>static void +<BR>client(void){ +<BR> <FONT COLOR="#FF0000">//Create a memory allocator. Be sure that +the client passes</FONT> +<BR><FONT COLOR="#FF0000"> // in the "right" name here so that both +the client and the</FONT> +<BR><FONT COLOR="#FF0000"> //server use the same memory pool. We wouldnt +want them to</FONT> +<BR><FONT COLOR="#FF0000"> // BOTH create different underlying pools.</FONT> +<BR> Malloc_Allocator shm_allocator(poolname); + +<P><FONT COLOR="#FF0000"> //Lets get that first message. Notice that +the find is looking up the</FONT> +<BR><FONT COLOR="#FF0000"> //memory based on the "name" that was bound +to it by the server.</FONT> +<BR> void *Message1; +<BR> if(shm_allocator.find("FirstMessage",Message1)==-1){ +<BR> ACE_ERROR((LM_ERROR, +<BR> "Client: Problem cant find data that server has +sent\n")); +<BR> ACE_OS::exit(1); +<BR> } +<BR> ACE_OS::printf(">>%s\n",(char*) Message1); +<BR> ACE_OS::fflush(stdout); + +<P> <FONT COLOR="#FF0000">//Lets get that second message now.</FONT> +<BR> void *Message2; +<BR> if(shm_allocator.find("SecondMessage",Message2)==-1){ +<BR> ACE_ERROR((LM_ERROR,"Client: Problem cant find data that server +has sent\n")); +<BR> ACE_OS::exit(1); +<BR> } +<BR> ACE_OS::printf(">>%s\n",(char*)Message2); +<BR> ACE_OS::fflush(stdout); + +<P> ACE_DEBUG((LM_DEBUG,"Client done reading! BYE NOW\n")); +<BR> ACE_OS::fflush(stdout); +<BR>} +<BR> + +<P>int main (int, char *[]){ +<BR>switch (ACE_OS::fork ()) +<BR> { +<BR> case -1: +<BR> ACE_ERROR_RETURN ((LM_ERROR, "%p\n", +"fork"), 1); +<BR> case 0: +<BR> <FONT COLOR="#FF0000"> // Make sure the +server starts up first.</FONT> +<BR> ACE_OS::sleep (1); +<BR> client (); +<BR> break; +<BR> default: +<BR> server (); +<BR> break; +<BR> } +<BR> return 0; +<BR>} +<BR> +<BR> <A HREF="../Chap_4/ex01.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_4/Chap_4.zip b/docs/tutorials/Chap_4/Chap_4.zip Binary files differnew file mode 100644 index 00000000000..b29059f1457 --- /dev/null +++ b/docs/tutorials/Chap_4/Chap_4.zip diff --git a/docs/tutorials/Chap_4/ex01.html b/docs/tutorials/Chap_4/ex01.html new file mode 100644 index 00000000000..00e8cb8f51d --- /dev/null +++ b/docs/tutorials/Chap_4/ex01.html @@ -0,0 +1,74 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 1</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "Thread Management"</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 1</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Thread.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/OS.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch_T.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Synch.h"</FONT> +<BR>static int number=0; +<BR>static int seed=0; + +<P>static void* +<BR>worker(void *arg){ +<BR> ACE_UNUSED_ARG(arg); +<BR> ACE_DEBUG((LM_DEBUG,"Thread (%t) Created to do some work")); +<BR> ::number++; +<BR> ACE_DEBUG((LM_DEBUG," and number is %d\n",::number)); +<BR> +<BR> <FONT COLOR="#FF0000">//Let the other guy go while I fall asleep +for a random period of time</FONT> +<BR> ACE_Thread::yield(); +<BR> ACE_OS::sleep(ACE_OS::rand()%2); + +<P><FONT COLOR="#FF0000"> //Exiting now</FONT> +<BR> ACE_DEBUG((LM_DEBUG, +<BR> "\t\t Thread (%t) Done! \t The number is now: %d\n",number)); +<BR> ACE_OS::fflush(stdout); +<BR> return 0; +<BR> } +<BR> + +<P>int main(int argc, char *argv[]){ +<BR>if(argc<2) +<BR> ACE_DEBUG((LM_DEBUG,"Usage: <program_name> <number of threads>\n")); +<BR> +<BR>int n_threads=ACE_OS::atoi(argv[1]); +<BR><FONT COLOR="#FF0000">//Setup the random number generator</FONT> +<BR>ACE_OS::srand(::seed); + +<P><FONT COLOR="#FF0000">//Spawn off n_threads number of threads</FONT> +<BR>for(int i=0; i<n_threads; i++){ +<BR> if(ACE_Thread::spawn((ACE_THR_FUNC)worker)==-1) +<BR> ACE_DEBUG((LM_DEBUG,"Error in spawning thread\n")); +<BR> } + +<P><FONT COLOR="#FF0000">//Wait for all the threads to exit before you +let the main fall through</FONT> +<BR><FONT COLOR="#FF0000">//and have the process exit. This way of using +join is non-portable</FONT> +<BR><FONT COLOR="#FF0000">//and may not work on a system using pthreads.</FONT> +<BR>int check_count=0; +<BR>while(ACE_Thread::join(NULL,NULL,NULL)==0) check_count++; +<BR>ACE_ASSERT(check_count==n_threads); +<BR>} + +<P> <A HREF="ex02.html">Next Example</A> +<BR> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_4/ex02.html b/docs/tutorials/Chap_4/ex02.html new file mode 100644 index 00000000000..4feefe6dbe5 --- /dev/null +++ b/docs/tutorials/Chap_4/ex02.html @@ -0,0 +1,67 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 2</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "Thread Management"</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 2</FONT> +<BR><FONT COLOR="#000099">#include </FONT><FONT COLOR="#006600">"ace/OS.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch.h"</FONT> + +<P><FONT COLOR="#FF0000">//Arguments that are to be passed to the worker +thread are passed through this class.</FONT> +<BR>class Args{ +<BR>public: +<BR>Args(int iterations): +<BR> mutex_(),iterations_(iterations){} +<BR>ACE_Thread_Mutex mutex_; +<BR>int iterations_; +<BR>}; + +<P><FONT COLOR="#FF0000">//The starting point for the worker threads</FONT> +<BR>static void* +<BR>worker(void*arguments){ +<BR>Args *arg= (Args*) arguments; +<BR>for(int i=0;i<arg->iterations_;i++){ +<BR> ACE_DEBUG((LM_DEBUG, +<BR> "(%t) Trying to get a hold of this iteration\n")); +<BR><FONT COLOR="#FF0000"> //This is our critical section</FONT> +<BR> arg->mutex_.acquire(); +<BR> ACE_DEBUG((LM_DEBUG,"(%t) This is iteration number %d\n",i)); +<BR><FONT COLOR="#FF0000"> //work</FONT> +<BR> ACE_OS::sleep(2); +<BR> arg->mutex_.release(); +<BR> } +<BR>return 0; +<BR>} + +<P>int main(int argc, char*argv[]){ +<BR>if(argc<2){ +<BR>ACE_OS::printf("Usage: egx <number_of_threads> +<BR> <number_of_iterations>\n"); +<BR> ACE_OS::exit(1); +<BR> } +<BR><FONT COLOR="#FF0000">//Setup the arguments</FONT> +<BR>Args arg(ACE_OS::atoi(argv[2])); + +<P>ACE_Thread::spawn_n +<BR> (ACE_OS::atoi(argv[1]),(ACE_THR_FUNC)worker,(void*)&arg); +<BR><FONT COLOR="#FF0000">//Spawn the worker threads</FONT> +<BR>while(ACE_Thread::join(NULL,NULL,NULL)==0); +<BR>} +<BR> +<BR> <A HREF="ex03.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_4/ex03.html b/docs/tutorials/Chap_4/ex03.html new file mode 100644 index 00000000000..56fbd9441aa --- /dev/null +++ b/docs/tutorials/Chap_4/ex03.html @@ -0,0 +1,78 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 3</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "Thread Management"</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 3</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/OS.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch_T.h"</FONT> + +<P><FONT COLOR="#FF0000">//Arguments that are to be passed to the worker +thread are passed through this class.</FONT> +<BR>class Args{ +<BR>public: +<BR>Args(ACE_Lock* lock,int iterations): +<BR> mutex_(lock),iterations_(iterations){} +<BR>ACE_Lock* mutex_; +<BR>int iterations_; +<BR>}; + +<P><FONT COLOR="#FF0000">//The starting point for the worker threads</FONT> +<BR>static void* +<BR>worker(void*arguments){ +<BR>Args *arg= (Args*) arguments; +<BR>for(int i=0;i<arg->iterations_;i++){ +<BR> ACE_DEBUG((LM_DEBUG, +<BR> "(%t) Trying to get a hold of this iteration\n")); +<BR><FONT COLOR="#FF0000"> //This is our critical section</FONT> +<BR> arg->mutex_->acquire(); +<BR> ACE_DEBUG((LM_DEBUG,"(%t) This is iteration number %d\n",i)); +<BR><FONT COLOR="#FF0000"> //work</FONT> +<BR> ACE_OS::sleep(2); +<BR> arg->mutex_->release(); +<BR> } +<BR>return 0; +<BR>} + +<P>int main(int argc, char*argv[]){ +<BR>if(argc<4){ +<BR> ACE_OS::printf("Usage: egx <number_of_threads> +<BR> <number_of_iterations> <lock_type>\n"); +<BR> ACE_OS::exit(1); +<BR> } +<BR><FONT COLOR="#FF0000">//Lock used by application</FONT> +<BR>ACE_Lock *lock; + +<P><FONT COLOR="#FF0000">//Decide which lock you want to use at run time. +Possible due to</FONT> +<BR><FONT COLOR="#FF0000">//ACE_Lock.</FONT> +<BR>if(ACE_OS::strcmp(argv[3],"Thread")) +<BR> lock=new ACE_Lock_Adapter<ACE_Thread_Mutex>; +<BR>else +<BR> lock=new ACE_Lock_Adapter<ACE_Mutex> + +<P><FONT COLOR="#FF0000">//Setup the arguments</FONT> +<BR>Args arg(lock,ACE_OS::atoi(argv[2])); +<BR><FONT COLOR="#FF0000">//Spawn the worker threads</FONT> +<BR>ACE_Thread::spawn_n +<BR> (ACE_OS::atoi(argv[1]),(ACE_THR_FUNC)worker,(void*)&arg); +<BR>while(ACE_Thread::join(NULL,NULL,NULL)==0); +<BR>} + +<P> <A HREF="ex04.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_4/ex04.html b/docs/tutorials/Chap_4/ex04.html new file mode 100644 index 00000000000..091433ba5be --- /dev/null +++ b/docs/tutorials/Chap_4/ex04.html @@ -0,0 +1,69 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 4</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "Thread Management"</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 4</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/OS.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Token.h"</FONT> + +<P><FONT COLOR="#FF0000">//Arguments that are to be passed to the worker +thread are passed</FONT> +<BR><FONT COLOR="#FF0000">//through this class.</FONT> +<BR>class Args{ +<BR>public: +<BR>Args(int iterations): +<BR> mutex_(),iterations_(iterations){} +<BR>ACE_Token mutex_; +<BR>int iterations_; +<BR>}; + +<P><FONT COLOR="#FF0000">//The starting point for the worker threads</FONT> +<BR>static void* +<BR>worker(void*arguments){ +<BR>Args *arg= (Args*) arguments; +<BR>for(int i=0;i<arg->iterations_;i++){ +<BR> ACE_DEBUG((LM_DEBUG,"(%t) Trying to get a hold of this iteration\n")); +<BR><FONT COLOR="#FF0000"> //This is our critical section</FONT> +<BR> arg->mutex_.acquire(); +<BR> ACE_DEBUG((LM_DEBUG,"(%t) This is iteration number %d\n",i)); +<BR><FONT COLOR="#FF0000"> //work</FONT> +<BR> ACE_OS::sleep(2); +<BR> arg->mutex_.release(); +<BR> } +<BR>return 0; +<BR>} +<BR> + +<P>int main(int argc, char*argv[]){ +<BR>if(argc<4){ +<BR> ACE_OS::printf("Usage: egx <number_of_threads> +<BR> <number_of_iterations> <lock_type>\n"); +<BR> ACE_OS::exit(1); +<BR> } + +<P><FONT COLOR="#FF0000">//Setup the arguments</FONT> +<BR>Args arg(ACE_OS::atoi(argv[2])); +<BR><FONT COLOR="#FF0000">//Spawn the worker threads</FONT> +<BR>ACE_Thread::spawn_n(ACE_OS::atoi(argv[1]),(ACE_THR_FUNC)worker,(void*)&arg); + +<P>while(ACE_Thread::join(NULL,NULL,NULL)==0); + +<P>} + +<P> <A HREF="ex05.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_4/ex05.html b/docs/tutorials/Chap_4/ex05.html new file mode 100644 index 00000000000..74fbb7cd80f --- /dev/null +++ b/docs/tutorials/Chap_4/ex05.html @@ -0,0 +1,69 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 5</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "Thread Management"</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 5</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/OS.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch_T.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Token.h"</FONT> + +<P><FONT COLOR="#FF0000">//Arguments that are to be passed to the worker +thread are passed through this class.</FONT> +<BR>class Args{ +<BR>public: +<BR>Args(int iterations): +<BR> mutex_(),iterations_(iterations){} +<BR>ACE_Token mutex_; +<BR>int iterations_; +<BR>}; + +<P><FONT COLOR="#FF0000">//The starting point for the worker threads</FONT> +<BR>static void* +<BR>worker(void*arguments){ +<BR>Args *arg= (Args*) arguments; +<BR>for(int i=0;i<arg->iterations_;i++){ +<BR> ACE_DEBUG((LM_DEBUG,"(%t) Trying to get a hold of this iteration\n")); +<BR> {<FONT COLOR="#FF0000">//begin critical section</FONT> +<BR> ACE_Guard<ACE_Token> guard(arg->mutex_); +<BR> <FONT COLOR="#FF0000"> //This is our critical section</FONT> +<BR> ACE_DEBUG((LM_DEBUG,"(%t) This is iteration number %d\n",i)); +<BR><FONT COLOR="#FF0000"> //work</FONT> +<BR> ACE_OS::sleep(2); +<BR> }<FONT COLOR="#FF0000">//end critical section</FONT> +<BR> } +<BR>return 0; +<BR>} +<BR> + +<P>int main(int argc, char*argv[]){ +<BR>if(argc<3){ +<BR> ACE_OS::printf("Usage: egx <number_of_threads> <number_of_iterations> +\n"); +<BR> ACE_OS::exit(1); +<BR> } + +<P><FONT COLOR="#FF0000">//Setup the arguments</FONT> +<BR>Args arg(ACE_OS::atoi(argv[2])); +<BR><FONT COLOR="#FF0000">//Spawn the worker threads</FONT> +<BR>ACE_Thread::spawn_n(ACE_OS::atoi(argv[1]),(ACE_THR_FUNC)worker,(void*)&arg); +<BR>while(ACE_Thread::join(NULL,NULL,NULL)==0); +<BR>} + +<P> <A HREF="ex06.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_4/ex06.html b/docs/tutorials/Chap_4/ex06.html new file mode 100644 index 00000000000..7a8df16dcd3 --- /dev/null +++ b/docs/tutorials/Chap_4/ex06.html @@ -0,0 +1,95 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 6</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "Thread Management"</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 6</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Thread.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/OS.h"</FONT> +<BR><FONT COLOR="#000099">#include </FONT><FONT COLOR="#006600">"ace/Synch_T.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Synch.h"</FONT> + +<P>static int number=0; +<BR>static int seed=0; + +<P>class Args{ +<BR>public: +<BR>Args(ACE_Condition<ACE_Thread_Mutex> *cond, int threads): +<BR> cond_(cond), threads_(threads){} +<BR>ACE_Condition<ACE_Thread_Mutex> *cond_; +<BR>int threads_; +<BR>}; + +<P>static void* +<BR>worker(void *arguments){ +<BR> Args *arg= (Args*)arguments; +<BR> ACE_DEBUG((LM_DEBUG,"Thread (%t) Created to do some work\n")); +<BR> ::number++; +<BR><FONT COLOR="#FF0000"> //Work</FONT> +<BR> ACE_OS::sleep(ACE_OS::rand()%2); + +<P><FONT COLOR="#FF0000"> //Exiting now</FONT> +<BR> ACE_DEBUG((LM_DEBUG, +<BR> "\tThread (%t) Done! \n\tThe number is now: %d\n",number)); +<BR><FONT COLOR="#FF0000"> //If all threads are done signal main thread +that program can now exit</FONT> +<BR> if(number==arg->threads_){ +<BR> ACE_DEBUG((LM_DEBUG, +<BR> "(%t) Last Thread!\n All threads have done +their job! +<BR> Signal main thread\n")); +<BR> arg->cond_->signal(); +<BR> } +<BR>return 0; +<BR>} +<BR> + +<P>int main(int argc, char *argv[]){ +<BR>if(argc<2){ +<BR> ACE_DEBUG((LM_DEBUG,"Usage: <program_name> <number of threads>\n")); +<BR> ACE_OS::exit(1); +<BR> } +<BR> +<BR>int n_threads=ACE_OS::atoi(argv[1]); + +<P><FONT COLOR="#FF0000">//Setup the random number generator</FONT> +<BR>ACE_OS::srand(::seed); + +<P><FONT COLOR="#FF0000">//Setup arguments for threads</FONT> +<BR>ACE_Thread_Mutex mutex; +<BR>ACE_Condition<ACE_Thread_Mutex> cond(mutex); +<BR>Args arg(&cond,n_threads); + +<P><FONT COLOR="#FF0000">//Spawn off n_threads number of threads</FONT> +<BR>for(int i=0; i<n_threads; i++){ +<BR> if(ACE_Thread::spawn((ACE_THR_FUNC)worker,(void*)&arg, +<BR> THR_DETACHED|THR_NEW_LWP)==-1) +<BR> ACE_DEBUG((LM_DEBUG,"Error in spawning thread\n")); +<BR> } + +<P><FONT COLOR="#FF0000">//Wait for signal indicating that all threads +are done and program can exit</FONT> +<BR>mutex.acquire(); +<BR>if(number!=n_threads) +<BR> cond.wait(); +<BR>ACE_DEBUG((LM_DEBUG,"(%t) Main Thread got signal. Program exiting..\n")); +<BR>mutex.release(); +<BR>ACE_OS::exit(0); +<BR>} + +<P> <A HREF="ex07.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_4/ex07.html b/docs/tutorials/Chap_4/ex07.html new file mode 100644 index 00000000000..4adf56569d3 --- /dev/null +++ b/docs/tutorials/Chap_4/ex07.html @@ -0,0 +1,84 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 7</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "Thread Management"</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 7</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Thread.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/OS.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch_T.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch.h"</FONT> + +<P>static int number=0; +<BR>static int seed=0; + +<P>class Args{ +<BR>public: +<BR>Args(ACE_Barrier *barrier): +<BR> barrier_(barrier){} +<BR>ACE_Barrier *barrier_; +<BR>}; + +<P>static void* +<BR>worker(void *arguments){ +<BR> Args *arg= (Args*)arguments; +<BR> ACE_DEBUG((LM_DEBUG,"Thread (%t) Created to do some work\n")); +<BR> ::number++; +<BR> +<BR><FONT COLOR="#FF0000"> //Work</FONT> +<BR> ACE_OS::sleep(ACE_OS::rand()%2); + +<P><FONT COLOR="#FF0000"> //Exiting now</FONT> +<BR> ACE_DEBUG((LM_DEBUG, +<BR> "\tThread (%t) Done! \n\tThe number is now: %d\n",number)); +<BR><FONT COLOR="#FF0000"> //Let the barrier know we are done.</FONT> +<BR> arg->barrier_->wait(); +<BR> ACE_DEBUG((LM_DEBUG,"Thread (%t) is exiting \n")); +<BR> return 0; +<BR>} +<BR> + +<P>int main(int argc, char *argv[]){ +<BR>if(argc<2){ +<BR> ACE_DEBUG((LM_DEBUG,"Usage: <program_name> <number of threads>\n")); +<BR> ACE_OS::exit(1); +<BR> } +<BR> +<BR>int n_threads=ACE_OS::atoi(argv[1]); +<BR>ACE_DEBUG((LM_DEBUG,"Preparing to spawn %d threads",n_threads)); +<BR><FONT COLOR="#FF0000">//Setup the random number generator</FONT> +<BR>ACE_OS::srand(::seed); + +<P><FONT COLOR="#FF0000">//Setup arguments for threads</FONT> +<BR>ACE_Barrier barrier(n_threads); +<BR>Args arg(&barrier); + +<P><FONT COLOR="#FF0000">//Spawn off n_threads number of threads</FONT> +<BR>for(int i=0; i<n_threads; i++){ if(ACE_Thread::spawn((ACE_THR_FUNC)worker,(void*)&arg,THR_DETACHED|THR_NEW_LWP)==-1) +<BR> ACE_DEBUG((LM_DEBUG,"Error in spawning thread\n")); +<BR> } + +<P><FONT COLOR="#FF0000">//Wait for all the other threads to let the main +thread</FONT> +<BR><FONT COLOR="#FF0000">// know that they are done using hte barrier</FONT> +<BR>barrier.wait(); +<BR>ACE_DEBUG((LM_DEBUG,"(%t)Other threads are finished. Program exiting..\n")); +<BR>ACE_OS::sleep(2); +<BR>} + +<P> <A HREF="ex08.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_4/ex08.html b/docs/tutorials/Chap_4/ex08.html new file mode 100644 index 00000000000..2418a93c0a8 --- /dev/null +++ b/docs/tutorials/Chap_4/ex08.html @@ -0,0 +1,72 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 8</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "Thread Management"</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 8</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch_T.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch.h"</FONT> + +<P>ACE_Atomic_Op<ACE_Thread_Mutex,int> foo; + +<P>static void* +<BR>worker(void *arg){ +<BR> ACE_UNUSED_ARG(arg); +<BR> foo=5; +<BR> ACE_ASSERT (foo == 5); +<BR> +<BR> ++foo; +<BR> ACE_ASSERT (foo == 6); +<BR> +<BR> --foo; +<BR> ACE_ASSERT (foo == 5); +<BR> +<BR> foo += 10; +<BR> ACE_ASSERT (foo == 15); +<BR> +<BR> foo -= 10; +<BR> ACE_ASSERT (foo == 5); +<BR> +<BR> foo = 5L; +<BR> ACE_ASSERT (foo == 5); +<BR> return 0; +<BR>} + +<P>int main(int argc, char *argv[]){ +<BR>if(argc<2){ +<BR> ACE_DEBUG((LM_DEBUG,"Usage: <program_name> <number of threads>\n")); +<BR> ACE_OS::exit(1); +<BR> } +<BR> +<BR>int n_threads=ACE_OS::atoi(argv[1]); +<BR>ACE_DEBUG((LM_DEBUG,"Preparing to spawn %d threads\n",n_threads)); +<BR> + +<P><FONT COLOR="#FF0000">//Spawn off n_threads number of threads</FONT> +<BR>for(int i=0; i<n_threads; i++){ +<BR> if(ACE_Thread::spawn((ACE_THR_FUNC)worker,0,THR_DETACHED|THR_NEW_LWP)==-1) +<BR> ACE_DEBUG((LM_DEBUG,"Error in spawning thread\n")); +<BR> } + +<P><FONT COLOR="#FF0000">//Wait for all the other threads to let the main +thread know when it is time to exit</FONT> +<BR>while(ACE_Thread::join(NULL,NULL,NULL)==0); +<BR>ACE_DEBUG((LM_DEBUG,"(%t)Other threads are finished. Program exiting..\n")); +<BR>} + +<P> <A HREF="../Chap_5/ex01.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_5/Chap_5.zip b/docs/tutorials/Chap_5/Chap_5.zip Binary files differnew file mode 100644 index 00000000000..5eb2b6646d0 --- /dev/null +++ b/docs/tutorials/Chap_5/Chap_5.zip diff --git a/docs/tutorials/Chap_5/ex01.html b/docs/tutorials/Chap_5/ex01.html new file mode 100644 index 00000000000..54bb3204b61 --- /dev/null +++ b/docs/tutorials/Chap_5/ex01.html @@ -0,0 +1,75 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 1</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Reactor" (Event +Management)</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#FF0000">//Example 1</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600"><signal.h></FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Reactor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Event_Handler.h"</FONT> + +<P><FONT COLOR="#FF0000">//Create our subclass to handle the signal events</FONT> +<BR><FONT COLOR="#FF0000">//that we wish to handle. Since we know that +this particular</FONT> +<BR><FONT COLOR="#FF0000">//event handler is going to be using signals +we only overload the</FONT> +<BR><FONT COLOR="#FF0000">//handle_signal method.</FONT> + +<P>class +<BR>MyEventHandler: public ACE_Event_Handler{ +<BR>int +<BR>handle_signal(int signum, siginfo_t*,ucontext_t*){ +<BR> switch(signum){ +<BR> case SIGWINCH: +<BR> ACE_DEBUG((LM_DEBUG, "You pressed SIGWINCH \n")); +<BR> break; + +<P> case SIGINT: +<BR> ACE_DEBUG((LM_DEBUG, "You pressed SIGINT \n")); +<BR> break; +<BR> } +<BR> return 0; +<BR> } +<BR>}; + +<P>int main(int argc, char *argv[]){ +<BR><FONT COLOR="#FF0000"> //instantiate the handler</FONT> +<BR> MyEventHandler *eh =new MyEventHandler; + +<P><FONT COLOR="#FF0000">//Register the handler asking to call back when +either SIGWINCH</FONT> +<BR><FONT COLOR="#FF0000">//or SIGINT signals occur. Note that in both +the cases we asked the</FONT> +<BR><FONT COLOR="#FF0000">//Reactor to call back the same Event_Handler +i.e., MyEventHandler.</FONT> +<BR><FONT COLOR="#FF0000">//This is the reason why we had to write a switch +statement in the handle_signal()</FONT> +<BR><FONT COLOR="#FF0000">//method above. Also note that the</FONT> +<BR><FONT COLOR="#FF0000">//ACE_Reactor is being used as a Singleton object +(Singleton pattern)</FONT> + +<P> ACE_Reactor::instance()->register_handler(SIGWINCH,eh); +<BR> ACE_Reactor::instance()->register_handler(SIGINT,eh); +<BR> while(1) +<BR> <FONT COLOR="#FF0000"> //Start the reactors event loop</FONT> +<BR> ACE_Reactor::instance()->handle_events(); +<BR>} + +<P> <A HREF="ex02.html">Next Example</A> +<BR> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_5/ex02.html b/docs/tutorials/Chap_5/ex02.html new file mode 100644 index 00000000000..89f5094b9c7 --- /dev/null +++ b/docs/tutorials/Chap_5/ex02.html @@ -0,0 +1,148 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 2</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Reactor" (Event +Management)</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 2</FONT> +<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Reactor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/SOCK_Acceptor.h"</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">PORT_NO +19998</FONT> +<BR>typedef ACE_SOCK_Acceptor Acceptor; +<BR><FONT COLOR="#FF0000">//forward declaration</FONT> +<BR>class My_Accept_Handler; + +<P>class +<BR>My_Input_Handler: public ACE_Event_Handler{ +<BR>public: +<BR><FONT COLOR="#FF0000"> //Constructor</FONT> +<BR> My_Input_Handler(){ +<BR> ACE_DEBUG((LM_DEBUG,?Constructor\n?); +<BR> } +<BR> +<BR><FONT COLOR="#FF0000"> //Called back to handle any input receieved</FONT> +<BR> int +<BR> handle_input(ACE_HANDLE){ +<BR><FONT COLOR="#FF0000"> //receive the data</FONT> +<BR> peer().recv_n(data,12); +<BR> ACE_DEBUG((LM_DEBUG,?%s\n?,data)); +<BR> +<BR> <FONT COLOR="#FF0000"> // do something with the input received.</FONT> +<BR><FONT COLOR="#FF0000"> // ...</FONT> + +<P><FONT COLOR="#FF0000"> //keep yourself registered with the reactor</FONT> +<BR> return 0; +<BR> } +<BR> +<BR><FONT COLOR="#FF0000"> //Used by the reactor to determine the +underlying handle</FONT> +<BR> ACE_HANDLE +<BR> get_handle()const { +<BR> return this->peer_i().get_handle(); +<BR> } +<BR> +<BR><FONT COLOR="#FF0000"> //Returns a reference to the underlying +stream.</FONT> +<BR> ACE_SOCK_Stream & +<BR> peer_i(){ +<BR> return this->peer_; +<BR> } + +<P>private: +<BR> ACE_SOCK_Stream peer_; +<BR> char data [12]; +<BR>}; +<BR> + +<P>class +<BR>My_Accept_Handler: public ACE_Event_Handler{ +<BR>public: +<BR><FONT COLOR="#FF0000">//Constructor</FONT> +<BR> My_Accept_Handler(ACE_Addr &addr){ +<BR> this->open(addr); +<BR> } + +<P><FONT COLOR="#FF0000">//Open the peer_acceptor so it starts to ?listen?</FONT> +<BR><FONT COLOR="#FF0000">//for incoming clients.</FONT> +<BR> int +<BR> open(ACE_Addr &addr){ +<BR> peer_acceptor.open(addr); +<BR> return 0; +<BR> } + +<P><FONT COLOR="#FF0000">//Overload the handle input method</FONT> +<BR> int +<BR> handle_input(ACE_HANDLE handle){ +<BR> <FONT COLOR="#FF0000"> //Client has requested connection to server.</FONT> +<BR><FONT COLOR="#FF0000"> //Create a handler to handle the connection</FONT> +<BR> My_Input_Handler *eh= new My_Input_Handler(); + +<P> <FONT COLOR="#FF0000">//Accept the connection ?into? the Event +Handler</FONT> +<BR> if (this->peer_acceptor.accept (eh->peer (), <FONT COLOR="#FF0000">// +stream</FONT> +<BR> 0, <FONT COLOR="#FF0000">// remote address</FONT> +<BR> 0, <FONT COLOR="#FF0000">// timeout</FONT> +<BR> 1) ==-1) <FONT COLOR="#FF0000">//restart +if interrupted</FONT> +<BR> ACE_DEBUG((LM_ERROR,"Error in connection\n")); + +<P> ACE_DEBUG((LM_DEBUG,"Connection established\n")); + +<P><FONT COLOR="#FF0000"> //Register the input event handler for +reading</FONT> +<BR> ACE_Reactor::instance()-> +<BR> register_handler(eh,ACE_Event_Handler::READ_MASK); + +<P><FONT COLOR="#FF0000"> //Unregister as the acceptor is not expecting +new clients</FONT> +<BR> return -1; +<BR> } + +<P><FONT COLOR="#FF6666"> //Used by the reactor to determine the underlying +handle</FONT> +<BR> ACE_HANDLE +<BR> get_handle(void) const{ +<BR> return this->peer_acceptor.get_handle(); +<BR> } +<BR>private: +<BR> Acceptor peer_acceptor; +<BR>}; + +<P>int main(int argc, char * argv[]){ +<BR><FONT COLOR="#FF0000"> //Create an address on which to receive +connections</FONT> +<BR> ACE_INET_Addr addr(PORT_NO); + +<P><FONT COLOR="#FF0000">//Create the Accept Handler which automatically +begins to "listen"</FONT> +<BR><FONT COLOR="#FF0000">//for client requests for connections</FONT> +<BR> My_Accept_Handler *eh=new My_Accept_Handler(addr); + +<P><FONT COLOR="#FF0000">//Register the reactor to call back when incoming +client connects</FONT> +<BR>ACE_Reactor::instance()->register_handler(eh, +<BR> ACE_Event_Handler::ACCEPT_MASK); + +<P><FONT COLOR="#FF0000">//Start the event loop</FONT> +<BR>while(1) +<BR> ACE_Reactor::instance()->handle_events(); +<BR>} + +<P> <A HREF="ex03.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_5/ex03.html b/docs/tutorials/Chap_5/ex03.html new file mode 100644 index 00000000000..07dabd17a97 --- /dev/null +++ b/docs/tutorials/Chap_5/ex03.html @@ -0,0 +1,86 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 3</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Reactor" (Event +Management)</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#FF0000">//Example 3</FONT> +<BR><FONT COLOR="#000099">#include</FONT> "<FONT COLOR="#006600">ace/Timer_Queue.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> "<FONT COLOR="#006600">ace/Reactor.h"</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">NUMBER_TIMERS +10</FONT> + +<P>static int done = 0; +<BR>static int count = 0; + +<P>class Time_Handler : public ACE_Event_Handler +<BR>{ +<BR>public: +<BR> <FONT COLOR="#FF0000">//Method which is called back by the Reactor +when timeout occurs.</FONT> +<BR> virtual int handle_timeout (const ACE_Time_Value &tv, +<BR> const void *arg){ +<BR> long current_count = long (arg); +<BR> ACE_ASSERT (current_count == count); +<BR> ACE_DEBUG ((LM_DEBUG, "%d: Timer #%d timed out at %d!\n", +<BR> count, current_count, tv.sec())); +<BR> + +<P><FONT COLOR="#FF0000">//Increment count</FONT> +<BR> count ++; + +<P><FONT COLOR="#FF0000">//Make sure assertion doesnt fail for missing +5th timer.</FONT> +<BR> if (count ==5) +<BR> count++; +<BR> +<BR><FONT COLOR="#FF0000"> //If all timers done then set done flag</FONT> +<BR> if (current_count == NUMBER_TIMERS - 1) +<BR> done = 1; +<BR><FONT COLOR="#FF0000"> //Keep yourself registered with the Reactor.</FONT> +<BR> return 0; +<BR> } +<BR>}; + +<P>int +<BR>main (int, char *[]) +<BR>{ +<BR> ACE_Reactor reactor; +<BR> Time_Handler *th=new Time_Handler; +<BR> int timer_id[NUMBER_TIMERS]; +<BR> int i; + +<P> for (i = 0; i < NUMBER_TIMERS; i++) +<BR> timer_id[i] = reactor.schedule_timer (th, +<BR> (const void *) i, <FONT COLOR="#FF0000">// argument sent +to handle_timeout()</FONT> +<BR> ACE_Time_Value (2 * i + 1));<FONT COLOR="#FF0000"> //set +timer to go off with delay</FONT> + +<P><FONT COLOR="#CC0000"> //Cancel the fifth timer before it goes +off</FONT> +<BR> reactor.cancel_timer(timer_id[5]);<FONT COLOR="#FF0000">//Timer +ID of timer to be removed</FONT> + +<P> while (!done) +<BR> reactor.handle_events (); + +<P> return 0; +<BR>} + +<P> <A HREF="ex04.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_5/ex04.html b/docs/tutorials/Chap_5/ex04.html new file mode 100644 index 00000000000..e0d0181d14d --- /dev/null +++ b/docs/tutorials/Chap_5/ex04.html @@ -0,0 +1,84 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 4</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Reactor" (Event +Management)</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#FF0000">//Example 4</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Reactor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Event_Handler.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch_T.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Thread_Manager.h"</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">WAIT_TIME +1</FONT> +<BR><FONT COLOR="#000099">#define</FONT><FONT COLOR="#663366"> SLEEP_TIME +2</FONT> + +<P>class My_Handler: public ACE_Event_Handler{ +<BR> public: + +<P><FONT COLOR="#FF0000"> //Start the event handling process.</FONT> +<BR> My_Handler(){ +<BR> ACE_DEBUG((LM_DEBUG,"Event Handler created\n")); +<BR> ACE_Reactor::instance()->max_notify_iterations(5); +<BR> return 0; +<BR> } + +<P><FONT COLOR="#FF0000">//Perform the notifications i.e., notify the reactor +10 times</FONT> +<BR> void perform_notifications(){ +<BR> for(int i=0;i<10;i++) +<BR> ACE_Reactor::instance()-> +<BR> notify(this,ACE_Event_Handler::READ_MASK); +<BR> } +<BR> +<BR><FONT COLOR="#FF0000"> //The actual handler which in this case +will handle the notifications</FONT> +<BR> int handle_input(int){ +<BR> ACE_DEBUG((LM_DEBUG,"Got notification # %d\n",no)); +<BR> no++; +<BR> return 0; +<BR> } +<BR>private: +<BR> static int no; +<BR>}; + +<P><FONT COLOR="#FF0000">//Static members</FONT> +<BR>int My_Handler::no=1; +<BR> + +<P>int main(int argc, char *argv[]){ +<BR><FONT COLOR="#FF0000"> //Instantiating the handler</FONT> +<BR> My_Handler handler; +<BR> +<BR><FONT COLOR="#FF0000"> //The done flag is set to not done yet.</FONT> +<BR> int done=0; + +<P>while(1){ +<BR> <FONT COLOR="#FF0000"> //After WAIT_TIME the handle_events will +fall through if no events arrive.</FONT> +<BR> ACE_Reactor::instance()->handle_events(ACE_Time_Value(WAIT_TIME)); +<BR> if(!done){ +<BR> handler.perform_notifications(); +<BR> done=1; +<BR> } +<BR> sleep(SLEEP_TIME); +<BR> } +<BR>} + +<P> <A HREF="ex05.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_5/ex05.html b/docs/tutorials/Chap_5/ex05.html new file mode 100644 index 00000000000..665730fcace --- /dev/null +++ b/docs/tutorials/Chap_5/ex05.html @@ -0,0 +1,87 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 5</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Reactor" (Event +Management)</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 5</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Reactor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Event_Handler.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch_T.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Thread_Manager.h"</FONT> + +<P>class My_Handler: public ACE_Event_Handler{ +<BR>public: +<BR><FONT COLOR="#FF0000"> //Start the event handling process.</FONT> +<BR> My_Handler(){ +<BR> ACE_DEBUG((LM_DEBUG,"Got open\n")); +<BR> activate_threads(); +<BR> ACE_Reactor::instance()->max_notify_iterations(5); +<BR> return 0; +<BR> } + +<P><FONT COLOR="#FF0000">//Spawn a separate thread so that it notifies +the reactor</FONT> +<BR> void activate_threads(){ +<BR> ACE_Thread_Manager::instance() +<BR> ->spawn((ACE_THR_FUNC)svc_start,(void*)this); +<BR> } +<BR> +<BR><FONT COLOR="#FF0000"> //Notify the Reactor 10 times.</FONT> +<BR> void svc(){ +<BR> for(int i=0;i<10;i++) +<BR> ACE_Reactor::instance() +<BR> ->notify(this, ACE_Event_Handler::READ_MASK); +<BR> } + +<P><FONT COLOR="#FF0000">//The actual handler which in this case will handle +the notifications</FONT> +<BR> int handle_input(int){ +<BR> ACE_DEBUG((LM_DEBUG, ?Got notification # %d\n?, no)); +<BR> no++; +<BR> return 0; +<BR> } + +<P> <FONT COLOR="#FF0000">//The entry point for the new thread that +is to be created.</FONT> +<BR> static int svc_start(void* arg); +<BR>private: +<BR> static int no; +<BR>}; +<BR> + +<P><FONT COLOR="#FF0000">//Static members</FONT> +<BR>int My_Handler::no=1; +<BR>int My_Handler::svc_start(void* arg){ +<BR> My_Handler *eh= (My_Handler*)arg; +<BR> eh->svc(); +<BR> return -1; <FONT COLOR="#FF0000">//de-register from the reactor</FONT> +<BR> } + +<P>int main(int argc, char *argv[]){ +<BR> ACE_DEBUG((LM_DEBUG,"Starting test \n")); +<BR> My_Handler handler; + +<P> while(1){ +<BR> ACE_Reactor::instance()->handle_events(); +<BR> sleep(3); +<BR> } +<BR>} +<BR> +<BR> +<BR> <A HREF="../Chap_6/ex01.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_6/Chap_6.zip b/docs/tutorials/Chap_6/Chap_6.zip Binary files differnew file mode 100644 index 00000000000..fcfd5455cba --- /dev/null +++ b/docs/tutorials/Chap_6/Chap_6.zip diff --git a/docs/tutorials/Chap_6/ex01.html b/docs/tutorials/Chap_6/ex01.html new file mode 100644 index 00000000000..ff60ea6dcb7 --- /dev/null +++ b/docs/tutorials/Chap_6/ex01.html @@ -0,0 +1,81 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 1</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Acceptor/Connector" +(Connection Initialization)</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#FF0000">//Example 1</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Reactor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Svc_Handler.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Acceptor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Synch.h"</FONT> +<BR><FONT COLOR="#000099">#include </FONT><FONT COLOR="#006600">"ace/SOCK_Acceptor.h"</FONT> + +<P><FONT COLOR="#FF0000">//Create a Service Handler whose open() method +will be called back automatically.</FONT> +<BR><FONT COLOR="#FF0000">//This class MUST derive from ACE_Svc_Handler +which is an interface and</FONT> +<BR><FONT COLOR="#FF0000">//as can be seen is a template container class +itself. The first parameter to //ACE_Svc_Handler is the underlying stream +that it may use for communication.</FONT> +<BR><FONT COLOR="#FF0000">//Since we are using TCP sockets the stream is +ACE_SOCK_STREAM.</FONT> +<BR><FONT COLOR="#FF0000">//The second is the internal synchronization +mechanism it could use.</FONT> +<BR><FONT COLOR="#FF0000">//Since we have a single threaded application +we pass it a "null" lock</FONT> +<BR><FONT COLOR="#FF0000">//which will do nothing.</FONT> + +<P>class My_Svc_Handler: +<BR> public ACE_Svc_Handler <ACE_SOCK_STREAM,ACE_NULL_SYNCH>{ +<BR><FONT COLOR="#FF0000">//the open method which will be called back automatically +after the</FONT> +<BR><FONT COLOR="#FF0000">//connection has been established</FONT>. + +<P>public: +<BR>int open(void*){ +<BR> cout<<?Connection established?<<endl; +<BR> } +<BR>}; +<BR><FONT COLOR="#FF0000">// Create the acceptor as described above.</FONT> +<BR>typedef ACE_Acceptor<My_Svc_Handler,ACE_SOCK_ACCEPTOR> MyAcceptor; + +<P>int main(int argc, char* argv[]){ +<BR><FONT COLOR="#FF0000">//create the address on which we wish to +connect. The constructor takes</FONT> +<BR><FONT COLOR="#FF0000">//the port number on which to listen and will +automatically take the hosts</FONT> +<BR><FONT COLOR="#FF0000">//IP address as the IP Address for the addr object</FONT> + +<P>ACE_INET_Addr addr(PORT_NUM); + +<P><FONT COLOR="#FF0000">//instantiate the appropriate acceptor object +with the address on which we wish to</FONT> +<BR><FONT COLOR="#FF0000">//accept and the Reactor instance we want to +use. In this case we just use the global</FONT> +<BR><FONT COLOR="#FF0000">//ACE_Reactor singleton. (Read more about the +reactor in the previous chapter)</FONT> +<BR>MyAcceptor acceptor(address, ACE_Reactor::instance()); + +<P>while(1) +<BR><FONT COLOR="#FF0000"> // Start the reactors event loop</FONT> +<BR> ACE_Reactor::instance()->handle_events(); +<BR>} + +<P> <A HREF="ex02.html">Next Example</A> +<BR> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_6/ex02.html b/docs/tutorials/Chap_6/ex02.html new file mode 100644 index 00000000000..a5ab4cca339 --- /dev/null +++ b/docs/tutorials/Chap_6/ex02.html @@ -0,0 +1,94 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 2</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Acceptor/Connector" +(Connection Initialization)</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 2</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Reactor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Svc_Handler.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Acceptor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/SOCK_Acceptor.h"</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">PORT_NUM +10101</FONT> +<BR><FONT COLOR="#000099">#define</FONT><FONT COLOR="#663366"> DATA_SIZE +12</FONT> + +<P><FONT COLOR="#FF0000">//forward declaration</FONT> +<BR>class My_Svc_Handler; + +<P><FONT COLOR="#FF0000">//Create the Acceptor class</FONT> +<BR>typedef ACE_Acceptor<My_Svc_Handler,ACE_SOCK_ACCEPTOR> MyAcceptor; + +<P><FONT COLOR="#FF0000">//Create a service handler similar to as seen +in example 1.</FONT> +<BR><FONT COLOR="#FF0000">//Except this time include the handle_input() +method which will be</FONT> +<BR><FONT COLOR="#FF0000">//called back automatically by the reactor when +new data arrives</FONT> +<BR><FONT COLOR="#FF0000">//on the newly established connection</FONT> +<BR>class My_Svc_Handler: +<BR> public ACE_Svc_Handler <ACE_SOCK_STREAM,ACE_NULL_SYNCH>{ +<BR>public: +<BR>My_Svc_Handler(){ +<BR> data= new char[DATA_SIZE]; +<BR> } +<BR>int open(void*){ +<BR> ACE_DEBUG((LM_DEBUG,"Connection established")); + +<P><FONT COLOR="#FF0000"> //Register the service handler with the +reactor</FONT> +<BR> ACE_Reactor::instance()->register_handler(this, +<BR> ACE_Event_Handler::READ_MASK); +<BR> return 0; +<BR> } + +<P>int handle_input(ACE_HANDLE){ +<BR> <FONT COLOR="#FF0000">//After using the peer() method of ACE_Svc_Handler +to obtain a</FONT> +<BR><FONT COLOR="#FF0000">//reference to the underlying stream of the service +handler class</FONT> +<BR><FONT COLOR="#FF0000">//we call recv_n() on it to read the data which +has been received.</FONT> +<BR><FONT COLOR="#FF0000">//This data is stored in the data array and then +printed out</FONT> +<BR> peer().recv_n(data,DATA_SIZE); +<BR> ACE_OS::printf("<< %s\n",data); + +<P> <FONT COLOR="#FF0000">//keep yourself registered with the reactor</FONT> +<BR> return 0; +<BR> } +<BR>private: +<BR> char* data; +<BR>}; + +<P>int main(int argc, char* argv[]){ +<BR> ACE_INET_Addr addr(PORT_NUM); +<BR><FONT COLOR="#FF0000"> //create the acceptor</FONT> +<BR> MyAcceptor acceptor(addr, <FONT COLOR="#FF0000">//address to +accept on</FONT> +<BR> ACE_Reactor::instance()); <FONT COLOR="#FF0000">//the reactor +to use</FONT> + +<P>while(1) +<BR><FONT COLOR="#FF0000"> //Start the reactor?s event loop</FONT> +<BR> ACE_Reactor::instance()->handle_events(); +<BR>} + +<P> <A HREF="ex03.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_6/ex03.html b/docs/tutorials/Chap_6/ex03.html new file mode 100644 index 00000000000..a68bd303b61 --- /dev/null +++ b/docs/tutorials/Chap_6/ex03.html @@ -0,0 +1,50 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 3</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Acceptor/Connector" +(Connection Initialization)</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example3</FONT> + +<P>class My_Svc_Handler: +<BR>public ACE_Svc_Handler <ACE_LSOCK_STREAM,ACE_NULL_SYNCH>{ +<BR>public: +<BR>int open(void*){ +<BR> ACE_DEBUG((LM_DEBUG,"Connection established")); +<BR> ACE_Reactor::instance() ->register_handler(this,ACE_Event_Handler::READ_MASK); +<BR> } + +<P> int handle_input(ACE_HANDLE){ +<BR> char* data= new char[DATA_SIZE]; +<BR> peer().recv_n(data,DATA_SIZE); +<BR> ACE_OS::printf("<< %s\n",data); +<BR> return 0; +<BR> } +<BR>}; + +<P>typedef ACE_Acceptor<My_Svc_Handler,ACE_LSOCK_ACCEPTOR> MyAcceptor; + +<P>int main(int argc, char* argv[]){ +<BR> ACE_UNIX_Addr addr("/tmp/addr.ace"); +<BR> MyAcceptor acceptor(address, ACE_Reactor::instance()); + +<P>while(1) <FONT COLOR="#FF0000">/* Start the reactors event loop */</FONT> +<BR> ACE_Reactor::instance()->handle_events(); +<BR>} + +<P> <A HREF="ex04.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_6/ex04.html b/docs/tutorials/Chap_6/ex04.html new file mode 100644 index 00000000000..f5910341621 --- /dev/null +++ b/docs/tutorials/Chap_6/ex04.html @@ -0,0 +1,44 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 4</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Acceptor/Connector" +(Connection Initialization)</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 4 (Use in conjunction with other examples +to create running example)</FONT><FONT COLOR="#CC0000"></FONT> + +<P>typedef ACE_Connector<My_Svc_Handler,ACE_SOCK_CONNECTOR> MyConnector; + +<P>int main(int argc, char * argv[]){ +<BR> ACE_INET_Addr addr(PORT_NO,HOSTNAME); +<BR> My_Svc_Handler * handler= new My_Svc_Handler; + +<P><FONT COLOR="#FF0000">//Create the connector</FONT> +<BR> MyConnector connector; + +<P><FONT COLOR="#FF0000">//Connects to remote machine</FONT> +<BR> if(connector.connect(handler,addr)==-1) +<BR> ACE_ERROR(LM_ERROR,?%P|%t, %p?,?Connection failed?); +<BR> + +<P><FONT COLOR="#FF0000">//Registers with the Reactor</FONT> +<BR> while(1) +<BR> ACE_Reactor::instance()->handle_events(); +<BR>} + +<P> <A HREF="ex05.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_6/ex05.html b/docs/tutorials/Chap_6/ex05.html new file mode 100644 index 00000000000..c983e5751f9 --- /dev/null +++ b/docs/tutorials/Chap_6/ex05.html @@ -0,0 +1,129 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 5</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Acceptor/Connector" +(Connection Initialization)</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 5</FONT> +<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Reactor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> "<FONT COLOR="#006600">ace/Svc_Handler.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> "<FONT COLOR="#006600">ace/Acceptor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/SOCK_Acceptor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Thread.h"</FONT> + +<P><FONT COLOR="#FF0000">//Add our own Reactor singleton</FONT> +<BR>typedef ACE_Singleton<ACE_Reactor,ACE_Null_Mutex> Reactor; +<BR><FONT COLOR="#FF0000">//Create an Acceptor</FONT> +<BR>typedef ACE_Acceptor<MyServiceHandler,ACE_SOCK_ACCEPTOR> Acceptor; +<BR><FONT COLOR="#FF0000">//Create a Connector</FONT> +<BR>typedef ACE_Connector<MyServiceHandler,ACE_SOCK_CONNECTOR> Connector; + +<P>class MyServiceHandler: +<BR>public ACE_Svc_Handler<ACE_SOCK_STREAM,ACE_NULL_SYNCH>{ +<BR>public: +<BR><FONT COLOR="#FF0000"> //Used by the two threads "globally" to +determine their peer stream</FONT> +<BR> static ACE_SOCK_Stream* Peer; + +<P><FONT COLOR="#FF0000">//Thread ID used to identify the threads</FONT> +<BR> ACE_thread_t t_id; + +<P>int open(void*){ +<BR> ACE_DEBUG((LM_DEBUG,"Acceptor: received new connection\n")); + +<P><FONT COLOR="#FF0000">//Register with the reactor to remember this handlle</FONT> +<BR> Reactor::instance() ->register_handler(this,ACE_Event_Handler::READ_MASK); + +<P><FONT COLOR="#FF0000">//Determine the peer stream and record it globally</FONT> +<BR> MyServiceHandler::Peer=&peer(); +<BR> +<BR> <FONT COLOR="#FF0000">//Spawn new thread to send string every +second</FONT> +<BR> ACE_Thread::spawn((ACE_THR_FUNC)send_data,0,THR_NEW_LWP,&t_id); +<BR> +<BR> <FONT COLOR="#FF0000"> //keep the service handler registered +by returning 0 to the reactor</FONT> +<BR> return 0; +<BR> } +<BR> + +<P>static void* send_data(void*){ +<BR> while(1){ +<BR> ACE_DEBUG((LM_DEBUG,"Hello World\n")); +<BR> Peer->send_n("Hello World",sizeof("Hello World")); +<BR> +<BR> <FONT COLOR="#FF0000">//Go to sleep for a second before +sending again</FONT> +<BR> ACE_OS::sleep(1); +<BR> } +<BR> return 0; +<BR> } +<BR> + +<P>int handle_input(ACE_HANDLE){ +<BR> char* data= new char[12]; +<BR> +<BR> <FONT COLOR="#FF0000"> //Check if peer aborted the connection</FONT> +<BR> if(Peer.recv_n(data,12)==0){ +<BR> ACE_DEBUG((LM_DEBUG,"Peer probably aborted connection\n")); +<BR> ACE_Thread::cancel(t_id); <FONT COLOR="#CC0000">//kill +sending thread ..</FONT> +<BR> return -1; <FONT COLOR="#FF0000">//de-register from the +Reactor.</FONT> +<BR> } + +<P> <FONT COLOR="#FF0000"> //Show what you got..</FONT> +<BR> ACE_DEBUG((LM_DEBUG,"<< %s\n",data)); +<BR> +<BR> <FONT COLOR="#FF0000">//keep yourself registered</FONT> +<BR> return 0; +<BR> } +<BR>}; + +<P><FONT COLOR="#FF0000">//Global stream identifier used by both threads</FONT> +<BR>ACE_SOCK_Stream * MyServiceHandler::Peer=0; +<BR> + +<P>void main_accept(){ +<BR> ACE_INET_Addr addr(PORT_NO); +<BR> Acceptor myacceptor(addr,Reactor::instance()); +<BR> while(1) +<BR> Reactor::instance()->handle_events(); + +<P> return 0; +<BR> } + +<P>void main_connect(){ +<BR> ACE_INET_Addr addr(PORT_NO,HOSTNAME); +<BR> Connector myconnector; +<BR> myconnector.connect(my_svc_handler,addr); +<BR> while(1) +<BR> Reactor::instance()->handle_events(); + +<P> } +<BR> + +<P>int main(int argc, char* argv[]){ +<BR><FONT COLOR="#FF0000"> // Use ACE_Get_Opt to parse and obtain +arguments and then call the</FONT> +<BR> <FONT COLOR="#FF0000">// approriate function for accept or connect.</FONT> +<BR><FONT COLOR="#CC0000">//...</FONT> +<BR>} +<BR> +<BR> <A HREF="ex06.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_6/ex06.html b/docs/tutorials/Chap_6/ex06.html new file mode 100644 index 00000000000..7bfc3b91beb --- /dev/null +++ b/docs/tutorials/Chap_6/ex06.html @@ -0,0 +1,134 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 6</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Acceptor/Connector" +(Connection Initialization)</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 6</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Reactor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Svc_Handler.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Acceptor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/SOCK_Acceptor.h"</FONT> + +<P>class MyServiceHandler; //forward declaration +<BR>typedef ACE_Singleton<ACE_Reactor,ACE_Null_Mutex> Reactor; +<BR>typedef ACE_Acceptor<MyServiceHandler,ACE_SOCK_ACCEPTOR> Acceptor; + +<P>class MyServiceHandler: +<BR>public ACE_Svc_Handler<ACE_SOCK_STREAM,ACE_MT_SYNCH>{ +<BR><FONT COLOR="#FF0000">// The two thread names are kept here</FONT> +<BR>ACE_thread_t thread_names[2]; + +<P>public: +<BR>int open(void*){ +<BR> ACE_DEBUG((LM_DEBUG, "Acceptor: received new connection \n")); +<BR> +<BR> <FONT COLOR="#FF0000">//Register with the reactor to remember +this handler..</FONT> +<BR> Reactor::instance() ->register_handler(this,ACE_Event_Handler::READ_MASK); +<BR> ACE_DEBUG((LM_DEBUG,"Acceptor: ThreadID:(%t) open\n")); + +<P><FONT COLOR="#CC0000"> //Create two new threads to create and send +messages to the remote machine.</FONT> +<BR> activate(THR_NEW_LWP, +<BR> 2, <FONT COLOR="#FF0000">//2 new threads</FONT> +<BR> 0, <FONT COLOR="#FF0000">//force active false, if already +created dont try again.</FONT> +<BR> ACE_DEFAULT_THREAD_PRIORITY,<FONT COLOR="#FF0000">//Use +default thread priority</FONT> +<BR> -1, +<BR> this,<FONT COLOR="#FF0000">//Which ACE_Task object to +create? In this case this one.</FONT> +<BR> 0,<FONT COLOR="#FF0000">// dont care about thread handles +used</FONT> +<BR> 0,<FONT COLOR="#FF0000">// dont care about where stacks +are created</FONT> +<BR> 0,<FONT COLOR="#FF0000">//dont care about stack sizes</FONT> +<BR> thread_names); <FONT COLOR="#FF0000">// keep identifiers +in thread_names</FONT> +<BR> +<BR><FONT COLOR="#FF0000"> //keep the service handler registered with +the acceptor.</FONT> +<BR> return 0; +<BR> } + +<P>void send_message1(void){ +<BR> <FONT COLOR="#FF0000">//Send message type 1</FONT> +<BR> ACE_DEBUG((LM_DEBUG,"(%t)Sending message >>")); + +<P> <FONT COLOR="#FF0000">//Send the data to the remote peer</FONT> +<BR> ACE_DEBUG((LM_DEBUG,"Sent message1")); +<BR> peer().send_n("Message1",LENGTH_MSG_1); +<BR> } <FONT COLOR="#FF0000">//end send_message1</FONT> + +<P>int send_message2(void){ +<BR> <FONT COLOR="#FF0000">//Send message type 1</FONT> +<BR> ACE_DEBUG((LM_DEBUG,"(%t)Sending message >>")); + +<P> <FONT COLOR="#FF0000">//Send the data to the remote peer</FONT> +<BR> ACE_DEBUG((LM_DEBUG,"Sent Message2")); +<BR> peer().send_n("Message2",LENGTH_MSG_2); +<BR> }<FONT COLOR="#FF0000">//end send_message_2</FONT> +<BR> +<BR>int svc(void){ +<BR> ACE_DEBUG( (LM_DEBUG,?(%t) Svc thread \n?)); +<BR> +<BR> if(ACE_Thread::self()== thread_names[0]) +<BR> while(1) send_message1(); <FONT COLOR="#FF0000">//send message +1s forever</FONT> +<BR> else +<BR> while(1) send_message2(); <FONT COLOR="#FF0000">//send message +2s forever</FONT> +<BR> return 0; <FONT COLOR="#FF0000">// keep the compiler happy.</FONT> +<BR>} +<BR> +<BR>int handle_input(ACE_HANDLE){ +<BR> ACE_DEBUG((LM_DEBUG,?(%t) handle_input ::?)); +<BR> char* data= new char[13]; +<BR> +<BR> <FONT COLOR="#FF0000">//Check if peer aborted the connection</FONT> +<BR> if(peer().recv_n(data,12)==0){ +<BR> ACE_OS::printf("Peer probably aborted connection\n"); +<BR> return -1; <FONT COLOR="#FF0000">//de-register from the Reactor.</FONT> +<BR> } +<BR> +<BR> <FONT COLOR="#FF0000">//Show what you got..</FONT> +<BR> ACE_OS::printf("<< %s\n",data); +<BR> +<BR> <FONT COLOR="#FF0000">//keep yourself registered</FONT> +<BR> return 0; +<BR> +<BR> } +<BR>}; + +<P>int main(int argc, char* argv[]){ +<BR> ACE_INET_Addr addr(10101); +<BR> ACE_DEBUG((LM_DEBUG,"Thread: (%t) main\n")); + +<P> <FONT COLOR="#FF0000">//Prepare to accept connections</FONT> +<BR> Acceptor myacceptor(addr,Reactor::instance()); + +<P><FONT COLOR="#FF0000"> // wait for something to happen.</FONT> +<BR> while(1) +<BR> Reactor::instance()->handle_events(); +<BR> +<BR> return 0; +<BR>} + +<P> <A HREF="ex07.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_6/ex07.html b/docs/tutorials/Chap_6/ex07.html new file mode 100644 index 00000000000..7ecf0e57bb3 --- /dev/null +++ b/docs/tutorials/Chap_6/ex07.html @@ -0,0 +1,173 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 7</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Acceptor/Connector" +(Connection Initialization)</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 7</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Reactor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Svc_Handler.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Acceptor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Synch.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/SOCK_Acceptor.h"</FONT> +<BR><FONT COLOR="#000099">#include </FONT><FONT COLOR="#006600">"ace/Thread.h"</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">NETWORK_SPEED +3</FONT> +<BR>class MyServiceHandler;<FONT COLOR="#FF0000"> //forward declaration</FONT> +<BR>typedef ACE_Singleton<ACE_Reactor,ACE_Null_Mutex> Reactor; +<BR>typedef ACE_Acceptor<MyServiceHandler,ACE_SOCK_ACCEPTOR> Acceptor; + +<P>class MyServiceHandler: +<BR>public ACE_Svc_Handler<ACE_SOCK_STREAM,ACE_MT_SYNCH>{ +<BR><FONT COLOR="#FF0000">// The message sender and creator threads are +handled here.</FONT> +<BR>ACE_thread_t thread_names[2]; + +<P>public: +<BR>int open(void*){ +<BR> ACE_DEBUG((LM_DEBUG, "Acceptor: received new connection \n")); + +<P><FONT COLOR="#FF0000"> //Register with the reactor to remember +this handler..</FONT> +<BR> Reactor::instance() ->register_handler(this,ACE_Event_Handler::READ_MASK); +<BR> ACE_DEBUG((LM_DEBUG,"Acceptor: ThreadID:(%t) open\n")); + +<P><FONT COLOR="#CC0000"> //Create two new threads to create and send +messages to the</FONT> +<BR><FONT COLOR="#CC0000"> //remote machine.</FONT> +<BR> activate(THR_NEW_LWP, +<BR> 2, <FONT COLOR="#FF0000">//2 new threads</FONT> +<BR> 0, +<BR> ACE_DEFAULT_THREAD_PRIORITY, +<BR> -1, +<BR> this, +<BR> 0, +<BR> 0, +<BR> 0, +<BR> thread_names); <FONT COLOR="#FF0000">// identifiers in +thread_handles</FONT> +<BR> +<BR> <FONT COLOR="#FF0000">//keep the service handler registered with +the acceptor.</FONT> +<BR> return 0; +<BR> } + +<P>void send_message(void){ +<BR><FONT COLOR="#FF0000"> //Dequeue the message and send it off</FONT> +<BR> ACE_DEBUG((LM_DEBUG,"(%t)Sending message >>")); + +<P><FONT COLOR="#FF0000"> //dequeue the message from the message queue</FONT> +<BR> ACE_Message_Block *mb; +<BR> ACE_ASSERT(this->getq(mb)!=-1); +<BR> int length=mb->length(); +<BR> char *data =mb->rd_ptr(); + +<P> +<BR><FONT COLOR="#FF0000"> //Send the data to the remote peer</FONT> +<BR> ACE_DEBUG((LM_DEBUG,"%s \n",data,length)); +<BR> peer().send_n(data,length); + +<P> <FONT COLOR="#FF0000">//Simulate very SLOW network.</FONT> +<BR> ACE_OS::sleep(NETWORK_SPEED); + +<P><FONT COLOR="#FF0000"> //release the message block</FONT> +<BR> mb->release(); +<BR> } <FONT COLOR="#FF0000">//end send_message</FONT> + +<P>int construct_message(void){ +<BR><FONT COLOR="#FF0000"> // A very fast message creation algorithm</FONT> +<BR><FONT COLOR="#FF0000"> // would lead to the need for queuing messages..</FONT> +<BR><FONT COLOR="#FF0000"> // here. These messages are created and +then sent</FONT> +<BR><FONT COLOR="#FF0000"> // using the SLOW send_message() routine +which is</FONT> +<BR><FONT COLOR="#FF0000"> // running in a different thread so that +the message</FONT> +<BR><FONT COLOR="#FF0000"> //construction thread isn?t blocked.</FONT> +<BR> ACE_DEBUG((LM_DEBUG,"(%t)Constructing message >> ")); + +<P> <FONT COLOR="#FF0000">// Create a new message to send</FONT> +<BR> ACE_Message_Block *mb; +<BR> char *data="Hello Connector"; +<BR> ACE_NEW_RETURN (mb,ACE_Message_Block (16,<FONT COLOR="#FF0000">//Message +16 bytes long</FONT> +<BR> ACE_Message_Block::MB_DATA,<FONT COLOR="#FF0000">//Set +header to data</FONT> +<BR> 0,<FONT COLOR="#FF0000">//No continuations</FONT>. +<BR> data<FONT COLOR="#FF0000">//The data we want to send</FONT> +<BR> ), 0); +<BR> mb->wr_ptr(16); <FONT COLOR="#FF0000">//Set the write pointer.</FONT> +<BR> +<BR> <FONT COLOR="#FF0000">// Enqueue the message into the message +queue</FONT> +<BR><FONT COLOR="#FF0000"> // we COULD have done a timed wait for +enqueuing in case</FONT> +<BR><FONT COLOR="#FF0000"> // someone else holds the lock to the queue +so it doesn?t block</FONT> +<BR><FONT COLOR="#FF0000"> //forever..</FONT> +<BR> ACE_ASSERT(this->putq(mb)!=-1); +<BR> ACE_DEBUG((LM_DEBUG,"Enqueued msg successfully\n")); +<BR>} +<BR> +<BR>int svc(void){ +<BR> ACE_DEBUG( (LM_DEBUG,?(%t) Svc thread \n?)); +<BR> +<BR><FONT COLOR="#FF0000"> //call the message creator thread</FONT> +<BR> if(ACE_Thread::self()== thread_names[0]) +<BR> while(1) construct_message(); <FONT COLOR="#FF0000">//create +messages forever</FONT> +<BR> else +<BR> while(1) send_message(); <FONT COLOR="#FF0000">//send messages +forever</FONT> +<BR> return 0; <FONT COLOR="#FF0000">// keep the compiler happy.</FONT> +<BR>} +<BR> +<BR>int handle_input(ACE_HANDLE){ +<BR> ACE_DEBUG((LM_DEBUG,"(%t) handle_input ")); +<BR> char* data= new char[13]; +<BR> +<BR> <FONT COLOR="#FF0000">//Check if peer aborted the connection</FONT> +<BR> if(peer().recv_n(data,12)==0){ +<BR> ACE_OS::printf("Peer probably aborted connection"); +<BR> return -1; <FONT COLOR="#FF0000">//de-register from the Reactor.</FONT> +<BR> } +<BR> +<BR><FONT COLOR="#FF0000"> //Show what you got..</FONT> +<BR> ACE_OS::printf("<< %s\n",data); +<BR> +<BR><FONT COLOR="#FF0000"> //keep yourself registered</FONT> +<BR> return 0; +<BR> +<BR> } +<BR>}; + +<P>int main(int argc, char* argv[]){ +<BR> ACE_INET_Addr addr(10101); +<BR> ACE_DEBUG((LM_DEBUG,"Thread: (%t) main\n")); + +<P> <FONT COLOR="#FF0000">//Prepare to accept connections</FONT> +<BR> Acceptor myacceptor(addr,Reactor::instance()); + +<P><FONT COLOR="#FF0000"> // wait for something to happen.</FONT> +<BR> while(1) +<BR> Reactor::instance()->handle_events(); +<BR> +<BR> return 0; +<BR>} + +<P> <A HREF="ex08.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_6/ex08.html b/docs/tutorials/Chap_6/ex08.html new file mode 100644 index 00000000000..d90c00fbd67 --- /dev/null +++ b/docs/tutorials/Chap_6/ex08.html @@ -0,0 +1,96 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 8</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Acceptor/Connector" +(Connection Initialization)</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 8</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Reactor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Svc_Handler.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Acceptor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/SOCK_Acceptor.h"</FONT> +<BR><FONT COLOR="#000099">#define</FONT><FONT COLOR="#663366"> PORT_NUM +10101</FONT> +<BR><FONT COLOR="#000099">#define</FONT><FONT COLOR="#663366"> DATA_SIZE +12</FONT><FONT COLOR="#FF0000"></FONT> + +<P><FONT COLOR="#FF0000">//forward declaration</FONT> +<BR>class My_Svc_Handler;<FONT COLOR="#FF0000"></FONT> + +<P><FONT COLOR="#FF0000">//instantiate a strategy acceptor</FONT> +<BR>typedef ACE_Strategy_Acceptor<My_Svc_Handler,ACE_SOCK_ACCEPTOR> +MyAcceptor;<FONT COLOR="#FF0000"></FONT> + +<P><FONT COLOR="#FF0000">//instantiate a concurrency strategy</FONT> +<BR>typedef ACE_Process_Strategy<My_Svc_Handler> Concurrency_Strategy; + +<P><FONT COLOR="#FF0000">// Define the Service Handler</FONT> +<BR>class My_Svc_Handler: +<BR> public ACE_Svc_Handler <ACE_SOCK_STREAM,ACE_NULL_SYNCH>{ +<BR>private: +<BR> char* data; +<BR>public: +<BR> My_Svc_Handler(){ +<BR> data= new char[DATA_SIZE]; +<BR> } +<BR> My_Svc_Handler(ACE_Thread_Manager* tm){ +<BR> data= new char[DATA_SIZE]; +<BR> } +<BR> int open(void*){ +<BR> ACE_DEBUG((LM_DEBUG,"Connection +established\n")); +<BR><FONT COLOR="#FF0000"> +//Register with the reactor</FONT> +<BR> ACE_Reactor::instance()->register_handler(this, +<BR> ACE_Event_Handler::READ_MASK); +<BR> return 0; +<BR> } + +<P> int handle_input(ACE_HANDLE){ +<BR> peer().recv_n(data,DATA_SIZE); +<BR> ACE_OS::printf(?<< %s\n?,data); +<BR> +<BR><FONT COLOR="#FF0000"> // keep yourself registered +with the reactor</FONT> +<BR> return 0; +<BR> } +<BR>}; + +<P>int main(int argc, char* argv[]){ +<BR> ACE_INET_Addr addr(PORT_NUM); + +<P> <FONT COLOR="#FF0000">//Concurrency Strategy</FONT> +<BR> Concurrency_Strategy my_con_strat; + +<P><FONT COLOR="#FF0000">//Instantiate the acceptor</FONT> +<BR> MyAcceptor acceptor(addr, <FONT COLOR="#FF0000">//address to +accept on</FONT> +<BR> ACE_Reactor::instance(), <FONT COLOR="#FF0000">//the reactor +to use</FONT> +<BR> 0, <FONT COLOR="#FF0000">// dont care about creation strategy</FONT> +<BR> 0, <FONT COLOR="#FF0000">// dont care about connection estb. +strategy</FONT> +<BR> &my_con_strat);<FONT COLOR="#FF0000"> // use our new process +concurrency strategy</FONT> + +<P>while(1)<FONT COLOR="#FF0000"> // Start the reactors event loop</FONT> +<BR> ACE_Reactor::instance()->handle_events(); +<BR>} + +<P> <A HREF="ex09.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_6/ex09.html b/docs/tutorials/Chap_6/ex09.html new file mode 100644 index 00000000000..e641da20bc5 --- /dev/null +++ b/docs/tutorials/Chap_6/ex09.html @@ -0,0 +1,211 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 9</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Acceptor/Connector" +(Connection Initialization)</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 9</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Reactor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#663366"> </FONT><FONT COLOR="#006600">"ace/Svc_Handler.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Connector.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Synch.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/SOCK_Connector.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/INET_Addr.h"</FONT> + +<P><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">PORT_NUM +10101</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">DATA_SIZE +16</FONT> + +<P><FONT COLOR="#FF0000">//forward declaration</FONT> +<BR>class My_Svc_Handler; +<BR><FONT COLOR="#FF0000">//Function prototype</FONT> +<BR>static void make_connections(void *arg); + +<P><FONT COLOR="#FF0000">// Template specializations for the hashing function +for the</FONT> +<BR><FONT COLOR="#FF0000">// hash_map which is used by the cache. The cache +is used internally by the</FONT> +<BR><FONT COLOR="#FF0000">// Cached Connection Strategy . Here we use ACE_Hash_Addr</FONT> +<BR><FONT COLOR="#FF0000">// as our external identifier. This utility class +has already</FONT> +<BR><FONT COLOR="#FF0000">// overloaded the == operator and the hash() +method. (The</FONT> +<BR><FONT COLOR="#FF0000">// hashing function). The hash() method delgates +the work to</FONT> +<BR><FONT COLOR="#FF0000">// hash_i() and we use the IP address and port +to get a</FONT> +<BR><FONT COLOR="#FF0000">// a unique integer hash value.</FONT> +<BR>size_t +<BR>ACE_Hash_Addr<ACE_INET_Addr>::hash_i (const ACE_INET_Addr &addr) +const +<BR>{ +<BR> return addr.get_ip_address () + addr.get_port_number (); +<BR>} + +<P><FONT COLOR="#FF0000">//instantiate a strategy acceptor</FONT> +<BR>typedef ACE_Strategy_Connector<My_Svc_Handler,ACE_SOCK_CONNECTOR> +<BR>STRATEGY_CONNECTOR; + +<P><FONT COLOR="#FF0000">//Instantiate the Creation Strategy</FONT> +<BR>typedef ACE_NOOP_Creation_Strategy<My_Svc_Handler> +<BR> NULL_CREATION_STRATEGY; +<BR><FONT COLOR="#FF0000">//Instantiate the Concurrency Strategy</FONT> +<BR>typedef ACE_NOOP_Concurrency_Strategy<My_Svc_Handler> +<BR> NULL_CONCURRENCY_STRATEGY; +<BR><FONT COLOR="#FF0000">//Instantiate the Connection Strategy</FONT> +<BR>typedef ACE_Cached_Connect_Strategy<My_Svc_Handler, +<BR> +ACE_SOCK_CONNECTOR, +<BR> +ACE_SYNCH_RW_MUTEX> +<BR> CACHED_CONNECT_STRATEGY; +<BR> +<BR>class My_Svc_Handler: +<BR>public ACE_Svc_Handler <ACE_SOCK_STREAM,ACE_MT_SYNCH>{ +<BR>private: +<BR>char* data; + +<P>public: +<BR>My_Svc_Handler(){ +<BR>data= new char[DATA_SIZE]; +<BR> } +<BR>My_Svc_Handler(ACE_Thread_Manager* tm){ +<BR>data= new char[DATA_SIZE]; +<BR> } +<BR><FONT COLOR="#FF0000">//Called before the service handler is recycled..</FONT> +<BR>int +<BR>recycle (void *a=0){ +<BR> ACE_DEBUG ((LM_DEBUG, +<BR> "(%P|%t) recycling Svc_Handler %d with handle %d\n", +<BR> +this, this->peer ().get_handle ())); +<BR> return 0; +<BR> } + +<P>int open(void*){ +<BR> ACE_DEBUG((LM_DEBUG,"(%t)Connection established \n")); +<BR> +<BR> +<BR> + +<P><FONT COLOR="#FF0000"> //Register the service handler with the +reactor</FONT> +<BR> ACE_Reactor::instance() ->register_handler(this,ACE_Event_Handler::READ_MASK); +<BR> activate(THR_NEW_LWP|THR_DETACHED); +<BR> return 0; +<BR> } + +<P>int handle_input(ACE_HANDLE){ +<BR> ACE_DEBUG((LM_DEBUG,"Got input in thread: (%t) \n")); +<BR> peer().recv_n(data,DATA_SIZE); +<BR> ACE_DEBUG((LM_DEBUG,"<< %s\n",data)); + +<P> <FONT COLOR="#FF0000">//keep yourself registered with the reactor</FONT> +<BR> return 0; +<BR>} + +<P>int svc(void){ +<BR><FONT COLOR="#FF0000"> //send a few messages and then mark connection +as idle so that it can be recycled later.</FONT> +<BR> ACE_DEBUG((LM_DEBUG,"Started the service routine \n")); + +<P> for(int i=0;i<3;i++){ +<BR> ACE_DEBUG((LM_DEBUG,"(%t)>>Hello World\n")); +<BR> ACE_OS::fflush(stdout); +<BR> peer().send_n("Hello World",sizeof("Hello World")); +<BR> } + +<P> <FONT COLOR="#FF0000">//Mark the service handler as being idle +now and let the other threads reuse this connection</FONT> +<BR> this->idle(1); + +<P> <FONT COLOR="#FF0000">//Wait for the thread to die</FONT> +<BR> this->thr_mgr()->wait(); +<BR> return 0; +<BR> } +<BR>}; +<BR>ACE_INET_Addr *addr; + +<P>int main(int argc, char* argv[]){ +<BR> addr= new ACE_INET_Addr(PORT_NUM,argv[1]); +<BR><FONT COLOR="#FF0000"> //Creation Strategy</FONT> +<BR> NULL_CREATION_STRATEGY creation_strategy; + +<P><FONT COLOR="#FF0000"> //Concurrency Strategy</FONT> +<BR> NULL_CONCURRENCY_STRATEGY concurrency_strategy; + +<P><FONT COLOR="#FF0000"> //Connection Strategy</FONT> +<BR> CACHED_CONNECT_STRATEGY caching_connect_strategy; +<BR> + +<P><FONT COLOR="#FF0000"> //instantiate the connector</FONT> +<BR> STRATEGY_CONNECTOR connector( +<BR> ACE_Reactor::instance(),<FONT COLOR="#FF0000"> //the reactor +to use</FONT> +<BR> &creation_strategy, +<BR> &caching_connect_strategy, +<BR> &concurrency_strategy); +<BR><FONT COLOR="#FF0000"> //Use the thread manager to spawn +a single thread to</FONT> +<BR><FONT COLOR="#FF0000"> //connect multiple times passing it the +address</FONT> +<BR><FONT COLOR="#FF0000"> //of the strategy connector</FONT> +<BR> if(ACE_Thread_Manager::instance()->spawn( +<BR> (ACE_THR_FUNC) make_connections, +<BR> (void *) &connector, +<BR> THR_NEW_LWP) == -1) +<BR> ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n%a", "client thread spawn +failed")); + +<P>while(1) /* Start the reactor?s event loop */ +<BR> ACE_Reactor::instance()->handle_events(); +<BR>} + +<P><FONT COLOR="#FF0000">//Connection establishment function, tries to +establish connections</FONT> +<BR><FONT COLOR="#FF0000">//to the same server again and re-uses the connections +from the</FONT> +<BR><FONT COLOR="#FF0000">//cache</FONT> +<BR>void make_connections(void *arg){ +<BR> ACE_DEBUG((LM_DEBUG,"(%t)Prepared to connect \n")); +<BR> STRATEGY_CONNECTOR *connector= (STRATEGY_CONNECTOR*) arg; +<BR> for (int i = 0; i < 10; i++){ +<BR> My_Svc_Handler *svc_handler = 0; +<BR> + +<P> <FONT COLOR="#FF0000">// Perform a blocking connect to the server +using the Strategy</FONT> +<BR><FONT COLOR="#FF0000"> // Connector with a connection caching +strategy. Since we are</FONT> +<BR><FONT COLOR="#FF0000"> // connecting to the same <server_addr> +these calls will return the</FONT> +<BR><FONT COLOR="#FF0000"> // same dynamically allocated <Svc_Handler> +for each <connect> call.</FONT> +<BR> if (connector->connect (svc_handler, *addr) == -1){ +<BR> ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "connection failed\n")); +<BR> return; +<BR> } + +<P><FONT COLOR="#FF0000"> // Rest for a few seconds so that the connection +has been freed up</FONT> +<BR> ACE_OS::sleep (5); +<BR> } +<BR>} +<BR> +<BR> <A HREF="ex10.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_6/ex10.html b/docs/tutorials/Chap_6/ex10.html new file mode 100644 index 00000000000..872c1c44a82 --- /dev/null +++ b/docs/tutorials/Chap_6/ex10.html @@ -0,0 +1,110 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 10</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Acceptor/Connector" +(Connection Initialization)</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 10</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Reactor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Svc_Handler.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Acceptor.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/SOCK_Acceptor.h"</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">PORT_NUM +10101</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">DATA_SIZE +12</FONT> + +<P><FONT COLOR="#FF0000">//forward declaration</FONT> +<BR>class My_Svc_Handler; + +<P><FONT COLOR="#FF0000">//Create the Acceptor class</FONT> +<BR>typedef ACE_Acceptor<My_Event_Handler,ACE_SOCK_ACCEPTOR> +<BR>MyAcceptor; + +<P><FONT COLOR="#FF0000">//Create an event handler similar to as seen in +example 2.</FONT> +<BR><FONT COLOR="#FF0000">//We have to overload the get_handle() method +and write the peer()</FONT> +<BR><FONT COLOR="#FF0000">//method. We also provide the data member peer_ +as the underlying</FONT> +<BR><FONT COLOR="#FF0000">//stream which is used.</FONT> +<BR>class My_Event_Handler: +<BR> public ACE_Event_Handler{ +<BR>private: +<BR>char* data; +<BR><FONT COLOR="#FF0000">//Add a new attribute for the underlying stream +which will be used by the Event Handler</FONT> +<BR>ACE_SOCK_Stream peer_; +<BR>public: +<BR>My_Event_Handler(){ +<BR> data= new char[DATA_SIZE]; +<BR> } + +<P>int +<BR>open(void*){ +<BR> ACE_DEBUG((LM_DEBUG,"Connection established\n")); +<BR><FONT COLOR="#FF0000"> //Register the event handler with the reactor</FONT> +<BR> ACE_Reactor::instance()->register_handler(this, ACE_Event_Handler::READ_MASK); +<BR> return 0; +<BR> } + +<P>int +<BR>handle_input(ACE_HANDLE){ +<BR> <FONT COLOR="#FF0000">// After using the peer() method of our +ACE_Event_Handler to obtain a</FONT> +<BR><FONT COLOR="#FF0000"> //reference to the underlying stream of +the service handler class we</FONT> +<BR><FONT COLOR="#FF0000"> //call recv_n() on it to read the data +which has been received. This</FONT> +<BR><FONT COLOR="#FF0000"> //data is stored in the data array and +then printed out</FONT> +<BR> peer().recv_n(data,DATA_SIZE); +<BR> ACE_OS::printf("<< %s\n",data); + +<P> <FONT COLOR="#FF0000">// keep yourself registered with the reactor</FONT> +<BR> return 0; +<BR> } + +<P><FONT COLOR="#FF0000">// new method which returns the handle to the +reactor when it asks for it.</FONT> +<BR>ACE_HANDLE +<BR>get_handle(void) const{ +<BR> return this->peer_.get_handle(); +<BR> } + +<P><FONT COLOR="#FF0000">//new method which returns a reference to the +peer stream</FONT> +<BR>ACE_SOCK_Stream & +<BR>peer(void) const{ +<BR> return (ACE_SOCK_Stream &) this->peer_; +<BR> } +<BR>}; + +<P>int main(int argc, char* argv[]){ +<BR> ACE_INET_Addr addr(PORT_NUM); +<BR> <FONT COLOR="#FF0000">//create the acceptor</FONT> +<BR> MyAcceptor acceptor(addr,<FONT COLOR="#FF0000"> //address to +accept on</FONT> +<BR> ACE_Reactor::instance()); <FONT COLOR="#FF0000">//the reactor +to use</FONT> +<BR>while(1)<FONT COLOR="#FF0000"> // Start the reactors event loop</FONT> +<BR> ACE_Reactor::instance()->handle_events(); +<BR>} +<BR> +<BR> <A HREF="../Chap_7/ex01.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_7/Chap_7.zip b/docs/tutorials/Chap_7/Chap_7.zip Binary files differnew file mode 100644 index 00000000000..0073e63d504 --- /dev/null +++ b/docs/tutorials/Chap_7/Chap_7.zip diff --git a/docs/tutorials/Chap_7/ex01.html b/docs/tutorials/Chap_7/ex01.html new file mode 100644 index 00000000000..59c8a3745d0 --- /dev/null +++ b/docs/tutorials/Chap_7/ex01.html @@ -0,0 +1,90 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 1</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Message Queue"</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 1</FONT> +<BR><FONT COLOR="#000099">#include</FONT> "<FONT COLOR="#006600">ace/Message_Queue.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Get_Opt.h"</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">SIZE_BLOCK +1</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">NO_MSGS +10</FONT> + +<P>class QTest{ +<BR>public: +<BR>QTest():no_msgs_(NO_MSGS){ +<BR> <FONT COLOR="#FF0000">//First create a message queue of default +size.</FONT> +<BR> if(!(this->mq_=new ACE_Message_Queue<ACE_NULL_SYNCH> ())) +<BR> ACE_DEBUG((LM_ERROR,"Error in message queue initialization \n")); +<BR> } +<BR> +<BR>int start_test(){ +<BR> for(int i=0; i<no_msgs_;i++){ +<BR> <FONT COLOR="#FF0000">//create a new message block of size 1</FONT> +<BR> ACE_Message_Block *mb= new ACE_Message_Block(SIZE_BLOCK);<FONT COLOR="#FF0000"></FONT> + +<P><FONT COLOR="#FF0000"> //Insert data into the message block using +the rd_ptr</FONT> +<BR> *mb->wr_ptr()=i; + +<P><FONT COLOR="#FF0000"> //Be careful to advance the wr_ptr</FONT> +<BR> mb->wr_ptr(1); + +<P> <FONT COLOR="#FF0000">//Enqueue the message block onto the message +queue</FONT> +<BR> if(this->mq_->enqueue_prio(mb)==-1){ +<BR> ACE_DEBUG((LM_ERROR,"\nCould not enqueue on to mq!!\n")); +<BR> return -1; +<BR> } +<BR> +<BR> ACE_DEBUG((LM_INFO,"EQd data: %d\n",*mb->rd_ptr())); +<BR> } <FONT COLOR="#FF0000">//end for</FONT> + +<P><FONT COLOR="#FF0000">//Now dequeue all the messages</FONT> +<BR>this->dequeue_all(); +<BR>return 0; +<BR> } + +<P>void dequeue_all(){ +<BR> ACE_DEBUG((LM_INFO,"\n\nBeginning DQ \n")); +<BR> ACE_DEBUG((LM_INFO,"No. of Messages on Q:%d Bytes on Q:%d \n",mq_->message_count(), +mq_->message_bytes())); +<BR> ACE_Message_Block *mb; + +<P> <FONT COLOR="#FF0000">//dequeue the head of the message queue +until no more messages are left</FONT> +<BR> for(int i=0;i<no_msgs_;i++){ +<BR> mq_->dequeue_head(mb); +<BR> ACE_DEBUG((LM_INFO,"DQd data %d\n",*mb->rd_ptr())); +<BR> } +<BR> } +<BR>private: +<BR> ACE_Message_Queue<ACE_NULL_SYNCH> *mq_; +<BR> int no_msgs_; +<BR>}; +<BR> + +<P>int main(int argc, char* argv[]){ +<BR> QTest test; +<BR> if(test.start_test()<0) +<BR> ACE_DEBUG((LM_ERROR,"Program failure \n")); +<BR>} + +<P> <A HREF="ex02.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_7/ex02.html b/docs/tutorials/Chap_7/ex02.html new file mode 100644 index 00000000000..3062e546994 --- /dev/null +++ b/docs/tutorials/Chap_7/ex02.html @@ -0,0 +1,165 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 2</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Message Queue"</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 2</FONT><FONT COLOR="#000099"></FONT> + +<P><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Message_Queue.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Get_Opt.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> "<FONT COLOR="#006600">ace/Malloc_T.h"</FONT> +<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">SIZE_BLOCK +1</FONT> + +<P>class Args{ +<BR>public: +<BR>Args(int argc, char*argv[],int& no_msgs, ACE_Message_Queue<ACE_NULL_SYNCH>* +&mq){ +<BR> ACE_Get_Opt get_opts(argc,argv,"h:l:t:n:xsd"); +<BR> while((opt=get_opts())!=-1) +<BR> switch(opt){ +<BR> case 'n': +<BR> <FONT COLOR="#FF0000"> //set the number of messages we +wish to enqueue and dequeue</FONT> +<BR> no_msgs=ACE_OS::atoi(get_opts.optarg); +<BR> ACE_DEBUG((LM_INFO,"Number of Messages %d \n",no_msgs)); +<BR> break; + +<P> case 'h': +<BR> <FONT COLOR="#FF0000">//set the high water mark</FONT> +<BR> hwm=ACE_OS::atoi(get_opts.optarg); +<BR> mq->high_water_mark(hwm); +<BR> ACE_DEBUG((LM_INFO,"High Water Mark %d msgs \n",hwm)); +<BR> break; +<BR> case 'l': +<BR> <FONT COLOR="#FF0000"> //set the low water mark</FONT> +<BR> lwm=ACE_OS::atoi(get_opts.optarg); +<BR> mq->low_water_mark(lwm); +<BR> ACE_DEBUG((LM_INFO,"Low Water Mark %d msgs \n",lwm)); +<BR> break; +<BR> default: +<BR> ACE_DEBUG((LM_ERROR, "Usage -n<no. messages> -h<hwm> +-l<lwm>\n")); +<BR> break; +<BR> } +<BR> } + +<P>private: +<BR> int opt; +<BR> int hwm; +<BR> int lwm; +<BR>}; +<BR> +<BR> + +<P>class QTest{ +<BR>public: +<BR>QTest(int argc, char*argv[]){ +<BR><FONT COLOR="#FF0000"> //First create a message queue of default +size.</FONT> +<BR> if(!(this->mq_=new ACE_Message_Queue<ACE_NULL_SYNCH> ())) +<BR> ACE_DEBUG((LM_ERROR,"Error in message queue initialization \n")); +<BR> +<BR> <FONT COLOR="#FF0000">//Use the arguments to set the water marks +and the no of messages</FONT> +<BR> args_ = new Args(argc,argv,no_msgs_,mq_); +<BR> } +<BR>int start_test(){ +<BR> for(int i=0; i<no_msgs_;i++){ +<BR> <FONT COLOR="#FF0000">//Create a new message block of data buffer +size 1</FONT> +<BR> ACE_Message_Block * mb= new ACE_Message_Block(SIZE_BLOCK); +<BR> +<BR><FONT COLOR="#FF0000"> //Insert data into the message block using +the rd_ptr</FONT> +<BR> *mb->wr_ptr()=i; +<BR> +<BR> <FONT COLOR="#FF0000">//Be careful to advance the wr_ptr</FONT> +<BR> mb->wr_ptr(1); + +<P><FONT COLOR="#FF0000"> //Enqueue the message block onto the message +queue</FONT> +<BR> if(this->mq_->enqueue_prio(mb)==-1){ +<BR> ACE_DEBUG((LM_ERROR,"\nCould not enqueue on to mq!!\n")); +<BR> return -1; +<BR> } +<BR> +<BR> ACE_DEBUG((LM_INFO,"EQd data: %d\n",*mb->rd_ptr())); +<BR> } +<BR> <FONT COLOR="#FF0000">//Use the iterators to read</FONT> +<BR> this->read_all(); + +<P> <FONT COLOR="#FF0000">//Dequeue all the messages</FONT> +<BR> this->dequeue_all(); +<BR> return 0; +<BR> } + +<P>void read_all(){ +<BR> ACE_DEBUG((LM_INFO,"No. of Messages on Q:%d Bytes on Q:%d \n", +mq_->message_count(),mq_->message_bytes())); +<BR> ACE_Message_Block *mb; + +<P> <FONT COLOR="#FF0000">//Use the forward iterator</FONT> +<BR> ACE_DEBUG((LM_INFO,"\n\nBeginning Forward Read \n")); +<BR> ACE_Message_Queue_Iterator<ACE_NULL_SYNCH> mq_iter_(*mq_); +<BR> while(mq_iter_.next(mb)){ +<BR> mq_iter_.advance(); +<BR> ACE_DEBUG((LM_INFO,"Read data %d\n",*mb->rd_ptr())); +<BR> } +<BR> +<BR> <FONT COLOR="#FF0000">//Use the reverse iterator</FONT> +<BR> ACE_DEBUG((LM_INFO,"\n\nBeginning Reverse Read \n")); +<BR> ACE_Message_Queue_Reverse_Iterator<ACE_NULL_SYNCH> +<BR> mq_rev_iter_(*mq_); +<BR> while(mq_rev_iter_.next(mb)){ +<BR> mq_rev_iter_.advance(); +<BR> ACE_DEBUG((LM_INFO,"Read data %d\n",*mb->rd_ptr())); +<BR> } +<BR> +<BR> } + +<P>void dequeue_all(){ +<BR> ACE_DEBUG((LM_INFO,"\n\nBeginning DQ \n")); +<BR> ACE_DEBUG((LM_INFO,"No. of Messages on Q:%d Bytes on Q:%d \n", +mq_->message_count(),mq_->message_bytes())); +<BR> ACE_Message_Block *mb; + +<P><FONT COLOR="#FF0000"> //dequeue the head of the message queue +until no more messages are left</FONT> +<BR> for(int i=0;i<no_msgs_;i++){ +<BR> mq_->dequeue_head(mb); +<BR> ACE_DEBUG((LM_INFO,"DQd data %d\n",*mb->rd_ptr())); +<BR> } +<BR> } + +<P>private: +<BR> Args *args_; +<BR> ACE_Message_Queue<ACE_NULL_SYNCH> *mq_; +<BR> int no_msgs_; +<BR>}; +<BR> +<BR> + +<P>int main(int argc, char* argv[]){ +<BR> QTest test(argc,argv); +<BR> if(test.start_test()<0) +<BR> ACE_DEBUG((LM_ERROR,"Program failure \n")); +<BR> +<BR>} + +<P> <A HREF="ex03.html">Next Example</A> +</BODY> +</HTML> diff --git a/docs/tutorials/Chap_7/ex03.html b/docs/tutorials/Chap_7/ex03.html new file mode 100644 index 00000000000..03b6dda63d6 --- /dev/null +++ b/docs/tutorials/Chap_7/ex03.html @@ -0,0 +1,158 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="Author" CONTENT="Ambreen Ilyas"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> + <TITLE>Example 3</TITLE> +</HEAD> +<BODY> +<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> +<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers +Guide.</FONT> +<BR><FONT COLOR="#CC0000">//// Chapter: "The Message Queue"</FONT> +<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> +<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> +<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> +<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> +<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> + +<P><FONT COLOR="#CC0000">//Example 3</FONT> +<BR><FONT COLOR="#000099">#include</FONT> "<FONT COLOR="#006600">ace/Message_Queue.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> "<FONT COLOR="#006600">ace/Get_Opt.h"</FONT> +<BR><FONT COLOR="#000099">#include</FONT> "<FONT COLOR="#006600">ace/OS.h"</FONT> + +<P>class Args{ +<BR>public: +<BR>Args(int argc, char*argv[],int& no_msgs, int& time,ACE_Message_Queue<ACE_NULL_SYNCH>* +&mq){ +<BR> ACE_Get_Opt get_opts(argc,argv,"h:l:t:n:xsd"); +<BR> while((opt=get_opts())!=-1) +<BR> switch(opt){ +<BR> case 't': +<BR> time=ACE_OS::atoi(get_opts.optarg); +<BR> ACE_DEBUG((LM_INFO,"Time: %d \n",time)); +<BR> break; +<BR> case 'n': +<BR> no_msgs=ACE_OS::atoi(get_opts.optarg); +<BR> ACE_DEBUG((LM_INFO,"Number of Messages %d \n",no_msgs)); +<BR> break; +<BR> case 'x': +<BR> mq=ACE_Message_Queue_Factory<ACE_NULL_SYNCH>:: create_laxity_message_queue(); +<BR> ACE_DEBUG((LM_DEBUG,"Creating laxity q\n")); +<BR> break; +<BR> case 'd': +<BR> mq=ACE_Message_Queue_Factory<ACE_NULL_SYNCH>:: create_deadline_message_queue(); +<BR> ACE_DEBUG((LM_DEBUG,"Creating deadline q\n")); +<BR> break; +<BR> case 's': +<BR> mq=ACE_Message_Queue_Factory<ACE_NULL_SYNCH>:: create_static_message_queue(); +<BR> ACE_DEBUG((LM_DEBUG,"Creating static q\n")); +<BR> break; +<BR> case 'h': +<BR> hwm=ACE_OS::atoi(get_opts.optarg); +<BR> mq->high_water_mark(hwm); +<BR> ACE_DEBUG((LM_INFO,"High Water Mark %d msgs \n",hwm)); +<BR> break; +<BR> case 'l': +<BR> lwm=ACE_OS::atoi(get_opts.optarg); +<BR> mq->low_water_mark(lwm); +<BR> ACE_DEBUG((LM_INFO,"Low Water Mark %d msgs \n",lwm)); +<BR> break; +<BR> default: +<BR> ACE_DEBUG((LM_ERROR,"Usage specify queue type\n")); +<BR> break; +<BR> } +<BR> } + +<P>private: +<BR> int opt; +<BR> int hwm; +<BR> int lwm; +<BR>}; +<BR> +<BR> + +<P>class QTest{ +<BR>public: +<BR>QTest(int argc, char*argv[]){ +<BR> args_ = new Args(argc,argv,no_msgs_,time_,mq_); +<BR> array_ =new ACE_Message_Block*[no_msgs_]; +<BR> } + +<P>int start_test(){ +<BR> for(int i=0; i<no_msgs_;i++){ +<BR> ACE_NEW_RETURN (array_[i], ACE_Message_Block (1), -1); +<BR> set_deadline(i); +<BR> set_execution_time(i); +<BR> enqueue(i); +<BR> } + +<P> this->dequeue_all(); +<BR> return 0; +<BR> } + +<P><FONT COLOR="#FF0000">//Call the underlying ACE_Message_Block method +msg_deadline_time() to set the deadline of the message.</FONT> +<BR>void set_deadline(int msg_no){ +<BR> float temp=(float) time_/(msg_no+1); +<BR> ACE_Time_Value tv; +<BR> tv.set(temp); +<BR> ACE_Time_Value deadline(ACE_OS::gettimeofday()+tv); +<BR> array_[msg_no]->msg_deadline_time(deadline); +<BR> ACE_DEBUG((LM_INFO,"EQd with DLine %d:%d\n", deadline.sec(),deadline.usec())); +<BR> } + +<P><FONT COLOR="#FF0000">//Call the underlying ACE_Message_Block method +to set the execution time</FONT> +<BR>void set_execution_time(int msg_no){ +<BR> float temp=(float) time_/10*msg_no; +<BR> ACE_Time_Value tv; +<BR> tv.set(temp); +<BR> ACE_Time_Value xtime(ACE_OS::gettimeofday()+tv); +<BR> array_[msg_no]->msg_execution_time (xtime); +<BR> ACE_DEBUG((LM_INFO,"Xtime %d:%d\n",xtime.sec(),xtime.usec())); +<BR> } + +<P>void enqueue(int msg_no){ +<BR><FONT COLOR="#FF0000"> //Set the value of data at the read position</FONT> +<BR> *array_[msg_no]->rd_ptr()=msg_no; +<BR><FONT COLOR="#FF0000"> //Advance write pointer</FONT> +<BR> array_[msg_no]->wr_ptr(1); +<BR><FONT COLOR="#FF0000"> //Enqueue on the message queue</FONT> +<BR> if(mq_->enqueue_prio(array_[msg_no])==-1){ +<BR> ACE_DEBUG((LM_ERROR,"\nCould not enqueue on to mq!!\n")); +<BR> return; +<BR> } +<BR> ACE_DEBUG((LM_INFO,"Data %d\n",*array_[msg_no]->rd_ptr())); +<BR> } + +<P>void dequeue_all(){ +<BR> ACE_DEBUG((LM_INFO,"Beginning DQ \n")); +<BR> ACE_DEBUG((LM_INFO,"No. of Messages on Q:%d Bytes on Q:%d \n", +mq_->message_count(),mq_->message_bytes())); +<BR> for(int i=0;i<no_msgs_ ;i++){ +<BR> ACE_Message_Block *mb; +<BR> if(mq_->dequeue_head(mb)==-1){ +<BR> ACE_DEBUG((LM_ERROR,'\nCould not dequeue from mq!!\n")); +<BR> return; +<BR> } +<BR> ACE_DEBUG((LM_INFO,"DQd data %d\n",*mb->rd_ptr())); +<BR> } +<BR> } +<BR>private: +<BR> Args *args_; +<BR> ACE_Message_Block **array_; +<BR> ACE_Message_Queue<ACE_NULL_SYNCH> *mq_; +<BR> int no_msgs_; +<BR> int time_; +<BR>}; + +<P>int main(int argc, char* argv[]){ +<BR> QTest test(argc,argv); +<BR> if(test.start_test()<0) +<BR> ACE_DEBUG((LM_ERROR,"Program failure \n")); +<BR> +<BR>} +<BR> +</BODY> +</HTML> diff --git a/docs/tutorials/guide-tutorials.html b/docs/tutorials/guide-tutorials.html new file mode 100644 index 00000000000..762e32b5557 --- /dev/null +++ b/docs/tutorials/guide-tutorials.html @@ -0,0 +1,48 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> +</HEAD> +<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#333333" ALINK="#FE0000"> + +<HR WIDTH="100%"><P> +<H3>Online Examples from the ACE Programmers Guide</H3> + +The following page has links to the example code that is presented in +the <A HREF="http://www.cs.wustl.edu/~schmidt/ACE-tutorials.ps.gz">ACE +programmers guide</a>. The guide was created at <A +HREF="http://www.hns.com">Hughes Network Systems</A>. Questions +regarding the guide should be sent to <A +HREF="mailto:usyyid@hns.com">Umar Syyid <usyyid@hns.com></A> + +<P> +<HR WIDTH="100%"> +<H3>Chapter Breakdown</H3> + + +<H4> Chapter 2: <A HREF="Chap_2/ex01.html">IPC _SAP</A></H4> + +<H4> Chapter 3: <A HREF="Chap_3/ex01.html">Memory Management</A></H4> + +<H4> Chapter 4: <A HREF="Chap_4/ex01.html">Thread Management</A></H4> + +<H4> Chapter 5: Tasks and Active Objects</H4> + +<H4> Chapter 6: <A HREF="Chap_5/ex01.html">The Reactor</A></H4> + +<H4> Chapter 7: <A HREF="Chap_6/ex01.html">The Acceptor and Connector</A></H4> + +<H4> Chapter 8: The Service Configurator</H4> + +<H4> Chapter 9: <A HREF="Chap_7/ex01.html">Message Queues</A></H4> + +<P><HR> + +<P>Back to the <A +HREF="http://www.cs.wustl.edu/~schmidt/ACE_wrappers/docs/ACE-tutorials.html">ACE +tutorials</A> page. + +<P> +<!--#include virtual="/~schmidt/cgi-sig.html" --> +</BODY> +</HTML> diff --git a/docs/tutorials/index.html b/docs/tutorials/online-tutorials.html index f56cde885a6..f56cde885a6 100644 --- a/docs/tutorials/index.html +++ b/docs/tutorials/online-tutorials.html |