int parse_args (int argc, ACE_TCHAR *argv[]) { ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:n")); int c; while ((c = get_opts ()) != -1) switch (c) { case 'o': output = get_opts.opt_arg (); break; case 'k': input = get_opts.opt_arg (); break; case 'n': named_orbs = 1; server_orb.set ("server_orb"); client_orb.set ("client_orb"); break; case '?': default: // This is a hack but that is okay! return 0; } // Indicates successful parsing of the command line return 0; }
int HTML_Body_Iterator::next (ACE_CString &url) { size_t len = BUFSIZ; const char *buf; ACE_CString buffer; int href_index = 0; for (buf = this->url_.stream ().recv (len); buf > 0; buf = this->url_.stream ().recv (len)) { buffer.set (buf, BUFSIZ, 1); href_index = ACE_Utils::truncate_cast<int> (buffer.find ("HREF")); if (href_index < 0) href_index = ACE_Utils::truncate_cast<int> (buffer.find ("href")); // Grep fpr " and grab the string until end-" if ( href_index > 0) { // Get back to buffer start location. this->url_.stream ().seek (-1 * static_cast<ACE_OFF_T> (len), SEEK_CUR); int start_index = ACE_Utils::truncate_cast<int> ( buffer.find ('\"', href_index)); if (start_index <= 0) break; start_index += href_index; int end_index = ACE_Utils::truncate_cast<int> ( buffer.find ('\"', start_index + 1)); if (end_index <= 0) break; end_index += start_index + 1; ssize_t url_len = end_index - (start_index + 1); ACE_CString temp = buffer.substring (start_index + 1, url_len); url.set (temp.c_str (), len, 1); this->url_.stream ().seek (end_index + 1); return url_len; } } return 0; }
int HTTP_Header_Iterator::next (ACE_CString &line) { if (this->end_of_header_) return 0; else { for (char c; (c = this->url_.stream ().get_char ()) != (char)EOF; ) { // Check to see if we're at the end of the header line. if (c == '\r' && this->url_.stream ().peek_char (0) == '\n') { line.set (this->url_.stream ().recv (), this->url_.stream ().recv_len () - 1, 1); // Check to see if we're at the end of the header. if (this->url_.stream ().peek_char (1) == '\r' && this->url_.stream ().peek_char (2) == '\n') { this->end_of_header_ = 1; // We're at the end of the header section. this->url_.stream ().seek (3); } else // We're at the end of the line. this->url_.stream ().seek (1); return 1; } // Handle broken Web servers that use '\n' instead of // '\r\n'. else if (c == '\n') { line.set (this->url_.stream ().recv (), (this->url_.stream ().recv_len ()), 1); // Check to see if we're at the end of the header. if (this->url_.stream ().peek_char (0) == '\n') { // We're at the end of the header section. this->url_.stream ().seek (1); this->end_of_header_ = 1; } return 1; } } } return 0; }
int parse_args (int argc, ACE_TCHAR *argv[]) { ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:n:m:")); int c; while ((c = get_opts ()) != -1) switch (c) { case 'o': output = get_opts.opt_arg (); break; case 'k': input = get_opts.opt_arg (); break; case 'n': // named_orbs = 1; server_orb.set ("server_orb"); client_orb.set ("client_orb"); break; case 'm': mode = get_opts.opt_arg (); // cout << "mode = " << mode << endl; ACE_DEBUG ((LM_DEBUG, "(%P|%t) - mode set to <%C> for collocated oneway test\n", mode)); if(mode) { if(!ACE_OS::strcmp(ACE_TEXT("none"), mode)) { syncMode = Client_Task::MODE_NONE; } else if (!ACE_OS::strcmp(ACE_TEXT("transport"), mode)) { syncMode = Client_Task::MODE_TRANSPORT; } else if (!ACE_OS::strcmp(ACE_TEXT("server"), mode)) { syncMode = Client_Task::MODE_SERVER; } else if (!ACE_OS::strcmp(ACE_TEXT("target"), mode)) { syncMode = Client_Task::MODE_TARGET; } } else { // same hack used in original test! return 0; } break; case '?': default: // This is a hack but that is okay! return 0; } // Indicates successful parsing of the command line return 0; }
int parse_args (int argc, ACE_TCHAR *argv[]) { ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("sk:o:n")); int c; while ((c = get_opts ()) != -1) switch (c) { case 's' : result = true; break; case 'n': server_orb.set ("server_orb"); client_orb.set ("client_orb"); break; case '?': default: // This is a hack but that is okay! return 0; } // Indicates successful parsing of the command line return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { ACE_CString srcname; if (argc > 1) srcname.set(argv[1]); else ACE_ERROR_RETURN ((LM_ERROR,"Usage: %s <source_file>\nwhere source file is the full path to a code set registry text file.\n",argv[0]),-1); csdb_generator csdb; if (csdb.init_output(srcname.c_str()) == -1) return 0; if (csdb.read_from (srcname.c_str()) == 0) csdb.fini_output ("Codeset_Registry_db.cpp"); return 0; }
int URL_Download_Iterator::next (ACE_CString &buffer) { size_t len = BUFSIZ; const char *buf = this->url_.stream ().recv (len); if (buf == 0) return 0; else { buffer.set (buf, len, 1); return 1; } }
int ACE_Codeset_Registry::registry_to_locale_i (ACE_CDR::ULong codeset_id, ACE_CString &locale, ACE_CDR::UShort *num_sets, ACE_CDR::UShort **char_sets) { registry_entry const *element = 0; for (size_t i = 0; element == 0 && i < num_registry_entries_; i++) if (codeset_id == registry_db_[i].codeset_id_) element = ®istry_db_[i]; if (element == 0) return 0; locale.set (element->loc_name_); if (num_sets != 0) *num_sets = element->num_sets_; if (char_sets != 0) { ACE_NEW_RETURN (*char_sets,ACE_CDR::UShort[element->num_sets_],0); ACE_OS::memcpy (*char_sets, element->char_sets_, element->num_sets_ * sizeof (ACE_CDR::UShort)); } return 1; }
void TAO_Storable_Naming_Context_ReaderWriter::write (TAO_Storable_Naming_Context & context) { TAO_NS_Persistence_Header header; header.size (static_cast<unsigned int> (context.storable_context_->current_size())); header.destroyed (context.destroyed_); this->write_header(header); if (0u == header.size ()) return; ACE_Hash_Map_Iterator<TAO_Storable_ExtId,TAO_Storable_IntId, ACE_Null_Mutex> it = context.storable_context_->map().begin(); ACE_Hash_Map_Iterator<TAO_Storable_ExtId,TAO_Storable_IntId, ACE_Null_Mutex> itend = context.storable_context_->map().end(); ACE_Hash_Map_Entry<TAO_Storable_ExtId,TAO_Storable_IntId> ent = *it; while (!(it == itend)) { TAO_NS_Persistence_Record record; ACE_CString name; CosNaming::BindingType bt = (*it).int_id_.type_; if (bt == CosNaming::ncontext) { CORBA::Object_var obj = context.orb_->string_to_object ((*it).int_id_.ref_.in ()); if (obj->_is_collocated ()) { // This is a local (i.e. non federated context) we therefore // store only the ObjectID (persistence filename) for the object. // The driving force behind storing ObjectIDs rather than IORs for // local contexts is to provide for a redundant naming service. // That is, a naming service that runs simultaneously on multiple // machines sharing a file system. It allows multiple redundant // copies to be started and stopped independently. // The original target platform was Tru64 Clusters where there was // a cluster address. In that scenario, clients may get different // servers on each request, hence the requirement to keep // synchronized to the disk. It also works on non-cluster system // where the client picks one of the redundant servers and uses it, // while other systems can pick different servers. (However in this // scenario, if a server fails and a client must pick a new server, // that client may not use any saved context IORs, instead starting // from the root to resolve names. So this latter mode is not quite // transparent to clients.) [Rich Seibel (seibel_r) of ociweb.com] PortableServer::ObjectId_var oid = context.poa_->reference_to_id (obj.in ()); CORBA::String_var nm = PortableServer::ObjectId_to_string (oid.in ()); const char *newname = nm.in (); name.set (newname); // The local ObjectID (persistance filename) record.type (TAO_NS_Persistence_Record::LOCAL_NCONTEXT); } else { // Since this is a foreign (federated) context, we can not store // the objectID (because it isn't in our storage), if we did, when // we restore, we would end up either not finding a permanent // record (and thus ending up incorrectly assuming the context was // destroyed) or loading another context altogether (just because // the contexts shares its objectID filename which is very likely). // [Simon Massey (sma) of prismtech.com] name.set ((*it).int_id_.ref_.in ()); // The federated context IOR record.type (TAO_NS_Persistence_Record::REMOTE_NCONTEXT); } } else // if (bt == CosNaming::nobject) // shouldn't be any other, can there? { name.set ((*it).int_id_.ref_.in ()); // The non-context object IOR record.type (TAO_NS_Persistence_Record::OBJREF); } record.ref(name); const char *myid = (*it).ext_id_.id(); ACE_CString id(myid); record.id(id); const char *mykind = (*it).ext_id_.kind(); ACE_CString kind(mykind); record.kind(kind); write_record (record); it.advance(); } context.write_occurred_ = 1; }
int ACE_TMAIN(int argc, ACE_TCHAR* argv[]) { ::DDS::ReturnCode_t retcode; ::DDS::StringDataWriter *string_writer = 0; ::DDS::Topic *topic = 0; ::DDS::DataWriter *data_writer = 0; int main_result = 1; /* error by default */ if (parse_args (argc, argv) != 0) return 1; ACE_Time_Value tv (0, 1000); //1 msec /* Create the domain participant */ ::DDS::DomainParticipant *participant = ::DDS::DomainParticipantFactory::get_instance()-> create_participant( 0, /* Domain ID */ DDS_PARTICIPANT_QOS_DEFAULT, /* QoS */ 0, /* Listener */ DDS_STATUS_MASK_NONE); if (!participant) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create domain participant.\n"))); goto clean_exit; } /* Create the topic "Hello, World" for the String type */ topic = participant->create_topic( "Hello, World", /* Topic name*/ ::DDS::StringTypeSupport::get_type_name(), /* Type name */ DDS_TOPIC_QOS_DEFAULT, /* Topic QoS */ 0, /* Listener */ DDS_STATUS_MASK_NONE); if (!topic) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create topic.\n"))); goto clean_exit; } /* Create the data writer using the default publisher */ data_writer = participant->create_datawriter( topic, DDS_DATAWRITER_QOS_DEFAULT, /* QoS */ 0, /* Listener */ DDS_STATUS_MASK_NONE); if (!data_writer) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create data writer.\n"))); goto clean_exit; } /* Perform a safe type-cast from a generic data writer into a * specific data writer for the type "DDS::String" */ string_writer = ::DDS::StringDataWriter::narrow(data_writer); if (!string_writer) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("DDS_StringDataWriter_narrow failed.\n"))); /* In this specific case, this will never fail */ goto clean_exit; } // Sleep a couple seconds to allow discovery to happen ACE_OS::sleep (1); /* --- Write Data ----------------------------------------------------- */ for (int i = 0; i < number_of_iterations; i++) { char timestamp[16]; ACE_CString msg (send_string); ACE_CString ret; ACE_Date_Time now; ACE_OS::sprintf (timestamp, "%02d.%d", static_cast<int> (now.second()), static_cast<int> (now.microsec ())); ret.set (timestamp); ret = ret + " " + msg; retcode = string_writer->write( ret.c_str (), DDS_HANDLE_NIL); if (retcode != DDS_RETCODE_OK) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Write failed: %d.\n"), retcode)); } ACE_OS::sleep (tv); } /* --- Clean Up ------------------------------------------------------- */ main_result = 0; clean_exit: ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Exiting."))); if (participant) { retcode = participant->delete_contained_entities(); if (retcode != DDS_RETCODE_OK) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Deletion failed.\n"))); main_result = 1; } retcode = ::DDS::DomainParticipantFactory::get_instance()-> delete_participant(participant); if (retcode != DDS_RETCODE_OK) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Deletion failed.\n"))); main_result = 1; } } return main_result; }
int TAO_Connector::make_mprofile (const char *string, TAO_MProfile &mprofile) { // This method utilizes the "Template Method" design pattern to // parse the given URL style IOR for the protocol being used // and create an mprofile from it. // // The methods that must be defined by all Connector sub-classes are: // make_profile // check_prefix // Check for a valid string if (!string || !*string) { throw ::CORBA::INV_OBJREF ( CORBA::SystemException::_tao_minor_code ( 0, EINVAL), CORBA::COMPLETED_NO); } // Check for the proper prefix in the IOR. If the proper prefix isn't // in the IOR then it is not an IOR we can use. if (this->check_prefix (string) != 0) { return 1; // Failure: not the correct IOR for this protocol. // DO NOT throw an exception here since the Connector_Registry // should be allowed the opportunity to continue looking for // an appropriate connector. } if (TAO_debug_level > 0) { TAOLIB_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - TAO_Connector::make_mprofile ") ACE_TEXT ("<%C>\n"), string)); } ACE_CString ior; ior.set (string, ACE_OS::strlen (string), 1); // Find out where the protocol ends ACE_CString::size_type ior_index = ior.find ("://"); if (ior_index == ACE_CString::npos) { throw ::CORBA::INV_OBJREF (); // No colon ':' in the IOR! } else { ior_index += 3; // Add the length of the colon and the two forward slashes `://' // to the IOR string index (i.e. 3) } // Find the object key const ACE_CString::size_type objkey_index = ior.find (this->object_key_delimiter (), ior_index); if (objkey_index == 0 || objkey_index == ACE_CString::npos) { throw ::CORBA::INV_OBJREF (); // Failure: No endpoints specified or no object key specified. } const char endpoint_delimiter = ','; // The delimiter used to separate individual addresses. // Count the number of endpoints in the IOR. This will be the number // of entries in the MProfile. CORBA::ULong profile_count = 1; // Number of endpoints in the IOR (initialized to 1). // Only check for endpoints after the protocol specification and // before the object key. for (ACE_CString::size_type i = ior_index; i < objkey_index; ++i) { if (ior[i] == endpoint_delimiter) ++profile_count; } // Tell the MProfile object how many Profiles it should hold. // MProfile::set(size) returns the number profiles it can hold. if (mprofile.set (profile_count) != static_cast<int> (profile_count)) { throw ::CORBA::INV_OBJREF ( CORBA::SystemException::_tao_minor_code ( TAO_MPROFILE_CREATION_ERROR, 0), CORBA::COMPLETED_NO); // Error while setting the MProfile size! } // The idea behind the following loop is to split the IOR into several // strings that can be parsed by each profile. // For example, // `1.3@moo,shu,1.1@chicken/arf' // will be parsed into: // `1.3@moo/arf' // `shu/arf' // `1.1@chicken/arf' ACE_CString::size_type begin = 0; ACE_CString::size_type end = ior_index - 1; // Initialize the end of the endpoint index for (CORBA::ULong j = 0; j < profile_count; ++j) { begin = end + 1; if (j < profile_count - 1) { end = ior.find (endpoint_delimiter, begin); } else { end = objkey_index; // Handle last endpoint differently } if (end < ior.length () && end != ior.npos) { ACE_CString endpoint = ior.substring (begin, end - begin); // Add the object key to the string. endpoint += ior.substring (objkey_index); // The endpoint should now be of the form: // `N.n@endpoint/object_key' // or // `endpoint/object_key' TAO_Profile *profile = this->make_profile (); // Failure: Problem during profile creation // Initialize a Profile using the individual endpoint // string. // @@ Not exception safe! We need a TAO_Profile_var! profile->parse_string (endpoint.c_str () ); // Give up ownership of the profile. if (mprofile.give_profile (profile) == -1) { profile->_decr_refcnt (); throw ::CORBA::INV_OBJREF ( CORBA::SystemException::_tao_minor_code ( TAO_MPROFILE_CREATION_ERROR, 0), CORBA::COMPLETED_NO); // Failure presumably only occurs when MProfile is full! // This should never happen. } } else { throw ::CORBA::INV_OBJREF (); // Unable to separate endpoints } } return 0; // Success }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { if (parse_args (argc, argv) == -1) return -1; server_orb.set ("server_orb"); client_orb.set ("client_orb"); try { PortableInterceptor::ORBInitializer_ptr temp_initializer; ACE_NEW_RETURN (temp_initializer, Collocated_ORBInitializer, -1); // No exceptions yet! PortableInterceptor::ORBInitializer_var initializer = temp_initializer; PortableInterceptor::register_orb_initializer (initializer.in ()); CORBA::ORB_var sorb = CORBA::ORB_init (argc, argv, server_orb.c_str ()); ACE_Manual_Event me; Server_Task server_task (output, sorb.in (), me, ACE_Thread_Manager::instance ()); if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, 1, 1) == -1) { ACE_ERROR ((LM_ERROR, "Error activating server task\n")); } // Wait for the server thread to do some processing me.wait (); CORBA::ORB_var corb = CORBA::ORB_init (argc, argv, client_orb.c_str ()); Client_Task client_task (input, corb.in (), ACE_Thread_Manager::instance ()); if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, 1, 1) == -1) { ACE_ERROR ((LM_ERROR, "Error activating client task\n")); } ACE_Thread_Manager::instance ()->wait (); } catch (const CORBA::Exception&) { // Ignore exceptions.. } return 0; }