Ejemplo n.º 1
0
void UnitStateMgr::DropAction(UnitActionPriority priority)
{
    // Don't remove action with NONE priority - static
    if (priority < UNIT_ACTION_PRIORITY_IDLE)
        return;

    UnitActionStorage::iterator itr = m_actions.find(priority);

    if (itr != m_actions.end())
    {
        bool bActiveActionChanged = false;
        ActionInfo* oldInfo = CurrentState();
        UnitActionPtr oldAction = oldInfo ? oldInfo->Action() : UnitActionPtr();

        // if dropped current active state...
        if (oldInfo && itr->second.Action() == oldInfo->Action() && !oldInfo->HasFlag(ACTION_STATE_FINALIZED))
            bActiveActionChanged = true;

        // in first - erasing current action, if his active
        if (itr->second.Action() == m_oldAction)
            m_oldAction = UnitActionPtr(NULL);

        // Possible erasing by iterator more fast and logic, but by Key much more safe
        m_actions.erase(priority);

        // Finalized not ActionInfo, but real action (saved before), due to ActionInfo wrapper already deleted.
        if (bActiveActionChanged && oldAction)
        {
            DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "DropAction: %s finalize (direct) action %s", GetOwnerStr().c_str(), oldAction->Name());
            oldAction->Finalize(*GetOwner());
        }
        // in this point we delete last link to UnitActionPtr, after this UnitAction be auto-deleted...
    }
}
Ejemplo n.º 2
0
void UnitStateMgr::Update(uint32 diff)
{
    if (m_needReinit)
    {
        m_needReinit = false;
        InitDefaults(true);
    }

    ActionInfo* state = CurrentState();

    if (!m_oldAction)
        m_oldAction = state->Action();
    else if (m_oldAction && m_oldAction != state->Action())
    {
        if (ActionInfo* oldAction = GetAction(m_oldAction))
        {
            if (oldAction->HasFlag(ACTION_STATE_ACTIVE) &&
                !oldAction->HasFlag(ACTION_STATE_FINALIZED) &&
                !oldAction->HasFlag(ACTION_STATE_INTERRUPTED))
                oldAction->Interrupt(this);
        }
        // else do nothing - action be deleted without interrupt/finalize (may be need correct?)
        m_oldAction = state->Action();
    }

    if (!state->Update(this, diff))
    {
        DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "UnitStateMgr: %s finished action %s", GetOwnerStr().c_str(), state->TypeName());
        DropAction(state->priority);
    }
}
static void
destroy_import_chooser (GtkWidget *dialog, gpointer user_data)
{
	ActionInfo *info = (ActionInfo *) user_data;

	gtk_widget_destroy (dialog);
	info->callback (NULL, info->user_data);
	g_free (info);
}
Ejemplo n.º 4
0
static void
import_vpn_from_file_cb (GtkWidget *dialog, gint response, gpointer user_data)
{
	char *filename = NULL;
	ActionInfo *info = (ActionInfo *) user_data;
	GHashTableIter iter;
	gpointer key;
	NMVpnPluginUiInterface *plugin;
	NMConnection *connection = NULL;
	GError *error = NULL;

	if (response != GTK_RESPONSE_ACCEPT)
		goto out;

	filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
	if (!filename) {
		g_warning ("%s: didn't get a filename back from the chooser!", __func__);
		goto out;
	}

	g_hash_table_iter_init (&iter, plugins);
	while (!connection && g_hash_table_iter_next (&iter, &key, (gpointer *)&plugin)) {
		g_clear_error (&error);
		connection = nm_vpn_plugin_ui_interface_import (plugin, filename, &error);
	}

	if (connection)
		info->callback (connection, info->user_data);
	else {
		GtkWidget *err_dialog;
		char *bname = g_path_get_basename (filename);

		err_dialog = gtk_message_dialog_new (NULL,
		                                     GTK_DIALOG_DESTROY_WITH_PARENT,
		                                     GTK_MESSAGE_ERROR,
		                                     GTK_BUTTONS_OK,
		                                     _("Cannot import VPN connection"));
		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (err_dialog),
		                                 _("The file '%s' could not be read or does not contain recognized VPN connection information\n\nError: %s."),
		                                 bname, error ? error->message : "unknown error");
		g_free (bname);
		g_signal_connect (err_dialog, "delete-event", G_CALLBACK (gtk_widget_destroy), NULL);
		g_signal_connect (err_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
		gtk_widget_show_all (err_dialog);
		gtk_window_present (GTK_WINDOW (err_dialog));
	}

	g_clear_error (&error);
	g_free (filename);

out:
	gtk_widget_hide (dialog);
	gtk_widget_destroy (dialog);
	g_free (info);
}
Ejemplo n.º 5
0
void UnitStateMgr::PushAction(UnitActionId actionId, UnitActionPtr state, UnitActionPriority priority, eActionType restoreable)
{
    ActionInfo* oldInfo = CurrentState();
    UnitActionPriority _priority = oldInfo ? oldInfo->priority : UNIT_ACTION_PRIORITY_IDLE;

    // Only interrupt action, if not drop his below and action lower by priority
    if (oldInfo &&
        oldInfo->HasFlag(ACTION_STATE_ACTIVE) && 
        oldInfo->Id != actionId &&
        _priority < priority)
        oldInfo->Interrupt(this);

    if (_priority > UNIT_ACTION_PRIORITY_IDLE)
    {
        // Some speedup - testing - not need drop Idle/None actions
        DropAction(actionId, priority);
        DropAction(priority);
    }

    bool needInsert = true;

    if (restoreable != ACTION_TYPE_NONRESTOREABLE)
    {
        // Don't replace (only interrupt and reset!) restoreable actions
        UnitActionStorage::iterator itr = m_actions.find(priority);
        if (itr != m_actions.end())
        {
            if (itr->second.Id == actionId)
            {
                itr->second.Reset(this);
                needInsert = false;
            }
        }
    }

    if (needInsert)
        m_actions.insert(UnitActionStorage::value_type(priority,ActionInfo(actionId, state, priority, restoreable)));

    IncreaseCounter(actionId);
/*
    ActionInfo* newInfo = CurrentState();
    if (newInfo && newInfo != oldInfo)
    {
        if (!newInfo->HasFlag(ACTION_STATE_INITIALIZED))
            newInfo->Initialize(this);
    }
*/
}
Ejemplo n.º 6
0
bool ActionInfo::operator != (ActionInfo& val)
{
    return (Action() != val.Action());
};
Ejemplo n.º 7
0
UnitActionPtr UnitStateMgr::CurrentAction()
{
    ActionInfo* action = CurrentState();
    return action ? action->Action() : UnitActionPtr(NULL);
}