HttpResourceTree.h
Go to the documentation of this file.
1 /****`
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * HttpResourceTree.h
8  *
9  * @author: 2017 - Slavey Karadzhov <slav@attachix.com>
10  *
11  ****/
12 
13 #pragma once
14 
15 #include "HttpResource.h"
16 
18 
20 #define RESOURCE_PATH_DEFAULT String('*')
21 
26 class HttpResourceTree : public ObjectMap<String, HttpResource>
27 {
28 public:
32  void setDefault(HttpResource* resource)
33  {
34  set(RESOURCE_PATH_DEFAULT, resource);
35  }
36 
40  void setDefault(const HttpResourceDelegate& onRequestComplete)
41  {
42  set(RESOURCE_PATH_DEFAULT, onRequestComplete);
43  }
44 
46  void setDefault(const HttpPathDelegate& callback)
47  {
48  set(RESOURCE_PATH_DEFAULT, callback);
49  }
50 
55  {
57  }
58 
59  using ObjectMap::set;
60 
68  void set(const String& path, const HttpResourceDelegate& onRequestComplete)
69  {
70  HttpResource* resource = new HttpResource;
71  resource->onRequestComplete = onRequestComplete;
72  set(path, resource);
73  }
74 
82  void set(String path, const HttpPathDelegate& callback);
83 };
Implementation of a HashMap for owned objects, i.e. anything created with new().
Definition: ObjectMap.h:47
HttpResourceDelegate onRequestComplete
request is complete OR upgraded
Definition: HttpResource.h:51
void set(const K &key, V *value)
Set a key value.
Definition: ObjectMap.h:208
void setDefault(const HttpResourceDelegate &onRequestComplete)
Set the default resource handler, identified by "*" wildcard.
Definition: HttpResourceTree.h:40
The String class.
Definition: WString.h:136
Definition: Delegate.h:20
HttpResource * getDefault()
Get the current default resource handler, if any.
Definition: HttpResourceTree.h:54
#define RESOURCE_PATH_DEFAULT
Identifies the default resource path.
Definition: HttpResourceTree.h:20
Instances of this class are registered with an HttpServer for a specific URL.
Definition: HttpResource.h:34
void setDefault(const HttpPathDelegate &callback)
Set the default resource handler, identified by "*" wildcard.
Definition: HttpResourceTree.h:46
Class to map URL paths to classes which handle them.
Definition: HttpResourceTree.h:26
void setDefault(HttpResource *resource)
Set the default resource handler.
Definition: HttpResourceTree.h:32
HttpResource * find(const String &key) const
Find the value for a given key, if it exists.
Definition: ObjectMap.h:225