mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-11 05:17:41 +03:00
Feature #1483: Create new Util.h file to define common methods, like creating log timestamp strings
This commit is contained in:
parent
f9b7f820c6
commit
3b01566e9b
60
include/Util.h
Normal file
60
include/Util.h
Normal file
@ -0,0 +1,60 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef UTIL_H_
|
||||
#define UTIL_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace one_util
|
||||
{
|
||||
string& toupper(string& st)
|
||||
{
|
||||
transform(st.begin(),st.end(),st.begin(),(int(*)(int))std::toupper);
|
||||
return st;
|
||||
};
|
||||
|
||||
string& tolower(string& st)
|
||||
{
|
||||
transform(st.begin(),st.end(),st.begin(),(int(*)(int))std::tolower);
|
||||
return st;
|
||||
};
|
||||
|
||||
string log_time(time_t the_time)
|
||||
{
|
||||
char time_str[26];
|
||||
|
||||
#ifdef SOLARIS
|
||||
ctime_r(&(the_time),time_str,sizeof(char)*26);
|
||||
#else
|
||||
ctime_r(&(the_time),time_str);
|
||||
#endif
|
||||
|
||||
time_str[24] = '\0'; // Get rid of final enter character
|
||||
|
||||
return string(time_str);
|
||||
};
|
||||
|
||||
string log_time()
|
||||
{
|
||||
return log_time( time(0) );
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif /* UTIL_H_ */
|
@ -34,6 +34,7 @@
|
||||
#include "RankPolicy.h"
|
||||
#include "NebulaLog.h"
|
||||
#include "PoolObjectAuth.h"
|
||||
#include "Util.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -649,21 +650,10 @@ int Scheduler::scheduled_actions()
|
||||
int action_time, done_time, has_time, has_done;
|
||||
string action_st, error_msg;
|
||||
|
||||
// TODO: Move the time string creation to a common place
|
||||
|
||||
char time_str[26];
|
||||
|
||||
ostringstream oss;
|
||||
ostringstream oss_aux;
|
||||
|
||||
#ifdef SOLARIS
|
||||
ctime_r(&(the_time),time_str,sizeof(char)*26);
|
||||
#else
|
||||
ctime_r(&(the_time),time_str);
|
||||
#endif
|
||||
|
||||
time_str[24] = '\0'; // Get rid of final enter character
|
||||
|
||||
string time_str = one_util::log_time(the_time);
|
||||
|
||||
const map<int, ObjectXML*> vms = vmpool->get_objects();
|
||||
|
||||
@ -689,9 +679,10 @@ int Scheduler::scheduled_actions()
|
||||
has_time = vatt->vector_value("TIME", action_time);
|
||||
has_done = vatt->vector_value("DONE", done_time);
|
||||
|
||||
// TODO: Transform to lower case
|
||||
action_st = vatt->vector_value("ACTION");
|
||||
|
||||
one_util::tolower(action_st);
|
||||
|
||||
if (has_time == 0 && has_done == -1 && action_time < the_time)
|
||||
{
|
||||
oss.str("");
|
||||
|
Loading…
Reference in New Issue
Block a user