void dlm_message_out(struct dlm_message *ms) { struct dlm_header *hd = (struct dlm_header *) ms; header_out(hd); ms->m_type = cpu_to_le32(ms->m_type); ms->m_nodeid = cpu_to_le32(ms->m_nodeid); ms->m_pid = cpu_to_le32(ms->m_pid); ms->m_lkid = cpu_to_le32(ms->m_lkid); ms->m_remid = cpu_to_le32(ms->m_remid); ms->m_parent_lkid = cpu_to_le32(ms->m_parent_lkid); ms->m_parent_remid = cpu_to_le32(ms->m_parent_remid); ms->m_exflags = cpu_to_le32(ms->m_exflags); ms->m_sbflags = cpu_to_le32(ms->m_sbflags); ms->m_flags = cpu_to_le32(ms->m_flags); ms->m_lvbseq = cpu_to_le32(ms->m_lvbseq); ms->m_hash = cpu_to_le32(ms->m_hash); ms->m_status = cpu_to_le32(ms->m_status); ms->m_grmode = cpu_to_le32(ms->m_grmode); ms->m_rqmode = cpu_to_le32(ms->m_rqmode); ms->m_bastmode = cpu_to_le32(ms->m_bastmode); ms->m_asts = cpu_to_le32(ms->m_asts); ms->m_result = cpu_to_le32(to_dlm_errno(ms->m_result)); }
void dlm_rcom_out(struct dlm_rcom *rc) { struct dlm_header *hd = (struct dlm_header *) rc; int type = rc->rc_type; header_out(hd); rc->rc_type = cpu_to_le32(rc->rc_type); rc->rc_result = cpu_to_le32(rc->rc_result); rc->rc_id = cpu_to_le64(rc->rc_id); rc->rc_seq = cpu_to_le64(rc->rc_seq); rc->rc_seq_reply = cpu_to_le64(rc->rc_seq_reply); if ((type == DLM_RCOM_LOCK) || (type == DLM_RCOM_LOCK_REPLY)) rcom_lock_out((struct rcom_lock *) rc->rc_buf); else if (type == DLM_RCOM_STATUS_REPLY) rcom_config_out((struct rcom_config *) rc->rc_buf); }
int main(int argc, char* argv[]) { if (argc < 4 || argc > 6) { std::cout << "Usage: embedfile [-wx] [-text] <inout> <output> <fieldname>" << std::endl; return error_invalidargs; } bool wxWidgets_image = false; bool text_content = false; int argc_offset = 1; if (casecmp(argv[argc_offset], "-wx")) { wxWidgets_image = true; argc_offset++; } if (casecmp(argv[argc_offset], "-text")) { text_content = true; argc_offset++; } std::string input_file(argv[argc_offset]); std::string output_basename(argv[argc_offset + 1]); std::string field_name(argv[argc_offset + 2]); std::ios::openmode mode = std::ios::in; if (!text_content) { mode |= std::ios::binary; } std::ifstream file_in(input_file.c_str(), mode); if (file_in.bad()) { std::cout << "ERROR: Error opening input file: " << input_file << std::endl; return error_cantopenfile; } // Get the size of the input stream size_t input_size; file_in.seekg(0, std::ios::end); if ((int) file_in.tellg() != -1) { input_size = (size_t) file_in.tellg(); } else { std::cout << "ERROR: Failed to get size of input file: " << input_file << std::endl; file_in.close(); return error_ioerror; } file_in.seekg(0, std::ios::beg); // Generates two files, one header and one source file std::string headerName = output_basename + ".h"; std::string sourceName = output_basename + ".cpp"; std::ofstream source_out(sourceName.c_str()); if (source_out.bad()) { std::cout << "ERROR: Error opening output file: " << sourceName << std::endl; return error_cantoutputfile; } std::ofstream header_out(headerName.c_str()); if (header_out.bad()) { std::cout << "ERROR: Error opening output file: " << headerName << std::endl; return error_cantoutputfile; } if (text_content) { do_text_content(file_in, source_out, field_name, input_size); } else { do_binary_content(file_in, source_out, field_name, input_size, wxWidgets_image); } write_header(header_out, field_name, text_content, wxWidgets_image); file_in.close(); source_out.close(); header_out.close(); return error_none; }
int main(int argc, char *argv[]) { namespace po = boost::program_options; namespace fs = boost::filesystem; po::options_description desc("Allowed options"); desc.add_options() ("input,i", po::value<std::string>(), "input file") ("output,o", po::value<std::string>(), "output file") ("cpp,x", "produce cpp/header file on successful compilation") ("platform,p", po::value<unsigned>(), "set platform") ("device,d", po::value<unsigned>(), "set device") ("options,c", po::value<std::string>(), "compile options") ("help,h", "print this help message") ("list,l", "list platforms and devices"); po::positional_options_description pos; pos.add("input", 1); pos.add("output", 1); po::variables_map vm; try { po::store( po::command_line_parser(argc, argv).options(desc) .positional(pos).run(), vm); } catch(std::exception &e) { std::cerr << "options parsing error.\n" << desc << std::endl; return EXIT_FAILURE; } po::notify(vm); if(vm.count("help")) { std::cout << desc << std::endl; return EXIT_FAILURE; } if(vm.count("list")) { std::cout << "Accessible platforms:\n"; std::vector<cl::platform_ref> platforms; cl::platform_ref::get_platforms(platforms); for(unsigned i=0; i<platforms.size(); ++i) { cl::platform_ref p = platforms[i]; std::cout << i << ") " << p.name() << "\n"; std::cout << "\tAssociated devices:\n"; std::vector<cl::device_ref> devices; p.get_devices(devices); for(unsigned j=0; j<devices.size(); ++j) { cl::device_ref d = devices[j]; std::cout << "\t" << j << ") " << d.name() << "\n"; } } return EXIT_SUCCESS; } std::string input_path; std::string output_path; std::string options; bool do_output = false; unsigned platform_id = 0; unsigned device_id = 0; if(vm.count("input")) { input_path = vm["input"].as<std::string>(); } else { std::cout << "must provide input file.\n"; return EXIT_FAILURE; } if(vm.count("output")) { output_path = vm["output"].as<std::string>(); do_output = true; } if(vm.count("platform")) { platform_id = vm["platform"].as<unsigned>(); } if(vm.count("device")) { device_id = vm["device"].as<unsigned>(); } if(vm.count("options")) { options = vm["options"].as<std::string>(); } std::stringstream ss; std::ifstream in(input_path.c_str()); std::string line; while(std::getline(in, line)) { ss << line << "\n"; } std::vector<cl::platform_ref> platforms; std::vector<cl::device_ref> devices; cl::platform_ref::get_platforms(platforms); if(platform_id >= platforms.size()) { std::cerr << "invalid platform id\n"; return EXIT_FAILURE; } cl::platform_ref platform = platforms[platform_id]; platform.get_devices(devices); if(device_id >= devices.size()) { std::cerr << "invalid device id\n"; return EXIT_FAILURE; } cl::device_ref device = devices[device_id]; cl::context_ref context(platform, device); cl::program_ref program(context, ss.str()); std::cout << "context is " << platform.name() << "/" << device.name() << "\n"; std::cout << "OpenCL compiler options: " << options << "\n"; try { program.build(options); std::cout << "build successful!\n"; if(vm.count("cpp")) { fs::path input_path_obj(input_path); // older versions of boost don't have this method //std::string file_base = input_path_obj.stem(); std::size_t start = input_path.find_last_of('/'); if(start == std::string::npos) { start = 0; } else { ++start; } std::string file_base = input_path.substr(start, input_path.find_last_of('.')-start); std::string file_base_upper = file_base; boost::to_upper(file_base_upper); // write header std::stringstream filess; filess << input_path << ".hpp"; std::ofstream header_out(filess.str().c_str()); filess.str(""); filess << "#ifndef _" << file_base_upper << "_OPENCL_HPP_" << "\n"; filess << "#define _" << file_base_upper << "_OPENCL_HPP_" << "\n"; filess << "\n"; filess << "extern const char *" << file_base << "_opencl_source;" << "\n"; filess << "\n"; filess << "#endif\n\n"; header_out << filess.str(); header_out.close(); // write cpp file boost::regex rx; rx.assign( "(\\\\)|" "(\")"); const char *format = "(?1\\\\\\\\)" "(?2\\\\\")"; filess.str(""); filess << input_path << ".cpp"; std::ofstream source_out(filess.str().c_str()); std::ifstream source_in(input_path.c_str()); filess.str(""); filess << "const char *" << file_base << "_opencl_source = " << "\n"; while(getline(source_in, line)) { std::string sanitized_line = boost::regex_replace(line, rx, format, boost::match_default | boost::format_all); filess << "\t\"" << sanitized_line << "\\n\"\n"; } filess << ";"; source_out << filess.str(); source_out.close(); } } catch(const cl::cl_error &c) { std::cout << "error building program\n"; } std::cout << "build log:\n" << program.get_build_log(device) << "\n"; return EXIT_SUCCESS; }
void ClientRDPSNDChannel::receive(InStream & chunk) { if (this->wave_data_to_wait) { this->wave_data_to_wait -= chunk.in_remain(); if (this->wave_data_to_wait < 0) { this->wave_data_to_wait = 0; } if (this->last_PDU_is_WaveInfo) { chunk.in_skip_bytes(4); this->last_PDU_is_WaveInfo = false; } if (this->impl_sound) { this->impl_sound->setData(chunk.get_current(), chunk.in_remain()); } if (!(this->wave_data_to_wait)) { if (bool(this->verbose & RDPVerbose::rdpsnd)) { LOG(LOG_INFO, "SERVER >> RDPEA: Wave PDU"); } LOG(LOG_INFO, "SERVER >> RDPEA: Wave PDU 1"); if (this->impl_sound) { LOG(LOG_INFO, "SERVER >> RDPEA: Wave PDU 2"); uint8_t data[] = {'\0'}; LOG(LOG_INFO, "SERVER >> RDPEA: Wave PDU 3"); this->impl_sound->setData(data, 1); LOG(LOG_INFO, "SERVER >> RDPEA: Wave PDU 4"); this->impl_sound->play(); LOG(LOG_INFO, "SERVER >> RDPEA: Wave PDU 5"); // LOG(LOG_INFO, "ClientRDPSNDChannel::receive play!!!"); } LOG(LOG_INFO, "SERVER >> RDPEA: Wave PDU 6"); StaticOutStream<16> out_stream; rdpsnd::RDPSNDPDUHeader header(rdpsnd::SNDC_WAVECONFIRM, 4); header.emit(out_stream); LOG(LOG_INFO, "SERVER >> RDPEA: Wave PDU 7"); rdpsnd::WaveConfirmPDU wc(this->last_wTimeStamp, this->last_cBlockNo); wc.emit(out_stream); InStream chunk_to_send(out_stream.get_bytes()); LOG(LOG_INFO, "SERVER >> RDPEA: Wave PDU 8"); this->callback->send_to_mod_channel( channel_names::rdpsnd , chunk_to_send , out_stream.get_offset() , this->channel_flags ); if (bool(this->verbose & RDPVerbose::rdpsnd)) { LOG(LOG_INFO, "CLIENT >> RDPEA: Wave Confirm PDU"); } } } else { rdpsnd::RDPSNDPDUHeader header; header.receive(chunk); switch (header.msgType) { case rdpsnd::SNDC_FORMATS: { if (bool(this->verbose & RDPVerbose::rdpsnd)) { LOG(LOG_INFO, "SERVER >> RDPEA: Server Audio Formats and Version PDU"); } rdpsnd::ServerAudioFormatsandVersionHeader safsvh; safsvh.receive(chunk); StaticOutStream<1024> out_stream; rdpsnd::RDPSNDPDUHeader header_out(rdpsnd::SNDC_FORMATS, 38); header_out.emit(out_stream); rdpsnd::ClientAudioFormatsandVersionHeader cafvh( this->dwFlags , this->dwVolume , this->dwPitch , this->wDGramPort , this->wNumberOfFormats , this->wVersion ); cafvh.emit(out_stream); for (uint16_t i = 0; i < safsvh.wNumberOfFormats; i++) { rdpsnd::AudioFormat format; format.receive(chunk); // format.log(); if (format.wFormatTag == rdpsnd::WAVE_FORMAT_PCM) { format.emit(out_stream); if (this->impl_sound) { this->impl_sound->n_sample_per_sec = format.nSamplesPerSec; this->impl_sound->bit_per_sample = format.wBitsPerSample; this->impl_sound->n_channels = format.nChannels; this->impl_sound->n_block_align = format.nBlockAlign; this->impl_sound->bit_per_sec = format.nSamplesPerSec * (format.wBitsPerSample/8) * format.nChannels; } else { //LOG(LOG_WARNING, "No Sound System module found"); } } } InStream chunk_to_send(out_stream.get_bytes()); this->callback->send_to_mod_channel( channel_names::rdpsnd , chunk_to_send , out_stream.get_offset() , this->channel_flags ); if (bool(this->verbose & RDPVerbose::rdpsnd)) { LOG(LOG_INFO, "CLIENT >> RDPEA: Client Audio Formats and Version PDU"); } StaticOutStream<32> quality_stream; rdpsnd::RDPSNDPDUHeader header_quality(rdpsnd::SNDC_QUALITYMODE, 8); header_quality.emit(quality_stream); rdpsnd::QualityModePDU qm(rdpsnd::HIGH_QUALITY); qm.emit(quality_stream); InStream chunk_to_send2(quality_stream.get_bytes()); this->callback->send_to_mod_channel( channel_names::rdpsnd , chunk_to_send2 , quality_stream.get_offset() , this->channel_flags ); if (bool(this->verbose & RDPVerbose::rdpsnd)) { LOG(LOG_INFO, "CLIENT >> RDPEA: Quality Mode PDU"); } } break; case rdpsnd::SNDC_TRAINING: { if (bool(this->verbose & RDPVerbose::rdpsnd)) { LOG(LOG_INFO, "SERVER >> RDPEA: Training PDU"); } rdpsnd::TrainingPDU train; train.receive(chunk); StaticOutStream<32> out_stream; rdpsnd::RDPSNDPDUHeader header_quality(rdpsnd::SNDC_TRAINING, 4); header_quality.emit(out_stream); rdpsnd::TrainingConfirmPDU train_conf(train.wTimeStamp, train.wPackSize); train_conf.emit(out_stream); InStream chunk_to_send(out_stream.get_bytes()); this->callback->send_to_mod_channel( channel_names::rdpsnd , chunk_to_send , out_stream.get_offset() , this->channel_flags ); if (bool(this->verbose & RDPVerbose::rdpsnd)) { LOG(LOG_INFO, "CLIENT >> RDPEA: Training Confirm PDU"); } } break; case rdpsnd::SNDC_WAVE: { if (bool(this->verbose & RDPVerbose::rdpsnd)) { LOG(LOG_INFO, "SERVER >> RDPEA: Wave Info PDU"); } this->wave_data_to_wait = header.BodySize - 8; rdpsnd::WaveInfoPDU wi; wi.receive(chunk); this->last_cBlockNo = wi.cBlockNo; this->last_wTimeStamp = wi.wTimeStamp; if (this->impl_sound) { this->impl_sound->init(header.BodySize - 12); this->impl_sound->setData(wi.Data, 4); } this->last_PDU_is_WaveInfo = true; } break; case rdpsnd::SNDC_CLOSE: if (bool(this->verbose & RDPVerbose::rdpsnd)) { LOG(LOG_INFO, "SERVER >> RDPEA: Close PDU"); } break; case rdpsnd::SNDC_SETVOLUME: if (bool(this->verbose & RDPVerbose::rdpsnd)) { LOG(LOG_INFO, "SERVER >> RDPEA: SNDC_SETVOLUME PDU"); } { rdpsnd::VolumePDU v; v.receive(chunk); } break; case rdpsnd::SNDC_SETPITCH: if (bool(this->verbose & RDPVerbose::rdpsnd)) { LOG(LOG_INFO, "SERVER >> RDPEA: SNDC_SETPITCH PDU"); } { rdpsnd::PitchPDU p; p.receive(chunk); } break; // case rdpsnd::SNDC_CRYPTKEY: // LOG(LOG_INFO, "SERVER >> RDPEA: SNDC_CRYPTKEY PDU"); // break; // case rdpsnd::SNDC_WAVEENCRYPT: // LOG(LOG_INFO, "SERVER >> RDPEA: SNDC_WAVEENCRYPT PDU"); // break; case rdpsnd::SNDC_QUALITYMODE: if (bool(this->verbose & RDPVerbose::rdpsnd)) { LOG(LOG_INFO, "SERVER >> RDPEA: SNDC_QUALITYMODE PDU"); } { rdpsnd::QualityModePDU qm; qm.receive(chunk); } break; case rdpsnd::SNDC_WAVE2: if (bool(this->verbose & RDPVerbose::rdpsnd)) { LOG(LOG_INFO, "SERVER >> RDPEA: SNDC_WAVE2 PDU"); } { this->wave_data_to_wait = header.BodySize - 12; rdpsnd::Wave2PDU w2; w2.receive(chunk); if (this->impl_sound) { this->impl_sound->init(header.BodySize - 12); this->impl_sound->setData(chunk.get_current(), chunk.in_remain()); } this->last_PDU_is_WaveInfo = true; } break; default: LOG(LOG_WARNING, "SERVER >> RDPEA: Unknown message type: %x", header.msgType); break; } } }