summaryrefslogtreecommitdiff
path: root/docs/tutorials/013/block.cpp
blob: 5dd72a2013e3397d7d425f438fcda7594e778c72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

// $Id$

#include "block.h"

/*
   Construct a Dat_Block to contain a unit of work.  Note the careful
   construction of the baseclass to set the block type and the locking
   strategy. 
 */
Data_Block::Data_Block (Unit_Of_Work * _data)
        : ACE_Data_Block (0, ACE_Message_Block::MB_DATA, 0, 0, new Lock (), 0, 0)
         ,data_ (_data)
{
    ACE_DEBUG ((LM_DEBUG, "(%P|%t) 0x%x Data_Block ctor for 0x%x\n", (void *) this, (void *) data_));
}

/*
   The Lock object created in the constructor is stored in the baseclass and
   available through the locking_strategy() method.  We can cast it's value to
   our Lock object and invoke the destroy() to indicate that we want it to go
   away when the lock is released. 
 */
Data_Block::~Data_Block (void)
{
    ACE_DEBUG ((LM_DEBUG, "(%P|%t) 0x%x Data_Block dtor for 0x%x\n", (void *) this, (void *) data_));
    ((Lock *) locking_strategy ())->destroy ();
    delete data_;
}

/*
   Return the data 
 */
Unit_Of_Work *Data_Block::data (void)
{
    return this->data_;
}

Data_Block:: Lock::Lock (void)
{
    ACE_DEBUG ((LM_DEBUG, "(%P|%t) 0x%x Lock ctor\n", (void *) this));
}

Data_Block:: Lock::~Lock (void)
{
    ACE_DEBUG ((LM_DEBUG, "(%P|%t) 0x%x Lock dtor\n", (void *) this));
}

/*
   Delete ourselves to prevent any memory leak
 */
int Data_Block::Lock::destroy (void)
{
    delete this;
    return (0);
}

/*
   Create an baseclass unit of work when we instantiate a hangup message. 
 */
Message_Block::Message_Block (void)
        :ACE_Message_Block (new Data_Block (new Unit_Of_Work ()))
{
    ACE_DEBUG ((LM_DEBUG, "(%P|%t) 0x%x Message_Block ctor for shutdown\n", (void *) this));
    this->msg_type (MB_HANGUP);
}

/*
   Store the unit of work in a Data_Block and initialize the baseclass with
   that data. 
 */
Message_Block::Message_Block (Unit_Of_Work * _data)
        :ACE_Message_Block (new Data_Block (_data))
{
    ACE_DEBUG ((LM_DEBUG, "(%P|%t) 0x%x Message_Block ctor for 0x%x\n", (void *) this, (void *) _data));
}

Message_Block::~Message_Block (void)
{
    ACE_DEBUG ((LM_DEBUG, "(%P|%t) 0x%x Message_Block dtor\n", (void *) this));
}