| 1 |
|
| MODE: INLINE |
| 2 |
|
| |
| 3 |
|
| #include <iostream> |
| 4 |
|
| |
| 5 |
|
| enum class Status07 { CONNECTED = 1, AUTHORIZED = 2, NOT_AUTHORIZED = 3, DISCONNECTED = 4 }; |
| 6 |
|
| |
| 7 |
|
| struct Client07 { |
| 8 |
|
| int id; |
| 9 |
|
| Status07 status; |
| 10 |
|
| |
| 11 |
|
| Client07 (int id_): id{id_}, status{Status07::CONNECTED } {} |
| 12 |
|
| void disconnect() { |
| 13 |
|
| std::cout << "disconnecting " << id << "\n"; |
| 14 |
|
| status = Status07::DISCONNECTED; |
| 15 |
|
| } |
| 16 |
|
| void welcome() { |
| 17 |
|
| std::cout << "[sending] welcome dear client " << id << "\n"; |
| 18 |
|
| } |
| 19 |
|
| }; |
| 20 |
|
| |
| 21 |
|
| struct ServerBase07 { |
| 22 |
|
| void on_client(Client07* c) { |
| 23 |
|
| if (c->status == Status07::AUTHORIZED) c->welcome(); |
| 24 |
|
| if (c->status == Status07::NOT_AUTHORIZED) c->disconnect(); |
| 25 |
|
| } |
| 26 |
|
| }; |
| 27 |
|
| |
| 28 |
|
| struct LoggerPlugin07 { |
| 29 |
|
| void on_client(Client07* c) { std::cout << "client " << c->id << ", status: " << (int) c->status << "\n"; } |
| 30 |
|
| }; |
| 31 |
|
| |
| 32 |
|
| struct AuthorizerPlugin07 { |
| 33 |
|
| void on_client(Client07* c) { |
| 34 |
|
| c->status = (c->id < 0) ? Status07::NOT_AUTHORIZED : Status07::AUTHORIZED; |
| 35 |
|
| } |
| 36 |
|
| }; |
| 37 |
|
| |
| 38 |
|
| namespace xs { |
| 39 |
|
| template <> |
| 40 |
|
| struct Typemap<Client07*> : TypemapObject<Client07*, Client07*, ObjectTypePtr, ObjectStorageMG> { |
| 41 |
|
| static std::string package () { return "MyTest::Cookbook::Client07"; } |
| 42 |
|
| }; |
| 43 |
|
| |
| 44 |
|
| template <> |
| 45 |
|
| struct Typemap<ServerBase07*> : TypemapObject<ServerBase07*, ServerBase07*, ObjectTypePtr, ObjectStorageMG> { |
| 46 |
|
| static std::string package () { return "MyTest::Cookbook::ServerBase07"; } |
| 47 |
|
| }; |
| 48 |
|
| |
| 49 |
|
| template <> |
| 50 |
|
| struct Typemap<LoggerPlugin07*> : TypemapObject<LoggerPlugin07*, LoggerPlugin07*, ObjectTypePtr, ObjectStorageMG> { |
| 51 |
|
| static std::string package () { return "MyTest::Cookbook::LoggerPlugin07"; } |
| 52 |
|
| }; |
| 53 |
|
| |
| 54 |
|
| template <> |
| 55 |
|
| struct Typemap<AuthorizerPlugin07*> : TypemapObject<AuthorizerPlugin07*, AuthorizerPlugin07*, ObjectTypePtr, ObjectStorageMG> { |
| 56 |
|
| static std::string package () { return "MyTest::Cookbook::AuthorizerPlugin07"; } |
| 57 |
|
| }; |
| 58 |
|
| } |
| 59 |
|
| |
| 60 |
|
| |
| 61 |
|
| |
| 62 |
|
| MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::Client07 |
| 63 |
|
| PROTOTYPES: DISABLE |
| 64 |
|
| |
| 65 |
0 |
| void Client07::disconnect() |
| 66 |
|
| |
| 67 |
0 |
| void Client07::welcome() |
| 68 |
|
| |
| 69 |
0 |
| Client07* Client07::new(int id) |
| 70 |
0 |
▶ | |
Branch: 1 branch
| Branch | True | False | Total |
|
0 |
0 |
0 |
|
| 71 |
0 |
▶ | |
Branch: 2 branches
| Branch | True | False | Total |
|
0 |
0 |
0 |
|
0 |
0 |
0 |
|
| 72 |
|
| MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::ServerBase07 |
| 73 |
|
| PROTOTYPES: DISABLE |
| 74 |
|
| |
| 75 |
0 |
| void ServerBase07::on_client(Client07* c) |
| 76 |
|
| |
| 77 |
0 |
| ServerBase07* ServerBase07::new() |
| 78 |
0 |
▶ | |
Branch: 1 branch
| Branch | True | False | Total |
|
0 |
0 |
0 |
|
| 79 |
0 |
▶ | MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::LoggerPlugin07 |
Branch: 2 branches
| Branch | True | False | Total |
| MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::LoggerPlugin07 |
0 |
0 |
0 |
| MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::LoggerPlugin07 |
0 |
0 |
0 |
|
| 80 |
|
| PROTOTYPES: DISABLE |
| 81 |
|
| |
| 82 |
|
| void LoggerPlugin07::on_client(Client07* c) { |
| 83 |
0 |
| THIS->on_client(c); |
| 84 |
0 |
▶ | Object(ST(0)).call_next(cv, &ST(1), items-1); |
Branch: 3 branches
| Branch | True | False | Total |
| Object(ST(0)).call_next(cv, &ST(1), items-1); |
0 |
0 |
0 |
| Object(ST(0)).call_next(cv, &ST(1), items-1); |
0 |
0 |
0 |
| Object(ST(0)).call_next(cv, &ST(1), items-1); |
0 |
0 |
0 |
|
| 85 |
0 |
| THIS->on_client(c); |
| 86 |
|
| } |
| 87 |
|
| |
| 88 |
|
| LoggerPlugin07* LoggerPlugin07::new (...) { |
| 89 |
0 |
| PROTO = Stash::from_name(CLASS).call_next(cv, &ST(1), items-1); |
| 90 |
0 |
▶ | if (!PROTO.defined()) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!PROTO.defined()) XSRETURN_UNDEF; |
0 |
0 |
0 |
|
| 91 |
0 |
▶ | RETVAL = new LoggerPlugin07(); |
Branch: 3 branches
| Branch | True | False | Total |
| RETVAL = new LoggerPlugin07(); |
0 |
0 |
0 |
| RETVAL = new LoggerPlugin07(); |
0 |
0 |
0 |
| RETVAL = new LoggerPlugin07(); |
0 |
0 |
0 |
|
| 92 |
0 |
▶ | } |
Branch: 2 branches
| Branch | True | False | Total |
| } |
0 |
0 |
0 |
| } |
0 |
0 |
0 |
|
| 93 |
0 |
▶ | |
Branch: 2 branches
| Branch | True | False | Total |
|
0 |
0 |
0 |
|
0 |
0 |
0 |
|
| 94 |
|
| MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::AuthorizerPlugin07 |
| 95 |
|
| PROTOTYPES: DISABLE |
| 96 |
|
| |
| 97 |
|
| void AuthorizerPlugin07::on_client(Client07* c) { |
| 98 |
0 |
| THIS->on_client(c); |
| 99 |
0 |
▶ | Object(ST(0)).call_next(cv, &ST(1), items-1); |
Branch: 3 branches
| Branch | True | False | Total |
| Object(ST(0)).call_next(cv, &ST(1), items-1); |
0 |
0 |
0 |
| Object(ST(0)).call_next(cv, &ST(1), items-1); |
0 |
0 |
0 |
| Object(ST(0)).call_next(cv, &ST(1), items-1); |
0 |
0 |
0 |
|
| 100 |
|
| } |
| 101 |
|
| |
| 102 |
|
| AuthorizerPlugin07* AuthorizerPlugin07::new (...) { |
| 103 |
0 |
| PROTO = Stash::from_name(CLASS).call_next(cv, &ST(1), items-1); |
| 104 |
0 |
▶ | if (!PROTO.defined()) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!PROTO.defined()) XSRETURN_UNDEF; |
0 |
0 |
0 |
|
| 105 |
0 |
▶ | RETVAL = new AuthorizerPlugin07(); |
Branch: 3 branches
| Branch | True | False | Total |
| RETVAL = new AuthorizerPlugin07(); |
0 |
0 |
0 |
| RETVAL = new AuthorizerPlugin07(); |
0 |
0 |
0 |
| RETVAL = new AuthorizerPlugin07(); |
0 |
0 |
0 |
|
| 106 |
0 |
▶ | } |
Branch: 2 branches
| Branch | True | False | Total |
| } |
0 |
0 |
0 |
| } |
0 |
0 |
0 |
|
| 107 |
0 |
▶ | |
Branch: 2 branches
| Branch | True | False | Total |
|
0 |
0 |
0 |
|
0 |
0 |
0 |
|
| 108 |
|
| MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::Server07 |
| 109 |
|
| PROTOTYPES: DISABLE |
| 110 |
|
| |
| 111 |
|
| BOOT { |
| 112 |
35 |
▶ | auto stash = Stash(__PACKAGE__, GV_ADD); |
Branch: 1 branch
| Branch | True | False | Total |
| auto stash = Stash(__PACKAGE__, GV_ADD); |
35 |
0 |
35 |
|
| 113 |
35 |
▶ | stash.inherit("MyTest::Cookbook::LoggerPlugin07"); |
Branch: 1 branch
| Branch | True | False | Total |
| stash.inherit("MyTest::Cookbook::LoggerPlugin07"); |
35 |
0 |
35 |
|
| 114 |
35 |
▶ | stash.inherit("MyTest::Cookbook::AuthorizerPlugin07"); |
Branch: 1 branch
| Branch | True | False | Total |
| stash.inherit("MyTest::Cookbook::AuthorizerPlugin07"); |
35 |
0 |
35 |
|
| 115 |
35 |
▶ | stash.inherit("MyTest::Cookbook::ServerBase07"); |
Branch: 1 branch
| Branch | True | False | Total |
| stash.inherit("MyTest::Cookbook::ServerBase07"); |
35 |
0 |
35 |
|
| 116 |
35 |
| } |