summaryrefslogtreecommitdiff
path: root/comm
diff options
context:
space:
mode:
authorchatty1993-11-29 11:08:19 +0000
committerchatty1993-11-29 11:08:19 +0000
commitd6bd0c0e8e08660606801e846273d4740947d658 (patch)
tree1bd0c7f4eef00d52768b11762274ca5c886ac0af /comm
parent86bc9bfd4d2915bc50999437619346b9c2114a43 (diff)
downloadivy-league-d6bd0c0e8e08660606801e846273d4740947d658.zip
ivy-league-d6bd0c0e8e08660606801e846273d4740947d658.tar.gz
ivy-league-d6bd0c0e8e08660606801e846273d4740947d658.tar.bz2
ivy-league-d6bd0c0e8e08660606801e846273d4740947d658.tar.xz
Renamed into UchMsgMgr
Heavy additions.
Diffstat (limited to 'comm')
-rw-r--r--comm/OLD/ReqMgr.cc396
-rw-r--r--comm/OLD/ReqMgr.h75
-rw-r--r--comm/OLD/ReqMgr.l4
-rw-r--r--comm/OLD/ReqMgr.y103
4 files changed, 433 insertions, 145 deletions
diff --git a/comm/OLD/ReqMgr.cc b/comm/OLD/ReqMgr.cc
index 3850723..8d317f2 100644
--- a/comm/OLD/ReqMgr.cc
+++ b/comm/OLD/ReqMgr.cc
@@ -17,49 +17,133 @@
#include <fstream.h>
#include <fcntl.h>
-UchReqMgr :: UchReqMgr ()
+UchMsgMgr :: UchMsgMgr ()
: Name ()
{
}
-UchReqMgr :: ~UchReqMgr ()
+UchMsgMgr :: ~UchMsgMgr ()
{
}
void
-UchReqMgr :: SetName (const char* n)
+UchMsgMgr :: SetName (const char* n)
{
if (Name)
- fprintf (stderr, "client type already set to %s\n", (const char*) Name);
+ fprintf (stderr, "service type already set to %s\n", (const char*) Name);
else
Name = n;
}
void
-UchReqMgr :: DumpHeader (const char* file)
+UchMsgMgr :: DumpEnum (ofstream& f, MsgType::msg_kind k, CcuListOf <MsgType>& l)
{
+ if (l.IsEmpty ())
+ return;
+
+ f << "enum " << Name << MsgType::EnumSuffix [k] << " {\n";
+ CcuListIterOf <MsgType> msg = l;
+ bool first = TRUE;
+ while (++msg) {
+ if (first)
+ first = FALSE;
+ else
+ f << ",\n";
+ f << "\t" << MsgType::EnumPrefix [k] << (*msg)->GetName ();
+ }
+ f << "\n};\n\n";
+}
+
+/*?
+Create the C++ header file containing the declarations of the requests defined in the file that
+has been read.
+?*/
+void
+UchMsgMgr :: DumpServerHeader ()
+{
+ /* build file name: <Name>ServerMsg.h, eg. FooServerMsg.h */
+ char file [128];
+ sprintf (file, "%sServerMsg.h", GetName ());
+
+ DumpDecl (file, isServer);
+}
+
+void
+UchMsgMgr :: DumpClientHeader ()
+{
+ /* build file name: <Name>ClientMsg.h, eg. FooClientMsg.h */
+ char file [128];
+ sprintf (file, "%sClientMsg.h", GetName ());
+
+ DumpDecl (file, isClient);
+}
+
+
+void
+UchMsgMgr :: DumpDecl (const char* file, int dest)
+{
+ char macro [128];
+ sprintf (macro, "%sMsg_H_", GetName ());
+
ofstream f (file, ios::out);
if (!f) {
extern int errno;
fprintf (stderr, "can't write to %s: %s\n", file, sys_errlist [errno]);
return;
}
- f << "/*\n *\tRequests for clients " << Name << "\n";
+ f << "/*\n *\tMessages for service " << Name << "\n";
f << " *\n *\tThis file was generated by reqgen - do not edit\n*/\n\n";
- f << "#ifndef " << Name << "Req_H_\n";
- f << "#define " << Name << "Req_H_\n\n";
+ f << "#ifndef " << macro << "\n";
+ f << "#define " << macro << "\n";
f << "#include <uch.h>\n\n";
-
- CcuListIterOf <RequestType> req (Requests);
- while (++req) {
- (*req)->DumpHeader (f);
- }
- f << "#endif\t/* " << Name << "Req_H_ */\n";
+
+
+ DumpEnum (f, MsgType::isRequest, Requests);
+ DumpEnum (f, MsgType::isAnswer, Answers);
+ DumpEnum (f, MsgType::isEvent, Events);
+
+ CcuListIterOf <MsgType> msg = Requests;
+ while (++msg)
+ (*msg)->DumpDecl (f, dest);
+
+ msg = Answers;
+ while (++msg)
+ (*msg)->DumpDecl (f, dest);
+
+ msg = Events;
+ while (++msg)
+ (*msg)->DumpDecl (f, dest);
+
+ f << "#endif\t/* " << macro << " */\n";
}
+
+/*?
+Create the C++ file containing the code implementing the requests defined in the file read.
+?*/
+void
+UchMsgMgr :: DumpClientSource (const char* suffix)
+{
+ /* build file name: <Name>ClientMsg.<suffix>, eg. FooClientMsg.cc */
+ char file [128];
+ sprintf (file, "%sClientMsg.%s", GetName (), suffix);
+
+ DumpCode (file, isClient);
+}
+
+void
+UchMsgMgr :: DumpServerSource (const char* suffix)
+{
+ /* build file name: <Name>ServerMsg.<suffix>, eg. FooServerMsg.cc */
+ char file [128];
+ sprintf (file, "%sServerMsg.%s", GetName (), suffix);
+
+ DumpCode (file, isServer);
+}
+
void
-UchReqMgr :: DumpSource (const char* file)
+UchMsgMgr :: DumpCode (const char* file, int dest)
{
ofstream f (file, ios::out);
if (!f) {
@@ -68,59 +152,179 @@ UchReqMgr :: DumpSource (const char* file)
return;
}
- f << "/*\n *\tRequests for clients " << Name << "\n";
+ f << "/*\n *\tMessages for service " << Name << "\n";
f << " *\n *\tThis file was generated by reqgen - do not edit\n*/\n\n";
- f << "#include \"" << file << ".h\"\n\n";
-
- CcuListIterOf <RequestType> req (Requests);
+
+ if (dest & isClient) {
+ f << "#include \"" << Name << "ClientMsg.h\"\n";
+ f << "#include \"" << Name << "Service.h\"\n";
+ }
+
+ if (dest & isServer) {
+ f << "#include \"" << Name << "ServerMsg.h\"\n";
+ f << "#include \"" << Name << "Server.h\"\n";
+ }
+ f << "\n";
+
+ CcuListIterOf <MsgType> msg = Requests;
+ while (++msg)
+ (*msg)->DumpCode (f, dest);
+
+ msg = Answers;
+ while (++msg)
+ (*msg)->DumpCode (f, dest);
+
+ msg = Events;
+ while (++msg)
+ (*msg)->DumpCode (f, dest);
+
+ if (dest & isClient)
+ DumpClientCode (f);
+
+ if (dest & isServer)
+ DumpServerCode (f);
+}
+
+void
+UchMsgMgr :: DumpClientCode (ofstream& f)
+{
+ f << "void*\n" << Name << "Service :: ConvertAnswer (UchMsgBuffer& b)\n{\n";
+ f << "\tlword type;\n";
+ f << "\tb.MsgPeek (&type);\n\n";
+ f << "\tUchMessage* a = 0;\n";
+ f << "\tswitch (type) {\n";
+ CcuListIterOf <MsgType> ans = Answers;
+ while (++ans) {
+ f << "\tcase " << "an" << (*ans)->GetName () << ":\n";
+ f << "\t\ta = new " << (*ans)->GetName () << "Ans;\n";
+ f << "\t\tbreak;\n";
+ }
+ f << "\t}\n";
+ f << "\tif (a)\n\t\tb.Get (*a);\n\treturn a;\n}\n\n";
+
+
+ f << "bool\n" << Name << "Service :: NewMessage (UchMsgBuffer& b, bool)\n{\n";
+ f << "\tlword type;\n";
+ f << "\tb.MsgPeek (&type);\n\n";
+ f << "\tUchMessage* m = 0;\n";
+ f << "\tswitch (type) {\n";
+ CcuListIterOf <MsgType> evt = Events;
+ while (++evt) {
+ f << "\tcase " << "ev" << (*evt)->GetName () << ":\n";
+ f << "\t\tm = new " << (*evt)->GetName () << "Event;\n";
+ f << "\t\tbreak;\n";
+ }
+ f << "\t}\n";
+ f << "\tif (m) {\n\t\tb.Get (*m);\n\t\tPutEvent (m);\n\t\treturn TRUE;\n";
+ f << "\t} else\n\t\treturn FALSE;\n}\n\n";
+}
+
+
+void
+UchMsgMgr :: DumpServerCode (ofstream& f)
+{
+ f << "bool\n" << Name << "Client :: NewMessage (UchMsgBuffer& b, bool)\n{\n";
+ f << "\tlword type;\n";
+ f << "\tb.MsgPeek (&type);\n\n";
+ f << "\tUchMessage* m = 0;\n";
+ f << "\tswitch (type) {\n";
+ CcuListIterOf <MsgType> req = Requests;
while (++req) {
- (*req)->DumpSource (f);
+ f << "\tcase " << "rq" << (*req)->GetName () << ":\n";
+ f << "\t\tm = new " << (*req)->GetName () << "Req;\n";
+ f << "\t\tbreak;\n";
}
+ f << "\t}\n";
+ f << "\tif (m) {\n\t\tb.Get (*m);\n\t\tm->Activate (*this);\n\t\treturn TRUE;\n";
+ f << "\t} else\n\t\treturn FALSE;\n}\n\n";
+
+ f << "UchClient*\n" << Name << "Server :: HandleNew (UchChannel* ch)\n{\n";
+ f << "\treturn new " << Name << "Client (ch);\n}\n\n";
}
+const char* const MsgType::ClassSuffix [3] = {"Req", "Ans", "Event"};
+const char* const MsgType::EnumPrefix[3] = {"rq", "an", "ev"};
+const char* const MsgType::EnumSuffix[3] = {"_requests", "_answers", "_events"};
+/*?
+Dump the declaration of a request type to a file.
+?*/
void
-RequestType :: DumpHeader (ofstream& f)
+MsgType :: DumpDecl (ofstream& f, int dest)
{
- f << "class " << Name << " : public UchMessage {\nprotected:\n";
+ char classname [128];
+ sprintf (classname, "%s%s", GetName (), ClassSuffix [Kind]);
- CcuListIterOf <RequestField> fields (Fields);
+ int emitter, receiver;
+ if (Kind == isRequest) {
+ emitter = (dest & isClient);
+ receiver = (dest & isServer);
+ } else {
+ emitter = (dest & isServer);
+ receiver = (dest & isClient);
+ }
+
+ /* name and base class */
+ f << "class " << classname << " : public UchMessage {\n";
+
+ /* field containing the type */
+ f << "protected:\n";
+ f << "\tlword\tType;\n";
+
+ /* other fields */
+ CcuListIterOf <MsgField> fields (Fields);
while (++fields) {
- RequestField* field = *fields;
+ MsgField* field = *fields;
f << "\t" << field->GetImpl () << "\t" << field->GetName () << ";\n";
}
- f << "public:\n\t\t" << Name << " ();\n";
+ /* default constructor, used in servers */
+ f << "public:\n";
+ if (!DefaultConstructor && (Fields.IsEmpty () || receiver))
+ f << "\t\t" << classname << " ();\n";
- CcuListIterOf <RequestConstructor> constr (Constructors);
- while (++constr) {
- f << "\t\t" << Name << " (";
- CcuListIterOf <RequestField> fields ((*constr)->GetParameters ());
- int first = 1;
- while (++fields) {
- if (first)
- first = 0;
- else
- f << ", ";
- f << (*fields)->GetType ();
+ /* constructors declared in the file */
+ if (emitter) {
+ CcuListIterOf <MsgConstructor> constr (Constructors);
+ while (++constr) {
+ f << "\t\t" << classname << " (";
+ CcuListIterOf <MsgField> fields ((*constr)->GetParameters ());
+ int first = 1;
+ while (++fields) {
+ if (first)
+ first = 0;
+ else
+ f << ", ";
+ f << (*fields)->GetType ();
+ }
+ f << ");\n";
}
- f << ");\n";
}
- f << "\t\t~" << Name << " ();\n";
- f << "\tvoid\tWriteTo (UchMsgBuffer&);\n";
- f << "\tvoid\tReadFrom (UchMsgBuffer&, lword);\n";
- f << "\tvoid\tActivate ();\n";
- CcuListIterOf <RequestField> getter (Getters);
+ /* destructor */
+ f << "\t\t~" << classname << " ();\n";
+
+ /* other methods */
+ if (emitter)
+ f << "\tvoid\tWriteTo (UchMsgBuffer&);\n";
+ if (receiver) {
+ f << "\tvoid\tReadFrom (UchMsgBuffer&, lword);\n";
+ if (Kind == isRequest)
+ f << "\tvoid\tActivate (UchMsgStream&);\n";
+ }
+
+ /* getters defined in the file */
+ CcuListIterOf <MsgField> getter (Getters);
while (++getter) {
- RequestField* field = *getter;
+ MsgField* field = *getter;
f << "inline\t" << field->GetType () << "\tGet" << field->GetName ()
<< " () const { return (" << field->GetType () << ") " << field->GetName () << "; }\n";
}
- CcuListIterOf <RequestField> setter (Setters);
+ /* setters defined in the file */
+ CcuListIterOf <MsgField> setter (Setters);
while (++setter) {
- RequestField* field = *setter;
+ MsgField* field = *setter;
f << "inline\tvoid\tSet" << field->GetName () << " (" << field->GetType ()
<< " f) { " << field->GetName () << " = (" << field->GetImpl () << ") f; }\n";
}
@@ -128,57 +332,77 @@ RequestType :: DumpHeader (ofstream& f)
f << "};\n\n";
}
+/*?
+Dump the code of a request class to a file.
+?*/
void
-RequestType :: DumpSource (ofstream& f)
+MsgType :: DumpCode (ofstream& f, int dest)
{
- f << Name << " :: " << Name << " ()\n: UchMessage ()\n{\n}\n\n";
-
- CcuListIterOf <RequestConstructor> constr (Constructors);
- while (++constr) {
- f << Name << " :: " << Name << " (";
- CcuListIterOf <RequestField> fields ((*constr)->GetParameters ());
- int i = 0;
- while (++fields) {
- if (i > 0)
- f << ", ";
- f << (*fields)->GetType () << " i" << i;
- ++i;
- }
- f << ")\n: UchMessage ()";
- fields.Reset ();
- i = 0;
- while (++fields) {
- f << ",\n " << (*fields)->GetName () << " (i" << i << ")";
- ++i;
- }
- f << "\n{\n}\n\n";
+ char classname [128];
+ sprintf (classname, "%s%s", GetName (), ClassSuffix [Kind]);
+
+ int emitter, receiver;
+ if (Kind == isRequest) {
+ emitter = (dest & isClient);
+ receiver = (dest & isServer);
+ } else {
+ emitter = (dest & isServer);
+ receiver = (dest & isClient);
}
- f << Name << " :: ~" << Name << " ()\n{\n}\n\n";
+ /* the default constructor*/
+ if (!DefaultConstructor && (Fields.IsEmpty () || receiver)) {
+ f << classname << " :: " << classname << " ()\n: UchMessage (),\n";
+ f << " Type (" << EnumPrefix [Kind] << Name << ")\n{\n}\n\n";
+ }
- f << "#ifdef SERVER\n\n";
- f << "void\n" << Name << " :: ReadFrom (UchMsgBuffer& b, lword l)\n{\n";
- f << "\tb";
- CcuListIterOf <RequestField> field (Fields);
- while (++field) {
- f << " >> " << (*field)->GetName ();
+ /* other constructors, used in emitters */
+ if (emitter) {
+ CcuListIterOf <MsgConstructor> constr (Constructors);
+ while (++constr) {
+ f << classname << " :: " << classname << " (";
+ CcuListIterOf <MsgField> fields ((*constr)->GetParameters ());
+ int i = 0;
+ while (++fields) {
+ if (i > 0)
+ f << ", ";
+ f << (*fields)->GetType () << " i" << i;
+ ++i;
+ }
+ f << ")\n: UchMessage (),\n Type (" << EnumPrefix [Kind] << Name << ")";
+ fields.Reset ();
+ i = 0;
+ while (++fields) {
+ f << ",\n " << (*fields)->GetName () << " (i" << i << ")";
+ ++i;
+ }
+ f << "\n{\n}\n\n";
+ }
}
- f << ";\n";
- f << "}\n\n";
- f << "#endif\t/* SERVER */\n\n";
- f << "#ifdef CLIENT\n\n";
+ /* destructor */
+ f << classname << " :: ~" << classname << " ()\n{\n}\n\n";
- f << "void\n" << Name << " :: " << "WriteTo (UchMsgBuffer& b)\n{\n";
- f << "\tb";
- field.Reset ();
- while (++field) {
- f << " << " << (*field)->GetName ();
+
+ CcuListIterOf <MsgField> field (Fields);
+ if (receiver) {
+ f << "void\n" << classname << " :: ReadFrom (UchMsgBuffer& b, lword)\n{\n";
+ f << "\tlword type;\n\tb >> type";
+ while (++field)
+ f << " >> " << (*field)->GetName ();
+ f << ";\n";
+ f << "}\n\n";
}
- f << ";\n";
- f << "}\n\n";
- f << "#endif\t/* CLIENT */\n";
+ if (emitter) {
+ f << "void\n" << classname << " :: " << "WriteTo (UchMsgBuffer& b)\n{\n";
+ f << "\tb << Type";
+ field.Reset ();
+ while (++field)
+ f << " << " << (*field)->GetName ();
+ f << ";\n";
+ f << "}\n\n";
+ }
}
diff --git a/comm/OLD/ReqMgr.h b/comm/OLD/ReqMgr.h
index 1b02196..811cca7 100644
--- a/comm/OLD/ReqMgr.h
+++ b/comm/OLD/ReqMgr.h
@@ -17,65 +17,90 @@
#include "ccu/String.h"
#include "ccu/List.h"
+#include "ccu/bool.h"
+
class ofstream;
-class RequestField {
+class MsgField {
protected:
CcuString Name;
CcuString Type;
CcuString Impl;
public:
-inline RequestField (const char* n, const char* t, const char* i) : Name (n), Type (t), Impl (i) {}
+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 RequestConstructor {
+class MsgConstructor {
friend int yyparse ();
protected:
- CcuListOf <RequestField> Params;
+ CcuListOf <MsgField> Params;
public:
-inline void AddParameter (RequestField& f) { Params.Append (&f); }
-inline const CcuListOf <RequestField>& GetParameters () const { return Params; }
+inline void AddParameter (MsgField& f) { Params.Append (&f); }
+inline const CcuListOf <MsgField>& GetParameters () const { return Params; }
};
-class RequestType {
+class MsgType {
friend int yyparse ();
+
+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;
- CcuListOf <RequestField> Fields;
- CcuListOf <RequestField> Getters;
- CcuListOf <RequestField> Setters;
- CcuListOf <RequestConstructor> Constructors;
+ msg_kind Kind;
+ CcuListOf <MsgField> Fields;
+ CcuListOf <MsgField> Getters;
+ CcuListOf <MsgField> Setters;
+ CcuListOf <MsgConstructor> Constructors;
+ bool DefaultConstructor;
+
public:
-inline RequestType (const char* n) : Name (n) { }
-inline void AddField (RequestField* f) { Fields.Append (f); }
-inline void AddConstructor (RequestConstructor* f) { Constructors.Append (f); }
+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 Dump (ofstream&);
- void DumpHeader (ofstream&);
- void DumpSource (ofstream&);
+ void DumpDecl (ofstream&, int);
+ void DumpCode (ofstream&, int);
};
+enum destination { isClient = 1<<0, isServer = 1<<1};
-class UchReqMgr {
+class UchMsgMgr {
friend int yyparse ();
protected:
CcuString Name;
- CcuListOf <RequestType> Requests;
+ CcuListOf <MsgType> Requests;
+ CcuListOf <MsgType> Answers;
+ CcuListOf <MsgType> Events;
void SetName (const char*);
-inline void Add (RequestType* t) { Requests.Append (t); }
+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:
- UchReqMgr ();
- ~UchReqMgr ();
+ UchMsgMgr ();
+ ~UchMsgMgr ();
void Read (const char*);
- void Dump (const char*);
- void DumpHeader (const char*);
- void DumpSource (const char*);
+ void DumpClientHeader ();
+ void DumpServerHeader ();
+ void DumpClientSource (const char*);
+ void DumpServerSource (const char*);
+inline const char* GetName () const { return Name; }
};
#endif /* ReqMgr_H_ */
+
diff --git a/comm/OLD/ReqMgr.l b/comm/OLD/ReqMgr.l
index bad288c..b4314ec 100644
--- a/comm/OLD/ReqMgr.l
+++ b/comm/OLD/ReqMgr.l
@@ -38,8 +38,10 @@ LexInit ()
{
if (!ResWords) {
ResWords = new CcuDictionnary (10);
- (*ResWords)["client"] = (void*) (Y_CLIENT);
+ (*ResWords)["service"] = (void*) (Y_SERVICE);
(*ResWords)["request"] = (void*) (Y_REQUEST);
+ (*ResWords)["answer"] = (void*) (Y_ANSWER);
+ (*ResWords)["event"] = (void*) (Y_EVENT);
(*ResWords)["getters"] = (void*) (Y_GETTERS);
(*ResWords)["setters"] = (void*) (Y_SETTERS);
(*ResWords)["const"] = (void*) (Y_CONST);
diff --git a/comm/OLD/ReqMgr.y b/comm/OLD/ReqMgr.y
index 4c29f00..8c0078f 100644
--- a/comm/OLD/ReqMgr.y
+++ b/comm/OLD/ReqMgr.y
@@ -34,12 +34,12 @@ static void error (const char*, ...);
#include "ReqMgr.h"
-static UchReqMgr* CurMgr;
-static RequestType* CurRequest;
-static CcuListOf <RequestField>* CurFieldList;
-static CcuDictionnaryOf <RequestField> Fields (16);
+static UchMsgMgr* CurMgr;
+static MsgType* CurMsg;
+static CcuListOf <MsgField>* CurFieldList;
+static CcuDictionnaryOf <MsgField> Fields (16);
-static void AddFieldToReq (const char*, const char*, const char*, const char*, const char*);
+static void AddFieldToMsg (const char*, const char*, const char*, const char*, const char*);
static void AddFieldToList (const char*);
%}
@@ -49,7 +49,7 @@ static void AddFieldToList (const char*);
const char *string;
}
-%token <integer> Y_CLIENT Y_REQUEST Y_YIELDS Y_GETTERS Y_SETTERS Y_CONST
+%token <integer> Y_SERVICE Y_REQUEST Y_ANSWER Y_EVENT Y_YIELDS Y_GETTERS Y_SETTERS Y_CONST
%token <string> Y_ID
%type <string> opt_star
@@ -61,12 +61,14 @@ file:
;
decl:
- client
+ service
| request
+ | answer
+ | event
;
-client:
- Y_CLIENT Y_ID ';'
+service:
+ Y_SERVICE Y_ID ';'
{
CurMgr->SetName ($2);
}
@@ -75,19 +77,44 @@ client:
request:
Y_REQUEST Y_ID
{
- CurRequest = new RequestType ($2);
- CurMgr->Add (CurRequest);
+ CurMsg = new MsgType ($2, MsgType::isRequest);
+ CurMgr->AddRequest (CurMsg);
Fields.Clear ();
}
- '{' request_entries '}' ';'
+ msg_body
;
-request_entries:
+answer:
+ Y_ANSWER Y_ID
+ {
+ CurMsg = new MsgType ($2, MsgType::isAnswer);
+ CurMgr->AddAnswer (CurMsg);
+ Fields.Clear ();
+ }
+ msg_body
+ ;
+
+event:
+ Y_EVENT Y_ID
+ {
+ CurMsg = new MsgType ($2, MsgType::isEvent);
+ CurMgr->AddEvent (CurMsg);
+ Fields.Clear ();
+ }
+ msg_body
+ ;
+
+
+ msg_body:
+ '{' msg_entries '}' ';'
+ ;
+
+msg_entries:
/* empty */
- | request_entries request_entry
+ | msg_entries msg_entry
;
-request_entry:
+msg_entry:
field
| getters
| setters
@@ -97,11 +124,11 @@ request_entry:
field:
Y_CONST Y_ID opt_star Y_ID Y_YIELDS Y_ID ';'
{
- AddFieldToReq ("const", $2, $3, $4, $6);
+ AddFieldToMsg ("const", $2, $3, $4, $6);
}
| Y_ID opt_star Y_ID Y_YIELDS Y_ID ';'
{
- AddFieldToReq (0, $1, $2, $3, $5);
+ AddFieldToMsg (0, $1, $2, $3, $5);
}
;
@@ -113,7 +140,7 @@ opt_star:
getters:
Y_GETTERS
{
- CurFieldList = &CurRequest->Getters;
+ CurFieldList = &CurMsg->Getters;
}
'(' id_list ')' ';'
;
@@ -121,7 +148,7 @@ getters:
setters:
Y_SETTERS
{
- CurFieldList = &CurRequest->Setters;
+ CurFieldList = &CurMsg->Setters;
}
'(' id_list ')' ';'
;
@@ -129,14 +156,18 @@ setters:
constructor:
Y_ID
{
- if (strcmp ($1, CurRequest->GetName ()) != 0)
+ if (strcmp ($1, CurMsg->GetName ()) != 0)
fprintf (stderr, "unknown name %s in request type %s. Considering as constructor.\n",
- $1, CurRequest->GetName ());
- RequestConstructor* c = new RequestConstructor;
- CurRequest->AddConstructor (c);
+ $1, CurMsg->GetName ());
+ MsgConstructor* c = new MsgConstructor;
+ CurMsg->AddConstructor (c);
CurFieldList = &c->Params;
}
'(' id_list ')' ';'
+ {
+ if (CurFieldList->IsEmpty ())
+ CurMsg->UseDefaultConstructor ();
+ }
;
id_list:
@@ -149,32 +180,32 @@ id_list:
#include <stdio.h>
static void
-AddFieldToReq (const char* c, const char* t, const char* s, const char* id, const char* impl)
+AddFieldToMsg (const char* c, const char* t, const char* s, const char* id, const char* impl)
{
int found;
- CcuHashCellOf <RequestField>* hc = Fields.Add (id, &found);
+ CcuHashCellOf <MsgField>* hc = Fields.Add (id, &found);
if (found) {
fprintf (stderr, "warning: duplicate field %s in request %s. Ignoring. \n",
- id, CurRequest->GetName ());
+ id, CurMsg->GetName ());
} else {
char buf [128];
if (c || s) {
sprintf (buf, "%s %s %s", (c ? c : ""), t, (s ? s : ""));
t = buf;
}
- RequestField* f = new RequestField (id, t, impl);
+ MsgField* f = new MsgField (id, t, impl);
hc->SetInfo (f);
- CurRequest->AddField (f);
+ CurMsg->AddField (f);
}
}
static void
AddFieldToList (const char* name)
{
- RequestField* f = Fields [name];
+ MsgField* f = Fields [name];
if (!f) {
fprintf (stderr, "warning: unknown field %s in request %s\n",
- name, CurRequest->GetName ());
+ name, CurMsg->GetName ());
} else {
CurFieldList->Append (f);
}
@@ -212,12 +243,18 @@ tee (int x)
case Y_ID:
s = "ID";
break;
- case Y_CLIENT:
- s = "CLIENT";
+ case Y_SERVICE:
+ s = "SERVICE";
break;
case Y_REQUEST:
s = "REQUEST";
break;
+ case Y_ANSWER:
+ s = "ANSWER";
+ break;
+ case Y_EVENT:
+ s = "EVENT";
+ break;
case Y_YIELDS:
s = "->";
break;
@@ -254,7 +291,7 @@ yywrap ()
}
void
-UchReqMgr :: Read (const char* file)
+UchMsgMgr :: Read (const char* file)
{
extern void LexInit ();
extern FILE *yyin;