solarpowerlog trunk
/home/tobi/workspace/solarpowerlog/src/Connections/CAsyncCommand.cpp
Go to the documentation of this file.
00001 /*
00002  * CAsyncCommand.cpp
00003  *
00004  *  Created on: Dec 14, 2009
00005  *      Author: tobi
00006  */
00007 
00008 #ifdef HAVE_CONFIG_H
00009 #include "config.h"
00010 #include "porting.h"
00011 #endif
00012 
00013 #include "configuration/Registry.h"
00014 #include "interfaces/CWorkScheduler.h"
00015 #include "Connections/CAsyncCommand.h"
00016 
00017 CAsyncCommand::CAsyncCommand(enum Commando c, ICommand *callback, sem_t *sem)
00018 {
00019      this->c = c;
00020      if (!callback) {
00021           this->callback = new ICommand(NULL, NULL);
00022           private_icommand = true;
00023      } else {
00024           this->callback = callback;
00025           private_icommand = false;
00026      }
00027 
00028      this->sem = sem;
00029 }
00030 
00031 CAsyncCommand::~CAsyncCommand()
00032 {
00033      // if we created the callback, delete it.
00034      // else, we are not owner of it, and so we cannot delete it.
00035      if (private_icommand) {
00036           delete callback;
00037      }
00038 }
00039 
00040 void CAsyncCommand::HandleCompletion( void )
00041 {
00042      if (!private_icommand) {
00043           Registry::GetMainScheduler()->ScheduleWork(callback);
00044      } else {
00045           sem_post(sem);
00046      }
00047 }
00048