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
|
/*
* The Unix Channel
*
* by Michel Beaudouin-Lafon
*
* Copyright 1993-1995
* Centre d'Etudes de la Navigation Aerienne (CENA)
*
* Request management, by Stephane Chatty
*
* $Id$
* $CurLog$
*/
#ifndef ReqMgr_H_
#define ReqMgr_H_
#include "ccu/String.h"
#include "ccu/List.h"
#include "ccu/bool.h"
class ofstream;
class MsgField {
protected:
CcuString Name;
CcuString Type;
CcuString Impl;
public:
inline MsgField (const char* n, const char* t, const char* i) : Name (n), Type (t), Impl (i) {}
inline const char* GetName () const { return Name; }
inline const char* GetType () const { return Type; }
inline const char* GetImpl () const { return Impl; }
};
class MsgConstructor {
friend int Uch_parse ();
protected:
CcuListOf <MsgField> Params;
public:
inline void AddParameter (MsgField& f) { Params.Append (&f); }
inline const CcuListOf <MsgField>& GetParameters () const { return Params; }
};
class MsgType {
friend int Uch_parse ();
public:
enum msg_kind { isRequest, isAnswer, isEvent };
static const char* const ClassSuffix [3];
static const char* const EnumPrefix [3];
static const char* const EnumSuffix [3];
protected:
CcuString Name;
msg_kind Kind;
CcuListOf <MsgField> Fields;
CcuListOf <MsgField> Getters;
CcuListOf <MsgField> Setters;
CcuListOf <MsgConstructor> Constructors;
bool DefaultConstructor;
public:
inline MsgType (const char* n, msg_kind k) : Name (n), Kind (k), DefaultConstructor (false) {}
inline void AddField (MsgField* f) { Fields.Append (f); }
inline void AddConstructor (MsgConstructor* f) { Constructors.Append (f); }
inline void UseDefaultConstructor () { DefaultConstructor = true; }
inline const char* GetName () const { return Name; }
void DumpDecl (ofstream&, int);
void DumpCode (ofstream&, int);
};
enum destination { isClient = 1<<0, isServer = 1<<1};
class UchMsgMgr {
friend int Uch_parse ();
protected:
CcuString Name;
CcuListOf <MsgType> Requests;
CcuListOf <MsgType> Answers;
CcuListOf <MsgType> Events;
void SetName (const char*);
inline void AddRequest (MsgType* t) { Requests.Append (t); }
inline void AddAnswer (MsgType* t) { Answers.Append (t); }
inline void AddEvent (MsgType* t) { Events.Append (t); }
void DumpCode (const char*, int);
void DumpDecl (const char*, int);
void DumpEnum (ofstream&, MsgType::msg_kind, CcuListOf <MsgType>&);
void DumpClientCode (ofstream&);
void DumpServerCode (ofstream&);
public:
UchMsgMgr ();
~UchMsgMgr ();
void Read (const char*);
void DumpClientHeader ();
void DumpServerHeader ();
void DumpClientSource (const char*);
void DumpServerSource (const char*);
inline const char* GetName () const { return Name; }
};
#endif /* ReqMgr_H_ */
|