MicroStepper::MicroStepper(PinConfiguration* micro, PinConfiguration* basic, PinConfiguration::name_type s, 
	unsigned int delay_l_h, unsigned int delay_h_l, unsigned short steps, bool initially_locked) : 
basic_pins(basic), micro_pins(micro), name(s), delay_high_to_low(delay_h_l), delay_low_to_high(delay_l_h), number_of_steps(steps), locked(initially_locked) {

	display_name("Starting initial setup\n");
	basic_pins->update_pins();
	micro_pins->update_pins();
	display_name("initial setup finished\n");

}
void MicroStepper::set_micro_pins(PinConfiguration* pins) {

	if (!locked) {

		display_name("Setting micro pins\n");
		micro_pins = pins;
		micro_pins->update_pins();
		display_name("micro pins set\n");
	}
}
void MicroStepper::set_backward_direction() {
	
	if (!locked) {
		display_name("direction pin: ");
		basic_pins->set_pin_low("direction");
	}
}
void MicroStepper::do_step() {

	if (!locked) {

		for ( unsigned int i =0; i<number_of_steps; ++i ) {
			
			display_name("step pin: ");

			if (basic_pins->is_high("step")) {

				// delayMicroseconds(delay_high_to_low);

				basic_pins->flip_pin_state("step");

				// delayMicroseconds(delay_low_to_high);

				basic_pins->flip_pin_state("step");

			
			} else {

				// delayMicroseconds(delay_low_to_high);

				basic_pins->flip_pin_state("step");

				// delayMicroseconds(delay_high_to_low);

				basic_pins->flip_pin_state("step");

			}

		}
	}
}
Пример #5
0
void ActorView::Display(bool full_redraw)
{

 if(portrait_data != NULL && (full_redraw || update_display || Game::get_game()->is_original_plus_full_map()))
  {
   update_display = false;
   if(MD)
   {
     fill_md_background(area);
     screen->blit(area.x+1,area.y+16,portrait_data,8,portrait->get_portrait_width(),portrait->get_portrait_height(),portrait->get_portrait_width(), true);
   }
   else
   {
     screen->fill(bg_color, area.x, area.y, area.w, area.h);
     screen->blit(area.x,area.y+8,portrait_data,8,portrait->get_portrait_width(),portrait->get_portrait_height(),portrait->get_portrait_width(), false);
   }
   display_name();
   display_actor_stats();
   DisplayChildren(); //draw buttons
   screen->update(area.x, area.y, area.w, area.h);
  }

 if(show_cursor && cursor_tile != NULL)
  {
   screen->blit(cursor_pos.px, cursor_pos.py, (unsigned char *)cursor_tile->data,
                8, 16, 16, 16, true, NULL);
   screen->update(cursor_pos.px, cursor_pos.py, 16, 16);
  }

}
Пример #6
0
void CDropbox::RequestAccountInfo()
{
	MCONTACT hContact = CDropbox::GetDefaultContact();

	ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
	GetAccountInfoRequest request(token);
	NLHR_PTR response(request.Send(hNetlibConnection));
	HandleHttpResponseError(response);

	JSONNode root = JSONNode::parse(response->pData);
	if (root.empty())
		return;

	JSONNode referral_link = root.at("referral_link");
	if (!referral_link.empty())
		db_set_s(hContact, MODULE, "Homepage", referral_link.as_string().c_str());

	JSONNode display_name = root.at("display_name");
	if (!display_name.empty())
	{
		ptrT display_name(mir_utf8decodeT(display_name.as_string().c_str()));
		TCHAR *sep = _tcsrchr(display_name, _T(' '));
		if (sep)
		{
			db_set_ts(hContact, MODULE, "LastName", sep + 1);
			display_name[mir_tstrlen(display_name) - mir_tstrlen(sep)] = '\0';
			db_set_ts(hContact, MODULE, "FirstName", display_name);
		}
		else
		{
			db_set_ts(hContact, MODULE, "FirstName", display_name);
			db_unset(hContact, MODULE, "LastName");
		}
	}

	JSONNode country = root.at("country");
	if (!country.empty())
	{
		std::string isocode = country.as_string();

		if (isocode.empty())
			db_unset(hContact, MODULE, "Country");
		else
		{
			char *country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode.c_str(), 0);
			db_set_s(hContact, MODULE, "Country", country);
		}
	}

	JSONNode quota_info = root.at("quota_info");
	if (!quota_info.empty())
	{
		db_set_dw(hContact, MODULE, "SharedQuota", quota_info.at("shared").as_int());
		db_set_dw(hContact, MODULE, "NormalQuota", quota_info.at("normal").as_int());
		db_set_dw(hContact, MODULE, "TotalQuota", quota_info.at("quota").as_int());
	}
}
void MicroStepper::unsleep() {

	if (!locked) {
		display_name("sleep pin: ");
		basic_pins->set_pin_high("sleep");
	} else {
		sleep();
	}
}
void MicroStepper::lock() {

	if (!locked) {
		display_name("locked\n");
		locked = true;
	} else {
		unlock();
	}
}
void MicroStepper::unlock() {

	if (locked) {
		display_name("unlocked\n");
		locked = false;
	} else {
		lock();
	}
}
Пример #10
0
void StatsTreeDialog::fillTree()
{
    GString *error_string;
    if (!st_cfg_ || file_closed_) return;

    gchar* display_name_temp = stats_tree_get_displayname(st_cfg_->name);
    QString display_name(display_name_temp);
    g_free(display_name_temp);

    // The GTK+ UI appends "Stats Tree" to the window title. If we do the same
    // here we should expand the name completely, e.g. to "Statistics Tree".
    setWindowSubtitle(display_name);

    st_cfg_->pr = &cfg_pr_;
    cfg_pr_.st_dlg = this;

    if (st_) {
        stats_tree_free(st_);
    }
    st_ = stats_tree_new(st_cfg_, NULL, ui->displayFilterLineEdit->text().toUtf8().constData());

    // Add number of columns for this stats_tree
    QStringList headerLabels;
    for (int count = 0; count<st_->num_columns; count++) {
        headerLabels.push_back(stats_tree_get_column_name(count));
    }
    ui->statsTreeWidget->setColumnCount(headerLabels.count());
    ui->statsTreeWidget->setHeaderLabels(headerLabels);
    resize(st_->num_columns*80+80, height());
    for (int count = 0; count<st_->num_columns; count++) {
        headerLabels.push_back(stats_tree_get_column_name(count));
    }
    ui->statsTreeWidget->setSortingEnabled(false);

    error_string = register_tap_listener(st_cfg_->tapname,
                          st_,
                          st_->filter,
                          st_cfg_->flags,
                          resetTap,
                          stats_tree_packet,
                          drawTreeItems);
    if (error_string) {
        QMessageBox::critical(this, tr("%1 failed to attach to tap").arg(display_name),
                             error_string->str);
        g_string_free(error_string, TRUE);
        reject();
    }

    cf_retap_packets(cap_file_.capFile());
    drawTreeItems(st_);

    ui->statsTreeWidget->setSortingEnabled(true);
    remove_tap_listener(st_);

    st_cfg_->pr = NULL;
}
Пример #11
0
char *
plural_item_name(int item, int qty)
{
	char *s;

	if (qty == 1)
		return display_name(item);

	s = rp_item(item) ? rp_item(item)->plural_name : "";

	if (s == NULL || *s == '\0')
	{
		fprintf(stderr, "warning: plural name not set for "
				"item %s\n", box_code(item));
		s = display_name(item);
	}

	return s;
}
Пример #12
0
    Profile *ProfileManager::create_profile(const std::string &name)
    {
        auto find = s_profiles.find(name);
        if (find != s_profiles.end())
        {
            throw std::runtime_error("A profile with that name already exists");
        }

        auto new_profile = new Profile(name);
        new_profile->display_name(name);
        s_profiles[name] = std::unique_ptr<Profile>(new_profile);
        return new_profile;
    }
Пример #13
0
char *
just_name(int n)
{
	char *s;

	if (n == garrison_magic)
		return "Garrison";

	if (valid_box(n))
	{
		s = display_name(n);
		if (s && *s)
			return s;
	}

	return box_code(n);
}
Пример #14
0
static int setparam_display(struct param_opts *popt, char *pattern, char *value)
{
        int rc;
        int fd;
        int i;
        glob_t glob_info;
        char filename[PATH_MAX + 1];    /* extra 1 byte for file type */

        rc = glob(pattern, GLOB_BRACE, NULL, &glob_info);
        if (rc) {
                fprintf(stderr, "error: set_param: %s: %s\n",
                        pattern, globerrstr(rc));
                return -ESRCH;
        }
	for (i = 0; i  < glob_info.gl_pathc; i++) {
		char *valuename = NULL;

		if (popt->po_show_path) {
			if (strlen(glob_info.gl_pathv[i]) > sizeof(filename)-1)
				return -E2BIG;
			strncpy(filename, glob_info.gl_pathv[i],
				sizeof(filename));
			valuename = display_name(filename, 0);
			if (valuename)
				printf("%s=%s\n", valuename, value);
		}
		/* Write the new value to the file */
		fd = open(glob_info.gl_pathv[i], O_WRONLY);
		if (fd >= 0) {
			rc = write(fd, value, strlen(value));
			if (rc < 0)
				fprintf(stderr, "error: set_param: setting "
					"%s=%s: %s\n", glob_info.gl_pathv[i],
					value, strerror(errno));
			else
				rc = 0;
			close(fd);
		} else {
			fprintf(stderr, "error: set_param: %s opening %s\n",
				strerror(rc = errno), glob_info.gl_pathv[i]);
		}
	}

	globfree(&glob_info);
	return rc;
}
Пример #15
0
static int listparam_display(struct param_opts *popt, char *pattern)
{
        int rc;
        int i;
        glob_t glob_info;
        char filename[PATH_MAX + 1];    /* extra 1 byte for file type */

        rc = glob(pattern, GLOB_BRACE | (popt->po_recursive ? GLOB_MARK : 0),
                  NULL, &glob_info);
        if (rc) {
                fprintf(stderr, "error: list_param: %s: %s\n",
                        pattern, globerrstr(rc));
                return -ESRCH;
        }

        for (i = 0; i  < glob_info.gl_pathc; i++) {
                char *valuename = NULL;
                int last;

                /* Trailing '/' will indicate recursion into directory */
                last = strlen(glob_info.gl_pathv[i]) - 1;

                /* Remove trailing '/' or it will be converted to '.' */
                if (last > 0 && glob_info.gl_pathv[i][last] == '/')
                        glob_info.gl_pathv[i][last] = '\0';
                else
                        last = 0;
                strcpy(filename, glob_info.gl_pathv[i]);
                valuename = display_name(filename, popt->po_show_type);
                if (valuename)
                        printf("%s\n", valuename);
                if (last) {
                        strcpy(filename, glob_info.gl_pathv[i]);
                        strcat(filename, "/*");
                        listparam_display(popt, filename);
                }
        }

        globfree(&glob_info);
        return rc;
}
Пример #16
0
static gfarm_error_t
display_replica_catalog(char *path, struct gfs_stat *st, void *arg)
{
	gfarm_error_t e = GFARM_ERR_NO_ERROR;
	gfarm_mode_t mode;

	display_name(path, st, arg);

	mode = st->st_mode;
	if (GFARM_S_ISDIR(mode))
		e = GFARM_ERR_IS_A_DIRECTORY;
	else if (!GFARM_S_ISREG(mode))
		e = GFARM_ERR_FUNCTION_NOT_IMPLEMENTED;

	if (e == GFARM_ERR_NO_ERROR)
		e = display_copy(path);

	if (e != GFARM_ERR_NO_ERROR)
		fprintf(stderr, "%s\n", gfarm_error_string(e));
	return (e);
}
Пример #17
0
char *
box_name(int n)
{
	char *s;

	if (n == garrison_magic)
		return "Garrison";

	if (valid_box(n))
	{
		s = display_name(n);
		if (s && *s)
		{
		  if (options.output_tags > 0)
		    return sout("<tag type=box id=%d>%s~%s</tag type=box id=%d>",
				n,
				s, box_code(n),n);
		  else
		    return sout("%s~%s", s, box_code(n));
		}
	}

	return box_code(n);
}
Пример #18
0
void inventory_selector::print_right_column() const
{
    if (right_column_width == 0) {
        return;
    }
    player &u = g->u;
    int drp_line = 1;
    drop_map::const_iterator dit = dropping.find(-1);
    if (dit != dropping.end()) {
        std::string item_name = u.weapname();
        if (dit->second == -1) {
            item_name.insert(0, "+ ");
        } else {
            item_name = string_format("# %s {%d}", item_name.c_str(), dit->second);
        }
        const char invlet = invlet_or_space(u.weapon);
        trim_and_print(w_inv, drp_line, right_column_offset, right_column_width - 4, c_ltblue, "%c %s", invlet, item_name.c_str());
        drp_line++;
    }
    auto iter = u.worn.begin();
    for (size_t k = 0; k < u.worn.size(); k++, ++iter) {
        // worn items can not be dropped partially
        if (dropping.count(player::worn_position_to_index(k)) == 0) {
            continue;
        }
        const char invlet = invlet_or_space(*iter);
        trim_and_print(w_inv, drp_line, right_column_offset, right_column_width - 4, c_cyan, "%c + %s", invlet, iter->display_name().c_str());
        drp_line++;
    }
    for( const auto &elem : dropping ) {
        if( elem.first < 0 ) { // worn or wielded item, already displayed above
            continue;
        }
        const std::list<item> &stack = u.inv.const_stack( elem.first );
        const item &it = stack.front();
        const char invlet = invlet_or_space(it);
        const int count = elem.second;
        const int display_count = (count == -1) ? (it.charges >= 0) ? it.charges : stack.size() : count;
        const nc_color col = it.color_in_inventory();
        std::string item_name = it.tname( display_count );
        if (count == -1) {
            if (stack.size() > 1) {
                item_name = string_format("%d %s", stack.size(), item_name.c_str());
            } else {
                item_name.insert(0, "+ ");
            }
        } else {
            item_name = string_format("# %s {%d}", item_name.c_str(), count);
        }
        trim_and_print(w_inv, drp_line, right_column_offset, right_column_width - 2, col, "%c %s", invlet, item_name.c_str());
        drp_line++;
    }
}
Пример #19
0
void activity_handlers::make_zlave_finish( player_activity *act, player *p )
{
    static const int full_pulp_threshold = 4;

    auto items = g->m.i_at(p->pos());
    std::string corpse_name = act->str_values[0];
    item *body = NULL;

    for( auto it = items.begin(); it != items.end(); ++it ) {
        if( it->display_name() == corpse_name ) {
            body = &*it;
        }
    }

    if( body == NULL ) {
        add_msg(m_info, _("There's no corpse to make into a zombie slave!"));
        return;
    }

    int success = act->values[0];

    if( success > 0 ) {

        p->practice("firstaid", rng(2, 5));
        p->practice("survival", rng(2, 5));

        p->add_msg_if_player(m_good,
                             _("You slice muscles and tendons, and remove body parts until you're confident the zombie won't be able to attack you when it reainmates."));

        body->set_var( "zlave", "zlave" );
        //take into account the chance that the body yet can regenerate not as we need.
        if( one_in(10) ) {
            body->set_var( "zlave", "mutilated" );
        }

    } else {

        if( success > -20 ) {

            p->practice("firstaid", rng(3, 6));
            p->practice("survival", rng(3, 6));

            p->add_msg_if_player(m_warning,
                                 _("You hack into the corpse and chop off some body parts.  You think the zombie won't be able to attack when it reanimates."));

            success += rng(1, 20);

            if( success > 0 && !one_in(5) ) {
                body->set_var( "zlave", "zlave" );
            } else {
                body->set_var( "zlave", "mutilated" );
            }

        } else {

            p->practice("firstaid", rng(1, 8));
            p->practice("survival", rng(1, 8));

            int pulp = rng(1, full_pulp_threshold);

            body->damage += pulp;

            if( body->damage >= full_pulp_threshold ) {
                body->damage = full_pulp_threshold;
                body->active = false;

                p->add_msg_if_player(m_warning, _("You cut up the corpse too much, it is thoroughly pulped."));
            } else {
                p->add_msg_if_player(m_warning,
                                     _("You cut into the corpse trying to make it unable to attack, but you don't think you have it right."));
            }
        }
    }
}
Пример #20
0
static void describe(const char *arg, int last_one)
{
	unsigned char sha1[20];
	struct commit *cmit, *gave_up_on = NULL;
	struct commit_list *list;
	struct commit_name *n;
	struct possible_tag all_matches[MAX_TAGS];
	unsigned int match_cnt = 0, annotated_cnt = 0, cur_match;
	unsigned long seen_commits = 0;
	unsigned int unannotated_cnt = 0;

	if (get_sha1(arg, sha1))
		die(_("Not a valid object name %s"), arg);
	cmit = lookup_commit_reference(sha1);
	if (!cmit)
		die(_("%s is not a valid '%s' object"), arg, commit_type);

	n = find_commit_name(cmit->object.sha1);
	if (n && (tags || all || n->prio == 2)) {
		/*
		 * Exact match to an existing ref.
		 */
		display_name(n);
		if (longformat)
			show_suffix(0, n->tag ? n->tag->tagged->sha1 : sha1);
		if (dirty)
			printf("%s", dirty);
		printf("\n");
		return;
	}

	if (!max_candidates)
		die(_("no tag exactly matches '%s'"), sha1_to_hex(cmit->object.sha1));
	if (debug)
		fprintf(stderr, _("searching to describe %s\n"), arg);

	if (!have_util) {
		for_each_hash(&names, set_util, NULL);
		have_util = 1;
	}

	list = NULL;
	cmit->object.flags = SEEN;
	commit_list_insert(cmit, &list);
	while (list) {
		struct commit *c = pop_commit(&list);
		struct commit_list *parents = c->parents;
		seen_commits++;
		n = c->util;
		if (n) {
			if (!tags && !all && n->prio < 2) {
				unannotated_cnt++;
			} else if (match_cnt < max_candidates) {
				struct possible_tag *t = &all_matches[match_cnt++];
				t->name = n;
				t->depth = seen_commits - 1;
				t->flag_within = 1u << match_cnt;
				t->found_order = match_cnt;
				c->object.flags |= t->flag_within;
				if (n->prio == 2)
					annotated_cnt++;
			}
			else {
				gave_up_on = c;
				break;
			}
		}
		for (cur_match = 0; cur_match < match_cnt; cur_match++) {
			struct possible_tag *t = &all_matches[cur_match];
			if (!(c->object.flags & t->flag_within))
				t->depth++;
		}
		if (annotated_cnt && !list) {
			if (debug)
				fprintf(stderr, _("finished search at %s\n"),
					sha1_to_hex(c->object.sha1));
			break;
		}
		while (parents) {
			struct commit *p = parents->item;
			parse_commit(p);
			if (!(p->object.flags & SEEN))
				commit_list_insert_by_date(p, &list);
			p->object.flags |= c->object.flags;
			parents = parents->next;
		}
	}

	if (!match_cnt) {
		const unsigned char *sha1 = cmit->object.sha1;
		if (always) {
			printf("%s", find_unique_abbrev(sha1, abbrev));
			if (dirty)
				printf("%s", dirty);
			printf("\n");
			return;
		}
		if (unannotated_cnt)
			die(_("No annotated tags can describe '%s'.\n"
			    "However, there were unannotated tags: try --tags."),
			    sha1_to_hex(sha1));
		else
			die(_("No tags can describe '%s'.\n"
			    "Try --always, or create some tags."),
			    sha1_to_hex(sha1));
	}

	qsort(all_matches, match_cnt, sizeof(all_matches[0]), compare_pt);

	if (gave_up_on) {
		commit_list_insert_by_date(gave_up_on, &list);
		seen_commits--;
	}
	seen_commits += finish_depth_computation(&list, &all_matches[0]);
	free_commit_list(list);

	if (debug) {
		for (cur_match = 0; cur_match < match_cnt; cur_match++) {
			struct possible_tag *t = &all_matches[cur_match];
			fprintf(stderr, " %-11s %8d %s\n",
				prio_names[t->name->prio],
				t->depth, t->name->path);
		}
		fprintf(stderr, _("traversed %lu commits\n"), seen_commits);
		if (gave_up_on) {
			fprintf(stderr,
				_("more than %i tags found; listed %i most recent\n"
				"gave up search at %s\n"),
				max_candidates, max_candidates,
				sha1_to_hex(gave_up_on->object.sha1));
		}
	}

	display_name(all_matches[0].name);
	if (abbrev)
		show_suffix(all_matches[0].depth, cmit->object.sha1);
	if (dirty)
		printf("%s", dirty);
	printf("\n");

	if (!last_one)
		clear_commit_marks(cmit, -1);
}
Пример #21
0
void StatsTreeDialog::fillTree()
{
    GString *error_string;
    if (!st_cfg_) return;

    gchar* display_name_temp = stats_tree_get_displayname(st_cfg_->name);
    QString display_name(display_name_temp);
    g_free(display_name_temp);

    setWindowTitle(display_name + tr(" Stats Tree"));

    if (!cap_file_) return;

    if (st_cfg_->in_use) {
        QMessageBox::warning(this, tr("%1 already open").arg(display_name),
                             tr("Each type of tree can only be generated one at at time."));
        reject();
    }

    st_cfg_->in_use = TRUE;
    st_cfg_->pr = &cfg_pr_;
    cfg_pr_.st_dlg = this;

    if (st_) {
        stats_tree_free(st_);
    }
    st_ = stats_tree_new(st_cfg_, NULL, ui->displayFilterLineEdit->text().toUtf8().constData());

    // Add number of columns for this stats_tree
    QStringList headerLabels;
    for (int count = 0; count<st_->num_columns; count++) {
        headerLabels.push_back(stats_tree_get_column_name(count));
    }
    ui->statsTreeWidget->setColumnCount(headerLabels.count());
    ui->statsTreeWidget->setHeaderLabels(headerLabels);
    resize(st_->num_columns*80+80, height());
    for (int count = 0; count<st_->num_columns; count++) {
        headerLabels.push_back(stats_tree_get_column_name(count));
    }
    ui->statsTreeWidget->setSortingEnabled(false);

    error_string = register_tap_listener(st_cfg_->tapname,
                          st_,
                          st_->filter,
                          st_cfg_->flags,
                          resetTap,
                          stats_tree_packet,
                          drawTreeItems);
    if (error_string) {
        QMessageBox::critical(this, tr("%1 failed to attach to tap").arg(display_name),
                             error_string->str);
        g_string_free(error_string, TRUE);
        reject();
    }

    cf_retap_packets(cap_file_);
    drawTreeItems(st_);

    ui->statsTreeWidget->setSortingEnabled(true);
    remove_tap_listener(st_);

    st_cfg_->in_use = FALSE;
    st_cfg_->pr = NULL;
}
Пример #22
0
/**
 * Perform a read, write or just a listing of a parameter
 *
 * \param[in] popt		list,set,get parameter options
 * \param[in] pattern		search filter for the path of the parameter
 * \param[in] value		value to set the parameter if write operation
 * \param[in] mode		what operation to perform with the parameter
 *
 * \retval number of bytes written on success.
 * \retval -errno on error and prints error message.
 */
static int
param_display(struct param_opts *popt, char *pattern, char *value,
	      enum parameter_operation mode)
{
	int dir_count = 0;
	char **dir_cache;
	glob_t paths;
	char *opname = parameter_opname[mode];
	int rc, i;

	rc = cfs_get_param_paths(&paths, "%s", pattern);
	if (rc != 0) {
		rc = -errno;
		if (!popt->po_recursive) {
			fprintf(stderr, "error: %s: param_path '%s': %s\n",
				opname, pattern, strerror(errno));
		}
		return rc;
	}

	dir_cache = calloc(paths.gl_pathc, sizeof(char *));
	if (dir_cache == NULL) {
		rc = -ENOMEM;
		fprintf(stderr,
			"error: %s: allocating '%s' dir_cache[%zd]: %s\n",
			opname, pattern, paths.gl_pathc, strerror(-rc));
		goto out_param;
	}

	for (i = 0; i < paths.gl_pathc; i++) {
		char *param_name = NULL, *tmp;
		char pathname[PATH_MAX];
		struct stat st;
		int rc2;

		if (stat(paths.gl_pathv[i], &st) == -1) {
			fprintf(stderr, "error: %s: stat '%s': %s\n",
				opname, paths.gl_pathv[i], strerror(errno));
			if (rc == 0)
				rc = -errno;
			continue;
		}

		if (popt->po_only_dir && !S_ISDIR(st.st_mode))
			continue;

		param_name = display_name(paths.gl_pathv[i], &st, popt);
		if (param_name == NULL) {
			fprintf(stderr,
				"error: %s: generating name for '%s': %s\n",
				opname, paths.gl_pathv[i], strerror(ENOMEM));
			if (rc == 0)
				rc = -ENOMEM;
			continue;
		}

		/**
		 * For the upstream client the parameter files locations
		 * are split between under both /sys/kernel/debug/lustre
		 * and /sys/fs/lustre. The parameter files containing
		 * small amounts of data, less than a page in size, are
		 * located under /sys/fs/lustre and in the case of large
		 * parameter data files, think stats for example, are
		 * located in the debugfs tree. Since the files are split
		 * across two trees the directories are often duplicated
		 * which means these directories are listed twice which
		 * leads to duplicate output to the user. To avoid scanning
		 * a directory twice we have to cache any directory and
		 * check if a search has been requested twice.
		 */
		if (S_ISDIR(st.st_mode)) {
			int j;

			for (j = 0; j < dir_count; j++) {
				if (!strcmp(dir_cache[j], param_name))
					break;
			}
			if (j != dir_count) {
				free(param_name);
				param_name = NULL;
				continue;
			}
			dir_cache[dir_count++] = strdup(param_name);
		}

		switch (mode) {
		case GET_PARAM:
			/* Read the contents of file to stdout */
			if (S_ISREG(st.st_mode))
				read_param(paths.gl_pathv[i], param_name, popt);
			break;
		case SET_PARAM:
			if (S_ISREG(st.st_mode)) {
				rc2 = write_param(paths.gl_pathv[i],
						  param_name, popt, value);
				if (rc2 < 0 && rc == 0)
					rc = rc2;
			}
			break;
		case LIST_PARAM:
			if (popt->po_show_path)
				printf("%s\n", param_name);
			break;
		}

		/* Only directories are searched recursively if
		 * requested by the user */
		if (!S_ISDIR(st.st_mode) || !popt->po_recursive) {
			free(param_name);
			param_name = NULL;
			continue;
		}

		/* Turn param_name into file path format */
		rc2 = clean_path(popt, param_name);
		if (rc2 < 0) {
			fprintf(stderr, "error: %s: cleaning '%s': %s\n",
				opname, param_name, strerror(-rc2));
			free(param_name);
			param_name = NULL;
			if (rc == 0)
				rc = rc2;
			continue;
		}

		/* Use param_name to grab subdirectory tree from full path */
		tmp = strstr(paths.gl_pathv[i], param_name);

		/* cleanup paramname now that we are done with it */
		free(param_name);
		param_name = NULL;

		/* Shouldn't happen but just in case */
		if (tmp == NULL) {
			if (rc == 0)
				rc = -EINVAL;
			continue;
		}

		rc2 = snprintf(pathname, sizeof(pathname), "%s/*", tmp);
		if (rc2 < 0) {
			/* snprintf() should never an error, and if it does
			 * there isn't much point trying to use fprintf() */
			continue;
		}
		if (rc2 >= sizeof(pathname)) {
			fprintf(stderr, "error: %s: overflow processing '%s'\n",
				opname, pathname);
			if (rc == 0)
				rc = -EINVAL;
			continue;
		}

		rc2 = param_display(popt, pathname, value, mode);
		if (rc2 != 0 && rc2 != -ENOENT) {
			/* errors will be printed by param_display() */
			if (rc == 0)
				rc = rc2;
			continue;
		}
	}

	for (i = 0; i < dir_count; i++)
		free(dir_cache[i]);
	free(dir_cache);
out_param:
	cfs_free_param_data(&paths);
	return rc;
}
void windows_tap_adapter::configure(const configuration_type& configuration)
{
    if (::FlushIpNetTable(m_interface_index) != NO_ERROR)
    {
        // Not able to flush the ARP table.
        //
        // This is non fatal.
    }

    if (layer() == tap_adapter_layer::ip)
    {
        if (!configuration.ipv4.network_address)
        {
            throw boost::system::system_error(make_error_code(asiotap_error::invalid_ip_configuration));
        }

        if (!configuration.ipv4.remote_address)
        {
            throw boost::system::system_error(make_error_code(asiotap_error::invalid_ip_configuration));
        }

        DWORD len = 0;

        const unsigned int plen = configuration.ipv4.network_address->prefix_length();

        const boost::asio::ip::address_v4::bytes_type addr = configuration.ipv4.network_address->address().to_bytes();
        const uint32_t netmask = htonl(plen > 0 ? 0 - (1 << (32 - plen)) : 0xFFFFFFFF);
        const uint32_t network = htonl(configuration.ipv4.remote_address->to_ulong()) & netmask;

        uint8_t param[3 * sizeof(uint32_t)];

        // address
        std::memcpy(param, addr.data(), addr.size());
        // network
        std::memcpy(param + sizeof(uint32_t), &network, sizeof(uint32_t));
        // netmask
        std::memcpy(param + 2 * sizeof(uint32_t), &netmask, sizeof(uint32_t));

        if (!::DeviceIoControl(descriptor().native_handle(), TAP_IOCTL_CONFIG_TUN, param, sizeof(param), param, sizeof(param), &len, NULL))
        {
            throw boost::system::system_error(::GetLastError(), boost::system::system_category());
        }
    }
    else
    {
        if (configuration.ipv4.remote_address)
        {
            throw boost::system::system_error(make_error_code(asiotap_error::invalid_ip_configuration));
        }
    }

    if (configuration.ipv4.network_address)
    {
        try
        {
            // Depending on the TAP adapter version this may not be supported.
            m_route_manager.netsh_interface_ip_set_address(display_name(), *configuration.ipv4.network_address);
        }
        catch (const boost::system::system_error& ex)
        {
            if (ex.code() != executeplus::executeplus_error::external_process_failed)
            {
                throw;
            }
        }
    }

    if (configuration.ipv6.network_address)
    {
        try
        {
            // Depending on the TAP adapter version this may not be supported.
            m_route_manager.netsh_interface_ip_set_address(display_name(), *configuration.ipv6.network_address);
        }
        catch (const boost::system::system_error& ex)
        {
            if (ex.code() != executeplus::executeplus_error::external_process_failed)
            {
                throw;
            }
        }
    }
}
Пример #24
0
static int getparam_display(struct param_opts *popt, char *pattern)
{
        int rc;
        int fd;
        int i;
        char *buf;
        glob_t glob_info;
        char filename[PATH_MAX + 1];    /* extra 1 byte for file type */

        rc = glob(pattern, GLOB_BRACE, NULL, &glob_info);
        if (rc) {
                fprintf(stderr, "error: get_param: %s: %s\n",
                        pattern, globerrstr(rc));
                return -ESRCH;
        }

	buf = malloc(PAGE_CACHE_SIZE);
	for (i = 0; i  < glob_info.gl_pathc; i++) {
		char *valuename = NULL;

		memset(buf, 0, PAGE_CACHE_SIZE);
                /* As listparam_display is used to show param name (with type),
                 * here "if (only_path)" is ignored.*/
                if (popt->po_show_path) {
			if (strlen(glob_info.gl_pathv[i]) >
			    sizeof(filename)-1) {
				free(buf);
				return -E2BIG;
			}
			strncpy(filename, glob_info.gl_pathv[i],
				sizeof(filename));
                        valuename = display_name(filename, 0);
                }

                /* Write the contents of file to stdout */
                fd = open(glob_info.gl_pathv[i], O_RDONLY);
                if (fd < 0) {
                        fprintf(stderr,
                                "error: get_param: opening('%s') failed: %s\n",
                                glob_info.gl_pathv[i], strerror(errno));
                        continue;
                }

		do {
			rc = read(fd, buf, PAGE_CACHE_SIZE);
			if (rc == 0)
				break;
                        if (rc < 0) {
                                fprintf(stderr, "error: get_param: "
                                        "read('%s') failed: %s\n",
                                        glob_info.gl_pathv[i], strerror(errno));
                                break;
                        }
                        /* Print the output in the format path=value if the
                         * value contains no new line character or cab be
                         * occupied in a line, else print value on new line */
                        if (valuename && popt->po_show_path) {
                                int longbuf = strnchr(buf, rc - 1, '\n') != NULL
                                              || rc > 60;
                                printf("%s=%s", valuename, longbuf ? "\n" : buf);
                                valuename = NULL;
                                if (!longbuf)
                                        continue;
                                fflush(stdout);
                        }
                        rc = write(fileno(stdout), buf, rc);
                        if (rc < 0) {
                                fprintf(stderr, "error: get_param: "
                                        "write to stdout failed: %s\n",
                                        strerror(errno));
                                break;
                        }
                } while (1);
                close(fd);
        }

        globfree(&glob_info);
        free(buf);
        return rc;
}
Пример #25
0
void MTSendDlg::on_fromButton_clicked()
{
    // Select from Accounts in local wallet.
    //
    DlgChooser theChooser(this);
    theChooser.SetIsAccounts();
    // -----------------------------------------------
    mapIDName & the_map = theChooser.m_map;

    bool bFoundDefault = false;
    // -----------------------------------------------
    const int32_t acct_count = OTAPI_Wrap::GetAccountCount();
    // -----------------------------------------------
    for(int32_t ii = 0; ii < acct_count; ++ii)
    {
        //Get OT Acct ID
        QString OT_acct_id = QString::fromStdString(OTAPI_Wrap::GetAccountWallet_ID(ii));
        QString OT_acct_name("");
        // -----------------------------------------------
        if (!OT_acct_id.isEmpty())
        {
            if (!m_myAcctId.isEmpty() && (OT_acct_id == m_myAcctId))
                bFoundDefault = true;
            // -----------------------------------------------
            MTNameLookupQT theLookup;

            OT_acct_name = QString::fromStdString(theLookup.GetAcctName(OT_acct_id.toStdString()));
            // -----------------------------------------------
            the_map.insert(OT_acct_id, OT_acct_name);
        }
     }
    // -----------------------------------------------
    if (bFoundDefault && !m_myAcctId.isEmpty())
        theChooser.SetPreSelected(m_myAcctId);
    // -----------------------------------------------
    theChooser.setWindowTitle(tr("Select the Source Account"));
    // -----------------------------------------------
    if (theChooser.exec() == QDialog::Accepted)
    {
        qDebug() << QString("SELECT was clicked for AcctID: %1").arg(theChooser.m_qstrCurrentID);

        if (!theChooser.m_qstrCurrentID.isEmpty())
        {
            QString display_name("");
            QString from_button_text("");
            // -----------------------------------------
            m_myAcctId = theChooser.m_qstrCurrentID;
            // -----------------------------------------
            if (theChooser.m_qstrCurrentName.isEmpty())
                display_name = QString("");
            else
                display_name = theChooser.m_qstrCurrentName;
            // -----------------------------------------
            from_button_text = MTHome::FormDisplayLabelForAcctButton(m_myAcctId, display_name);
            // -----------------------------------------
            ui->fromButton->setText(from_button_text);
            // -----------------------------------------
            return;
        }
    }
    else
    {
      qDebug() << "CANCEL was clicked";
    }
    // -----------------------------------------------
    m_myAcctId = QString("");
    ui->fromButton->setText(tr("<Click to choose Account>"));
}