/*
** SellaNMS
** $Id: state.h,v 1.7 2005/11/26 06:48:45 sella Exp $
** Copyright (c) 2001-2005 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
*/

#ifndef __DGS_MONITOR_STATE_H
#define __DGS_MONITOR_STATE_H

#ifdef HAVE_CONFIG_H
	#include "config.h"
#endif

#include "defaults.h"
#include "state.h"
#include "common/util.h"
#include "common/netblock.h"
#include "storage/storagedata.h"
#include "policy_framework/policy_framework.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <stl/hash_map>
#include <stl/stack>

#define MONITOR_STATE_UPDATEINTERVAL_DEF	30
#define MONITOR_STATE_UPDATEINTERVAL_MIN	1
#define MONITOR_STATE_UPDATEINTERVAL_MAX	3600
#define MONITOR_STATE_UPDATEINTERVAL_MLT	1000000
#define MONITOR_STATE_EXPIREINTERVAL_DEF	3600
#define MONITOR_STATE_EXPIREINTERVAL_MIN	30
#define MONITOR_STATE_EXPIREINTERVAL_MAX	86400
#define MONITOR_STATE_EXPIREINTERVAL_MLT	1000000
#define MONITOR_STATE_MAXDELETE_DEF			250
#define MONITOR_STATE_MAXDELETE_MIN			1
#define MONITOR_STATE_MAXDELETE_MAX			5000

class State {
	public:
		State();
		~State();
		virtual RESULT execute();
		virtual RESULT readConfig();

	protected:
		RESULT expire();
		RESULT update();
		RESULT processPolicy(variable_binding_t& policy_input, hash_map<string, string>& tableMap);
		RESULT processChange(variable_binding_t& policy_input, variable_binding_t& policy_output, hash_map<string, string>& tableMap);
		RESULT processExpirePolicy(variable_binding_t& policy_input, stack<string> &ids);
		RESULT deleteExpired(stack<string> &ids, const char* table);

	private:
		static RESULT expire_thread(void *args);

		virtual void printConfig();

		time_t timestamp;
		unsigned long interval;
		unsigned long expireInterval;
		unsigned long maxDelete;

		Storage storage;

		PolicyFramework inputPolicy;
	 	PolicyFramework outputPolicy;

		bool processElementOnly;

		unsigned int updateCount;

};

#endif

/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim600: fdm=marker
** vim: noet ts=3 sw=3
*/
