/* This is a template file generated by command */
/* orbit-idl-2 --skeleton-impl IMAPIAdviseSink.idl */
/* User must edit this file, inserting servant  */
/* specific code between markers. */

#include "IMAPIAdviseSink.h"

/*** App-specific servant structures ***/

#if !defined(_typedef_impl_POA_BRUTUS_IMAPIAdviseSink_)
#define _typedef_impl_POA_BRUTUS_IMAPIAdviseSink_ 1
typedef struct {
	POA_BRUTUS_IMAPIAdviseSink servant;
	PortableServer_POA poa;
	/* ------ add private attributes here ------ */
	volatile int *notice_;
	/* ------ ---------- end ------------ ------ */
} impl_POA_BRUTUS_IMAPIAdviseSink;
#endif


/*** Implementation stub prototypes ***/

#if !defined(_decl_impl_BRUTUS_IMAPIAdviseSink__destroy_)
#define _decl_impl_BRUTUS_IMAPIAdviseSink__destroy_ 1
static void impl_BRUTUS_IMAPIAdviseSink__destroy(impl_POA_BRUTUS_IMAPIAdviseSink * servant,
						 CORBA_Environment * ev);
#endif

#if !defined(_decl_impl_BRUTUS_IMAPIAdviseSink_OnNotify_)
#define _decl_impl_BRUTUS_IMAPIAdviseSink_OnNotify_ 1
static void impl_BRUTUS_IMAPIAdviseSink_OnNotify(impl_POA_BRUTUS_IMAPIAdviseSink * servant,
						 const BRUTUS_seq_NOTIFICATION * lpNotifications,
						 CORBA_Environment * ev);
#endif

#if !defined(_decl_impl_BRUTUS_IMAPIAdviseSink_InternalError_)
#define _decl_impl_BRUTUS_IMAPIAdviseSink_InternalError_ 1
static void impl_BRUTUS_IMAPIAdviseSink_InternalError(impl_POA_BRUTUS_IMAPIAdviseSink * servant,
						      const BRUTUS_BRESULT ErrorCode,
						      CORBA_Environment * ev);
#endif


/*** epv structures ***/

#if !defined(_impl_BRUTUS_IMAPIAdviseSink_base_epv_)
#define _impl_BRUTUS_IMAPIAdviseSink_base_epv_ 1
static PortableServer_ServantBase__epv impl_BRUTUS_IMAPIAdviseSink_base_epv = {
	NULL,			/* _private data */
	(gpointer) & impl_BRUTUS_IMAPIAdviseSink__destroy,	/* finalize routine */
	NULL,			/* default_POA routine */
};
#endif

#if !defined(_impl_BRUTUS_IMAPIAdviseSink_epv_)
#define _impl_BRUTUS_IMAPIAdviseSink_epv_ 1
static POA_BRUTUS_IMAPIAdviseSink__epv impl_BRUTUS_IMAPIAdviseSink_epv = {
	NULL,			/* _private */
	(gpointer) & impl_BRUTUS_IMAPIAdviseSink_OnNotify,
	(gpointer) & impl_BRUTUS_IMAPIAdviseSink_InternalError,
};
#endif


/*** vepv structures ***/

#if !defined(_impl_BRUTUS_IMAPIAdviseSink_vepv_)
#define _impl_BRUTUS_IMAPIAdviseSink_vepv_ 1
static POA_BRUTUS_IMAPIAdviseSink__vepv impl_BRUTUS_IMAPIAdviseSink_vepv = {
	&impl_BRUTUS_IMAPIAdviseSink_base_epv,
	&impl_BRUTUS_IMAPIAdviseSink_epv,
};
#endif


/*** Stub implementations ***/

#if !defined(_impl_BRUTUS_IMAPIAdviseSink__create_)
#define _impl_BRUTUS_IMAPIAdviseSink__create_ 1
static BRUTUS_IMAPIAdviseSink impl_BRUTUS_IMAPIAdviseSink__create(volatile int *Notice,
								  PortableServer_POA poa,
								  CORBA_Environment * ev)
{
	BRUTUS_IMAPIAdviseSink retval;
	impl_POA_BRUTUS_IMAPIAdviseSink *newservant;
	PortableServer_ObjectId *objid;

	newservant = g_new0(impl_POA_BRUTUS_IMAPIAdviseSink, 1);
	newservant->servant.vepv = &impl_BRUTUS_IMAPIAdviseSink_vepv;
	newservant->poa = (PortableServer_POA) CORBA_Object_duplicate((CORBA_Object) poa, ev);
	POA_BRUTUS_IMAPIAdviseSink__init((PortableServer_Servant)
					 newservant, ev);
	/* Before servant is going to be activated all
	 * private attributes must be initialized.  */

	/* ------ init private attributes here ------ */
	newservant->notice_ = Notice;
	/* ------ ---------- end ------------- ------ */

	objid = PortableServer_POA_activate_object(poa, newservant, ev);
	CORBA_free(objid);
	retval = PortableServer_POA_servant_to_reference(poa, newservant, ev);

	return retval;
}
#endif

#if !defined(_impl_BRUTUS_IMAPIAdviseSink__destroy_)
#define _impl_BRUTUS_IMAPIAdviseSink__destroy_ 1
static void impl_BRUTUS_IMAPIAdviseSink__destroy(impl_POA_BRUTUS_IMAPIAdviseSink * servant,
						 CORBA_Environment * ev)
{
	CORBA_Object_release((CORBA_Object) servant->poa, ev);

	/* No further remote method calls are delegated to 
	 * servant and you may free your private attributes. */
	/* ------ free private attributes here ------ */
	/* ------ ---------- end ------------- ------ */

	POA_BRUTUS_IMAPIAdviseSink__fini((PortableServer_Servant) servant, ev);

	g_free(servant);
}
#endif

static inline const char *bnot_to_str(BRUTUS_BDEFINE descr)
{
	if (BRUTUS_BRUTUS_fnevCriticalError == descr)
		return "BRUTUS_fnevCriticalError";

	if (BRUTUS_BRUTUS_fnevNewMail == descr)
		return "BRUTUS_fnevNewMail";

	if (BRUTUS_BRUTUS_fnevObjectCreated == descr)
		return "BRUTUS_fnevObjectCreated";

	if (BRUTUS_BRUTUS_fnevObjectDeleted == descr)
		return "BRUTUS_fnevObjectDeleted";

	if (BRUTUS_BRUTUS_fnevObjectModified == descr)
		return "BRUTUS_fnevObjectModified";

	if (BRUTUS_BRUTUS_fnevObjectMoved == descr)
		return "BRUTUS_fnevObjectMoved";

	if (BRUTUS_BRUTUS_fnevObjectCopied == descr)
		return "BRUTUS_fnevObjectCopied";

	if (BRUTUS_BRUTUS_fnevSearchComplete == descr)
		return "BRUTUS_fnevSearchComplete";

	if (BRUTUS_BRUTUS_fnevTableModified == descr)
		return "BRUTUS_fnevTableModified";

	if (BRUTUS_BRUTUS_fnevTableModified == descr)
		return "BRUTUS_fnevTableModified";

	if (BRUTUS_BRUTUS_fnevStatusObjectModified == descr)
		return "BRUTUS_fnevStatusObjectModified";

	if (BRUTUS_BRUTUS_fnevReservedForMapi == descr)
		return "BRUTUS_fnevReservedForMapi";

	if (BRUTUS_BRUTUS_fnevExtended == descr)
		return "BRUTUS_fnevExtended";

	return "UNKNONW";
}


#if !defined(_impl_BRUTUS_IMAPIAdviseSink_OnNotify_)
#define _impl_BRUTUS_IMAPIAdviseSink_OnNotify_ 1
static void impl_BRUTUS_IMAPIAdviseSink_OnNotify(impl_POA_BRUTUS_IMAPIAdviseSink * servant,
						 const BRUTUS_seq_NOTIFICATION * lpNotifications,
						 CORBA_Environment * ev)
{
	/* ------   insert method code here   ------ */
	g_print("\n\tNotifications recieved - count is %d\n", lpNotifications->_length);

	CORBA_unsigned_long n;
	for (n=0; n<lpNotifications->_length; n++) {
		g_print("\tNotification[%d] event type is %s\n", n, bnot_to_str(lpNotifications->_buffer[n].ulEventType));
		switch (lpNotifications->_buffer[n].info._d) {
		case BRUTUS_BRUTUS_fnevObjectCopied : 
		case BRUTUS_BRUTUS_fnevObjectCreated : 
		case BRUTUS_BRUTUS_fnevObjectDeleted :
		case BRUTUS_BRUTUS_fnevObjectModified :
		case BRUTUS_BRUTUS_fnevObjectMoved :
		case BRUTUS_BRUTUS_fnevSearchComplete :
			g_print("\t\tObject notification, affected object type is ");
			switch (lpNotifications->_buffer[n].info._u.obj.ulObjType) {
			case BRUTUS_BRUTUS_MAPI_STORE :
				g_print("BRUTUS_BRUTUS_MAPI_STORE");
				break;
			case BRUTUS_BRUTUS_MAPI_ADDRBOOK :
				g_print("BRUTUS_BRUTUS_MAPI_ADDRBOOK");
				break;
			case BRUTUS_BRUTUS_MAPI_FOLDER :
				g_print("BRUTUS_BRUTUS_MAPI_FOLDER");
				break;
			case BRUTUS_BRUTUS_MAPI_ABCONT :
				g_print("BRUTUS_BRUTUS_MAPI_ABCONT");
				break;
			case BRUTUS_BRUTUS_MAPI_MESSAGE :
				g_print("BRUTUS_BRUTUS_MAPI_MESSAGE");
				break;
			case BRUTUS_BRUTUS_MAPI_MAILUSER :
				g_print("BRUTUS_BRUTUS_MAPI_MAILUSER");
				break;
			case BRUTUS_BRUTUS_MAPI_ATTACH :
				g_print("BRUTUS_BRUTUS_MAPI_ATTACH");
				break;
			case BRUTUS_BRUTUS_MAPI_DISTLIST :
				g_print("BRUTUS_BRUTUS_MAPI_DISTLIST");
				break;
			case BRUTUS_BRUTUS_MAPI_PROFSECT :
				g_print("BRUTUS_BRUTUS_MAPI_PROFSECT");
				break;
			case BRUTUS_BRUTUS_MAPI_STATUS :
				g_print("BRUTUS_BRUTUS_MAPI_STATUS");
				break;
			case BRUTUS_BRUTUS_MAPI_SESSION :
				g_print("BRUTUS_BRUTUS_MAPI_SESSION");
				break;
			default :
				g_print("UNKNOWN");
				break;
			}
			g_print("\n");
			break;
		case BRUTUS_BRUTUS_fnevCriticalError : 
			g_print("\t\tError notification\n");
			break;
		case BRUTUS_BRUTUS_fnevExtended :
			g_print("\t\tExtended notification\n");
			break;
		case BRUTUS_BRUTUS_fnevNewMail : 
			g_print("\t\tNew Mail notification\n");
			break;
		case BRUTUS_BRUTUS_fnevTableModified : 
			g_print("\t\tTable notification\n");
			break;
		case BRUTUS_BRUTUS_fnevStatusObjectModified :
			g_print("\t\tStatus Object notification\n");
			break;
		default :
			g_print("\t\tUNKNOWN Notification\n");
		}
	}
	*servant->notice_ = 1;
	/* ------ ---------- end ------------ ------ */
}
#endif

#if !defined(_impl_BRUTUS_IMAPIAdviseSink_InternalError_)
#define _impl_BRUTUS_IMAPIAdviseSink_InternalError_ 1
static void impl_BRUTUS_IMAPIAdviseSink_InternalError(impl_POA_BRUTUS_IMAPIAdviseSink * servant,
						      const BRUTUS_BRESULT ErrorCode,
						      CORBA_Environment * ev)
{
	/* ------   insert method code here   ------ */
	*servant->notice_ = 1;
	g_message("InternalError");
	/* ------ ---------- end ------------ ------ */
}
#endif
