void JAWS_Synch_IO::receive_file (JAWS_IO_Handler *ioh, const char *filename, void *initial_data, unsigned int initial_data_length, unsigned int entire_length) { ACE_Filecache_Handle handle (filename, (int) entire_length); int result = handle.error (); if (result == ACE_Filecache_Handle::ACE_SUCCESS) { ACE_SOCK_Stream stream; stream.set_handle (ioh->handle ()); int bytes_to_memcpy = ACE_MIN (entire_length, initial_data_length); ACE_OS::memcpy (handle.address (), initial_data, bytes_to_memcpy); int bytes_to_read = entire_length - bytes_to_memcpy; int bytes = stream.recv_n ((char *) handle.address () + initial_data_length, bytes_to_read); if (bytes == bytes_to_read) ioh->receive_file_complete (); else result = -1; } if (result != ACE_Filecache_Handle::ACE_SUCCESS) ioh->receive_file_error (result); }
MCT_Config (void) : group_start_ (MCT_START_PORT, MCT_START_GROUP), groups_ (0), debug_ (0), role_ (BOTH), sdm_opts_ (ACE_SOCK_Dgram_Mcast::DEFOPTS), iterations_ (MCT_ITERATIONS), ttl_ (1), wait_ (2) { if (IP_MAX_MEMBERSHIPS == 0) this->groups_ = MCT_GROUPS; else this->groups_ = ACE_MIN (IP_MAX_MEMBERSHIPS, MCT_GROUPS); }
int Sender::initiate_read_file (void) { ACE_TEST_ASSERT (0 == this->file_offset_ % chunk_size); static const size_t file_size = ACE_OS::filesize (input_file); static const size_t number_of_chunks_needed_for_file = static_cast<size_t> (ACE_OS::ceil ((double) file_size / chunk_size)); size_t relevant_number_of_chunks = ACE_MIN ((size_t)ACE_IOV_MAX, number_of_chunks_needed_for_file - (size_t)(this->file_offset_ / chunk_size)); if (!relevant_number_of_chunks) { ACE_TEST_ASSERT (0); // Just 2 C it coming return 0; } ACE_Message_Block *head_mb = 0; if (-1 == allocate_chunks_chain (head_mb, relevant_number_of_chunks)) { ACE_TEST_ASSERT (0); return -1; } // Inititiate read if (this->rf_.readv (*head_mb, head_mb->total_size (), this->file_offset_) == -1) { free_chunks_chain (head_mb); ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("Sender::initiate_read_file::") ACE_TEXT ("ACE_Asynch_Read_Stream::readv")), -1); } ++this->io_count_; return 0; }
int MCT_Config::open (int argc, ACE_TCHAR *argv[]) { int retval = 0; int help = 0; //FUZZ: disable check_for_lack_ACE_OS ACE_Get_Opt getopt (argc, argv, ACE_TEXT (":?"), 1, 1); //FUZZ: enable check_for_lack_ACE_OS if (getopt.long_option (ACE_TEXT ("GroupStart"), 'g', ACE_Get_Opt::ARG_REQUIRED) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add GroupStart option.\n")), 1); if (getopt.long_option (ACE_TEXT ("Groups"), 'n', ACE_Get_Opt::ARG_REQUIRED) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add Groups option.\n")), 1); if (getopt.long_option (ACE_TEXT ("Debug"), 'd', ACE_Get_Opt::NO_ARG) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add Debug option.\n")), 1); if (getopt.long_option (ACE_TEXT ("Role"), 'r', ACE_Get_Opt::ARG_REQUIRED) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add Role option.\n")), 1); if (getopt.long_option (ACE_TEXT ("SDM_options"), 'm', ACE_Get_Opt::ARG_REQUIRED) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add Multicast_Options option.\n")), 1); if (getopt.long_option (ACE_TEXT ("Iterations"), 'i', ACE_Get_Opt::ARG_REQUIRED) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add iterations option.\n")), 1); if (getopt.long_option (ACE_TEXT ("TTL"), 't', ACE_Get_Opt::ARG_REQUIRED) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add TTL option.\n")), 1); if (getopt.long_option (ACE_TEXT ("Wait"), 'w', ACE_Get_Opt::ARG_REQUIRED) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add wait option.\n")), 1); if (getopt.long_option (ACE_TEXT ("help"), 'h', ACE_Get_Opt::NO_ARG) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add help option.\n")), 1); //FUZZ: disable check_for_lack_ACE_OS // Now, let's parse it... int c = 0; while ((c = getopt ()) != EOF) { //FUZZ: enable check_for_lack_ACE_OS switch (c) { case 0: // Long Option. This should never happen. retval = -1; break; case 'g': { // @todo validate all these, i.e., must be within range // 224.255.0.0 to 238.255.255.255, but we only allow the // administrative "site local" range, 239.255.0.0 to // 239.255.255.255. ACE_TCHAR *group = getopt.opt_arg (); if (this->group_start_.set (group) != 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Bad group address:%s\n"), group)); } } break; case 'i': this->iterations_ = ACE_OS::atoi (getopt.opt_arg ()); break; case 'n': { int n = ACE_OS::atoi (getopt.opt_arg ()); // I'm assuming 0 means unlimited, so just use whatever the // user provides. Seems to work okay on Solaris 5.8. if (IP_MAX_MEMBERSHIPS == 0) this->groups_ = n; else this->groups_ = ACE_MIN (ACE_MAX (n, MCT_MIN_GROUPS), IP_MAX_MEMBERSHIPS); break; } case 'd': this->debug_ = 1; break; case 'r': { ACE_TCHAR *c = getopt.opt_arg (); if (ACE_OS::strcasecmp (c, ACE_TEXT ("CONSUMER")) == 0) this->role_ = CONSUMER; else if (ACE_OS::strcasecmp (c, ACE_TEXT ("PRODUCER")) == 0) this->role_ = PRODUCER; else { help = 1; retval = -1; } } break; case 'm': { //@todo add back OPT_BINDADDR_NO... ACE_TCHAR *c = getopt.opt_arg (); if (ACE_OS::strcasecmp (c, ACE_TEXT ("OPT_BINDADDR_YES")) == 0) ACE_SET_BITS (this->sdm_opts_, ACE_SOCK_Dgram_Mcast::OPT_BINDADDR_YES); else if (ACE_OS::strcasecmp (c, ACE_TEXT ("OPT_BINDADDR_NO")) == 0) ACE_CLR_BITS (this->sdm_opts_, ACE_SOCK_Dgram_Mcast::OPT_BINDADDR_YES); else if (ACE_OS::strcasecmp (c, ACE_TEXT ("DEFOPT_BINDADDR")) == 0) { ACE_CLR_BITS (this->sdm_opts_, ACE_SOCK_Dgram_Mcast::OPT_BINDADDR_YES); ACE_SET_BITS (this->sdm_opts_, ACE_SOCK_Dgram_Mcast::DEFOPT_BINDADDR); } else if (ACE_OS::strcasecmp (c, ACE_TEXT ("OPT_NULLIFACE_ALL")) == 0) ACE_SET_BITS (this->sdm_opts_, ACE_SOCK_Dgram_Mcast::OPT_NULLIFACE_ALL); else if (ACE_OS::strcasecmp (c, ACE_TEXT ("OPT_NULLIFACE_ONE")) == 0) ACE_CLR_BITS (this->sdm_opts_, ACE_SOCK_Dgram_Mcast::OPT_NULLIFACE_ALL); else if (ACE_OS::strcasecmp (c, ACE_TEXT ("DEFOPT_NULLIFACE")) == 0) { ACE_CLR_BITS (this->sdm_opts_, ACE_SOCK_Dgram_Mcast::OPT_NULLIFACE_ALL); ACE_SET_BITS (this->sdm_opts_, ACE_SOCK_Dgram_Mcast::DEFOPT_NULLIFACE); } else if (ACE_OS::strcasecmp (c, ACE_TEXT ("DEFOPTS")) == 0) this->sdm_opts_ = ACE_SOCK_Dgram_Mcast::DEFOPTS; else { help = 1; retval = -1; } } break; case 't': this->ttl_ = ACE_OS::atoi (getopt.opt_arg ()); break; case 'w': this->wait_ = ACE_OS::atoi (getopt.opt_arg ()); break; case ':': // This means an option requiring an argument didn't have one. ACE_ERROR ((LM_ERROR, ACE_TEXT (" Option '%c' requires an argument but ") ACE_TEXT ("none was supplied\n"), getopt.opt_opt ())); help = 1; retval = -1; break; case '?': case 'h': default: if (ACE_OS::strcmp (argv[getopt.opt_ind () - 1], ACE_TEXT ("-?")) != 0 && getopt.opt_opt () != 'h') // Don't allow unknown options. ACE_ERROR ((LM_ERROR, ACE_TEXT (" Found an unknown option (%c) ") ACE_TEXT ("we couldn't handle.\n"), getopt.opt_opt ())); // getopt.last_option ())); //readd with "%s" when // last_option() is available. help = 1; retval = -1; break; } } if (retval == -1) { if (help) // print usage here ACE_ERROR ((LM_ERROR, ACE_TEXT ("usage: %s [options]\n") ACE_TEXT ("Options:\n") ACE_TEXT (" -g {STRING} --GroupStart={STRING} ") ACE_TEXT ("starting multicast group address\n") ACE_TEXT (" ") ACE_TEXT ("(default=239.255.0.1:16000)\n") ACE_TEXT (" -n {#} --Groups={#} ") ACE_TEXT ("number of groups (default=5)\n") ACE_TEXT (" -d --Debug ") ACE_TEXT ("debug flag (default=off)\n") ACE_TEXT (" -r {STRING} --Role={STRING} ") ACE_TEXT ("role {PRODUCER|CONSUMER|BOTH}\n") ACE_TEXT (" ") ACE_TEXT ("(default=BOTH)\n") ACE_TEXT (" -m {STRING} --SDM_options={STRING} ") ACE_TEXT ("ACE_SOCK_Dgram_Mcast ctor options\n") ACE_TEXT (" ") ACE_TEXT ("(default=DEFOPTS)\n") ACE_TEXT (" -i {#} --Iterations={#} ") ACE_TEXT ("number of iterations (default=100)\n") ACE_TEXT (" -t {#} --TTL={#} ") ACE_TEXT ("time to live (default=1)\n") ACE_TEXT (" -w {#} --Wait={#} ") ACE_TEXT ("number of seconds to wait on CONSUMER\n") ACE_TEXT (" ") ACE_TEXT ("(default=2)\n") ACE_TEXT (" -h/? --help ") ACE_TEXT ("show this message\n"), argv[0])); return -1; } return 0; }
/** Update tracks and settings from database. */ bool RecorderImpl::UpdateFromDatabase(unsigned int max_inputs, unsigned int max_tracks_per_input) { bool ok = true; // Load recorder object from database prodauto::Recorder * rec = 0; try { rec = prodauto::Database::getInstance()->loadRecorder(mName); } catch (const prodauto::DBException & dbe) { ACE_DEBUG((LM_ERROR, ACE_TEXT("Database Exception: %C\n"), dbe.getMessage().c_str())); ok = false; } if (!rec) { // If there was a problem, re-initialise database and hope // for better luck next time. ACE_DEBUG((LM_WARNING, ACE_TEXT("Re-initialising database.\n"))); DatabaseManager::Instance()->ReInitialise(); } else { // Store the Recorder object mRecorder.reset(rec); // Update RecorderSettings RecorderSettings * settings = RecorderSettings::Instance(); if (settings) { settings->Update(rec); } // Clear the set of SourceConfigs // and the various maps mSourceConfigs.clear(); mTrackMap.clear(); mTrackIndexMap.clear(); mRecordingLocationMap.clear(); // Set the source track names const unsigned int n_inputs = ACE_MIN((unsigned int)rec->recorderInputConfigs.size(), max_inputs); unsigned int track_i = 0; unsigned int n_video_tracks = 0; for (unsigned int i = 0; i < n_inputs; ++i) { prodauto::RecorderInputConfig * ric = rec->getInputConfig(i + 1); // We force number of tracks per input to be the hardware max because // this makes it easier to map to hardware parameters when filling out // tracks status with "signal present" etc. //const unsigned int n_tracks = ACE_MIN(ric->trackConfigs.size(), mMaxTracksPerInput); const unsigned int n_tracks = max_tracks_per_input; for (unsigned int j = 0; j < n_tracks; ++j) { prodauto::RecorderInputTrackConfig * ritc = 0; if (ric && j < ric->trackConfigs.size()) { ritc = ric->getTrackConfig(j + 1); } prodauto::SourceConfig * sc = 0; if (ritc) { sc = ritc->sourceConfig; } prodauto::SourceTrackConfig * stc = 0; if (sc) { stc = sc->getTrackConfig(ritc->sourceTrackID); } // Update our set of SourceConfig. Actually using // a map with database ID as the key, simply because // having a pointer as a key is not good practice. if (sc) { long id = sc->getDatabaseID(); mSourceConfigs[id] = sc; } // Update our map of RecordingLocation names if (sc) { long id = sc->recordingLocation; if (id) { try { mRecordingLocationMap[id] = prodauto::Database::getInstance()->loadLocationName(id); ACE_DEBUG((LM_DEBUG, ACE_TEXT("Location %d \"%C\"\n"), id, mRecordingLocationMap[id].c_str())); } catch (const prodauto::DBException & dbe) { ACE_DEBUG((LM_ERROR, ACE_TEXT("Database Exception: %C\n"), dbe.getMessage().c_str())); } } } // Update map from source to hardware tracks if (stc) { long id = stc->getDatabaseID(); HardwareTrack trk = {i, j}; mTrackMap[id] = trk; } // Note that here we assemble our list of tracks in harware order. // An alternative would be to present them in source order. The // GUI already re-orders them in source order and presents them to // the user in that form. // Update map from source to mTracks index long stc_db_id = 0; if (stc) { stc_db_id = stc->getDatabaseID(); // Check for duplicate input tracks if (mTrackIndexMap.find(stc_db_id) != mTrackIndexMap.end()) { ACE_DEBUG((LM_WARNING, ACE_TEXT("Warning: Duplicate input tracks connected! This is likely to cause problems.\n"))); } mTrackIndexMap[stc_db_id] = track_i; } mTracks->length(track_i + 1); ProdAuto::Track & track = mTracks->operator[](track_i); // Set track type if (stc && stc->dataDef == PICTURE_DATA_DEFINITION) { track.type = ProdAuto::VIDEO; ++n_video_tracks; } else if (stc && stc->dataDef == SOUND_DATA_DEFINITION) { track.type = ProdAuto::AUDIO; } // If no source track, assume hardware track 0 is video else if (j == 0) { track.type = ProdAuto::VIDEO; ++n_video_tracks; } else { track.type = ProdAuto::AUDIO; } #if 1 // Name track by hardware input std::ostringstream s; if (track.type == ProdAuto::VIDEO) { s << "V"; } else { track.type = ProdAuto::AUDIO; s << "A" << j; } s << " (input " << i << ")"; track.name = CORBA::string_dup(s.str().c_str()); #else // Name track by source track name if (stc) { track.name = CORBA::string_dup(stc->name.c_str()); } #endif // Set track id if (stc) { track.id = stc->getDatabaseID(); // Helps to have this as used as key for maps } else { // No source connected track.id = 0; } if (sc && stc) { track.has_source = 1; track.src.package_name = CORBA::string_dup(sc->name.c_str()); prodauto::SourcePackage * sp = sc->getSourcePackage(); if (sp) { track.src.tape_name = CORBA::string_dup(sp->name.c_str()); } else { track.src.tape_name = CORBA::string_dup(""); } track.src.track_name = CORBA::string_dup(stc->name.c_str()); } else { // No connection to this input track.has_source = 0; track.src.package_name = CORBA::string_dup("zz No Connection"); track.src.tape_name = CORBA::string_dup(""); track.src.track_name = CORBA::string_dup(""); } ACE_DEBUG((LM_DEBUG, ACE_TEXT("Input %d, track %d, databse id %3d, src.track_name \"%C\"\n"), i, j, stc_db_id, (const char *) track.src.track_name)); ++track_i; } // tracks } // inputs //mVideoTrackCount = n_video_tracks; // Re-initialise tracks status, if necessary. if (mTracksStatus->length() != mTracks->length()) { mTracksStatus->length(mTracks->length()); for (unsigned int i = 0; i < mTracksStatus->length(); ++i) { ProdAuto::TrackStatus & ts = mTracksStatus->operator[](i); ts.rec = 0; ts.rec_error = 0; ts.signal_present = 0; ts.timecode.undefined = true; //ts.timecode.edit_rate = mEditRate; } } ACE_DEBUG((LM_INFO, ACE_TEXT("Updated sources for recorder \"%C\"\n"), mRecorder->name.c_str())); } // Set source package names (using tape names if available) ok = ok && SetSourcePackages(); return ok; }
int Writer::initiate_write_file (void) { // find out how much can we merge ACE_Message_Block *dummy_last = 0; size_t odd_count = last_chunk (this->odd_chain_, dummy_last); size_t even_count = last_chunk (this->even_chain_, dummy_last); size_t merge_size = ACE_MIN (ACE_MIN (odd_count, even_count), (size_t) ACE_IOV_MAX); // the options here are as follows: // io_count_ can be zero or greater. // merge_size can be zero or not. // if non zero merge, write the merge. ASSERT receiver_count_ is non zero too. // if zero merge: // if receiver_count_ is non zero, NOOP. // if zero receiver_count_, we should write whatever is left, // and terminate the writer at completion. // if nothing to write, and io_count_ is zero too, terminate here. if (0 == merge_size && 0 != this->receiver_count_) return 0; if (0 == merge_size && 0 == this->receiver_count_ && 0 == odd_count && 0 == even_count && 0 == this->io_count_) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Writer::initiate_write_file") ACE_TEXT (" - ending proactor event loop\n"))); ACE_Proactor::instance ()->end_event_loop (); delete this; return 0; } // if we reached nere and merge_size is zero, we should write whatever is // in the queues (1 to 2 chunks together), so let's force the merge size to 1. if (0 == merge_size) { ACE_TEST_ASSERT (1 == odd_count && 1 >= even_count); merge_size = 1; } // Now that we found out what we want to do, prepare the chain // that will be written, and update the remainders ACE_Message_Block *new_odd_chain_head = this->odd_chain_; ACE_Message_Block *new_even_chain_head = this->even_chain_; // locate the place for detachment in the chains ACE_Message_Block *pre_odd = 0; ACE_Message_Block *pre_even = 0; for (size_t index = 0; index < merge_size; ++index) { pre_odd = new_odd_chain_head; if (new_odd_chain_head) new_odd_chain_head = new_odd_chain_head->cont (); pre_even = new_even_chain_head; if (new_even_chain_head) new_even_chain_head = new_even_chain_head->cont (); } // now detach the chain if (pre_odd) pre_odd->cont (0); if (pre_even) pre_even->cont (0); // perform merge between the two chains merge_odd_even_chains (this->odd_chain_, this->even_chain_); // and now finally perform the write ACE_Message_Block *united_mb = this->odd_chain_; // update the remainders of the chains this->odd_chain_ = new_odd_chain_head; this->even_chain_ = new_even_chain_head; size_t increment_writing_file_offset = united_mb->total_length (); // Reconstruct the file // Write the size, not the length, because we must write in chunks // of <page size> ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Writer::initiate_write_file: write %d bytes at %d\n"), united_mb->total_size (), this->writing_file_offset_)); if (this->wf_.writev (*united_mb, united_mb->total_size (), this->writing_file_offset_) == -1) { free_chunks_chain (united_mb); ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("Writer::initiate_write_file::ACE_Asynch_Write_Stream::writev")), -1); } // we update now because otherwise, we'd have error when performing // pipelined writing (that is, mulitple calls to write before the callbacks // to handle_x) this->writing_file_offset_ += static_cast<u_long> (increment_writing_file_offset); ++this->io_count_; return 0; }