changeset 5:aa427c18ffe2

Separation of Rot13Module and Rot13Handler into 2 separate files
author Zoltan K
date Sat, 20 Mar 2010 00:06:08 +0100
parents 81af35509f71
children e39c4397764c
files src/examples/rot13/CMakeLists.txt src/examples/rot13/Rot13Handler.cpp src/examples/rot13/Rot13Handler.hpp src/examples/rot13/Rot13Module.cpp src/examples/rot13/Rot13Module.hpp src/examples/rot13/main.cpp
diffstat 6 files changed, 90 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/src/examples/rot13/CMakeLists.txt	Fri Mar 19 22:56:21 2010 +0100
+++ b/src/examples/rot13/CMakeLists.txt	Sat Mar 20 00:06:08 2010 +0100
@@ -2,6 +2,7 @@
     main.cpp
     Buffer.cpp
     Rot13Module.cpp
+    Rot13Handler.cpp
    )
 
 ADD_EXECUTABLE(rot13 ${ROT13_SRC})
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/examples/rot13/Rot13Handler.cpp	Sat Mar 20 00:06:08 2010 +0100
@@ -0,0 +1,32 @@
+#include "Rot13Handler.hpp"
+
+char     Rot13Char(char c)
+{
+    if ((c >= ('a' + 13) && c <= 'z') || (c >= ('A' + 13) && c <= 'Z' ))
+        c -= 13;
+    else if ((c >= 'a' && c < 'a' + 13) || (c >= 'A' && c < 'A' + 13))
+        c += 13;
+    return (c);
+}
+
+zia::api::handler::EHook    Rot13Handler::getHook(void) const
+{
+    return (zia::api::handler::ResponseBodyModifier);
+}
+
+int     Rot13Handler::operator()(zia::api::http::ITransaction &, std::istream &, std::ostream &)
+{
+    return (0);
+}
+
+int     Rot13Handler::operator()(std::istream & is, std::ostream & os)
+{
+    char	c;
+
+    while (!is.eof())
+    {
+        is.get(c);
+        os << Rot13Char(c);
+    }
+    return (0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/examples/rot13/Rot13Handler.hpp	Sat Mar 20 00:06:08 2010 +0100
@@ -0,0 +1,54 @@
+#ifndef __ZIA_ROT13_HANDLER_HPP__
+# define __ZIA_ROT13_HANDLER_HPP__
+
+# include <ostream>
+# include <istream>
+
+# include "handler/IHttpHandler.hpp"
+
+/**
+ ** @brief Function that convert a char to its rot13 value
+ ** @param [in] The char to encode
+ ** @return The char encoded
+ */
+char    Rot13Char(char c);
+
+/**
+ ** @brief this class is an simple implementation of the StreamIt IHttpHandler interface
+ */
+class   Rot13Handler : public zia::api::handler::IHttpHandler
+{
+public:
+    virtual ~Rot13Handler(void) { }
+
+    /**
+     ** @brief Getter to know were we should plug this hook.
+     ** @return Enumeration telling when we should call this handler.
+     */
+    virtual zia::api::handler::EHook    getHook(void) const;
+
+    /**
+     ** @brief This is the normal method the server should call.
+     ** But since the purpose of this example is to show how
+     ** std::istream, std::ostream and std::streambuf works,
+     ** we overload the functor so we haven't to implement ITransaction.
+     */
+    virtual int     operator()(zia::api::http::ITransaction & transac,
+                               std::istream & is,
+                               std::ostream & os);
+
+    /**
+     ** @brief This is the method we will call in our example.
+     ** It is the same as the functor defined in the interface,
+     ** except there is no ITransaction parameter.
+     ** @param [in] input stream where to read data
+     ** @param [in] ouput stream where to write data
+     ** @return an integer TODO define an enum XXX
+     */
+    int     operator()(std::istream & is,
+                       std::ostream & os);
+
+};
+
+#endif	/* ! __ZIA_ROT13_HANDLER_HPP__ */
+
--- a/src/examples/rot13/Rot13Module.cpp	Fri Mar 19 22:56:21 2010 +0100
+++ b/src/examples/rot13/Rot13Module.cpp	Sat Mar 20 00:06:08 2010 +0100
@@ -1,35 +1,5 @@
 #include "Rot13Module.hpp"
-
-char     Rot13Char(char c)
-{
-    if ((c >= ('a' + 13) && c <= 'z') || (c >= ('A' + 13) && c <= 'Z' ))
-        c -= 13;
-    else if ((c >= 'a' && c < 'a' + 13) || (c >= 'A' && c < 'A' + 13))
-        c += 13;
-    return (c);
-}
-
-zia::api::handler::EHook    Rot13Handler::getHook(void) const
-{
-    return (zia::api::handler::ResponseBodyModifier);
-}
-
-int     Rot13Handler::operator()(zia::api::http::ITransaction &, std::istream &, std::ostream &)
-{
-    return (0);
-}
-
-int     Rot13Handler::operator()(std::istream & is, std::ostream & os)
-{
-    char	c;
-
-    while (!is.eof())
-    {
-        is.get(c);
-        os << Rot13Char(c);
-    }
-    return (0);
-}
+#include "Rot13Handler.hpp"
 
 ModRot13::ModRot13(void)
     : _name("Rot13Module"),
--- a/src/examples/rot13/Rot13Module.hpp	Fri Mar 19 22:56:21 2010 +0100
+++ b/src/examples/rot13/Rot13Module.hpp	Sat Mar 20 00:06:08 2010 +0100
@@ -1,52 +1,11 @@
 #ifndef _ZIA_ROT13_MODULE_HPP_
 # define _ZIA_ROT13_MODULE_HPP_
 
-# include <iostream>
-
-# include "handler/IHttpHandler.hpp"
 # include "http/ITransaction.hpp"
 # include "IConfig.hpp"
+# include "handler/IHandler.hpp"
 # include "IModule.hpp"
 
-char    Rot13Char(char c);
-
-/**
- ** @brief this class is an simple implementation of the StreamIt IHttpHandler interface
- */
-class   Rot13Handler : public zia::api::handler::IHttpHandler
-{
-public:
-    virtual ~Rot13Handler(void) { }
-
-    /**
-     ** @brief Getter to know were we should plug this hook.
-     ** @return Enumeration telling when we should call this handler.
-     */
-    virtual zia::api::handler::EHook    getHook(void) const;
-
-    /**
-     ** @brief This is the normal method the server should call.
-     ** But since the purpose of this example is to show how
-     ** std::istream, std::ostream and std::streambuf works,
-     ** we overload the functor so we haven't to implement ITransaction.
-     */
-    virtual int     operator()(zia::api::http::ITransaction & transac,
-                               std::istream & is,
-                               std::ostream & os);
-
-    /**
-     ** @brief This is the method we will call in our example.
-     ** It is the same as the functor defined in the interface,
-     ** except there is no ITransaction parameter.
-     ** @param [in] input stream where to read data
-     ** @param [in] ouput stream where to write data
-     ** @return an integer TODO define an enum XXX
-     */
-    int     operator()(std::istream & is,
-                       std::ostream & os);
-
-};
-
 /**
  ** @brief this class is an simple implementation of the StreamIt IModule interface
  */
--- a/src/examples/rot13/main.cpp	Fri Mar 19 22:56:21 2010 +0100
+++ b/src/examples/rot13/main.cpp	Sat Mar 20 00:06:08 2010 +0100
@@ -2,6 +2,7 @@
 #include <vector>
 
 #include "Rot13Module.hpp"
+#include "Rot13Handler.hpp"
 #include "Buffer.hpp"
 
 void            process_stream(std::istream & is, std::ostream & os)