/*
** SellaNMS
** $Id: snmp.h,v 1.44 2005/05/15 05:21:17 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_MODULE_DISCOVERY_SNMP_H
#define __DGS_MODULE_DISCOVERY_SNMP_H

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

#include "defaults.h"
#include "util.h"
#include "snmp_util.h"
#include "storagedata.h"
#include "policy_framework/policy_framework.h"
#include "../discovery.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/time.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#ifdef HAVE_NET_SNMP
	#include <net-snmp/net-snmp-config.h>
	#include <net-snmp/net-snmp-includes.h>
	#include <net-snmp/library/default_store.h>
#else
	#include <ucd-snmp/ucd-snmp-config.h>
	#include <ucd-snmp/ucd-snmp-includes.h>
	#include <ucd-snmp/default_store.h>
#endif
#include <stl/list>
#include <stl/queue>
#include <stl/string>

#define MODULE_DISCOVERY_SNMP_THREADCOUNT_DEFAULT		32
#define MODULE_DISCOVERY_SNMP_BURST_DEFAULT				0
#define MODULE_DISCOVERY_SNMP_COMMITCOUNT_DEFAULT		300
#define MODULE_DISCOVERY_SNMP_RETRY_DEFAULT				5
#define MODULE_DISCOVERY_SNMP_TIMEOUT_DEFAULT			2000

typedef vector<pair<oid*, size_t> > oid_vector_t;
typedef queue<pair<string, string> > query_result_t;
typedef queue<pair<string, query_result_t *> > result_snmp_t;

class SNMP: public Discovery {
	public:
		SNMP();
		virtual ~SNMP();

	protected:
		virtual RESULT printConfig();

	private:
		virtual RESULT execute();
		virtual RESULT readConfig();

		RESULT fillWorkQueue();
		RESULT spawnThreads();
		RESULT queryThreads();
		RESULT writeResults();
		RESULT sendRequest(pthread_t, const char*, query_result_t &ret_val);
		static RESULT query_thread(void* args);

		unsigned long maxThreadCount;
		unsigned long timeout;
		unsigned long retry;
		unsigned long commit_count;
		vector<string> communities;

		list<pthread_t> children;

		uint32_t			source;

		priority_queue<string> to_do_queue;
		pthread_mutex_t to_do_queue_mutex;
		pthread_mutex_t result_queue_mutex;
		result_snmp_t result_queue;
		oid_vector_t real_oids;
};

#endif

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