30 #ifndef _GENERIC_PORT_HXX_
31 #define _GENERIC_PORT_HXX_
61 template <
typename DataManipulator,
class COUPLING_POLICY >
65 typedef typename DataManipulator::Type
DataType;
75 void close (PortableServer::POA_var poa, PortableServer::ObjectId_var
id);
77 template <
typename TimeType,
typename TagType>
void erase(
TimeType time,
TagType tag,
bool before );
105 template <
typename DataManipulator,
typename COUPLING_POLICY >
107 cond_instance(& this->storedDatas_mutex),waitingForConvenientDataId(false),
108 waitingForAnyDataId(false),lastDataIdSet(false) {}
110 template <
typename DataManipulator,
typename COUPLING_POLICY>
112 typename DataTable::iterator it;
113 for (it=storedDatas.begin(); it!=storedDatas.end(); ++it) {
115 std::cerr <<
"~GenericPort() : destruction de la donnnée associée au DataId :"<< (*it).first << std::endl;
117 DataManipulator::delete_data( (*it).second );
121 template <
typename DataManipulator,
typename COUPLING_POLICY>
void
123 PortableServer::ObjectId_var
id) {
126 poa->deactivate_object (
id);
129 template <
typename DataManipulator,
typename COUPLING_POLICY>
void
133 std::cout <<
"-------- wakeupWaiting ------------------" << std::endl;
135 storedDatas_mutex.lock();
136 if (waitingForAnyDataId || waitingForConvenientDataId) {
138 std::cout <<
"-------- wakeupWaiting:signal --------" << std::endl;
139 std::cout << std::flush;
141 cond_instance.signal();
143 storedDatas_mutex.unlock();
152 template <
typename DataManipulator,
typename COUPLING_POLICY>
153 template <
typename TimeType,
typename TagType>
162 std::cerr <<
"parametres emis: " << time <<
", " << tag << std::endl;
163 DataManipulator::dump(dataParam);
170 typedef typename COUPLING_POLICY::DataIdContainer DataIdContainer;
173 DataId dataId(time,tag);
177 DataIdContainer dataIds(dataId, *
this);
179 typename DataIdContainer::iterator dataIdIt = dataIds.begin();
181 bool expectedDataReceived =
false;
184 std::cout <<
"-------- Put : MARK 1 ------------------" << std::endl;
186 if ( dataIds.empty() )
return;
188 std::cout <<
"-------- Put : MARK 1bis ------------------" << std::endl;
193 DataType data = DataManipulator::get_data(dataParam);
199 std::cout <<
"-------- Put : MARK 2 ------ "<< (dataIdIt == dataIds.end()) <<
"------------" << std::endl;
200 std::cout <<
"-------- Put : MARK 2bis "<< (*dataIdIt) <<
"------------------" << std::endl;
202 storedDatas_mutex.lock();
204 for (;dataIdIt != dataIds.end();++dataIdIt) {
207 std::cout <<
"-------- Put : MARK 3 ------------------" << std::endl;
210 if (nbOfIter > 0) data = DataManipulator::clone(data);
212 std::cout <<
"-------- Put : MARK 3bis -----"<< dataIdIt.operator*() <<
"------------" << std::endl;
215 DataId currentDataId=*dataIdIt;
218 std::cerr <<
"processing dataId : "<< currentDataId << std::endl;
220 std::cout <<
"-------- Put : MARK 4 ------------------" << std::endl;
230 typename DataTable::iterator wDataIt = storedDatas.lower_bound(currentDataId);
232 std::cout <<
"-------- Put : MARK 5 ------------------" << std::endl;
237 if (wDataIt == storedDatas.end() || storedDatas.key_comp()(currentDataId,(*wDataIt).first) ) {
239 std::cout <<
"-------- Put : MARK 6 ------------------" << std::endl;
242 wDataIt = storedDatas.insert(wDataIt, make_pair (currentDataId, data));
247 std::cout <<
"-------- Put : MARK 7 ------------------" << std::endl;
251 DataType old_data = (*wDataIt).second;
252 (*wDataIt).second = data;
254 DataManipulator::delete_data (old_data);
258 std::cout <<
"-------- Put : MARK 8 ------------------" << std::endl;
264 std::cout <<
"-------- Put : waitingForConvenientDataId : " << waitingForConvenientDataId <<
"---" << std::endl;
265 std::cout <<
"-------- Put : waitingForAnyDataId : " << waitingForAnyDataId <<
"---" << std::endl;
266 std::cout <<
"-------- Put : currentDataId : " << currentDataId <<
"---" << std::endl;
267 std::cout <<
"-------- Put : expectedDataId : " << expectedDataId <<
"---" << std::endl;
268 std::cout <<
"-------- Put : MARK 9 ------------------" << std::endl;
279 bool dummy1,dummy2;
typename DataTable::iterator dummy3;
284 if ( waitingForAnyDataId ||
285 ( waitingForConvenientDataId &&
286 this->isDataIdConveniant(storedDatas, expectedDataId, dummy1, dummy2, dummy3) )
289 std::cout <<
"-------- Put : MARK 10 ------------------" << std::endl;
292 expectedDataReceived =
true;
296 if (expectedDataReceived) {
298 std::cout <<
"-------- Put : MARK 11 ------------------" << std::endl;
302 if (waitingForAnyDataId)
303 waitingForAnyDataId =
false;
305 waitingForConvenientDataId =
false;
316 std::cerr <<
"-------- Put : new datas available ------------------" << std::endl;
318 fflush(stdout);fflush(stderr);
319 cond_instance.signal();
322 std::cout <<
"-------- Put : MARK 12 ------------------" << std::endl;
326 storedDatas_mutex.unlock();
329 std::cout <<
"-------- Put : MARK 13 ------------------" << std::endl;
337 storedDatas_mutex.unlock();
344 template <
typename DataManipulator,
typename COUPLING_POLICY >
345 template <
typename TimeType,
typename TagType>
349 typename COUPLING_POLICY::template EraseDataIdBeforeOrAfterTagProcessor<DataManipulator> processEraseDataId(*
this);
350 processEraseDataId.apply(storedDatas,time,tag,before);
360 template <
typename DataManipulator,
typename COUPLING_POLICY >
361 template <
typename TimeType,
typename TagType>
362 typename DataManipulator::Type
373 bool isEqual, isBounded;
374 typedef typename DataManipulator::InnerType InnerType;
377 std::cout <<
"-------- Get : MARK 1 ------------------" << std::endl;
379 expectedDataId =
DataId(time,tag);
381 std::cout <<
"-------- Get : MARK 2 ------------------" << std::endl;
384 typename DataTable::iterator wDataIt1;
387 storedDatas_mutex.lock();
397 this->isDataIdConveniant(storedDatas,expectedDataId,isEqual,isBounded,wDataIt1);
399 std::cout <<
"-------- Get : MARK 3 ------------------" << std::endl;
406 std::cout <<
"-------- Get : MARK 4 ------------------" << std::endl;
412 dataToTransmit = (*wDataIt1).second;
415 std::cout <<
"-------- Get : MARK 5 ------------------" << std::endl;
416 std::cout <<
"-------- Get : Données trouvées à t : " << std::endl;
417 typename DataManipulator::InnerType
const *
const InIt1 = DataManipulator::getPointer(dataToTransmit);
418 size_t N = DataManipulator::size(dataToTransmit);
419 std::copy(InIt1, InIt1 + N,
420 std::ostream_iterator< InnerType > (std::cout,
" "));
421 std::cout << std::endl;
427 typename COUPLING_POLICY::template EraseDataIdProcessor<DataManipulator> processEraseDataId(*
this);
428 processEraseDataId.apply(storedDatas,wDataIt1);
430 std::cout <<
"-------- Get : MARK 6 ------------------" << std::endl;
436 std::cout <<
"-------- Get : MARK 7 ------------------" << std::endl;
450 std::cout <<
"-------- Get : MARK 8 ------------------" << std::endl;
453 typedef typename COUPLING_POLICY::template BoundedDataIdProcessor<DataManipulator> BDI;
454 BDI processBoundedDataId(*
this);
459 processBoundedDataId.apply(dataToTransmit,expectedDataId,wDataIt1);
465 storedDatas[expectedDataId]=dataToTransmit;
468 std::cout <<
"-------- Get : Données calculées à t : " << std::endl;
469 typename DataManipulator::InnerType
const *
const InIt1 = DataManipulator::getPointer(dataToTransmit);
470 size_t N = DataManipulator::size(dataToTransmit);
472 std::copy(InIt1, InIt1 + N,
473 std::ostream_iterator< InnerType > (std::cout,
" "));
474 std::cout << std::endl;
475 std::cout <<
"-------- Get : MARK 9 ------------------" << std::endl;
478 typename COUPLING_POLICY::template EraseDataIdProcessor<DataManipulator> processEraseDataId(*
this);
479 processEraseDataId.apply(storedDatas,wDataIt1);
486 typename COUPLING_POLICY::template DisconnectProcessor<DataManipulator> processDisconnect(*
this);
487 if ( processDisconnect.apply(storedDatas, expectedDataId, wDataIt1) )
continue;
492 std::cout <<
"-------- Get : MARK 10 ------------------" << std::endl;
495 waitingForConvenientDataId =
true;
497 std::cout <<
"-------- Get : MARK 11 ------------------" << std::endl;
500 std::cout <<
"-------- Get : waiting datas ------------------" << std::endl;
502 fflush(stdout);fflush(stderr);
505 cond_instance.wait();
509 omni_thread::get_time(&ts,&tns, rs,0);
510 int success=cond_instance.timedwait(ts,tns);
514 std::stringstream msg;
515 msg<<
"Timeout ("<<rs<<
" s) exceeded";
523 std::cout <<
"-------- Get : MARK 12 ------------------" << std::endl;
528 waitingForConvenientDataId =
true;
529 storedDatas_mutex.unlock();
534 storedDatas_mutex.unlock();
536 std::cout <<
"-------- Get : MARK 13 ------------------" << std::endl;
543 return dataToTransmit;
547 template <
typename DataManipulator,
typename COUPLING_POLICY >
548 template <
typename TimeType,
typename TagType>
549 typename DataManipulator::Type
553 ti = COUPLING_POLICY::getEffectiveTime(ti,tf);
560 template <
typename DataManipulator,
typename COUPLING_POLICY >
561 template <
typename TimeType,
typename TagType>
562 typename DataManipulator::Type
572 storedDatas_mutex.lock();
575 std::cout <<
"-------- Next : MARK 1 ---lastDataIdSet ("<<lastDataIdSet<<
")---------------" << std::endl;
578 typename DataTable::iterator wDataIt1;
579 wDataIt1 = storedDatas.end();
591 wDataIt1 = storedDatas.upper_bound(lastDataId);
592 else if ( !storedDatas.empty() ) {
593 lastDataIdSet =
true;
594 wDataIt1 = storedDatas.begin();
597 typename COUPLING_POLICY::template DisconnectProcessor<DataManipulator> processDisconnect(*
this);
599 while ( storedDatas.empty() || wDataIt1 == storedDatas.end() ) {
603 if ( processDisconnect.apply(storedDatas, lastDataId, wDataIt1) ) {
604 waitingForAnyDataId =
false;
break;
608 std::cout <<
"-------- Next : MARK 2 ------------------" << std::endl;
611 waitingForAnyDataId =
true;
613 std::cout <<
"-------- Next : MARK 3 ------------------" << std::endl;
615 std::cout <<
"-------- Next : waiting datas ------------------" << std::endl;
617 fflush(stdout);fflush(stderr);
620 cond_instance.wait();
624 omni_thread::get_time(&ts,&tns, rs,0);
625 int success=cond_instance.timedwait(ts,tns);
629 std::stringstream msg;
630 msg<<
"Timeout ("<<rs<<
" s) exceeded";
638 std::cout <<
"-------- Next : MARK 4 ------------------" << std::endl;
640 wDataIt1 = storedDatas.upper_bound(lastDataId);
643 std::cout <<
"-------- Next : MARK 5 ------------------" << std::endl;
645 lastDataIdSet =
true;
646 wDataIt1 = storedDatas.begin();
651 std::cout <<
"-------- Next : MARK 6 ------------------" << std::endl;
654 t = this->getTime( (*wDataIt1).first );
655 tag = this->getTag ( (*wDataIt1).first );
656 dataToTransmit = (*wDataIt1).second;
659 std::cout <<
"-------- Next : MARK 7 ------------------" << std::endl;
661 lastDataId = (*wDataIt1).first;
663 typename COUPLING_POLICY::template EraseDataIdProcessor<DataManipulator> processEraseDataId(*
this);
664 processEraseDataId.apply(storedDatas, wDataIt1);
667 std::cout <<
"-------- Next : MARK 8 ------------------" << std::endl;
671 std::cout <<
"-------- Next : MARK 8bis ------------------" << std::endl;
673 waitingForAnyDataId =
false;
674 storedDatas_mutex.unlock();
677 storedDatas_mutex.unlock();
680 std::cout <<
"-------- Next : MARK 9 ------------------" << std::endl;
687 return dataToTransmit;