mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-22 22:03:39 +03:00
B #5425: License and minor formatting
This commit is contained in:
parent
55a66ae983
commit
b12113e5aa
@ -1,3 +1,19 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* 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 CACHE_POOL_H_
|
||||
#define CACHE_POOL_H_
|
||||
|
||||
@ -12,29 +28,30 @@
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* The Cache Pool class.
|
||||
* The Cache Pool class. This class is used to store volatile pool data.
|
||||
*/
|
||||
template<typename T> class CachePool
|
||||
{
|
||||
private:
|
||||
|
||||
pthread_mutex_t resource_lock;
|
||||
|
||||
std::map<int, T *> resources;
|
||||
|
||||
public:
|
||||
CachePool(){
|
||||
pthread_mutex_init(&resource_lock,0);
|
||||
CachePool()
|
||||
{
|
||||
pthread_mutex_init(&resource_lock, 0);
|
||||
}
|
||||
|
||||
~CachePool()
|
||||
{
|
||||
typename std::map<int, T *>::iterator it;
|
||||
|
||||
pthread_mutex_lock(&resource_lock);
|
||||
|
||||
for (it=resources.begin(); it != resources.end() ; ++it)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&resource_lock);
|
||||
|
||||
pthread_mutex_destroy(&resource_lock);
|
||||
};
|
||||
|
||||
T * get_resource(int oid)
|
||||
@ -77,6 +94,12 @@ public:
|
||||
|
||||
pthread_mutex_unlock(&resource_lock);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
pthread_mutex_t resource_lock;
|
||||
|
||||
std::map<int, T *> resources;
|
||||
};
|
||||
|
||||
#endif /*CACHE_POOL_H_*/
|
@ -40,7 +40,7 @@ public:
|
||||
const string& hook_location, const string& remotes_location,
|
||||
time_t expire_time);
|
||||
|
||||
~HostPool();
|
||||
~HostPool(){};
|
||||
|
||||
/**
|
||||
* Function to allocate a new Host object
|
||||
@ -320,15 +320,15 @@ private:
|
||||
set<int> prev_rediscovered_vms;
|
||||
};
|
||||
|
||||
pthread_mutex_t host_vm_lock;
|
||||
|
||||
CachePool<HostVM> cache;
|
||||
|
||||
HostVM * get_host_vm(int oid){
|
||||
HostVM * get_host_vm(int oid)
|
||||
{
|
||||
return cache.get_resource(oid);
|
||||
}
|
||||
|
||||
void delete_host_vm(int oid){
|
||||
void delete_host_vm(int oid)
|
||||
{
|
||||
cache.delete_resource(oid);
|
||||
}
|
||||
|
||||
|
@ -224,16 +224,6 @@ public:
|
||||
return groups.contains(_group_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets session token
|
||||
*
|
||||
* @param session_token the new session token
|
||||
*/
|
||||
void set_session(SessionToken * session_token)
|
||||
{
|
||||
session = session_token;
|
||||
}
|
||||
|
||||
// *************************************************************************
|
||||
// Quotas
|
||||
// *************************************************************************
|
||||
@ -381,7 +371,8 @@ protected:
|
||||
password(_password),
|
||||
auth_driver(_auth_driver),
|
||||
enabled(_enabled),
|
||||
groups("GROUPS")
|
||||
groups("GROUPS"),
|
||||
session(0)
|
||||
{
|
||||
obj_template = new UserTemplate;
|
||||
};
|
||||
|
@ -86,7 +86,7 @@ public:
|
||||
|
||||
if ( u != 0 )
|
||||
{
|
||||
u->set_session(get_session_token(oid));
|
||||
u->session = get_session_token(oid);
|
||||
}
|
||||
|
||||
return u;
|
||||
@ -106,7 +106,7 @@ public:
|
||||
|
||||
if ( u != 0 )
|
||||
{
|
||||
u->set_session(get_session_token(u->oid));
|
||||
u->session = get_session_token(u->oid);
|
||||
}
|
||||
|
||||
return u;
|
||||
@ -237,13 +237,15 @@ private:
|
||||
**/
|
||||
static time_t _session_expiration_time;
|
||||
|
||||
|
||||
CachePool<SessionToken> cache;
|
||||
SessionToken * get_session_token(int oid){
|
||||
|
||||
SessionToken * get_session_token(int oid)
|
||||
{
|
||||
return cache.get_resource(oid);
|
||||
}
|
||||
|
||||
void delete_session_token(int oid){
|
||||
void delete_session_token(int oid)
|
||||
{
|
||||
cache.delete_resource(oid);
|
||||
}
|
||||
|
||||
|
@ -140,18 +140,11 @@ HostPool::HostPool(SqlDB* db,
|
||||
|
||||
add_hook(hook);
|
||||
}
|
||||
|
||||
pthread_mutex_init(&host_vm_lock,0);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
HostPool::~HostPool(){};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HostPool::allocate (
|
||||
int * oid,
|
||||
const string& hostname,
|
||||
|
@ -497,10 +497,8 @@ int UserPool::drop(PoolObjectSQL * objsql, string& error_msg)
|
||||
return -1;
|
||||
}
|
||||
|
||||
User * user = static_cast<User *>(objsql);
|
||||
int oid = user->oid;
|
||||
|
||||
int rc = PoolSQL::drop(objsql, error_msg);
|
||||
int oid = (static_cast<User *>(objsql))->oid;
|
||||
int rc = PoolSQL::drop(objsql, error_msg);
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user