[fpc-devel] Proposed change in simpleipc
Luiz Americo Pereira Camara
pascalive at bol.com.br
Mon Dec 18 17:28:30 CET 2006
While developing with simpleipc i found that there's no straightforward
way to identify the type of a message (see the forth paragraph of
http://lazarusroad.blogspot.com/2006/12/only-one-instance.html), so i
looked what i could do to improve it.
Currently, TMessageType is defined as an enum type with two possible
values: mtString and mtUnknow. If you use SendMessage mtUnknow is used
if SendMessageString is used mtString is used. But the message type is
not being used: under windows the message type is not even passed to
the server, under linux is passed but not used.
What i propose is simple: change the TMessageType to an 32bit ordinal
type (longint or longword), provide ways the user to send custom message
types and add a MsgType property to IPCServer. This way the user
(programmer) can send messages with different purposes and easily know
what to do when they arrive. Some thing like that:
with IPCServer do
begin
case MsgType of
mtString:;
mtMyType1:;
mtMyType2:;
end;
end;
The patch i'm sending does:
- Change TMessageType to longint
- Define mtString and mtUnknow as constants
- Add overloaded methods SendMessage and SendMessageString with an
extra parameter (MsgType)
- Added MsgType property to TSimpleIPCServer
- Changed some capitalizations
win32
- MsgType is passed through an unused CopyDataStruct field
unix:
- No changes at all, just fixed a bug (mtString was used always)
Notice that there's no memory or resource increase since the patch uses
previously unused resources.
I'm sending also a test program written in Lazarus. It was tested under
win32 and linux (ubuntu 10.06)
Luiz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testipc.zip
Type: application/zip
Size: 2996 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20061218/5f54a5ff/attachment.zip>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ipcdiff.zip
Type: application/zip
Size: 1512 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20061218/5f54a5ff/attachment-0001.zip>
More information about the fpc-devel
mailing list