/***************************************************************************
                AutoDisableUpload.cpp
                -----------------------------------------
    begin      : 2011/07/26
    copyright  : (C) 2010 SolutionBox Inc.
    author     : svc1
    email      : svc1@solbox.com
    version    : 1.0

    CopyRight(C) 2010 SolutionBox Inc. All Rights reserved.
    Redistribution and use in source and binary forms, with or with out
    modification, are not permitted in outside of SolutionBox Inc.
***************************************************************************/
#include "AutoDisableUpload.h"

	
using namespace std;

CAutoDisableUpload::CAutoDisableUpload()
{
}

CAutoDisableUpload::~CAutoDisableUpload()
{
}

void CAutoDisableUpload::DoProcess( int eventCategory, int eventId )
{
	if( IsDisableUpload( eventCategory, eventId ) == false )
	{
		return;
	}

	system( "touch /user/service/vmasd.disable" );

	struct stat st;

	if( lstat( "/user/service/vmasd.disable", &st ) != 0 )
	{
		LOG(LERR, "can't touch vmasd.disable. event category = %s, event name = %s",
					m_szEventCategory.c_str(), m_szEventName.c_str() );
		return;
	}

	_LOG(LINF, "disable upload. event category = %s, event name = %s", 
			   m_szEventCategory.c_str(), m_szEventName.c_str() );
}

bool CAutoDisableUpload::IsDisableUpload( int eventCategory, int eventId )
{
    switch( eventCategory )
    {
        case EVENT_DEVICE:      
            /// The meaning of eventId. 
            ///  0(DEV_EVT_ADDED)			- Device Inserted
            ///  1(DEV_EVT_REMOVED)			- Device Removed
            ///  2(DEV_EVT_READ_ERROR)		- Reading Error
            ///  3(DEV_EVT_WRITE_ERROR)		- Writing Error
            ///  4(DEV_EVT_ATA_ECC_ERROR)	- ATA Ecc Error
            ///  5(DEV_EVT_ATA_CHANGE_MODE)	- Change ATA Mode
            ///  6(DEV_EVT_TIMEOUT)			- Time Out Error
            ///  7(DEV_EVT_MARK_FAILED)		- Device Failed
            ///  8(DEV_EVT_PCI_ERROR)		- PCI Parity Error
            ///  9(DEV_EVT_SMART_FAILED)	- Dev Fail (SMART)
            /// 10(DEV_EVT_CREATE_PASS)		- Pass Through Disk Created
			/// 11(DEV_EVT_MODIFY_PASS)		- Pass Through Disk Modified
			/// 12(DEV_EVT_DELETE_PASS)		- Pass Through Disk Deleted

			m_szEventCategory = "Device Event";
			m_szEventName = htmDevEvent[ eventId ];
			return ( eventId == DEV_EVT_MARK_FAILED ? true : false );

        case EVENT_VOLUMESET:
			/// The meaning of eventId.
			///  0(VS_EVT_INITIALIZING)			- Start Initialize
			///  1(VS_EVT_REBUILDING)			- Start Rebuilding
			///  2(VS_EVT_MIGRATING)			- Start Migrating
			///  3(VS_EVT_CHECKING)				- Start Checking
			///  4(VS_EVT_COMPLETE_INIT)		- Complete Init
			///  5(VS_EVT_COMPLETE_REBUILD)		- Complete Rebuild
			///  6(VS_EVT_COMPLETE_MIGRATING)	- Complete Migrate
			///  7(VS_EVT_COMPLETE_CHECKING)	- Complete Check
			///  8(VS_EVT_CREATE)				- Create Volume
			///  9(VS_EVT_DELETE)				- Delete Volume
			/// 10(VS_EVT_MODIFY)				- Modify Volume
			/// 11(VS_EVT_DEGRADED)				- Volume Degraded
			/// 12(VS_EVT_FAILED)				- Volume Failed
			/// 13(VS_EVT_REVIVED)				- Failed Volume Revived
			/// 14(VS_EVT_ABORT_INIT)			- Abort Initialization
			/// 15(VS_EVT_ABORT_REBUILD)		- Abort Rebuilding
			/// 16(VS_EVT_ABORT_MIGRATING)		- Abort Migration
			/// 17(VS_EVT_ABORT_CHECKING)		- Abort Checking
			/// 18(VS_EVT_STOP_INIT)			- Stop Initialization
			/// 19(VS_EVT_STOP_REBUILD)			- Stop Rebuilding
			/// 20(VS_EVT_STOP_MIGRATING)		- Stop Migration
			/// 21(VS_EVT_STOP_CHECKING)		- Stop Checking

			m_szEventCategory = "VolumeSet Event";
			m_szEventName = htmVolEvent[ eventId ];
			return ( ( eventId == VS_EVT_REBUILDING ) || ( eventId == VS_EVT_DEGRADED ) ? true : false );

        case EVENT_RAIDSET: 
			/// The meaning of eventId
			///  0(RS_EVT_CREATE) - Create RaidSet
			///  1(RS_EVT_DELETE) - Delete RaidSet
			///  2(RS_EVT_EXPAND) - Expand RaidSet
			///  3(RS_EVT_REBUILD) - Rebuild RaidSet
			///  4(RS_EVT_DEGRADED) - RaidSet Degraded

			m_szEventCategory = "RaidSet Event";
			m_szEventName = htmRaidEvent[ eventId ];
			return ( ( eventId == RS_EVT_REBUILD ) || ( eventId == RS_EVT_DEGRADED ) ? true : false );

		/// for test code
		///case EVENT_NEW_83782D:
		///	m_szEventCategory = "New Events";
		///	m_szEventName = htmNewEventStr[ eventId ];
		///	return ( eventId == GHM_GUI_LOGIN ? true : false );

		default:
			m_szEventCategory = "";
			m_szEventName = "";
    }

	return false;
}

