Public Member Functions | Private Member Functions | Private Attributes

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.

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

Detailed Description

Definition at line 66 of file i_svc_impl.h.


Constructor & Destructor Documentation

i_Service_i::i_Service_i (  ) 

Definition at line 49 of file i_svc_impl.cpp.

                        {
    // add extra constructor code here
}

i_Service_i::~i_Service_i (  )  [virtual]

Definition at line 53 of file i_svc_impl.cpp.

References log_FUNC_m, and ipc_Corba::Shutdown().

Here is the call graph for this function:


Member Function Documentation

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

Definition at line 314 of file i_svc_impl.cpp.

References log_FUNC_A_m.

                                                                     {

    log_FUNC_A_m(CreateBackupAgent,
        "dev: " << a_device << " pipe: " << a_pipe << " blksize: " << a_blkSize
    );

    try {
        i_BackupAgent_i* agent =
            new i_BackupAgent_i(a_device, a_pipe, a_blkSize);

        i_BackupAgent_var agentRef = agent->_this();
        agent->_remove_ref();

        return agentRef._retn();
    }
    ipc_CATCH_IVD_THROW_CORBA_m;
}

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

Definition at line 297 of file i_svc_impl.cpp.

References log_FUNC_A_m.

                                                                                                      {

    log_FUNC_A_m(CreateDownloadAgent,
        "type: " << a_dtType << " name: " << a_relName
    );

    try {
        i_DownloadAgent_i* download = new i_DownloadAgent_i(a_dtType, a_relName);
        i_DownloadAgent_var downloadRef = download->_this();
        download->_remove_ref();

        return downloadRef._retn();
    }
    ipc_CATCH_IVD_THROW_CORBA_m;
}

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

Definition at line 334 of file i_svc_impl.cpp.

References log_FUNC_A_m.

                                                                     {

    log_FUNC_A_m(CreateRestoreAgent,
        "dev: " << a_device << " pipe: " << a_pipe << " blksize: " << a_blkSize
    );

    try {
        i_RestoreAgent_i* agent =
            new i_RestoreAgent_i(a_device, a_pipe, a_blkSize);

        i_RestoreAgent_var agentRef = agent->_this();
        agent->_remove_ref();

        return agentRef._retn();
    }
    ipc_CATCH_IVD_THROW_CORBA_m;
}

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

Definition at line 280 of file i_svc_impl.cpp.

References log_FUNC_A_m.

                                                                                                  {

    log_FUNC_A_m(CreateUploadAgent,
        "type: " << a_dtType << " name: " << a_relName
    );

    try {
        i_UploadAgent_i* upload = new i_UploadAgent_i(a_dtType, a_relName);
        i_UploadAgent_var uploadRef = upload->_this();
        upload->_remove_ref();

        return uploadRef._retn();
    }
    ipc_CATCH_IVD_THROW_CORBA_m;
}

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

Definition at line 354 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, ivd_Directories::log, log_DBG_m, log_FUNC_A_m, ivd_Directories::part, and ivd_Directories::tmp.

                                                                              {
    log_FUNC_A_m(DeleteFile,
        "type: " << a_dtType << " name: " << a_relName
    );

    try {

        cmn_Path fileName;
        switch (a_dtType) {
            case dt_ETC: fileName = g_cmn.dirs.etc + a_relName; break;
            case dt_DISKBUF: fileName = g_cmn.dirs.diskbuf + a_relName; break;
            case dt_FRI: fileName = g_cmn.dirs.fri + a_relName; break;
            case dt_LOG: fileName = g_cmn.dirs.log + a_relName; break;
            case dt_PART: fileName = g_cmn.dirs.part + a_relName; break;
            case dt_TMP: fileName = g_cmn.dirs.tmp + a_relName; break;
            default: throw ivd_InternalError(
                ie_INVALID_ARG, "Unsupported directory on delete.");
        }

        log_DBG_m(dbg_NORM, "About to delete file: " << fileName);

        cmn_File file(fileName);
        file.DeleteF();

    }
    ipc_CATCH_IVD_THROW_CORBA_m;
}

Here is the call graph for this function:

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

Definition at line 142 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, log_DBG_m, log_FUNC_m, log_WriteEvent(), and ivd_Directories::tmp.

                                                                                {

    CORBA::Long ret = 0;

    string deleteMountPoint;

    log_FUNC_m(Execute);
    log_DBG_m(dbg_DETAIL,"will exec: " << a_binary);
    try {
        UInt32_t flags;
        cmn_Path execThis = FindCmd(a_binary, flags);

        log_DBG_m(dbg_DETAIL, "Preparing to execute: " << execThis);

        vector<string> argVec;

        for (UInt32_t i = 0; i < a_arg.length(); i++){
            string arg(a_arg[i]);
            argVec.push_back(arg);
        }

        if ((a_binary == i_IVD) && (argVec.size()>2) &&
            (argVec[0].compare("--mount-recovery") == 0 || (argVec[0].compare("--umount-recovery") == 0)) &&
            (argVec[1].empty())) {
            // Special handling when called from recovery.
            string mountdir = argVec[2];
            replace(mountdir.begin(), mountdir.end(), '/', '_');
            argVec[1] = g_cmn.dirs.tmp + string("recovery") + mountdir;
            
            if (argVec[0].compare("--umount-recovery") == 0) {
                // Store path for delete after ExecCommand.
                deleteMountPoint = argVec[1];
            }
            else { // --mount
                cmn_CreatePathNoException(argVec[1]);
            }
        }
        else {

            // if we are running in debug -> pass debug to started program too
            if (g_cmn.dbg.GetArgLevel() != "") {
                argVec.push_back("--dbg");
                argVec.push_back(g_cmn.dbg.GetArgLevel());
                argVec.push_back(g_cmn.dbg.GetArgFile());
                argVec.push_back(g_cmn.dbg.GetArgFlags());
            }
        }

        try {
            ret = cmn_ExecCommand(execThis, argVec, flags);
        }
        catch (ivd_Exception &e) {
            ostringstream sstr;
            sstr << "ERROR: Cannot execute " << execThis
                 << " (" << e.GetFriendly() << ").";
            log_WriteEvent(sstr.str());
            throw;
        }
        if (!deleteMountPoint.empty()) {
            // Specall handling when called from recovery.
            cmn_File::DeleteDir(deleteMountPoint);
        }
    }
    ipc_CATCH_IVD_THROW_CORBA_m;

    return ret;
}

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 211 of file i_svc_impl.cpp.

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

                                                                                  {

    CORBA::Long ret = 0;

    log_FUNC_m(ExecutePy);
    log_DBG_m(dbg_DETAIL,"will exec script: " << a_script);
    try {
#if TGT_OS_windows
        vector<string> pyVer;
        try {
            pyVer = cmn_RegGetKeys("SOFTWARE\\Python\\PythonCore");
        }
        catch (...) {
            throw ivd_Error(ie_FILE_ERROR, "Python not installed.");
        }
        if (pyVer.size() == 0) {
            throw ivd_Error(ie_FILE_ERROR, "Python not installed.");
        }
        log_DBG_m(dbg_DETAIL, "python version: " << pyVer[pyVer.size()-1]);
        string pythonCmd;
        try {
            pythonCmd = cmn_RegGetValue(string("SOFTWARE\\Python\\PythonCore\\")
                                        + pyVer[pyVer.size()-1] + "\\InstallPath",
                                        "");
        }
        catch (...) {
            throw ivd_Error(ie_FILE_ERROR, "Cannot get Python install path.");
        }
        if (pythonCmd.empty()) {
            throw ivd_Error(ie_FILE_ERROR, "Cannot get Python install path.");
        }
        pythonCmd += "\\python.exe";
        log_DBG_m(dbg_DETAIL, "python executable: " << pythonCmd);
#elif TGT_OS_hpux
        string pythonCmd("/usr/local/aCCPython/bin/python");

#elif TGT_OS_linux
        string pythonCmd("/usr/bin/python");
#endif
        UInt32_t flags;
        cmn_Path script = FindPy(a_script, flags);

        vector<string> argVec;
        argVec.push_back(script);
        for (UInt32_t i = 0; i < a_arg.length(); i++){
            string arg(a_arg[i]);
            argVec.push_back(arg);
        }
        // TODO: what to do with debugs for scripts? --dbg should be supported

        log_DBG_m(dbg_DETAIL, "Preparing to execute script: " << script);

        try {
            ret = cmn_ExecCommand(pythonCmd, argVec, flags);
        }
        catch (ivd_Exception &e) {
            ostringstream sstr;
            sstr << "ERROR: Cannot execute script " << script
                 << " (" << e.GetFriendly() << ").";
            log_WriteEvent(sstr.str());
            throw;
        }
    }
    ipc_CATCH_IVD_THROW_CORBA_m;

    return ret;
}

Here is the call graph for this function:

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

Definition at line 100 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 Execute().

                                                                           {
    log_FUNC_m(FindCmd);

    UInt32_t i = 0;

    while ((allowedCmd[i].binary != i_SENTINEL) && !allowedCmd[i].path.empty()){
        if ( allowedCmd[i].binary == a_binary ) {
            log_DBG_m(dbg_DETAIL,
                "Found command:" <<
                allowedCmd[i].path << allowedCmd[i].fileName);
            a_flags = allowedCmd[i].flags;
            return allowedCmd[i].path
                + (string(allowedCmd[i].fileName) + svc_execPostfix);
        }
        i++;
    }
    log_DBG_m(dbg_LOW, "Can not execute unknown command: " << a_binary);
    throw ivd_InternalError(ie_INVALID_ARG, "Can not execute unknown command.");
}

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 121 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().

                                                                           {
    log_FUNC_m(FindPy);

    UInt32_t i = 0;

    while ((allowedPy[i].binary != i_SENTINEL) && !allowedPy[i].path.empty()) {
        if ( allowedPy[i].binary == a_script ) {
            log_DBG_m(dbg_DETAIL,
                "Found python script:" <<
                allowedPy[i].path << allowedPy[i].fileName);
            a_flags = allowedPy[i].flags;
            return allowedPy[i].path + string(allowedPy[i].fileName);
        }
        i++;
    }
    log_DBG_m(dbg_LOW, "Can not execute unknown Script: " << a_script);
    throw ivd_InternalError(ie_INVALID_ARG, "Can not execute unknown script.");
}

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from i_Component_i.

Definition at line 70 of file i_svc_impl.h.


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