summaryrefslogtreecommitdiff
path: root/apps/Gateway/Gateway/Config_Files.cpp
blob: 7e99902b0dbb3e340db34293248878417af3d69e (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "ace/OS.h"
// $Id$

#include "Config_Files.h"

// This fixes a nasty bug with cfront-based compilers (like
// Centerline).
typedef FP::Return_Type FP_RETURN_TYPE;

FP_RETURN_TYPE
Consumer_Config_File_Parser::read_entry (Consumer_Config_File_Entry &entry, 
					 int &line_number) 
{
  FP_RETURN_TYPE read_result;

  // Increment the line count.
  line_number++;

  // Ignore comments, check for EOF and EOLINE if this succeeds, we
  // have our connection id.
  while ((read_result = this->getint (entry.conn_id_)) != FP::SUCCESS) 
    {
      if (read_result == FP::EOFILE) 
	return FP::EOFILE;
      else if (read_result == FP::EOLINE 
	       || read_result == FP::COMMENT)
	line_number++;
    }

  // Get the logic id.
  if ((read_result = this->getint (entry.supplier_id_)) != FP::SUCCESS)
    return read_result;

  // Get the payload type.
  if ((read_result = this->getint (entry.type_)) != FP::SUCCESS)
    return read_result;

  // get all the destinations.
  entry.total_destinations_ = 0;

  while ((read_result = this->getint (entry.destinations_[entry.total_destinations_]))
	 == FP::SUCCESS)
    ++entry.total_destinations_; // do nothing

  if (read_result == FP::EOLINE || read_result == FP::EOFILE)
    return FP::SUCCESS;
  else
    return read_result;
}

FP_RETURN_TYPE
Connection_Config_File_Parser::read_entry (Connection_Config_File_Entry &entry, 
					   int &line_number) 
{
  char buf[BUFSIZ];
  FP_RETURN_TYPE read_result;
  // increment the line count
  line_number++;

  // Ignore comments, check for EOF and EOLINE
  // if this succeeds, we have our connection id
  while ((read_result = this->getint (entry.conn_id_)) != FP::SUCCESS) 
    {
      if (read_result == FP::EOFILE) 
	return FP::EOFILE;
      else if (read_result == FP::EOLINE || 
	       read_result == FP::COMMENT) 
	line_number++;
    }

  // get the hostname
  if ((read_result = this->getword (entry.host_)) != FP::SUCCESS)
    return read_result;

  int port;

  // Get the port number.
  if ((read_result = this->getint (port)) != FP::SUCCESS)
    return read_result;
  else
    entry.remote_poconsumer_ = (u_short) port;

  // Get the direction.
  if ((read_result = this->getword (buf)) != FP::SUCCESS)
    return read_result;
  else
    entry.direction_ = buf[0];

  // Get the max retry delay.
  if ((read_result = this->getint (entry.max_retry_delay_)) != FP::SUCCESS)
    return read_result;

  // Get the local port number.
  if ((read_result = this->getint (port)) != FP::SUCCESS)
    return read_result;
  else
    entry.local_poconsumer_ = (u_short) port;

  return FP::SUCCESS;
}

#if defined (DEBUGGING)
int main (int argc, char *argv[])
{
  if (argc != 4) {
//    ACE_ERROR_RETURN ((LM_ERROR, "%s filename\n", argv[0]), -1);
    cerr << argv[0] << " CCfilename filename Mapfilename.\n";
    exit (1);
  }
  FP_RETURN_TYPE result;
  Connection_Config_File_Entry CCentry;
  Connection_Config_File_Parser CCfile;
  
  CCfile.open (argv[1]);

  int line_number = 0;

  printf ("ConnID\tHost\t\tRPort\tDir\tRetry\tLPort\n");

  // Read config file line at a time.
  while ((result = CCfile.read_entry (CCentry, line_number)) != EOF)
    {
      if (result != FP::SUCCESS)
 //	ACE_DEBUG ((LM_DEBUG, "Error line %d.\n", line_number));
	cerr << "Error at line " << line_number << endl;
      else 
	printf ("%d\t%s\t%d\t%c\t%d\t%c\t%d\n",
	       CCentry.conn_id_, CCentry.host_, CCentry.remote_poconsumer_, CCentry.direction_,
	       CCentry.max_retry_delay_, CCentry.transform_, CCentry.local_poconsumer_);
    }
  CCfile.close();

  Consumer_Config_File_Entry entry;
  Consumer_Config_File_Parser file;

  file.open (argv[2]);

  line_number = 0;

  printf ("\nConnID\tLogic\tPayload\tDestinations\n");

  // Read config file line at a time.
  while ((result = file.read_entry (entry, line_number)) != EOF)
    {
      if (result != FP::SUCCESS)
	cerr << "Error at line " << line_number << endl;
      else 
	{
	  printf ("%d\t%d\t%d\t%d\t",
		  entry.conn_id_, entry.supplier_id_, entry.type_);
	  while (--entry.total_destinations_ >= 0)
	    printf ("%d,", entry.destinations_[entry.total_destinations_]);
	  printf ("\n");
	}
    }
  file.close();

  return 0;
}
#endif /* DEBUGGING */

#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION)
template class File_Parser<Connection_Config_File_Entry>;
template class File_Parser<Consumer_Config_File_Entry>;
#endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */