summaryrefslogtreecommitdiff
path: root/TAO/tests/ZIOP/server.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/tests/ZIOP/server.cpp')
-rw-r--r--TAO/tests/ZIOP/server.cpp251
1 files changed, 158 insertions, 93 deletions
diff --git a/TAO/tests/ZIOP/server.cpp b/TAO/tests/ZIOP/server.cpp
index 7af7f1885c0..66ced845c6e 100644
--- a/TAO/tests/ZIOP/server.cpp
+++ b/TAO/tests/ZIOP/server.cpp
@@ -5,6 +5,8 @@
#include "ace/OS_NS_stdio.h"
#include "tao/ZIOP/ZIOP.h"
#include "tao/Compression/zlib/ZlibCompressor_Factory.h"
+#include "tao/Compression/bzip2/Bzip2Compressor_Factory.h"
+#include "TestCompressor/TestCompressor_Factory.h"
#include "tao/Policy_ManagerC.h"
#include "tao/Policy_CurrentC.h"
#include "tao/Transport.h"
@@ -14,12 +16,12 @@ ACE_RCSID (Hello,
"$Id$")
const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
-Compression::CompressionLevel level = 6;
+int test = 1;
int
parse_args (int argc, ACE_TCHAR *argv[])
{
- ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:l:"));
+ ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:t:"));
int c;
while ((c = get_opts ()) != -1)
@@ -28,8 +30,8 @@ parse_args (int argc, ACE_TCHAR *argv[])
case 'o':
ior_output_file = get_opts.opt_arg ();
break;
- case 'l':
- level = ACE_OS::atoi (get_opts.opt_arg ());
+ case 't':
+ test = ACE_OS::atoi (get_opts.opt_arg ());
break;
case '?':
@@ -46,117 +48,182 @@ parse_args (int argc, ACE_TCHAR *argv[])
}
int
-ACE_TMAIN(int argc, ACE_TCHAR *argv[])
+register_factories (CORBA::ORB_ptr orb)
{
- try
+ CORBA::Object_var compression_manager =
+ orb->resolve_initial_references("CompressionManager");
+
+ ::Compression::CompressionManager_var manager =
+ ::Compression::CompressionManager::_narrow (compression_manager.in ());
+
+ if (CORBA::is_nil(manager.in ()))
+ ACE_ERROR_RETURN ((LM_ERROR,
+ " (%P|%t) Panic: nil compression manager\n"),
+ 1);
+ //register Zlib compressor
+ ::Compression::CompressorFactory_ptr compressor_factory;
+ ACE_NEW_RETURN (compressor_factory, TAO::Zlib_CompressorFactory (), 1);
+ ::Compression::CompressorFactory_var compr_fact = compressor_factory;
+ manager->register_factory(compr_fact.in ());
+
+ // register bzip2 compressor
+ ACE_NEW_RETURN (compressor_factory, TAO::Bzip2_CompressorFactory (), 1);
+ compr_fact = compressor_factory;
+ manager->register_factory(compr_fact.in ());
+
+ // register test compressor
+ ACE_NEW_RETURN (compressor_factory, TAO::Test_CompressorFactory (), 1);
+ compr_fact = compressor_factory;
+ manager->register_factory(compr_fact.in ());
+
+ return 0;
+}
+
+CORBA::Policy_ptr
+create_compressor_id_level_list_policy (CORBA::ORB_ptr orb)
+{
+ ::Compression::CompressorIdLevelList compressor_id_list;
+
+ if (test == 2)
{
- CORBA::ORB_var orb =
- CORBA::ORB_init (argc, argv);
+ compressor_id_list.length(1);
+ compressor_id_list[0].compressor_id = COMPRESSORID_FOR_TESTING;
+ compressor_id_list[0].compression_level = 5;
+ }
+ else
+ {
+ compressor_id_list.length(3);
+ compressor_id_list[0].compressor_id = ::Compression::COMPRESSORID_BZIP2;
+ compressor_id_list[0].compression_level = 5;
+ compressor_id_list[1].compressor_id = ::Compression::COMPRESSORID_ZLIB;
+ compressor_id_list[1].compression_level = 5;
+ compressor_id_list[2].compressor_id = COMPRESSORID_FOR_TESTING;
+ compressor_id_list[2].compression_level = 5;
+ }
- CORBA::Object_var compression_manager =
- orb->resolve_initial_references("CompressionManager");
+ CORBA::Any compressor_id_any;
+ compressor_id_any <<= compressor_id_list;
- Compression::CompressionManager_var manager =
- Compression::CompressionManager::_narrow (compression_manager.in ());
+ return orb->create_policy (ZIOP::COMPRESSOR_ID_LEVEL_LIST_POLICY_ID, compressor_id_any);
+}
- if (CORBA::is_nil(manager.in ()))
- ACE_ERROR_RETURN ((LM_ERROR,
- " (%P|%t) Panic: nil compression manager\n"),
- 1);
+CORBA::Policy_ptr
+create_low_value_policy (CORBA::ORB_ptr orb)
+{
+ // Setting policy for minimum amount of bytes that needs to be
+ // compressed. If a message is smaller than this, it doesn't get
+ // compressed
+ CORBA::ULong compression_low_value = 100;
+ CORBA::Any low_value_any;
+ low_value_any <<= compression_low_value;
+
+ return orb->create_policy (ZIOP::COMPRESSION_LOW_VALUE_POLICY_ID, low_value_any);
+}
- Compression::CompressorFactory_ptr compressor_factory;
+CORBA::Policy_ptr
+create_compression_enabled_policy (CORBA::ORB_ptr orb)
+{
+ // Setting policy whether compression is used.
+ CORBA::Boolean compression_enabling = true;
+ CORBA::Any compression_enabling_any;
+ compression_enabling_any <<= CORBA::Any::from_boolean(compression_enabling);
- ACE_NEW_RETURN (compressor_factory, TAO::Zlib_CompressorFactory (), 1);
+ return orb->create_policy (ZIOP::COMPRESSION_ENABLING_POLICY_ID, compression_enabling_any);
+}
- Compression::CompressorFactory_var compr_fact = compressor_factory;
- manager->register_factory(compr_fact.in ());
+CORBA::Policy_ptr
+create_min_ratio_policy (CORBA::ORB_ptr orb)
+{
+ CORBA::Any min_compression_ratio_any;
+ CORBA::Long min_compression_ratio = 75;
+ min_compression_ratio_any <<= min_compression_ratio;
- CORBA::Object_var poa_object =
- orb->resolve_initial_references("RootPOA");
+ return orb->create_policy (ZIOP::COMPRESSION_MIN_RATIO_POLICY_ID, min_compression_ratio_any);
+}
- PortableServer::POA_var root_poa =
- PortableServer::POA::_narrow (poa_object.in ());
+Test::Hello_var
+prepare_tests (CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa)
+{
+ register_factories(orb);
- if (CORBA::is_nil (root_poa.in ()))
- ACE_ERROR_RETURN ((LM_ERROR,
- " (%P|%t) Panic: nil RootPOA\n"),
- 1);
+ CORBA::Object_var objectman =
+ orb->resolve_initial_references ("ORBPolicyManager");
- if (parse_args (argc, argv) != 0)
- return 1;
+ CORBA::PolicyManager_var policy_manager =
+ CORBA::PolicyManager::_narrow (objectman.in ());
- Compression::CompressorIdLevelList compressor_id_list(2);
- compressor_id_list.length(2);
- compressor_id_list[0].compressor_id = Compression::COMPRESSORID_ZLIB;
- compressor_id_list[0].compression_level = 6;
- compressor_id_list[1].compressor_id = Compression::COMPRESSORID_BZIP2;
- compressor_id_list[1].compression_level = 6;
-
- //Setting policy whether compression is used.
- CORBA::Boolean compression_enabling = true;
- CORBA::Any compression_enabling_any;
- compression_enabling_any <<= CORBA::Any::from_boolean(compression_enabling);
-
- //Setting policy for minimum amount of bytes that needs to be
- //compressed. If a message is smaller than this, it doesn't get
- //compressed
- CORBA::ULong compression_low_value = 100;
- CORBA::Any low_value_any;
- low_value_any <<= compression_low_value;
-
- CORBA::Any min_compression_ratio_any;
- CORBA::Long min_compression_ratio = 40;
- min_compression_ratio_any <<= min_compression_ratio;
-
- CORBA::Any compressor_id_any;
- compressor_id_any <<= compressor_id_list;
-
- PortableServer::POA_var my_compress_poa = 0;
- CORBA::PolicyList policies(4);
- policies.length(4);
-
- try {
- policies[0] = orb->create_policy (ZIOP::COMPRESSION_ENABLING_POLICY_ID, compression_enabling_any);
- policies[1] = orb->create_policy (ZIOP::COMPRESSOR_ID_LEVEL_LIST_POLICY_ID, compressor_id_any);
- policies[2] = orb->create_policy (ZIOP::COMPRESSION_LOW_VALUE_POLICY_ID, low_value_any);
- policies[3] = orb->create_policy (ZIOP::COMPRESSION_MIN_RATIO_POLICY_ID, min_compression_ratio_any);
- my_compress_poa = root_poa->create_POA("My_Compress_Poa", 0, policies);
- }
- catch(const CORBA::PolicyError&) {
- policies.length(0);
- my_compress_poa = root_poa->create_POA("My_Compress_Poa", 0, policies);
- }
+ PortableServer::POA_var my_compress_poa = 0;
+ CORBA::PolicyList policies(4);
+ policies.length(4);
- CORBA::Object_var objectman =
- orb->resolve_initial_references ("ORBPolicyManager");
+ try
+ {
+ policies[0] = create_compressor_id_level_list_policy (orb);
+ policies[1] = create_low_value_policy (orb);
+ policies[2] = create_compression_enabled_policy (orb);
+ policies[3] = create_min_ratio_policy (orb);
- CORBA::PolicyManager_var policy_manager =
- CORBA::PolicyManager::_narrow (objectman.in ());
+ my_compress_poa = root_poa->create_POA("My_Compress_Poa", 0, policies);
+ }
+ catch(const CORBA::PolicyError&)
+ {
+ policies.length(0);
+ my_compress_poa = root_poa->create_POA("My_Compress_Poa", 0, policies);
+ }
- policy_manager->set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
+ policy_manager->set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
- CORBA::Object_var pcobject =
- orb->resolve_initial_references ("PolicyCurrent");
+ CORBA::Object_var pcobject =
+ orb->resolve_initial_references ("PolicyCurrent");
- CORBA::PolicyCurrent_var policy_current =
- CORBA::PolicyCurrent::_narrow (pcobject.in ());
+ CORBA::PolicyCurrent_var policy_current =
+ CORBA::PolicyCurrent::_narrow (pcobject.in ());
- policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
+ policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
- PortableServer::POAManager_var poa_manager = my_compress_poa->the_POAManager ();
+ PortableServer::POAManager_var poa_manager = my_compress_poa->the_POAManager ();
- Hello *hello_impl = 0;
- ACE_NEW_RETURN (hello_impl,
- Hello (orb.in ()),
- 1);
- PortableServer::ServantBase_var owner_transfer(hello_impl);
+ Hello *hello_impl = 0;
+ ACE_NEW_RETURN (hello_impl,
+ Hello (orb),
+ 0);
+ PortableServer::ServantBase_var owner_transfer(hello_impl);
+
+ PortableServer::ObjectId_var id =
+ my_compress_poa->activate_object (hello_impl);
- PortableServer::ObjectId_var id =
- my_compress_poa->activate_object (hello_impl);
+ CORBA::Object_var object = my_compress_poa->id_to_reference (id.in ());
- CORBA::Object_var object = my_compress_poa->id_to_reference (id.in ());
+ Test::Hello_var hello = Test::Hello::_narrow (object.in ());
- Test::Hello_var hello = Test::Hello::_narrow (object.in ());
+ poa_manager->activate ();
+
+ return hello._retn ();
+}
+
+int
+ACE_TMAIN(int argc, ACE_TCHAR *argv[])
+{
+ try
+ {
+ CORBA::ORB_var orb =
+ CORBA::ORB_init (argc, argv);
+
+ CORBA::Object_var poa_object =
+ orb->resolve_initial_references("RootPOA");
+
+ PortableServer::POA_var root_poa =
+ PortableServer::POA::_narrow (poa_object.in ());
+
+ if (CORBA::is_nil (root_poa.in ()))
+ ACE_ERROR_RETURN ((LM_ERROR,
+ " (%P|%t) Panic: nil RootPOA\n"),
+ 1);
+
+ if (parse_args (argc, argv) != 0)
+ return 1;
+
+ Test::Hello_var hello = prepare_tests (orb.in (), root_poa.in ());
CORBA::String_var ior = orb->object_to_string (hello.in ());
@@ -170,8 +237,6 @@ ACE_TMAIN(int argc, ACE_TCHAR *argv[])
ACE_OS::fprintf (output_file, "%s", ior.in ());
ACE_OS::fclose (output_file);
- poa_manager->activate ();
-
orb->run ();
ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));