<commit_before>/*
	Flexisip, a flexible SIP proxy server with media capabilities.
    Copyright (C) 2010  Belledonne Communications SARL.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "net-snmp/net-snmp-config.h"
#include "net-snmp/net-snmp-includes.h"
#include "net-snmp/agent/net-snmp-agent-includes.h"
#include <signal.h>
#include <functional>
#include "snmp-agent.h"
#include "configmanager.hh"

using namespace std;

SnmpAgent::~SnmpAgent() {
	mTask.mKeepRunning=false;
	LOGD("Waiting for the SNMP agent task to terminate");
	mThread.join();
}

SnmpAgent::SnmpAgentTask::SnmpAgentTask(Agent& agent,GenericManager& cm, map<string,string> &oset)
:mConfigmanager(cm),mAgent(agent) {
	bool disabled=oset.find("nosnmp") != oset.end();
	mKeepRunning=!disabled;
}

void SnmpAgent::SnmpAgentTask::operator()() {
	if (!mKeepRunning) {
		LOGD("SNMP has been disabled");
		return;
	}
	init_snmp("flexisip");
	mConfigmanager.getSnmpNotifier()->setInitialized(true);
	while (mKeepRunning) {
		if (mConfigmanager.mNeedRestart) mKeepRunning=false;
		agent_check_and_process(1);
	}
	mConfigmanager.getSnmpNotifier()->setInitialized(false);
	snmp_shutdown("flexisip");
	SOCK_CLEANUP;
}

SnmpAgent::SnmpAgent(Agent& agent,GenericManager &cm, map<string,string> &oset)
: mTask(agent,cm, oset),mThread(std::ref(mTask)){
}


<commit_msg>allow snmp module to stop on macosx<commit_after>/*
	Flexisip, a flexible SIP proxy server with media capabilities.
    Copyright (C) 2010  Belledonne Communications SARL.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "net-snmp/net-snmp-config.h"
#include "net-snmp/net-snmp-includes.h"
#include "net-snmp/agent/net-snmp-agent-includes.h"
#include <signal.h>
#include <functional>
#include "snmp-agent.h"
#include "configmanager.hh"

using namespace std;

SnmpAgent::~SnmpAgent() {
	mTask.mKeepRunning=false;
	LOGD("Waiting for the SNMP agent task to terminate");
	mThread.join();
}

SnmpAgent::SnmpAgentTask::SnmpAgentTask(Agent& agent,GenericManager& cm, map<string,string> &oset)
:mConfigmanager(cm),mAgent(agent) {
	bool disabled=oset.find("nosnmp") != oset.end();
	mKeepRunning=!disabled;
}

void SnmpAgent::SnmpAgentTask::operator()() {
	if (!mKeepRunning) {
		LOGD("SNMP has been disabled");
		return;
	}
	init_snmp("flexisip");
	mConfigmanager.getSnmpNotifier()->setInitialized(true);
	while (mKeepRunning) {
		if (mConfigmanager.mNeedRestart) mKeepRunning=false;
		agent_check_and_process(0);
		usleep(100000);
	}
	mConfigmanager.getSnmpNotifier()->setInitialized(false);
	snmp_shutdown("flexisip");
	SOCK_CLEANUP;
}

SnmpAgent::SnmpAgent(Agent& agent,GenericManager &cm, map<string,string> &oset)
: mTask(agent,cm, oset),mThread(std::ref(mTask)){
}



{'fraction_non_alphanumeric': 0.11181221605249873, 'fraction_numerical': 0.004543160020191822, 'mean_word_length': 5.041158536585366, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2082904', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1275, 'n_words': 373}