Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _MYSQL_USER_ "[username]"
- #include "soaploadProxy.h"
- #include "load.nsmap"
- #include <iostream>
- #include <stdlib.h>
- #include <mysql_connection.h>
- #include <cppconn/driver.h>
- #include <cppconn/exception.h>
- #include <cppconn/resultset.h>
- #include <cppconn/statement.h>
- #include <boost/lexical_cast.hpp>
- using namespace std;
- int generationCheck(loadProxy &load);
- const char serverLoad[] = "http://[ip address]/cgi-bin/loadserver.cgi";
- int main(int argc, char **argv)
- {
- loadProxy load;
- load.soap_endpoint = serverLoad;
- while (true)
- {
- generationCheck(load);
- }
- return 1;
- }
- int generationCheck(loadProxy &load)
- {
- double result;
- int id, done, transact;
- std::string datetime;
- std::string query;
- double watts, timespan, tariffPaid;
- try
- {
- sql::Driver *driver;
- sql::Connection *con;
- sql::Statement *stmt;
- sql::ResultSet *res;
- // Create the connection
- driver = get_driver_instance();
- con = driver->connect("tcp://[ip address]:3306", _MYSQL_USER_, "[password]");
- // Connect to the MySQL database
- con->setSchema("db");
- // Create MySQL statement
- stmt = con->createStatement();
- // Define MySQL query
- res = stmt->executeQuery("SELECT * FROM l1 WHERE generated = 1 AND done = 0;");
- while (res->next())
- {
- id = res->getInt("id");
- transact = res->getInt("transact");
- datetime = res->getString("datetime");
- watts = res->getDouble("watts");
- timespan = res->getDouble("timespan");
- tariffPaid = res->getDouble("tariffPaid");
- printf("Yes, id: %d\n", id);
- load.bidMetGenerator(transact, datetime, watts, timespan, tariffPaid, &result);
- if (load.error)
- load.soap_stream_fault(std::cerr);
- else
- printf("Bid met by generator. Result: %f\n", result);
- if (result == 0)
- {
- query = "UPDATE l1 SET utility = 1 WHERE id = ";
- query += boost::lexical_cast<string>(id);
- query += ";";
- stmt->executeUpdate(query);
- }
- else
- {
- query = "UPDATE l1 SET done = 1 WHERE id = ";
- query += boost::lexical_cast<string>(id);
- query += ";";
- stmt->executeUpdate(query);
- }
- }
- delete stmt;
- delete res;
- delete con;
- } catch (sql::SQLException &e) {
- cout << "# ERR: SQLException in " << __FILE__;
- cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
- cout << "#ERR: " << e.what();
- cout << " (MySQL error code: " << e.getErrorCode();
- cout << ", SQLStateL " << e.getSQLState() << " )" << endl;
- return 0;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement