OWLNext
7.0
Borland's Object Windows Library for the modern age
Toggle main menu visibility
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
13
namespace
owl
{
14
15
OWL_DIAGINFO
;
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
//
24
TSerializer::TSerializer
(HWND hwndTarget,
uint32
length,
void
* data)
25
{
26
if
(!::IsWindow(hwndTarget) || length == 0)
27
return
;
28
TMsgId
msg = ::RegisterWindowMessage(
SerializerMessage
);
29
30
::SendMessage(hwndTarget, msg,
Begin
, length);
31
32
// Send blocks 4 at a time
33
//
34
uint32
* dataBlocks = (
uint32
*)data;
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
//
50
uint8
* dataBytes = (
uint8
*)dataBlocks;
51
uint32
finalBlock = 0;
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
68
DEFINE_RESPONSE_TABLE1
(
TSerializeReceiver
,
TEventHandler
)
69
EV_REGISTERED
(
SerializerMessage
, BlockReceived),
70
END_RESPONSE_TABLE
;
71
72
//
73
// Constructor
74
//
75
TSerializeReceiver
::
TSerializeReceiver
()
76
:
77
TEventHandler
(), Data(
nullptr
), CurPtr(
nullptr
), Length(0)
78
{
79
}
80
81
//
82
/// Automatically puts the data blocks back together.
83
//
84
TResult
85
TSerializeReceiver::BlockReceived
(
TParam1
param1,
TParam2
param2)
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
109
case
TSerializer::Data1
:
110
case
TSerializer::Data2
:
111
case
TSerializer::Data3
:
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
124
if
(param1 >=
TSerializer::Data2
)
125
*CurPtr++ =
static_cast<
char
>
(
LoUint8
(
HiUint16
(param2)));
126
127
if
(param1 ==
TSerializer::Data3
)
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
//
138
void
139
TSerializeReceiver::DataReceived
(
uint32
/*length*/
,
void
*
/*data*/
)
140
{
141
}
142
143
}
// OWL namespace
144
/* ========================================================================== */
145
owl::TEventHandler
TEventHandler is a base class from which you can derive classes that handle messages.
Definition
eventhan.h:162
owl::TSerializeReceiver
Mix-in class that automatically puts together the block of data sent by TSerializer.
Definition
serialze.h:59
owl::TSerializeReceiver::DataReceived
virtual void DataReceived(uint32 length, void *data)
This virtual function will be called whenever the data has been reconstructed.
Definition
serialze.cpp:139
owl::TSerializeReceiver::BlockReceived
TResult BlockReceived(TParam1, TParam2)
Automatically puts the data blocks back together.
Definition
serialze.cpp:85
owl::TSerializeReceiver::TSerializeReceiver
TSerializeReceiver()
Definition
serialze.cpp:75
owl::TSerializer::Data3
@ Data3
data is stored in bits 0x00FFFFFF of lParam
Definition
serialze.h:39
owl::TSerializer::Data2
@ Data2
data is stored in bits 0x0000FFFF of lParam
Definition
serialze.h:38
owl::TSerializer::Data4
@ Data4
data is stored in bits 0xFFFFFFFF of lParam
Definition
serialze.h:40
owl::TSerializer::End
@ End
end of data, lParam == 0
Definition
serialze.h:36
owl::TSerializer::Data1
@ Data1
data is stored in bits 0x000000FF of lParam
Definition
serialze.h:37
owl::TSerializer::Begin
@ Begin
beginning of data, lParam length of data
Definition
serialze.h:41
owl::TSerializer::TSerializer
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_RESPONSE_TABLE1
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition
eventhan.h:492
pch.h
owl
Object Windows Library (OWLNext Core).
Definition
animctrl.h:22
owl::TMsgId
UINT TMsgId
Message ID type.
Definition
dispatch.h:53
owl::HiUint16
uint16 HiUint16(LRESULT r)
Definition
defs.h:270
owl::uint8
unsigned char uint8
Definition
number.h:32
owl::uint32
unsigned long uint32
Definition
number.h:34
owl::TParam2
LPARAM TParam2
Second parameter type.
Definition
dispatch.h:55
owl::EV_REGISTERED
EV_REGISTERED(DRAGLISTMSGSTRING, DragNotify)
owl::TParam1
WPARAM TParam1
First parameter type.
Definition
dispatch.h:54
owl::LoUint16
uint16 LoUint16(LRESULT r)
Definition
defs.h:264
owl::OWL_DIAGINFO
OWL_DIAGINFO
Definition
animctrl.cpp:14
owl::END_RESPONSE_TABLE
END_RESPONSE_TABLE
Definition
button.cpp:26
owl::HiUint8
uint8 HiUint8(LRESULT r)
Definition
defs.h:282
owl::TResult
LRESULT TResult
Result type.
Definition
dispatch.h:52
owl::LoUint8
uint8 LoUint8(LRESULT r)
Definition
defs.h:276
serialze.h
Definition of TSerializer class.
SerializerMessage
#define SerializerMessage
Serializer window targets should catch the following registered message to receive the block of data.
Definition
serialze.h:50
windowev.h
Event response table macros for windows messages.
source
owlcore
serialze.cpp
Generated by
1.18.0