-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented sync/async message handling, transport abstraction, deplo…
…yment
- Loading branch information
Showing
58 changed files
with
1,538 additions
and
513 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
cmake_minimum_required(VERSION 2.6) | ||
project (ngrestcommon CXX) | ||
|
||
set (PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) | ||
|
||
FILE(GLOB NGRESTCOMMON_SOURCES ${PROJECT_SOURCE_DIR}/*.cpp) | ||
FILE(GLOB NGRESTCOMMON_HEADERS ${PROJECT_SOURCE_DIR}/*.h) | ||
|
||
file(COPY ${NGRESTCOMMON_HEADERS} DESTINATION ${PROJECT_INCLUDE_DIR}/ngrest/common/) | ||
|
||
add_library(ngrestcommon SHARED ${NGRESTCOMMON_SOURCES}) | ||
|
||
target_link_libraries(ngrestcommon ngrestutils) | ||
|
||
target_compile_features(ngrestcommon PRIVATE cxx_range_for) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef NGREST_HTTPMESSAGE_H | ||
#define NGREST_HTTPMESSAGE_H | ||
|
||
#include "HttpMethod.h" | ||
#include "HttpStatus.h" | ||
#include "Message.h" | ||
|
||
namespace ngrest { | ||
|
||
struct HttpRequest: public Request | ||
{ | ||
HttpMethod method = HttpMethod::UNKNOWN; | ||
const char* methodStr = nullptr; | ||
|
||
const char* clientHost = nullptr; | ||
const char* clientPort = nullptr; | ||
}; | ||
|
||
|
||
struct HttpResponse: public Response | ||
{ | ||
int statusCode = HTTP_STATUS_200_OK; | ||
|
||
// // name must be in lower case | ||
// const Header* getHeader(const char* name) const; | ||
}; | ||
|
||
} | ||
|
||
#endif // NGREST_HTTPMESSAGE_H | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef NGREST_HTTPMETHOD_H | ||
#define NGREST_HTTPMETHOD_H | ||
|
||
namespace ngrest { | ||
|
||
enum class HttpMethod | ||
{ | ||
UNKNOWN, | ||
POST, | ||
GET, | ||
PUT, | ||
DELETE | ||
}; | ||
|
||
} // namespace ngrest | ||
|
||
#endif // NGREST_HTTPMETHOD_H | ||
|
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <string.h> | ||
|
||
#include "Message.h" | ||
|
||
namespace ngrest { | ||
|
||
const Header* Request::getHeader(const char* name) const | ||
{ | ||
for (const Header* header = headers; header; header = header->next) | ||
if (!strcmp(name, header->name)) | ||
return header; | ||
return nullptr; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#ifndef NGREST_MESSAGECONTEXT_H | ||
#define NGREST_MESSAGECONTEXT_H | ||
|
||
#include <stdint.h> | ||
|
||
#include <ngrest/common/Callback.h> | ||
#include <ngrest/utils/MemPool.h> | ||
|
||
namespace ngrest { | ||
|
||
class Exception; | ||
class Transport; | ||
struct Node; | ||
struct MessageContext; | ||
|
||
struct Header | ||
{ | ||
const char* name; | ||
const char* value; | ||
const Header* next; | ||
|
||
inline Header(const char* name_ = nullptr, const char* value_ = nullptr, const Header* next_ = nullptr): | ||
name(name_), value(value_), next(next_) | ||
{ | ||
} | ||
}; | ||
|
||
|
||
struct Request | ||
{ | ||
const char* path = nullptr; | ||
const Header* headers = nullptr; | ||
|
||
char* body = nullptr; | ||
uint64_t bodySize = 0; | ||
|
||
Node* node; | ||
|
||
// name must be in lower case | ||
const Header* getHeader(const char* name) const; | ||
}; | ||
|
||
struct Response | ||
{ | ||
const Header* headers = nullptr; | ||
|
||
Node* node; | ||
|
||
// char* body = nullptr; | ||
// uint64_t bodySize = 0; | ||
MemPool poolBody; | ||
}; | ||
|
||
class MessageCallback: public Callback<MessageContext*> | ||
{ | ||
}; | ||
|
||
struct MessageContext | ||
{ | ||
Transport* transport; | ||
Request* request = nullptr; | ||
Response* response = nullptr; | ||
MessageCallback* callback = nullptr; | ||
MemPool pool; | ||
}; | ||
|
||
} // namespace ngrest | ||
|
||
#endif // NGREST_MESSAGECONTEXT_H | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <string.h> | ||
|
||
#include "ObjectModel.h" | ||
|
||
namespace ngrest { | ||
|
||
NamedNode* Object::findChildByName(const char* name) const | ||
{ | ||
for (NamedNode* child = firstChild; child; child = child->nextSibling) | ||
if (!strcmp(child->name, name)) | ||
return child; | ||
|
||
return nullptr; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#ifndef NGREST_OBJECTMODEL_H | ||
#define NGREST_OBJECTMODEL_H | ||
|
||
namespace ngrest { | ||
|
||
enum class NodeType | ||
{ | ||
NamedNode, | ||
LinkedNode, | ||
Object, | ||
Array, | ||
Value | ||
}; | ||
|
||
enum class ValueType | ||
{ | ||
Undefined, | ||
Null, | ||
NaN, | ||
String, | ||
Number, | ||
Boolean | ||
}; | ||
|
||
struct Node | ||
{ | ||
const NodeType type; | ||
|
||
inline Node(NodeType type_): | ||
type(type_) | ||
{ | ||
} | ||
}; | ||
|
||
struct LinkedNode: public Node { | ||
Node* node; | ||
LinkedNode* nextSibling = nullptr; | ||
|
||
inline LinkedNode(Node* node_ = nullptr): | ||
Node(NodeType::NamedNode), | ||
node(node_) | ||
{ | ||
} | ||
}; | ||
|
||
struct NamedNode: public Node { | ||
const char* name; | ||
Node* node; | ||
NamedNode* nextSibling = nullptr; | ||
|
||
inline NamedNode(const char* name_ = nullptr, Node* node_ = nullptr): | ||
Node(NodeType::NamedNode), | ||
name(name_), | ||
node(node_) | ||
{ | ||
} | ||
}; | ||
|
||
struct Object: public Node | ||
{ | ||
NamedNode* firstChild = nullptr; | ||
|
||
inline Object(): | ||
Node(NodeType::Object) | ||
{ | ||
} | ||
|
||
NamedNode* findChildByName(const char* name) const; | ||
}; | ||
|
||
struct Array: public Node | ||
{ | ||
LinkedNode* firstChild = nullptr; | ||
|
||
inline Array(): | ||
Node(NodeType::Array) | ||
{ | ||
} | ||
}; | ||
|
||
struct Value: public Node | ||
{ | ||
ValueType valueType; | ||
const char* value; | ||
|
||
inline Value(ValueType valueType_, const char* value_ = nullptr): | ||
Node(NodeType::Value), | ||
valueType(valueType_), | ||
value(value_) | ||
{ | ||
} | ||
}; | ||
|
||
} | ||
|
||
#endif // NGREST_OBJECTMODEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "Service.h" | ||
|
||
namespace ngrest { | ||
|
||
Service::Service() | ||
{ | ||
|
||
} | ||
|
||
Service::~Service() | ||
{ | ||
|
||
} | ||
|
||
} // namespace ngrest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef NGREST_SERVICE_H | ||
#define NGREST_SERVICE_H | ||
|
||
#include <string> | ||
|
||
namespace ngrest { | ||
|
||
class Service | ||
{ | ||
public: | ||
Service(); | ||
virtual ~Service(); | ||
}; | ||
|
||
} // namespace ngrest | ||
|
||
#endif // NGREST_SERVICE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.