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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
7221d999
Commit
7221d999
authored
Nov 24, 2015
by
Craig Tiller
Browse files
Options
Downloads
Patches
Plain Diff
Global hook for doing something in response to a synchronous server call
parent
447c795b
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/grpc++/server.h
+12
-0
12 additions, 0 deletions
include/grpc++/server.h
src/cpp/server/server.cc
+18
-0
18 additions, 0 deletions
src/cpp/server/server.cc
with
30 additions
and
0 deletions
include/grpc++/server.h
+
12
−
0
View file @
7221d999
...
...
@@ -56,6 +56,7 @@ class AsyncGenericService;
class
RpcService
;
class
RpcServiceMethod
;
class
ServerAsyncStreamingInterface
;
class
ServerContext
;
class
ThreadPoolInterface
;
/// Models a gRPC server.
...
...
@@ -84,6 +85,17 @@ class Server GRPC_FINAL : public GrpcLibrary, private CallHook {
/// call \a Shutdown for this function to ever return.
void
Wait
();
/// Global Callbacks
///
/// Can be set exactly once per application to install hooks whenever
/// a server event occurs
class
GlobalCallbacks
{
public:
virtual
void
PreSynchronousRequest
(
ServerContext
*
context
)
=
0
;
virtual
void
PostSynchronousRequest
(
ServerContext
*
context
)
=
0
;
};
static
void
SetGlobalCallbacks
(
GlobalCallbacks
*
callbacks
);
private
:
friend
class
AsyncGenericService
;
friend
class
AsynchronousService
;
...
...
...
...
This diff is collapsed.
Click to expand it.
src/cpp/server/server.cc
+
18
−
0
View file @
7221d999
...
...
@@ -51,6 +51,15 @@
namespace
grpc
{
class
DefaultGlobalCallbacks
GRPC_FINAL
:
public
Server
::
GlobalCallbacks
{
public:
void
PreSynchronousRequest
(
ServerContext
*
context
)
GRPC_OVERRIDE
{}
void
PostSynchronousRequest
(
ServerContext
*
context
)
GRPC_OVERRIDE
{}
};
static
DefaultGlobalCallbacks
g_default_callbacks
;
static
Server
::
GlobalCallbacks
*
g_callbacks
=
&
g_default_callbacks
;
class
Server
::
UnimplementedAsyncRequestContext
{
protected:
UnimplementedAsyncRequestContext
()
:
generic_stream_
(
&
server_context_
)
{}
...
...
@@ -220,8 +229,10 @@ class Server::SyncRequest GRPC_FINAL : public CompletionQueueTag {
void
Run
()
{
ctx_
.
BeginCompletionOp
(
&
call_
);
g_callbacks
->
PreSynchronousRequest
(
&
ctx_
);
method_
->
handler
()
->
RunHandler
(
MethodHandler
::
HandlerParameter
(
&
call_
,
&
ctx_
,
request_payload_
,
call_
.
max_message_size
()));
g_callbacks
->
PostSynchronousRequest
(
&
ctx_
);
request_payload_
=
nullptr
;
void
*
ignored_tag
;
bool
ignored_ok
;
...
...
@@ -304,6 +315,13 @@ Server::~Server() {
delete
sync_methods_
;
}
void
Server
::
SetGlobalCallbacks
(
GlobalCallbacks
*
callbacks
)
{
GPR_ASSERT
(
g_callbacks
==
&
g_default_callbacks
);
GPR_ASSERT
(
callbacks
!=
NULL
);
GPR_ASSERT
(
callbacks
!=
&
g_default_callbacks
);
g_callbacks
=
callbacks
;
}
bool
Server
::
RegisterService
(
const
grpc
::
string
*
host
,
RpcService
*
service
)
{
for
(
int
i
=
0
;
i
<
service
->
GetMethodCount
();
++
i
)
{
RpcServiceMethod
*
method
=
service
->
GetMethod
(
i
);
...
...
...
...
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
sign in
to comment