void ElementsCtrlBase::OnReset( wxCommandEvent& )
{
  if( m_selels.size() == 0 )
    return;

  OptionalMessageDialog dlg(wxT("dlg_reset"), wxID_YES, wxID_NO); 
  dlg.add_button_yesno();
  wxString msg =  _("This fills default values on all properties (except rectangle) of selected elements:\n\n");
  for( cit_elements cit = m_selels.begin(); cit != m_selels.end(); ++cit )
    msg += (*cit)->name() + wxT("\n");

  msg += wxT("\n");
  msg += _("Proceed?");
  dlg.Create(0, msg, _("Reset properties?"));

  if( dlg.ShowModal() != wxID_YES )
    return;

  wxGetApp().hudfile()->set_modified();

  std::for_each(m_selels.begin(), m_selels.end(), std::mem_fun(&ElementBase::reset));

  wxGetApp().mainframe()->update_displayctrl();
  wxGetApp().mainframe()->update_propertiesctrl();
  wxGetApp().mainframe()->update_configpreview();
  // update item
  cit_indecies idit = m_selidx.begin();
  wxASSERT( m_selidx.size() == m_selels.size() );
  for( cit_elements elit = m_selels.begin(); elit != m_selels.end(); ++elit, ++idit )
    update_item(*idit, *elit);
}
Exemple #2
0
static map_val_t update_item (node_t *item, map_val_t expectation, map_val_t new_val) {
    map_val_t old_val = item->val;

    // If the item's value is DOES_NOT_EXIST it means another thread removed the node out from under us.
    if (EXPECT_FALSE(old_val == DOES_NOT_EXIST)) {
        TRACE("s2", "update_item: lost a race to another thread removing the item. retry", 0, 0);
        return DOES_NOT_EXIST; // retry
    }

    if (EXPECT_FALSE(expectation == CAS_EXPECT_DOES_NOT_EXIST)) {
        TRACE("s1", "update_item: the expectation was not met; the skiplist was not changed", 0, 0);
        return old_val; // failure
    }

    // Use a CAS and not a SWAP. If the CAS fails it means another thread removed the node or updated its
    // value. If another thread removed the node but it is not unlinked yet and we used a SWAP, we could
    // replace DOES_NOT_EXIST with our value. Then another thread that is updating the value could think it
    // succeeded and return our value even though it should return DOES_NOT_EXIST.
    if (old_val == SYNC_CAS(&item->val, old_val, new_val)) {
        TRACE("s1", "update_item: the CAS succeeded. updated the value of the item", 0, 0);
        return old_val; // success
    }
    TRACE("s2", "update_item: lost a race. the CAS failed. another thread changed the item's value", 0, 0);

    // retry
    return update_item(item, expectation, new_val); // tail call
}
bool ElementsCtrlBase::update_item( const ElementBase* const pel )
{
  // look for item index
  long idx = index_by_pointer(pel);
  if( idx == wxNOT_FOUND )
    return false;
  return update_item(idx, pel);
}
Exemple #4
0
/******************************************************************************
 *                                                                            *
 * Function: process_new_value                                                *
 *                                                                            *
 * Purpose: process new item value                                            *
 *                                                                            *
 * Parameters: item - item data                                               *
 *             value - new value of the item                                  *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments: for trapper poller process                                       *
 *                                                                            *
 ******************************************************************************/
void	process_new_value(DB_ITEM *item, AGENT_RESULT *value, time_t now)
{
	zabbix_log( LOG_LEVEL_DEBUG, "In process_new_value(%s)",
		item->key);

	if (0 == CONFIG_DBSYNCER_FORKS)
	{
		if (SUCCEED == add_history(item, value, now))
		{
			update_item(item, value, now);
			update_functions(item, now);
			update_triggers(item->itemid);
		}
		else
			update_item(item, value, now);
	}
	else
		dc_add_history(item, value, now);
}
void playlist_view_cache::get_colour(unsigned playlist, unsigned idx, int col, colourinfo & out)
{	
	playlist_cache * p_cache = get_item(playlist);
	if (idx >= 0 && idx < p_cache->get_count())
	{
		if (!p_cache->get_item(idx))
		{
			if (!update_item(playlist, idx)) return;
		}
		p_cache->get_item(idx)->get_item(col)->get_colour(out);
	}
}
COLORREF playlist_view_cache::get_colour(unsigned playlist, unsigned idx, int col, colour_type colour)
{	
	playlist_cache * p_cache = get_item(playlist);
	if (idx >= 0 && idx < p_cache->get_count())
	{
		if (!p_cache->get_item(idx))
		{
			if (!update_item(playlist, idx)) return 0x000000FF;
		}
		return p_cache->get_item(idx)->get_item(col)->get_colour(colour);
	}
	return 0x000000FF;
}
void playlist_view_cache::get_display_name(unsigned playlist, unsigned idx, int col, pfc::string_base & out)
{	
	playlist_cache * p_cache = get_item(playlist);
	if (idx >= 0 && idx < p_cache->get_count())
	{
		if (!p_cache->get_item(idx))
		{
			if (!update_item(playlist, idx)) {out.set_string("Error"); return;}
		}
		p_cache->get_item(idx)->get_item(col)->get_display(out); return;
	}
	out.set_string("Internal error - invalid playlist entry!");
}
void ShipGoalsDlg::update()
{
	int i;

	if (goalp) {
		for (i=0; i<ED_MAX_GOALS; i++)
			update_item(i);

		verify_orders();

	} else {
		object *ptr;

		ptr = GET_FIRST(&obj_used_list);
		while (ptr != END_OF_LIST(&obj_used_list)) {
			if (((ptr->type == OBJ_SHIP) || (ptr->type == OBJ_START)) && (ptr->flags[Object::Object_Flags::Marked])) {
				goalp = Ai_info[Ships[ptr->instance].ai_index].goals;
				for (i=0; i<ED_MAX_GOALS; i++)
					update_item(i, 1);
			}

			ptr = GET_NEXT(ptr);
		}

		ptr = GET_FIRST(&obj_used_list);
		while (ptr != END_OF_LIST(&obj_used_list)) {
			if (((ptr->type == OBJ_SHIP) || (ptr->type == OBJ_START)) && (ptr->flags[Object::Object_Flags::Marked])) {
				self_ship = ptr->instance;
				goalp = Ai_info[Ships[self_ship].ai_index].goals;
				verify_orders(self_ship);
			}

			ptr = GET_NEXT(ptr);
		}
	}
}
Exemple #9
0
/**
 * Received GUI update events sent by the Controller. Check if the
 * currently displayed screen template contains the tag, and update
 * if on screen if it does. If the current screen does not display the
 * tag, then do nothing
 *
 * @param tag   name of the variable to update
 * @param value value of the variable to update
 */
void GUI::receive_update(const char *tag,const void *value) {

  if(m_pause_display_updates) return;

  for(uint32_t n=0;n<screens_layout[current_screen].item_count;n++) {
    if(strcmp(tag,screens_layout[current_screen].items[n].text) == 0) {
      update_item(screens_layout[current_screen].items[n],value);

      // has to be in the GUI object, because we don't have access to current_screen outside it.
      if(screens_layout[current_screen].items[n].type == ITEM_TYPE_DELAY) {
        if(get_item_state_delay(screens_layout[current_screen].items[n]) == 0) {
          jump_to_screen(get_item_state_delay_destination(screens_layout[current_screen].items[n]));
        }
      }
    }
  }
}
Exemple #10
0
void GUI::process_key_up() {
	if(screens_layout[current_screen].items[selected_item].type == ITEM_TYPE_VARNUM) {
		uint8_t current = get_item_state_varnum(screens_layout[current_screen].items[selected_item]);

		int8_t val[1];
		val[0] = current+1;
		if(val[0] > 9) val[0] = 9;
		update_item(screens_layout[current_screen].items[selected_item],val);
		receive_gui_events.receive_gui_event("varnumchange",screens_layout[current_screen].items[selected_item].text);
		return;
	}


	if(selected_item == 1) return;
  last_selected_item = selected_item;
	selected_item--;
}
void ElementsCtrlBase::OnItemActivated( wxListEvent& ev )
{
  elements_type& els = selected_elements();
  indecies_type& idx = selected_indecies();
  ElementBase *pel = 0;
  cit_indecies idxit = idx.begin();
  for( it_elements it = els.begin(); it != els.end(); ++it, ++idxit )
  {
    (*it)->set_enabled( !(*it)->is_enabled() ); // toggle
    update_item(*idxit, *it);
  }
  wxGetApp().hudfile()->set_modified();
  // trigger update of other views relying on properties

  // propagate
  wxGetApp().mainframe()->OnPropertiesChanged();
}
Exemple #12
0
void GUI::process_key_down() {
	if(screens_layout[current_screen].items[selected_item].type == ITEM_TYPE_VARNUM) {
		uint8_t current = get_item_state_varnum(screens_layout[current_screen].items[selected_item]);

		int8_t val[1];
		val[0] = current-1;
		if(val[0] < 0) val[0] = 0;
		update_item(screens_layout[current_screen].items[selected_item],val);

		receive_gui_events.receive_gui_event("varnumchange",screens_layout[current_screen].items[selected_item].text);
		return;
	}

	if((selected_item+1) < screens_layout[current_screen].item_count) {
    last_selected_item = selected_item;
	  selected_item++;
	}
}
void ElementsCtrlBase::OnPaste( wxCommandEvent& )
{
  if( m_selels.size() == 0 || m_copyfrom == 0 )
    return;

  std::for_each(m_selels.begin(), m_selels.end(), std::bind2nd(std::mem_fun(&ElementBase::copy_from), m_copyfrom));

  wxGetApp().mainframe()->update_displayctrl();
  wxGetApp().mainframe()->update_propertiesctrl();
  wxGetApp().mainframe()->update_configpreview();
  // update item
  cit_indecies idit = m_selidx.begin();
  wxASSERT( m_selidx.size() == m_selels.size() );
  for( cit_elements elit = m_selels.begin(); elit != m_selels.end(); ++elit, ++idit )
    update_item(*idit, *elit);
  
  wxGetApp().hudfile()->set_modified();
}
void ElementsCtrlBase::update_items()
{
  for( int i=0; i < m_list->GetItemCount(); ++i )
    update_item(i);
}
Exemple #15
0
map_val_t sl_cas (skiplist_t *sl, map_key_t key, map_val_t expectation, map_val_t new_val) {
    TRACE("s1", "sl_cas: key %p skiplist %p", key, sl);
    TRACE("s1", "sl_cas: expectation %p new value %p", expectation, new_val);
    ASSERT((int64_t)new_val > 0);

    node_t *preds[MAX_LEVELS];
    node_t *nexts[MAX_LEVELS];
    node_t *new_item = NULL;
    int n = random_levels(sl);
    node_t *old_item = find_preds(preds, nexts, n, sl, key, ASSIST_UNLINK);

    // If there is already an item in the skiplist that matches the key just update its value.
    if (old_item != NULL) {
        map_val_t ret_val = update_item(old_item, expectation, new_val);
        if (ret_val != DOES_NOT_EXIST)
            return ret_val;

        // If we lose a race with a thread removing the item we tried to update then we have to retry.
        return sl_cas(sl, key, expectation, new_val); // tail call
    }

    if (EXPECT_FALSE(expectation != CAS_EXPECT_DOES_NOT_EXIST && expectation != CAS_EXPECT_WHATEVER)) {
        TRACE("s1", "sl_cas: the expectation was not met, the skiplist was not changed", 0, 0);
        return DOES_NOT_EXIST; // failure, the caller expected an item for the <key> to already exist
    }

    // Create a new node and insert it into the skiplist.
    TRACE("s3", "sl_cas: attempting to insert a new item between %p and %p", preds[0], nexts[0]);
    map_key_t new_key = sl->key_type == NULL ? key : (map_key_t)sl->key_type->clone((void *)key);
    new_item = node_alloc(n, new_key, new_val);

    // Set <new_item>'s next pointers to their proper values
    markable_t next = new_item->next[0] = (markable_t)nexts[0];
    for (int level = 1; level < new_item->num_levels; ++level) {
        new_item->next[level] = (markable_t)nexts[level];
    }

    // Link <new_item> into <sl> from the bottom level up. After <new_item> is inserted into the bottom level
    // it is officially part of the skiplist.
    node_t *pred = preds[0];
    markable_t other = SYNC_CAS(&pred->next[0], next, (markable_t)new_item);
    if (other != next) {
        TRACE("s3", "sl_cas: failed to change pred's link: expected %p found %p", next, other);

        // Lost a race to another thread modifying the skiplist. Free the new item we allocated and retry.
        if (sl->key_type != NULL) {
            nbd_free((void *)new_key);
        }
        nbd_free(new_item);
        return sl_cas(sl, key, expectation, new_val); // tail call
    }

    TRACE("s3", "sl_cas: successfully inserted a new item %p at the bottom level", new_item, 0);

    ASSERT(new_item->num_levels <= MAX_LEVELS);
    for (int level = 1; level < new_item->num_levels; ++level) {
        TRACE("s3", "sl_cas: inserting the new item %p at level %p", new_item, level);
        do {
            node_t *   pred = preds[level];
            ASSERT(new_item->next[level]==(markable_t)nexts[level] || new_item->next[level]==MARK_NODE(nexts[level]));
            TRACE("s3", "sl_cas: attempting to to insert the new item between %p and %p", pred, nexts[level]);

            markable_t other = SYNC_CAS(&pred->next[level], (markable_t)nexts[level], (markable_t)new_item);
            if (other == (markable_t)nexts[level])
                break; // successfully linked <new_item> into the skiplist at the current <level>
            TRACE("s3", "sl_cas: lost a race. failed to change pred's link. expected %p found %p", nexts[level], other);

            // Find <new_item>'s new preds and nexts.
            find_preds(preds, nexts, new_item->num_levels, sl, key, ASSIST_UNLINK);

            for (int i = level; i < new_item->num_levels; ++i) {
                markable_t old_next = new_item->next[i];
                if ((markable_t)nexts[i] == old_next)
                    continue;

                // Update <new_item>'s inconsistent next pointer before trying again. Use a CAS so if another thread
                // is trying to remove the new item concurrently we do not stomp on the mark it places on the item.
                TRACE("s3", "sl_cas: attempting to update the new item's link from %p to %p", old_next, nexts[i]);
                other = SYNC_CAS(&new_item->next[i], old_next, (markable_t)nexts[i]);
                ASSERT(other == old_next || other == MARK_NODE(old_next));

                // If another thread is removing this item we can stop linking it into to skiplist
                if (HAS_MARK(other)) {
                    find_preds(NULL, NULL, 0, sl, key, FORCE_UNLINK); // see comment below
                    return DOES_NOT_EXIST;
                }
            }
        } while (1);
    }

    // In case another thread was in the process of removing the <new_item> while we were added it, we have to
    // make sure it is completely unlinked before we return. We might have lost a race and inserted the new item
    // at some level after the other thread thought it was fully removed. That is a problem because once a thread
    // thinks it completely unlinks a node it queues it to be freed
    if (HAS_MARK(new_item->next[new_item->num_levels - 1])) {
        find_preds(NULL, NULL, 0, sl, key, FORCE_UNLINK);
    }

    return DOES_NOT_EXIST; // success, inserted a new item
}