53 if(
mPort<=0)
return false;
54 if(
mIp==
"")
return false;
55 if(
mIp.find(
':',0)!=std::string::npos)
return false;
62 if(!
Valid())
return res;
69 FD_DHV(
"SimplenetAddress::IpColonPort(): " << ipcolonport <<
" --> ?");
74 std::size_t cpos = ipcolonport.find(
':',0);
75 if(cpos==std::string::npos)
return;
77 if(cpos+1>= ipcolonport.length())
return;
79 mIp=ipcolonport.substr(0,cpos);
83 FD_DHV(
"SimplenetAddress::IpColonPort(): " << ipcolonport <<
" --> " <<
IpColonPort());
93 if(this->
mIp < rOther.
mIp)
return true;
94 if(this->
mIp > rOther.
mIp)
return false;
101 #ifdef FAUDES_IODEVICE_SIMPLENET
121 (void) rLabel; (void) pContext;
127 (void) rLabel; (void) pContext;
129 FD_DHV(
"AttributeSimplenetOutput(" <<
this <<
")::DoRead(tr)");
161 (void) rLabel; (void) pContext;
167 (void) rLabel; (void) pContext;
169 FD_DHV(
"AttributeSimplenetInput(" <<
this <<
")::DoRead(tr)");
203 FD_DHV(
"AttributeSimplenetEvent::AttributeSimplenetEvent(" <<
this <<
")");;
204 pOutputPrototype=OutputPrototypep();
205 pInputPrototype=InputPrototypep();
212 FD_DHV(
"AttributeSimplenetEvent(" <<
this <<
"): form other attr " << &rOtherAttr);
248 int syncSend(
int dest,
const char* data,
int len,
int flag) {
252 int rc=send(dest, data+from, left, 0);
254 std::stringstream errstr;
255 errstr <<
"Simplenet fatal network error (cannot send message)";
256 throw Exception(
"nDevice::syncSend", errstr.str(), 553,
true);
266 FD_DHV(
"nDevice(" <<
this <<
")::nDevice()");
272 mName=
"SimplenetNode";
277 faudes_mutex_init(&
mMutex);
284 FD_DHV(
"nDevice(" <<
this <<
")::~nDevice()");
288 faudes_mutex_destroy(&
mMutex);
293 FD_DHV(
"nDevice(" <<
this <<
")::Clear()");
360 FD_DHV(
"nDevice(" <<
this <<
")::Compile()");
368 FD_DHV(
"nDevice::DoWrite()");
386 std::map<std::string,std::string>::const_iterator nit;
391 if(defaddress.
Valid())
400 FD_DHV(
"nDevice::DoReadPreface()");
410 std::stringstream errstr;
411 errstr <<
"Simplenet address expected at " << rTr.
FileLine();
412 throw Exception(
"nDevice::DoRead", errstr.str(), 50);
417 while(!rTr.
Eos(
"Network")) {
429 std::stringstream errstr;
430 errstr <<
"Simplenet address expected at " << rTr.
FileLine();
431 throw Exception(
"nDevice::DoRead", errstr.str(), 50);
437 if(token.
IsBegin(
"BroadcastAddress")) {
441 std::stringstream errstr;
442 errstr <<
"Simplenet address expected at " << rTr.
FileLine();
443 throw Exception(
"nDevice::DoRead", errstr.str(), 50);
445 rTr.
ReadEnd(
"BroadcastAddress");
452 while(!rTr.
Eos(
"Network")) {
460 if(!defaddress.
Valid()) {
461 std::stringstream errstr;
462 errstr <<
"Simplenet address expected at " << rTr.
FileLine();
463 throw Exception(
"nDevice::DoRead", errstr.str(), 50);
474 #define LOCK_E {int rc = faudes_mutex_lock(&mMutex); \
475 if(rc) {FD_ERR("nDevice::LOCK_E: lock mutex error\n"); exit(1); }}
476 #define UNLOCK_E {int rc = faudes_mutex_unlock(&mMutex); \
477 if(rc) {FD_ERR("nDevice::LOCK_E: unlock mutex error\n"); exit(1); }}
478 #define TLOCK_E {int rc = faudes_mutex_lock(&ndevice->mMutex); \
479 if(rc) {FD_ERR("nDevice::TLOCK_E: lock mutex error\n"); exit(1); }}
480 #define TUNLOCK_E {int rc = faudes_mutex_unlock(&ndevice->mMutex); \
481 if(rc) {FD_ERR("nDevice::TLOCK_E: unlock mutex error\n"); exit(1); }}
494 std::stringstream errstr;
495 errstr <<
"Unknown output event " << output;
496 throw Exception(
"nDevice::WriteOutput", errstr.str(), 65);
502 std::stringstream errstr;
503 errstr <<
"Invalid output attribute " << output;
504 throw Exception(
"nDevice::WriteOutput", errstr.str(), 65);
509 FD_DHV(
"nDevice::WriteOutput(): message: " << message.substr(0,message.length()-1));
517 if(!sit->second.mEvents.Empty())
518 if(!sit->second.mEvents.Exists(output))
520 clientsock=sit->second.mClientSocket;
522 FD_DHV(
"nDevice::WriteOutput(): to socket " << clientsock);
523 syncSend(clientsock, message.c_str(), message.length(), 0);
527 FD_DH(
"nDevice::WriteOutput(): failed to notify client on socket " << clientsock);
530 FD_DHV(
"nDevice::WriteOutput(): done");
544 std::map<std::string,std::string>::iterator nit;
546 if(nit->first ==
mName)
continue;
556 int hostname_len =1023;
557 if(gethostname(hostname,hostname_len)!=0) {
558 std::stringstream errstr;
559 errstr <<
"Simplenet fatal network error (cannot get hostname)";
560 throw Exception(
"nDevice::Start", errstr.str(), 553);
562 hostname[hostname_len]=0;
569 std::stringstream errstr;
570 errstr <<
"Simplenet fatal network error (cannot open server socket)";
571 throw Exception(
"nDevice::Start", errstr.str(), 553);
574 faudes_setsockopt(
mListenSocket,SOL_SOCKET, SO_REUSEADDR, &reuse,
sizeof(reuse));
576 struct sockaddr_in serveraddr;
577 memset(&serveraddr, 0,
sizeof(serveraddr));
578 serveraddr.sin_family = AF_INET;
579 serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
582 if(bind(
mListenSocket, (
struct sockaddr *) &serveraddr,
sizeof(serveraddr)) <0) {
583 std::stringstream errstr;
584 errstr <<
"Simplenet fatal network error (cannot bind socket)";
585 throw Exception(
"nDevice::Start", errstr.str(), 553);
589 std::stringstream errstr;
590 errstr <<
"Simplenet fatal network error (cannot listen from socket)";
591 throw Exception(
"nDevice::Start", errstr.str(), 553);
596 std::stringstream errstr;
597 errstr <<
"Simplenet fatal network error (cannot open broadcast socket)";
598 throw Exception(
"nDevice::Start", errstr.str(), 553);
601 faudes_setsockopt(
mBroadcastSocket,SOL_SOCKET, SO_REUSEADDR, &reuse,
sizeof(reuse));
602 faudes_setsockopt(
mBroadcastSocket,SOL_SOCKET, SO_REUSEPORT, &reuse,
sizeof(reuse));
605 if(faudes_setsockopt(
mBroadcastSocket, SOL_SOCKET, SO_BROADCAST, &reuse,
sizeof(reuse)) ) {
606 std::stringstream errstr;
607 errstr <<
"Simplenet fatal network error (cannot setopt broadcast socket)";
608 throw Exception(
"nDevice::Start", errstr.str(), 553);
611 struct sockaddr_in broadcastaddr;
612 memset(&broadcastaddr, 0,
sizeof(broadcastaddr));
613 broadcastaddr.sin_family = AF_INET;
614 broadcastaddr.sin_addr.s_addr = htonl(INADDR_ANY);
617 if(bind(
mBroadcastSocket, (
struct sockaddr *) &broadcastaddr,
sizeof(broadcastaddr)) <0) {
618 std::stringstream errstr;
619 errstr <<
"Simplenet fatal network error (cannot bind broadcast socket)";
620 throw Exception(
"nDevice::Start", errstr.str(), 553);
627 std::stringstream errstr;
628 errstr <<
"Simplenet fatal thread error (cannot create thread)";
629 throw Exception(
"nDevice::Start", errstr.str(), 554);
637 FD_DH(
"nDevice::Stop()");
643 std::string message=
"<Stop> " +
mNetwork +
" " +
mName +
" </Stop>\n";
644 struct sockaddr_in broadcastaddr;
645 memset(&broadcastaddr,
'\0',
sizeof(broadcastaddr));
646 broadcastaddr.sin_family=AF_INET;
651 (
struct sockaddr *) & broadcastaddr,
sizeof(broadcastaddr));
654 FD_DH(
"nDevice::Stop(): waiting for listen thread");
656 FD_DH(
"nDevice::Stop(): listen thread finished");
679 std::map<std::string,nDevice::ServerState>::iterator sit;
680 std::map<int,nDevice::ClientState>::iterator cit;
684 FD_DH(
"nDevice::Listen(" << ndevice <<
")");
686 faudes_systime_t lastbroadcast;
687 lastbroadcast.tv_sec=0;
688 lastbroadcast.tv_nsec=0;
689 #ifdef FAUDES_DEBUG_IODEVICE
702 if(!sit->second.mAddress.Valid()) {
703 FD_DH(
"nDevice::Listen(): missing server address for node: " << sit->first);
709 if(sit->second.mServerSocket<=0) {
710 FD_DH(
"nDevice::Listen(): missing server connection for node: " << sit->first);
719 if(cit->second.mClientSocket<0)
continue;
720 if(cit->second.mConnected) clientmis--;
722 #ifdef FAUDES_DEBUG_IODEVICE
723 if(clientmis!=servermis)
724 FD_DH(
"nDevice::Listen(): missing clients to subscribe: #"<< clientmis);
743 faudes_systime_t now;
744 faudes_gettimeofday(&now);
745 faudes_mstime_t diffms;
749 std::string message=
"<Request> "
750 + ndevice->
mNetwork +
" " + ndevice->
mName +
" </Request>\n";
752 struct sockaddr_in broadcastaddr;
753 memset(&broadcastaddr,
'\0',
sizeof(broadcastaddr));
754 broadcastaddr.sin_family=AF_INET;
759 0,(
struct sockaddr *) & broadcastaddr,
sizeof(broadcastaddr));
761 FD_DH(
"nDevice::Listen(): broadcast request: " << message.substr(0,message.length()-1) <<
" #" << rc);
763 faudes_gettimeofday(&lastbroadcast);
770 if(sit->second.mServerSocket>0)
continue;
772 if(!sit->second.mAddress.Valid())
continue;
774 FD_DH(
"nDevice::Listen(): subscribing to " << sit->first <<
775 " at " << sit->second.mAddress.IpColonPort());
777 int serversock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
779 FD_DH(
"nDevice::Listen(): subscription failed: no socket");
783 unsigned long int serverinaddr = INADDR_NONE;
784 if(serverinaddr==INADDR_NONE) {
785 FD_DH(
"nDevice::Listen(): using address as advertised");
786 serverinaddr = inet_addr(sit->second.mAddress.Ip().c_str());
788 if(serverinaddr==INADDR_NONE) {
789 struct hostent *host;
790 host = gethostbyname(sit->second.mAddress.Ip().c_str());
792 FD_DH(
"nDevice::Listen(): using address by name lookup");
793 serverinaddr = *(
unsigned long int*) host->h_addr;
796 if(serverinaddr==INADDR_NONE) {
797 FD_DH(
"nDevice::Listen(): subscription failed: invalid address " << sit->second.mAddress.Ip());
798 faudes_closesocket(serversock);
802 struct sockaddr_in serveraddress;
803 memset(&serveraddress, 0,
sizeof(serveraddress));
804 serveraddress.sin_family = AF_INET;
805 serveraddress.sin_addr.s_addr=serverinaddr;
806 serveraddress.sin_port = htons(sit->second.mAddress.Port());
808 if(connect(serversock, (
struct sockaddr*) &serveraddress,
sizeof(serveraddress))<0) {
809 FD_DH(
"nDevice::Listen(): subscription failed: connect");
810 faudes_closesocket(serversock);
816 hello=
"% Simplenet universal event subscription: "+ndevice->
mName+
" subscribing from "+sit->first+
"\n";
817 syncSend(serversock, hello.c_str(), hello.length(), 0);
818 hello=
"% Expecting notifications in format '<Notify> event_name </Notify>'\n";
819 syncSend(serversock, hello.c_str(), hello.length(), 0);
820 hello=
"% Trying to subscribe to all required events\n";
821 syncSend(serversock, hello.c_str(), hello.length(), 0);
823 faudes_closesocket(serversock);
827 FD_DH(
"nDevice::Listen(): subscription failed: cannot write");
828 faudes_closesocket(serversock);
832 FD_DH(
"nDevice::Listen(): subscribing to " << sit->first <<
" via socket " << serversock);
833 sit->second.mServerSocket=serversock;
836 sevents.
Name(
"Subscribe");
837 std::string message=sevents.
ToString() +
"\n";
838 syncSend(serversock,message.c_str(), message.length(),0);
845 FD_DH(
"nDevice::Listen(): subscribing to " << sit->first <<
" via socket " << serversock <<
": ok");
854 if(mysocks_max<ndevice->mListenSocket) mysocks_max=ndevice->
mListenSocket;
855 if(mysocks_max>= FD_SETSIZE)
FD_ERR(
"NDeviceListen: fail to select socket " << mysocks_max);
858 if(mysocks_max< ndevice->mBroadcastSocket) mysocks_max=ndevice->
mBroadcastSocket;
859 if(mysocks_max>= FD_SETSIZE)
FD_ERR(
"NDeviceListen: fail to select socket " << mysocks_max);
863 int serversock=sit->second.mServerSocket;
864 if(serversock<0)
continue;
865 if(mysocks_max< serversock) mysocks_max=serversock;
866 if(mysocks_max>= FD_SETSIZE)
FD_ERR(
"NDeviceListen: fail to select socket " << mysocks_max);
867 FD_SET(serversock, &mysocks);
871 int clientsock=cit->second.mClientSocket;
872 if(clientsock<0)
continue;
873 if(mysocks_max< clientsock) mysocks_max=clientsock;
874 if(mysocks_max>= FD_SETSIZE)
FD_ERR(
"NDeviceListen: fail to select socket " << mysocks_max);
875 FD_SET(clientsock, &mysocks);
882 int avail=select(mysocks_max+1, &mysocks, NULL, NULL, &tv);
891 #ifdef FAUDES_DEBUG_IODEVICE
893 if((debuglisten>10) || (avail>0)) {
894 FD_DH(
"nDevice::Listen(): listen as node \"" << ndevice->
mName <<
"\" on network \"" << ndevice->
mNetwork <<
"\"" <<
" #" << avail);
904 struct sockaddr_in clientaddr;
905 socklen_t clientaddr_len =
sizeof(clientaddr);
906 clientsock=accept(ndevice->
mListenSocket, (
struct sockaddr *) &clientaddr, &clientaddr_len );
908 FD_DH(
"nDevice::Listen(): failed to accept incomming connection");
911 FD_DH(
"nDevice::Listen(): accepted connection from client " << inet_ntoa(clientaddr.sin_addr) <<
912 " on socket " << clientsock);
916 hello=
"% Simplenet Event Server: "+ndevice->
mName+
" providing events\n";
917 syncSend(clientsock, hello.c_str(), hello.length(), 0);
918 hello=
"% Notifications will have format '<Notify> event_name </Notify>'\n";
919 syncSend(clientsock, hello.c_str(), hello.length(), 0);
920 hello=
"% Commands are accepted in format '<Cmd> cmd_name </Cmd>'\n";
921 syncSend(clientsock, hello.c_str(), hello.length(), 0);
922 hello=
"% Supported commands are Subscribe, Info, Status, and ResetRequest\n";
923 syncSend(clientsock, hello.c_str(), hello.length(), 0);
925 faudes_closesocket(clientsock);
929 FD_DH(
"nDevice::Listen(): connection test failed: cannot write");
930 faudes_closesocket(clientsock);
950 struct sockaddr_in fromaddr;
951 socklen_t fromaddr_len =
sizeof(fromaddr);
952 data_len=recvfrom(ndevice->
mBroadcastSocket,data,data_len,0, (
struct sockaddr*) &fromaddr,&fromaddr_len);
953 if(data_len<0) data_len=0;
955 if(data_len>=1)
if(data[data_len-1]==
'\n') data[data_len-1]=0;
956 FD_DH(
"nDevice::Listen(): received udp datagram " << data <<
957 " from " << inet_ntoa(fromaddr.sin_addr));
975 if(sit->second.mServerSocket==-1) {
976 lastbroadcast.tv_sec=0;
977 lastbroadcast.tv_nsec=0;
981 if(snode!=ndevice->
mName) {
983 std::string message=
"<Advert> "
985 + ndevice->
mName +
" " +
988 struct sockaddr_in replyaddr;
989 memset(&replyaddr,
'\0',
sizeof(replyaddr));
990 replyaddr.sin_family=AF_INET;
996 int rc = sendto(ndevice->
mBroadcastSocket,message.c_str(),message.length(),0,(
struct sockaddr *) & replyaddr,
sizeof(replyaddr));
998 FD_DH(
"nDevice::Listen(): reply advert: " << message.substr(0,message.length()-1) <<
" #" << rc);
1000 FD_DH(
"nDevice::Listen(): ingoring request from myself");
1003 FD_DH(
"nDevice::Listen(): ingoring request from other network");
1013 addr.
Ip(inet_ntoa(fromaddr.sin_addr));
1014 FD_DHV(
"nDevice::Listen(): figure actual ip address " << addr.
Ip());
1017 FD_DH(
"nDevice::Listen(): fallback to explicit ip address " << addr.
Ip());
1019 std::map<std::string,nDevice::ServerState>::iterator sit;
1022 FD_DH(
"nDevice::Listen(): ignoring irrelevant advert from " << node);
1023 }
else if(sit->second.mAddress.Valid()) {
1024 FD_DH(
"nDevice::Listen(): ignoring address overwrite (hardwired?) " << node);
1027 if(!sit->second.mAddress.Valid()) {
1028 FD_DH(
"nDevice::Listen(): accept advert " << node);
1029 sit->second.mAddress=addr;
1030 if(sit->second.mServerSocket>=0) faudes_closesocket(sit->second.mServerSocket);
1031 sit->second.mServerSocket=-1;
1034 FD_DH(
"nDevice::Listen(): ingoring advert from other network");
1038 FD_DH(
"nDevice::Listen(): ignore invalid udp message");
1047 int serversock=sit->second.mServerSocket;
1048 if(serversock<0)
continue;
1049 if(FD_ISSET(serversock, &mysocks)) {
1051 FD_DH(
"nDevice::Listen(): reading sock " << serversock);
1054 int count = recv(serversock, buffer, 1024, 0);
1056 FD_DH(
"nDevice::Listen(): reading server sock " << serversock <<
" : eof");
1057 faudes_closesocket(serversock);
1058 sit->second.mServerSocket=-1;
1061 FD_DH(
"nDevice::Listen(): reading server sock " << serversock <<
": #" << count);
1063 sit->second.mLineBuffer +=std::string(buffer);
1066 if(buffer[count-1]==
'\n')
1067 if(sit->second.mLineBuffer.length()>0)
1069 const std::string& linebuffer = sit->second.mLineBuffer;
1070 #ifdef FAUDES_DEBUG_IODEVICE
1071 if(linebuffer.length()>0)
1072 if(linebuffer[0]!=
'%')
1073 FD_DH(
"nDevice::Listen(): reading server sock " << serversock <<
": line: " << linebuffer);
1079 while(tr.
Peek(token)) {
1086 FD_DH(
"nDevice::Listen(): found event " << event);
1095 FD_DH(
"nDevice::Listen(): found device info");
1116 while(!tr.
Eos(section)) tr.
Get(token);
1121 FD_DH(
"nDevice::Listen(): error: ignore token");
1125 FD_DH(
"nDevice::Listen(): " << serversock <<
": invalid notification");
1127 sit->second.mLineBuffer.clear();
1135 int clientsock=cit->second.mClientSocket;
1136 if(clientsock<0)
continue;
1137 if(FD_ISSET(clientsock, &mysocks)) {
1139 FD_DH(
"nDevice::Listen(): reading client sock " << clientsock);
1142 int count = recv(clientsock, buffer, 1024, 0);
1144 FD_DH(
"nDevice::Listen(): reading client sock " << clientsock <<
" : eof");
1146 faudes_closesocket(clientsock);
1147 cit->second.mClientSocket=-1;
1148 cit->second.mConnected=
false;
1152 FD_DH(
"nDevice::Listen(): reading client sock " << clientsock <<
": #" << count);
1154 cit->second.mLineBuffer +=std::string(buffer);
1157 if(buffer[count-1]==
'\n')
1158 if(cit->second.mLineBuffer.length()>0)
1160 const std::string& linebuffer = cit->second.mLineBuffer;
1161 #ifdef FAUDES_DEBUG_IODEVICE
1162 if(linebuffer.length()>0)
1163 if(linebuffer[0]!=
'%')
1164 FD_DH(
"nDevice::Listen(): reading client sock " << clientsock <<
": line: " << linebuffer);
1170 while(tr.
Peek(token)) {
1176 std::string response=
"<NAck> </NAck>\n";
1177 FD_DH(
"nDevice::Reply(" << clientsock <<
"): received cmd " << cmd);
1181 response=ndevice->
ToString() +
"\n";
1193 if(cmd==
"ResetRequest") {
1194 FD_DH(
"nDevice::Reply(" << clientsock <<
"): reset request");
1202 syncSend(clientsock, response.c_str(), response.length(), 0);
1205 if(token.
IsBegin(
"Subscribe")) {
1207 sevents.
Read(tr,
"Subscribe");
1209 sevents.
Name(
"Subscribed");
1210 FD_DH(
"nDevice::Reply(" << clientsock <<
"): providing events " << sevents.
ToString());
1212 cit->second.mEvents.Clear();
1213 cit->second.mEvents.InsertSet(sevents);
1214 cit->second.mConnected=
true;
1215 std::string response=sevents.
ToString()+
"\n";
1218 syncSend(clientsock, response.c_str(), response.length(), 0);
1222 FD_DH(
"nDevice::Reply(" << clientsock <<
"): invalid cmd");
1224 cit->second.mLineBuffer.clear();
1231 FD_DH(
"nDevice::Listen(): broadcast condition");
1243 FD_DH(
"nDevice::Listen(): select error");
1249 FD_DH(
"nDevice::Listen(): close client sockets");
1252 int clientsock= cit->second.mClientSocket;
1253 if(clientsock>0) faudes_closesocket(clientsock);
1254 cit->second.mClientSocket=-1;
1255 cit->second.mConnected=
false;
1260 FD_DH(
"nDevice::Listen(): close server sockets");
1262 int serversock=sit->second.mServerSocket;
1263 if(serversock>0) faudes_closesocket(serversock);
1264 sit->second.mServerSocket=-1;
1266 FD_DH(
"nDevice::Listen(): terminating listen thread");
1267 faudes_thread_exit(NULL);
1281 std::string message=
"<Cmd> ResetRequest </Cmd>\n";
1286 int serversock=sit->second.mServerSocket;
1287 if(serversock<0)
continue;
1288 FD_DH(
"nDevice::Reset(): sending reset request to socket " << serversock);
1289 syncSend(serversock, message.c_str(), message.length(), 0);
#define FD_ERR(message)
Debug: report more errors with file/line info.
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
faudes type implementation macros, overall
Attribute for the configuration of a input or output mapping.
const AttributeVoid * pOutputPrototype
Output Prototype (set to nontrivial attribute in derived classes)
void DefaultOutput(void)
Set to default output attribute.
const AttributeVoid * pInputPrototype
Input Prototype (set to nontrivial attribute in derived classes)
void DefaultInput(void)
Set to default input attribute.
Configuration of a networked input or output.
void DoAssign(const AttributeSimplenetEvent &rSrc)
DoAssign.
AttributeSimplenetEvent(void)
Default constructor (no mapping at all)
static const AttributeSimplenetInput * InputPrototypep(void)
Prototype, input (construct on first use static)
static const AttributeSimplenetOutput * OutputPrototypep(void)
Prototype, output (construct on first use static)
Configuration of a network output mapping.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads the attribute from TokenReader, see AttributeVoid for public wrappers.
Auto register faudes-type with specified type name.
Set of indices with symbolic names.
bool Exists(const Idx &rIndex) const
Test existence of index.
void SymbolicName(Idx index, const std::string &rName)
Set new name for existing index.
Idx Index(const std::string &rName) const
Index lookup.
void RestrictSet(const NameSet &rOtherSet)
Restrict to elements specified by rOtherSet.
int Port(void) const
Get TCP port.
bool operator<(const SimplenetAddress &rOther) const
Order for sorting containers of addresses.
std::string IpColonPort(void) const
Get as colon seperated string.
bool Valid(void) const
Return true if valid.
SimplenetAddress(void)
Default constructor.
std::string mIp
Ip address.
std::string Ip(void) const
Get IP address.
Set of indices with symbolic names and attributes.
A TokenReader reads sequential tokens from a file or string.
std::string FileLine(void) const
Return "filename:line".
bool Eos(const std::string &rLabel)
Peek a token and check whether it ends the specified section.
void ReadEnd(const std::string &rLabel)
Close the current section by matching the previous ReadBegin().
std::string ReadString(void)
Read string token.
void ReadBegin(const std::string &rLabel)
Open a section by specified label.
bool Get(Token &token)
Get next token.
bool Peek(Token &token)
Peek next token.
A TokenWriter writes sequential tokens to a file, a string or stdout.
void WriteEnd(const std::string &rLabel)
Write end label.
Tokens model atomic data for stream IO.
const std::string & StringValue(void) const
Get string value of a name token.
@ Begin
<label> (begin of section)
bool IsString(void) const
Test token Type.
bool ExistsAttributeString(const std::string &name)
Test attibute existence.
bool IsBegin(void) const
Test token Type.
void SetEmpty(const std::string &rName)
Initialize as empty-tag token.
void SetBegin(const std::string &rName)
Initialize as Begin token.
void InsAttributeString(const std::string &name, const std::string &value)
Insert named attribute with string value.
const std::string & AttributeStringValue(const std::string &name)
Access attribute value.
TokenType Type(void) const
Get token Type.
Base class of all libFAUDES objects that participate in the run-time interface.
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Read configuration data from file with label specified.
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
Write configuration data to a string.
An nDevice implements networked IO via a simple TCP/IP protocol.
void BroadcastAddress(const std::string &rAddr)
Set broadcast address for address resolution Note: you can only set the broadcast address while the d...
void InsNode(const std::string &rNodeName)
Add a node to the network configuration.
void ServerAddress(const std::string &rAddr)
Set server address of this node.
virtual void Compile(void)
Set up internal data structures.
virtual void DoReadPreface(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Actual method to read device configuration from tokenreader.
virtual void Clear(void)
Clear all configuration.
void InsNodeAddress(const std::string &rNode, const std::string &rAddress)
Add entry to node name resolution.
SimplenetAddress mListenAddress
Simplenet: address of my server incl port (localhost:40000)
TaNameSet< AttributeSimplenetEvent > * pConfiguration
Overall configuration (with actual type)
std::string mNetwork
Simplenet: network id.
std::map< std::string, EventSet > mInputSubscriptions
Compiled data: map subscriptions.
void NetworkName(const std::string &rNetwork)
Set network name to participate.
faudes_thread_t mThreadListen
Background: thread handle (global)
virtual ~nDevice(void)
Explicit destructor.
std::map< std::string, ServerState > mInputServerStates
Background: connection states to event servers (by node name)
void InsOutputEvent(const std::string &event)
Insert event as output event.
int mBroadcastSocket
Background: udp broadcast socket (background only)
void ClearNodes(void)
Add a node to the network configuration.
virtual void DoWritePreface(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Actual method to write the device configuration to a TokenWriter.
std::map< int, ClientState > mOutputClientStates
Background: map sockets to connection states (shared)
faudes_mutex_t mMutex
Background: mutex for below shared variables.
friend void * NDeviceListen(void *)
nDevice(void)
Default constructor.
SimplenetAddress mEffectiveListenAddress
Simplenet: effective address of my server port.
virtual void Stop(void)
Deactivate the device.
virtual void WriteOutput(Idx output)
Run output command.
SimplenetAddress mBroadcastAddress
Simplenet: address for udp broadcast (255.255.255.255:40000.
bool mStopListen
Background: request to join via flag (mutexed)
virtual void Reset(void)
Reset device.
std::map< std::string, std::string > mNetworkNodes
Simplenet: list of nodes in this network incl default addresses.
int mListenSocket
Background: server socket to listen (background only)
virtual void Start(void)
Activate the device.
void InsInputEvent(const std::string &event)
Insert event as input event.
Virtual base class to define the interface for event io.
bool mResetRequest
Reset request marker (mutexed)
faudes_mutex_t * pBufferMutex
Actual mutex for input buffer (mutexted)
virtual void Clear(void)
Clear all configuration.
virtual const EventSet & Inputs(void) const
Get inputs as plain set.
virtual void Compile(void)
Compile inner data-structures.
std::string mDefaultLabel
Default label for token io.
faudes_cond_t * pWaitCondition
Actual Wait Condition.
virtual void DoReadPreface(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads non-event-configuration data from TokenReader.
virtual void Stop(void)
Deactivate the device.
virtual void Start(void)
Activate the device.
EventSet * mpConfiguration
Overall event configuration (uses cast for type)
EventSet mInputs
All inputs.
EventSet mOutputs
All outputs.
virtual void Reset(void)
Reset device.
virtual void DoWritePreface(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Writes non-event-configuration data from TokenWriter.
faudes_mutex_t * pWaitMutex
Actual Wait Condition Mutex.
std::deque< Idx > * pInputBuffer
Actual Fifo buffer for input readings.
DeviceState mState
Status: running, starting etc.
virtual const EventSet & Outputs(void) const
Get outputs as plain set.
virtual void Clear(void)
Clear all set.
NameSet EventSet
Convenience typedef for plain event sets.
const std::string & Name(void) const
Return name of TBaseSet.
Simple networked events via TCP/IP.
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
void * NDeviceListen(void *arg)
Idx ToIdx(const std::string &rString)
Convert a string to Idx.
std::string ToStringInteger(Int number)
integer to string
int syncSend(int dest, const char *data, int len, int flag)
AutoRegisterType< nDevice > gRtiRegisterSimplenetDevice("SimplenetDevice")
Background: state of a connection to a client (shared)