/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/*
 *  Copyright (C) 2008 OMC Denmark ApS.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, either version 3 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 Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __IMSGSERVICEADMINS_IMPL_H_
#define __IMSGSERVICEADMINS_IMPL_H_

#include "IMsgServiceAdminS.h"
#include "utils/macros.h"

#define MAPIGUID_H // do not include mapiguid.h
#include <mapix.h>

#include "Brutus_Loader_Impl_Export.h"

class Brutus_Loader_Impl_Export BRUTUS_IMsgServiceAdmin_i : public virtual POA_BRUTUS::IMsgServiceAdmin,
							    public virtual ::PortableServer::RefCountServantBase
{
public:
	BRUTUS_IMsgServiceAdmin_i(LPSERVICEADMIN ServiceAdmin,
				  LPMAPISESSION MAPISession,
				  ::PortableServer::POA_ptr Poa);

	virtual ::BRUTUS::BRESULT GetLastError(::BRUTUS::BRESULT bResult,
					       ::BRUTUS::BDEFINE ulFlags,
					       ::BRUTUS::MAPIERROR_out lppMAPIError);

	virtual ::BRUTUS::BRESULT GetMsgServiceTable(::BRUTUS::BDEFINE ulFlags,
						     ::BRUTUS::IMAPITable_out lppTable);

	virtual ::BRUTUS::BRESULT CreateMsgService(const char * lpszService,
						   const char * lpszDisplayName,
						   ::BRUTUS::BDEFINE ulFlags);

	virtual ::BRUTUS::BRESULT DeleteMsgService(const char * lpUID);

	virtual ::BRUTUS::BRESULT CopyMsgService(const char * lpUID,
						 const char * lpszDisplayName,
						 const char * lpInterfaceToCopy,
						 const char * lpInterfaceDst,
						 const ::BRUTUS::ENTRYID & lpObjectDst,
						 ::BRUTUS::BDEFINE ulFlags);

	virtual ::BRUTUS::BRESULT RenameMsgService(const char * lpUID,
						   ::BRUTUS::BDEFINE ulFlags,
						   const char * lpszDisplayName);

	virtual ::BRUTUS::BRESULT ConfigureMsgService(const char * lpUID,
						      ::BRUTUS::BDEFINE ulFlags,
						      const ::BRUTUS::seq_SPropValue & lpProps);

	virtual ::BRUTUS::BRESULT OpenProfileSection(const char * lpUID,
						     const char * lpInterface,
						     ::BRUTUS::BDEFINE ulFlags,
						     ::BRUTUS::IProfSect_out lppProfSect);

	virtual ::BRUTUS::BRESULT MsgServiceTransportOrder(const ::BRUTUS::seq_MAPIUID & lpUIDList,
							   ::BRUTUS::BDEFINE ulFlags);

	virtual ::BRUTUS::BRESULT AdminProviders(const char * lpUID,
						 ::BRUTUS::BDEFINE ulFlags,
						 ::BRUTUS::IProviderAdmin_out lppProviderAdmin);

	virtual ::BRUTUS::BRESULT SetPrimaryIdentity(const char * lpUID,
						     ::BRUTUS::BDEFINE ulFlags);

	virtual ::BRUTUS::BRESULT GetProviderTable(::BRUTUS::BDEFINE ulFlags,
						   ::BRUTUS::IMAPITable_out lppTable);

	virtual ::BRUTUS::BRESULT QueryInterface(const char *iid,
						 ::BRUTUS::IUnknown_out ppvObject);

	virtual void Destroy(::CORBA::ULong InstanceID);

private:
	// Skeleton constructor
	BRUTUS_IMsgServiceAdmin_i (void)
	{ };

	// Destructor
	virtual ~BRUTUS_IMsgServiceAdmin_i(void)
	{
		try {
			service_admin_->Release();
			mapi_session_->Release();
		}
		catch (...) {
			BRUTUS_LOG_ERR("Exception caught");
		}
	};

	LPSERVICEADMIN service_admin_;
	LPMAPISESSION mapi_session_;
	::PortableServer::POA_var poa_;

	ACE_RW_Mutex mutex_;
};


#endif /* __IMSGSERVICEADMINS_IMPL_H_  */
