Commit a8a717b2 authored by Michael Ott's avatar Michael Ott
Browse files

Add multi-threading

parent 33d33fd4
......@@ -11,7 +11,7 @@ include $(DCDBCOREPATH)/common.mk
CXXFLAGS = -O2 -g -Wall $(CXX11FLAGS) -I$(DCDBDEPLOYPATH)/include/ -I$(DCDBBASEPATH)/include -I../deps/freeipmi-$(FREEIPMI_VERSION)/libfreeipmi/include -I../deps/freeipmi-$(FREEIPMI_VERSION)/libfreeipmi/api
OBJS = ipmipusher.o IPMISensor.o IPMIHost.o
LIBS = -L$(DCDBDEPLOYPATH)/lib/ -lpthread -lfreeipmi -lboost_regex -lboost_system -lboost_date_time
LIBS = -L$(DCDBDEPLOYPATH)/lib/ -lfreeipmi -lboost_thread -lboost_regex -lboost_system -lboost_date_time
TARGET = ipmipusher
$(DCDBDEPSPATH)/freeipmi-$(FREEIPMI_VERSION)/.installed: $(DCDBDEPSPATH)/freeipmi-$(FREEIPMI_VERSION)/.patched
......
sensors
{
global {
threads 16
}
sensors {
sensor energy {
type raw
freq 1000
freq 2000
cmd "0x00 0x2e 0x81 0x4d 0x4f 0x00 0x00 0x01 0x82 0x00 0x08"
start 5
stop 12
......
......@@ -4,6 +4,7 @@
#include <boost/optional.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/asio.hpp>
#include <boost/thread/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <string>
......@@ -12,24 +13,31 @@
#include <exception>
#include <iostream>
#include <unistd.h>
#include <thread>
#include "IPMIHost.h"
#include "IPMISensor.h"
std::list<DCDB::IPMIHost> hosts;
typedef std::map<std::string, DCDB::IPMISensor> sensorMap_t;
sensorMap_t sensors;
int numOfThreads = 1;
boost::asio::io_service io;
boost::thread_group threads;
int parseConfig(std::string cfgFile) {
boost::property_tree::iptree cfg;
boost::property_tree::read_info(cfgFile, cfg);
BOOST_FOREACH(boost::property_tree::iptree::value_type &global, cfg.get_child("global")) {
std::cout << global.first << " " << global.second.data() << std::endl;
if (boost::iequals(global.first, "threads")) {
numOfThreads = stoi(global.second.data());
}
}
BOOST_FOREACH(boost::property_tree::iptree::value_type &sensor, cfg.get_child("sensors")) {
std::cout << sensor.first << std::endl;
if (boost::iequals(sensor.first, "sensor")) {
std::cout << "Sensor " << sensor.second.data() << std::endl;
if (!sensor.second.empty()) {
......@@ -90,12 +98,6 @@ int parseConfig(std::string cfgFile) {
return 0;
}
void runTask(const boost::system::error_code& e, boost::asio::deadline_timer* t, DCDB::IPMISensor* sensor) {
t->expires_from_now(boost::posix_time::seconds(5));
std::cout << sensor->getHost()->getHostName() << "::" << sensor->getName() << " (" << sensor->getHost()->getMqttPrefix() << sensor->getMqttSuffix() << ") : " << sensor->query() << std::endl;
t->async_wait(boost::bind(runTask, boost::asio::placeholders::error, t, sensor));
}
int main (int argc, char **argv) {
if (argc <= 1) {
std::cout << "Please specify a config file" << std::endl;
......@@ -112,7 +114,10 @@ int main (int argc, char **argv) {
}
}
io.run();
for (std::size_t i = 0; i < numOfThreads; i++) {
threads.create_thread(boost::bind(&boost::asio::io_service::run, &io));
}
threads.join_all();
/*
BOOST_FOREACH(DCDB::IPMIHost &host, hosts) {
host.disconnect();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment