S
sunil
Hello,
I have a class deriving from a class that provides ability to
serialize/deserialize objects over the network. There are two classes
Requests (sent from client to server) Response(sent from server to
client), these two classes need to implement a pure virtual method
called dispatch(), however only client needs to implement
Response::dispatch() and only server needs to implement
Request::dispatch(). I am planning to build a library from these two
classes and client/server will link in this library. The goal is that
server when linked should not see concrete implementation for
Response::dispatch() as it will contain calls to client specific
code , vice versa (will cause bad link errors when building my client/
server tasks). I am constrained to use the class that provides
serialization/deserialization infrastructure. The only way I could
think of getting around this problem is to provide:
-Request.h that specifies complete interface and Request.cpp that
provides implementation only for functions common to client/server
(like getters/setters for formulating req/resp)
-Request_server.h that includes Request.h and provides inline
implementation for dispatch() function that contains calls to server
specific code (included in server)
-Request_client.h that includes Request.h and provides inline NO-OP
implementation for dispatch() .
(included in client)
However since dispatch() is virtual it cannot be inlined
(inline=compile time, viritual=runtime orthogonal to each other). The
only workaround I can think of was to implement dispatch() by calling
non-virtual function called dispatchRequest(), and implement
dispatchRequest() as no-op inline function in Request_client.h and as
acutal function with code in Request_server.h. Is this correct
solution to the problem?
Thanks
I have a class deriving from a class that provides ability to
serialize/deserialize objects over the network. There are two classes
Requests (sent from client to server) Response(sent from server to
client), these two classes need to implement a pure virtual method
called dispatch(), however only client needs to implement
Response::dispatch() and only server needs to implement
Request::dispatch(). I am planning to build a library from these two
classes and client/server will link in this library. The goal is that
server when linked should not see concrete implementation for
Response::dispatch() as it will contain calls to client specific
code , vice versa (will cause bad link errors when building my client/
server tasks). I am constrained to use the class that provides
serialization/deserialization infrastructure. The only way I could
think of getting around this problem is to provide:
-Request.h that specifies complete interface and Request.cpp that
provides implementation only for functions common to client/server
(like getters/setters for formulating req/resp)
-Request_server.h that includes Request.h and provides inline
implementation for dispatch() function that contains calls to server
specific code (included in server)
-Request_client.h that includes Request.h and provides inline NO-OP
implementation for dispatch() .
(included in client)
However since dispatch() is virtual it cannot be inlined
(inline=compile time, viritual=runtime orthogonal to each other). The
only workaround I can think of was to implement dispatch() by calling
non-virtual function called dispatchRequest(), and implement
dispatchRequest() as no-op inline function in Request_client.h and as
acutal function with code in Request_server.h. Is this correct
solution to the problem?
Thanks