-
-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce ObjectMap #1638
Introduce ObjectMap #1638
Conversation
f1f5728
to
8c71732
Compare
// Check existing connection | ||
connection = httpConnectionPool.valueAt(i); | ||
if(connection->getConnectionState() > eTCS_Connecting && !connection->isActive()) { | ||
debug_d("Removing stale connection: State: %d, Active: %d", connection->getConnectionState(), | ||
connection->isActive()); | ||
delete connection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder, is it necessary to delete the connection? Could we just reset it, perhaps?
Sming/SmingCore/Network/HttpServer.h
Outdated
|
||
void setDefaultHandler(const HttpPathDelegate& callback); | ||
void setDefaultResource(HttpResource* resource); | ||
void addPath(const String& path, HttpResource* resource) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe deprecate some of these, use resourceTree directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good idea. Deprecate it now and the removal will be after two or three major releases. The Readme.md has to be updated too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've renamed resourceTree
to paths
as it seems to make more sense to me when in use. I left the internal references (in HttpServerConnection
) alone.
* } | ||
* | ||
*/ | ||
void set(const K& key, V* value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That set
will cause confusion. We have two ways to add things to the map that behave diffently:
ObjectMap<String, MyType> map;
map["key1"] = object1;
// and
map.set("key1, object1);
The best would have been to make map["key1"] = object1;
behave as set
. But probably it would be better to remove completely V& operator[](const K& key)
since I cannot think of a proper way to implement the above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The best would have been to make
map["key1"] = object1;
behave asset
Done :-)
Rename `ResourceTree` to `HttpResourceTree` Deprecate `HttpServeri::addPath()` and `setDefault` methods Make `HttpCompatResource` private, move into `HttpResourceTree` module
bodyParser = (*bodyParsers)[types.at(i)]; | ||
const String& type = types[i]; | ||
if(bodyParsers->contains(type)) { | ||
bodyParser = (*bodyParsers)[type]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bodyParsers->get(type) would be nicer... That's HashMap though...
Sming/SmingCore/Data/ObjectMap.h
Outdated
/** @brief Access map entry by reference | ||
* @param key | ||
* @retval Value Guarded access to mapped value corresponding to given key | ||
* @note If the given key does not exist in the map then it will be created and a null value entry returned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid this (usually) un-desirable side-effect we could take advantage of our Value
class and use it to create an entry in the map only when a value is actually assigned.
…by `operator[]` `Value` revised to work with map directly rather than just taking value reference - safer and more useful Move example code to class comment
dc0c01e
to
79269c0
Compare
c3702e6
to
23686a6
Compare
In `HttpConnection::multipartProducer()` the `IDataSourceStream*` entry from `files` must be extracted, not removed Add `extractAt()` method added to `ObjectMap` to support this operation more efficiently
In `HttpConnection::multipartProducer()` the `IDataSourceStream*` entry from `files` must be extracted, not removed Add `extractAt()` method added to `ObjectMap` to support this operation more efficiently
Add
ObjectMap
classMove
ResourceTree
class into separate file, rename asHttpResourceTree
Rename
HttpServer::resourceTree
aspaths
, make publicDeprecate
HttpServer::addPath
andHttpServer::setDefault
methodsAddresses #1637