"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "brutus-server/advise_utils.h" of archive brutus-server-1.0.0.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 /*
    2  *    Brutus header file for call-back notification class.
    3  *    Copyright (C) 2004, 2005 OMC Denmark ApS.
    4  *
    5  *    This program is free software; you can redistribute it and/or modify
    6  *    it under the terms of the GNU General Public License as published by
    7  *    the Free Software Foundation; either version 2 of the License, or
    8  *    (at your option) any later version.
    9  *
   10  *    This program is distributed in the hope that it will be useful,
   11  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  *    GNU General Public License for more details.
   14  *
   15  *    You should have received a copy of the GNU General Public License
   16  *    along with this program; if not, write to the Free Software
   17  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
   18  */
   19 
   20 #ifndef _ADVISE_UTIL_H_
   21 #define _ADVISE_UTIL_H_
   22 
   23 #include <vector>
   24 #include <ace/Synch.h>
   25 #include <brutus-idl/IMAPIAdviseSinkC.h>
   26 #include <brutus-server/macros.h>
   27 
   28 #include <brutus-server/guid.h>
   29 
   30 #include <tao/PortableServer/PortableServer.h>
   31 
   32 #define MAPIGUID_H // do not include mapiguid.h
   33 #include <mapix.h>
   34 
   35 
   36 class CMAPIAdviseSink : public virtual IMAPIAdviseSink {
   37 public:
   38 	CMAPIAdviseSink(BRUTUS::IMAPIAdviseSink_ptr BrutusSink,
   39 			LPMAPISESSION MAPISession,
   40 			PortableServer::POA_ptr Poa)
   41 		: ref_count_(1),
   42 		  connection_(0),
   43 		  mapi_session_(MAPISession),
   44 		  poa_(PortableServer::POA::_duplicate(Poa)),
   45 		  brutus_sink_(BRUTUS::IMAPIAdviseSink::_duplicate(BrutusSink))
   46 		{
   47 			mapi_session_->AddRef();
   48 		};
   49 
   50 	STDMETHODIMP QueryInterface(REFIID  riid,
   51 				    LPVOID *ppvObj)
   52 		{
   53 			HRESULT hr = E_NOINTERFACE;
   54 			*ppvObj = 0;
   55 
   56 			if ((IID_IUnknown == riid) || (IID_IMAPIAdviseSink == riid)) {
   57 				*ppvObj = (LPVOID)this;
   58 				AddRef();
   59 				hr = S_OK;
   60 			}
   61 
   62 			return hr;
   63 		};
   64 
   65 
   66 	STDMETHODIMP_(ULONG) AddRef()
   67 		{
   68 			return InterlockedIncrement(&ref_count_);
   69 		};
   70 
   71 
   72 	STDMETHODIMP_(ULONG) Release()
   73 		{
   74 			ULONG count = InterlockedDecrement(&ref_count_);
   75 			if (!count)
   76 				delete this;
   77 
   78 			return count;
   79 		};
   80 
   81 	STDMETHODIMP_(ULONG) OnNotify(ULONG cNotify,
   82 				      LPNOTIFICATION lpNotifications);
   83 private:
   84 	~CMAPIAdviseSink()
   85 		{
   86 			try {
   87 				mapi_session_->Release();
   88 			}
   89 			catch (...) {
   90 				BRUTUS_LOG_ERR("Exception caught");
   91 			}
   92 		};
   93 
   94 	LONG ref_count_;
   95 	LONG connection_;
   96 	LPMAPISESSION mapi_session_;
   97 	PortableServer::POA_var poa_;
   98 	BRUTUS::IMAPIAdviseSink_var brutus_sink_;
   99 };
  100 
  101 
  102 class Sinks {
  103 public:
  104 	Sinks()
  105 		{
  106 			advise_sinks_.resize(0);
  107 		};
  108 
  109 	~Sinks()
  110 		{
  111 			ACE_Write_Guard<ACE_RW_Mutex> guard(mutex_);
  112 			advise_sinks_.resize(0);
  113 		};
  114 
  115 	void AddSink(const unsigned long SinkID)
  116 		{
  117 			ACE_Write_Guard<ACE_RW_Mutex> guard(mutex_);
  118 			advise_sinks_.push_back(SinkID);
  119 		};
  120 
  121 	void RemoveSink(const unsigned long SinkID)
  122 		{
  123 			ACE_Write_Guard<ACE_RW_Mutex> guard(mutex_);
  124 			for (unsigned long n = 0; n < advise_sinks_.size(); n++)
  125 				if (advise_sinks_[n] == SinkID) {
  126 					advise_sinks_.erase(advise_sinks_.begin() + n);
  127 					break;
  128 				}
  129 		};
  130 
  131 	void Clear()
  132 		{
  133 			ACE_Write_Guard<ACE_RW_Mutex> guard(mutex_);
  134 			advise_sinks_.resize(0);
  135 		}
  136 
  137 	unsigned long length() const
  138 		{
  139 			return (unsigned long)advise_sinks_.size();
  140 		};
  141 
  142 	unsigned long operator[](const unsigned long Index) const
  143 		{
  144 			return advise_sinks_[Index];
  145 		};
  146 
  147 private:
  148 	ACE_RW_Mutex mutex_;
  149 	std::vector<unsigned long> advise_sinks_;
  150 };
  151 
  152 #endif // _ADVISE_UTIL_H_
  153 
  154 /*
  155  * Local variables:
  156  * mode: C++
  157  * c-basic-offset: 8
  158  * tab-width: 8
  159  * indent-tabs-mode: nil
  160  * End:
  161  */