Windows NT Systems Programming
[ Home
| Syllabus |Course Notes]
RPC Postscript
Running Second Version (Revised)
(code is here)
Server Program
- Create server project as console application
- Import ccrpc2.idl, mandels2.cpp
- Run midl on ccrpc.idl to generate
- Either use console window and type command "midl
ccrpc.idl"
- Or import into project (created below) and in Project/Settings,
custom build with the command
midl $(InputPath)
and the output file(s):
$(ProjDir)\$(InputName).h
$(ProjDir)\$(InputName)_s.c
- Import ccrpc2.h, ccrpc2_s.c (generated by midl)
- Change project settings to add to the Link tab the libraries
"rpcrt4.lib" and "rpcns4.lib"
- In "ccrpc.cpp", change the line
for (x=left, i=0; x<=right; x += xstep, i++)
to the line
for (x=left, i=0; i<width; x += xstep, i++)
(the old line wrote beyond the end of the line array)
- Build project
Client Program
- Create client project (could open another VC++) as a win32
application
- Add files mandelc2.cpp
mandelc2.rc, menus.h
- If using custom build for midl, in Project/Settings, custom build
with the command
midl $(InputPath)
and the output file(s):
$(ProjDir)\$(InputName).h
$(ProjDir)\$(InputName)_c.c
- Add files ccprc2.h, ccrpc2_c.c
- Add two libraries above
- Change general settings to use MFC in shared DLL
- added #include "memstub"
to mandelc2.cpp
- build project
ccrpc2.idl
[
uuid (87654329-4321-1234-4321-987654321CBA),
version(1.0),
endpoint ("ncacn_np:[\\pipe\\ccrpc2]")
]
interface calcline
{
typedef struct
{
double real;
double imag;
} complex;
void CalcLine([in] double left,
[in] double right,
[in] double y, [in] long width,
[out, size_is(width)] short line[]);
}
Memory Allocation (MEMSTUB)
void __RPC_FAR * __RPC_API
midl_user_allocate(size_t len)
{
return(new(unsigned char [len]));
}
void __RPC_API midl_user_free(void __RPC_FAR * ptr)
{
delete(ptr);
}
RPCs and Objects: Towards a distributed object model
- RPCs work well for stateless functions which do not access any
environment specific functions/variables
Stateless IN and stateless OUT
- If the member functions of an object are truly stateless, then
there is no problem in distributing.
- HOWEVER, one the main rationales for object is that they
encapsulate both functions and state.
- While member functions belong to the class, the variables belong
to an object
- In addition to naming the state variable, one must also name the
object containing that variable.
- Unlike function names, Objects names are created dynamically
- Object creation implies a client name, server name and a way to
resolve the two dynamically
- The constructor could hide much of this by creating a Object
shell
which knows the name of the real object living on the server
e.g. CMessage msg;
- Create an Object "shell" (analogous to a function stub)
which contains the member function stubs and appropriate state information about the
remote object.
- calls server to create a new object and return its name which is
stored in shell as a state variable.
- Each member function call (RPC) uses the stub in the object
shell which also adds the server object name so that the proper server object is accessed
- Changes to the object state are made on the server.
- Must disallow direct access to the data members of an object
(only private data members) or keep a copy of these variables in the shell (there will be
some synchronization issues).
Copyright chris wild 1997.
For problems or questions regarding this web contact [Dr. Wild].
Last updated: November 03, 1997.