Skip to content

Commit 1b67e73

Browse files
committed
Fixed scripts.wsjcpp/generate.WsjcppJsonRpc20Handler
1 parent 5944acf commit 1b67e73

File tree

5 files changed

+107
-18
lines changed

5 files changed

+107
-18
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ set(EXECUTABLE_OUTPUT_PATH ${wsjcpp-jsonrpc20_SOURCE_DIR})
1111
list (APPEND WSJCPP_INCLUDE_DIRS "src")
1212

1313
list (APPEND WSJCPP_SOURCES "src/main.cpp")
14+
list (APPEND WSJCPP_SOURCES "src/wsjcpp_jsonrpc20.h")
15+
list (APPEND WSJCPP_SOURCES "src/wsjcpp_jsonrpc20.cpp")
16+
17+
# examples
18+
list (APPEND WSJCPP_SOURCES "./src/examples/wsjcpp_json_rpc20_handler_game_create.h")
19+
list (APPEND WSJCPP_SOURCES "./src/examples/wsjcpp_json_rpc20_handler_game_create.cpp")
1420

1521
#### BEGIN_WSJCPP_APPEND
1622
#### END_WSJCPP_APPEND
@@ -28,3 +34,4 @@ install(
2834
/usr/bin
2935
)
3036

37+

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,32 @@ $ wsjcpp install https://github.com/wsjcpp/wsjcpp-jsonrpc20:master
3030
* src/wsjcpp_jsonrpc20_export_cli_python.h
3131
* src/wsjcpp_jsonrpc20_export_cli_python.cpp
3232

33+
## Prepare handler
34+
35+
easy way:
36+
37+
```
38+
$ wsjcpp generate WsjcppJsonRpc20Handler GameCreate
39+
```
40+
41+
Will be generated new files
42+
43+
- ./src/wsjcpp_json_rpc20_handler_game_create.h
44+
- ./src/wsjcpp_json_rpc20_handler_game_create.cpp
45+
46+
And automaticly included to CMakeLists.txt between `#### BEGIN_WSJCPP_APPEND` and `#### END_WSJCPP_APPEND`
47+
48+
Like this:
49+
```
50+
#### BEGIN_WSJCPP_APPEND
51+
list (APPEND WSJCPP_SOURCES "./src/wsjcpp_json_rpc20_handler_game_create.h")
52+
list (APPEND WSJCPP_SOURCES "./src/wsjcpp_json_rpc20_handler_game_create.cpp")
53+
#### END_WSJCPP_APPEND
54+
```
55+
56+
They will contains class `WsjcppJsonRpc20HandlerGameCreate` with method `game_create`
57+
58+
3359
## Example
3460

3561
``` cpp

scripts.wsjcpp/generate.WsjcppJsonRpc20Handler

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
make_dir "src"
77

8-
var argument_processor_name
9-
set_value argument_processor_name arg1
10-
normalize_class_name argument_processor_name
11-
convert_CamelCase_to_snake_case argument_processor_name argument_processor_name
8+
var method_name
9+
set_value method_name arg1
10+
normalize_class_name method_name
11+
convert_CamelCase_to_snake_case method_name method_name
1212

1313
var class_name
1414
concat class_name "WsjcppJsonRpc20Handler" arg1
@@ -34,7 +34,7 @@ var content_header
3434
concat content_header "#ifndef " ifndef_header "
3535
#define " ifndef_header "
3636

37-
#include <wsjcpp_arguments.h>
37+
#include <wsjcpp_jsonrpc20.h>
3838

3939
class " class_name " : public WsjcppJsonRpc20HandlerBase {
4040
public:
@@ -46,45 +46,46 @@ class " class_name " : public WsjcppJsonRpc20HandlerBase {
4646

4747

4848
var content_source
49-
concat content_source "
49+
concat content_source "
5050
#include \"" base_filename ".h\"
51+
#include <wsjcpp_core.h>
5152
#include <wsjcpp_jsonrpc20.h>
5253

5354
// ---------------------------------------------------------------------
5455
// " class_name "
5556

5657
" class_name "::" class_name "()
57-
: WsjcppJsonRpc20HandlerBase(\"" argument_processor_name "\", \"TODO description\") {
58+
: WsjcppJsonRpc20HandlerBase(\"" method_name "\", \"TODO description\") {
5859
TAG = \"" class_name "\";
5960
// setAccessUnauthorized(true);
6061
// setAccessUser(true);
61-
// setAccessTester(\"here example of command\");
62-
// setAccessAdmin();
63-
// void setActivatedFromVersion(\"v0.0.1"); // TODO authomatic set WSJCPP_APP_VERSION
64-
// void setDeprecatedFromVersion("");
62+
// setAccessTester(true);
63+
// setAccessAdmin(true);
64+
// void setActivatedFromVersion(\"v0.0.1\"); // TODO authomatic set WSJCPP_APP_VERSION
65+
// void setDeprecatedFromVersion(\"\");
6566

6667
// description of input params
67-
// requireStringParam(\"uuid\", "object uuid")
68+
// requireStringParam(\"uuid\", \"object uuid\")
6869
// .addValidator(new WsjcppValidatorUUID());
69-
// optionalStringParam(\"name\", "Name of object")
70+
// optionalStringParam(\"name\", \"Name of object\")
7071
// .addValidator(new WsjcppValidatorStringLength(3,10));
7172

72-
// requireIntegerParam(\"cost\", "Name of object")
73+
// requireIntegerParam(\"cost\", \"Name of object\")
7374
// .addValidator(new WsjcppValidatorIntegerMinValue(3))
7475
// .addValidator(new WsjcppValidatorIntegerMaxValue(1000));
75-
// optionalIntegerParam(\"age\", "Name of object")
76+
// optionalIntegerParam(\"age\", \"Name of object\")
7677
// .addValidator(new WsjcppValidatorIntegerMinValue(0))
7778

78-
// requireBooleanParam(\"public\", "True if object is public");
79-
// optionalBooleanParam(\"activated\", "If object can handle");
79+
// requireBooleanParam(\"public\", \"True if object is public\");
80+
// optionalBooleanParam(\"activated\", \"If object can handle\");
8081
}
8182

8283
// ---------------------------------------------------------------------
8384

8485
void " class_name "::handle(WsjcppJsonRpc20Request *pRequest) {
8586
WsjcppLog::err(TAG, \"Not implemented\");
8687
// TODO
87-
pRequest->fail(WsjcppJsonRpc20Error(501, "NOT_IMPLEMENTED"));
88+
pRequest->fail(WsjcppJsonRpc20Error(501, \"NOT_IMPLEMENTED\"));
8889
}
8990

9091
"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
#include "wsjcpp_json_rpc20_handler_game_create.h"
3+
#include <wsjcpp_core.h>
4+
#include <wsjcpp_jsonrpc20.h>
5+
6+
// ---------------------------------------------------------------------
7+
// WsjcppJsonRpc20HandlerGameCreate
8+
9+
WsjcppJsonRpc20HandlerGameCreate::WsjcppJsonRpc20HandlerGameCreate()
10+
: WsjcppJsonRpc20HandlerBase("game_create", "TODO description") {
11+
TAG = "WsjcppJsonRpc20HandlerGameCreate";
12+
// setAccessUnauthorized(true);
13+
// setAccessUser(true);
14+
// setAccessTester(true);
15+
// setAccessAdmin(true);
16+
// void setActivatedFromVersion("v0.0.1"); // TODO authomatic set WSJCPP_APP_VERSION
17+
// void setDeprecatedFromVersion("");
18+
19+
// description of input params
20+
// requireStringParam("uuid", "object uuid")
21+
// .addValidator(new WsjcppValidatorUUID());
22+
// optionalStringParam("name", "Name of object")
23+
// .addValidator(new WsjcppValidatorStringLength(3,10));
24+
25+
// requireIntegerParam("cost", "Name of object")
26+
// .addValidator(new WsjcppValidatorIntegerMinValue(3))
27+
// .addValidator(new WsjcppValidatorIntegerMaxValue(1000));
28+
// optionalIntegerParam("age", "Name of object")
29+
// .addValidator(new WsjcppValidatorIntegerMinValue(0))
30+
31+
// requireBooleanParam("public", "True if object is public");
32+
// optionalBooleanParam("activated", "If object can handle");
33+
}
34+
35+
// ---------------------------------------------------------------------
36+
37+
void WsjcppJsonRpc20HandlerGameCreate::handle(WsjcppJsonRpc20Request *pRequest) {
38+
WsjcppLog::err(TAG, "Not implemented");
39+
// TODO
40+
pRequest->fail(WsjcppJsonRpc20Error(501, "NOT_IMPLEMENTED"));
41+
}
42+
43+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef WSJCPP_JSON_RPC20_HANDLER_GAME_CREATE_H
2+
#define WSJCPP_JSON_RPC20_HANDLER_GAME_CREATE_H
3+
4+
#include <wsjcpp_jsonrpc20.h>
5+
6+
class WsjcppJsonRpc20HandlerGameCreate : public WsjcppJsonRpc20HandlerBase {
7+
public:
8+
WsjcppJsonRpc20HandlerGameCreate();
9+
virtual void handle(WsjcppJsonRpc20Request *pRequest) override;
10+
};
11+
12+
#endif // WSJCPP_JSON_RPC20_HANDLER_GAME_CREATE_H

0 commit comments

Comments
 (0)