summaryrefslogtreecommitdiff
path: root/docs/tutorials/013/work.h
blob: bdd0835e09802ede2209a35ef4ca2e1502a44dae (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

// $Id$

#ifndef WORK_H
#define WORK_H

#include "ace/Log_Msg.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Synch.h"
#include "mld.h"

/*
   Our specilized message queue and thread pool will know how to do "work" on
   our Unit_Of_Work baseclass.
 */
class Unit_Of_Work
{
public:
    Unit_Of_Work (void);

    virtual ~ Unit_Of_Work (void);

        // Display the object instance value
    void who_am_i (void);

        // The baseclass can override this to show it's "type name"
    virtual void what_am_i (void);

        // This is where you do application level logic.  It will be
        // called once for each thread pool it passes through.  It
        // would typically implement a state machine and execute a
        // different state on each call.
    virtual int process (void);

        // This is called by the last Task in the series (see task.h)
        // in case our process() didn't get through all of it's states.
    virtual int fini (void);

protected:
    ACE_Atomic_Op < ACE_Mutex, int >state_;
    MLD;
};

/*
   A fairly trivial work derivative that implements an equally trivial state
   machine in process()
 */
class Work : public Unit_Of_Work
{
public:
    Work (void);

    Work (int message);

    virtual ~ Work (void);

    void what_am_i (void);

    int process (void);

    int fini (void);

protected:
    int message_;
    MLD;
};

#endif