summaryrefslogtreecommitdiff
path: root/docs/tutorials/014/EndTask.h
blob: 1666c5e886980cdb8e4389416ba18c345bf0e1e2 (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

// $Id$

// EndTask.h
//
// Tutorial regarding a way to use ACE_Stream.
//
// written by bob mcwhirter (bob@netwrench.com)
//
//

#ifndef ENDTASK_H
#define ENDTASK_H

#include "Task.h"

// When you setup a Stream and push your modules on,
// there are two additional modules that go unseen
// by the user.
//
// The Stream pushes on a Stream_Head in front of
// your first module, and a Stream_Tail behind your
// last module.
//
// If your put() a message to the Stream Tail, it
// assumes you did so in error. This simple EndTask
// class allows you to push a message to it and just
// have it safely Go Away.
//
// All this Task does is release the Message_Block
// and return 0.  It's a suitable black-hole.


class EndTask : public Task
{

public:

  typedef Task inherited;

  EndTask(const char *nameOfTask) :
    inherited(nameOfTask, 0) {

    // when we get open()'d, it with 0 threads
    // since there is actually no processing to do.

        cerr << __LINE__ << " " << __FILE__ << endl;
  };

  virtual int open(void *)
  {
        cerr << __LINE__ << " " << __FILE__ << endl;
        return 0;
  }

  virtual int open(void)
  {
        cerr << __LINE__ << " " << __FILE__ << endl;
        return 0;
  }

  virtual ~EndTask(void) {
  };

  virtual int put(ACE_Message_Block *message,
                  ACE_Time_Value *timeout) {

        cerr << __LINE__ << " " << __FILE__ << endl;
    ACE_UNUSED_ARG(timeout);

    // we don't have anything to do, so
    // release() the message.
    ACE_DEBUG ((LM_DEBUG, "(%P|%t) %s EndTask::put() -- releasing Message_Block\n", this->nameOfTask()));
    message->release();
    return 0;
  };

};

#endif // ENDTASK_H