World Ocean Simulation System (WOSS) library
woss-manager.h
Go to the documentation of this file.
1/* WOSS - World Ocean Simulation System -
2 *
3 * Copyright (C) 2009 Federico Guerra
4 * and regents of the SIGNET lab, University of Padova
5 *
6 * Author: Federico Guerra - federico@guerra-tlc.com
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation;
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22/*
23 * This software has been developed by Federico Guerra and SIGNET lab,
24 * University of Padova, in collaboration with the NATO Centre for
25 * Maritime Research and Experimentation (http://www.cmre.nato.int ;
26 * E-mail: pao@cmre.nato.int), whose support is gratefully acknowledged.
27 */
28
29
40#ifndef WOSS_MANAGER_DEFINITIONS_H
41#define WOSS_MANAGER_DEFINITIONS_H
42
43
44#include <definitions-handler.h>
46#include "woss-creator.h"
47#include <woss-db-manager.h>
48
49
50namespace woss {
51
52
56 typedef ::std::pair< CoordZ, CoordZ > CoordZPair;
57
61 typedef ::std::vector< CoordZPair > CoordZPairVect;
62
63
67 typedef ::std::pair< double, double > SimFreq;
68
72 typedef ::std::vector< SimFreq > SimFreqVector;
73
74
78 typedef ::std::vector< Pressure* > PressureVector;
79
83 typedef ::std::vector< TimeArr* > TimeArrVector;
84
85
94
95
96 public:
97
98
102 WossManager();
103
104 virtual ~WossManager();
105
106
115 virtual const Woss& getActiveWoss( const CoordZ& tx, const CoordZ& rx, double start_frequency, double end_frequency ) const;
116
125 virtual WossManager& eraseActiveWoss( const CoordZ& tx, const CoordZ& rx, double start_frequency, double end_frequency ) = 0;
126
136 virtual Pressure* getWossPressure( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, const Time& time_value ) = 0;
137
147 virtual Pressure* getWossPressure( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, double time_value = 0.0 );
148
157 virtual PressureVector getWossPressure( const CoordZPairVect& coordinates, double start_frequency, double end_frequency, const Time& time_value );
158
167 virtual PressureVector getWossPressure( const CoordZPairVect& coordinates, double start_frequency, double end_frequency, double time_value = 0.0 );
168
178 virtual TimeArr* getWossTimeArr( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, const Time& time_value ) = 0;
179
189 virtual TimeArr* getWossTimeArr( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, double time_value = 0.0 );
190
199 virtual TimeArrVector getWossTimeArr( const CoordZPairVect& coordinates, double start_frequency, double end_frequency, const Time& time_value );
200
209 virtual TimeArrVector getWossTimeArr( const CoordZPairVect& coordinates, double start_frequency, double end_frequency, double time_value = 0.0 );
210
211
216 virtual bool reset() = 0;
217
218
224 virtual bool timeEvolve( const Time& time_value ) = 0;
225
226
232 WossManager& setWossCreator( const WossCreator* const ptr ) { woss_creator = ptr; return *this; }
233
234 void setTimeEvolutionActiveFlag( bool flag ) { is_time_evolution_active = flag; }
235
236 void setDebugFlag( bool flag ) { debug = flag; }
237
238
239 const WossCreator* const getWossCreator() { return woss_creator; }
240
241 bool getTimeEvolutionActiveFlag() { return (bool)is_time_evolution_active; }
242
243 bool getDebugFlag() { return (bool)debug; }
244
245
246 protected:
247
248
249 static const Time NO_EVOLUTION_TIME;
250
251
256
257
261 bool debug;
262
263
264 bool is_time_evolution_active;
265
266
275 virtual Woss* const getWoss( const CoordZ& tx, const CoordZ& rx, double start_frequency, double end_frequency ) = 0;
276
277
278 };
279
280
288
289
290 public:
291
292
294
295 virtual ~WossManagerResDb() {}
296
297
307 virtual Pressure* getWossPressure( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, const Time& time_value );
308
318// virtual Pressure* getWossPressure( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, double time_value );
319
329 virtual TimeArr* getWossTimeArr( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, const Time& time_value );
330
340// virtual TimeArr* getWossTimeArr( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, double time_value );
341
342
348 WossManagerResDb& setWossDbManager( const WossDbManager* const ptr ) { woss_db_manager = ptr; return *this; }
349
350
351 protected:
352
353
358
359
369 TimeArr* dbGetTimeArr( const CoordZ& tx, const CoordZ& rx, double frequency, const Time& time_value ) const;
370
379 void dbInsertTimeArr( const CoordZ& tx, const CoordZ& rx, double frequency, const Time& time_value, const TimeArr& channel ) const;
380
381
391 Pressure* dbGetPressure( const CoordZ& tx, const CoordZ& rx, double frequency, const Time& time_value ) const;
392
401 void dbInsertPressure( const CoordZ& tx, const CoordZ& rx, double frequency, const Time& time_value, const Pressure& press ) const;
402
403
404 };
405
406
407 //inline functions
409 inline void WossManagerResDb::dbInsertTimeArr( const CoordZ& tx, const CoordZ& rx, double frequency, const Time& time_value, const TimeArr& channel ) const {
410 if ( woss_db_manager ) woss_db_manager->insertTimeArr( tx, rx, frequency, time_value, channel ) ;
411 }
412
413
414 inline TimeArr* WossManagerResDb::dbGetTimeArr( const CoordZ& tx, const CoordZ& rx, double frequency, const Time& time_value ) const {
415 if ( woss_db_manager ) return( woss_db_manager->getTimeArr( tx, rx, frequency, time_value ) );
416 return( SDefHandler::instance()->getTimeArr()->create( TimeArr::createNotValid() ) );
417 }
418
419
420 inline void WossManagerResDb::dbInsertPressure( const CoordZ& tx, const CoordZ& rx, double frequency, const Time& time_value, const Pressure& press ) const {
421 if ( woss_db_manager ) woss_db_manager->insertPressure( tx, rx, frequency, time_value, press );
422 }
423
424
425 inline Pressure* WossManagerResDb::dbGetPressure( const CoordZ& tx, const CoordZ& rx, double frequency, const Time& time_value ) const {
426 if ( woss_db_manager ) return( woss_db_manager->getPressure( tx, rx, frequency, time_value ) );
427 return( SDefHandler::instance()->getPressure()->create( Pressure::createNotValid() ) );
428 }
429
430
431 #ifdef WOSS_MULTITHREAD
432
433
434 #include <set>
435
436
440 #define MAX_TOTAL_PTHREAD 32
441
442
453
454
455 public:
456
457
462
463 virtual ~WossManagerResDbMT();
464
465
475 virtual Pressure* getWossPressure( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, const Time& time_value );
476
486 virtual Pressure* getWossPressure( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, double time_value );
487
488
498 virtual TimeArr* getWossTimeArr( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, const Time& time_value );
499
509 virtual TimeArr* getWossTimeArr( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, double time_value );
510
511
520 virtual PressureVector getWossPressure( const CoordZPairVect& coordinates, double start_frequency, double end_frequency, const Time& time_value );
521
530 virtual PressureVector getWossPressure( const CoordZPairVect& coordinates, double start_frequency, double end_frequency, double time_value );
531
540 virtual TimeArrVector getWossTimeArr( const CoordZPairVect& coordinates, double start_frequency, double end_frequency, const Time& time_value );
541
550 virtual TimeArrVector getWossTimeArr( const CoordZPairVect& coordinates, double start_frequency, double end_frequency, double time_value );
551
558
564
565
566 friend void* WMSMTcreateThreadTimeArr( void* ptr );
567
568 friend void* WMSMTcreateThreadPressure( void* ptr );
569
570
571 protected:
572
573
577 //typedef ::std::pair< CoordZPairVect, SimFreq > ThreadQuery;
578 struct ThreadQuery {
579
580
581 CoordZPairVect coordz_pair_vect;
582
583 SimFreq sim_freq;
584
585 int curr_index;
586
587 struct {
588 bool is_time_object;
589
590 Time time_cal;
591
592 double time_double;
593
594 } time_data;
595
596 };
597
598
602// typedef ::std::pair< CoordZPair, SimFreq > ThreadParam;
603 struct ThreadParam {
604
605
606 CoordZPair coordz_pair;
607
608 SimFreq sim_freq;
609
610 struct {
611 bool is_time_object;
612
613 Time time_cal;
614
615 double time_double;
616
617 } time_data;
618
619
620 };
621
622
626 typedef ::std::pair< int, ThreadParam > ThreadParamIndex;
627
628
630
631
632 ThreadCondSignal() { pthread_mutex_init( &mutex, NULL ); pthread_cond_init( &condition, NULL ); }
633
634 ~ThreadCondSignal() { pthread_mutex_destroy( &mutex ); pthread_cond_destroy( &condition ); }
635
636
637 pthread_mutex_t mutex;
638
639 pthread_cond_t condition;
640
641
642 };
643
644
645 typedef ::std::map< Woss*, ThreadCondSignal* > ActiveWoss;
646 typedef ActiveWoss::iterator AWIter;
647 typedef ActiveWoss::reverse_iterator AWRIter;
648 typedef ActiveWoss::const_iterator AWCIter;
649 typedef ActiveWoss::const_reverse_iterator AWCRIter;
650
651
656
661
666
667
672
676 volatile int total_thread_ended;
677
678
683
687 pthread_t thread_arr[MAX_TOTAL_PTHREAD];
688
689
693 pthread_spinlock_t mutex;
694
698 pthread_spinlock_t request_mutex;
699
700
705
706
711
716
720 ActiveWoss active_woss;
721
726
730 void initThreadVars();
731
732
738
739
745 void insertThreadReplyTimeArr( int index, woss::TimeArr* time_arr );
746
752 void insertThreadReplyPressure( int index, woss::Pressure* pressure );
753
754
755 };
756
757
763 void* WMSMTcreateThreadTimeArr( void* ptr );
764
770 void* WMSMTcreateThreadPressure( void* ptr );
771
772
773#endif // WOSS_MULTITHREAD
774
775
776}
777
778
779#endif /* WOSS_MANAGER_DEFINITIONS_H */
780
3D-Coordinates (lat, long, depth) class definitions and functions library
Definition coordinates-definitions.h:403
Complex attenuated pressure class.
Definition pressure-definitions.h:59
static const ::std::complex< double > createNotValid()
Definition pressure-definitions.h:148
static T * instance()
Definition singleton-definitions.h:99
Channel power delay profile class.
Definition time-arrival-definitions.h:82
static TimeArrMap & createNotValid()
Definition time-arrival-definitions.h:588
a class for time date manipulation
Definition time-definitions.h:95
Abstract class that provides correctly initialized Woss objects.
Definition woss-creator.h:65
Abstraction layer for database and data manipulation.
Definition woss-db-manager.h:84
virtual void insertTimeArr(const CoordZ &coord_tx, const CoordZ &coord_rx, const double frequency, const Time &time_value, const TimeArr &channel) const
Definition woss-db-manager.cpp:345
virtual Pressure * getPressure(const CoordZ &coord_tx, const CoordZ &coord_rx, const double frequency, const Time &time_value) const
Definition woss-db-manager.cpp:350
virtual TimeArr * getTimeArr(const CoordZ &coord_tx, const CoordZ &coord_rx, const double frequency, const Time &time_value) const
Definition woss-db-manager.cpp:339
virtual void insertPressure(const CoordZ &coord_tx, const CoordZ &coord_rx, const double frequency, const Time &time_value, const Pressure &pressure) const
Definition woss-db-manager.cpp:356
Multi-threaded extension of WossManagerResDb.
Definition woss-manager.h:452
int max_thread_number
Definition woss-manager.h:655
virtual TimeArr * getWossTimeArr(const CoordZ &tx_coordz, const CoordZ &rx_coordz, double start_frequency, double end_frequency, const Time &time_value)
Definition woss-manager.cpp:784
friend void * WMSMTcreateThreadTimeArr(void *ptr)
volatile int total_thread_ended
Definition woss-manager.h:676
ThreadQuery thread_query
Definition woss-manager.h:704
PressureVector thread_pressure_reply
Definition woss-manager.h:715
int concurrent_threads
Definition woss-manager.h:665
::std::pair< int, ThreadParam > ThreadParamIndex
Definition woss-manager.h:626
ActiveWoss active_woss
Definition woss-manager.h:720
WossManagerResDbMT()
Definition woss-manager.cpp:417
TimeArrVector thread_time_arr_reply
Definition woss-manager.h:710
void setConcurrentThreads(int number)
Definition woss-manager.h:557
void insertThreadReplyTimeArr(int index, woss::TimeArr *time_arr)
Definition woss-manager.cpp:770
friend void * WMSMTcreateThreadPressure(void *ptr)
pthread_spinlock_t request_mutex
Definition woss-manager.h:698
volatile int total_thread_created
Definition woss-manager.h:671
pthread_t thread_arr[MAX_TOTAL_PTHREAD]
Definition woss-manager.h:687
ThreadParamIndex popThreadParamIndex()
Definition woss-manager.cpp:459
pthread_t thread_controller
Definition woss-manager.h:682
virtual Pressure * getWossPressure(const CoordZ &tx_coordz, const CoordZ &rx_coordz, double start_frequency, double end_frequency, const Time &time_value)
Definition woss-manager.cpp:941
void checkConcurrentThreads()
Definition woss-manager.cpp:448
int total_queries
Definition woss-manager.h:660
int getConcurrentThreads()
Definition woss-manager.h:563
void initThreadVars()
Definition woss-manager.cpp:677
pthread_spinlock_t mutex
Definition woss-manager.h:693
void insertThreadReplyPressure(int index, woss::Pressure *pressure)
Definition woss-manager.cpp:777
Abstract class that implements WossManager. It adds computed results dbs control.
Definition woss-manager.h:287
void dbInsertTimeArr(const CoordZ &tx, const CoordZ &rx, double frequency, const Time &time_value, const TimeArr &channel) const
Definition woss-manager.h:409
const WossDbManager * woss_db_manager
Definition woss-manager.h:357
void dbInsertPressure(const CoordZ &tx, const CoordZ &rx, double frequency, const Time &time_value, const Pressure &press) const
Definition woss-manager.h:420
Pressure * dbGetPressure(const CoordZ &tx, const CoordZ &rx, double frequency, const Time &time_value) const
Definition woss-manager.h:425
TimeArr * dbGetTimeArr(const CoordZ &tx, const CoordZ &rx, double frequency, const Time &time_value) const
Definition woss-manager.h:414
virtual TimeArr * getWossTimeArr(const CoordZ &tx_coordz, const CoordZ &rx_coordz, double start_frequency, double end_frequency, const Time &time_value)
Definition woss-manager.cpp:264
WossManagerResDb & setWossDbManager(const WossDbManager *const ptr)
Definition woss-manager.h:348
virtual Pressure * getWossPressure(const CoordZ &tx_coordz, const CoordZ &rx_coordz, double start_frequency, double end_frequency, const Time &time_value)
Definition woss-manager.cpp:337
Abstract class that interfaces Pressure or TimeArr requests from user layer.
Definition woss-manager.h:93
virtual WossManager & eraseActiveWoss(const CoordZ &tx, const CoordZ &rx, double start_frequency, double end_frequency)=0
WossManager()
Definition woss-manager.cpp:57
virtual Pressure * getWossPressure(const CoordZ &tx_coordz, const CoordZ &rx_coordz, double start_frequency, double end_frequency, const Time &time_value)=0
Definition woss-manager.cpp:122
virtual const Woss & getActiveWoss(const CoordZ &tx, const CoordZ &rx, double start_frequency, double end_frequency) const
Definition woss-manager.cpp:248
virtual bool timeEvolve(const Time &time_value)=0
virtual TimeArr * getWossTimeArr(const CoordZ &tx_coordz, const CoordZ &rx_coordz, double start_frequency, double end_frequency, const Time &time_value)=0
Definition woss-manager.cpp:70
virtual Woss *const getWoss(const CoordZ &tx, const CoordZ &rx, double start_frequency, double end_frequency)=0
virtual bool reset()=0
bool debug
Definition woss-manager.h:261
const WossCreator * woss_creator
Definition woss-manager.h:255
WossManager & setWossCreator(const WossCreator *const ptr)
Definition woss-manager.h:232
Abstract class that provides the interface for initializing and running a channel simulator.
Definition woss.h:89
Provides the interface for woss::DefHandler class.
Definition woss-manager.h:629
Definition woss-manager.h:603
Definition woss-manager.h:578
Definitions and library for woss::TimeArr class.
Provides the interface for woss::WossCreator class.
Provides the interface for woss::WossDbManager class.
::std::vector< CoordZPair > CoordZPairVect
Definition woss-manager.h:61
::std::vector< TimeArr * > TimeArrVector
Definition woss-manager.h:83
::std::pair< CoordZ, CoordZ > CoordZPair
Definition woss-manager.h:56
::std::pair< double, double > SimFreq
Definition woss-manager.h:67
::std::vector< SimFreq > SimFreqVector
Definition woss-manager.h:72
void * WMSMTcreateThreadTimeArr(void *ptr)
Definition woss-manager.cpp:690
::std::vector< Pressure * > PressureVector
Definition woss-manager.h:78
void * WMSMTcreateThreadPressure(void *ptr)
Definition woss-manager.cpp:732