summaryrefslogtreecommitdiff
path: root/TAO/examples/Callback_Quoter/Consumer_Signal_Handler.cpp
blob: 394695123ad9e10c05f3e7a7912fb26e14747000 (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
82
83
84
85
86
87
88
/* -*- C++ -*- */
// $Id$

// ===========================================================
//
//
// = LIBRARY
//    TAO/examples/Callback_Quoter
//
// = FILENAME
//    Consumer_Input_Handler.cpp
//
// = DESCRIPTION
//    Implementation of the Consumer_Signal_Handler class.
//
// = AUTHOR
//    Kirthika Parameswaran <kirthika@cs.wustl.edu>
//
// ===========================================================

#include "Consumer_Signal_Handler.h"

Consumer_Signal_Handler::Consumer_Signal_Handler (Consumer_Handler *consumer_handler)
  : consumer_handler_ (consumer_handler)
{
}

Consumer_Signal_Handler:: ~Consumer_Signal_Handler (void)
{
}

// Method to handle the ^C signal.
int
Consumer_Signal_Handler::handle_signal (int /* signum */,
                                        siginfo_t*,
                                        ucontext_t*)
{
  ACE_DEBUG ((LM_DEBUG,
              " Exiting on receiving ^C\n"));

  quit_on_signal ();
  
  return 0;
}

// Method called before the Event_Handler dies.
int
Consumer_Signal_Handler::handle_close (ACE_HANDLE,
                                       ACE_Reactor_Mask)
{
  // End of the signal handler.
  delete this;

  return 0;
}

int
Consumer_Signal_Handler::quit_on_signal (void)
{
  // Only if the consumer is registered and wants to shut down, its
  // necessary to unregister and then shutdown.

  //  CORBA::Environment TAO_TRY_ENV;

  ACE_TRY_NEW_ENV
    {
      if (consumer_handler_->unregistered_ != 1
          && consumer_handler_->registered_ == 1)
	{
	  this->consumer_handler_->server_->unregister_callback 
            (this->consumer_handler_->consumer_var_.in ());
	  ACE_DEBUG ((LM_DEBUG,
		      "Consumer Unregistered\n"));
	  ACE_TRY_CHECK;
	}
      this->consumer_handler_->consumer_servant_->shutdown 
        (ACE_TRY_ENV);
    }

  ACE_CATCHANY
    {
      ACE_TRY_ENV.print_exception ("Consumer_Input_Handler::quit_consumer_process()");
      return -1;
    }
  ACE_ENDTRY;

  return 0;
}