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
131 virtual WossManager& eraseAllWoss() = 0;
132
142 virtual Pressure* getWossPressure( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, const Time& time_value ) = 0;
143
153 virtual Pressure* getWossPressure( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, double time_value = 0.0 );
154
163 virtual PressureVector getWossPressure( const CoordZPairVect& coordinates, double start_frequency, double end_frequency, const Time& time_value );
164
173 virtual PressureVector getWossPressure( const CoordZPairVect& coordinates, double start_frequency, double end_frequency, double time_value = 0.0 );
174
184 virtual TimeArr* getWossTimeArr( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, const Time& time_value ) = 0;
185
195 virtual TimeArr* getWossTimeArr( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, double time_value = 0.0 );
196
205 virtual TimeArrVector getWossTimeArr( const CoordZPairVect& coordinates, double start_frequency, double end_frequency, const Time& time_value );
206
215 virtual TimeArrVector getWossTimeArr( const CoordZPairVect& coordinates, double start_frequency, double end_frequency, double time_value = 0.0 );
216
217
222 virtual bool reset() = 0;
223
224
230 virtual bool timeEvolve( const Time& time_value ) = 0;
231
232
238 WossManager& setWossCreator( const WossCreator* const ptr ) { woss_creator = ptr; return *this; }
239
240 void setTimeEvolutionActiveFlag( bool flag ) { is_time_evolution_active = flag; }
241
242 void setDebugFlag( bool flag ) { debug = flag; }
243
244
245 const WossCreator* const getWossCreator() { return woss_creator; }
246
247 bool getTimeEvolutionActiveFlag() { return (bool)is_time_evolution_active; }
248
249 bool getDebugFlag() { return (bool)debug; }
250
251
252 protected:
253
254
255 static const Time NO_EVOLUTION_TIME;
256
257
262
263
267 bool debug;
268
269
270 bool is_time_evolution_active;
271
272
281 virtual Woss* const getWoss( const CoordZ& tx, const CoordZ& rx, double start_frequency, double end_frequency ) = 0;
282
283
284 };
285
286
294
295
296 public:
297
298
300
301 virtual ~WossManagerResDb() {}
302
303
313 virtual Pressure* getWossPressure( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, const Time& time_value );
314
324// virtual Pressure* getWossPressure( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, double time_value );
325
335 virtual TimeArr* getWossTimeArr( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, const Time& time_value );
336
346// virtual TimeArr* getWossTimeArr( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, double time_value );
347
348
354 WossManagerResDb& setWossDbManager( const WossDbManager* const ptr ) { woss_db_manager = ptr; return *this; }
355
356
357 protected:
358
359
364
365
375 TimeArr* dbGetTimeArr( const CoordZ& tx, const CoordZ& rx, double frequency, const Time& time_value ) const;
376
385 void dbInsertTimeArr( const CoordZ& tx, const CoordZ& rx, double frequency, const Time& time_value, const TimeArr& channel ) const;
386
387
397 Pressure* dbGetPressure( const CoordZ& tx, const CoordZ& rx, double frequency, const Time& time_value ) const;
398
407 void dbInsertPressure( const CoordZ& tx, const CoordZ& rx, double frequency, const Time& time_value, const Pressure& press ) const;
408
409
410 };
411
412
413 //inline functions
415 inline void WossManagerResDb::dbInsertTimeArr( const CoordZ& tx, const CoordZ& rx, double frequency, const Time& time_value, const TimeArr& channel ) const {
416 if ( woss_db_manager ) woss_db_manager->insertTimeArr( tx, rx, frequency, time_value, channel ) ;
417 }
418
419
420 inline TimeArr* WossManagerResDb::dbGetTimeArr( const CoordZ& tx, const CoordZ& rx, double frequency, const Time& time_value ) const {
421 if ( woss_db_manager ) return( woss_db_manager->getTimeArr( tx, rx, frequency, time_value ) );
422 return( SDefHandler::instance()->getTimeArr()->create( TimeArr::createNotValid() ) );
423 }
424
425
426 inline void WossManagerResDb::dbInsertPressure( const CoordZ& tx, const CoordZ& rx, double frequency, const Time& time_value, const Pressure& press ) const {
427 if ( woss_db_manager ) woss_db_manager->insertPressure( tx, rx, frequency, time_value, press );
428 }
429
430
431 inline Pressure* WossManagerResDb::dbGetPressure( const CoordZ& tx, const CoordZ& rx, double frequency, const Time& time_value ) const {
432 if ( woss_db_manager ) return( woss_db_manager->getPressure( tx, rx, frequency, time_value ) );
433 return( SDefHandler::instance()->getPressure()->create( Pressure::createNotValid() ) );
434 }
435
436
437 #ifdef WOSS_MULTITHREAD
438
439
440 #include <set>
441
442
446 #define MAX_TOTAL_PTHREAD 32
447
448
459
460
461 public:
462
463
468
469 virtual ~WossManagerResDbMT();
470
471
481 virtual Pressure* getWossPressure( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, const Time& time_value );
482
492 virtual Pressure* getWossPressure( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, double time_value );
493
494
504 virtual TimeArr* getWossTimeArr( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, const Time& time_value );
505
515 virtual TimeArr* getWossTimeArr( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency, double time_value );
516
517
526 virtual PressureVector getWossPressure( const CoordZPairVect& coordinates, double start_frequency, double end_frequency, const Time& time_value );
527
536 virtual PressureVector getWossPressure( const CoordZPairVect& coordinates, double start_frequency, double end_frequency, double time_value );
537
546 virtual TimeArrVector getWossTimeArr( const CoordZPairVect& coordinates, double start_frequency, double end_frequency, const Time& time_value );
547
556 virtual TimeArrVector getWossTimeArr( const CoordZPairVect& coordinates, double start_frequency, double end_frequency, double time_value );
557
564
570
571
572 friend void* WMSMTcreateThreadTimeArr( void* ptr );
573
574 friend void* WMSMTcreateThreadPressure( void* ptr );
575
576
577 protected:
578
579
583 //typedef ::std::pair< CoordZPairVect, SimFreq > ThreadQuery;
584 struct ThreadQuery {
585
586
587 CoordZPairVect coordz_pair_vect;
588
589 SimFreq sim_freq;
590
591 int curr_index;
592
593 struct {
594 bool is_time_object;
595
596 Time time_cal;
597
598 double time_double;
599
600 } time_data;
601
602 };
603
604
608// typedef ::std::pair< CoordZPair, SimFreq > ThreadParam;
609 struct ThreadParam {
610
611
612 CoordZPair coordz_pair;
613
614 SimFreq sim_freq;
615
616 struct {
617 bool is_time_object;
618
619 Time time_cal;
620
621 double time_double;
622
623 } time_data;
624
625
626 };
627
628
632 typedef ::std::pair< int, ThreadParam > ThreadParamIndex;
633
634
636
637
638 ThreadCondSignal() { pthread_mutex_init( &mutex, NULL ); pthread_cond_init( &condition, NULL ); }
639
640 ~ThreadCondSignal() { pthread_mutex_destroy( &mutex ); pthread_cond_destroy( &condition ); }
641
642
643 pthread_mutex_t mutex;
644
645 pthread_cond_t condition;
646
647
648 };
649
650
651 typedef ::std::map< Woss*, ThreadCondSignal* > ActiveWoss;
652 typedef ActiveWoss::iterator AWIter;
653 typedef ActiveWoss::reverse_iterator AWRIter;
654 typedef ActiveWoss::const_iterator AWCIter;
655 typedef ActiveWoss::const_reverse_iterator AWCRIter;
656
657
662
667
672
673
678
682 volatile int total_thread_ended;
683
684
689
693 pthread_t thread_arr[MAX_TOTAL_PTHREAD];
694
695
699 pthread_spinlock_t mutex;
700
704 pthread_spinlock_t request_mutex;
705
706
711
712
717
722
726 ActiveWoss active_woss;
727
732
736 void initThreadVars();
737
738
744
745
751 void insertThreadReplyTimeArr( int index, woss::TimeArr* time_arr );
752
758 void insertThreadReplyPressure( int index, woss::Pressure* pressure );
759
760
761 };
762
763
769 void* WMSMTcreateThreadTimeArr( void* ptr );
770
776 void* WMSMTcreateThreadPressure( void* ptr );
777
778
779#endif // WOSS_MULTITHREAD
780
781
782}
783
784
785#endif /* WOSS_MANAGER_DEFINITIONS_H */
786
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:334
virtual Pressure * getPressure(const CoordZ &coord_tx, const CoordZ &coord_rx, const double frequency, const Time &time_value) const
Definition woss-db-manager.cpp:339
virtual TimeArr * getTimeArr(const CoordZ &coord_tx, const CoordZ &coord_rx, const double frequency, const Time &time_value) const
Definition woss-db-manager.cpp:328
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:345
Multi-threaded extension of WossManagerResDb.
Definition woss-manager.h:458
int max_thread_number
Definition woss-manager.h:661
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:682
ThreadQuery thread_query
Definition woss-manager.h:710
PressureVector thread_pressure_reply
Definition woss-manager.h:721
int concurrent_threads
Definition woss-manager.h:671
::std::pair< int, ThreadParam > ThreadParamIndex
Definition woss-manager.h:632
ActiveWoss active_woss
Definition woss-manager.h:726
WossManagerResDbMT()
Definition woss-manager.cpp:417
TimeArrVector thread_time_arr_reply
Definition woss-manager.h:716
void setConcurrentThreads(int number)
Definition woss-manager.h:563
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:704
volatile int total_thread_created
Definition woss-manager.h:677
pthread_t thread_arr[MAX_TOTAL_PTHREAD]
Definition woss-manager.h:693
ThreadParamIndex popThreadParamIndex()
Definition woss-manager.cpp:459
pthread_t thread_controller
Definition woss-manager.h:688
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:666
int getConcurrentThreads()
Definition woss-manager.h:569
void initThreadVars()
Definition woss-manager.cpp:677
pthread_spinlock_t mutex
Definition woss-manager.h:699
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:293
void dbInsertTimeArr(const CoordZ &tx, const CoordZ &rx, double frequency, const Time &time_value, const TimeArr &channel) const
Definition woss-manager.h:415
const WossDbManager * woss_db_manager
Definition woss-manager.h:363
void dbInsertPressure(const CoordZ &tx, const CoordZ &rx, double frequency, const Time &time_value, const Pressure &press) const
Definition woss-manager.h:426
Pressure * dbGetPressure(const CoordZ &tx, const CoordZ &rx, double frequency, const Time &time_value) const
Definition woss-manager.h:431
TimeArr * dbGetTimeArr(const CoordZ &tx, const CoordZ &rx, double frequency, const Time &time_value) const
Definition woss-manager.h:420
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:354
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:267
const WossCreator * woss_creator
Definition woss-manager.h:261
WossManager & setWossCreator(const WossCreator *const ptr)
Definition woss-manager.h:238
virtual WossManager & eraseAllWoss()=0
Abstract class that provides the interface for initializing and running a channel simulator.
Definition woss.h:94
Provides the interface for woss::DefHandler class.
Definition woss-manager.h:635
Definition woss-manager.h:609
Definition woss-manager.h:584
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