You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
293 lines
7.2 KiB
293 lines
7.2 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 12/08/2002
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: HZMaskSchedule.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of HZMaskSchedule.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "HZMaskSchedule.h"
|
|
#include "Application.h"
|
|
|
|
CHZMaskSchedule::CHZMaskSchedule()
|
|
{
|
|
m_pApplication = NULL;
|
|
|
|
m_nDayOfWeek = -1;
|
|
}
|
|
|
|
CHZMaskSchedule::~CHZMaskSchedule()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
BOOL CHZMaskSchedule::Create( CApplication *pApplication )
|
|
{
|
|
m_pApplication = pApplication;
|
|
|
|
// mark that it is nessessary to make initializatioin
|
|
m_nDayOfWeek = -1;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CHZMaskSchedule::Destroy()
|
|
{
|
|
DeleteAll();
|
|
}
|
|
|
|
void CHZMaskSchedule::OnTimer( SYSTEMTIME *pST, PBOOL pStateHZ )
|
|
{
|
|
// perform initialization at the begining of the new day
|
|
if( m_nDayOfWeek != pST->wDayOfWeek )
|
|
{
|
|
// determine special day entry
|
|
BOOL bSpecialDayEntry = FALSE;
|
|
|
|
// find any special day schedule entry
|
|
for( INT i = 0; i < m_HzScheduleArray.GetCount(); i++ )
|
|
{
|
|
PHZ_SCHEDULE_EX pSchedule = &m_HzScheduleArray[i];
|
|
|
|
// if rule applies only to special day
|
|
if( pSchedule->bSpecialDay )
|
|
{
|
|
if( pST->wYear == pSchedule->stDate.wYear &&
|
|
pST->wMonth == pSchedule->stDate.wMonth &&
|
|
pST->wDay == pSchedule->stDate.wDay )
|
|
{
|
|
// mark that need to be performed
|
|
pSchedule->bPerform = TRUE;
|
|
|
|
// mark that found special day entry
|
|
bSpecialDayEntry = TRUE;
|
|
|
|
// log informaion
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CHZMaskSchedule::OnTimer", "found special day rule #%d", i );
|
|
}
|
|
else
|
|
{
|
|
// mark that need does not to be performed
|
|
pSchedule->bPerform = FALSE;
|
|
}
|
|
}
|
|
}
|
|
|
|
// find any special day schedule entry
|
|
for( i = 0; i < m_HzScheduleArray.GetCount(); i++ )
|
|
{
|
|
PHZ_SCHEDULE_EX pSchedule = &m_HzScheduleArray[i];
|
|
|
|
// if rule applies only to week day
|
|
if( !pSchedule->bSpecialDay )
|
|
{
|
|
// if this day is required day of week and no special day rules
|
|
if( pSchedule->bWeek[ pST->wDayOfWeek ] && !bSpecialDayEntry )
|
|
{
|
|
// mark that need to be performed
|
|
pSchedule->bPerform = TRUE;
|
|
|
|
// log informaion
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CHZMaskSchedule::OnTimer", "found week day rule #%d", i );
|
|
}
|
|
else
|
|
{
|
|
// mark that need does not to be performed
|
|
pSchedule->bPerform = FALSE;
|
|
}
|
|
}
|
|
}
|
|
|
|
// store current day
|
|
m_nDayOfWeek = pST->wDayOfWeek;
|
|
}
|
|
|
|
// check schedule plan
|
|
BOOL pHzOn[5] = { pStateHZ[0], pStateHZ[1], pStateHZ[2], pStateHZ[3], pStateHZ[4] };
|
|
for( INT i = 0; i < m_HzScheduleArray.GetCount(); i++ )
|
|
{
|
|
PHZ_SCHEDULE_EX pSchedule = &m_HzScheduleArray[i];
|
|
// if rule should be performed
|
|
if( pSchedule->bPerform )
|
|
{
|
|
// convert time from H:M:S to S
|
|
INT nTimeInSec = pST->wHour * 3600 + pST->wMinute * 60 + pST->wSecond;
|
|
INT nScheduleTimeInSec = pSchedule->stTime.wHour * 3600 + pSchedule->stTime.wMinute * 60 + pSchedule->stTime.wSecond;
|
|
|
|
// check date & time
|
|
if( nTimeInSec > nScheduleTimeInSec )
|
|
{
|
|
// mark as performed
|
|
pSchedule->bPerform = FALSE;
|
|
|
|
// log information
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CHZMaskSchedule::OnTimer", "rule #%d", i );
|
|
|
|
// update masks array
|
|
for( INT j = 0; j < 5; j++ )
|
|
if( pSchedule->pHzEnable[j] )
|
|
pHzOn[j] = pSchedule->pHzOn[j];
|
|
}
|
|
}
|
|
}
|
|
|
|
// pefrom hz switching
|
|
for( i = 0; i < 5; i++ )
|
|
{
|
|
// if changed
|
|
if( pStateHZ[i] != pHzOn[i] )
|
|
{
|
|
// perform switching
|
|
DoSwitchHZ( i, pHzOn[i] );
|
|
}
|
|
}
|
|
}
|
|
|
|
void CHZMaskSchedule::UpdateSchedule( INT nIndex )
|
|
{
|
|
// get current time & date
|
|
SYSTEMTIME st;
|
|
::GetLocalTime( &st );
|
|
|
|
// if this rule is rule for special day
|
|
if( m_HzScheduleArray[nIndex].bSpecialDay )
|
|
{
|
|
if( st.wYear == m_HzScheduleArray[nIndex].stDate.wYear &&
|
|
st.wMonth == m_HzScheduleArray[nIndex].stDate.wMonth &&
|
|
st.wDay == m_HzScheduleArray[nIndex].stDate.wDay )
|
|
{
|
|
// now is a special day for this rule
|
|
m_HzScheduleArray[nIndex].bPerform = TRUE;
|
|
return;
|
|
}
|
|
// requared day isn't today
|
|
m_HzScheduleArray[nIndex].bPerform = FALSE;
|
|
return;
|
|
}
|
|
|
|
// find any other special day schedule entry
|
|
for( INT i = 0; i < m_HzScheduleArray.GetCount(); i++ )
|
|
{
|
|
PHZ_SCHEDULE_EX pSchedule = &m_HzScheduleArray[i];
|
|
|
|
// if rule applies only to special day
|
|
if( pSchedule->bSpecialDay )
|
|
{
|
|
if( st.wYear == pSchedule->stDate.wYear &&
|
|
st.wMonth == pSchedule->stDate.wMonth &&
|
|
st.wDay == pSchedule->stDate.wDay )
|
|
{
|
|
// mark that it is not need to be performed
|
|
m_HzScheduleArray[nIndex].bPerform = FALSE;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
// if this day is required day of week and no special day rules
|
|
if( m_HzScheduleArray[nIndex].bWeek[ st.wDayOfWeek ] )
|
|
// mark that need to be performed
|
|
m_HzScheduleArray[nIndex].bPerform = TRUE;
|
|
else
|
|
// mark that it is not need to be performed
|
|
m_HzScheduleArray[nIndex].bPerform = FALSE;
|
|
}
|
|
|
|
BOOL CHZMaskSchedule::Load( LPCTSTR pFileName )
|
|
{
|
|
// open file
|
|
FILE *f = fopen( pFileName, "rb" );
|
|
if( !f )
|
|
return FALSE;
|
|
|
|
// read cumder of items
|
|
INT nCount = 0;
|
|
fread( &nCount, 1, sizeof( nCount ), f );
|
|
|
|
// validate number of items
|
|
if( nCount < 0 && nCount > 64000 )
|
|
{
|
|
fclose( f );
|
|
return FALSE;
|
|
}
|
|
|
|
// read all schedule plan
|
|
for( INT i = 0; i < nCount; i++ )
|
|
{
|
|
HZ_SCHEDULE HzSchedule;
|
|
|
|
// load from file
|
|
fread( &HzSchedule, 1, sizeof( HZ_SCHEDULE ), f );
|
|
|
|
Add( &HzSchedule );
|
|
}
|
|
|
|
// mark that nessesary to initialize
|
|
m_nDayOfWeek = -1;
|
|
|
|
// close file
|
|
fclose( f );
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CHZMaskSchedule::Save( LPCTSTR pFileName )
|
|
{
|
|
// open file
|
|
FILE *f = fopen( pFileName, "wb" );
|
|
if( !f )
|
|
return FALSE;
|
|
|
|
// write cumder of items
|
|
INT nCount = m_HzScheduleArray.GetCount();
|
|
fwrite( &nCount, 1, sizeof( nCount ), f );
|
|
|
|
// write all schedule plan
|
|
for( INT i = 0; i < m_HzScheduleArray.GetCount(); i++ )
|
|
{
|
|
PHZ_SCHEDULE pSchedule = &m_HzScheduleArray[i];
|
|
fwrite( pSchedule, 1, sizeof( HZ_SCHEDULE ), f );
|
|
}
|
|
|
|
// close file
|
|
fclose( f );
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CHZMaskSchedule::Add( PHZ_SCHEDULE pHzSchedule )
|
|
{
|
|
// perform strcut convertion from HZ_SCHEDULE to HZ_SCHEDULE_EX
|
|
HZ_SCHEDULE_EX HzScheduleEx;
|
|
PHZ_SCHEDULE pHzScheduleEx = &HzScheduleEx;
|
|
*pHzScheduleEx = *pHzSchedule;
|
|
|
|
HzScheduleEx.bPerform = TRUE;
|
|
|
|
// plase int orules array
|
|
return m_HzScheduleArray.Add( HzScheduleEx );
|
|
}
|
|
|
|
BOOL CHZMaskSchedule::Delete( INT nIndex )
|
|
{
|
|
// remove from rules array
|
|
return m_HzScheduleArray.Remove( nIndex );
|
|
}
|
|
|
|
void CHZMaskSchedule::DeleteAll()
|
|
{
|
|
// remove from rules array
|
|
m_HzScheduleArray.RemoveAll();
|
|
}
|
|
|
|
void CHZMaskSchedule::DoSwitchHZ( INT nHz, BOOL bOn )
|
|
{
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CHZMaskSchedule::SwitchHZ", "Hidden zone %d %s", nHz, bOn ? "on" : "off" );
|
|
|
|
// switch hidden zone
|
|
m_pApplication->SetViewZoneMode( nHz, bOn );
|
|
}
|