/* * Brutus header file for call-back notification class. * Copyright (C) 2004, 2005 OMC Denmark ApS. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _ADVISE_UTIL_H_ #define _ADVISE_UTIL_H_ #include #include #include #include #include #include #define MAPIGUID_H // do not include mapiguid.h #include class CMAPIAdviseSink : public virtual IMAPIAdviseSink { public: CMAPIAdviseSink(BRUTUS::IMAPIAdviseSink_ptr BrutusSink, LPMAPISESSION MAPISession, PortableServer::POA_ptr Poa) : ref_count_(1), connection_(0), mapi_session_(MAPISession), poa_(PortableServer::POA::_duplicate(Poa)), brutus_sink_(BRUTUS::IMAPIAdviseSink::_duplicate(BrutusSink)) { mapi_session_->AddRef(); }; STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObj) { HRESULT hr = E_NOINTERFACE; *ppvObj = 0; if ((IID_IUnknown == riid) || (IID_IMAPIAdviseSink == riid)) { *ppvObj = (LPVOID)this; AddRef(); hr = S_OK; } return hr; }; STDMETHODIMP_(ULONG) AddRef() { return InterlockedIncrement(&ref_count_); }; STDMETHODIMP_(ULONG) Release() { ULONG count = InterlockedDecrement(&ref_count_); if (!count) delete this; return count; }; STDMETHODIMP_(ULONG) OnNotify(ULONG cNotify, LPNOTIFICATION lpNotifications); private: ~CMAPIAdviseSink() { try { mapi_session_->Release(); } catch (...) { BRUTUS_LOG_ERR("Exception caught"); } }; LONG ref_count_; LONG connection_; LPMAPISESSION mapi_session_; PortableServer::POA_var poa_; BRUTUS::IMAPIAdviseSink_var brutus_sink_; }; class Sinks { public: Sinks() { advise_sinks_.resize(0); }; ~Sinks() { ACE_Write_Guard guard(mutex_); advise_sinks_.resize(0); }; void AddSink(const unsigned long SinkID) { ACE_Write_Guard guard(mutex_); advise_sinks_.push_back(SinkID); }; void RemoveSink(const unsigned long SinkID) { ACE_Write_Guard guard(mutex_); for (unsigned long n = 0; n < advise_sinks_.size(); n++) if (advise_sinks_[n] == SinkID) { advise_sinks_.erase(advise_sinks_.begin() + n); break; } }; void Clear() { ACE_Write_Guard guard(mutex_); advise_sinks_.resize(0); } unsigned long length() const { return (unsigned long)advise_sinks_.size(); }; unsigned long operator[](const unsigned long Index) const { return advise_sinks_[Index]; }; private: ACE_RW_Mutex mutex_; std::vector advise_sinks_; }; #endif // _ADVISE_UTIL_H_ /* * Local variables: * mode: C++ * c-basic-offset: 8 * tab-width: 8 * indent-tabs-mode: nil * End: */