diff options
author | Johnny Willemsen <jwillemsen@remedy.nl> | 2008-10-23 08:18:15 +0000 |
---|---|---|
committer | Johnny Willemsen <jwillemsen@remedy.nl> | 2008-10-23 08:18:15 +0000 |
commit | ed37afe58ed28bf9b04e1f74e06510c4d2ff38e4 (patch) | |
tree | 361719952171facf0d419fbde903eaff9754f95e /TAO/orbsvcs/DevGuideExamples/InterfaceRepo | |
parent | f4dff7911a76550ca5c512237b57ce07d6c3ec60 (diff) | |
download | ATCD-ed37afe58ed28bf9b04e1f74e06510c4d2ff38e4.tar.gz |
Thu Oct 23 07:54:00 UTC 2008 Johnny Willemsen <jwillemsen@remedy.nl>
* DevGuideExamples/EventServices
* DevGuideExamples/ImplRepo
* DevGuideExamples/InterfaceRepo
* DevGuideExamples/NamingService
* DevGuideExamples/NotifyService
* DevGuideExamples/Security
Moved these directories to orbsvcs/DevGuideExamples, that makes
it much easier to just build the core examples
Diffstat (limited to 'TAO/orbsvcs/DevGuideExamples/InterfaceRepo')
4 files changed, 384 insertions, 0 deletions
diff --git a/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/IFRBrowser.cpp b/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/IFRBrowser.cpp new file mode 100644 index 00000000000..944aef0f190 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/IFRBrowser.cpp @@ -0,0 +1,279 @@ +// $Id$ + +// +// IFRBrowser.cpp +// +// A rudimentary interface repository +// browser, very rudimentary +// + +#include "tao/IFR_Client/IFR_BasicC.h" +#include "tao/ORB.h" +#include "ace/Log_Msg.h" + +#include <iostream> + +const char* programLabel = "IFR Browser"; + +void listContents(const CORBA::ContainedSeq &repoContents); +void listInterface(CORBA::InterfaceDef_ptr interfaceDef); +void listOperation(CORBA::OperationDescription* operationDescr); +void listParameter(CORBA::ParameterDescription* parameterDescr); + +const char* decodeTypeCode(const CORBA::TypeCode_ptr typeCode); +const char* decodeParameterMode(CORBA::ParameterMode mode); +const char* decodeOperationMode(CORBA::OperationMode mode); + +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; +} + +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; + } + } +} + +void listInterface(CORBA::InterfaceDef_ptr interfaceDef) +{ + CORBA::InterfaceDef::FullInterfaceDescription_var fullDescr = + interfaceDef->describe_interface(); + + const char* interfaceName = + fullDescr->name; + const char* interfaceRepoId = + fullDescr->id; + + ACE_DEBUG((LM_INFO, + ACE_TEXT("%s:\n\t// %s\n\tinterface %s\n\t{"), + programLabel, + interfaceRepoId, + interfaceName + )); + + + unsigned int operationsCount; + if ((operationsCount = fullDescr->operations.length()) > 0) + { + for(unsigned int i = 0; i < operationsCount; ++i) + { + listOperation(&(fullDescr->operations[i])); + } + } + + unsigned int attributesCount; + if ((attributesCount = fullDescr->attributes.length()) > 0) + { + ACE_DEBUG((LM_INFO, + ACE_TEXT("%s: %s has %d attribute(s).\n"), + programLabel, + interfaceName, + attributesCount + )); + } + + ACE_DEBUG((LM_INFO, "\n\t}\n")); +} + +void listOperation(CORBA::OperationDescription* operationDescr) +{ + const char* operationName = + operationDescr->name; + const char* operationRepoId = + operationDescr->id; + const char* operationResult = + decodeTypeCode(operationDescr->result.in()); + const char* operationMode = + decodeOperationMode(operationDescr->mode); + + ACE_DEBUG((LM_INFO, + ACE_TEXT("\n\t\t// %s \n\t\t%s %s %s"), + operationRepoId, + operationResult, + operationName, + operationMode + )); + + CORBA::ParDescriptionSeq* params = &(operationDescr->parameters); + CORBA::ULong paramsCount = params->length(); + if (paramsCount > 0) + { + ACE_DEBUG((LM_INFO, "\n\t\t(\n\t\t")); + for(CORBA::ULong i =0; i < paramsCount; ++i) + { + listParameter(&((*params)[i])); + if(i < (paramsCount - 1)) + { + ACE_DEBUG((LM_INFO, ",\n\t\t")); + } + } + ACE_DEBUG((LM_INFO, "\n\t\t);\n")); + } + else + { + ACE_DEBUG((LM_INFO, "();\n")); + } +} + +void listParameter(CORBA::ParameterDescription *parameterDescr) +{ + const char *typCode = + decodeTypeCode(parameterDescr->type.in()); + const char *paramMode = + decodeParameterMode(parameterDescr->mode); + ACE_DEBUG((LM_INFO, + ACE_TEXT("%s %s %s"), + paramMode, + typCode, + parameterDescr->name.in() + )); +} + +const char* decodeTypeCode(const CORBA::TypeCode_ptr typeCode) +{ + const char* code = ""; + if (typeCode->equivalent(CORBA::_tc_void)) { + code = "void"; + } else if (typeCode->equivalent(CORBA::_tc_boolean)) { + code = "boolean"; + } else if (typeCode->equivalent(CORBA::_tc_string)) { + code = "string"; + } + return code; +} + +const char* decodeParameterMode(CORBA::ParameterMode mode) +{ + const char* paramMode; + switch(mode) + { + case CORBA::PARAM_IN: + { + paramMode = "in"; + break; + } + case CORBA::PARAM_OUT: + { + paramMode = "out"; + break; + } + case CORBA::PARAM_INOUT: + { + paramMode = "inout"; + break; + } + default: + paramMode = ""; + } + return paramMode; +} + +const char* decodeOperationMode(CORBA::OperationMode mode) +{ + return (mode == CORBA::OP_NORMAL) ? "synchronous" : "asynchronous"; +} diff --git a/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/InterfaceRepo.mpc b/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/InterfaceRepo.mpc new file mode 100644 index 00000000000..84c40a3a130 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/InterfaceRepo.mpc @@ -0,0 +1,5 @@ +// $Id$ + +project(*Browser): taoexe, portableserver, ifr_client { + exename = IFRBrowser +} diff --git a/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/run_test.pl b/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/run_test.pl new file mode 100755 index 00000000000..70c47951eb8 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/run_test.pl @@ -0,0 +1,86 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use Env (TAO_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$status = 0; + +$ifr_iorfile= "if_repo.ior"; + +$ifr_server = "$ENV{TAO_ROOT}/orbsvcs/IFR_Service/IFR_Service"; +$tao_ifr = "$ENV{ACE_ROOT}/bin/tao_ifr"; +$test_idl = "test.idl"; + +$lookup_by_name = ""; +$other = ""; + +for ($i = 0; $i <= $#ARGV; $i++) { + if ($ARGV[$i] eq "-n") { + $lookup_by_name = "-n"; + } + else { + $other .= $ARGV[$i]; + } +} + +$TAO_IFR = new PerlACE::Process ($tao_ifr); +$IFR = new PerlACE::Process ($ifr_server); +$CL = new PerlACE::Process ("IFRBrowser", "-ORBInitRef InterfaceRepository=file://$ifr_iorfile $lookup_by_name"); + +# We want the tao_ifr executable to be found exactly in the path +# given, without being modified by the value of -ExeSubDir. +# So, we tell its Process object to ignore the setting of -ExeSubDir. + +$TAO_IFR->IgnoreExeSubDir (1); + +unlink $ifr_iorfile; + +$IFR->Spawn (); + +if (PerlACE::waitforfile_timed ($ifr_iorfile, 15) == -1) { + print STDERR "ERROR: cannot find file <$ifr_iorfile>\n"; + $IFR->Kill (); + exit 1; +} + +$TAO_IFR->Arguments ("-ORBInitRef InterfaceRepository=file://$ifr_iorfile $test_idl"); + +$tresult = $TAO_IFR->SpawnWaitKill (30); + +if ($tresult != 0) { + print STDERR "ERROR: tao_ifr (test.idl) returned $tresult\n"; + exit 1; +} + +$client = $CL->SpawnWaitKill (5); +if ($client != 0) { + print STDERR "ERROR: client returned $client\n"; + $status = 1; +} + +# remove the interface from the Interface Repository. +$TAO_IFR->Arguments ("-ORBInitRef InterfaceRepository=file://$ifr_iorfile -r $test_idl"); + +$tresult = $TAO_IFR->SpawnWaitKill (30); + +if ($tresult != 0) { + print STDERR "ERROR: tao_ifr (-r test.idl) returned $tresult\n"; + $status = 1; +} + +$server = $IFR->TerminateWaitKill (5); +if ($server != 0) { + print STDERR "ERROR: IFR returned $server\n"; + $status = 1; +} + +unlink $ifr_iorfile; + +exit $status; + diff --git a/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/test.idl b/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/test.idl new file mode 100644 index 00000000000..8ac11a758fb --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/test.idl @@ -0,0 +1,14 @@ +// -*- C++ -*- +// $Id$ + +module warehouse +{ + interface inventory + { + boolean getCDinfo (in string artist, + inout string title, + out float price); + }; +}; + + |