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

📄 log_constraint_visitors.cpp

📁 这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用于网络游戏医学图像网关的高qos要求.更详细的内容可阅读相应的材料
💻 CPP
📖 第 1 页 / 共 3 页
字号:
#include "Log_Constraint_Visitors.h"

#include "orbsvcs/ETCL/ETCL_Constraint.h"
#include "orbsvcs/ETCL/ETCL_y.h"

#include "tao/DynamicAny/DynArray_i.h"
#include "tao/DynamicAny/DynSequence_i.h"
#include "tao/DynamicAny/DynStruct_i.h"
#include "tao/DynamicAny/DynUnion_i.h"
#include "tao/DynamicAny/DynEnum_i.h"
#include "tao/DynamicAny/DynAnyFactory.h"

#include "tao/Any_Unknown_IDL_Type.h"

ACE_RCSID (Log,
           Log_Constraint_Visitors,
           "Log_Constraint_Visitors.cpp,v 1.10 2003/10/28 18:34:23 bala Exp")

TAO_Log_Constraint_Visitor::TAO_Log_Constraint_Visitor (
  DsLogAdmin::LogRecord &rec)
  :rec_ (rec)
{
  ACE_CString name1 = (ACE_CString)"id";
  ACE_CString name2 = (ACE_CString)"time";
  ACE_CString name3 = (ACE_CString)"info";

  CORBA::Any *value = 0;
  ACE_NEW (value, CORBA::Any);

#if defined (ACE_LACKS_LONGLONG_T)
  *value <<= ACE_U64_TO_U32 (this->rec_.id);
#else
  *value <<= ACE_static_cast (ACE_UINT32, (this->rec_.id));
#endif
  if (value != 0)
    {
      // @@ Where's the error check?
      this->property_lookup_.bind (name1, value);
    }

  CORBA::Any *value2 = 0;
  ACE_NEW (value2, CORBA::Any);

#if defined (ACE_LACKS_LONGLONG_T)
  *value2 <<= ACE_U64_TO_U32 (this->rec_.time)
#else
  *value2 <<= ACE_static_cast (ACE_UINT32, (this->rec_.time));
#endif
  if (value2 != 0)
    {
      // @@ Where's the error check?
      this->property_lookup_.bind (name2, value2);
    }

  CORBA::Any *value3 = 0;
  ACE_NEW (value3, CORBA::Any);

  *value3 <<= this->rec_.info;

  if (value3 != 0)
    {
      // @@ Where's the error check?
      this->property_lookup_.bind (name3, value3);
    }
}

CORBA::Boolean
TAO_Log_Constraint_Visitor::evaluate_constraint (TAO_ETCL_Constraint* root)
{
  CORBA::Boolean result = 0;
  this->queue_.reset ();

  // Evaluate the constraint in root_;
  if (root != 0)
    {
      if ((root->accept (this) == 0) &&
          (! this->queue_.is_empty ()))
        {
          TAO_ETCL_Literal_Constraint top;
          this->queue_.dequeue_head (top);
          result = (CORBA::Boolean) top;
        }
    }

  // If a property couldn't be evaluated we must return 0.
  return result;
}

int
TAO_Log_Constraint_Visitor::visit_literal (
    TAO_ETCL_Literal_Constraint *literal
  )
{
  this->queue_.enqueue_head (*literal);
  return 0;
}

int
TAO_Log_Constraint_Visitor::visit_identifier (TAO_ETCL_Identifier *ident)
{
  int return_value = -1;
  const char *name = ident->value ();
  ACE_CString key (name, 0, 0);

  CORBA::Any *any = 0;

  if (this->property_lookup_.find (key, any) == 0)
    {
      if (any != 0)
        {
          this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (any));
          return_value = 0;
        }
    }

  return return_value;
}

int
TAO_Log_Constraint_Visitor::visit_union_value (
    TAO_ETCL_Union_Value *union_value
  )
{
  switch (union_value->sign ())
  {
    case 0:
      this->queue_.enqueue_head (*union_value->string ());
      break;
    case -1:
      this->queue_.enqueue_head (-(*union_value->integer ()));
      break;
    case 1:
      this->queue_.enqueue_head (*union_value->integer ());
      break;
    default:
      return -1;
  }

  return 0;
}

int
TAO_Log_Constraint_Visitor::visit_union_pos (
    TAO_ETCL_Union_Pos *union_pos
  )
{
  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      if (union_pos->union_value ()->accept (this) == 0)
        {
          TAO_ETCL_Literal_Constraint disc_val;
          this->queue_.dequeue_head (disc_val);

          TAO_DynUnion_i dyn_union;
          dyn_union.init (this->current_member_.in ()
                          ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          CORBA::TypeCode_var tc = this->current_member_->type ();

          switch (disc_val.expr_type ())
          {
            case TAO_ETCL_INTEGER:
            case TAO_ETCL_SIGNED:
            case TAO_ETCL_UNSIGNED:
              {
                CORBA::Any disc_any;
                CORBA::TypeCode_var disc_tc =
                  tc->discriminator_type (ACE_ENV_SINGLE_ARG_PARAMETER);
                ACE_TRY_CHECK;
                CORBA::TCKind disc_kind =
                  TAO_DynAnyFactory::unalias (disc_tc.in ()
                                              ACE_ENV_ARG_PARAMETER);
                ACE_TRY_CHECK;

                switch (disc_kind)
                {
                  case CORBA::tk_boolean:
                    disc_any <<= CORBA::Any::from_boolean ((CORBA::Boolean) disc_val);
                    break;
                  case CORBA::tk_short:
                    disc_any <<= (CORBA::Short) ((CORBA::Long) disc_val);
                    break;
                  case CORBA::tk_ushort:
                    disc_any <<= (CORBA::UShort) ((CORBA::ULong) disc_val);
                    break;
                  case CORBA::tk_long:
                    disc_any <<= (CORBA::Long) disc_val;
                    break;
                  case CORBA::tk_ulong:
                    disc_any <<= (CORBA::ULong) disc_val;
                    break;
                  case CORBA::tk_enum:
                    {
                      TAO_OutputCDR cdr;
                      cdr.write_ulong ((CORBA::ULong) disc_val);

                      TAO::Unknown_IDL_Type *unk = 0;
                      ACE_NEW_RETURN (unk,
                                      TAO::Unknown_IDL_Type (
                                          disc_tc.in (),
                                          cdr.begin (),
                                          TAO_ENCAP_BYTE_ORDER
                                        ),
                                      -1);

                      disc_any.replace (unk);
                      break;
                    }
                  // @@@ (JP) I don't think ETCL handles 64-bit
                  // integers at this point, and I also think that
                  // chars and/or wchars will just come out in the
                  // constraint as (w)strings of length 1.
                  case CORBA::tk_longlong:
                  case CORBA::tk_ulonglong:
                  case CORBA::tk_char:
                  case CORBA::tk_wchar:
                  default:
                    return -1;
                }

                DynamicAny::DynAny_var dyn_any =
                  TAO_DynAnyFactory::make_dyn_any (disc_any
                                                   ACE_ENV_ARG_PARAMETER);
                ACE_TRY_CHECK;
                dyn_union.set_discriminator (dyn_any.in ()
                                             ACE_ENV_ARG_PARAMETER);
                ACE_TRY_CHECK;
                DynamicAny::DynAny_var u_member =
                  dyn_union.member (ACE_ENV_SINGLE_ARG_PARAMETER);
                ACE_TRY_CHECK;
                this->current_member_ =
                  u_member->to_any (ACE_ENV_SINGLE_ARG_PARAMETER);
                ACE_TRY_CHECK;

                break;
              }
            case TAO_ETCL_STRING:
              {
                const char *name = (const char *) disc_val;
                CORBA::ULong count =
                  tc->member_count (ACE_ENV_SINGLE_ARG_PARAMETER);
                ACE_TRY_CHECK;

                const char *member_name = 0;
                CORBA::ULong i = 0;

                for (i = 0; i < count; ++i)
                  {
                    member_name = tc->member_name (i
                                                   ACE_ENV_ARG_PARAMETER);
                    ACE_TRY_CHECK;

                    if (ACE_OS::strcmp (name, member_name) == 0)
                      {
                        break;
                      }
                  }

                // If there's no match, member_label will throw
                // CORBA::TypeCode::Bounds and the catch block will
                // return -1;
                this->current_member_ = tc->member_label (i
                                                          ACE_ENV_ARG_PARAMETER);
                ACE_TRY_CHECK;

                break;
              }
            // The TAO_ETCL_Union_Value that was put on the queue
            // shouldn't have any other type.
            default:
              return -1;
          }

          TAO_ETCL_Constraint *nested = union_pos->component ();

          // If there's no nested component, then we just want the
          // union member value on the queue. Otherwise, we want
          // the member value in current_member_ while we visit
          // the nested component.
          if (nested == 0)
            {
              TAO_ETCL_Literal_Constraint lit (this->current_member_);
              this->queue_.enqueue_head (lit);
              return 0;
            }
          else
            {
              return nested->accept (this);
            }
        }
      else
        {
          return -1;
        }
    }
  ACE_CATCHANY
    {
      return -1;
    }
  ACE_ENDTRY;
  ACE_CHECK_RETURN (-1);

  return 0;
}

int
TAO_Log_Constraint_Visitor::visit_component_pos (TAO_ETCL_Component_Pos *pos)
{
  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      // If we are here (from visit_component) the Any containing the
      // component as found in property_lookup_ will be in current_member_.
      CORBA::TypeCode_var tc = this->current_member_->type ();
      CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc.in ()
                                                       ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      DynamicAny::DynAny_var member;
      CORBA::Boolean success = 0;
      CORBA::ULong slot = (CORBA::ULong) *pos->integer ();

      switch (kind)
      {
        case CORBA::tk_enum:
          {
            TAO_DynEnum_i dyn_enum;
            dyn_enum.init (this->current_member_.in ()
                           ACE_ENV_ARG_PARAMETER);
            ACE_TRY_CHECK;

            success = dyn_enum.seek (slot
                                     ACE_ENV_ARG_PARAMETER);
            ACE_TRY_CHECK;

            if (success == 0)
              {
                return -1;
              }

            member =
              dyn_enum.current_component (ACE_ENV_SINGLE_ARG_PARAMETER);
            ACE_TRY_CHECK;

            break;
          }
        case CORBA::tk_struct:
          {
            TAO_DynStruct_i dyn_struct;
            dyn_struct.init (this->current_member_.in ()
                             ACE_ENV_ARG_PARAMETER);
            ACE_TRY_CHECK;

            success = dyn_struct.seek (slot
                                       ACE_ENV_ARG_PARAMETER);
            ACE_TRY_CHECK;

            if (success == 0)
              {
                return -1;
              }

            member = dyn_struct.current_component (ACE_ENV_SINGLE_ARG_PARAMETER);
            ACE_TRY_CHECK;

            break;
          }
        // @@@ (JP) I think enums and structs are the only two cases handled
        // by Component_Pos, since arrays and sequences are handled by
        // Component_Array, and unions are handled by Union_Pos.
        default:
          return -1;
      }

      CORBA::Any_var value = member->to_any (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      TAO_ETCL_Constraint *comp = pos->component ();

      if (comp == 0)
        {
          TAO_ETCL_Literal_Constraint result (value);
          this->queue_.enqueue_head (result);
          return 0;
        }
      else
        {
          this->current_member_ = value._retn ();
          return comp->accept (this);
        }
    }
  ACE_CATCHANY
    {
      return -1;
    }
  ACE_ENDTRY;
  ACE_CHECK_RETURN (-1);

  return 0;
}

int
TAO_Log_Constraint_Visitor::visit_component_assoc (
  TAO_ETCL_Component_Assoc *assoc)
{
  // @@@ (JP) The spec reserves this type of constraint for NVLists.
  // Since NVLists don't have type codes or Any operators, there's
  // no way that TAO can put one into the event's filterable data.
  // However, from the looks of the ETCL grammar, I believe that a
  // contruct like 'exist $(foo)' is legal, and is in effect using
  // the event's filterable data as one big NVList. It is
  // equivalent to '$.foo'. I've implemented this method on that
  // basis, while keeping in mind that a clearer interpretation of
  // the spec may come along someday.

  const char *name = assoc->identifier ()->value ();
  ACE_CString key (name, 0, 0);
  CORBA::Any *any = 0;

  if (this->property_lookup_.find (key, any) != 0
      || any == 0)
    {
      return -1;
    }

  TAO_ETCL_Constraint *comp = assoc->component ();

  if (comp == 0)
    {
      TAO_ETCL_Literal_Constraint result (any);
      this->queue_.enqueue_head (result);
      return 0;
    }
  else
    {
      CORBA::Any *any_ptr = 0;
      ACE_NEW_RETURN (any_ptr,
                      CORBA::Any (*any),
                      -1);
      this->current_member_ = any_ptr;
      return comp->accept (this);
    }
}

int
TAO_Log_Constraint_Visitor::visit_component_array (
    TAO_ETCL_Component_Array *array
  )
{
  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      // If we are here (from visit_component) the Any containing the
      // component as found in property_lookup_ will be in current_member_.
      CORBA::TypeCode_var tc = this->current_member_->type ();
      CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc.in ()
                                                       ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      DynamicAny::DynAny_var member;
      CORBA::Boolean success = 0;
      CORBA::ULong slot = (CORBA::ULong) *array->integer ();

      switch (kind)
      {

⌨️ 快捷键说明

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