/home/greg/src/restcgi-test/src/resource.h

00001 /*
00002 Copyright (c) 2009 zooml.com
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a copy
00005 of this software and associated documentation files (the "Software"), to deal
00006 in the Software without restriction, including without limitation the rights
00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008 copies of the Software, and to permit persons to whom the Software is
00009 furnished to do so, subject to the following conditions:
00010 
00011 The above copyright notice and this permission notice shall be included in
00012 all copies or substantial portions of the Software.
00013 
00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020 THE SOFTWARE.
00021 */
00022 #ifndef restcgi_resource_h
00023 #define restcgi_resource_h
00024 #include "apidefs.h"
00025 #include "method_e.h"
00026 #include "content.h"
00027 #include "status_code_e.h"
00028 #include "version.h"
00029 #include <uripp/path.h>
00030 #include <uripp/query.h>
00031 #include <utility>
00032 #include <boost/shared_ptr.hpp>
00033 #include <boost/weak_ptr.hpp>
00034 namespace restcgi {
00035     class method;
00036     class version;
00037     class version_tag;
00038     class request_hdr;
00039     class response_hdr;
00040     class content_hdr;
00042     class RESTCGI_API uri_info {
00043     public:
00044         typedef restcgi::method method_type; 
00045         typedef boost::shared_ptr<method_type> method_pointer; 
00046         uri_info(); 
00047         uri_info(method_pointer m); 
00048         const uripp::path& path() const; 
00049         const uripp::query& query() const; 
00050         void method(method_pointer m); 
00051     private:
00052         method_pointer method_;
00053     };
00083     class RESTCGI_API resource {
00084     public:
00085         typedef boost::shared_ptr<resource> pointer; 
00086         typedef boost::shared_ptr<const resource> const_pointer; 
00087         typedef restcgi::method method_type; 
00088         typedef boost::shared_ptr<method_type> method_pointer; 
00089         typedef uripp::path uri_path_type; 
00090         typedef restcgi::uri_info uri_info_type; 
00091         typedef restcgi::version version_type; 
00092         typedef restcgi::version_tag version_tag_type; 
00093         typedef restcgi::version_constraint version_constraint_type; 
00094         virtual ~resource();
00095         void method(method_pointer m); 
00096         method_pointer method() const {return method_;} 
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120         virtual pointer locate(uri_path_type& path);
00137         virtual void get_method();
00157         virtual void put_method();
00179         virtual void post_method();
00199         virtual void del_method();
00220         virtual void options_method();
00236         virtual void head_method();
00237         int methods_allowed_mask() const {return methods_allowed_mask_;} 
00238         pointer child() const {return child_;} 
00239         pointer parent() const {return parent_.lock();} 
00240         bool chain_children() const {return chain_children_;} 
00241         void child(pointer rthis, pointer cr); 
00242     protected:
00243         typedef uripp::query uri_query_type; 
00244 
00245 
00246 
00247 
00248 
00249 
00250 
00251 
00252 
00253 
00254 
00255 
00256 
00257 
00258         resource(int methods_allowed_mask, bool chain_children = false);
00259         const method_e& me() const; 
00260         const uri_info_type& uri_info() const {return uri_info_;} 
00261 
00262         version_constraint_type version_constraint() const {return version_constraint_;}
00267         void default_response(bool v);
00280         virtual version_type read(bool veronly);
00288         virtual version_type update(icontent::pointer ic);
00293         virtual pointer create_child();
00294         typedef std::pair<uri_path_type, version_type> id_version_type; 
00295 
00296 
00297 
00298 
00299 
00300 
00301 
00302 
00303 
00304         virtual id_version_type create(icontent::pointer ic);
00309         virtual void del();
00331         virtual void on_responding(status_code_e& sc, response_hdr& rh, content_hdr& ch);
00343         virtual void write(ocontent::pointer oc);
00344     private:
00345         void setup();
00346         void respond(const version_type& v = version_type());
00347         int methods_allowed_mask_;
00348         bool chain_children_;
00349         bool default_response_;
00350         method_pointer method_;
00351         uri_info_type uri_info_;
00352         version_constraint_type version_constraint_;
00353         pointer child_;
00354         boost::weak_ptr<resource> parent_;
00355     };
00375     void RESTCGI_API copy(const request_hdr& rh, version_constraint& vc);
00377     void RESTCGI_API copy(const version& v, response_hdr& rh);
00378 }
00379 #endif

Generated on Fri May 15 11:27:12 2009 for restcgi by  doxygen 1.4.7