NCBI C++ ToolKit
active_obj.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: active_obj.cpp 33815 2007-05-04 17:18:18Z kazimird $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Michael Kholodov
27 *
28 * File Description: CActiveObject and IEventListener, object notification
29 * interface
30 *
31 * ---------------------------------------------------------------------------
32 */
33 
34 #include <ncbi_pch.hpp>
35 #include "active_obj.hpp"
36 #include <corelib/ncbistre.hpp>
37 #include <typeinfo>
38 
40 
42 {
43  SetIdent("ActiveObject");
44 }
45 
47 {
48 }
49 
51 {
52  CMutexGuard guard(m_listMutex);
53 
54  m_listenerList.push_back(obj);
55  _TRACE("Object " << obj->GetIdent() << " " << (void*)obj
56  << " inserted into "
57  << GetIdent() << " " << (void*)this << " listener list");
58 }
59 
61 {
62  CMutexGuard guard(m_listMutex);
63 
64  m_listenerList.remove(obj);
65  _TRACE("Object " << obj->GetIdent() << " " << (void*)obj
66  << " removed from "
67  << GetIdent() << " " << (void*)this << " listener list");
68 
69 }
70 
72 {
73  CMutexGuard guard(m_listMutex);
74 
75  TLList::iterator i = m_listenerList.begin();
76  for( ; i != m_listenerList.end(); ++i ) {
77  _TRACE("Object " << GetIdent() << " " << (void*)this
78  << " notifies " << (*i)->GetIdent() << " " << (void*)(*i));
79  (*i)->Action(e);
80  }
81 }
82 
84 {
85 
86 }
87 
89 {
90  return m_listenerList;
91 }
92 
94 {
95  return m_ident;
96 }
97 
98 void CActiveObject::SetIdent(const string& name)
99 {
100  m_ident = name;
101 }
102 
CMutex m_listMutex
Definition: active_obj.hpp:150
void RemoveListener(CActiveObject *obj)
Definition: active_obj.cpp:60
TLList & GetListenerList()
Definition: active_obj.cpp:88
void SetIdent(const string &name)
Definition: active_obj.cpp:98
virtual ~CActiveObject()
Definition: active_obj.cpp:46
virtual void Action(const CDbapiEvent &e)
Definition: active_obj.cpp:83
void AddListener(CActiveObject *obj)
Definition: active_obj.cpp:50
list< CActiveObject * > TLList
Definition: active_obj.hpp:140
string GetIdent() const
Definition: active_obj.cpp:93
void Notify(const CDbapiEvent &e)
Definition: active_obj.cpp:71
TLList m_listenerList
Definition: active_obj.hpp:148
#define _TRACE(message)
Definition: ncbidbg.hpp:122
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
int i
NCBI C++ stream class wrappers for triggering between "new" and "old" C++ stream libraries.
Modified on Thu Feb 22 17:08:46 2024 by modify_doxy.py rev. 669887