Ejemplo n.º 1
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb_ = CORBA::ORB_init (argc, argv);

      CORBA::Object_var object =
        orb_->resolve_initial_references ("InterfaceRepository");

      CORBA::Repository_var repo_ = CORBA::Repository::_narrow (object.in ());


      CORBA::ContainedSeq_var interfaces =
                  repo_->contents (CORBA::dk_Interface,    // Any type of contained object.
                                   1                       // Exclude parents of interfaces.
                                   );

      CORBA::ULong length = interfaces->length ();

      if (length != 1)
      {
        ACE_DEBUG ((LM_DEBUG, "CLIENT (%P): Incorrect number of elements in IFR - length is %d\n", length));
        return -1;
      }

      CORBA::ULong first_one = 0;

      CORBA::InterfaceDef_var the_interface =
            CORBA::InterfaceDef::_narrow (interfaces[first_one]);

      CORBA::String_var name = the_interface->name();

      if (ACE_OS::strcmp (name.in(), "int"))
      {
        ACE_DEBUG ((LM_DEBUG, "CLIENT (%P): Interface name has been munged - it is now %C\n",
                      name.in()));
        return -1;
      }


    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception ...");
      return -1;
    }
  return 0;
}
Ejemplo n.º 2
0
Archivo: main.cpp Proyecto: CCJY/ATCD
void printContents (const CORBA::ContainedSeq& cont)
{
  try
    {
      for (CORBA::ULong i = 0; i < cont.length(); ++i)
        {
          CORBA::Contained::Description_var topdesc = cont[i]->describe ();
          if (topdesc->kind == CORBA::dk_Interface)
            {
              CORBA::InterfaceDef_var intDef =
                CORBA::InterfaceDef::_narrow (cont[i]);

              CORBA::InterfaceDef::FullInterfaceDescription_var desc =
                intDef->describe_interface ();

              //printf ("-- %s:\n", desc->name.in ());

              for (CORBA::ULong j1 = 0; j1 < desc->operations.length (); ++j1)
                ACE_DEBUG ((LM_DEBUG,
                            "operation %C::%C\n",
                            desc->name.in (),
                            desc->operations[j1].name.in ()));

              for (CORBA::ULong j2 = 0; j2 < desc->attributes.length (); ++j2)
                ACE_DEBUG ((LM_DEBUG,
                            "attribute %C::%C\n",
                            desc->name.in (),
                            desc->attributes[j2].name.in ()));
            }
          else if (topdesc->kind == CORBA::dk_Module)
            {
              CORBA::ModuleDef_var moduleDef =
                CORBA::ModuleDef::_narrow (cont[i]);

              CORBA::ContainedSeq_var moduleContents =
                moduleDef->contents (CORBA::dk_all, 1);
              printContents (moduleContents.in ());
            }
        }
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("printContents");
      ACE_OS::exit(-1); // the test has failed!
    }
}
Ejemplo n.º 3
0
Archivo: main.cpp Proyecto: CCJY/ATCD
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
      CORBA::Object_var object =
        orb->resolve_initial_references ("InterfaceRepository");

      if (CORBA::is_nil (object.in ()))
        {
          ACE_ERROR_RETURN ((
              LM_ERROR,
              "Null objref from resolve_initial_references\n"),
             -1);
        }

      CORBA::Repository_var  ifr =
        CORBA::Repository::_narrow (object.in ());

      if (CORBA::is_nil (ifr.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "CORBA::Repository::_narrow failed\n"),
                            -1);
        }

      CORBA::ContainedSeq_var cont = ifr->contents (CORBA::dk_all, 0);

      printContents (cont.in ());

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("main");
      return -1;
    }

  return 0;
}
Ejemplo n.º 4
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
  {
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    CORBA::Object_var obj =
      orb->resolve_initial_references("InterfaceRepository");

    CORBA::Repository_var ifrRepo = CORBA::Repository::_narrow(obj.in());

    if (CORBA::is_nil(ifrRepo.in()))
    {
      ACE_DEBUG((LM_ERROR,
        ACE_TEXT("(%N) failed to narrow interface repository referece.\n")
        ));
      return -1;
    }

    CORBA::ContainedSeq_var repoContents = ifrRepo->contents(CORBA::dk_all, 1);

    ACE_DEBUG((LM_INFO,
      ACE_TEXT("%s: the interface repository contains %d elements.\n"),
      programLabel,
      repoContents->length()
      ));
    listContents(repoContents.in());

    return 0;
  }
  catch(const CORBA::Exception& ex)
  {
    std::cerr << "main() Caught CORBA::Exception : " << ex << std::endl;
  }
  return 1;
}
Ejemplo n.º 5
0
OCI_APT::ArgList *
OCI_APT::OperationTable::add_interface (CORBA::InterfaceDef_ptr intDef,
					const char * desired_op)
{
	bool want_attribute = false;
	if (desired_op && desired_op[0] == '_')
		want_attribute = ACE_OS::strncmp(desired_op+2,"et_",3) == 0;

	ACE_Write_Guard<ACE_RW_Thread_Mutex>(this->lock_);
	OCI_APT::ArgList *result = 0;
	CORBA::InterfaceDefSeq_var bases = intDef->base_interfaces ();
	CORBA::String_var *derived = new CORBA::String_var[bases->length()];
	CORBA::ULong n_bases = bases->length();
	CORBA::ULong i = 0;
	for (; i <= n_bases; i++)
	{
		CORBA::String_var rep_id = intDef->id();
		if (i == 0)
		{
			OCI_APT::ArgList *al = this->add_is_a (rep_id.in());
			if (!want_attribute && desired_op && ACE_OS::strcmp("_is_a",desired_op) == 0)
				result = al;
			else
				al->remove_ref();

			al = this->add_non_existent (rep_id.in());
			if (!want_attribute && desired_op && ACE_OS::strcmp("_non_existent",desired_op) == 0)
				result = al;
			else
				al->remove_ref();
		}

		CORBA::ContainedSeq_var attributes =
			intDef->contents (CORBA::dk_Attribute,1);
		CORBA::ULong n_ats = attributes->length();
		for (CORBA::ULong at = 0; at < n_ats; ++at)
		{
			CORBA::String_var attr_name = attributes[at]->name();
			CORBA::AttributeDef_var attr =
				CORBA::AttributeDef::_narrow (attributes[at]);
			CORBA::String_var attr_op =
				CORBA::string_alloc(ACE_OS::strlen(attr_name.in()) + 5);
			ACE_OS::strcpy(attr_op.inout(),"_get_");
			ACE_OS::strcat(attr_op.inout(),attr_name.in());
			OCI_APT::Operation *op_ptr = this->find_or_add(attr_op.in());
			OCI_APT::ArgList *arg_list =
				new OCI_APT::ArgList (0, 0, false);
			arg_list->result (attr->type());
			if (want_attribute && ACE_OS::strcmp (attr_op.in(),desired_op) == 0)
			{
				arg_list->add_ref();
				result = arg_list;
			}

			op_ptr->add_set (new OpArgs(rep_id.in(),arg_list));
			for (CORBA::ULong d = 0; d < i; d++)
				op_ptr->add_set (new OpArgs(derived[d],arg_list));
			arg_list->remove_ref();

			if (attr->mode() == CORBA::ATTR_READONLY)
				continue;

			attr_op.inout()[1] = 's'; // from _get_ to _set_
			op_ptr = this->find_or_add(attr_op.in());
			arg_list =
				new OCI_APT::ArgList (1, 0, false);
			arg_list->set_arg(0, attr->type(),CORBA::ARG_IN);
			arg_list->result (CORBA::_tc_void);
			if (want_attribute && ACE_OS::strcmp (attr_op.in(),desired_op) == 0)
			{
				arg_list->add_ref();
				result = arg_list;
			}

			op_ptr->add_set (new OpArgs(rep_id.in(),arg_list));
			for (CORBA::ULong d = 0; d < i; d++)
				op_ptr->add_set (new OpArgs(derived[d],arg_list));
			arg_list->remove_ref();

		}

		CORBA::ContainedSeq_var operations =
			intDef->contents (CORBA::dk_Operation,1);

		CORBA::ULong n_ops = operations->length ();
		for (CORBA::ULong op = 0; op < n_ops; ++op)
		{
			CORBA::String_var op_name = operations[op]->name();
			OCI_APT::Operation *op_ptr = this->find_or_add(op_name.in());

			CORBA::OperationDef_var opDef =
				CORBA::OperationDef::_narrow (operations[op]);
			CORBA::ParDescriptionSeq_var params = opDef->params ();
			CORBA::ExceptionDefSeq_var excepts = opDef->exceptions();

			int is_oneway = opDef->mode() == CORBA::OP_ONEWAY;
			OCI_APT::ArgList *arg_list =
				new OCI_APT::ArgList (params->length(),
						      excepts->length(),
						      is_oneway);
			if (!is_oneway)
				arg_list->result (opDef->result());

			for (CORBA::ULong p = 0; p < params->length (); ++p)
			{
				CORBA::Flags mode = CORBA::ARG_IN;
				if (params[p].mode == CORBA::PARAM_OUT)
					mode = CORBA::ARG_OUT;
				else if (params[p].mode == CORBA::PARAM_INOUT)
					mode = CORBA::ARG_INOUT;

				arg_list->set_arg(p, params[p].type.in(),mode);
			}

			for (CORBA::ULong e = 0; e < excepts->length (); ++e)
			{
				CORBA::TypeCode_var tc = excepts[e]->type();
				arg_list->set_excep(e, tc.in());
			}

			if (!want_attribute && desired_op && ACE_OS::strcmp(op_name,desired_op) == 0)
			{
				arg_list->add_ref();
				result = arg_list;
			}

			op_ptr->add_set (new OpArgs(rep_id.in(),arg_list));
			for (CORBA::ULong d = 0; d < i; d++)
				op_ptr->add_set (new OpArgs(derived[d],arg_list));
			arg_list->remove_ref();
		}

		if (i < bases->length())
		{
			derived[i] = rep_id;
			intDef = bases[i];
		}
	}
	delete [] derived;
	return result;
}
Ejemplo n.º 6
0
Archivo: client.cpp Proyecto: CCJY/ATCD
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  //init IFR objref
  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      TAO_IFR_Client_Adapter *ifr_client =
        ACE_Dynamic_Service<TAO_IFR_Client_Adapter>::instance (
          TAO_ORB_Core::ifr_client_adapter_name ());

      if (ifr_client == 0)
        {
          throw ::CORBA::INTF_REPOS ();
        }

      ACE_DEBUG ((LM_DEBUG, "Got IFR_Client ref.\n"));

      CORBA::InterfaceDef_var intDef =
        ifr_client->get_interface (orb.in (), "IDL:IFR_Test/test_if:1.0");

      if (CORBA::is_nil (intDef.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                            "get interface returned nil ref\n"),
                            1);
        }

      CORBA::ContainedSeq_var attributes =
        intDef->contents (CORBA::dk_Attribute, 1);
      CORBA::ULong n_ats = attributes->length ();

      CORBA::ULong index = 0UL;
      CORBA::String_var name = attributes[index]->name ();
      ACE_DEBUG ((LM_DEBUG,
                  "found %d attributes, name = %s\n",
                  n_ats,
                  name.in ()));

      CORBA::AttributeDef_var attr =
        CORBA::AttributeDef::_narrow (attributes[index]);

      if (CORBA::is_nil (attr.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                            "could not narrow attribute ref\n"),
                            1);
        }

      CORBA::TypeCode_var tc = attr->type ();

      ACE_DEBUG ((LM_DEBUG, "foo attr typecode = %s\n", tc->id ()));
    }
  catch (const ::CORBA::Exception &ex)
    {
      ex._tao_print_exception("ERROR : unexpected CORBA exception caugth :");
      return 1;
    }

  return 0;
}
Ejemplo n.º 7
0
void listContents(const CORBA::ContainedSeq& repoContents)
{
  //
  // List the contents of each element.
  //
  for(unsigned int i = 0; i < repoContents.length(); ++i)
  {
    CORBA::Contained::Description_var desc = repoContents[i]->describe();
    switch(desc->kind)
    {
    case CORBA::dk_Constant:
      ACE_DEBUG((LM_INFO,
        ACE_TEXT("%s: element[%d] is a constant definition.\n"),
        programLabel,
        i + 1
        ));
      break;
    case CORBA::dk_Typedef:
      ACE_DEBUG((LM_INFO,
        ACE_TEXT("%s: element[%d] is a typedef definition.\n"),
        programLabel,
        i + 1
        ));
      break;
    case CORBA::dk_Exception:
      ACE_DEBUG((LM_INFO,
        ACE_TEXT("%s: element[%d] is an exception definition.\n"),
        programLabel,
        i + 1
        ));
      break;
    case CORBA::dk_Interface:
      {
        ACE_DEBUG((LM_INFO,
          ACE_TEXT("%s: element[%d] is an interface definition.\n")
          ACE_TEXT("%s: listing element[%d]...\n"),
          programLabel,
          i + 1,
          programLabel,
          i + 1
          ));
        CORBA::InterfaceDef_var interfaceDef =
          CORBA::InterfaceDef::_narrow(repoContents[i]);
        listInterface(interfaceDef.in());
        break;
      }
    case CORBA::dk_Module: {
      ACE_DEBUG((LM_INFO,
        ACE_TEXT("%s: element[%d] is a module definition.\n"),
        programLabel,
        i + 1
        ));
      CORBA::ModuleDef_var moduleDef =
        CORBA::ModuleDef::_narrow(repoContents[i]);
      CORBA::ContainedSeq_var moduleContents =
        moduleDef->contents(CORBA::dk_all,1);
      CORBA::String_var moduleId = moduleDef->id();
      CORBA::String_var moduleName = moduleDef->name();

      ACE_DEBUG((LM_INFO,
        ACE_TEXT("%s:\n// %s\nmodule %s\n{\n")
        ACE_TEXT("%s: the module contains %d elements.\n"),
        programLabel,
        moduleId.in(),
        moduleName.in(),
        programLabel,
        moduleContents->length()
        ));
      listContents(moduleContents.in());
      ACE_DEBUG((LM_INFO, ACE_TEXT("}\n")));
      break;
                           }
    default:
      break;
    }
  }
}