1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

The Pool is now Hookable so we can hook on database updates

git-svn-id: http://svn.opennebula.org/one/trunk@430 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Rubén S. Montero 2009-03-27 00:32:02 +00:00
parent 7b1f4a93ae
commit 80bd74457b
3 changed files with 20 additions and 9 deletions

View File

@ -91,7 +91,7 @@ public:
virtual ~Hookable()
{
vector<Hook *>::size_type sz = hooks.size();
int sz = static_cast<int>(hooks.size());
for (int i=0; i<sz ; i++)
{
@ -116,8 +116,8 @@ public:
*/
void clear_hooks()
{
vector<Hook *>::size_type sz = hooks.size();
int sz = static_cast<int>(hooks.size());
for (int i=0; i<sz ; i++)
{
delete hooks[i];
@ -133,7 +133,7 @@ public:
*/
void do_hooks(void *arg = 0)
{
vector<Hook *>::size_type sz = hooks.size();
int sz = static_cast<int>(hooks.size());
for (int i=0; i<sz ; i++)
{
@ -152,4 +152,4 @@ private:
vector<Hook *> hooks;
};
#endif
#endif

View File

@ -25,6 +25,7 @@
#include "SqliteDB.h"
#include "PoolObjectSQL.h"
#include "Log.h"
#include "Hook.h"
using namespace std;
@ -34,7 +35,7 @@ using namespace std;
* multithreaded applications. Any modification or access function to the pool
* SHOULD block the mutex.
*/
class PoolSQL
class PoolSQL: public Hookable
{
public:
@ -94,7 +95,16 @@ public:
virtual int update(
PoolObjectSQL * objsql)
{
return objsql->update(db);
int rc;
rc = objsql->update(db);
if ( rc == 0 )
{
do_hooks(objsql);
}
return rc;
};
/**

View File

@ -64,8 +64,7 @@ extern "C"
/* -------------------------------------------------------------------------- */
PoolSQL::PoolSQL(SqliteDB * _db, const char * table)
:db(_db)
PoolSQL::PoolSQL(SqliteDB * _db, const char * table): Hookable(), db(_db)
{
ostringstream oss;
@ -139,6 +138,8 @@ int PoolSQL::allocate(
rc = lastOID;
}
do_hooks(objsql);
objsql->unlock();
delete objsql;