⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 context.cc

📁 编译工具
💻 CC
📖 第 1 页 / 共 2 页
字号:
  if( delete_me )  delete this;}intContextImpl::matchPattern(const char* pattern, CORBA::ULong& bottom_out,			  CORBA::ULong& top_out) const{  if( !pattern || !*pattern )    OMNIORB_THROW(BAD_PARAM,BAD_PARAM_EmptyContextPattern,CORBA::COMPLETED_NO);  size_t pat_len = strlen(pattern);  int wildcard = 0;  if( pattern[pat_len - 1] == '*' ){    wildcard = 1;    pat_len--;  }  CORBA::ULong count = pd_entries.length();  CORBA::ULong bottom = 0;  CORBA::ULong top = count;  int match = 0;  if (wildcard && pat_len == 0) {    // Match everything    bottom_out = bottom;    top_out = top;    return (top != bottom);  }  // Find a match (binary search).  while( bottom < top ){    CORBA::ULong i = (bottom + top) / 2;    int cmp;    if( wildcard )  cmp = ::strncasecmp(pattern, pd_entries[i].name, pat_len);    else            cmp = ::strcasecmp(pattern, pd_entries[i].name);    if( cmp < 0 )       top = i;    else if( cmp > 0 )  bottom = (bottom == i) ? i + 1 : i;    else{      match = 1;      bottom = i;      break;    }  }  if( !match )  return 0;  if( wildcard ){    top = bottom + 1;    while( bottom > 0 &&	   !strncasecmp(pattern, pd_entries[bottom - 1].name, pat_len) )      bottom--;    while( top < count &&	   !strncasecmp(pattern, pd_entries[top].name, pat_len) )      top++;    bottom_out = bottom;    top_out = top;  }else{    bottom_out = bottom;    top_out = bottom + 1;  }  return 1;}voidContextImpl::add_values(ContextImpl* c, CORBA::Flags op_flags,			const char* pattern, int wildcard,			CORBA::NVList_ptr val_list){  if (!CORBA::NVList::PR_is_valid(val_list))    OMNIORB_THROW(BAD_PARAM, BAD_PARAM_InvalidNVList, CORBA::COMPLETED_NO);  CORBA::ULong bottom, top;  do{    omni_tracedmutex_lock lock(c->pd_lock);    if( c->matchPattern(pattern, bottom, top) ){      for( CORBA::ULong i = bottom; i < top; i++ ){	CORBA::ULong val_list_count = val_list->count();	Entry* e = &(c->pd_entries[i]);	// Search val_list to see if it already has entry for this name	// (not very efficient).	CORBA::ULong j;	for( j = 0; j < val_list_count; j++ )	  if( !strcasecmp(e->name, val_list->item(j)->name()) )	    break;	if( j == val_list_count ){	  char* name = CORBA::string_dup(e->name);	  CORBA::Any* value = new CORBA::Any();	  *value <<= (const char*)e->value;	  val_list->add_value_consume(name, value, CORBA::Flags(0));	}      }      // pattern does not have a '*', so only one match required      if( !wildcard )  return;    }    if( (op_flags & CORBA::CTX_RESTRICT_SCOPE) || CORBA::is_nil(c->pd_parent) )      return;    c = (ContextImpl*)c->pd_parent;  }while( 1 );}voidContextImpl::check_context_name(const char* n){  if( !isalpha(*n++) )  OMNIORB_THROW(BAD_PARAM,				      BAD_PARAM_InvalidContextName,				      CORBA::COMPLETED_NO);  while( isalnum(*n) || *n == '_' )  n++;  if( *n != '\0' )  OMNIORB_THROW(BAD_PARAM,				  BAD_PARAM_InvalidContextName,				  CORBA::COMPLETED_NO);}voidContextImpl::check_property_name(const char* n){  do{    if( !isalpha(*n++) )  OMNIORB_THROW(BAD_PARAM,					BAD_PARAM_InvalidContextName,					CORBA::COMPLETED_NO);    while( isalnum(*n) || *n == '_' )  n++;  }while( *n == '.' && (n++,1) );  if( *n != '\0' )  OMNIORB_THROW(BAD_PARAM,				  BAD_PARAM_InvalidContextName,				  CORBA::COMPLETED_NO);}voidContextImpl::loseChild(ContextImpl* child){  CORBA::Boolean delete_me = 0;  {    // This lock guarentees that no other thread will be accessing the    // list of children - as a context's list of siblings is managed by    // its parent.    omni_tracedmutex_lock sync(pd_lock);    // Find the pointer to <child> in the list of dependents.    ContextImpl** p = &pd_children;    while( *p && *p != child )  p = &(*p)->pd_nextSibling;    if( !*p )  throw omniORB::fatalException(__FILE__,__LINE__,					     "ContextImpl::loseChild()");    // Remove <child> from the list.    *p = (*p)->pd_nextSibling;    if( pd_refCount == 0 && !pd_children )      delete_me = 1;  }  if( delete_me )  delete this;}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////class omniNilContext : public CORBA::Context, public omniTrackedObject {public:  virtual const char* context_name() const {    _CORBA_invoked_nil_pseudo_ref();    return 0;  }  virtual CORBA::Context_ptr parent() const {    _CORBA_invoked_nil_pseudo_ref();    return _nil();  }  virtual void create_child(const char*, CORBA::Context_out) {    _CORBA_invoked_nil_pseudo_ref();    }  virtual void set_one_value(const char*, const CORBA::Any&) {    _CORBA_invoked_nil_pseudo_ref();    }  virtual void set_values(CORBA::NVList_ptr) {    _CORBA_invoked_nil_pseudo_ref();    }  virtual void delete_values(const char*) {    _CORBA_invoked_nil_pseudo_ref();    }  virtual void get_values(const char* start_scope,				   CORBA::Flags op_flags,				   const char* pattern,				   CORBA::NVList_out values) {    _CORBA_invoked_nil_pseudo_ref();    }  virtual CORBA::Boolean NP_is_nil() const {    return 1;  }  virtual CORBA::Context_ptr NP_duplicate() {    return _nil();  }};OMNI_NAMESPACE_END(omni)OMNI_USING_NAMESPACE(omni)///////////////////////////////////////////////////////////////////////////////////////////////////// Context ////////////////////////////////////////////////////////////////////////////////////////////////////CORBA::Context::~Context() { pd_magic = 0; }CORBA::Context_ptrCORBA::Context::_duplicate(Context_ptr p){  if (!PR_is_valid(p))    OMNIORB_THROW(BAD_PARAM, BAD_PARAM_InvalidContext, CORBA::COMPLETED_NO);  if( !CORBA::is_nil(p) ) {    ContextImpl* c = (ContextImpl*) p;    omni_tracedmutex_lock sync(c->pd_lock);    c->pd_refCount++;    return c;  }  else    return _nil();}CORBA::Context_ptrCORBA::Context::_nil(){  static omniNilContext* _the_nil_ptr = 0;  if( !_the_nil_ptr ) {    omni::nilRefLock().lock();    if( !_the_nil_ptr ) {      _the_nil_ptr = new omniNilContext;      registerTrackedObject(_the_nil_ptr);    }    omni::nilRefLock().unlock();  }  return _the_nil_ptr;}voidCORBA::Context::marshalContext(CORBA::Context_ptr ctxt,			       const char*const* which,			       int whichlen, cdrStream& s){  if( CORBA::is_nil(ctxt) ) {    CORBA::ULong(0) >>= s;    return;  }  ContextImpl* c = (ContextImpl*) ctxt;  _CORBA_Unbounded_Sequence_String seq;  CORBA::ULong l = 0;  do {    omni_tracedmutex_lock sync(c->pd_lock);    int i;    CORBA::ULong top, bottom, j;    for (i=0; i < whichlen; i++) {      CORBA::ULong curr_len = l;      if (c->matchPattern(which[i], bottom, top)) {	for (; bottom < top; bottom++) {	  ContextImpl::Entry* e = &(c->pd_entries[bottom]);	  // Very inefficiently look to see if we've already added this name	  for (j=0; j < curr_len; j+=2)	    if (!strcasecmp(seq[j], e->name))	      break;	  if (j == curr_len) {	    l += 2;	    if (l > seq.maximum()) seq.length(l * 6 / 5 + 2);	    seq.length(l);	    seq[l-2] = (const char*)e->name;	    seq[l-1] = (const char*)e->value;	  }	}      }    }    if (CORBA::is_nil(c->pd_parent)) break;    c = (ContextImpl*)c->pd_parent;  } while(1);  // Now marshal the sequence  seq.length() >>= s;  for (CORBA::ULong i=0; i < seq.length(); i++)    s.marshalRawString(seq[i]);}CORBA::Context_ptrCORBA::Context::unmarshalContext(cdrStream& s){  CORBA::ULong nentries;  nentries <<= s;  if( nentries % 2 )  OMNIORB_THROW(MARSHAL,				    MARSHAL_InvalidContextList,				    CORBA::COMPLETED_MAYBE);  nentries /= 2;  ContextImpl* c = new ContextImpl("", CORBA::Context::_nil());  try {    for( CORBA::ULong i = 0; i < nentries; i++ ) {      char* name  = s.unmarshalRawString();      char* value = s.unmarshalRawString();      c->insert_single_consume(name, value);    }  }  catch(...) {    delete c;    throw;  }  return c;}CORBA::Context_ptrCORBA::Context::filterContext(CORBA::Context_ptr ctxt,			      const char*const* which,			      int whichlen){  ContextImpl* ret = new ContextImpl("", CORBA::Context::_nil());  if (CORBA::is_nil(ctxt))    return ret;  if (!PR_is_valid(ctxt))    OMNIORB_THROW(BAD_PARAM, BAD_PARAM_InvalidContext, CORBA::COMPLETED_NO);  ContextImpl* c = (ContextImpl*)ctxt;  do {    omni_tracedmutex_lock sync(c->pd_lock);    int i;    CORBA::ULong top, bottom, j, z1, z2;    for (i=0; i < whichlen; i++) {      if (c->matchPattern(which[i], bottom, top)) {	for (; bottom < top; bottom++) {	  ContextImpl::Entry* e = &(c->pd_entries[bottom]);	  // See if already added	  if (ret->matchPattern(e->name, z1, z2))	    continue;	  ret->insert_single_consume(CORBA::string_dup(e->name),				     CORBA::string_dup(e->value));	}      }    }    if (CORBA::is_nil(c->pd_parent)) break;    c = (ContextImpl*)c->pd_parent;  } while(1);  return ret;}////////////////////////////////////////////////////////////////////////////////////////////////////// CORBA /////////////////////////////////////////////////////////////////////////////////////////////////////voidCORBA::release(CORBA::Context_ptr p){  if( CORBA::Context::PR_is_valid(p) && !CORBA::is_nil(p) )    ((ContextImpl*)p)->decrRefCount();}voidCORBA::ORB::get_default_context(CORBA::Context_out context_out){  if( !default_context )    default_context = new ContextImpl("default", CORBA::Context::_nil());  context_out = CORBA::Context::_duplicate(default_context);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -