i_Service_i Class Reference
[IVD Helper Service]

#include <i_svc_impl.h>

Inheritance diagram for i_Service_i:

Inheritance graph
[legend]
Collaboration diagram for i_Service_i:

Collaboration graph
[legend]

List of all members.


Detailed Description

Definition at line 52 of file i_svc_impl.h.


Public Member Functions

 i_Service_i ()
virtual ~i_Service_i ()
CORBA::Long Execute (i_Binaries_e a_binary, const i_StringList_t &a_arg)
CORBA::Long ExecutePy (i_Binaries_e a_script, const i_StringList_t &a_arg)
i_UploadAgent_ptr CreateUploadAgent (i_DirectoryType_e a_dtType, const char *a_relName)
i_DownloadAgent_ptr CreateDownloadAgent (i_DirectoryType_e a_dtType, const char *a_relName)
i_BackupAgent_ptr CreateBackupAgent (const char *a_device, const char *a_pipe, i_BlkSize_t a_blkSize)
i_RestoreAgent_ptr CreateRestoreAgent (const char *a_device, const char *a_pipe, i_BlkSize_t a_blkSize)
void DeleteFile (i_DirectoryType_e a_dtType, const char *a_relName)

Private Member Functions

cmn_Path FindCmd (const i_Binaries_e a_binary, UInt32_t &a_flags)
cmn_Path FindPy (const i_Binaries_e a_script, UInt32_t &a_flags)

Private Attributes

 log_CLASSID_m

Constructor & Destructor Documentation

i_Service_i::i_Service_i (  ) 

Definition at line 35 of file i_svc_impl.cpp.

00035                         {
00036     // add extra constructor code here
00037 }

i_Service_i::~i_Service_i (  )  [virtual]

Definition at line 39 of file i_svc_impl.cpp.

References log_FUNC_m, and ipc_Corba::Shutdown().

00039                          {
00040     log_FUNC_m(~i_Service_i);
00041 
00042     ipc_Corba::Shutdown();
00043 }

Here is the call graph for this function:


Member Function Documentation

cmn_Path i_Service_i::FindCmd ( const i_Binaries_e  a_binary,
UInt32_t a_flags 
) [private]

Definition at line 86 of file i_svc_impl.cpp.

References dbg_DETAIL, dbg_LOW, svc_execString::flags, i_SENTINEL, ie_INVALID_ARG, log_DBG_m, log_FUNC_m, svc_execString::path, path, and svc_execPostfix.

Referenced by Execute().

00086                                                                            {
00087     log_FUNC_m(FindCmd);
00088 
00089     UInt32_t i = 0;
00090 
00091     while ((allowedCmd[i].binary != i_SENTINEL) && !allowedCmd[i].path.empty()){
00092         if ( allowedCmd[i].binary == a_binary ) {
00093             log_DBG_m(dbg_DETAIL,
00094                 "Found command:" <<
00095                 allowedCmd[i].path << allowedCmd[i].fileName);
00096             a_flags = allowedCmd[i].flags;
00097             return allowedCmd[i].path
00098                 + (string(allowedCmd[i].fileName) + svc_execPostfix);
00099         }
00100         i++;
00101     }
00102     log_DBG_m(dbg_LOW, "Can not execute unknown command: " << a_binary);
00103     throw ivd_InternalError(ie_INVALID_ARG, "Can not execute unknown command.");
00104 }

Here is the caller graph for this function:

cmn_Path i_Service_i::FindPy ( const i_Binaries_e  a_script,
UInt32_t a_flags 
) [private]

Definition at line 107 of file i_svc_impl.cpp.

References dbg_DETAIL, dbg_LOW, svc_execString::flags, i_SENTINEL, ie_INVALID_ARG, log_DBG_m, log_FUNC_m, svc_execString::path, and path.

Referenced by ExecutePy().

00107                                                                            {
00108     log_FUNC_m(FindPy);
00109 
00110     UInt32_t i = 0;
00111 
00112     while ((allowedPy[i].binary != i_SENTINEL) && !allowedPy[i].path.empty()) {
00113         if ( allowedPy[i].binary == a_script ) {
00114             log_DBG_m(dbg_DETAIL,
00115                 "Found python script:" <<
00116                 allowedPy[i].path << allowedPy[i].fileName);
00117             a_flags = allowedPy[i].flags;
00118             return allowedPy[i].path + string(allowedPy[i].fileName);
00119         }
00120         i++;
00121     }
00122     log_DBG_m(dbg_LOW, "Can not execute unknown Script: " << a_script);
00123     throw ivd_InternalError(ie_INVALID_ARG, "Can not execute unknown script.");
00124 }

Here is the caller graph for this function:

CORBA::Long i_Service_i::Execute ( i_Binaries_e  a_binary,
const i_StringList_t a_arg 
)

Definition at line 128 of file i_svc_impl.cpp.

References cmn_CreatePathNoException(), cmn_ExecCommand(), cmn_Global::dbg, dbg_DETAIL, cmn_File::DeleteDir(), cmn_Global::dirs, FindCmd(), g_cmn, log_Debugger::GetArgFile(), log_Debugger::GetArgFlags(), log_Debugger::GetArgLevel(), ivd_BaseException::GetFriendly(), i_IVD, ipc_CATCH_IVD_THROW_CORBA_m, log_DBG_m, log_FUNC_m, log_WriteEvent(), and ivd_Directories::tmp.

00128                                                                                 {
00129 
00130     CORBA::Long ret = 0;
00131 
00132     string deleteMountPoint;
00133 
00134     log_FUNC_m(Execute);
00135     log_DBG_m(dbg_DETAIL,"will exec: " << a_binary);
00136     try {
00137         UInt32_t flags;
00138         cmn_Path execThis = FindCmd(a_binary, flags);
00139 
00140         log_DBG_m(dbg_DETAIL, "Preparing to execute: " << execThis);
00141 
00142         vector<string> argVec;
00143 
00144         for (UInt32_t i = 0; i < a_arg.length(); i++){
00145             string arg(a_arg[i]);
00146             argVec.push_back(arg);
00147         }
00148 
00149         if ((a_binary == i_IVD) && (argVec.size()>2) &&
00150             (argVec[0].compare("--mount-recovery") == 0 || (argVec[0].compare("--umount-recovery") == 0)) &&
00151             (argVec[1].empty())) {
00152             // Special handling when called from recovery.
00153             string mountdir = argVec[2];
00154             replace(mountdir.begin(), mountdir.end(), '/', '_');
00155             argVec[1] = g_cmn.dirs.tmp + string("recovery") + mountdir;
00156             
00157             if (argVec[0].compare("--umount-recovery") == 0) {
00158                 // Store path for delete after ExecCommand.
00159                 deleteMountPoint = argVec[1];
00160             }
00161             else { // --mount
00162                 cmn_CreatePathNoException(argVec[1]);
00163             }
00164         }
00165         else {
00166 
00167             // if we are running in debug -> pass debug to started program too
00168             if (g_cmn.dbg.GetArgLevel() != "") {
00169                 argVec.push_back("--dbg");
00170                 argVec.push_back(g_cmn.dbg.GetArgLevel());
00171                 argVec.push_back(g_cmn.dbg.GetArgFile());
00172                 argVec.push_back(g_cmn.dbg.GetArgFlags());
00173             }
00174         }
00175 
00176         try {
00177             ret = cmn_ExecCommand(execThis, argVec, flags);
00178         }
00179         catch (ivd_Exception &e) {
00180             ostringstream sstr;
00181             sstr << "ERROR: Cannot execute " << execThis
00182                  << " (" << e.GetFriendly() << ").";
00183             log_WriteEvent(sstr.str());
00184             throw;
00185         }
00186         if (!deleteMountPoint.empty()) {
00187             // Specall handling when called from recovery.
00188             cmn_File::DeleteDir(deleteMountPoint);
00189         }
00190     }
00191     ipc_CATCH_IVD_THROW_CORBA_m;
00192 
00193     return ret;
00194 }

Here is the call graph for this function:

CORBA::Long i_Service_i::ExecutePy ( i_Binaries_e  a_script,
const i_StringList_t a_arg 
)

Definition at line 197 of file i_svc_impl.cpp.

References cmn_ExecCommand(), cmn_RegGetKeys(), cmn_RegGetValue(), dbg_DETAIL, FindPy(), ivd_BaseException::GetFriendly(), ie_FILE_ERROR, ipc_CATCH_IVD_THROW_CORBA_m, ivd_Error, log_DBG_m, log_FUNC_m, and log_WriteEvent().

00197                                                                                   {
00198 
00199     CORBA::Long ret = 0;
00200 
00201     log_FUNC_m(ExecutePy);
00202     log_DBG_m(dbg_DETAIL,"will exec script: " << a_script);
00203     try {
00204 #if TGT_OS_windows
00205         vector<string> pyVer;
00206         try {
00207             pyVer = cmn_RegGetKeys("SOFTWARE\\Python\\PythonCore");
00208         }
00209         catch (...) {
00210             throw ivd_Error(ie_FILE_ERROR, "Python not installed.");
00211         }
00212         if (pyVer.size() == 0) {
00213             throw ivd_Error(ie_FILE_ERROR, "Python not installed.");
00214         }
00215         log_DBG_m(dbg_DETAIL, "python version: " << pyVer[pyVer.size()-1]);
00216         string pythonCmd;
00217         try {
00218             pythonCmd = cmn_RegGetValue(string("SOFTWARE\\Python\\PythonCore\\")
00219                                         + pyVer[pyVer.size()-1] + "\\InstallPath",
00220                                         "");
00221         }
00222         catch (...) {
00223             throw ivd_Error(ie_FILE_ERROR, "Cannot get Python install path.");
00224         }
00225         if (pythonCmd.empty()) {
00226             throw ivd_Error(ie_FILE_ERROR, "Cannot get Python install path.");
00227         }
00228         pythonCmd += "\\python.exe";
00229         log_DBG_m(dbg_DETAIL, "python executable: " << pythonCmd);
00230 #elif TGT_OS_hpux
00231         string pythonCmd("/usr/local/aCCPython/bin/python");
00232 
00233 #elif TGT_OS_linux
00234         string pythonCmd("/usr/bin/python");
00235 #endif
00236         UInt32_t flags;
00237         cmn_Path script = FindPy(a_script, flags);
00238 
00239         vector<string> argVec;
00240         argVec.push_back(script);
00241         for (UInt32_t i = 0; i < a_arg.length(); i++){
00242             string arg(a_arg[i]);
00243             argVec.push_back(arg);
00244         }
00245         // TODO: what to do with debugs for scripts? --dbg should be supported
00246 
00247         log_DBG_m(dbg_DETAIL, "Preparing to execute script: " << script);
00248 
00249         try {
00250             ret = cmn_ExecCommand(pythonCmd, argVec, flags);
00251         }
00252         catch (ivd_Exception &e) {
00253             ostringstream sstr;
00254             sstr << "ERROR: Cannot execute script " << script
00255                  << " (" << e.GetFriendly() << ").";
00256             log_WriteEvent(sstr.str());
00257             throw;
00258         }
00259     }
00260     ipc_CATCH_IVD_THROW_CORBA_m;
00261 
00262     return ret;
00263 }

Here is the call graph for this function:

i_UploadAgent_ptr i_Service_i::CreateUploadAgent ( i_DirectoryType_e  a_dtType,
const char *  a_relName 
)

Definition at line 266 of file i_svc_impl.cpp.

References ipc_CATCH_IVD_THROW_CORBA_m, and log_FUNC_A_m.

00266                                                                                                   {
00267 
00268     log_FUNC_A_m(CreateUploadAgent,
00269         "type: " << a_dtType << " name: " << a_relName
00270     );
00271 
00272     try {
00273         i_UploadAgent_i* upload = new i_UploadAgent_i(a_dtType, a_relName);
00274         i_UploadAgent_var uploadRef = upload->_this();
00275         upload->_remove_ref();
00276 
00277         return uploadRef._retn();
00278     }
00279     ipc_CATCH_IVD_THROW_CORBA_m;
00280 }

i_DownloadAgent_ptr i_Service_i::CreateDownloadAgent ( i_DirectoryType_e  a_dtType,
const char *  a_relName 
)

Definition at line 283 of file i_svc_impl.cpp.

References ipc_CATCH_IVD_THROW_CORBA_m, and log_FUNC_A_m.

00283                                                                                                       {
00284 
00285     log_FUNC_A_m(CreateDownloadAgent,
00286         "type: " << a_dtType << " name: " << a_relName
00287     );
00288 
00289     try {
00290         i_DownloadAgent_i* download = new i_DownloadAgent_i(a_dtType, a_relName);
00291         i_DownloadAgent_var downloadRef = download->_this();
00292         download->_remove_ref();
00293 
00294         return downloadRef._retn();
00295     }
00296     ipc_CATCH_IVD_THROW_CORBA_m;
00297 }

i_BackupAgent_ptr i_Service_i::CreateBackupAgent ( const char *  a_device,
const char *  a_pipe,
i_BlkSize_t  a_blkSize 
)

Definition at line 300 of file i_svc_impl.cpp.

References ipc_CATCH_IVD_THROW_CORBA_m, and log_FUNC_A_m.

00301                                                                      {
00302 
00303     log_FUNC_A_m(CreateBackupAgent,
00304         "dev: " << a_device << " pipe: " << a_pipe << " blksize: " << a_blkSize
00305     );
00306 
00307     try {
00308         i_BackupAgent_i* agent =
00309             new i_BackupAgent_i(a_device, a_pipe, a_blkSize);
00310 
00311         i_BackupAgent_var agentRef = agent->_this();
00312         agent->_remove_ref();
00313 
00314         return agentRef._retn();
00315     }
00316     ipc_CATCH_IVD_THROW_CORBA_m;
00317 }

i_RestoreAgent_ptr i_Service_i::CreateRestoreAgent ( const char *  a_device,
const char *  a_pipe,
i_BlkSize_t  a_blkSize 
)

Definition at line 320 of file i_svc_impl.cpp.

References ipc_CATCH_IVD_THROW_CORBA_m, and log_FUNC_A_m.

00321                                                                      {
00322 
00323     log_FUNC_A_m(CreateRestoreAgent,
00324         "dev: " << a_device << " pipe: " << a_pipe << " blksize: " << a_blkSize
00325     );
00326 
00327     try {
00328         i_RestoreAgent_i* agent =
00329             new i_RestoreAgent_i(a_device, a_pipe, a_blkSize);
00330 
00331         i_RestoreAgent_var agentRef = agent->_this();
00332         agent->_remove_ref();
00333 
00334         return agentRef._retn();
00335     }
00336     ipc_CATCH_IVD_THROW_CORBA_m;
00337 }

void i_Service_i::DeleteFile ( i_DirectoryType_e  a_dtType,
const char *  a_relName 
)

Definition at line 340 of file i_svc_impl.cpp.

References dbg_NORM, cmn_File::DeleteF(), cmn_Global::dirs, ivd_Directories::diskbuf, dt_DISKBUF, dt_ETC, dt_FRI, dt_LOG, dt_PART, dt_TMP, ivd_Directories::etc, file, ivd_Directories::fri, g_cmn, ie_INVALID_ARG, ipc_CATCH_IVD_THROW_CORBA_m, ivd_Directories::log, log_DBG_m, log_FUNC_A_m, ivd_Directories::part, and ivd_Directories::tmp.

00340                                                                               {
00341     log_FUNC_A_m(DeleteFile,
00342         "type: " << a_dtType << " name: " << a_relName
00343     );
00344 
00345     try {
00346 
00347         cmn_Path fileName;
00348         switch (a_dtType) {
00349             case dt_ETC: fileName = g_cmn.dirs.etc + a_relName; break;
00350             case dt_DISKBUF: fileName = g_cmn.dirs.diskbuf + a_relName; break;
00351             case dt_FRI: fileName = g_cmn.dirs.fri + a_relName; break;
00352             case dt_LOG: fileName = g_cmn.dirs.log + a_relName; break;
00353             case dt_PART: fileName = g_cmn.dirs.part + a_relName; break;
00354             case dt_TMP: fileName = g_cmn.dirs.tmp + a_relName; break;
00355             default: throw ivd_InternalError(
00356                 ie_INVALID_ARG, "Unsupported directory on delete.");
00357         }
00358 
00359         log_DBG_m(dbg_NORM, "About to delete file: " << fileName);
00360 
00361         cmn_File file(fileName);
00362         file.DeleteF();
00363 
00364     }
00365     ipc_CATCH_IVD_THROW_CORBA_m;
00366 }

Here is the call graph for this function:


Member Data Documentation

Reimplemented from i_Component_i.

Definition at line 56 of file i_svc_impl.h.


The documentation for this class was generated from the following files:

Generated on Mon Feb 27 19:40:33 2012 for OPENARCHIVE by  doxygen 1.5.6