Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
2dff17d3
Commit
2dff17d3
authored
10 years ago
by
Craig Tiller
Browse files
Options
Downloads
Patches
Plain Diff
Async API declarations
parent
82ee98cc
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/grpc++/stream.h
+69
-0
69 additions, 0 deletions
include/grpc++/stream.h
src/compiler/cpp_generator.cc
+81
-9
81 additions, 9 deletions
src/compiler/cpp_generator.cc
src/cpp/common/completion_queue.cc
+0
-1
0 additions, 1 deletion
src/cpp/common/completion_queue.cc
with
150 additions
and
10 deletions
include/grpc++/stream.h
+
69
−
0
View file @
2dff17d3
...
@@ -256,6 +256,75 @@ class ServerReaderWriter : public WriterInterface<W>,
...
@@ -256,6 +256,75 @@ class ServerReaderWriter : public WriterInterface<W>,
StreamContextInterface
*
const
context_
;
// not owned
StreamContextInterface
*
const
context_
;
// not owned
};
};
template
<
class
W
>
class
ServerAsyncResponseWriter
{
public:
explicit
ServerAsyncResponseWriter
(
StreamContextInterface
*
context
)
:
context_
(
context
)
{
GPR_ASSERT
(
context_
);
context_
->
Start
(
true
);
context_
->
Read
(
context_
->
request
());
}
virtual
bool
Write
(
const
W
&
msg
)
{
return
context_
->
Write
(
const_cast
<
W
*>
(
&
msg
),
false
);
}
private
:
StreamContextInterface
*
const
context_
;
// not owned
};
template
<
class
R
>
class
ServerAsyncReader
:
public
ReaderInterface
<
R
>
{
public:
explicit
ServerAsyncReader
(
StreamContextInterface
*
context
)
:
context_
(
context
)
{
GPR_ASSERT
(
context_
);
context_
->
Start
(
true
);
}
virtual
bool
Read
(
R
*
msg
)
{
return
context_
->
Read
(
msg
);
}
private
:
StreamContextInterface
*
const
context_
;
// not owned
};
template
<
class
W
>
class
ServerAsyncWriter
:
public
WriterInterface
<
W
>
{
public:
explicit
ServerAsyncWriter
(
StreamContextInterface
*
context
)
:
context_
(
context
)
{
GPR_ASSERT
(
context_
);
context_
->
Start
(
true
);
context_
->
Read
(
context_
->
request
());
}
virtual
bool
Write
(
const
W
&
msg
)
{
return
context_
->
Write
(
const_cast
<
W
*>
(
&
msg
),
false
);
}
private
:
StreamContextInterface
*
const
context_
;
// not owned
};
// Server-side interface for bi-directional streaming.
template
<
class
W
,
class
R
>
class
ServerAsyncReaderWriter
:
public
WriterInterface
<
W
>
,
public
ReaderInterface
<
R
>
{
public:
explicit
ServerAsyncReaderWriter
(
StreamContextInterface
*
context
)
:
context_
(
context
)
{
GPR_ASSERT
(
context_
);
context_
->
Start
(
true
);
}
virtual
bool
Read
(
R
*
msg
)
{
return
context_
->
Read
(
msg
);
}
virtual
bool
Write
(
const
W
&
msg
)
{
return
context_
->
Write
(
const_cast
<
W
*>
(
&
msg
),
false
);
}
private
:
StreamContextInterface
*
const
context_
;
// not owned
};
}
// namespace grpc
}
// namespace grpc
#endif // __GRPCPP_STREAM_H__
#endif // __GRPCPP_STREAM_H__
This diff is collapsed.
Click to expand it.
src/compiler/cpp_generator.cc
+
81
−
9
View file @
2dff17d3
...
@@ -61,6 +61,17 @@ bool BidiStreaming(const google::protobuf::MethodDescriptor *method) {
...
@@ -61,6 +61,17 @@ bool BidiStreaming(const google::protobuf::MethodDescriptor *method) {
return
method
->
client_streaming
()
&&
method
->
server_streaming
();
return
method
->
client_streaming
()
&&
method
->
server_streaming
();
}
}
bool
HasUnaryCalls
(
const
google
::
protobuf
::
FileDescriptor
*
file
)
{
for
(
int
i
=
0
;
i
<
file
->
service_count
();
i
++
)
{
for
(
int
j
=
0
;
j
<
file
->
service
(
i
)
->
method_count
();
j
++
)
{
if
(
NoStreaming
(
file
->
service
(
i
)
->
method
(
j
)))
{
return
true
;
}
}
}
return
false
;
}
bool
HasClientOnlyStreaming
(
const
google
::
protobuf
::
FileDescriptor
*
file
)
{
bool
HasClientOnlyStreaming
(
const
google
::
protobuf
::
FileDescriptor
*
file
)
{
for
(
int
i
=
0
;
i
<
file
->
service_count
();
i
++
)
{
for
(
int
i
=
0
;
i
<
file
->
service_count
();
i
++
)
{
for
(
int
j
=
0
;
j
<
file
->
service
(
i
)
->
method_count
();
j
++
)
{
for
(
int
j
=
0
;
j
<
file
->
service
(
i
)
->
method_count
();
j
++
)
{
...
@@ -104,13 +115,20 @@ std::string GetHeaderIncludes(const google::protobuf::FileDescriptor *file) {
...
@@ -104,13 +115,20 @@ std::string GetHeaderIncludes(const google::protobuf::FileDescriptor *file) {
"class ChannelInterface;
\n
"
"class ChannelInterface;
\n
"
"class RpcService;
\n
"
"class RpcService;
\n
"
"class ServerContext;
\n
"
;
"class ServerContext;
\n
"
;
if
(
HasUnaryCalls
(
file
))
{
temp
.
append
(
"template <class OutMessage> class ServerAsyncResponseWriter;
\n
"
);
}
if
(
HasClientOnlyStreaming
(
file
))
{
if
(
HasClientOnlyStreaming
(
file
))
{
temp
.
append
(
"template <class OutMessage> class ClientWriter;
\n
"
);
temp
.
append
(
"template <class OutMessage> class ClientWriter;
\n
"
);
temp
.
append
(
"template <class InMessage> class ServerReader;
\n
"
);
temp
.
append
(
"template <class InMessage> class ServerReader;
\n
"
);
temp
.
append
(
"template <class OutMessage> class ClientAsyncWriter;
\n
"
);
temp
.
append
(
"template <class InMessage> class ServerAsyncReader;
\n
"
);
}
}
if
(
HasServerOnlyStreaming
(
file
))
{
if
(
HasServerOnlyStreaming
(
file
))
{
temp
.
append
(
"template <class InMessage> class ClientReader;
\n
"
);
temp
.
append
(
"template <class InMessage> class ClientReader;
\n
"
);
temp
.
append
(
"template <class OutMessage> class ServerWriter;
\n
"
);
temp
.
append
(
"template <class OutMessage> class ServerWriter;
\n
"
);
temp
.
append
(
"template <class OutMessage> class ClientAsyncReader;
\n
"
);
temp
.
append
(
"template <class InMessage> class ServerAsyncWriter;
\n
"
);
}
}
if
(
HasBidiStreaming
(
file
))
{
if
(
HasBidiStreaming
(
file
))
{
temp
.
append
(
temp
.
append
(
...
@@ -125,10 +143,10 @@ std::string GetHeaderIncludes(const google::protobuf::FileDescriptor *file) {
...
@@ -125,10 +143,10 @@ std::string GetHeaderIncludes(const google::protobuf::FileDescriptor *file) {
}
}
std
::
string
GetSourceIncludes
()
{
std
::
string
GetSourceIncludes
()
{
return
"#include
\"
grpc++/channel_interface.h
\"
\n
"
return
"#include
<
grpc++/channel_interface.h
>
\n
"
"#include
\"
grpc++/impl/rpc_method.h
\"
\n
"
"#include
<
grpc++/impl/rpc_method.h
>
\n
"
"#include
\"
grpc++/impl/rpc_service_method.h
\"
\n
"
"#include
<
grpc++/impl/rpc_service_method.h
>
\n
"
"#include
\"
grpc++/stream.h
\"
\n
"
;
"#include
<
grpc++/stream.h
>
\n
"
;
}
}
void
PrintHeaderClientMethod
(
google
::
protobuf
::
io
::
Printer
*
printer
,
void
PrintHeaderClientMethod
(
google
::
protobuf
::
io
::
Printer
*
printer
,
...
@@ -160,7 +178,7 @@ void PrintHeaderClientMethod(google::protobuf::io::Printer *printer,
...
@@ -160,7 +178,7 @@ void PrintHeaderClientMethod(google::protobuf::io::Printer *printer,
}
}
}
}
void
PrintHeaderServerMethod
(
google
::
protobuf
::
io
::
Printer
*
printer
,
void
PrintHeaderServerMethod
Sync
(
google
::
protobuf
::
io
::
Printer
*
printer
,
const
google
::
protobuf
::
MethodDescriptor
*
method
,
const
google
::
protobuf
::
MethodDescriptor
*
method
,
std
::
map
<
std
::
string
,
std
::
string
>
*
vars
)
{
std
::
map
<
std
::
string
,
std
::
string
>
*
vars
)
{
(
*
vars
)[
"Method"
]
=
method
->
name
();
(
*
vars
)[
"Method"
]
=
method
->
name
();
...
@@ -194,19 +212,56 @@ void PrintHeaderServerMethod(google::protobuf::io::Printer *printer,
...
@@ -194,19 +212,56 @@ void PrintHeaderServerMethod(google::protobuf::io::Printer *printer,
}
}
}
}
void
PrintHeaderServerMethodAsync
(
google
::
protobuf
::
io
::
Printer
*
printer
,
const
google
::
protobuf
::
MethodDescriptor
*
method
,
std
::
map
<
std
::
string
,
std
::
string
>
*
vars
)
{
(
*
vars
)[
"Method"
]
=
method
->
name
();
(
*
vars
)[
"Request"
]
=
grpc_cpp_generator
::
ClassName
(
method
->
input_type
(),
true
);
(
*
vars
)[
"Response"
]
=
grpc_cpp_generator
::
ClassName
(
method
->
output_type
(),
true
);
if
(
NoStreaming
(
method
))
{
printer
->
Print
(
*
vars
,
"void $Method$("
"::grpc::ServerContext* context, $Request$* request, "
"::grpc::ServerAsyncResponseWriter< $Response$>* response, "
"::grpc::CompletionQueue* cq, void *tag);
\n
"
);
}
else
if
(
ClientOnlyStreaming
(
method
))
{
printer
->
Print
(
*
vars
,
"void $Method$("
"::grpc::ServerContext* context, "
"::grpc::ServerAsyncReader< $Request$>* reader, "
"$Response$* response, "
"::grpc::CompletionQueue* cq, void *tag);
\n
"
);
}
else
if
(
ServerOnlyStreaming
(
method
))
{
printer
->
Print
(
*
vars
,
"void $Method$("
"::grpc::ServerContext* context, $Request$* request, "
"::grpc::ServerAsyncWriter< $Response$>* writer, "
"::grpc::CompletionQueue* cq, void *tag);
\n
"
);
}
else
if
(
BidiStreaming
(
method
))
{
printer
->
Print
(
*
vars
,
"void $Method$("
"::grpc::ServerContext* context, "
"::grpc::ServerReaderWriter< $Response$, $Request$>* stream, "
"::grpc::CompletionQueue* cq, void *tag);
\n
"
);
}
}
void
PrintHeaderService
(
google
::
protobuf
::
io
::
Printer
*
printer
,
void
PrintHeaderService
(
google
::
protobuf
::
io
::
Printer
*
printer
,
const
google
::
protobuf
::
ServiceDescriptor
*
service
,
const
google
::
protobuf
::
ServiceDescriptor
*
service
,
std
::
map
<
std
::
string
,
std
::
string
>
*
vars
)
{
std
::
map
<
std
::
string
,
std
::
string
>
*
vars
)
{
(
*
vars
)[
"Service"
]
=
service
->
name
();
(
*
vars
)[
"Service"
]
=
service
->
name
();
printer
->
Print
(
*
vars
,
printer
->
Print
(
*
vars
,
"class $Service$ {
\n
"
"class $Service$
final
{
\n
"
" public:
\n
"
);
" public:
\n
"
);
printer
->
Indent
();
printer
->
Indent
();
// Client side
// Client side
printer
->
Print
(
printer
->
Print
(
"class Stub : public ::grpc::InternalStub {
\n
"
"class Stub
final
: public ::grpc::InternalStub {
\n
"
" public:
\n
"
);
" public:
\n
"
);
printer
->
Indent
();
printer
->
Indent
();
for
(
int
i
=
0
;
i
<
service
->
method_count
();
++
i
)
{
for
(
int
i
=
0
;
i
<
service
->
method_count
();
++
i
)
{
...
@@ -220,7 +275,7 @@ void PrintHeaderService(google::protobuf::io::Printer *printer,
...
@@ -220,7 +275,7 @@ void PrintHeaderService(google::protobuf::io::Printer *printer,
printer
->
Print
(
"
\n
"
);
printer
->
Print
(
"
\n
"
);
// Server side
// Server side
- Synchronous
printer
->
Print
(
printer
->
Print
(
"class Service {
\n
"
"class Service {
\n
"
" public:
\n
"
);
" public:
\n
"
);
...
@@ -228,7 +283,24 @@ void PrintHeaderService(google::protobuf::io::Printer *printer,
...
@@ -228,7 +283,24 @@ void PrintHeaderService(google::protobuf::io::Printer *printer,
printer
->
Print
(
"Service() : service_(nullptr) {}
\n
"
);
printer
->
Print
(
"Service() : service_(nullptr) {}
\n
"
);
printer
->
Print
(
"virtual ~Service();
\n
"
);
printer
->
Print
(
"virtual ~Service();
\n
"
);
for
(
int
i
=
0
;
i
<
service
->
method_count
();
++
i
)
{
for
(
int
i
=
0
;
i
<
service
->
method_count
();
++
i
)
{
PrintHeaderServerMethod
(
printer
,
service
->
method
(
i
),
vars
);
PrintHeaderServerMethodSync
(
printer
,
service
->
method
(
i
),
vars
);
}
printer
->
Print
(
"::grpc::RpcService* service();
\n
"
);
printer
->
Outdent
();
printer
->
Print
(
" private:
\n
"
" ::grpc::RpcService* service_;
\n
"
);
printer
->
Print
(
"};
\n
"
);
// Server side - Asynchronous
printer
->
Print
(
"class AsyncService final {
\n
"
" public:
\n
"
);
printer
->
Indent
();
printer
->
Print
(
"AsyncService() : service_(nullptr) {}
\n
"
);
printer
->
Print
(
"~AsyncService();
\n
"
);
for
(
int
i
=
0
;
i
<
service
->
method_count
();
++
i
)
{
PrintHeaderServerMethodAsync
(
printer
,
service
->
method
(
i
),
vars
);
}
}
printer
->
Print
(
"::grpc::RpcService* service();
\n
"
);
printer
->
Print
(
"::grpc::RpcService* service();
\n
"
);
printer
->
Outdent
();
printer
->
Outdent
();
...
...
This diff is collapsed.
Click to expand it.
src/cpp/common/completion_queue.cc
+
0
−
1
View file @
2dff17d3
/*
/*
*
* Copyright 2014, Google Inc.
* Copyright 2014, Google Inc.
* All rights reserved.
* All rights reserved.
*
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment