summaryrefslogtreecommitdiff
path: root/comm/BusAccess.cc
diff options
context:
space:
mode:
authorsc2000-11-28 17:07:47 +0000
committersc2000-11-28 17:07:47 +0000
commitee937667fd0ecd82faab4c88d756b906fb625f1a (patch)
tree19e679318b5cb87e8be1a05a7bbc9ba5568d0814 /comm/BusAccess.cc
parent1326b11d65f7020f5f6c691305d2c090b064bd04 (diff)
downloadivy-league-ee937667fd0ecd82faab4c88d756b906fb625f1a.zip
ivy-league-ee937667fd0ecd82faab4c88d756b906fb625f1a.tar.gz
ivy-league-ee937667fd0ecd82faab4c88d756b906fb625f1a.tar.bz2
ivy-league-ee937667fd0ecd82faab4c88d756b906fb625f1a.tar.xz
Integration into IvyLeague
Uvh -> Ivl Multiplexer.* is renamed into Scheduler.* A few name conflicts in the merger with ex-DNN have been solved Imakefile is replaced by Makefile Created InetAddress.* and UnixAddress.* from Address.* Created IrdaAddress.* OLD/TextStream has been updated
Diffstat (limited to 'comm/BusAccess.cc')
-rw-r--r--comm/BusAccess.cc207
1 files changed, 98 insertions, 109 deletions
diff --git a/comm/BusAccess.cc b/comm/BusAccess.cc
index 5383e91..3f9605a 100644
--- a/comm/BusAccess.cc
+++ b/comm/BusAccess.cc
@@ -10,15 +10,17 @@
*
* $Id$
* $CurLog$
+ * Now handle Die
*/
#include "BusAccess.h"
-#include "Multiplexer.h"
+#include "Scheduler.h"
#include "BufStream.h"
-#include "ccu/String.h"
-#include "dnn/Trigger.h"
-#include "dnn/Reaction.h"
-#include "ccu/Signal.h"
+#include "InetAddress.h"
+#include "ivl/String.h"
+#include "ivl/Trigger.h"
+#include "ivl/Reaction.h"
+#include "ivl/Signal.h"
#include <stdlib.h>
#include <stdio.h>
#include <ostream.h>
@@ -26,10 +28,10 @@
#include <stdarg.h>
#include <ctype.h>
-int UchBusAccess::Version = 3;
-const char* const UchBusAccess::DefaultBus = "127:2010";
-const sword UchBusAccess::DefaultBusPort = 2010;
-const char* const UchBusAccess::DefaultBusNet = "127";
+int IvlBusAccess::Version = 3;
+const char* const IvlBusAccess::DefaultBus = "127:2010";
+const sword IvlBusAccess::DefaultBusPort = 2010;
+const char* const IvlBusAccess::DefaultBusNet = "127";
static int _BusDebug = 0;
@@ -48,49 +50,46 @@ typedef enum {
BusDie
} BusMsgType;
-
-
-
-class UchBusSubscription {
+class IvlBusSubscription {
protected:
int Id;
- CcuString Regexp;
+ IvlString Regexp;
regex_t Compiled;
public:
- UchBusSubscription (int, const char*);
+ IvlBusSubscription (int, const char*);
inline int GetId () const { return Id; }
inline const char* GetRegexp () const { return Regexp; }
inline const regex_t* GetCompiled () const { return &Compiled; }
};
-class UchBusTrigger : public DnnTrigger {
+class IvlBusTrigger : public IvlTrigger {
protected:
int Id;
- CcuString Regexp;
+ IvlString Regexp;
public:
- UchBusTrigger (const char*);
+ IvlBusTrigger (const char*);
inline int GetId () const { return Id; }
inline void SetId (int id) { Id = id; }
inline const char* GetRegexp () const { return Regexp; }
};
-class UchBusServer : public UchStream {
+class IvlBusServer : public IvlStream {
public:
- UchBusAccess* MyBus;
+ IvlBusAccess* MyBus;
- UchBusServer (UchBusAccess*);
+ IvlBusServer (IvlBusAccess*);
void HandleRead ();
};
/* this is used for local subscriptions */
-UchBusTrigger :: UchBusTrigger (const char* r)
+IvlBusTrigger :: IvlBusTrigger (const char* r)
: Id (-1),
Regexp (r)
{
}
/* this is used for remote subscriptions */
-UchBusSubscription :: UchBusSubscription (int id, const char* r)
+IvlBusSubscription :: IvlBusSubscription (int id, const char* r)
: Id (id),
Regexp (r)
{
@@ -99,8 +98,8 @@ UchBusSubscription :: UchBusSubscription (int id, const char* r)
cerr << "bad regexp " << r << "\n";
}
-UchBusServer :: UchBusServer (UchBusAccess* bus)
-: UchStream (new UchInetAddress (ANYADDR)),
+IvlBusServer :: IvlBusServer (IvlBusAccess* bus)
+: IvlStream (new IvlInetAddress (ANYADDR)),
MyBus (bus)
{
if (Listen () < 0) {
@@ -108,12 +107,12 @@ UchBusServer :: UchBusServer (UchBusAccess* bus)
return;
}
SetMode (IORead);
- Add (UchMpx);
+ Add (IvlScd);
}
/* this happens when another agent opens a connection with us */
void
-UchBusServer :: HandleRead ()
+IvlBusServer :: HandleRead ()
{
/* Accept connection */
int fd = Accept ();
@@ -125,28 +124,27 @@ UchBusServer :: HandleRead ()
/* create agent handle */
if (_BusDebug)
cout << "Someone was there. Hello!\n";
- UchBusAgent* a = new UchBusAgent (fd, MyBus);
+ IvlBusAgent* a = new IvlBusAgent (fd, MyBus);
/* send name and subscriptions */
a->SayHello ();
}
-UchBusAgent :: UchBusAgent (int fd, UchBusAccess* bus)
-: UchBufStream (),
+IvlBusAgent :: IvlBusAgent (int fd, IvlBusAccess* bus)
+: IvlBufStream (),
RemoteSubscriptions (),
MyBus (bus),
DirectMsg (16)
{
// SetMode (IOReadWrite);
SetMode (IORead);
- UchChannel::Open (fd);
- Add (UchMpx);
+ IvlChannel::Open (fd);
+ Add (IvlScd);
MyBus->Agents.Append (this);
}
-
-UchBusAgent :: UchBusAgent (const char* host, sword port, UchBusAccess *bus)
-: UchBufStream (0, new UchInetAddress (host, port)),
+IvlBusAgent :: IvlBusAgent (const char* host, sword port, IvlBusAccess *bus)
+: IvlBufStream (0, new IvlInetAddress (host, port)),
RemoteSubscriptions (),
MyBus (bus),
DirectMsg (16)
@@ -156,32 +154,30 @@ UchBusAgent :: UchBusAgent (const char* host, sword port, UchBusAccess *bus)
return;
}
SetMode (IORead);
- Add (UchMpx);
+ Add (IvlScd);
MyBus->Agents.Append (this);
}
-
-UchBusAgent :: ~UchBusAgent ()
+IvlBusAgent :: ~IvlBusAgent ()
{
MyBus->Agents.Remove (this);
Remove ();
Close ();
}
-
-/* this had to be redefined because UchChannel adds null character
+/* this had to be redefined because IvlChannel adds null character
and we don't want it */
void
-UchBusAgent :: WriteString (const char* s)
+IvlBusAgent :: WriteString (const char* s)
{
/* now that this is a BufStream, perhaps we should use Buffer? */
Write ((byte*) s, strlen (s));
}
void
-UchBusAgent :: SayHello ()
+IvlBusAgent :: SayHello ()
{
- CcuSignalBlocker b (SigPipe);
+ IvlSignalBlocker b (SigPipe);
char buf[32];
/* Say hello */
@@ -192,7 +188,7 @@ UchBusAgent :: SayHello ()
if (_BusDebug)
cout << "sending subscriptions\n";
- CcuListIterOf<UchBusTrigger> s = MyBus->LocalSubscriptions;
+ IvlListIterOf<IvlBusTrigger> s = MyBus->LocalSubscriptions;
while (++s)
SendLocalSubscription (*s);
@@ -202,7 +198,7 @@ UchBusAgent :: SayHello ()
}
void
-UchBusAgent :: SendLocalSubscription (const UchBusTrigger* s)
+IvlBusAgent :: SendLocalSubscription (const IvlBusTrigger* s)
{
char buf[32];
sprintf (buf, "%d %d%c", BusRegexp, s->GetId (), STX);
@@ -214,9 +210,9 @@ UchBusAgent :: SendLocalSubscription (const UchBusTrigger* s)
}
void
-UchBusAgent :: SayBye ()
+IvlBusAgent :: SayBye ()
{
- CcuSignalBlocker b (SigPipe);
+ IvlSignalBlocker b (SigPipe);
char buf[32];
/* Say bye */
@@ -224,10 +220,9 @@ UchBusAgent :: SayBye ()
WriteString (buf);
}
-
-/* this happens when another agent talks */
+/* this happens when another agent talks to us */
void
-UchBusAgent :: HandleRead ()
+IvlBusAgent :: HandleRead ()
{
/* read in buffer */
if (InBuffer.BufLength () == 0)
@@ -260,13 +255,13 @@ UchBusAgent :: HandleRead ()
static int id = 0;
static int
-has_id (UchBusSubscription* s)
+has_id (IvlBusSubscription* s)
{
return (s->GetId () == id);
}
void
-UchBusAgent :: ProcessLine (const char* line)
+IvlBusAgent :: ProcessLine (const char* line)
{
/* message structure is:
Bye: "0 0\002"
@@ -288,19 +283,19 @@ UchBusAgent :: ProcessLine (const char* line)
}
const char* p = (const char*) (line+nb_chars);
- DnnEvent* ev;
+ IvlEvent* ev;
switch (msg_type) {
case BusBye:
if (_BusDebug)
cout << "[bye " << Name << "]\n";
- ev = new UchAgentEvent (this, UchAgentEvent::BusAgentBye);
+ ev = new IvlAgentEvent (this, IvlAgentEvent::BusAgentBye);
Bye.Dispatch (*ev);
delete this;
break;
case BusRegexp:
if (_BusDebug)
cout << "[regexp " << Name << " " << p+1 << "]\n";
- RemoteSubscriptions.Append (new UchBusSubscription (id, p+1));
+ RemoteSubscriptions.Append (new IvlBusSubscription (id, p+1));
break;
case BusMsg:
if (_BusDebug)
@@ -316,15 +311,15 @@ UchBusAgent :: ProcessLine (const char* line)
case BusReady:
if (_BusDebug)
cout << "[ready " << Name << "]\n";
- ev = new UchAgentEvent (this, UchAgentEvent::BusNewAgent);
+ ev = new IvlAgentEvent (this, IvlAgentEvent::BusNewAgent);
MyBus->NewAgents.Dispatch (*ev);
break;
case BusDirectMsg:
{
if (_BusDebug)
cout << "[direct " << Name << id << " " << p+1 << "]\n";
- ev = new UchDirectEvent (this, p+1);
- DnnTrigger* t = DirectMsg[id];
+ ev = new IvlDirectEvent (this, p+1);
+ IvlTrigger* t = DirectMsg[id];
t->Dispatch (*ev);
break;
}
@@ -348,16 +343,16 @@ UchBusAgent :: ProcessLine (const char* line)
}
void
-UchBusAgent :: EmitEvent (const char* msg)
+IvlBusAgent :: EmitEvent (const char* msg)
{
- CcuSignalBlocker b (SigPipe);
+ IvlSignalBlocker b (SigPipe);
const int MAX_MATCHING_ARGS = 20;
regmatch_t pmatch[MAX_MATCHING_ARGS+1];
/* scan all subscriptions from this agent */
- CcuListIterOf<UchBusSubscription> r = RemoteSubscriptions;
+ IvlListIterOf<IvlBusSubscription> r = RemoteSubscriptions;
while (++r) {
- UchBusSubscription* s = *r;
+ IvlBusSubscription* s = *r;
/* does the message match the regexp? */
if (regexec (s->GetCompiled (), msg, MAX_MATCHING_ARGS, pmatch, 0) != 0)
continue;
@@ -392,7 +387,7 @@ UchBusAgent :: EmitEvent (const char* msg)
/* emit direct message */
void
-UchBusAgent :: Emit (int id, const char* fmt, ...)
+IvlBusAgent :: Emit (int id, const char* fmt, ...)
{
/* build message */
char message[4096];
@@ -403,7 +398,7 @@ UchBusAgent :: Emit (int id, const char* fmt, ...)
va_end (ap );
/* send it */
- CcuSignalBlocker b (SigPipe);
+ IvlSignalBlocker b (SigPipe);
char buf[32];
sprintf (buf, "%d %d%c", BusDirectMsg, id, STX);
WriteString (buf);
@@ -411,9 +406,9 @@ UchBusAgent :: Emit (int id, const char* fmt, ...)
WriteString ("\n");
}
-UchBusAccess :: UchBusAccess (const char* name, const char* bus)
-: UchDatagram (),
- UchBaseSignalHandler (*UchMpx, SigInt),
+IvlBusAccess :: IvlBusAccess (const char* name, const char* bus)
+: IvlDatagram (),
+ IvlBaseScheduledHandler (*IvlScd, SigInt),
Name (name),
ListenPort (0),
BroadcastPort (0),
@@ -423,7 +418,6 @@ UchBusAccess :: UchBusAccess (const char* name, const char* bus)
LocalSubscriptions ()
{
-
/** determine network list as well as broadcast port **/
/* (we accept addresses such as 123.231,123.123:2000 or 123.231 or :2000) */
@@ -441,9 +435,8 @@ UchBusAccess :: UchBusAccess (const char* name, const char* bus)
else
BroadcastPort = DefaultBusPort;
-
/** set up UDP broadcast socket **/
- UchInetAddress* a = new UchInetAddress (ANYADDR, BroadcastPort);
+ IvlInetAddress* a = new IvlInetAddress (ANYADDR, BroadcastPort);
BindTo (a);
if (!Open ()) {
perror ("Cannot open socket: ");
@@ -466,8 +459,8 @@ UchBusAccess :: UchBusAccess (const char* name, const char* bus)
SetMode (IORead);
/** set up stream **/
- Server = new UchBusServer (this);
- a = dynamic_cast<UchInetAddress*>(Server->BoundTo ());
+ Server = new IvlBusServer (this);
+ a = dynamic_cast<IvlInetAddress*>(Server->BoundTo ());
if (!a) {
cerr << "bad address type?!\n";
return;
@@ -511,7 +504,7 @@ UchBusAccess :: UchBusAccess (const char* name, const char* bus)
/* addresses are terminated by a comma or end of string */
} else {
printf ("Broadcasting on network %lx, port %d\n", mask, BroadcastPort);
- UchInetAddress ba (mask, BroadcastPort);
+ IvlInetAddress ba (mask, BroadcastPort);
Send ((byte*)handshake, strlen (handshake), ba);
numelem = 0;
mask = 0xffffffff;
@@ -543,29 +536,29 @@ UchBusAccess :: UchBusAccess (const char* name, const char* bus)
}
/* add to main loop */
- Add (UchMpx);
+ Add (IvlScd);
}
void
-UchBusAccess :: Clear ()
+IvlBusAccess :: Clear ()
{
/* say bye to all remote agents, remove and delete them */
- UchBusAgent* a;
+ IvlBusAgent* a;
while (a = Agents.RemoveFirst ()) {
a->SayBye ();
delete a;
}
}
-UchBusAccess :: ~UchBusAccess ()
+IvlBusAccess :: ~IvlBusAccess ()
{
}
/* this happens when someone sends a broadcast on the bus: a newcomer */
void
-UchBusAccess :: HandleRead ()
+IvlBusAccess :: HandleRead ()
{
/* read data */
byte buf [256];
@@ -585,7 +578,7 @@ UchBusAccess :: HandleRead ()
}
/* where did this come from? */
- UchInetAddress* a = dynamic_cast<UchInetAddress*> (From ());
+ IvlInetAddress* a = dynamic_cast<IvlInetAddress*> (From ());
if (!a) {
cerr << "bad address!?\n";
return;
@@ -605,17 +598,16 @@ UchBusAccess :: HandleRead ()
printf ("Arrivee de %s:%hu port %hu\n", remote_host, remote_port, remote_listen_port );
/* Create agent handle */
- UchBusAgent* ag = new UchBusAgent (remote_host, remote_listen_port, this);
+ IvlBusAgent* ag = new IvlBusAgent (remote_host, remote_listen_port, this);
/* send name and subscriptions */
ag->SayHello ();
}
-
void
-UchBusAccess :: HandleEvent (int id, const char* msg)
+IvlBusAccess :: HandleEvent (int id, const char* msg)
{
- UchBusTrigger* s = IdToSubscription.Get (id);
+ IvlBusTrigger* s = IdToSubscription.Get (id);
if (!s) {
cerr << "bad regexp id " << id << "\n";
return;
@@ -623,23 +615,23 @@ UchBusAccess :: HandleEvent (int id, const char* msg)
if (_BusDebug)
cout << "REGEXP " << s->GetId () << " MATCHED: " << msg << "\n";
- UchBusEvent* ev = new UchBusEvent (s->GetRegexp (), msg);
+ IvlBusEvent* ev = new IvlBusEvent (s->GetRegexp (), msg);
s->Dispatch (*ev);
}
/* this is the handler for SIGINT */
void
-UchBusAccess :: DeferredHandle (int)
+IvlBusAccess :: DeferredHandle (int)
{
cerr << "quitting\n";
Clear ();
- UchStop ();
+ IvlStop ();
}
bool
-UchBusAccess :: CheckUnicity (UchBusAgent* a, sword id)
+IvlBusAccess :: CheckUnicity (IvlBusAgent* a, sword id)
{
- CcuListIterOf<UchBusAgent> li = Agents;
+ IvlListIterOf<IvlBusAgent> li = Agents;
while (++li) {
if ((*li)->RemoteId == id && a != (*li))
return false;
@@ -648,7 +640,7 @@ UchBusAccess :: CheckUnicity (UchBusAgent* a, sword id)
}
void
-UchBusAccess :: Subscribe (DnnBaseReaction& r, const char* fmt, ...)
+IvlBusAccess :: Subscribe (IvlBaseReaction& r, const char* fmt, ...)
{
/* build regexp */
char regexp[4096];
@@ -659,13 +651,13 @@ UchBusAccess :: Subscribe (DnnBaseReaction& r, const char* fmt, ...)
va_end (ap );
/* store new subscription */
- UchBusTrigger* s = new UchBusTrigger (regexp);
+ IvlBusTrigger* s = new IvlBusTrigger (regexp);
LocalSubscriptions.Append (s);
int id = IdToSubscription.Store (s);
s->SetId (id);
/* emit to current remote agents */
- CcuListIterOf<UchBusAgent> a = Agents;
+ IvlListIterOf<IvlBusAgent> a = Agents;
while (++a)
(*a)->SendLocalSubscription (s);
@@ -673,9 +665,8 @@ UchBusAccess :: Subscribe (DnnBaseReaction& r, const char* fmt, ...)
r.SubscribeTo (*s);
}
-
void
-UchBusAccess :: Emit (const char* fmt, ...)
+IvlBusAccess :: Emit (const char* fmt, ...)
{
/* build message */
char message[4096];
@@ -685,17 +676,17 @@ UchBusAccess :: Emit (const char* fmt, ...)
vsprintf (message, fmt, ap);
va_end (ap );
- CcuListIterOf <UchBusAgent> a = Agents;
+ IvlListIterOf <IvlBusAgent> a = Agents;
while (++a)
(*a)->EmitEvent (message);
}
-DnnEventType* UchAgentEvent::BusNewAgent = new DnnEventType ("new agent", 0, 0);
-DnnEventType* UchAgentEvent::BusAgentBye = new DnnEventType ("agent bye", 0, 0);
+IvlEventType* IvlAgentEvent::BusNewAgent = new IvlEventType ("new agent", 0, 0);
+IvlEventType* IvlAgentEvent::BusAgentBye = new IvlEventType ("agent bye", 0, 0);
-UchBusEvent :: UchBusEvent (const char* r, const char* m)
-: DnnEvent (),
+IvlBusEvent :: IvlBusEvent (const char* r, const char* m)
+: IvlEvent (),
Regexp (r),
NbMatches (0),
Matches (m),
@@ -714,7 +705,7 @@ UchBusEvent :: UchBusEvent (const char* r, const char* m)
case ETX:
NbMatches++;
*q = '\0';
- MatchList.Append (new CcuString (p));
+ MatchList.Append (new IvlString (p));
p = q + 1;
/* fall through */
default:
@@ -723,34 +714,32 @@ UchBusEvent :: UchBusEvent (const char* r, const char* m)
}
}
-
-UchBusEvent :: ~UchBusEvent ()
+IvlBusEvent :: ~IvlBusEvent ()
{
- CcuListIterOf<CcuString> li = MatchList;
+ IvlListIterOf<IvlString> li = MatchList;
while (++li)
delete (*li);
}
-UchAgentEvent :: UchAgentEvent (UchBusAgent* a, DnnEventType* t)
-: DnnEvent (t),
+IvlAgentEvent :: IvlAgentEvent (IvlBusAgent* a, IvlEventType* t)
+: IvlEvent (t),
Agent (a)
{
}
-
-UchAgentEvent :: ~UchAgentEvent ()
+IvlAgentEvent :: ~IvlAgentEvent ()
{
}
-UchDirectEvent :: UchDirectEvent (UchBusAgent* a, const char* m)
-: DnnEvent (),
+IvlDirectEvent :: IvlDirectEvent (IvlBusAgent* a, const char* m)
+: IvlEvent (),
Agent (a),
Msg (m)
{
}
-UchDirectEvent::~UchDirectEvent ()
+IvlDirectEvent::~IvlDirectEvent ()
{
}