2 * $Id: RTPSHeardBeat.c,v 0.0.0.1 2003/10/07
4 * DEBUG: section 48 RTPS message HeardBeat
5 * AUTHOR: Petr Smolik petr.smolik@wo.cz
7 * ORTE - OCERA Real-Time Ethernet http://www.ocera.org/
8 * --------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
24 /**********************************************************************************/
26 RTPSHeardBeatCreate(u_int8_t *rtps_msg,u_int32_t max_msg_len,
27 SequenceNumber *firstSeqNumber,SequenceNumber *lastSeqNumber,
28 ObjectId woid,ObjectId roid,Boolean f_bit) {
29 if (max_msg_len<28) return -1;
30 rtps_msg[0]=(u_int8_t)HEARTBEAT;
31 rtps_msg[1]=ORTE_MY_MBO;
32 if (f_bit) rtps_msg[1]|=2;
33 *((ParameterLength*)(rtps_msg+2))=24;
35 *((ObjectId*)(rtps_msg+4))=roid;
37 *((ObjectId*)(rtps_msg+8))=woid;
38 *((SequenceNumber*)(rtps_msg+12))=*firstSeqNumber;
39 *((SequenceNumber*)(rtps_msg+20))=*lastSeqNumber;
43 /**********************************************************************************/
45 RTPSHeardBeat(ORTEDomain *d,u_int8_t *rtps_msg,MessageInterpret *mi) {
48 SequenceNumber fsn,lsn;
50 CSTReader *cstReader=NULL;
51 CSTRemoteWriter *cstRemoteWriter=NULL;
53 e_bit=rtps_msg[1] & 0x01;
54 f_bit=(rtps_msg[1] & 0x02)>>1;
55 roid=*((ObjectId*)(rtps_msg+4)); /* readerObjectId */
57 woid=*((ObjectId*)(rtps_msg+8)); /* writerObjectId */
59 fsn=*((SequenceNumber*)(rtps_msg+12)); /* firstSeqNumber */
61 lsn=*((SequenceNumber*)(rtps_msg+20)); /* lastSeqNumber */
63 if (SeqNumberCmp(fsn,lsn)==1) return; // lsn<fsn -> break
64 writerGUID.hid=mi->sourceHostId;
65 writerGUID.aid=mi->sourceAppId;
68 debug(48,3) ("recv: RTPS HB%c(0x%x) from 0x%x-0x%x\n",
69 f_bit ? 'F':'f',woid,mi->sourceHostId,mi->sourceAppId);
71 if ((d->guid.aid & 0x03)==MANAGER) {
72 if ((writerGUID.oid==OID_WRITE_APPSELF) &&
73 ((writerGUID.aid & 0x03)==MANAGER)) {
74 pthread_rwlock_wrlock(&d->readerManagers.lock);
75 cstReader=&d->readerManagers;
77 if (((writerGUID.oid==OID_WRITE_APPSELF) &&
78 ((writerGUID.aid & 0x03)==MANAGEDAPPLICATION)) ||
79 ((writerGUID.oid==OID_WRITE_APP) &&
80 ((writerGUID.aid & 0x03)==MANAGER))) {
81 pthread_rwlock_wrlock(&d->readerApplications.lock);
82 cstReader=&d->readerApplications;
85 if ((d->guid.aid & 3)==MANAGEDAPPLICATION) {
86 switch (writerGUID.oid) {
88 pthread_rwlock_wrlock(&d->readerManagers.lock);
89 cstReader=&d->readerManagers;
92 pthread_rwlock_wrlock(&d->readerApplications.lock);
93 cstReader=&d->readerApplications;
96 pthread_rwlock_wrlock(&d->readerPublications.lock);
97 cstReader=&d->readerPublications;
100 pthread_rwlock_wrlock(&d->readerSubscriptions.lock);
101 cstReader=&d->readerSubscriptions;
105 if (!cstReader) return;
106 cstRemoteWriter=CSTRemoteWriter_find(cstReader,&writerGUID);
107 if (!cstRemoteWriter) {
108 pthread_rwlock_unlock(&cstReader->lock);
111 cstRemoteWriter->firstSN=fsn;
112 cstRemoteWriter->lastSN=lsn;
113 cstRemoteWriter->ACKRetriesCounter=0;
114 if (SeqNumberCmp(cstRemoteWriter->sn,lsn)>0)
115 cstRemoteWriter->sn=lsn;
116 if (SeqNumberCmp(cstRemoteWriter->sn,fsn)<0) {
117 if (SeqNumberCmp(fsn,noneSN)!=0) {
118 SeqNumberDec(cstRemoteWriter->sn,fsn);
121 CSTReaderProcCSChanges(d,cstRemoteWriter);
122 if ((!f_bit) && (cstRemoteWriter->commStateACK==WAITING)) {
123 cstRemoteWriter->commStateACK=ACKPENDING;
125 cstRemoteWriter->objectEntryOID->objectEntryAID,
126 &cstRemoteWriter->repeatActiveQueryTimer,
129 cstRemoteWriter->objectEntryOID->objectEntryAID,
130 &cstRemoteWriter->delayResponceTimer,
131 1); //metatraffic timer
133 cstRemoteWriter->objectEntryOID->objectEntryAID,
134 &cstRemoteWriter->delayResponceTimer,
135 1, //metatraffic timer
136 "CSTReaderResponceTimer",
137 CSTReaderResponceTimer,
138 &cstRemoteWriter->cstReader->lock,
140 &cstRemoteWriter->cstReader->params.delayResponceTimeMin);
142 pthread_rwlock_unlock(&cstReader->lock);