OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
serialze.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of classes TSerializer and TSerializeReceiver
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/serialze.h>
10#include <owl/windowev.h>
11#include <stdio.h>
12
13namespace owl {
14
16
17//
18/// Breaks down the data into blocks and sends each block to the window via
19/// SendMessage.
20///
21/// wParam of the SendMessage is of type TBlock which signifies what
22/// lParam contains.
23//
25{
26 if (!::IsWindow(hwndTarget) || length == 0)
27 return;
29
30 ::SendMessage(hwndTarget, msg, Begin, length);
31
32 // Send blocks 4 at a time
33 //
35 while (length > 3) {
36 ::SendMessage(hwndTarget, msg, Data4, *dataBlocks);
37 dataBlocks += 1;
38 length -= 4;
39 }
40
41 // Block was an even multiple of 4
42 //
43 if (length == 0) {
44 ::SendMessage(hwndTarget, msg, End, 0);
45 return;
46 }
47
48 // Length must be either 1, 2, or 3
49 //
52
53 if (length == 3)
54 finalBlock += 0x100L * dataBytes[2];
55
56 if (length >= 2)
57 finalBlock += 0x10000L * dataBytes[1];
58
59 finalBlock += 0x1000000L * dataBytes[0];
60
61 ::SendMessage(hwndTarget, msg, int(length), finalBlock);
62 ::SendMessage(hwndTarget, msg, End, 0);
63}
64
65//----------------------------------------------------------------------------
66
67
71
72//
73// Constructor
74//
76:
77 TEventHandler(), Data(nullptr), CurPtr(nullptr), Length(0)
78{
79}
80
81//
82/// Automatically puts the data blocks back together.
83//
86{
87 switch (param1) {
88 case TSerializer::Begin: {
89 Length = static_cast<uint32>(param2);
90 Data = new char[Length];
91 CurPtr = Data;
92 return 0;
93 }
94
95 case TSerializer::End: {
96 DataReceived(Length, Data);
97 delete[] Data;
98 Data = nullptr;
99 return 0;
100 }
101
102 case TSerializer::Data4: {
103 uint32* ptr = (uint32*)CurPtr;
104 *ptr = static_cast<uint32>(param2);
105 CurPtr += 4;
106 return 0;
107 }
108
112 // Fall through
113 //
114 break;
115
116 default: // ignored, unknown block type
117 return 0;
118 }
119
120 // Unpack the last remaining bytes
121 //
122 *CurPtr++ = static_cast<char>(HiUint8(HiUint16(param2)));
123
125 *CurPtr++ = static_cast<char>(LoUint8(HiUint16(param2)));
126
128 *CurPtr++ = static_cast<char>(HiUint8(LoUint16(param2)));
129
130 return 0;
131}
132
133//
134/// This virtual function will be called whenever the data has been reconstructed.
135/// \note Derived classes should override this function to copy the data because it will
136/// be deleted when this function returns.
137//
138void
139TSerializeReceiver::DataReceived(uint32 /*length*/, void * /*data*/)
140{
141}
142
143} // OWL namespace
144/* ========================================================================== */
145
TEventHandler is a base class from which you can derive classes that handle messages.
Definition eventhan.h:162
Mix-in class that automatically puts together the block of data sent by TSerializer.
Definition serialze.h:59
virtual void DataReceived(uint32 length, void *data)
This virtual function will be called whenever the data has been reconstructed.
Definition serialze.cpp:139
TResult BlockReceived(TParam1, TParam2)
Automatically puts the data blocks back together.
Definition serialze.cpp:85
@ Data3
data is stored in bits 0x00FFFFFF of lParam
Definition serialze.h:39
@ Data2
data is stored in bits 0x0000FFFF of lParam
Definition serialze.h:38
@ Data4
data is stored in bits 0xFFFFFFFF of lParam
Definition serialze.h:40
@ End
end of data, lParam == 0
Definition serialze.h:36
@ Data1
data is stored in bits 0x000000FF of lParam
Definition serialze.h:37
@ Begin
beginning of data, lParam length of data
Definition serialze.h:41
TSerializer(HWND hwndTarget, uint32 length, void *data)
Breaks down the data into blocks and sends each block to the window via SendMessage.
Definition serialze.cpp:24
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
uint16 HiUint16(LRESULT r)
Definition defs.h:270
unsigned long uint32
Definition number.h:34
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
uint16 LoUint16(LRESULT r)
Definition defs.h:264
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
uint8 HiUint8(LRESULT r)
Definition defs.h:282
LRESULT TResult
Result type.
Definition dispatch.h:52
uint8 LoUint8(LRESULT r)
Definition defs.h:276
Definition of TSerializer class.
#define SerializerMessage
Serializer window targets should catch the following registered message to receive the block of data.
Definition serialze.h:50
Event response table macros for windows messages.
#define EV_REGISTERED(str, method)
Resonse table entry for a registered message.
Definition windowev.h:122