summaryrefslogtreecommitdiff
path: root/apps/JAWS/remora/app/Remora_Import.cc
blob: c97451f05663832103bb135cb9d8e233b33294f2 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// $Id$ 

#include "Remora_Import.h"

Remora_Import::Remora_Import(const char* label, int value,
			     int min_value, int max_value)
  : remora_agent_(0)
{
  this->control_.value_ = value;
  this->control_.label_ = label;
  this->control_.max_ = max_value;
  this->control_.min_ = min_value;

  this->init();
}

Remora_Import::Remora_Import(const Remora_Import& import)
  : remora_agent_(import.remora_agent_)
{
  this->control_.value_ = import.control_.value_; 
  this->control_.label_ = import.control_.label_;
  this->control_.max_ = import.control_.max_;
  this->control_.min_ = import.control_.min_;
}

Remora_Import::~Remora_Import()
{
  PMCTRY
    {
      if (this->remora_agent_ != 0)
	{
	  this->remora_agent_->removeControl(this->control_.label_);
	  this->remora_agent_->_release();
	}
    }
  PMCCATCH(remora::Invalid_Statistic, excp)
    {
      cerr << "Tried to remove invalid statistic.";
    }
  PMCAND_CATCH(CORBA::SystemException, excp)
    {
      CORBA::release(this->remora_agent_);
    }
  PMCEND_CATCH
}

void
Remora_Import::init()
{
  PMCTRY
    {
      int argc = 1;
      char* argv[1];
      argv[0] = CONTROL_AGENT_NAME;

      CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
      
      cout << this->control_.label_ << " Binding to server..." << endl;
      this->remora_agent_ =
	remora::Remora_Controls_Agent::_bind(CONTROL_AGENT_NAME);

      cout << this->control_.label_ << " Registering Control..." << endl;
      this->remora_agent_->acceptNewControl(this->control_);
    }
  PMCCATCH(CORBA::Exception, excp)
    {
      cerr << excp << endl;
    }
  PMCEND_CATCH
}

CORBA::Long
Remora_Import::grab_value(void)
{
  PMCTRY
    {
      if (this->remora_agent_ != 0)
	{
	  cout << this->control_.label_ << " Grabbing a value from the client." << endl;
	  this->remora_agent_->getControlState(this->control_);
	}
      
      // C++ exception handling needs a 'finally' construct
      return this->control_.value_;
    }
  PMCCATCH(CORBA::SystemException, sysex)
    {
      cerr << sysex << endl;
      this->remora_agent_->_release();
      this->remora_agent_ = 0;

      return this->control_.value_;
    }
  PMCAND_CATCH(remora::Invalid_Control, excp)
    {
      PMCTRY
	{
	  this->remora_agent_->acceptNewControl(this->control_);
	}
      PMCCATCH(CORBA::SystemException, sysex2)
	{
	  return this->control_.value_;
	}
      PMCEND_CATCH

      return this->control_.value_;
    }
  PMCEND_CATCH
}