コード例 #1
0
ファイル: utils.cpp プロジェクト: rogervictor/tws
void
tws::geoarray::load_geoarrays(std::map<std::string, geoarray_t>& arrays,
                              const std::string& input_file)
{
  arrays.clear();

  try
  {
    std::unique_ptr<rapidjson::Document> doc(tws::core::open_json_file(input_file));

    const rapidjson::Value& jarrays = (*doc)["arrays"];

    if(!jarrays.IsArray())
    {
      boost::format err_msg("error parsing input file '%1%': expected a vector of array metadata.");

      throw tws::parse_error() << tws::error_description((err_msg % input_file).str());
    }

    const rapidjson::SizeType nelements = jarrays.Size();

    for(rapidjson::SizeType i = 0; i != nelements; ++i)
    {
      const rapidjson::Value& jarray = jarrays[i];

      if(jarray.IsNull())
        continue;

      geoarray_t g_array = read_array_metadata(jarray);

      arrays.insert(std::make_pair(g_array.name, g_array));
    }
  }
  catch(...)
  {
    throw;
  }
  
}
コード例 #2
0
ファイル: many_pops.c プロジェクト: leocomitale/xppaut
int select_table()
{
 int i,j;
 Window temp=main_win;
 char *n[MAX_TAB],key[MAX_TAB],ch;
 for(i=0;i<NTable;i++){
   n[i]=(char *)malloc(25);
   key[i]='a'+i;
   sprintf(n[i],"%c: %s",key[i],my_table[i].name);
 }
 key[NTable]=0;  
 ch=(char)pop_up_list(&temp,"Table",n,key,NTable,12,0,10,0,
		       no_hint,info_pop,info_message);
   for(i=0;i<NTable;i++)free(n[i]);
  j=(int)(ch-'a');
  if(j<0||j>=NTable){
    err_msg("Not a valid table");
    return -1;
  }
  return j;

}
コード例 #3
0
ファイル: gmetad.c プロジェクト: bnicholes/monitor-core
static int
write_root_summary(datum_t *key, datum_t *val, void *arg)
{
   char *name, *type;
   char sum[256];
   char num[256];
   Metric_t *metric;
   int rc;
   struct type_tag *tt;

   name = (char*) key->data;
   metric = (Metric_t*) val->data;
   type = getfield(metric->strings, metric->type);

   /* Summarize all numeric metrics */
   tt = in_type_list(type, strlen(type));
   /* Don't write a summary for an unknown or STRING type. */
   if (!tt || (tt->type == STRING)) 
       return 0;

   /* We log all our sums in double which does not suffer from
      wraparound errors: for example memory KB exceeding 4TB. -twitham */
   sprintf(sum, "%.5f", metric->val.d);

   sprintf(num, "%u", metric->num);

   /* err_msg("Writing Overall Summary for metric %s (%s)", name, sum); */

   /* Save the data to a rrd file unless write_rrds == off */
	 if (gmetad_config.write_rrds == 0)
	     return 0;

   rc = write_data_to_rrd( NULL, NULL, name, sum, num, 15, 0, metric->slope);
   if (rc)
      {
         err_msg("Unable to write meta data for metric %s to RRD", name);
      }
   return 0;
}
コード例 #4
0
ファイル: xdeclare.c プロジェクト: catuss-a/raytracer
t_ram		*xdeclare(void)
{
  t_ram		*ram;

  ram = malloc(sizeof(*ram));
  if (ram == NULL)
    {
      err_msg("Critical error: ", 0, "Can't init XMap system.");
      exit(EXIT_FAILURE);
    }
  ram->next = NULL;
  ram->memory = NULL;
  ram->name = "Xmap root";
  debug(-1, "XMap System: No leak allowed", "");
  xmalloc(0, (char*)ram, INIT);
  xfree(ram, INIT);
  xfreedom(ram, INIT);
  xftmp(ram, INIT);
  showmem(INIT, ram);
  liveliness(ram, INIT);
  return (ram);
}
コード例 #5
0
ファイル: hasmntopt.c プロジェクト: AlexKordic/sandbox
int main (int argc, char **argv)
{
	FILE *fp;
	struct mnttab mp;
	int ret;

	if (argc != 2)
		err_quit ("Usage: hasmntopt mount_option");

	if ((fp = fopen ("/etc/mnttab", "r")) == NULL)
		err_msg ("Can't open /etc/mnttab");

	while ((ret = getmntent (fp, &mp)) == 0) {
		if (hasmntopt (&mp, argv [1]))
			printf ("%s\n", mp.mnt_mountp);
	}

	if (ret != -1)
		err_quit ("Bad /etc/mnttab file.\n");

	return (0);
}
コード例 #6
0
int main(int argc, char **argv) {

					//start of the address from argv
	char 			*ptr, **pptr;
	char 			str[INET_ADDRSTRLEN];
	struct hostent *hptr;

	while(--argc > 0) {

		ptr = *++argv;

		//gethostbyname is a function to get the ip from DNS - numeric tpye
		if((hptr = gethostbyname(ptr)) == NULL) {

			err_msg("gethostbyname error for host: %s: %s", ptr, hstrerror(h_errno));
			continue;
		}
		//This is the “official” name of the host.
		printf("official hostname: %s\r\n", hptr->h_name);

		//These are alternative names for the host, represented as a null-terminated vector of strings.
		for(pptr = hptr->h_aliases; *pptr != NULL; pptr++) {
			printf("\t alias: %s\r\n", *pptr);
		}


		//pointer to all known IPs for that DNS
		pptr = hptr->h_addr_list; // vector of addresses

		for( ; *pptr != NULL; pptr++) {

			printf("\t Addr %lu \r\n", hptr->h_addr);
			//AF_INET or AF_INET6 lattter is for IPV6
			printf("\t address :%s\r\n", Inet_ntop(hptr->h_addrtype, *pptr, str, sizeof(str)));
		}
	}

	exit(0);
}
コード例 #7
0
ファイル: cs_open1.c プロジェクト: AlexKordic/sandbox
static int cs_open (char *path, int oflag)
{
	int len;
	char buf [12];
	struct iovec iov [3];
	int pipe_fd [2];

	if (pipe (pipe_fd) == -1)
		err_msg ("pipe failed");

	switch (fork ()) {
		case -1:	
			err_msg ("fork failed");

		case 0:
			close (pipe_fd [0]);
			if (pipe_fd [1] != STDIN_FILENO) {
				if (dup2 (pipe_fd [1], STDIN_FILENO) != STDIN_FILENO)
					err_msg ("Can't dup2 stdin");
			}
			if (pipe_fd [1] != STDOUT_FILENO) {
				if (dup2 (pipe_fd [1], STDOUT_FILENO) != STDOUT_FILENO)
					err_msg ("Can't dup2 stdout");
			}

			execl ("./opend1", "opend", NULL);
			err_msg ("exec failed");

		default:
			close (pipe_fd [1]);

			snprintf (buf, 12, " %d", oflag);
			iov [0].iov_base = "open ";
			iov [0].iov_len = strlen ("open ");
			iov [1].iov_base = path;
			iov [1].iov_len = strlen (path);
			iov [2].iov_base = buf;
			iov [2].iov_len = strlen (buf) + 1;

			len = iov [0].iov_len + iov [1].iov_len + iov [2].iov_len;
			if (writev (pipe_fd [0], &iov [0], 3) != len)
				err_msg ("writev failed");

			return (recv_fd (pipe_fd [0]));
	}
}
コード例 #8
0
ファイル: break_chroot.c プロジェクト: AlexKordic/sandbox
int main (int argc, char **argv)
{
	struct stat buf1;
	struct stat buf2;

	if (argc != 2)
		err_quit ("Usage: break_chroot directory");

	if (chdir ("/") == -1)
		err_msg ("Can't chdir to /");

	if (chroot (argv [1]) == -1)
		err_msg ("Can't chroot to %s", argv [1]);

	for (;;) {
		if (stat (".", &buf1) == -1)
			err_msg ("Can't stat .");
		if (stat ("..", &buf2) == -1)
			err_msg ("Can't stat ..");

		if ((buf1.st_dev == buf2.st_dev) && (buf1.st_ino == buf2.st_ino))
			break;

		if (chdir ("..") == -1)
			err_msg ("Can't chdir to ..");
	}

	chroot (".");

	switch (fork ()) {
		case -1:
			err_msg ("Can't fork");
			break;

		case 0:
			execl ("/sbin/sh", "-sh", NULL);
			execl ("/bin/sh", "-sh", NULL);
			printf ("Can't find a shell - exiting.\n");
			_exit (0);

		default:
			break;
	}

	return (0);
}
コード例 #9
0
ファイル: vfstab.c プロジェクト: AlexKordic/sandbox
int main (int argc, char **argv)
{
	FILE *fp;
	struct vfstab vp;
	int ret;
	int i;

	if ((fp = fopen ("/etc/vfstab", "r")) == NULL)
		err_msg ("Can't open /etc/vfstab");

	if (argc == 1) {
		while ((ret = getvfsent (fp, &vp)) == 0)
			print_vfstab (&vp);

		if (ret != -1)
			err_quit ("Bad /etc/vfstab file.\n");
	}
	else {
		for (i = 1; argc-- > 1; i++) {
			switch (getvfsfile (fp, &vp, argv [i])) {
				case -1:
					rewind (fp);
					break;

				case 0:
					print_vfstab (&vp);
					rewind (fp);
					break;

				default:
					err_quit ("Bad /etc/vfstab file.\n");
					break;
			}
		}
	}

	return (0);
}
コード例 #10
0
static void handle_event(nge_event * e)
{
	switch (e->state_type) {
	case SERVICE_STATE_CHANGE:
		service_change(e->payload.service_state_change.service,
			       e->payload.service_state_change.is,
			       e->payload.service_state_change.state_name,
			       e->payload.service_state_change.percent_started,
			       e->payload.service_state_change.percent_stopped,
			       e->payload.service_state_change.service_type,
			       e->payload.service_state_change.hidden);
		return;
	case SYSTEM_STATE_CHANGE:
		sys_state(e->payload.system_state_change.system_state,
			  e->payload.system_state_change.runlevel);
		return;
	case ERR_MSG:
		err_msg(e->payload.err_msg.mt,
			e->payload.err_msg.file,
			e->payload.err_msg.func,
			e->payload.err_msg.line, e->payload.err_msg.message);
		return;
	case CONNECT:
		connected(e->payload.connect.pver,
			  e->payload.connect.initng_version);
		return;
	case DISCONNECT:
		disconnected();
		return;
	case SERVICE_OUTPUT:
		service_output(e->payload.service_output.service,
			       e->payload.service_output.process,
			       e->payload.service_output.output);
		return;
	default:
		return;
	}
}
コード例 #11
0
ファイル: network.c プロジェクト: hgn/ospfd
static int init_raw_4_socket(struct ospfd *ospfd)
{
	int fd, on = 1, ret, flags;

	fd = socket(AF_INET, SOCK_RAW, IPPROTO_OSPF);
	if (fd < 0) {
		err_sys("Failed to create raw IPPROTO_OSPF socket");
		return FAILURE;
	}

	ret = setsockopt(fd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on));
	if (ret < 0) {
		err_sys("Failed to set IP_HDRINCL socket option");
		return FAILURE;
	}

	ret = setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &on, sizeof(on));
	if (ret < 0) {
		err_sys("Failed to set IP_PKTINFO socket option");
		return FAILURE;
	}

	ret = join_router_4_multicast(fd);
	if (ret != SUCCESS) {
		err_msg("cannot join multicast groups");
		return FAILURE;
	}

	/* make socket non-blocking */
	if ((flags = fcntl(fd, F_GETFL, 0)) == -1)
		flags = 0;
	fcntl(fd, F_SETFL, flags | O_NONBLOCK);


	ospfd->network.fd = fd;

	return SUCCESS;
}
コード例 #12
0
ファイル: ithread.cpp プロジェクト: xubodong1994/test
IMutexLock::IMutexLock()
{
#ifdef  WIN32
  if (InitializeCriticalSectionAndSpinCount(&_M_mutex, 2000) != TRUE) {
    DeleteCriticalSection(&_M_mutex);
    std::cerr << "init critical section failed !" << std::endl;
  }
#elif defined(HAVE_PTHREAD)
  int       _ret_code = 0;
  if ((_ret_code = pthread_mutexattr_init(&_M_mutexattr)) != 0)
    std::cerr << "mutex attribute init failed !" << std::endl;
  if (_ret_code == 0)
    _ret_code = pthread_mutexattr_settype(&_M_mutexattr, PTHREAD_MUTEX_ERRORCHECK);
  if (_ret_code == 0)
    if ((_ret_code = pthread_mutex_init(&_M_mutex, &_M_mutexattr)) != 0)
      err_msg("pthread_mutex_init failed");

  if (_ret_code != 0) {
    (void)pthread_mutex_destroy(&_M_mutex);
    (void)pthread_mutexattr_destroy(&_M_mutexattr);
  }
#endif  // end of WIN32
}
コード例 #13
0
ファイル: grplib.c プロジェクト: OrbitalMechanic/sherpa
/* NONE
 * ----
 * Input parameters:
 *   numChans - number of channels in groupCol and qualCol
 *   groupCol - the GROUPING column
 *   qualCol  - the QUALITY column
 */
int grp_do_none(long numChans, short *groupCol, short *qualCol,
                dsErrList *errList){

    long ii;

    if((numChans <= 0) || !groupCol || !qualCol){
        if(errList)
            dsErrAdd(errList, dsDMGROUPBADPARAMERR, Accumulation,
                     Generic);
        else
            err_msg("ERROR: At least one input parameter has an "
                    "invalid value.\n");
        return(GRP_ERROR);
    }
    
    /* Reset all columns */
    for(ii = 0; ii < numChans; ii++){
        groupCol[ii] = GRP_BEGIN;
        qualCol[ii] = GRP_GOOD;
    }
    
    return(GRP_SUCCESS);
}
コード例 #14
0
ファイル: getprusage1.c プロジェクト: AlexKordic/sandbox
int main (int argc, char **argv)
{
	pid_t pid;
	prusage_t buf;
	int i;

	if (argc == 1) {
		if (getprusage (-1, &buf) == -1)
			err_msg ("getprusage failed");
		print_rusage (getpid (), &buf);
	}
	else {
		for (i = 1; i < argc; i++) {
			pid = atoi (argv [i]);
			if (getprusage (pid, &buf) == -1)
				err_ret ("getprusage failed");
			else
				print_rusage (pid, &buf);
		}
	}

	return (0);
}
コード例 #15
0
ファイル: put.c プロジェクト: rdavid42/ft_p
int					put(char *root, int *cs, char *cmd, int *id)
{
	int				fd;
	char			**cmd_args;
	int				len;
	int				ret;

	(void)root;
	cmd_args = ssplit(cmd, ' ');
	if (!check_errors(cs, cmd_args))
		return (0);
	ret = 0, send(*cs, (void *)&ret, sizeof(uint32_t), 0);
	if (!receive_file_header(cs, cmd_args, &len))
		return (afree(cmd_args), 0);
	if ((fd = open(cmd_args[1], O_RDWR | O_CREAT, 0644)) == -1)
		return (afree(cmd_args), err_msg(OPEN_ERR), 0);
	write_streaming_packets(cs, fd, &len, id);
	close(fd);
	afree(cmd_args);
	if (ret = 1, send(*cs, (void *)&ret, sizeof(uint32_t), 0) == -1)
		return (0);
	return (1);
}
コード例 #16
0
ファイル: udclient.c プロジェクト: yulingjie/Net
int main(int argc, const char *argv[])
{
    if(argc < 2)
    {
        err_msg("usage: udc <filepath>");
    }
    int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0); 
    struct sockaddr_un svraddr;
    bzero(&svraddr, sizeof(struct sockaddr_un));
    svraddr.sun_family = AF_LOCAL;
    memcpy(svraddr.sun_path, argv[1], strlen(argv[1]));
    connect(sockfd, (struct sockaddr*)&svraddr, sizeof(struct sockaddr*));

    char in_buf[MAXLINE];
    while(fgets(in_buf, MAXLINE, stdin) != NULL)
    {
        write(sockfd, in_buf, strlen(in_buf));
        bzero(in_buf, MAXLINE);
        read(sockfd, in_buf, MAXLINE);
        fprintf(stdout, "%s\n", in_buf);
    }
    return 0;
}
コード例 #17
0
ファイル: fit.C プロジェクト: ArnaudGastinel/jot-lib
int 
main(int argc, char *argv[])
{
   bool do_gauss_seidel = 0;

   if (argc == 2 && str_ptr(argv[1]) == str_ptr("-g"))
      do_gauss_seidel = 1;
   else if(argc != 1)
   {
      err_msg("Usage: %s [ -g ] < mesh.sm > mesh-fit.sm", argv[0]);
      return 1;
   }

   LMESHptr mesh = LMESH::read_jot_stream(cin);
   if (!mesh || mesh->empty())
      return 1; // didn't work

   fit(mesh, do_gauss_seidel);

   mesh->write_stream(cout);

   return 0;
}
コード例 #18
0
uint HeapRegionSeq::find_contiguous_from(uint from, uint num) {
  uint len = length();
  assert(num > 1, "use this only for sequences of length 2 or greater");
  assert(from <= len,
         err_msg("from: %u should be valid and <= than %u", from, len));

  uint curr = from;
  uint first = G1_NULL_HRS_INDEX;
  uint num_so_far = 0;
  while (curr < len && num_so_far < num) {
    if (at(curr)->is_empty()) {
      if (first == G1_NULL_HRS_INDEX) {
        first = curr;
        num_so_far = 1;
      } else {
        num_so_far += 1;
      }
    } else {
      first = G1_NULL_HRS_INDEX;
      num_so_far = 0;
    }
    curr += 1;
  }
  assert(num_so_far <= num, "post-condition");
  if (num_so_far == num) {
    // we found enough space for the humongous object
    assert(from <= first && first < len, "post-condition");
    assert(first < curr && (curr - first) == num, "post-condition");
    for (uint i = first; i < first + num; ++i) {
      assert(at(i)->is_empty(), "post-condition");
    }
    return first;
  } else {
    // we failed to find enough space for the humongous object
    return G1_NULL_HRS_INDEX;
  }
}
コード例 #19
0
// static
void LLFloaterReporter::uploadDoneCallback(const LLUUID &uuid, void *user_data, S32 result, LLExtStat ext_status) // StoreAssetData callback (fixed)
{
	LLUploadDialog::modalUploadFinished();

	LLResourceData* data = (LLResourceData*)user_data;

	if(result < 0)
	{
		LLSD args;
		args["REASON"] = std::string(LLAssetStorage::getErrorString(result));
		LLNotificationsUtil::add("ErrorUploadingReportScreenshot", args);

		std::string err_msg("There was a problem uploading a report screenshot");
		err_msg += " due to the following reason: " + args["REASON"].asString();
		llwarns << err_msg << llendl;
		return;
	}

	EReportType report_type = UNKNOWN_REPORT;
	if (data->mPreferredLocation == LLResourceData::INVALID_LOCATION)
	{
		report_type = COMPLAINT_REPORT;
	}
	else 
	{
		llwarns << "Unknown report type : " << data->mPreferredLocation << llendl;
	}

	LLFloaterReporter *self = getInstance();
	if (self)
	{
		self->mScreenID = uuid;
		llinfos << "Got screen shot " << uuid << llendl;
		self->sendReportViaLegacy(self->gatherReport());
		self->close();
	}
}
コード例 #20
0
ファイル: fpm_stub.c プロジェクト: ProyectoRRAP/LiveCode
/*
 * parse_netlink_msg
 */
void
parse_netlink_msg (char *buf, size_t buf_len)
{
  netlink_msg_ctx_t ctx_space, *ctx;
  struct nlmsghdr *hdr;
  int status;
  int len;

  ctx = &ctx_space;

  hdr = (struct nlmsghdr *) buf;
  len = buf_len;
  for (; NLMSG_OK (hdr, len); hdr = NLMSG_NEXT(hdr, len)) {

    netlink_msg_ctx_init(ctx);
    ctx->hdr = (struct nlmsghdr *) buf;

    switch (hdr->nlmsg_type) {

    case RTM_DELROUTE:
    case RTM_NEWROUTE:

      parse_route_msg(ctx);
      if (ctx->err_msg) {
	err_msg("Error parsing route message: %s", ctx->err_msg);
      }

      print_netlink_msg_ctx(ctx);
      break;

    default:
      trace(1, "Ignoring unknown netlink message - Type: %d", hdr->nlmsg_type);
    }

    netlink_msg_ctx_cleanup(ctx);
  }
}
コード例 #21
0
ファイル: sm2obj.cpp プロジェクト: QuLogic/jot-lib
int 
main(int argc, char *argv[])
{
   // -s option writes "simple" format, meaning faces are written as:
   //
   //   f 1 3 2
   //
   // instead of:
   //
   //   f 1//1 3//3 2//2

   bool do_simple = false;
   if (argc == 2 && string(argv[1]) == "-s") {
      do_simple = true;
   } else if (argc != 1) {
      err_msg("Usage: %s [ -s ] < input.sm > output.sm", argv[0]);
      return 1;
   }

   BMESHptr mesh = BMESH::read_jot_stream(cin);
   if (!mesh || mesh->empty())
      return 1; // didn't work

   if (Config::get_var_bool("JOT_RECENTER"))
      mesh->recenter();

   if (Config::get_var_bool("JOT_PRINT_MESH"))
      mesh->print();

   // write verts
   write_verts(*mesh, cout);

   // write faces
   write_faces(*mesh, cout, do_simple);

   return 0;
}
コード例 #22
0
ファイル: plab.cpp プロジェクト: shelan/jdk9-mirror
// Compute desired plab size and latch result for later
// use. This should be called once at the end of parallel
// scavenge; it clears the sensor accumulators.
void PLABStats::adjust_desired_plab_sz(uint no_of_gc_workers) {
  assert(ResizePLAB, "Not set");

  assert(is_object_aligned(max_size()) && min_size() <= max_size(),
         "PLAB clipping computation may be incorrect");

  if (_allocated == 0) {
    assert(_unused == 0,
           err_msg("Inconsistency in PLAB stats: "
                   "_allocated: "SIZE_FORMAT", "
                   "_wasted: "SIZE_FORMAT", "
                   "_unused: "SIZE_FORMAT,
                   _allocated, _wasted, _unused));

    _allocated = 1;
  }
  double wasted_frac    = (double)_unused / (double)_allocated;
  size_t target_refills = (size_t)((wasted_frac * TargetSurvivorRatio) / TargetPLABWastePct);
  if (target_refills == 0) {
    target_refills = 1;
  }
  size_t used = _allocated - _wasted - _unused;
  size_t recent_plab_sz = used / (target_refills * no_of_gc_workers);
  // Take historical weighted average
  _filter.sample(recent_plab_sz);
  // Clip from above and below, and align to object boundary
  size_t new_plab_sz = MAX2(min_size(), (size_t)_filter.average());
  new_plab_sz = MIN2(max_size(), new_plab_sz);
  new_plab_sz = align_object_size(new_plab_sz);
  // Latch the result
  if (PrintPLAB) {
    gclog_or_tty->print(" (plab_sz = " SIZE_FORMAT" desired_plab_sz = " SIZE_FORMAT") ", recent_plab_sz, new_plab_sz);
  }
  _desired_plab_sz = new_plab_sz;

  reset();
}
コード例 #23
0
ファイル: skin_meme.C プロジェクト: ArnaudGastinel/jot-lib
CWpt& 
SkinMeme::compute_update()
{
   static bool debug = ::debug || Config::get_var_bool("DEBUG_SKIN_UPDATE",false);

   // compute 3D vertex location WRT track simplex

   if (_is_sticky) {
      // this meme is supposed to follow the skeleton surface
      if (is_tracking()) {
         // it actually is following it
         return _update = skin_loc(track_simplex(), _bc, _h);
      }
      // supposed to follow, but has no track point: do nothing
      return _update = loc();
   }

   // this meme is not following the skeleton surface;
   // it computes its location via smooth subdivision.
   // but it may still track the closest point on the skeleton
   // surface to avoid penetrating inside the skeleton surface.

   if (vert()->parent() == 0)
      _update = loc();
   else
      _update = vert()->detail_loc_from_parent();
   track_to_target(_update);
   if (_non_penetrate && is_tracking()) {
      Wvec d = penetration_correction(_update, track_simplex(), _bc, _stay_out);
      if (debug && !d.is_null())
         err_msg("SkinMeme::compute_update: correcting penetration, level %d",
                 bbase()->subdiv_level());
      _update += d;
               
   }
   return _update;
}
コード例 #24
0
ファイル: wtss.cpp プロジェクト: e-sensing/wtss.cxx
std::vector<std::string> wtss::cxx::client::list_coverages() const
{

  rapidjson::Document doc;
  doc.Parse<0>(wtss::cxx::request(
    wtss::cxx::client::server_uri + "/list_coverages").c_str());

  if (doc.HasParseError())
  {
    boost::format err_msg("Error parsing requested document '%1%/list_coverages: %2%.");

    throw parse_error() << error_description(
      (err_msg % server_uri %doc.GetParseError()).str());
  }

  if (!doc.IsObject())
    throw parse_error() << error_description(
        "Invalid JSON document: expecting a object!");

  if (!doc.HasMember("coverages"))
    throw parse_error() << error_description(
        "Invalid JSON document: expecting a member named \"coverages\"!");

  const rapidjson::Value& j_coverages = doc["coverages"];

  if (!j_coverages.IsArray())
    throw parse_error() << error_description(
        "Invalid JSON document: member named \"coverages\" must be an array!");

  std::vector<std::string> result;

  for (rapidjson::Value::ConstValueIterator itr = j_coverages.Begin();
       itr != j_coverages.End(); ++itr)
    result.push_back(itr->GetString());

  return result;
}
コード例 #25
0
ファイル: server_manager.cpp プロジェクト: e-sensing/wtss.tl
void wtss::tl::server_manager::changeStatusServer(const QString &server_uri)
{
  QJsonDocument j_doc = loadSettings();
  QJsonObject j_object = j_doc.object();

  QJsonObject j_servers = j_object.find("servers").value().toObject();

  if(!j_servers.contains(server_uri))
  {
    boost::format err_msg("Could not find the server: %1%");
    throw out_of_range_exception()
        << error_description((err_msg % server_uri.toUtf8().data()).str());
  }

  QJsonObject j_server = j_servers.find(server_uri).value().toObject();

  bool active = j_server.find("active").value().toBool();
  j_server["active"] = !active;

  if(!active)
  {
    for(QJsonObject::iterator it = j_servers.begin(); it != j_servers.end(); ++it)
    {
      if(it.key() != server_uri)
      {
        QJsonObject j_sv = it.value().toObject();
        j_sv["active"] = QJsonValue(false);
        j_servers[it.key()] = j_sv;
      }
    }
  }

  j_servers[server_uri] = j_server;
  j_object["servers"] = j_servers;
  j_doc.setObject(j_object);
  saveSettings(j_doc);
}
コード例 #26
0
HeapWord*
G1BlockOffsetArray::forward_to_block_containing_addr_slow(HeapWord* q,
                                                          HeapWord* n,
                                                          const void* addr) {
  // We're not in the normal case.  We need to handle an important subcase
  // here: LAB allocation.  An allocation previously recorded in the
  // offset table was actually a lab allocation, and was divided into
  // several objects subsequently.  Fix this situation as we answer the
  // query, by updating entries as we cross them.

  // If the fist object's end q is at the card boundary. Start refining
  // with the corresponding card (the value of the entry will be basically
  // set to 0). If the object crosses the boundary -- start from the next card.
  size_t n_index = _array->index_for(n);
  size_t next_index = _array->index_for(n) + !_array->is_card_boundary(n);
  // Calculate a consistent next boundary.  If "n" is not at the boundary
  // already, step to the boundary.
  HeapWord* next_boundary = _array->address_for_index(n_index) +
                            (n_index == next_index ? 0 : N_words);
  assert(next_boundary <= _array->_end,
         err_msg("next_boundary is beyond the end of the covered region "
                 " next_boundary " PTR_FORMAT " _array->_end " PTR_FORMAT,
                 p2i(next_boundary), p2i(_array->_end)));
  if (addr >= gsp()->top()) return gsp()->top();
  while (next_boundary < addr) {
    while (n <= next_boundary) {
      q = n;
      oop obj = oop(q);
      if (obj->klass_or_null() == NULL) return q;
      n += block_size(q);
    }
    assert(q <= next_boundary && n > next_boundary, "Consequence of loop");
    // [q, n) is the block that crosses the boundary.
    alloc_block_work2(&next_boundary, &next_index, q, n);
  }
  return forward_to_block_containing_addr_const(q, n, addr);
}
コード例 #27
0
ファイル: mcopy.c プロジェクト: AlexKordic/sandbox
int main (int argc, char **argv)
{
	int src_fd;
	int dest_fd;
	char *src_ptr;
	char *dest_ptr;
	struct stat stat_buf;
	off_t len;

	if (argc != 3)
		err_quit ("Usage: mcopy src dest");

	if ((src_fd = open (argv [1], O_RDONLY)) == -1)
		err_msg ("Can't open source file %s", argv [1]);

	if (fstat (src_fd, &stat_buf) == -1)
		err_msg ("Can't fstat");
	len = stat_buf.st_size;

	if ((dest_fd = open (argv [2], O_RDWR | O_TRUNC | O_CREAT,
		FILE_PERMS)) == -1) {
		err_msg ("Can't open destination file %s", argv [2]);
	}

	if (ftruncate (dest_fd, len) == -1)
		err_msg ("Can't ftruncate");

	if ((src_ptr = mmap (0, len, PROT_READ, MAP_SHARED,
		src_fd, 0)) == MAP_FAILED) {
		err_msg ("Can't mmap source file");
	}

	if ((dest_ptr = mmap (0, len, PROT_WRITE, MAP_SHARED,
		dest_fd, 0)) == MAP_FAILED) {
		err_msg ("Can't mmap destination file");
	}

	close (src_fd);
	close (dest_fd);

	memcpy (dest_ptr, src_ptr, len);

	return (0);
}
コード例 #28
0
ファイル: process_xml.c プロジェクト: reznor/monitor-core
static int
endElement_CLUSTER(void *data, const char *el)
{
    xmldata_t *xmldata = (xmldata_t *) data;
    datum_t hashkey, hashval;
    datum_t *rdatum;
    hash_t *summary;
    Source_t *source;

    /* Only keep info on sources we are an authority on. */
    if (authority_mode(xmldata))
    {
        source = &xmldata->source;
        summary = xmldata->source.metric_summary;

        /* Release the partial sum mutex */
        pthread_mutex_unlock(source->sum_finished);

        hashkey.data = (void*) xmldata->sourcename;
        hashkey.size = strlen(xmldata->sourcename) + 1;

        hashval.data = source;
        /* Trim structure to the correct length. */
        hashval.size = sizeof(*source) - GMETAD_FRAMESIZE + source->stringslen;

        /* We insert here to get an accurate hosts up/down value. */
        rdatum = hash_insert( &hashkey, &hashval, xmldata->root);
        if (!rdatum) {
            err_msg("Could not insert source %s", xmldata->sourcename);
            return 1;
        }
        /* Write the metric summaries to the RRD. */
        hash_foreach(summary, finish_processing_source, data);
    }
    return 0;
}
コード例 #29
0
void AdaptiveFreeList<Chunk>::verify_stats() const {
  // The +1 of the LH comparand is to allow some "looseness" in
  // checking: we usually call this interface when adding a block
  // and we'll subsequently update the stats; we cannot update the
  // stats beforehand because in the case of the large-block BT
  // dictionary for example, this might be the first block and
  // in that case there would be no place that we could record
  // the stats (which are kept in the block itself).
  assert((_allocation_stats.prev_sweep() + _allocation_stats.split_births()
          + _allocation_stats.coal_births() + 1)   // Total Production Stock + 1
         >= (_allocation_stats.split_deaths() + _allocation_stats.coal_deaths()
             + (ssize_t)count()),                // Total Current Stock + depletion
         err_msg("FreeList " PTR_FORMAT " of size " SIZE_FORMAT
                 " violates Conservation Principle: "
                 "prev_sweep(" SIZE_FORMAT ")"
                 " + split_births(" SIZE_FORMAT ")"
                 " + coal_births(" SIZE_FORMAT ") + 1 >= "
                 " split_deaths(" SIZE_FORMAT ")"
                 " coal_deaths(" SIZE_FORMAT ")"
                 " + count(" SSIZE_FORMAT ")",
                 p2i(this), size(), _allocation_stats.prev_sweep(), _allocation_stats.split_births(),
                 _allocation_stats.split_births(), _allocation_stats.split_deaths(),
                 _allocation_stats.coal_deaths(), count()));
}
コード例 #30
0
ファイル: game_init.c プロジェクト: Protoxy-/LemIPC
int	first_step(t_util *util)
{
  int	pid;

  util->id = 0;
  util->shm_id = shmget(util->key, (sizeof(char) * (MAP_X * MAP_Y)),
			IPC_CREAT | SHM_R | SHM_W);
  util->msg_id = msgget(util->key, IPC_CREAT | SHM_R | SHM_W);
  util->sem_id = semget(util->key, 1, IPC_CREAT | SHM_R | SHM_W);
  if (util->shm_id == -1 || util->msg_id == -1 ||  util->sem_id == -1)
    return (err_msg(": the creation of a shared memory fail"));
  util->addr = shmat(util->shm_id, NULL, SHM_R | SHM_W);
  init_map(util);
  semctl(util->sem_id, 0, SETVAL, 1);
  pid = fork();
  if (pid != 0)
    {
      display(util->addr);
      return (1);
    }
  if (new_player(util) == -1)
    return (-1);
  return (1);
}