//=============================================================================
// METHOD: SPELLlistenerContext::onNewContext
//=============================================================================
void SPELLlistenerContext::onNewContext( const SPELLipcMessage& msg )
{
    ContextInfo* ctxInfo;

    std::string ctxName = msg.get(MessageField::FIELD_CTX_NAME);

    ctxInfo = &m_openContexts[ctxName];
    ctxInfo->m_key = msg.getKey();
    ctxInfo->m_port = STRI(msg.get(MessageField::FIELD_CTX_PORT));
    ctxInfo->m_status = MessageValue::DATA_CTX_RUNNING;

    DEBUG("New context:");
    DEBUG("- Name=" + ctxInfo->m_name);
    DEBUG("- Key=" + ISTR(ctxInfo->m_key));
    DEBUG("- Port=" + ISTR(ctxInfo->m_port));
    DEBUG("- Status=" + ctxInfo->m_status);

    m_waitForContextStart.set();

    // Notify to other clients
    SPELLipcMessage notify( msg );
    notify.setId( ListenerMessages::MSG_CONTEXT_OP );
    notify.setType( MSG_TYPE_ONEWAY );
    notify.set( MessageField::FIELD_CTX_STATUS, MessageValue::DATA_CTX_RUNNING );
    notify.setSender("LST");
    notify.setReceiver("GUI");
    m_gui->displace(&notify);

    // Send notification to peer if any, and if alignment is enabled
    if (m_peer) m_peer->displace(msg);
}
//=============================================================================
// CONSTRUCTOR: SPELLlistenerContext::SPELLlistenerContext
//=============================================================================
SPELLlistenerContext::SPELLlistenerContext(const std::string& configFile)
{
    SPELLcontextConfig* ctxConfig;
    SPELLdriverConfig* drvConfig;
    ContextInfo ctxInfo;
    std::vector<std::string> ctxList;

    m_gui = NULL;
    m_peer = NULL;

    m_configFile = configFile;
    m_port = STRI(SPELLconfiguration::instance().getListenerParameter("ContextListenerPort"));
    m_contextStartupCmd = SPELLconfiguration::instance().getListenerParameter("ContextScript");

    ctxList = SPELLconfiguration::instance().getAvailableContexts();

    for(std::vector<std::string>::iterator it = ctxList.begin() ;
        it != ctxList.end() ;
        it++)
    {
		DEBUG("Loading context information for " + *it);

		ctxInfo.m_key = 0;
		ctxInfo.m_name = *it;
		ctxInfo.m_port = 0;
		ctxInfo.m_status = MessageValue::DATA_CTX_AVAILABLE;

		try
		{
			ctxConfig = &SPELLconfiguration::instance().getContext(ctxInfo.m_name);
			drvConfig = &SPELLconfiguration::instance().getDriver(ctxConfig->getDriverName());
			ctxInfo.m_ctxConfig = ctxConfig;
			ctxInfo.m_drvConfig = drvConfig;
		}
		catch(SPELLcoreException& ex)
		{
			LOG_ERROR("Failed to read context configuration");
			ctxInfo.m_ctxConfig = NULL;
			ctxInfo.m_drvConfig = NULL;
		}

		m_openContexts[ctxInfo.m_name] = ctxInfo;

		DEBUG("Added context:");
		DEBUG("- Name=" + ctxInfo.m_name);
		DEBUG("- Key=" + ISTR(ctxInfo.m_key));
		DEBUG("- Port=" + ISTR(ctxInfo.m_port));
		DEBUG("- Status=" + ctxInfo.m_status);
    }
}
示例#3
0
//=============================================================================
// METHOD    : SPELLwsStorage::loadObject
//=============================================================================
PyObject* SPELLwsStorage::loadObject()
{
	if (!m_file.is_open()) return NULL;
    if (m_mode == MODE_WRITE)
    {
        THROW_EXCEPTION("Unable to load object", "Initialized in write mode", SPELL_ERROR_WSTART);
    }

    // FORMAT IN FILE:
    // COUNT \1 PTYPE \1 MARSHAL LENGTH
    // MARSHAL

    std::string line = "";
    // Get first the line with the info
    while(!m_file.eof() && (line == ""))
    {
    	std::getline(m_file,line);
        DEBUG("Obtained line [" + line + "]");
    }

    DEBUG("Load object from line [" + line + "]");

    std::vector<std::string> elements = SPELLutils::tokenize(line,"\1");

    PyObject* obj = NULL;
    std::string ptype = elements[1];
	int marshal_len = STRI(elements[2]);
	DEBUG("Decoding object of type " + elements[1] + ", marshal length " + elements[2]);
	// Get the line with the marshal
	char buffer[4512];
	m_file.read(buffer,marshal_len);
	obj = (PyObject*) PyMarshal_ReadObjectFromString( buffer, marshal_len );
	DEBUG("Decoded: " + PYCREPR(obj));
	// Check that the unmarshal was ok
	SPELLpythonHelper::instance().checkError();

    m_opCounter++;
    m_trace << "[" << m_opCounter << "] LOAD (" << m_filename << ") " << PYREPR(obj) << " [ Type=" << PYREPR(PyObject_Type(obj)) << ", Marshal length=" + ISTR(marshal_len) + " ]" << std::endl;
    std::flush(m_trace);


    if (obj != NULL) Py_INCREF(obj);

    return obj;
}
示例#4
0
//============================================================================
// Parse program arguments
//============================================================================
int parseArgs( int argc, char** argv )
{
    int code;
    while( ( code = getopt(argc, argv, "wp:f:n:c:r:s:")) != -1)
    {
        switch(code)
        {
        case 'w':
            warm = 1;
            std::cout << "* Enable warmstart" << std::endl;
            break;
        case 'f':
            script = 1;
            procId = std::string(optarg);
            std::cout << "* Run script " << procId << std::endl;
            break;
        case 'r':
            recover = 1;
            persis = std::string(optarg);
            std::cout << "* Enable recovery with file " << persis << std::endl;
            break;
        case 'p':
            script = 0;
            procId = std::string(optarg);
            std::cout << "* Run procedure " << procId << std::endl;
            break;
        case 'n':
            context = std::string(optarg);
            break;
        case 'c':
            configFile = std::string(optarg);
            break;
        case 't':
            timeId = std::string(optarg);
            break;
        case 's':
            port = STRI(optarg);
            break;
        }
    }
    // We need proc id and context at least
    if (procId == "")
    {
        std::cerr << "Error: procedure/script and/or context identifier not provided" << std::endl;
        usage(argv);
        return 1;
    }
    if (port == 0)
    {
        std::cerr << "Error: no context port provided" << std::endl;
        usage(argv);
        return 1;
    }
    if (configFile == "")
    {
        std::cerr << "Error: configuration file not provided" << std::endl;
        usage(argv);
        return 1;
    }
    return 0;
}
示例#5
0
//=============================================================================
// METHOD    : SPELLcontroller::executeCommand()
//=============================================================================
void SPELLcontroller::executeCommand( const ExecutorCommand& cmd )
{
	// If a (repeatable) command is being executed, discard this one
	if (isCommandPending() &&
	    (cmd.id != CMD_ABORT) &&
	    (cmd.id != CMD_FINISH) &&
	    (cmd.id != CMD_INTERRUPT) &&
	    (cmd.id != CMD_PAUSE) &&
	    (cmd.id != CMD_CLOSE))
	{
		LOG_WARN("Discarding command " + cmd.id);
		return;
	}

	LOG_INFO("Now executing command " + cmd.id);

    startCommandProcessing();

    if (cmd.id == CMD_ABORT)
    {
        doAbort();
    }
    else if (cmd.id == CMD_FINISH)
    {
        doFinish();
    }
    else if (cmd.id == CMD_ACTION)
    {
        doUserAction();
    }
    else if (cmd.id == CMD_STEP)
    {
        doStep( false );
    }
    else if (cmd.id == CMD_STEP_OVER)
    {
        doStep( true );
    }
    else if (cmd.id == CMD_RUN)
    {
        doPlay();
    }
    else if (cmd.id == CMD_SKIP)
    {
        doSkip();
    }
    else if (cmd.id == CMD_GOTO)
    {
        if (cmd.earg == "line")
        {
            DEBUG("[C] Processing go-to-line " + cmd.arg);
            try
            {
                int line = STRI(cmd.arg);
                doGoto( line );
            }
            catch(...) {};
        }
        else if (cmd.earg == "label")
        {
            DEBUG("[C] Processing go-to-label " + cmd.arg);
            doGoto( cmd.arg );
        }
        else
        {
        	SPELLexecutor::instance().getCIF().error("Unable to process Go-To command, no target information", LanguageConstants::SCOPE_SYS );
        }
    }
    else if (cmd.id == CMD_PAUSE)
    {
        doPause();
    }
    else if (cmd.id == CMD_INTERRUPT)
    {
        doInterrupt();
    }
    else if (cmd.id == CMD_SCRIPT)
    {
    	/** \todo determine when to override */
        doScript(cmd.arg,false);
    }
    else if (cmd.id == CMD_CLOSE)
    {
        m_recover = false;
        m_reload = false;
        doClose();
    }
    else if (cmd.id == CMD_RELOAD)
    {
        doReload();
    }
    else if (cmd.id == CMD_RECOVER)
    {
        doRecover();
    }
    else
    {
        LOG_ERROR("[C] UNRECOGNISED COMMAND: " + cmd.id)
    }
	m_mailbox.commandProcessed();

	// The command has finished, release the dispatcher
	setCommandFinished();
	DEBUG("[C] Command execution finished " + cmd.id);

	//TEMPORARILY DISABLED: it creates deadlocks.
	// notifyCommandToCore( cmd.id );
}