156 lines
4.5 KiB
C++

//----------------------------------------------------------------------------
//
// Copyright (C) Intel Corporation, 2006 - 2007.
//
// File: DevicePresence.h
//
// Contents: Notifies management consoles on tunnel connections.
//
// Notes:
//----------------------------------------------------------------------------
#ifndef _MPS_DEVICE_PRESENCE_H__
#define _MPS_DEVICE_PRESENCE_H__
//===================================================
// INCLUDES
//===================================================
#include <ace/OS.h>
#include <ace/Message_Block.h>
#include <ace/Svc_Handler.h>
#include <ace/SOCK_Stream.h>
#include <ace/Reactor_Notification_Strategy.h>
#include "OptionsUtils.h"
#include "soapStub.h"
// FW declaration
class SOAPCommunicator;
enum EVENT_REASON {e_connect, e_disconnect};
class MCList;
/***************************************************************************************
//class NotificationMessage
//
/**************************************************************************************/
class NotificationMessage : public ACE_Message_Block
{
public:
//===================================================
// CTOR/DTOR
//===================================================
NotificationMessage( string &MEAddress ,
unsigned short MEPort,
string &ME_UUID,
string &MPSAddress,
unsigned short MPSHttpPort,
unsigned short MPSSocksPort,
mps__ConnectionStateTypeDefinition state):
_MEAddress(MEAddress),
_MEPort(MEPort),
_ME_UUID(ME_UUID),
_MPSAddress(MPSAddress),
_MPSHttpPort(MPSHttpPort),
_MPSSocksPort(MPSSocksPort),
_state(state)
{};
~NotificationMessage(void){};
//===================================================
// Data Members
//===================================================
string _MEAddress;
unsigned short _MEPort;
string _ME_UUID;
string _MPSAddress;
unsigned short _MPSHttpPort;
unsigned short _MPSSocksPort;
mps__ConnectionStateTypeDefinition _state;
};
/***************************************************************************************
//class DevicePresence
//
//Class that runs in a different thread, which receives a list of MC, and send them MPS
// events about AMT connect/disconnect.
/**************************************************************************************/
class DevicePresence : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_MT_SYNCH>
{
public:
//===================================================
// CTOR/DTOR
//===================================================
private:
DevicePresence(void):
_is_open(false),
_soap_comm(NULL),
_mc_list(*getChangableMCSubscribersList()),
_notification_strategy(){};
public:
/*
* Return Singleton of DevicePresence.
* Must be called only after createInstance was called.
*/
static DevicePresence &instance (void) {
static DevicePresence _instance; // This is a singleton
return _instance;
};
~DevicePresence(void){
if (_soap_comm != NULL)
delete _soap_comm;
};
void sendEvent( string &MEAddress ,
unsigned short MEPort,
string &ME_UUID,
string &MPSAddress,
unsigned short MPSHttpPort,
unsigned short MPSSocksPort,
mps__ConnectionStateTypeDefinition state);
//===================================================
// PROTOTYPE:
//===================================================
// Implement the Service initialization, should be balled only once
int start(void);
// Handle output and close messages from the reactor
virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE,
ACE_Reactor_Mask close_mask =
ACE_Event_Handler::ALL_EVENTS_MASK);
virtual int handle_output (ACE_HANDLE = ACE_INVALID_HANDLE);
private:
//===================================================
// Private members
//===================================================
bool _is_open; // This flag keeps track if we are registered in the reactor
// to make sure we don't register ourself twice
SOAPCommunicator* _soap_comm;
ACE_Reactor_Notification_Strategy* _notification_strategy;
ACE_Recursive_Thread_Mutex _output_mutex;
// Notification list, from which to read the notification messages.
MCList& _mc_list;
//-----------------------------------------
// Sends events to MC already exist in MC list.
// if evnt_reason is connect - sends connect event, etc.
//
//Argument:
// @
//-----------------------------------------
void sendEvent(NotificationMessage *msg);
};
#endif //_MPS_DEVICE_PRESENCE_H__