示例#1
0
static void
append_block(struct sfs_fs *sfs, struct cache_inode *file, size_t size, uint32_t ino, const char *filename) {
    static_assert(SFS_LN_NBLKS <= SFS_L2_NBLKS);
    assert(size <= SFS_BLKSIZE);
    uint32_t nblks = file->nblks;
    struct inode *inode = &(file->inode);
    if (nblks >= SFS_LN_NBLKS) {
        open_bug(sfs, filename, "file is too big.\n");
    }
    if (nblks < SFS_L0_NBLKS) {
        inode->direct[nblks] = ino;
    }
    else if (nblks < SFS_L1_NBLKS) {
        nblks -= SFS_L0_NBLKS;
        update_cache(sfs, &(file->l1), &(inode->indirect));
        uint32_t *data = file->l1->cache;
        data[nblks] = ino;
    }
    else if (nblks < SFS_L2_NBLKS) {
        nblks -= SFS_L1_NBLKS;
        update_cache(sfs, &(file->l2), &(inode->db_indirect));
        uint32_t *data2 = file->l2->cache;
        update_cache(sfs, &(file->l1), &data2[nblks / SFS_BLK_NENTRY]);
        uint32_t *data1 = file->l1->cache;
        data1[nblks % SFS_BLK_NENTRY] = ino;
    }
    file->nblks ++;
    inode->size += size;
    inode->blocks ++;
}
示例#2
0
文件: memshare.c 项目: twik1/memshare
int check_proc_at_index(int index)
{
	proc_entry *entry = get_proc_at_index(index);
	int sem;

	/* Check if this entry has ever been seized or not */
	if (entry->key_active) {
		print(LOG_DEBUG, "key_active for index %d\n", index);
		/* get sem for the key */
		if ((sem = create_lock(entry->key_active, 0)) == -1) {
			print(LOG_ERR,
			      "Unable to create active lock in check_proc_at_index for key %d\n",
			      entry->key_active);
			return 0;
		}
		/* check if cache is updated with sem */
		if (mem_entry[index].active) {
			/* check if cache contains correct sem for the key */
			if (sem != mem_entry[index].active) {
				print(LOG_DEBUG,
				      "Cache and sem for key %d doesn't match, updating cache\n",
				      entry->key_active);
				update_cache(index, entry);
				/*mem_entry[index].active = sem; */
			}
		} else {
			print(LOG_DEBUG, "Cache empty update sem from key\n");
			/*mem_entry[index].active = sem; */
			update_cache(index, entry);
		}
		/* use sem in cache to check if active */
		if (try_lock1(mem_entry[index].active)) {
			if (!memcmp
			    (mem_entry[index].proc_name, entry->proc_name,
			     PROC_NAME_SIZE)) {
				print(LOG_DEBUG,
				      "Index %d is occupied by %s and active\n",
				      index, entry->proc_name);
			} else {
				print(LOG_DEBUG,
				      "Index %d is occupied by %s, cache is however outdated\n",
				      index, entry->proc_name);
				update_cache(index, entry);
			}
			return 1;
		} else {
			print(LOG_DEBUG,
			      "Index %d has been active but isn't any more, reset key_active\n",
			      index);
			free_index(index);
		}
	} else {
		print(LOG_DEBUG,
		      "Index %d has never been active (or released)\n", index);
	}
	return 0;
}
示例#3
0
/*********************************************************************
 * Process message Functions *
 *********************************************************************/
void process_arp_request(int sockfd, struct arp_msg *msg) {
	int i;
	struct arp_cache_entry cache_entry;

	bzero(&cache_entry, sizeof(cache_entry));

	cache_entry.connfd = sockfd;
	cache_entry.sll_ifindex = my_index;
	cache_entry.sll_hatype = msg->hrd;
	strcpy(cache_entry.ip, msg->sender_ip);
	for (i = 0; i < IF_HADDR; i++){
				cache_entry.mac[i] = msg->sender_mac[i];
	}

	cache_entry.isComplete = 1;
	cache_entry.isValid = 1;
	cache_entry.isLocal = 0;

	// Pertains to the request, insert new entry
	if (strcmp(my_ip, msg->target_ip) == 0 || isDest(msg->target_ip) ) {
		puts("----->ARP: DESTINATION.");
		if ((i = search_cache(msg->sender_ip) == -1)) {
			puts("----->ARP: I DO pertain to this request. Create new entry for this <senderIP, senderMAC>.\n");
			if (insert_entry(cache_entry) < 0) {
				perror("unable to insert cache entry.");
			}
		} else {
			puts("----->ARP: I DO pertain to this request. Update <senderIP, senderMAC>.\n");
			update_cache(i, msg);
		}
		// Send ARP reply
		msg->op = ARP_REP;
		for (i = 0; i < INET_ADDRSTRLEN; i ++) {
			msg->target_ip[i] = msg->sender_ip[i];
		}
		printf("Target ip:%s\n", msg->target_ip);
		for (i = 0; i < IF_HADDR; i++){
					msg->target_mac[i] = msg->sender_mac[i];
		}
		strcpy(msg->sender_ip, my_ip);
		for (i = 0; i < IF_HADDR; i++){
					msg->sender_mac[i] = if_hwaddr[my_index][i];
		}
		puts("----->ARP: I'm responsible for sending reply...");
		send_arp_msg(sockfd, msg->target_mac, msg);
		puts("----->ARP: Reply sent.\n");

	} else if ((i = search_cache(msg->sender_ip) != -1)) { // There is an existing entry, update
		puts("----->ARP: I'm not pertain to this request, but I have an existing entry, updating...\n");
		update_cache(i, msg);
	}
}
示例#4
0
 /** Gets the value associated with the key. returns true on success.. */
 std::pair<bool, ValueType> get(const KeyType &key) const {
   // figure out who owns the key
   size_t hashvalue = hasher(key);
   size_t owningmachine = hashvalue % rpc.dc().numprocs();
   
   std::pair<bool, ValueType> ret;
   // if I own the key, get it from the map table
   if (owningmachine == rpc.dc().procid()) {
     datalock.lock();
     typename map_type::const_iterator iter = data.find(key);    
     if (iter == data.end()) {
       ret.first = false;
     }
     else {
       ret.first = true;
       ret.second = iter->second;
     }
     datalock.unlock();
   }
   else {
     ret = rpc.remote_request(owningmachine, 
                              &caching_dht<KeyType,ValueType>::get, 
                              key);
     if (ret.first) update_cache(key, ret.second);
     else invalidate(key);
   }
   return ret;
 }
示例#5
0
int main(int argc, char* argv[])
{
  PGMemoRequest pgmr;
  zmqcpp::Socket socket(ZMQ_REP);
  bson::Document pgmconf = parse_config(argv[1]);
  zmqcpp::Message msg;
  std::string reply;
  if (pgmconf.field_names().count("zmq_bind"))
    socket.bind(pgmconf["zmq_bind"].data<std::string>());
  else if (pgmconf.field_names().count("zmq_connect"))
    socket.connect(pgmconf["zmq_connect"].data<std::string>());
  else
  {
    std::cerr << "No valid zmq_connect or zmq_bind configuration directive found; bailing" << std::endl;
    exit(1);
  }
  
  while (true)
  {
    socket.recv(msg);
    pgmr.ParseFromString(msg.last());
    msg.clear();
    memo_query(pgmr, pgmconf);
    pgmr.SerializeToString(&reply);
    socket.send(zmqcpp::Message(reply));
    if(pgmr.cached() && pgmr.refresh())
      update_cache(pgmr, pgmconf);
  }
  return 0;
}
示例#6
0
static void
ez_psu_process_save(struct ez_psu_save *psave, 
		    struct xcl_context *xc,
		    struct NL *nlp,
		    const char *lang)
{
  struct ez_psu p;
  memset(&p,'\0',sizeof(struct ez_psu));
  p.lang = (char*)lang;
  if (ez_psu_parse(psave,&p))
    return;

  /* for +=, add the PSU spec to the relevant ngrams list */
  if (*p.operator == '+')
    {
      struct form *fp = new_persistent_form();
      nl_set_location(file, psave->lnum);
      parse_ngram_line(nlp, 
		       (char*)ez_psu_create_input(&p), 
		       nlp->nngrams, nlp->owner, NULL);
      ++nlp->nngrams;
      /* then create a form structure and add it to the cache */
      fp->lang = p.lang;
      fp->file = (char*)file;
      fp->lnum = psave->lnum;
      lemparse(p.lemma,fp);
      update_cache(xc,fp);
    }
  else
    {
      /* for =, find the form structure in cache or dictionary and
	 clone it so we can add the new information
       */
    }
}
void
camel_groupwise_journal_transfer (CamelGroupwiseJournal *groupwise_journal, CamelGroupwiseFolder *source_folder,
				  CamelMimeMessage *message,  const CamelMessageInfo *mi,
				  const char *original_uid, char **transferred_uid,
				  CamelException *ex)
{
	CamelOfflineJournal *journal = (CamelOfflineJournal *) groupwise_journal;
	CamelGroupwiseStore *gw_store= CAMEL_GROUPWISE_STORE(journal->folder->parent_store) ;
	CamelGroupwiseJournalEntry *entry;
	char *uid;

	if (!update_cache (groupwise_journal, message, mi, &uid, ex))
		return;

	entry = g_new (CamelGroupwiseJournalEntry, 1);
	entry->type = CAMEL_GROUPWISE_JOURNAL_ENTRY_APPEND;
	entry->uid = uid;
	entry->original_uid = g_strdup (original_uid);
	entry->source_container = g_strdup (camel_groupwise_store_container_id_lookup (gw_store, ((CamelFolder *)source_folder)->name));

	e_dlist_addtail (&journal->queue, (EDListNode *) entry);

	if (transferred_uid)
		*transferred_uid = g_strdup (uid);
}
示例#8
0
文件: showimage.c 项目: cmatei/GCX
/*
 * an expose event to our image window
 * we only handle the i channel for now
 */
gboolean image_expose_cb(GtkWidget *widget, GdkEventExpose *event, gpointer window)
{
	struct map_cache *cache;
	struct image_channel *i_channel;
	struct map_geometry *geom;
	void *ret;

	extern void draw_sources_hook(GtkWidget *darea,
				      GtkWidget *window, GdkRectangle *area);


	ret = g_object_get_data(G_OBJECT(window), "map_cache");
	if (ret == NULL) /* no map cache, we don;t have a frame to display */
		return TRUE;
	cache = ret;

	ret = g_object_get_data(G_OBJECT(window), "i_channel");
	if (ret == NULL) /* no channel */
		return TRUE;
	i_channel = ret;
	if (i_channel->fr == NULL) /* no frame */
		return TRUE;

	ret = g_object_get_data(G_OBJECT(window), "geometry");
	if (ret == NULL) /* no geometry */
		return TRUE;
	geom = ret;

	if ((!i_channel->color && cache->type != MAP_CACHE_GRAY) ||
		(i_channel->color && cache->type != MAP_CACHE_RGB)) {
//		d3_printf("expose: other cache type\n");
		if (cache->dat)
			free(cache->dat);
		cache->cache_valid = 0;
	} else if (cache->zoom != geom->zoom) {
//		d3_printf("expose: other cache zoom\n");
		cache->cache_valid = 0;
	} else if (i_channel->channel_changed) {
//		d3_printf("expose: other channel\n");
		cache->cache_valid = 0;
		i_channel->channel_changed = 0;
	} else if (!area_in_cache(&(event->area), cache)) {
//		d3_printf("expose: other area\n");
		cache->cache_valid = 0;
	}
	if (!cache->cache_valid) {
		update_cache(cache, geom, i_channel, &(event->area));
	}
	if (cache->cache_valid) {
//		d3_printf("cache valid, area is %d by %d starting at %d, %d\n",
//			  cache->w, cache->h, cache->x, cache->y);
//		d3_printf("expose: from cache\n");
		if (cache->type == MAP_CACHE_GRAY)
			paint_from_gray_cache(widget, cache, &(event->area));
		else
			paint_from_rgb_cache(widget, cache, &(event->area));
	}
	draw_sources_hook(widget, window, &(event->area));
	return TRUE;
}
示例#9
0
static gboolean
try_query_info (GVfsBackend *backend,
                GVfsJobQueryInfo *job,
                const char *filename,
                GFileQueryInfoFlags flags,
                GFileInfo *info,
                GFileAttributeMatcher *matcher)
{
  if (is_root (filename))
  {
    GIcon *icon;
    
    g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY);
    g_file_info_set_name (info, "/");
    g_file_info_set_display_name (info, g_vfs_backend_get_display_name (backend));
    g_file_info_set_content_type (info, "inode/directory");
    icon = g_vfs_backend_get_icon (backend);
    if (icon != NULL)
      g_file_info_set_icon (info, icon);
    g_vfs_job_succeeded (G_VFS_JOB (job));
  }
  else
    update_cache (G_VFS_BACKEND_AFP_BROWSE (backend), G_VFS_JOB (job)->cancellable,
                  query_info_cb, job);
  
  return TRUE;
}
void TyplWrap::update_cache(size_t esize)
{
	try {
		update_cache(entry_, esize);
	} catch (std::exception &e) {
		E2promErrMsg(e.what());
	}
}
示例#11
0
static void
on_setting_changed(HippoConnection *connection,
                   const char      *key,
                   const char      *value,
                   void            *data)
{
    HippoSettings *settings = HIPPO_SETTINGS(data);
    
    update_cache(settings, key, value);
}
示例#12
0
文件: indent.cpp 项目: drb27/ecc
    indent& indent::operator--(int)
    {
	indentLevel--;

	assert(indentLevel>=0);
	if (indentLevel<0)
	    indentLevel=0;

	update_cache();
	return *this;
    }
示例#13
0
void restore_variables_for_loadstate()
{
	u32 oldpc;
	
	oldpc=(u32)m6502_pc;
	
	#if MOVIEPLAYER
	update_cache();
	build_chr_decode();
	#else
	rebankswitch();
	#endif
	
	lastbank= memmap_tbl[ (((u32)m6502_pc) & PRG_BANK_MASK) / (1024*PRG_BANK_SIZE)];
	m6502_pc= (u8*)((u32)oldpc+(u32)lastbank);
	m6502_s=(u8*)((u32)m6502_s+(u32)NES_RAM);
	
	cpustate[1]=(u32)memmap_tbl;
	
	ppustat_=ppustat_savestate;
	vramaddr = vramaddr_dummy;
	
	_pcmstart=(u8*) ((u32)_pcmstart+(u32)PCMWAV);
	_pcmcurrentaddr=(u8*) ((u32)_pcmcurrentaddr+(u32)PCMWAV);

	decode_timeouts();
	//Old versions used a Scanlines counter, and state of "CPU cycles" register 
	//had a negitive number to indicate how many cycles past the scanline start we were at.
	//Now we use a positive number indicating how many cycles are left until the next timeout.
	if (!(blocks_loaded & BLOCK_TIME))
	{
		if ((_cpu_cycles/0x100) <= 0)
		{
			_cpu_cycles += _cycles_to_run * 256;
		}
	}
	
	//we added the irq_time_add variable to mapper 4 (MMC3), set this if it's zero.
	if (mapper_number == 4)
	{
		if (mapperstate[3] == 0) //irq_time_add, this may be 0 in old savestates, change to 12
		{
			mapperstate[3] = 12;
		}
	}
	//If we didn't load sound state, then make these default changes:
	//disable Frame IRQ, and enable all sound channels.
	//Fixme: need to load old SND0 sound state correctly.
	if (!(blocks_loaded & BLOCK_SND1))
	{
		_frame_mode = 0x80;
		_channel_enables = 0x0F;
	}
}
示例#14
0
/*
 * db_set --
 *	Store a line in the file.
 *
 * PUBLIC: int db_set __P((SCR *, db_recno_t, CHAR_T *, size_t));
 */
int
db_set(SCR *sp, db_recno_t lno, CHAR_T *p, size_t len)
{
	DBT data, key;
	EXF *ep;
	const char *fp;
	size_t flen;

#if defined(DEBUG) && 0
	vtrace(sp, "replace line %lu: len %lu {%.*s}\n",
	    (u_long)lno, (u_long)len, MIN(len, 20), p);
#endif
	/* Check for no underlying file. */
	if ((ep = sp->ep) == NULL) {
		ex_emsg(sp, NULL, EXM_NOFILEYET);
		return (1);
	}
	if (ep->l_win && ep->l_win != sp->wp) {
		ex_emsg(sp, NULL, EXM_LOCKED);
		return 1;
	}
		
	/* Log before change. */
	log_line(sp, lno, LOG_LINE_RESET_B);

	INT2FILE(sp, p, len, fp, flen);

	/* Update file. */
	memset(&key, 0, sizeof(key));
	key.data = &lno;
	key.size = sizeof(lno);
	memset(&data, 0, sizeof(data));
	data.data = __UNCONST(fp);
	data.size = flen;
	if ((sp->db_error = ep->db->put(ep->db, NULL, &key, &data, 0)) != 0) {
		msgq(sp, M_DBERR, "006|unable to store line %lu", (u_long)lno);
		return (1);
	}

	/* Flush the cache, update line count, before screen update. */
	update_cache(sp, LINE_RESET, lno);

	/* File now dirty. */
	if (F_ISSET(ep, F_FIRSTMODIFY))
		(void)rcv_init(sp);
	F_SET(ep, F_MODIFIED);

	/* Log after change. */
	log_line(sp, lno, LOG_LINE_RESET_F);

	/* Update screen. */
	return (scr_update(sp, lno, LINE_RESET, 1));
}
示例#15
0
static int
lupdate(lua_State *L) {
	lua_getfield(L, LUA_REGISTRYINDEX, PROXYCACHE);
	lua_pushvalue(L, 1);
	// PROXYCACHE, table
	if (lua_rawget(L, -2) != LUA_TUSERDATA) {
		luaL_error(L, "Invalid proxy table %p", lua_topointer(L, 1));
	}
	struct proxy * p = lua_touserdata(L, -1);
	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
	const char * newdata = lua_touserdata(L, 2);
	update_cache(L, p->data, newdata);
	return 1;
}
示例#16
0
/*
 * db_delete --
 *	Delete a line from the file.
 *
 * PUBLIC: int db_delete __P((SCR *, db_recno_t));
 */
int
db_delete(SCR *sp, db_recno_t lno)
{
	DBT key;
	EXF *ep;

#if defined(DEBUG) && 0
	vtrace(sp, "delete line %lu\n", (u_long)lno);
#endif
	/* Check for no underlying file. */
	if ((ep = sp->ep) == NULL) {
		ex_emsg(sp, NULL, EXM_NOFILEYET);
		return (1);
	}
	if (ep->l_win && ep->l_win != sp->wp) {
		ex_emsg(sp, NULL, EXM_LOCKED);
		return 1;
	}
		
	/* Update marks, @ and global commands. */
	if (line_insdel(sp, LINE_DELETE, lno))
		return 1;

	/* Log before change. */
	log_line(sp, lno, LOG_LINE_DELETE_B);

	/* Update file. */
	memset(&key, 0, sizeof(key));
	key.data = &lno;
	key.size = sizeof(lno);
	if ((sp->db_error = ep->db->del(ep->db, NULL, &key, 0)) != 0) {
		msgq(sp, M_DBERR, "003|unable to delete line %lu", 
		    (u_long)lno);
		return (1);
	}

	/* Flush the cache, update line count, before screen update. */
	update_cache(sp, LINE_DELETE, lno);

	/* File now modified. */
	if (F_ISSET(ep, F_FIRSTMODIFY))
		(void)rcv_init(sp);
	F_SET(ep, F_MODIFIED);

	/* Log after change. */
	log_line(sp, lno, LOG_LINE_DELETE_F);

	/* Update screen. */
	return (scr_update(sp, lno, LINE_DELETE, 1));
}
示例#17
0
 /// Sets the key to the value
 void set(const KeyType& key, const ValueType &newval)  {
   size_t hashvalue = hasher(key);
   size_t owningmachine = hashvalue % rpc.dc().numprocs();
   if (owningmachine == rpc.dc().procid()) {
     datalock.lock();
     data[key] = newval;
     datalock.unlock();
   }
   else {
     rpc.remote_call(owningmachine, 
                     &caching_dht<KeyType,ValueType>::set, 
                     key,
                     newval);
     update_cache(key, newval);
   }
 }
示例#18
0
文件: madns.c 项目: mischasan/madns
void   *
madns_response(MADNS * mp, in_addr_t * ip)
{
    while (1) {
        char    pkt[DNS_PACKET_LEN];
        INADDR  sa;
        socklen_t salen = sizeof sa;
        RESPONSE resp;
        char    ips[99];

        int     len = recvfrom(mp->sock, pkt, sizeof pkt, 0,
                               (SADDR *) & sa, &salen);
        if (len <= 0)
            break;

        if (!parse_response(pkt, len, &resp))
            continue;

        LOG("resp: ip %s ttl %lu tid %hu name %s\n",
            ipstr(resp.ip, ips), resp.ttl, resp.tid, resp.name);

        QUERY  *qp = &mp->queries[(int)resp.tid % mp->qsize];

        if (qp->ctx && qp->tid == resp.tid && qp->server
            && qp->server->ip == sa.sin_addr.s_addr) {

            if (resp.ip != INADDR_ANY && !strcasecmp(resp.name, qp->name))
                update_cache(mp, &resp);
            return destroy_query(mp, qp, *ip = resp.ip);
        }

        log_packet(__LINE__, pkt, len);
        if (qp->server && qp->server->ip != sa.sin_addr.s_addr)
            LOG("resp.addr=%s tid=%hu ttl=%lu serv=%s\n",
                ipstr(sa.sin_addr.s_addr, pkt), resp.tid, resp.ttl,
                ipstr(qp->server->ip, pkt + 33));
    }

    if (!qempty(&mp->active)) {
        QUERY  *qp = link_QUERY(mp->active.next);

        if (qp->expires <= time(0))
            return destroy_query(mp, qp, *ip = INADDR_ANY);
    }

    return NULL;
}
示例#19
0
/**@brief this function receives an arp message from outside and processes it
 * @param fins_received is the pointer to the fins frame which has been received by the ARP module
 */
void arp_in(struct finsFrame *fins_received){

	struct ARP_message *arp_msg_ptr;

	fins_arp_in = fins_received;

	/**request or reply received from the network and as transmitted by the ethernet stub*/
	if (fins_arp_in->dataOrCtrl == DATA && (fins_arp_in->destinationID.id == (unsigned char) ARPID))
	{
		fins_to_arp(fins_arp_in, packet);  //extract arp hdr from the fins frame
		host_to_net(packet);               //convert it into the right format (e.g. htons issue etc.)
		arp_msg_ptr = &arp_msg;
		arp_hdr_to_msg(packet, arp_msg_ptr);  //convert the hdr into an internal ARP message (e.g. use uint64_t instead of unsigned char)

		print_msgARP(arp_msg_ptr);

		if (check_valid_arp(arp_msg_ptr)==1){

			update_cache(arp_msg_ptr);

			if ((arp_msg_ptr->target_IP_addrs==interface_IP_addrs) && (arp_msg_ptr->operation==ARPREQUESTOP))
				arp_out(REPLYDATA);//generate reply
			else if ((arp_msg_ptr->target_IP_addrs==interface_IP_addrs) && (arp_msg_ptr->operation==ARPREPLYOP))
			{	target_IP_addrs = arp_msg.sender_IP_addrs;
				arp_out(REPLYCONTROL);//generate fins control carrying neighbor's MAC address
			}
		}
	}
	else if ((fins_arp_in->dataOrCtrl == CONTROL) && (fins_arp_in->ctrlFrame.opcode == WRITEREQUEST)
			&& (fins_arp_in->destinationID.id == (unsigned char) ARPID))
	{/**as a request received from the ethernet stub-- IP address is provided in this fins control frame*/

		memcpy(fins_IP_address, fins_arp_in->ctrlFrame.paramterValue, PROTOCOLADDRSLEN);
		target_IP_addrs = gen_IP_addrs(fins_IP_address[0],fins_IP_address[1],fins_IP_address[2],fins_IP_address[3]);

		/**request initiated by the ethernet stub*/
		if (search_list(ptr_cacheHeader, target_IP_addrs)==0)//i.e. not found
			arp_out(REQUESTDATA); //generate arp request for MAC address and send out to the network
		else
			arp_out(REPLYCONTROL);//generate fins control carrying MAC address foe ethernet
	}

	print_cache();
}
示例#20
0
static int spr_get_sprite(UINT32 key)
{
	SPRITE *p = spr_head[key & SPR_HASH_MASK];

	while (p)
	{
		if (p->key == key)
		{
			if (p->used != frames_displayed)
			{
				update_cache(key << 7);
				p->used = frames_displayed;
			}
			return p->index;
		}
		p = p->next;
	}
	return -1;
}
void
camel_groupwise_journal_append (CamelGroupwiseJournal *groupwise_journal, CamelMimeMessage *message,
				const CamelMessageInfo *mi, char **appended_uid, CamelException *ex)
{
	CamelOfflineJournal *journal = (CamelOfflineJournal *) groupwise_journal;
	CamelGroupwiseJournalEntry *entry;
	char *uid;

	if (!update_cache (groupwise_journal, message, mi, &uid, ex))
		return;

	entry = g_new (CamelGroupwiseJournalEntry, 1);
	entry->type = CAMEL_GROUPWISE_JOURNAL_ENTRY_APPEND;
	entry->uid = uid;

	e_dlist_addtail (&journal->queue, (EDListNode *) entry);

	if (appended_uid)
		*appended_uid = g_strdup (uid);
}
示例#22
0
static gboolean
try_mount_mountable (GVfsBackend *backend,
                     GVfsJobMountMountable *job,
                     const char *filename,
                     GMountSource *mount_source)
{
  GVfsBackendAfpBrowse *afp_backend = G_VFS_BACKEND_AFP_BROWSE (backend);
  
  if (is_root (filename))
  {
    g_vfs_job_failed (G_VFS_JOB (job),
                      G_IO_ERROR, G_IO_ERROR_NOT_MOUNTABLE_FILE,
                      _("The file is not a mountable"));
    return TRUE;
  }

  update_cache (afp_backend, G_VFS_JOB (job)->cancellable, mount_mountable_cb, job);

  return TRUE;
                                      
}
示例#23
0
文件: showimage.c 项目: cmatei/GCX
void image_box_to_cache(struct map_cache *cache, struct image_channel *channel,
		       double zoom, int x, int y, int w, int h)
{
	struct map_geometry geom;
	GdkRectangle area;
	int zoom_in = 1;
	int zoom_out = 1;

	if (zoom > 1.0 && zoom <= 16.0) {
		zoom_in = floor(zoom + 0.5);
	} else if (zoom < 1.0 && zoom >= (1.0 / 16.0)) {
		zoom_out = floor(1.0 / zoom + 0.5);
	}

	memset(&geom, 0, sizeof(struct map_geometry));
	geom.zoom = zoom;
	area.x = x * zoom_in / zoom_out;
	area.y = y * zoom_in / zoom_out;
	area.width = w * zoom_in;
	area.height = h * zoom_in;
	update_cache(cache, &geom, channel, &area);
}
示例#24
0
static gboolean
try_enumerate (GVfsBackend *backend,
               GVfsJobEnumerate *job,
               const char *filename,
               GFileAttributeMatcher *attribute_matcher,
               GFileQueryInfoFlags flags)
{
  GVfsBackendAfpBrowse *afp_backend = G_VFS_BACKEND_AFP_BROWSE (backend);

  if (!is_root(filename))
  {
    g_vfs_job_failed (G_VFS_JOB (job),
                      G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
                      _("File doesn't exist"));
    return TRUE;
  }

  update_cache (afp_backend, G_VFS_JOB (job)->cancellable,
                enumerate_cache_updated_cb, job);
  
  return TRUE;
}
示例#25
0
 /** Gets the value associated with the key. returns true on success.. */
 std::pair<bool, ValueType> get(const KeyType &key) const {
   std::pair<bool, ValueType> ret = get_owned(key);
   if (ret.first) return ret;
 
   wait_struct w;
   w.numreplies = rmi.numprocs() - 1;
   size_t ptr = reinterpret_cast<size_t>(&w);
   // otherwise I need to find someone with the key
   for (size_t i = 0;i < rmi.numprocs(); ++i) {
     if (i != rmi.procid()) {
       rmi.RPC_CALL(remote_call,&lazy_dht<KeyType,ValueType>::remote_get_owned)
                    (i, key, rmi.procid(), ptr);
     }
   }
   w.mut.lock();
   while (w.numreplies > 0) w.cond.wait(w.mut);
   w.mut.unlock();
   ret.first = w.hasvalue;
   ret.second = w.val;
   if (ret.first) update_cache(key, ret.second);
   return ret;
 }
示例#26
0
/*
 * net_register()
 *
 *	Make sure the cache is properly sync'ed, and its registrations
 *	are in order.
 *
 *	Locking: the cache is locked by update_cache, and is held
 *	throughout update_cache's execution because it reads and
 *	possibly modifies cache links continuously.
 */
static int
net_register(rcm_handle_t *hd)
{
	update_cache(hd);
	/*
	 * Need to register interest in all new resources
	 * getting attached, so we get attach event notifications
	 */
	if (!events_registered) {
		if (rcm_register_event(hd, RCM_RESOURCE_PHYSLINK_NEW, 0, NULL)
		    != RCM_SUCCESS) {
			rcm_log_message(RCM_ERROR,
			    _("NET: failed to register %s\n"),
			    RCM_RESOURCE_PHYSLINK_NEW);
			return (RCM_FAILURE);
		} else {
			rcm_log_message(RCM_DEBUG, _("NET: registered %s \n"),
			    RCM_RESOURCE_PHYSLINK_NEW);
			events_registered++;
		}
	}

	return (RCM_SUCCESS);
}
示例#27
0
文件: snmp.c 项目: jianglei12138/cups
static void
probe_device(snmp_cache_t *device)	/* I - Device */
{
  char		uri[1024],		/* Full device URI */
		*uriptr,		/* Pointer into URI */
		*format;		/* Format string for device */
  device_uri_t	*device_uri;		/* Current DeviceURI match */


  debug_printf("DEBUG: %.3f Probing %s...\n", run_time(), device->addrname);

#ifdef __APPLE__
 /*
  * If the printer supports Bonjour/mDNS, don't report it from the SNMP backend.
  */

  if (!try_connect(&(device->address), device->addrname, 5353))
  {
    debug_printf("DEBUG: %s supports mDNS, not reporting!\n", device->addrname);
    return;
  }
#endif /* __APPLE__ */

 /*
  * Lookup the device in the match table...
  */

  for (device_uri = (device_uri_t *)cupsArrayFirst(DeviceURIs);
       device_uri;
       device_uri = (device_uri_t *)cupsArrayNext(DeviceURIs))
    if (device->make_and_model &&
        !regexec(&(device_uri->re), device->make_and_model, 0, NULL, 0))
    {
     /*
      * Found a match, add the URIs...
      */

      for (format = (char *)cupsArrayFirst(device_uri->uris);
           format;
	   format = (char *)cupsArrayNext(device_uri->uris))
      {
        for (uriptr = uri; *format && uriptr < (uri + sizeof(uri) - 1);)
	  if (*format == '%' && format[1] == 's')
	  {
	   /*
	    * Insert hostname/address...
	    */

	    strlcpy(uriptr, device->addrname, sizeof(uri) - (size_t)(uriptr - uri));
	    uriptr += strlen(uriptr);
	    format += 2;
	  }
	  else
	    *uriptr++ = *format++;

        *uriptr = '\0';

        update_cache(device, uri, NULL, NULL);
      }

      return;
    }

 /*
  * Then try the standard ports...
  */

  if (!try_connect(&(device->address), device->addrname, 9100))
  {
    debug_printf("DEBUG: %s supports AppSocket!\n", device->addrname);

    snprintf(uri, sizeof(uri), "socket://%s", device->addrname);
    update_cache(device, uri, NULL, NULL);
  }
  else if (!try_connect(&(device->address), device->addrname, 515))
  {
    debug_printf("DEBUG: %s supports LPD!\n", device->addrname);

    snprintf(uri, sizeof(uri), "lpd://%s/", device->addrname);
    update_cache(device, uri, NULL, NULL);
  }
}
示例#28
0
void
draw_multi_rooms (void)
{
  int x, y;

  mr_map_rooms ();

  if (anim_cycle == 0) {
    generate_wall_colors_for_room (0, room0_wall_color);
  }

  if (em == PALACE && vm == VGA
      && (has_mr_view_changed ()
          || em != mr.last.em
          || vm != mr.last.vm))
    generate_wall_colors ();

  if (has_mr_view_changed ()) {
    generate_stars ();
    generate_mirrors_reflex ();
  }

  if (mouse_pos.room != mr.last.mouse_pos.room
      || mouse_pos.floor != mr.last.mouse_pos.floor
      || mouse_pos.place != mr.last.mouse_pos.place) {
    if (is_valid_pos (&mouse_pos))
      update_cache_pos (&mouse_pos, em, vm);
    if (is_valid_pos (&mr.last.mouse_pos))
      update_cache_pos (&mr.last.mouse_pos, em, vm);
  }

  if (anim_cycle == 0
      || em != mr.last.em
      || vm != mr.last.vm
      || hgc != mr.last.hgc
      || hue != mr.last.hue) {
    update_room0_cache (em, vm);
  }

  if (anim_cycle == 0
      || has_mr_view_changed ()
      || em != mr.last.em
      || vm != mr.last.vm
      || hgc != mr.last.hgc
      || hue != mr.last.hue
      || level.number != mr.last.level) {
    update_cache (em, vm);
  }

  size_t i;
  for (i = 0; i < changed_pos_nmemb; i++) {
    /* printf ("%i,%i,%i\n", changed_pos[i].room, changed_pos[i].floor, changed_pos[i].place); */
    update_cache_pos (&changed_pos[i], em, vm);
  }
  destroy_array ((void **) &changed_pos, &changed_pos_nmemb);

  clear_bitmap (screen, BLACK);

  for (y = mr.h - 1; y >= 0; y--)
    for (x = 0; x < mr.w; x++) {
      if (! mr.cell[x][y].room) continue;
      mr.dx = x;
      mr.dy = y;
      draw_animated_background (mr.cell[x][y].screen, mr.cell[x][y].room);
    }

  if (! no_room_drawing) draw_bitmap (cache, screen, 0, 0, 0);

  for (y = mr.h - 1; y >= 0; y--)
    for (x = 0; x < mr.w; x++) {
      if (! mr.cell[x][y].room) continue;
      mr.dx = x;
      mr.dy = y;
      draw_animated_foreground (mr.cell[x][y].screen, mr.cell[x][y].room);
    }

  if (mr.select_cycles > 0) {
    al_hold_bitmap_drawing (false);

    int x0 = ORIGINAL_WIDTH * mr.x;
    int y0 = ROOM_HEIGHT * mr.y + 3;
    int x1 = x0 + ORIGINAL_WIDTH;
    int y1 = y0 + ROOM_HEIGHT;
    draw_rectangle (screen, x0, y0, x1, y1, RED, 1);

    mr.select_cycles--;
  }

  mr.dx = mr.dy = -1;

  mr_update_last_settings ();
}
示例#29
0
/**@brief this function tests a set of functions which are used when
 * (1) a host receives an ARP request, and (2) keeps updating its cache based on
 * these ARP requests
 * @param fileName is the file from which the list of neighbors is drawn
 */
void send_receive_update(char *fileName)
{
	extern struct node *ptr_cacheHeader;
	struct finsFrame request_fins, reply_fins, *request_fins_ptr, *reply_fins_ptr;
	struct ARP_message request_ARP1, request_ARP2, reply_ARP1, reply_ARP2;
	struct ARP_message *request_ARP_ptr1, *request_ARP_ptr2, *reply_ARP_ptr1, *reply_ARP_ptr2;
	struct arp_hdr hdr_ARP, *hdr_ARP_ptr;
	uint64_t MAC_addrs;
	uint32_t IP_addrs_read;
	int task;

	/**Following code generates a list of IP/MAC addresses of 'neighbors' and initializes cache*/
	ptr_cacheHeader = init_intface();
	gen_neighbor_list(fileName);
	init_recordsARP(fileName);
	print_cache();
	print_neighbors(ptr_neighbor_list);
	hdr_ARP_ptr = &hdr_ARP;
	IP_addrs_read = 1;
	task = 1;

	/**Begin Initialize/Instantiate Pointers */
	request_fins_ptr = &request_fins;
	reply_fins_ptr = &reply_fins;
	request_ARP_ptr1 = &request_ARP1;
	request_ARP_ptr2 = &request_ARP2;
	reply_ARP_ptr1 = &reply_ARP1;
	reply_ARP_ptr2 = &reply_ARP2;

	/**A host can send update its cache based on its own request or a request from another network host*/
	while (IP_addrs_read!=0 && (task==0 || task == 1))
	{
		PRINT_DEBUG("\nTest send request and update `0' or test receive a request `1' \n");
		scanf("%d", &task);
		IP_addrs_read = read_IP_addrs();

		/**The following functions test the internal operations of the module*/
		if (task==0){

			gen_requestARP(IP_addrs_read, request_ARP_ptr1);
			print_msgARP(request_ARP_ptr1);
			arp_to_fins(request_ARP_ptr1, request_fins_ptr);
			fins_to_arp(request_fins_ptr, request_ARP_ptr2);
			mimic_net_reply(request_ARP_ptr2, reply_ARP_ptr1);

			if (check_valid_arp(reply_ARP_ptr1)==1){
			arp_to_fins(reply_ARP_ptr1, reply_fins_ptr);
			fins_to_arp(reply_fins_ptr, reply_ARP_ptr2);
			print_msgARP(reply_ARP_ptr2);
			update_cache(reply_ARP_ptr2);}

			print_cache();
		}
		else if (task==1){

			MAC_addrs = search_MAC_addrs(IP_addrs_read, ptr_neighbor_list);
			mimic_net_request(IP_addrs_read, MAC_addrs,request_ARP_ptr1);
			print_msgARP(request_ARP_ptr1);

			if (check_valid_arp(request_ARP_ptr1)==1){
			arp_to_fins(request_ARP_ptr1, request_fins_ptr);
			fins_to_arp(request_fins_ptr, request_ARP_ptr2);
			print_msgARP(request_ARP_ptr2);
			update_cache(request_ARP_ptr2);}

			print_cache();
		}

		/**The following functions test the external operation of the module*/

		if (check_valid_arp(request_ARP_ptr2)==1){
		hdr_ARP_ptr = &hdr_ARP;
		/**convert ARP message to htons format and generate MAC addresses as unsigned char ptr*/
		net_fmt_conversion(request_ARP_ptr2, hdr_ARP_ptr);
		print_arp_hdr(hdr_ARP_ptr);/**print some fields of the ARP message in external format*/
		host_fmt_conversion(hdr_ARP_ptr, request_ARP_ptr2);/**convert ARP message to ntohs format*/
		print_msgARP(request_ARP_ptr2);/**print ARP message internal format*/
		}

	}

	term_intface();
}
示例#30
0
文件: bee-dep.c 项目: fpellanda/bee
static int bee_dep_update(int argc, char *argv[])
{
    int c, help;
    char *pkg;
    char path[PATH_MAX + 1];
    struct hash *graph;
    struct stat st;
    struct option long_options[] = {
        {"help", 0, &help, 1},
        {0, 0, 0, 0}
    };

    help = 0;

    while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) {
        switch (c) {
            case '?':
                usage_update();
                return 1;
        }
    }

    if (help) {
        usage_update();
        return 0;
    }

    if (argc == 1) {
        graph = get_cache();

        if (update_cache(graph) || save_cache(graph, cache_filename())) {
            hash_free(graph);
            return 1;
        }

        hash_free(graph);
        return 0;
    }

    if (argc < 2) {
        fprintf(stderr, "bee-dep: pkgname needed\n");
        return 1;
    }

    if (argc > 2) {
        fprintf(stderr, "bee-dep: too many arguments\n");
        return 1;
    }

    pkg = argv[1];

    if (sprintf(path, "%s/%s/DEPENDENCIES", bee_metadir(), pkg) < 0) {
        perror("bee-dep: sprintf");
        return 1;
    }

    graph = get_cache();

    if (stat(path, &st) != -1) {
        if (hash_search(graph, pkg)) {
            hash_free(graph);
            return 0;
        }

        if (graph_insert_nodes(graph, path)) {
            hash_free(graph);
            return 1;
        }
    } else {
        if (remove_package(graph, pkg)) {
            hash_free(graph);
            return 1;
        }
    }

    if (save_cache(graph, cache_filename())) {
        hash_free(graph);
        return 1;
    }

    hash_free(graph);
    return 0;
}