summaryrefslogtreecommitdiff
path: root/TAO/tests/Exposed_Policies/RT_Properties.cpp
blob: 4a23c92f0f5227baf7dbc58cd0cd6564704e8354 (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
//$Id$

#include "RT_Properties.h"

#include "tao/ORB_Constants.h"

#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_string.h"

ACE_RCSID (ExposedPolicies, RT_Properties, "$Id$")

RT_Properties::RT_Properties (void)
  : priority_ (10)
{
  ACE_OS::strcpy (ior_source_, "poa_default.ior");
}

RT_Properties::~RT_Properties (void)
{
  // No-Op.
}

RT_Properties *
RT_Properties::read_from (const char *file_name
                          ACE_ENV_ARG_DECL)
{
  FILE *fp = ACE_OS::fopen (file_name, "r");

  RT_Properties *rt_properties;

  ACE_NEW_THROW_EX (rt_properties,
                    RT_Properties,
                    CORBA::NO_MEMORY (TAO::VMCID,
                                      CORBA::COMPLETED_NO));

  // @@ Angelo: what if the length is more than 255?
  char string_field[256];
  int int_field;
  unsigned int i = 0;

  while (fscanf (fp, "%s", string_field) != EOF )
    {
      if (ACE_OS::strcmp (string_field, "Priority") == 0)
        {
          fscanf (fp, "%d", &int_field);
          rt_properties->priority (int_field);
        }
      else if (ACE_OS::strcmp (string_field, "Priority_Bands") == 0)
        {
          fscanf (fp, "%d", &int_field);
          rt_properties->priority_bands_.length (int_field);

        }
      else if (ACE_OS::strcmp (string_field, "Priority_Range") == 0)
        {
          fscanf (fp, "%d", &int_field);
          rt_properties->priority_bands_[i].low = int_field;

          fscanf (fp, "%d", &int_field);
          rt_properties->priority_bands_[i].high = int_field;

          ++i;
        }
    }


  return rt_properties;
}

void
RT_Properties::priority (RTCORBA::Priority priority)
{
  this->priority_ = priority;
}

RTCORBA::Priority
RT_Properties::priority (void)
{
  return this->priority_;
}

void
RT_Properties::priority_bands (const RTCORBA::PriorityBands& priority_bands)
{
  this->priority_bands_ = priority_bands;
}

const RTCORBA::PriorityBands&
RT_Properties::priority_bands (void)
{
  return this->priority_bands_;
}


void
RT_Properties::ior_source (const char *s)
{
  // @@ Angelo: please use strncpy() for strings like this, otherwise
  // you could blow the buffer limits!
  ACE_OS::strcpy (this->ior_source_, s);
}

const char *
RT_Properties::ior_source (void)
{
  return this->ior_source_;
}