コード例 #1
0
ファイル: plugin_mgr.c プロジェクト: andreiw/polaris
dm_plugin_error_t
dm_pm_indicator_execute(const char *action)
{
	dm_plugin_t *dmpip;
	char *protocol = extract_protocol(action); /* memory allocated here */
	char *actionp = extract_action(action);
	dm_plugin_action_handle_impl_t *hip;

	dmpip = protocol_to_dm_plugin(protocol);
	dstrfree(protocol);

	if (dmpip != NULL) {

		if ((hip = lookup_handle_by_action(actionp)) == NULL) {
			if (bind_action_handle(dmpip, actionp,
			    (dm_plugin_action_handle_t *)&hip) != DMPE_SUCCESS)
				return (DMPE_FAILURE);
		}

		dm_assert(dmpip->state == DMPS_INITED);
		if (dmpip->ops->indicator_execute)
			return (dmpip->ops->indicator_execute(hip->handle));
	}

	return (DMPE_FAILURE);
}
コード例 #2
0
ファイル: plugin_mgr.c プロジェクト: andreiw/polaris
dm_plugin_error_t
dm_pm_update_fru(const char *action, dm_fru_t *frup)
{
	char *protocol = extract_protocol(action);	/* mem alloced here */
	char *actionp = extract_action(action);
	dm_plugin_t *dmpip;

	if (protocol == NULL) {
		log_warn("FRU update: Invalid protocol specified in action "
		    "`%s'\n", action);
		return (DMPE_FAILURE);
	}

	dmpip = protocol_to_dm_plugin(protocol);
	dstrfree(protocol);

	if (dmpip != NULL) {
		dm_assert(dmpip->state == DMPS_INITED);
		if (dmpip->ops->indicator_fru_update)
			return (dmpip->ops->indicator_fru_update(actionp,
			    frup));
	}

	return (DMPE_FAILURE);
}
コード例 #3
0
ファイル: Racr.cpp プロジェクト: cblakkan/racr
// ------------------------------------------------------------------------
// Main loop the program runs in while connected to the server.
// Receives, authenticates, sends confirmation, and executes actions from
// the server.
// ------------------------------------------------------------------------
int Racr::daemon(){
    char packet[PACKET_SIZE + 1];
    
    if( _state != CONNECTED ){
        return FAIL;
    }

    while( _ethernet_client.connected() ){
        if( _ethernet_client.available() ){
            // Packet read failed, flush stream and continue
            // (the continue will then check for connection status)
            if( !read_packet(packet) ){ 
                Serial.println("Read Failed");
                _ethernet_client.flush();
                continue;
            }

            // If authentication fails, skip ahead to next packet.
            if( !auth_packet(packet) ){
                Serial.println("Auth Failed");
                continue;
            }

            // If we can't tell the server we got the command,
            // do not execute the command!
            if( !send_confirmation(packet) ){
                Serial.println("Receipt confirmation failed");
                continue;
            }
            
            // Execute the given action.
            int action = extract_action(packet);
            int arg    = extract_arg(packet);
            (*_action_funcs[action])(arg);
        }
    }

    Serial.println("Connection died =(");
    _ethernet_client.stop();

    _state = CONNECTION_SHUTDOWN;
    return SUCCESS;
}
コード例 #4
0
//==========================================================================================================
// Create grammar from definitions in input file.
// Production are of the form:
// N -> A B C ...
//==========================================================================================================
void Grammar::read_grammar_file(string grammar_file) {
    ifstream file = ifstream(grammar_file);
    
    if(!file.is_open())
        throw string("File " + grammar_file + " not found");
        
    //------------------------------------------------------------------------------------------------------
    // For each production line extract the symbols and add a production
    //------------------------------------------------------------------------------------------------------
    for(string line; getline(file, line);) {
        if(trim(line, "//").empty()) continue; // Ignore comments and empty lines
        
        vector<Symbol> symbols;
        string action_name;
        
        // If an action is specified, a number sign will serve to separate between the production and it
        int split_pos = line.find_first_of('#');        
        extract_symbols(line.substr(0, split_pos), symbols);
                
        if(split_pos != string::npos)
            extract_action(line.substr(split_pos + 1), action_name);
        
        productions.push_back(Production(symbols, action_name));
    }
    
    //------------------------------------------------------------------------------------------------------
    // First production nonterminal considered the start symbol. If it is not START, add a production:
    // START -> FIRST-NONTERMINAL
    //------------------------------------------------------------------------------------------------------
    if(productions[0][0] == START) {
        if(productions[0].size() != 2)
            throw string("Expected production for START to have just one symbol on right hand side");
        if(not is_nonterminal(productions[0][1]))
            throw string("Expected production for START to have a nonterminal on the right hand side");
    }
    else {
        productions.push_front(Production({START, productions[0][0]}, ""));
    }

} // read_grammar_file()