Example #1
0
Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) {

	ERR_FAIL_COND_V(p_mode_flags != READ, ERR_UNAVAILABLE);
	if (opened)
		close();
	FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
	DEBUG_PRINT("open: " + p_path);

	DEBUG_TIME("open_begin");

	nc->lock_mutex();
	nc->put_32(id);
	nc->accesses[id] = this;
	nc->put_32(COMMAND_OPEN_FILE);
	CharString cs = p_path.utf8();
	nc->put_32(cs.length());
	nc->client->put_data((const uint8_t *)cs.ptr(), cs.length());
	pos = 0;
	eof_flag = false;
	last_page = -1;
	last_page_buff = NULL;

	//buffers.clear();
	nc->unlock_mutex();
	DEBUG_PRINT("OPEN POST");
	DEBUG_TIME("open_post");
	nc->sem->post(); //awaiting answer
	DEBUG_PRINT("WAIT...");
	sem->wait();
	DEBUG_TIME("open_end");
	DEBUG_PRINT("WAIT ENDED...");

	return response;
}
Example #2
0
//////////////////////////////////////////////////
//@Fuction name : am_demux_close(U8 index)
//@Description:close filter
//@param <IN>
//@--index : same as outindex in the function demux_open(DMX_FILTER_TYPE type,U8 index,U8* outindex)
//@param <RET>
//@--TRUE:sucess
//@--FALSE:fail
TAPI_BOOL am_demux_close(TAPI_S8 index) {
    int ret = -1;
    am_demux_filter_t *am_dmx_filter_ptr = NULL;

    pthread_mutex_lock(&am_demux_dev.lock);
    if (TAPI_FALSE == get_filter_by_index(index, &am_dmx_filter_ptr)) {
        pthread_mutex_unlock(&am_demux_dev.lock);
        return TAPI_FALSE;
    }

    if (am_dmx_filter_ptr->fid != -1 && am_dmx_filter_ptr->used) {
        am_dmx_filter_ptr->enable = TAPI_FALSE;
        DEBUG_TIME();DEBUG("filter[%d]close pid = %d\n",am_dmx_filter_ptr->index,am_dmx_filter_ptr->pid);
        ret = AM_DMX_FreeFilter(am_dmx_filter_ptr->dmx_dev_id, am_dmx_filter_ptr->fid);
        if (ret != AM_SUCCESS) {
            LOGE("free filter failure!  filter_index=%d", am_dmx_filter_ptr->fid);
        }
        //free buf list used by filter
        dmx_cbuf_reset(&am_dmx_filter_ptr->cbuf);
        am_dmx_filter_ptr->used = TAPI_FALSE;
        am_dmx_filter_ptr->fid = -1;

        pthread_mutex_unlock(&am_demux_dev.lock);
        AM_DMX_Sync(am_dmx_filter_ptr->dmx_dev_id);
        pthread_mutex_lock(&am_demux_dev.lock);
        am_dmx_filter_ptr->serialnumread = am_dmx_filter_ptr->serialnumwrite = 0;
    }
    pthread_mutex_unlock(&am_demux_dev.lock);
    return ret == AM_SUCCESS ? TAPI_TRUE : TAPI_FALSE;
}
Example #3
0
/////////////////////////////////////
//@Fuction name : am_demux_stop(U8 index)
//@Description:stop a filter after set param,
//@param <IN>
//@--index : same as outindex in the function demux_open(DMX_FILTER_TYPE type,U8 index,U8* outindex)
//@param <RET>
//@--TRUE:sucess
//@--FALSE:fail
TAPI_BOOL am_demux_stop(TAPI_S8 index) {
    int ret = -1;
    am_demux_filter_t *am_dmx_filter_ptr = NULL;

    pthread_mutex_lock(&am_demux_dev.lock);
    if (TAPI_FALSE == get_filter_by_index(index, &am_dmx_filter_ptr)) {
        pthread_mutex_unlock(&am_demux_dev.lock);
        return TAPI_FALSE;
    }

    if (!am_dmx_filter_ptr->enable || !am_dmx_filter_ptr->used) {
        pthread_mutex_unlock(&am_demux_dev.lock);
        return TAPI_TRUE;
    }

    if (am_dmx_filter_ptr->fid != -1 && am_dmx_filter_ptr->enable) {
        DEBUG_TIME();DEBUG("filter[%d]stop pid = %d\n",am_dmx_filter_ptr->index,am_dmx_filter_ptr->pid);
        ret = AM_DMX_StopFilter(am_dmx_filter_ptr->dmx_dev_id, am_dmx_filter_ptr->fid);
        if (ret != AM_SUCCESS) {
            LOGE("stop filter failure!   filter_index=%d", am_dmx_filter_ptr->fid);
        } else {
            am_dmx_filter_ptr->enable = TAPI_FALSE;
        }
        if (am_dmx_filter_ptr->timeout_triggered == TAPI_TRUE) {
            am_dmx_filter_ptr->timeout_triggered = TAPI_FALSE;
        }
    }
    pthread_mutex_unlock(&am_demux_dev.lock);
    return ret == AM_SUCCESS ? TAPI_TRUE : TAPI_FALSE;;
}
Example #4
0
TAPI_BOOL am_demux_allocatefilter(DMX_FILTER_TYPE type, TAPI_S16 u16id, TAPI_S8 index, TAPI_S8* outindex) {
    int ret = -1;
    int fid;
    am_demux_filter_t *am_dmx_filter_ptr = NULL;
    int indexId;

    if (Demod_GetLockStatus() != TAPI_TRUE && u16id != AM_SI_PID_EIT){
        LOGE("not lock,fail to get  filter_index=%d", index);
        return TAPI_FALSE;
    }

    pthread_mutex_lock(&am_demux_dev.lock);

    for (indexId = 0; indexId < SECTION_FILTER_NUM; indexId++) {
        if (!g_am_demux_filter[indexId].used)
            break;
    }

    if (indexId >= SECTION_FILTER_NUM) {
        pthread_mutex_unlock(&am_demux_dev.lock);
        LOGE("max index,fail to get  filter_index=%d", index);
        return TAPI_FALSE;
    }

    am_dmx_filter_ptr = &g_am_demux_filter[indexId];

    if (am_dmx_filter_ptr->fid != -1) {
        ret = AM_DMX_StopFilter(am_dmx_filter_ptr->dmx_dev_id, am_dmx_filter_ptr->fid);
        if (ret != AM_SUCCESS) {
            LOGE("stop filter failure!  filter_index=%d", am_dmx_filter_ptr->fid);
        }
        ret = AM_DMX_FreeFilter(am_dmx_filter_ptr->dmx_dev_id, am_dmx_filter_ptr->fid);
        if (ret != AM_SUCCESS) {
            LOGE("free filter failure!  filter_index=%d", am_dmx_filter_ptr->fid);
        }
        pthread_mutex_unlock(&am_demux_dev.lock);
        AM_DMX_Sync(am_dmx_filter_ptr->dmx_dev_id);
        pthread_mutex_lock(&am_demux_dev.lock);
    }

    ret = AM_DMX_AllocateFilter(am_dmx_filter_ptr->dmx_dev_id, &fid);
    if (ret == AM_SUCCESS) {
        *outindex = indexId; //am_dmx_filter_ptr->fid;//customer prefer used the index them pass
        am_dmx_filter_ptr->type = type;
        //am_dmx_filter_ptr->index = indexId;
        am_dmx_filter_ptr->pid = u16id;
        am_dmx_filter_ptr->serialnumread = am_dmx_filter_ptr->serialnumwrite = 0;
        am_dmx_filter_ptr->hdi_dmx_filter_status = DMX_FILTER_STATUS_DATA_READY;
        am_dmx_filter_ptr->fid = fid;
        am_dmx_filter_ptr->used = TAPI_TRUE;
        am_dmx_filter_ptr->enable = TAPI_FALSE;
        DEBUG_TIME();DEBUG("=====set filter->fid=%d,input type=%d index=%d\n",am_dmx_filter_ptr->fid,type,indexId);
    } else {
        LOGE("allocate filter failure!");
    }
    pthread_mutex_unlock(&am_demux_dev.lock);
    return ret == AM_SUCCESS ? TAPI_TRUE : TAPI_FALSE;
}
void FileAccessNetworkClient::_thread_func() {

	client->set_nodelay(true);
	while(!quit) {

		DEBUG_PRINT("SEM WAIT - "+itos(sem->get()));
		Error err = sem->wait();
		DEBUG_TIME("sem_unlock");
		//DEBUG_PRINT("semwait returned "+itos(werr));
		DEBUG_PRINT("MUTEX LOCK "+itos(lockcount));
		DEBUG_PRINT("POPO");
		DEBUG_PRINT("PEPE");
		lock_mutex();
		DEBUG_PRINT("MUTEX PASS");

		blockrequest_mutex->lock();
		while(block_requests.size()) {
			put_32(block_requests.front()->get().id);
			put_32(FileAccessNetwork::COMMAND_READ_BLOCK);
			put_64(block_requests.front()->get().offset);
			put_32(block_requests.front()->get().size);
			block_requests.pop_front();
		}
		blockrequest_mutex->unlock();

		DEBUG_PRINT("THREAD ITER");

		DEBUG_TIME("sem_read");
		int id = get_32();

		int response = get_32();
		DEBUG_PRINT("GET RESPONSE: "+itos(response));

		FileAccessNetwork *fa=NULL;

		if (response!=FileAccessNetwork::RESPONSE_DATA) {
			ERR_FAIL_COND(!accesses.has(id));
		}

		if (accesses.has(id))
			fa=accesses[id];


		switch(response) {

			case FileAccessNetwork::RESPONSE_OPEN: {


				DEBUG_TIME("sem_open");
				int status = get_32();
				if (status!=OK) {
					fa->_respond(0,Error(status));
				} else {
					uint64_t len = get_64();
					fa->_respond(len,Error(status));
				}

				fa->sem->post();


			} break;
			case FileAccessNetwork::RESPONSE_DATA: {

				int64_t offset = get_64();
				uint32_t len = get_32();

				Vector<uint8_t> block;
				block.resize(len);
				client->get_data(block.ptr(),len);

				if (fa) //may have been queued
					fa->_set_block(offset,block);

			} break;
			case FileAccessNetwork::RESPONSE_FILE_EXISTS: {


				int status = get_32();
				fa->exists_modtime=status!=0;
				fa->sem->post();



			} break;
			case FileAccessNetwork::RESPONSE_GET_MODTIME: {


				uint64_t status = get_64();
				fa->exists_modtime=status;
				fa->sem->post();

			} break;

		}


		unlock_mutex();
	}

}
Example #6
0
TAPI_BOOL am_demux_getdata(TAPI_U8 index, TAPI_U8 serialnum, TAPI_U32 addr, TAPI_U32 len, TAPI_BOOL fgUpdateData, TAPI_U8* buf) {
    int ret = -1;
    am_demux_filter_psi_info_t *p_psi_info = NULL;
    am_demux_filter_t *am_dmx_filter_ptr = NULL;
    hdi_dmx_cbuf_t *cbuf;
    TAPI_U32 avail_len;

    pthread_mutex_lock(&am_demux_dev.lock);
    if (buf == NULL || len == 0 || addr == 0) {
        pthread_mutex_unlock(&am_demux_dev.lock);
        LOGE("invalidate data buf or buf length");
        return TAPI_FALSE;
    }

    if (TAPI_FALSE == get_filter_by_index(index, &am_dmx_filter_ptr)) {
        pthread_mutex_unlock(&am_demux_dev.lock);
        LOGE("can not find the assigned filter[%d]", index);
        return TAPI_FALSE;
    }

    if (!am_dmx_filter_ptr->used || !am_dmx_filter_ptr->enable) {
        pthread_mutex_unlock(&am_demux_dev.lock);
        LOGE("filter index =%d used=%d,enble=%d\n", am_dmx_filter_ptr->index, am_dmx_filter_ptr->used, am_dmx_filter_ptr->enable);
        return TAPI_FALSE;
    }
    cbuf = &am_dmx_filter_ptr->cbuf;
    if (cbuf->data == NULL) {
        pthread_mutex_unlock(&am_demux_dev.lock);
        LOGE("please alloc cbuf->data");
        return TAPI_FALSE;
    }
    //LOGE("%s,in len = %d pid=0x%x tid=%d\n",__FUNCTION__, len,am_dmx_filter_ptr->pid,am_dmx_filter_ptr->params.sec.filter.filter[0]);
    //LOGE("%s,filter[%d].serial=%d\n",__FUNCTION__,am_dmx_filter_ptr->fid,serialnum);
    /*Now read from cbuf*/
    avail_len = dmx_cbuf_avail(cbuf);
    if (avail_len <= 0) {
#if 0
        struct timespec rt;
        int rv;
        AM_TIME_GetTimeSpecTimeout(500, &rt); //wait 500ms
        rv = pthread_cond_timedwait(&cbuf->cond, &am_demux_dev.lock, &rt);
        if (rv == ETIMEDOUT) {
            pthread_mutex_unlock(&am_demux_dev.lock);
            LOGE("not avail data,timeout");
            return TAPI_FALSE;
        }
#else
        pthread_mutex_unlock(&am_demux_dev.lock);
        LOGE("not avail data");
        return TAPI_FALSE;
#endif
    } else {
        TAPI_U16 sec_len;
        if (avail_len >= 4) {
            dmx_cbuf_read(cbuf, buf, 3);
            sec_len = ((TAPI_U16)(buf[1] & 0x0f) << 8) | (TAPI_U16) buf[2];
            if ((TAPI_U32)(sec_len + 3) != len) {
                LOGE("length is not right,sec_len=%d,len=%d,filter[%d].pid=%d ", sec_len, len, am_dmx_filter_ptr->index, am_dmx_filter_ptr->pid);
                dmx_cbuf_reset(&am_dmx_filter_ptr->cbuf);
            } else {
                if (sec_len > 0) {
                    dmx_cbuf_read(cbuf, buf + 3, sec_len);
#if 0
                    if (am_dmx_filter_ptr->pid == 0) {
                        int j;
                        DEBUG_TIME();DEBUG("PAT DATA :\n");
                        for (j = 0; j < len; j++) {
                            DEBUG("%2x ",buf[j]);
                            if ((j + 1) % 8 == 0)
                                DEBUG("\n");
                        }DEBUG("\n");
                    }
                    if (am_dmx_filter_ptr->params.sec.filter.filter[0] == AM_SI_TID_PMT) {
                        int j;
                        DEBUG_TIME();DEBUG("PMT DATA :\n");
                        for (j = 0; j < len; j++) {
                            DEBUG("%2x ",buf[j]);
                            if ((j + 1) % 8 == 0)
                                DEBUG("\n");
                        }DEBUG("\n");
                    }
                    if (am_dmx_filter_ptr->params.sec.filter.filter[0] == AM_SI_TID_TDT) {
                      int j;
                      DEBUG_TIME();DEBUG("filter[%d] TDT DATA :\n",am_dmx_filter_ptr->index);
                      for (j = 0; j < len; j++) {
                         DEBUG("%2x ",buf[j]);
                         if ((j + 1) % 8 == 0)
                             DEBUG("\n");
                      }DEBUG("\n");
                   }
#endif
                    ret = 0;
                }
            }

        } else {
            if (avail_len != 0) {
                dmx_cbuf_reset(cbuf);

            }
        }
    }
    pthread_mutex_unlock(&am_demux_dev.lock);

    return ret == 0 ? TAPI_TRUE : TAPI_FALSE;
}
Example #7
0
void EditorFileServer::_subthread_start(void *s) {

	ClientData *cd = (ClientData *)s;

	cd->connection->set_nodelay(true);
	uint8_t buf4[8];
	Error err = cd->connection->get_data(buf4, 4);
	if (err != OK) {
		_close_client(cd);
		ERR_FAIL_COND(err != OK);
	}

	int passlen = decode_uint32(buf4);

	if (passlen > 512) {

		_close_client(cd);
		ERR_FAIL_COND(passlen > 512);
	} else if (passlen > 0) {

		Vector<char> passutf8;
		passutf8.resize(passlen + 1);
		err = cd->connection->get_data((uint8_t *)passutf8.ptr(), passlen);
		if (err != OK) {
			_close_client(cd);
			ERR_FAIL_COND(err != OK);
		}
		passutf8[passlen] = 0;
		String s;
		s.parse_utf8(passutf8.ptr());
		if (s != cd->efs->password) {
			encode_uint32(ERR_INVALID_DATA, buf4);
			cd->connection->put_data(buf4, 4);
			OS::get_singleton()->delay_usec(1000000);
			_close_client(cd);
			ERR_PRINT("CLIENT PASSWORD MISMATCH");
			ERR_FAIL();
		}
	} else {
		if (cd->efs->password != "") {
			encode_uint32(ERR_INVALID_DATA, buf4);
			cd->connection->put_data(buf4, 4);
			OS::get_singleton()->delay_usec(1000000);
			_close_client(cd);
			ERR_PRINT("CLIENT PASSWORD MISMATCH (should be empty!)");
			ERR_FAIL();
		}
	}

	encode_uint32(OK, buf4);
	cd->connection->put_data(buf4, 4);

	while (!cd->quit) {

		//wait for ID
		err = cd->connection->get_data(buf4, 4);
		//#define DEBUG_PRINT(m_p) print_line(m_p)
		DEBUG_TIME("get_data")

		if (err != OK) {
			_close_client(cd);
			ERR_FAIL_COND(err != OK);
		}
		int id = decode_uint32(buf4);

		//wait for command
		err = cd->connection->get_data(buf4, 4);
		if (err != OK) {
			_close_client(cd);
			ERR_FAIL_COND(err != OK);
		}
		int cmd = decode_uint32(buf4);

		switch (cmd) {

			case FileAccessNetwork::COMMAND_FILE_EXISTS:
			case FileAccessNetwork::COMMAND_GET_MODTIME:
			case FileAccessNetwork::COMMAND_OPEN_FILE: {

				DEBUG_TIME("open_file")
				err = cd->connection->get_data(buf4, 4);
				if (err != OK) {
					_close_client(cd);
					ERR_FAIL_COND(err != OK);
				}

				int namelen = decode_uint32(buf4);
				Vector<char> fileutf8;
				fileutf8.resize(namelen + 1);
				err = cd->connection->get_data((uint8_t *)fileutf8.ptr(), namelen);
				if (err != OK) {
					_close_client(cd);
					ERR_FAIL_COND(err != OK);
				}
				fileutf8[namelen] = 0;
				String s;
				s.parse_utf8(fileutf8.ptr());

				if (cmd == FileAccessNetwork::COMMAND_FILE_EXISTS) {
					print_line("FILE EXISTS: " + s);
				}
				if (cmd == FileAccessNetwork::COMMAND_GET_MODTIME) {
					print_line("MOD TIME: " + s);
				}
				if (cmd == FileAccessNetwork::COMMAND_OPEN_FILE) {
					print_line("OPEN: " + s);
				}

				if (!s.begins_with("res://")) {

					_close_client(cd);
					ERR_FAIL_COND(!s.begins_with("res://"));
				}
				ERR_CONTINUE(cd->files.has(id));

				if (cmd == FileAccessNetwork::COMMAND_FILE_EXISTS) {

					encode_uint32(id, buf4);
					cd->connection->put_data(buf4, 4);
					encode_uint32(FileAccessNetwork::RESPONSE_FILE_EXISTS, buf4);
					cd->connection->put_data(buf4, 4);
					encode_uint32(FileAccess::exists(s), buf4);
					cd->connection->put_data(buf4, 4);
					DEBUG_TIME("open_file_end")
					break;
				}

				if (cmd == FileAccessNetwork::COMMAND_GET_MODTIME) {

					encode_uint32(id, buf4);
					cd->connection->put_data(buf4, 4);
					encode_uint32(FileAccessNetwork::RESPONSE_GET_MODTIME, buf4);
					cd->connection->put_data(buf4, 4);
					encode_uint64(FileAccess::get_modified_time(s), buf4);
					cd->connection->put_data(buf4, 8);
					DEBUG_TIME("open_file_end")
					break;
				}

				FileAccess *fa = FileAccess::open(s, FileAccess::READ);
				if (!fa) {
					//not found, continue
					encode_uint32(id, buf4);
					cd->connection->put_data(buf4, 4);
					encode_uint32(FileAccessNetwork::RESPONSE_OPEN, buf4);
					cd->connection->put_data(buf4, 4);
					encode_uint32(ERR_FILE_NOT_FOUND, buf4);
					cd->connection->put_data(buf4, 4);
					DEBUG_TIME("open_file_end")
					break;
				}

				encode_uint32(id, buf4);
				cd->connection->put_data(buf4, 4);
				encode_uint32(FileAccessNetwork::RESPONSE_OPEN, buf4);
				cd->connection->put_data(buf4, 4);
				encode_uint32(OK, buf4);
				cd->connection->put_data(buf4, 4);
				encode_uint64(fa->get_len(), buf4);
				cd->connection->put_data(buf4, 8);

				cd->files[id] = fa;
				DEBUG_TIME("open_file_end")

			} break;
Example #8
0
File: priority.c Project: rolk/ug
void NS_DIM_PREFIX SetGhostObjectPriorities (GRID *theGrid)
{
  ELEMENT *theElement,*theNeighbor,*SonList[MAX_SONS];
  NODE    *theNode;
  EDGE    *theEdge;
  VECTOR  *theVector;
  INT i,prio,*proclist,hghost,vghost;

  /* reset USED flag for objects of ghostelements */
  for (theElement=PFIRSTELEMENT(theGrid);
       theElement!=NULL;
       theElement=SUCCE(theElement))
  {
    SETUSED(theElement,0); SETTHEFLAG(theElement,0);
    for (i=0; i<EDGES_OF_ELEM(theElement); i++)
    {
      theEdge = GetEdge(CORNER(theElement,CORNER_OF_EDGE(theElement,i,0)),
                        CORNER(theElement,CORNER_OF_EDGE(theElement,i,1)));
      ASSERT(theEdge != NULL);
      SETUSED(theEdge,0); SETTHEFLAG(theEdge,0);
    }
    if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC))
      for (i=0; i<SIDES_OF_ELEM(theElement); i++)
      {
        theVector = SVECTOR(theElement,i);
        if (theVector != NULL) {
          SETUSED(theVector,0);
          SETTHEFLAG(theVector,0);
        }
      }
  }
  /* to reset also nodes which are at corners of the boundary */
  /* reset of nodes need to be done through the node list     */
  for (theNode=PFIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode))
  {
    SETUSED(theNode,0); SETTHEFLAG(theNode,0);
    SETMODIFIED(theNode,0);
  }

  /* set FLAG for objects of horizontal and vertical overlap */
  for (theElement=PFIRSTELEMENT(theGrid);
       theElement!=NULL;
       theElement=SUCCE(theElement))
  {
    if (PARTITION(theElement) == me) continue;

    /* check for horizontal ghost */
    hghost = 0;
    for (i=0; i<SIDES_OF_ELEM(theElement); i++)
    {
      theNeighbor = NBELEM(theElement,i);
      if (theNeighbor == NULL) continue;

      if (PARTITION(theNeighbor) == me)
      {
        hghost = 1;
        break;
      }
    }

    /* check for vertical ghost */
    vghost = 0;
    GetAllSons(theElement,SonList);
    for (i=0; SonList[i]!=NULL; i++)
    {
      if (PARTITION(SonList[i]) == me)
      {
        vghost = 1;
        break;
      }
    }

    /* one or both of vghost and hghost should be true here   */
    /* except for elements which will be disposed during Xfer */

    if (vghost) SETTHEFLAG(theElement,1);
    if (hghost) SETUSED(theElement,1);
    for (i=0; i<CORNERS_OF_ELEM(theElement); i++)
    {
      theNode = CORNER(theElement,i);
      if (vghost) SETTHEFLAG(theNode,1);
      if (hghost) SETUSED(theNode,1);
    }
    for (i=0; i<EDGES_OF_ELEM(theElement); i++)
    {
      theEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement,i,0),
                        CORNER_OF_EDGE_PTR(theElement,i,1));
      ASSERT(theEdge != NULL);
      if (vghost) SETTHEFLAG(theEdge,1);
      if (hghost) SETUSED(theEdge,1);
    }
    if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC))
      for (i=0; i<SIDES_OF_ELEM(theElement); i++)
      {
        theVector = SVECTOR(theElement,i);
        if (theVector != NULL) {
          if (vghost) SETTHEFLAG(theVector,1);
          if (hghost) SETUSED(theVector,1);
        }
      }
  }

  DEBUG_TIME(0);

  /* set USED flag for objects of master elements */
  /* reset FLAG for objects of master elements  */
  for (theElement=PFIRSTELEMENT(theGrid);
       theElement!=NULL;
       theElement=SUCCE(theElement))
  {
    if (PARTITION(theElement) != me) continue;

    SETUSED(theElement,0); SETTHEFLAG(theElement,0);
    for (i=0; i<CORNERS_OF_ELEM(theElement); i++)
    {
      theNode = CORNER(theElement,i);
      SETUSED(theNode,0); SETTHEFLAG(theNode,0);
      SETMODIFIED(theNode,1);
    }
    for (i=0; i<EDGES_OF_ELEM(theElement); i++)
    {
      theEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement,i,0),
                        CORNER_OF_EDGE_PTR(theElement,i,1));
      ASSERT(theEdge != NULL);
      SETUSED(theEdge,0); SETTHEFLAG(theEdge,0);
    }
    if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC))
      for (i=0; i<SIDES_OF_ELEM(theElement); i++)
      {
        theVector = SVECTOR(theElement,i);
        if (theVector != NULL) {
          SETUSED(theVector,0);
          SETTHEFLAG(theVector,0);
        }
      }
  }

  DEBUG_TIME(0);

  /* set object priorities for ghostelements */
  for (theElement=PFIRSTELEMENT(theGrid);
       theElement!=NULL;
       theElement=SUCCE(theElement))
  {
    if (PARTITION(theElement) == me) continue;

    if (USED(theElement) || THEFLAG(theElement))
    {
      prio = PRIO_CALC(theElement);
      PRINTDEBUG(gm,1,("SetGhostObjectPriorities(): e=" EID_FMTX " new prio=%d\n",
                       EID_PRTX(theElement),prio))
      SETEPRIOX(theElement,prio);

      if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,ELEMVEC))
      {
        theVector = EVECTOR(theElement);
        if (theVector != NULL)
          SETPRIOX(theVector,prio);
      }
    }

    /* set edge priorities */
    for (i=0; i<EDGES_OF_ELEM(theElement); i++)
    {

      theEdge = GetEdge(CORNER(theElement,CORNER_OF_EDGE(theElement,i,0)),
                        CORNER(theElement,CORNER_OF_EDGE(theElement,i,1)));
      ASSERT(theEdge != NULL);

      if (USED(theEdge) || THEFLAG(theEdge))
      {
        PRINTDEBUG(dddif,3,(PFMT " dddif_SetGhostObjectPriorities():"
                            " downgrade edge=" EDID_FMTX " from=%d to PrioHGhost\n",
                            me,EDID_PRTX(theEdge),prio));

        EDGE_PRIORITY_SET(theGrid,theEdge,PRIO_CALC(theEdge));
      }
      else
        EDGE_PRIORITY_SET(theGrid,theEdge,PrioMaster);
    }

                        #ifdef __THREEDIM__
    /* if one(all) of the side nodes is (are) a hghost (vghost) node   */
    /* then its a hghost (vghost) side vector                          */
    if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC))
      for (i=0; i<SIDES_OF_ELEM(theElement); i++)
      {
        if (USED(theVector) || THEFLAG(theVector))
          SETPRIOX(theVector,PRIO_CALC(theVector));
      }
                        #endif

  }
  /* to set also nodes which are at corners of the boundary   */
  /* set them through the node list                           */
  for (theNode=PFIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode))
  {
    /* check if its a master node */
    if (USED(theNode) || THEFLAG(theNode))
    {
      PRINTDEBUG(dddif,3,(PFMT " dddif_SetGhostObjectPriorities():"
                          " downgrade node=" ID_FMTX " from=%d to PrioHGhost\n",
                          me,ID_PRTX(theNode),prio));

      /* set node priorities of node to ghost */
      NODE_PRIORITY_SET(theGrid,theNode,PRIO_CALC(theNode))
    }
    else if (MODIFIED(theNode) == 0)