Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
HttpResourceTree.h
1 /****`
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/anakod/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 #ifndef _SMING_CORE_NETWORK_HTTP_HTTP_RESOURCE_TREE_H_
14 #define _SMING_CORE_NETWORK_HTTP_HTTP_RESOURCE_TREE_H_
15 
16 #include "HttpResource.h"
17 
19 
21 #define RESOURCE_PATH_DEFAULT String('*')
22 
25 class HttpResourceTree : public ObjectMap<String, HttpResource>
26 {
27 public:
31  void setDefault(HttpResource* resource)
32  {
33  set(RESOURCE_PATH_DEFAULT, resource);
34  }
35 
39  void setDefault(const HttpResourceDelegate& onRequestComplete)
40  {
41  set(RESOURCE_PATH_DEFAULT, onRequestComplete);
42  }
43 
45  void setDefault(const HttpPathDelegate& callback)
46  {
47  set(RESOURCE_PATH_DEFAULT, callback);
48  }
49 
54  {
55  return find(RESOURCE_PATH_DEFAULT);
56  }
57 
58  using ObjectMap::set;
59 
67  void set(const String& path, const HttpResourceDelegate& onRequestComplete)
68  {
69  HttpResource* resource = new HttpResource;
70  resource->onRequestComplete = onRequestComplete;
71  set(path, resource);
72  }
73 
81  void set(String path, const HttpPathDelegate& callback);
82 };
83 
84 #endif /* _SMING_CORE_NETWORK_HTTP_HTTP_RESOURCE_TREE_H_ */
Implementation of a HashMap for owned objects, i.e. anything created with new().
Definition: ObjectMap.h:48
HttpResourceDelegate onRequestComplete
request is complete OR upgraded
Definition: HttpResource.h:49
void set(const K &key, V *value)
Set a key value.
Definition: ObjectMap.h:209
void setDefault(const HttpResourceDelegate &onRequestComplete)
Set the default resource handler, identified by "*" wildcard.
Definition: HttpResourceTree.h:39
The string class.
Definition: WString.h:104
Definition: Delegate.h:118
HttpResource * getDefault()
Get the current default resource handler, if any.
Definition: HttpResourceTree.h:53
Definition: HttpResource.h:32
void setDefault(const HttpPathDelegate &callback)
Set the default resource handler, identified by "*" wildcard.
Definition: HttpResourceTree.h:45
Class to map URL paths to classes which handle them.
Definition: HttpResourceTree.h:25
void setDefault(HttpResource *resource)
Set the default resource handler.
Definition: HttpResourceTree.h:31
HttpResource * find(const String &key) const
Find the value for a given key, if it exists.
Definition: ObjectMap.h:226