本文整理汇总了C++中CommandOptionParser类的典型用法代码示例。如果您正苦于以下问题:C++ CommandOptionParser类的具体用法?C++ CommandOptionParser怎么用?C++ CommandOptionParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommandOptionParser类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseCmdLine
Settings parseCmdLine(CommandOptionParser& cp, int argc, char** argv)
{
cp.parse(argc, argv);
if (cp.getOption(optHelp).isPresent())
{
cp.displayOptionsHelp(std::cout);
exit(0);
}
Settings s;
s.basePath = cp.getOption(optPath).getParam(0, s.basePath);
return s;
}
示例2: main
int main(int argc, char** argv)
{
CommandOptionParser cp;
cp.addOption(CommandOption(optHelp, 0, 0, " Displays help information."));
cp.addOption(CommandOption(optPrefix, 1, 1, "dir Prefix directory for aeron driver."));
signal(SIGINT, sigIntHandler);
try
{
Settings settings = parseCmdLine(cp, argc, argv);
// if (settings.dirPrefix != "")
// {
// context.aeronDir(settings.dirPrefix);
// }
while (running)
{
}
std::cout << "Shutting Down..." << std::endl;
}
catch (CommandOptionException& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
cp.displayOptionsHelp(std::cerr);
return -1;
}
catch (std::exception& e)
{
std::cerr << "FAILED: " << e.what() << " : " << std::endl;
return -1;
}
return 0;
}
示例3: parseCmdLine
Settings parseCmdLine(CommandOptionParser& cp, int argc, char** argv)
{
cp.parse(argc, argv);
if (cp.getOption(optHelp).isPresent())
{
cp.displayOptionsHelp(std::cout);
exit(0);
}
Settings s;
s.dirPrefix = cp.getOption(optPrefix).getParam(0, s.dirPrefix);
s.channel = cp.getOption(optChannel).getParam(0, s.channel);
s.streamId = cp.getOption(optStreamId).getParamAsInt(0, 1, INT32_MAX, s.streamId);
s.numberOfMessages = cp.getOption(optMessages).getParamAsInt(0, 0, INT32_MAX, s.numberOfMessages);
s.lingerTimeoutMs = cp.getOption(optLinger).getParamAsInt(0, 0, 60 * 60 * 1000, s.lingerTimeoutMs);
return s;
}
示例4: parseCmdLine
Settings parseCmdLine(CommandOptionParser& cp, int argc, char** argv)
{
cp.parse(argc, argv);
if (cp.getOption(optHelp).isPresent())
{
cp.displayOptionsHelp(std::cout);
exit(0);
}
Settings s;
s.dirPrefix = cp.getOption(optPrefix).getParam(0, s.dirPrefix);
s.channel = cp.getOption(optChannel).getParam(0, s.channel);
s.streamId = cp.getOption(optStreamId).getParamAsInt(0, 1, INT32_MAX, s.streamId);
s.fragmentCountLimit = cp.getOption(optFrags).getParamAsInt(0, 1, INT32_MAX, s.fragmentCountLimit);
return s;
}
示例5: main
int main(int argc, char **argv)
{
CommandOptionParser cp;
cp.addOption(CommandOption (optHelp, 0, 0, " Displays help information."));
cp.addOption(CommandOption (optPrefix, 1, 1, "dir Prefix directory for aeron driver."));
cp.addOption(CommandOption (optPingChannel, 1, 1, "channel Ping Channel."));
cp.addOption(CommandOption (optPongChannel, 1, 1, "channel Pong Channel."));
cp.addOption(CommandOption (optPingStreamId, 1, 1, "streamId Ping Stream ID."));
cp.addOption(CommandOption (optPongStreamId, 1, 1, "streamId Pong Stream ID."));
cp.addOption(CommandOption (optFrags, 1, 1, "limit Fragment Count Limit."));
signal (SIGINT, sigIntHandler);
try
{
Settings settings = parseCmdLine(cp, argc, argv);
std::cout << "Subscribing Ping at " << settings.pingChannel << " on Stream ID " << settings.pingStreamId << std::endl;
std::cout << "Publishing Pong at " << settings.pongChannel << " on Stream ID " << settings.pongStreamId << std::endl;
aeron::Context context;
if (settings.dirPrefix != "")
{
context.aeronDir(settings.dirPrefix);
}
context.newSubscriptionHandler(
[](const std::string& channel, std::int32_t streamId, std::int64_t correlationId)
{
std::cout << "Subscription: " << channel << " " << correlationId << ":" << streamId << std::endl;
});
context.newPublicationHandler(
[](const std::string& channel, std::int32_t streamId, std::int32_t sessionId, std::int64_t correlationId)
{
std::cout << "Publication: " << channel << " " << correlationId << ":" << streamId << ":" << sessionId << std::endl;
});
context.availableImageHandler([](
Image &image,
const std::string &channel,
std::int32_t streamId,
std::int32_t sessionId,
std::int64_t joiningPosition,
const std::string &sourceIdentity)
{
std::cout << "Available image on " << channel << " streamId=" << streamId << " sessionId=" << sessionId;
std::cout << " at position=" << joiningPosition << " from " << sourceIdentity << std::endl;
});
context.unavailableImageHandler(
[](Image &image, const std::string &channel, std::int32_t streamId, std::int32_t sessionId,
std::int64_t position)
{
std::cout << "Unavailable image on " << channel << "streamId=" << streamId << " sessionId=" << sessionId;
std::cout << " at position=" << position << std::endl;
});
Aeron aeron(context);
std::int64_t subscriptionId = aeron.addSubscription(settings.pingChannel, settings.pingStreamId);
std::int64_t publicationId = aeron.addPublication(settings.pongChannel, settings.pongStreamId);
std::shared_ptr<Subscription> pingSubscription = aeron.findSubscription(subscriptionId);
while (!pingSubscription)
{
std::this_thread::yield();
pingSubscription = aeron.findSubscription(subscriptionId);
}
std::shared_ptr<Publication> pongPublication = aeron.findPublication(publicationId);
while (!pongPublication)
{
std::this_thread::yield();
pongPublication = aeron.findPublication(publicationId);
}
BusySpinIdleStrategy idleStrategy;
BusySpinIdleStrategy pingHandlerIdleStrategy;
FragmentAssembler fragmentAssembler(
[&](AtomicBuffer& buffer, index_t offset, index_t length, Header& header)
{
while (pongPublication->offer(buffer, offset, length) < 0L)
{
pingHandlerIdleStrategy.idle(0);
}
});
fragment_handler_t handler = fragmentAssembler.handler();
while (running)
{
const int fragmentsRead = pingSubscription->poll(handler, settings.fragmentCountLimit);
idleStrategy.idle(fragmentsRead);
}
std::cout << "Shutting down...\n";
}
//.........这里部分代码省略.........
示例6: main
int main(int argc, char **argv)
{
CommandOptionParser cp;
cp.addOption(CommandOption (optHelp, 0, 0, " Displays help information."));
cp.addOption(CommandOption (optPrefix, 1, 1, "dir Prefix directory for aeron driver."));
cp.addOption(CommandOption (optChannel, 1, 1, "channel Channel."));
cp.addOption(CommandOption (optStreamId, 1, 1, "streamId Stream ID."));
cp.addOption(CommandOption (optFrags, 1, 1, "limit Fragment Count Limit."));
signal (SIGINT, sigIntHandler);
try
{
Settings settings = parseCmdLine(cp, argc, argv);
std::cout << "Subscribing to channel " << settings.channel << " on Stream ID " << settings.streamId << std::endl;
aeron::Context context;
if (settings.dirPrefix != "")
{
context.aeronDir(settings.dirPrefix);
}
context.newSubscriptionHandler(
[](const std::string& channel, std::int32_t streamId, std::int64_t correlationId)
{
std::cout << "Subscription: " << channel << " " << correlationId << ":" << streamId << std::endl;
});
context.newConnectionHandler([](
const std::string& channel,
std::int32_t streamId,
std::int32_t sessionId,
std::int64_t joiningPosition,
const std::string& sourceIdentity)
{
std::cout << "New connection on " << channel << " streamId=" << streamId << " sessionId=" << sessionId;
std::cout << " at position=" << joiningPosition << " from " << sourceIdentity << std::endl;
});
context.inactiveConnectionHandler(
[](const std::string& channel, std::int32_t streamId, std::int32_t sessionId, std::int64_t position)
{
std::cout << "Inactive connection on " << channel << "streamId=" << streamId << " sessionId=" << sessionId;
std::cout << " at position=" << position << std::endl;
});
Aeron aeron(context);
// add the subscription to start the process
std::int64_t id = aeron.addSubscription(settings.channel, settings.streamId);
std::shared_ptr<Subscription> subscription = aeron.findSubscription(id);
// wait for the subscription to be valid
while (!subscription)
{
std::this_thread::yield();
subscription = aeron.findSubscription(id);
}
BusySpinIdleStrategy idleStrategy;
RateReporter rateReporter(std::chrono::seconds(1), printRate);
FragmentAssemblyAdapter fragmentAssemblyAdapter(rateReporterHandler(rateReporter));
fragment_handler_t handler = fragmentAssemblyAdapter.handler();
std::thread rateReporterThread([&](){ rateReporter.run(); });
while (running)
{
const int fragmentsRead = subscription->poll(handler, settings.fragmentCountLimit);
idleStrategy.idle(fragmentsRead);
}
std::cout << "Shutting down...\n";
rateReporter.halt();
rateReporterThread.join();
}
catch (CommandOptionException& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
cp.displayOptionsHelp(std::cerr);
return -1;
}
catch (SourcedException& e)
{
std::cerr << "FAILED: " << e.what() << " : " << e.where() << std::endl;
return -1;
}
catch (std::exception& e)
{
std::cerr << "FAILED: " << e.what() << " : " << std::endl;
return -1;
}
return 0;
}
示例7: main
int main (int argc, char** argv)
{
CommandOptionParser cp;
cp.addOption(CommandOption(optHelp, 0, 0, " Displays help information."));
cp.addOption(CommandOption(optPath, 1, 1, "basePath Base Path to shared memory. Default: " + Context::defaultAeronPath()));
try
{
Settings settings = parseCmdLine(cp, argc, argv);
const std::string filename = LossReportDescriptor::file(settings.basePath);
if (MemoryMappedFile::getFileSize(filename.c_str()) < 0)
{
std::cerr << "Loss report does not exist: " << filename << std::endl;
std::exit(1);
}
MemoryMappedFile::ptr_t lossReportFile = MemoryMappedFile::mapExistingReadOnly(filename.c_str());
AtomicBuffer buffer(lossReportFile->getMemoryPtr(), lossReportFile->getMemorySize());
std::cout <<
"OBSERVATION_COUNT, " <<
"TOTAL_BYTES_LOST, " <<
"FIRST_OBSERVATION, " <<
"LAST_OBSERVATION, " <<
"SESSION_ID, " <<
"STREAM_ID, " <<
"CHANNEL, " <<
"SOURCE" << std::endl;
const int entriesRead = LossReportReader::read(
buffer,
[](
std::int64_t observationCount,
std::int64_t totalBytesLost,
std::int64_t firstObservationTimestamp,
std::int64_t lastObservationTimestamp,
std::int32_t sessionId,
std::int32_t streamId,
const std::string &channel,
const std::string &source)
{
std::cout << std::to_string(observationCount) << ",";
std::cout << std::to_string(totalBytesLost) << ",";
std::cout << formatDate(firstObservationTimestamp) << ",";
std::cout << formatDate(lastObservationTimestamp) << ",";
std::cout << std::to_string(sessionId) << ",";
std::cout << std::to_string(streamId) << ",";
std::cout << channel << ",";
std::cout << source << std::endl;
});
std::cout << std::to_string(entriesRead) << " entries read" << std::endl;
}
catch (const CommandOptionException& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
cp.displayOptionsHelp(std::cerr);
return -1;
}
catch (const SourcedException& e)
{
std::cerr << "FAILED: " << e.what() << " : " << e.where() << std::endl;
return -1;
}
catch (const std::exception& e)
{
std::cerr << "FAILED: " << e.what() << " : " << std::endl;
return -1;
}
return 0;
}
示例8: main
int main (int argc, char** argv)
{
CommandOptionParser cp;
cp.addOption(CommandOption(optHelp, 0, 0, " Displays help information."));
cp.addOption(CommandOption(optPath, 1, 1, "basePath Base Path to shared memory. Default: " + Context::defaultAeronPath()));
cp.addOption(CommandOption(optPeriod, 1, 1, "update period Update period in milliseconds. Default: 1000ms"));
signal (SIGINT, sigIntHandler);
try
{
Settings settings = parseCmdLine(cp, argc, argv);
MemoryMappedFile::ptr_t cncFile = MemoryMappedFile::mapExistingReadOnly(
(settings.basePath + "/" + CncFileDescriptor::CNC_FILE).c_str());
const std::int32_t cncVersion = CncFileDescriptor::cncVersionVolatile(cncFile);
if (cncVersion != CncFileDescriptor::CNC_VERSION)
{
std::cerr << "CNC version not supported: file version=" << cncVersion << std::endl;
return -1;
}
const std::int64_t clientLivenessTimeoutNs = CncFileDescriptor::clientLivenessTimeout(cncFile);
const std::int64_t pid = CncFileDescriptor::pid(cncFile);
AtomicBuffer metadataBuffer = CncFileDescriptor::createCounterMetadataBuffer(cncFile);
AtomicBuffer valuesBuffer = CncFileDescriptor::createCounterValuesBuffer(cncFile);
CountersReader counters(metadataBuffer, valuesBuffer);
while(running)
{
time_t rawtime;
char currentTime[80];
::time(&rawtime);
struct tm localTm;
#ifdef _MSC_VER
_localtime_s(&localTm, &rawTime);
#else
::localtime_r(&rawtime, &localTm);
#endif
::strftime(currentTime, sizeof(currentTime) - 1, "%H:%M:%S", &localTm);
std::printf("\033[H\033[2J");
std::printf(
"%s - Aeron Stat (CnC v%" PRId32 "), pid %" PRId64 ", client liveness %s ns\n",
currentTime, cncVersion, pid, toStringWithCommas(clientLivenessTimeoutNs).c_str());
std::printf("===========================\n");
counters.forEach([&](std::int32_t counterId, std::int32_t, const AtomicBuffer&, const std::string& l)
{
std::int64_t value = counters.getCounterValue(counterId);
std::printf("%3d: %20s - %s\n", counterId, toStringWithCommas(value).c_str(), l.c_str());
});
std::this_thread::sleep_for(std::chrono::milliseconds(settings.updateIntervalMs));
}
std::cout << "Exiting..." << std::endl;
}
catch (const CommandOptionException& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
cp.displayOptionsHelp(std::cerr);
return -1;
}
catch (const SourcedException& e)
{
std::cerr << "FAILED: " << e.what() << " : " << e.where() << std::endl;
return -1;
}
catch (const std::exception& e)
{
std::cerr << "FAILED: " << e.what() << " : " << std::endl;
return -1;
}
return 0;
}
示例9: main
int main(int argc, char** argv)
{
CommandOptionParser cp;
cp.addOption(CommandOption (optHelp, 0, 0, " Displays help information."));
cp.addOption(CommandOption (optPrefix, 1, 1, "dir Prefix directory for aeron driver."));
cp.addOption(CommandOption (optChannel, 1, 1, "channel Channel."));
cp.addOption(CommandOption (optStreamId, 1, 1, "streamId Stream ID."));
signal (SIGINT, sigIntHandler);
try
{
Settings settings = parseCmdLine(cp, argc, argv);
std::cout << "Subscribing to channel " << settings.channel << " on Stream ID " << settings.streamId << std::endl;
aeron::Context context;
if (settings.dirPrefix != "")
{
context.aeronDir(settings.dirPrefix);
}
context.newSubscriptionHandler(
[](const std::string& channel, std::int32_t streamId, std::int64_t correlationId)
{
std::cout << "Subscription: " << channel << " " << correlationId << ":" << streamId << std::endl;
});
context.availableImageHandler([](Image &image)
{
std::cout << "Available image correlationId=" << image.correlationId() << " sessionId=" << image.sessionId();
std::cout << " at position=" << image.position() << " from " << image.sourceIdentity() << std::endl;
});
context.unavailableImageHandler([](Image &image)
{
std::cout << "Unavailable image on correlationId=" << image.correlationId() << " sessionId=" << image.sessionId();
std::cout << " at position=" << image.position() << " from " << image.sourceIdentity() << std::endl;
});
std::shared_ptr<Aeron> aeron = Aeron::connect(context);
// add the subscription to start the process
std::int64_t id = aeron->addSubscription(settings.channel, settings.streamId);
std::shared_ptr<Subscription> subscription = aeron->findSubscription(id);
// wait for the subscription to be valid
while (!subscription)
{
std::this_thread::yield();
subscription = aeron->findSubscription(id);
}
fragment_handler_t handler = printStringMessage();
SleepingIdleStrategy idleStrategy(IDLE_SLEEP_MS);
while (running)
{
const int fragmentsRead = subscription->poll(handler, FRAGMENTS_LIMIT);
idleStrategy.idle(fragmentsRead);
}
}
catch (CommandOptionException& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
cp.displayOptionsHelp(std::cerr);
return -1;
}
catch (SourcedException& e)
{
std::cerr << "FAILED: " << e.what() << " : " << e.where() << std::endl;
return -1;
}
catch (std::exception& e)
{
std::cerr << "FAILED: " << e.what() << " : " << std::endl;
return -1;
}
return 0;
}
示例10: parseCmdLine
Settings parseCmdLine(CommandOptionParser& cp, int argc, char** argv)
{
cp.parse(argc, argv);
if (cp.getOption(optHelp).isPresent())
{
cp.displayOptionsHelp(std::cout);
exit(0);
}
Settings s;
s.dirPrefix = cp.getOption(optPrefix).getParam(0, s.dirPrefix);
s.channel = cp.getOption(optChannel).getParam(0, s.channel);
s.streamId = cp.getOption(optStreamId).getParamAsInt(0, 1, INT32_MAX, s.streamId);
s.numberOfMessages = cp.getOption(optMessages).getParamAsLong(0, 0, INT64_MAX, s.numberOfMessages);
s.messageLength = cp.getOption(optLength).getParamAsInt(0, sizeof(std::int64_t), INT32_MAX, s.messageLength);
s.lingerTimeoutMs = cp.getOption(optLinger).getParamAsInt(0, 0, 60 * 60 * 1000, s.lingerTimeoutMs);
s.fragmentCountLimit = cp.getOption(optFrags).getParamAsInt(0, 1, INT32_MAX, s.fragmentCountLimit);
s.randomMessageLength = cp.getOption(optRandLen).isPresent();
s.progress = cp.getOption(optProgress).isPresent();
return s;
}
示例11: main
int main(int argc, char **argv)
{
CommandOptionParser cp;
cp.addOption(CommandOption (optHelp, 0, 0, " Displays help information."));
cp.addOption(CommandOption (optRandLen, 0, 0, " Random Message Length."));
cp.addOption(CommandOption (optProgress, 0, 0, " Print rate progress while sending."));
cp.addOption(CommandOption (optPrefix, 1, 1, "dir Prefix directory for aeron driver."));
cp.addOption(CommandOption (optChannel, 1, 1, "channel Channel."));
cp.addOption(CommandOption (optStreamId, 1, 1, "streamId Stream ID."));
cp.addOption(CommandOption (optMessages, 1, 1, "number Number of Messages."));
cp.addOption(CommandOption (optLength, 1, 1, "length Length of Messages."));
cp.addOption(CommandOption (optLinger, 1, 1, "milliseconds Linger timeout in milliseconds."));
cp.addOption(CommandOption (optFrags, 1, 1, "limit Fragment Count Limit."));
signal (SIGINT, sigIntHandler);
try
{
Settings settings = parseCmdLine(cp, argc, argv);
std::cout << "Subscribing to channel " << settings.channel << " on Stream ID " << settings.streamId << std::endl;
::setlocale(LC_NUMERIC, "");
std::printf(
"Streaming %'ld messages of%s size %d bytes to %s on stream ID %d\n",
settings.numberOfMessages,
settings.randomMessageLength ? " random" : "",
settings.messageLength,
settings.channel.c_str(),
settings.streamId);
aeron::Context context;
if (settings.dirPrefix != "")
{
context.aeronDir(settings.dirPrefix);
}
context.newPublicationHandler(
[](const std::string& channel, std::int32_t streamId, std::int32_t sessionId, std::int64_t correlationId)
{
std::cout << "Publication: " << channel << " " << correlationId << ":" << streamId << ":" << sessionId << std::endl;
});
context.newSubscriptionHandler(
[](const std::string& channel, std::int32_t streamId, std::int64_t correlationId)
{
std::cout << "Subscription: " << channel << " " << correlationId << ":" << streamId << std::endl;
});
context.availableImageHandler([](
Image &image,
const std::string &channel,
std::int32_t streamId,
std::int32_t sessionId,
std::int64_t joiningPosition,
const std::string &sourceIdentity)
{
std::cout << "Available image on " << channel << " streamId=" << streamId << " sessionId=" << sessionId;
std::cout << " at position=" << joiningPosition << " from " << sourceIdentity << std::endl;
});
context.unavailableImageHandler(
[](Image &image, const std::string &channel, std::int32_t streamId, std::int32_t sessionId,
std::int64_t position)
{
std::cout << "Unavailable image on " << channel << "streamId=" << streamId << " sessionId=" << sessionId;
std::cout << " at position=" << position << std::endl;
});
Aeron aeron(context);
std::int64_t subscriptionId = aeron.addSubscription(settings.channel, settings.streamId);
std::int64_t publicationId = aeron.addPublication(settings.channel, settings.streamId);
std::shared_ptr<Subscription> subscription = aeron.findSubscription(subscriptionId);
while (!subscription)
{
std::this_thread::yield();
subscription = aeron.findSubscription(subscriptionId);
}
std::shared_ptr<Publication> publication = aeron.findPublication(publicationId);
while (!publication)
{
std::this_thread::yield();
publication = aeron.findPublication(publicationId);
}
std::unique_ptr<std::uint8_t[]> buffer(new std::uint8_t[settings.messageLength]);
concurrent::AtomicBuffer srcBuffer(buffer.get(), settings.messageLength);
BusySpinIdleStrategy offerIdleStrategy;
BusySpinIdleStrategy pollIdleStrategy;
RateReporter rateReporter(std::chrono::seconds(1), printRate);
FragmentAssembler fragmentAssembler(rateReporterHandler(rateReporter));
fragment_handler_t handler = fragmentAssembler.handler();
//.........这里部分代码省略.........
示例12: main
int main(int argc, char** argv)
{
CommandOptionParser cp;
cp.addOption(CommandOption (optHelp, 0, 0, " Displays help information."));
cp.addOption(CommandOption (optPrefix, 1, 1, "dir Prefix directory for aeron driver."));
cp.addOption(CommandOption (optChannel, 1, 1, "channel Channel."));
cp.addOption(CommandOption (optStreamId, 1, 1, "streamId Stream ID."));
cp.addOption(CommandOption (optMessages, 1, 1, "number Number of Messages."));
cp.addOption(CommandOption (optLinger, 1, 1, "milliseconds Linger timeout in milliseconds."));
signal (SIGINT, sigIntHandler);
try
{
Settings settings = parseCmdLine(cp, argc, argv);
std::cout << "Publishing to channel " << settings.channel << " on Stream ID " << settings.streamId << std::endl;
aeron::Context context;
if (settings.dirPrefix != "")
{
context.aeronDir(settings.dirPrefix);
}
context.newPublicationHandler(
[](const std::string& channel, std::int32_t streamId, std::int32_t sessionId, std::int64_t correlationId)
{
std::cout << "Publication: " << channel << " " << correlationId << ":" << streamId << ":" << sessionId << std::endl;
});
std::shared_ptr<Aeron> aeron = Aeron::connect(context);
// add the publication to start the process
std::int64_t id = aeron->addPublication(settings.channel, settings.streamId);
std::shared_ptr<Publication> publication = aeron->findPublication(id);
// wait for the publication to be valid
while (!publication)
{
std::this_thread::yield();
publication = aeron->findPublication(id);
}
AERON_DECL_ALIGNED(buffer_t buffer, 16);
concurrent::AtomicBuffer srcBuffer(&buffer[0], buffer.size());
char message[256];
for (int i = 0; i < settings.numberOfMessages && running; i++)
{
#if _MSC_VER
const int messageLen = ::sprintf_s(message, sizeof(message), "Hello World! %d", i);
#else
const int messageLen = ::snprintf(message, sizeof(message), "Hello World! %d", i);
#endif
srcBuffer.putBytes(0, reinterpret_cast<std::uint8_t *>(message), messageLen);
std::cout << "offering " << i << "/" << settings.numberOfMessages;
std::cout.flush();
const std::int64_t result = publication->offer(srcBuffer, 0, messageLen);
if (result < 0)
{
if (PUBLICATION_NOT_CONNECTED == result)
{
std::cout << " not connected yet." << std::endl;
}
else if (PUBLICATION_BACK_PRESSURE == result)
{
std::cout << " back pressured." << std::endl;
}
else
{
std::cout << " ah?! unknown " << result << std::endl;
}
}
else
{
std::cout << " yay!" << std::endl;
}
std::this_thread::sleep_for(std::chrono::seconds(1));
}
std::cout << "Done sending." << std::endl;
if (settings.lingerTimeoutMs > 0)
{
std::cout << "Lingering for " << settings.lingerTimeoutMs << " milliseconds." << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(settings.lingerTimeoutMs));
}
}
catch (CommandOptionException& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
cp.displayOptionsHelp(std::cerr);
return -1;
}
//.........这里部分代码省略.........
示例13: main
int main (int argc, char** argv)
{
CommandOptionParser cp;
cp.addOption(CommandOption(optHelp, 0, 0, " Displays help information."));
cp.addOption(CommandOption(optPath, 1, 1, "basePath Base Path to shared memory. Default: " + Context::defaultAeronPath()));
try
{
Settings settings = parseCmdLine(cp, argc, argv);
MemoryMappedFile::ptr_t cncFile = MemoryMappedFile::mapExistingReadOnly(
(settings.basePath + "/" + CncFileDescriptor::CNC_FILE).c_str());
const std::int32_t cncVersion = CncFileDescriptor::cncVersionVolatile(cncFile);
if (cncVersion != CncFileDescriptor::CNC_VERSION)
{
std::cerr << "CNC version not supported: file version=" << cncVersion << std::endl;
return -1;
}
AtomicBuffer errorBuffer = CncFileDescriptor::createErrorLogBuffer(cncFile);
const int distinctErrorCount = ErrorLogReader::read(
errorBuffer,
[](
std::int32_t observationCount,
std::int64_t firstObservationTimestamp,
std::int64_t lastObservationTimestamp,
const std::string &encodedException)
{
std::printf(
"***\n%d observations from %s to %s for:\n %s\n",
observationCount,
formatDate(firstObservationTimestamp).c_str(),
formatDate(lastObservationTimestamp).c_str(),
encodedException.c_str());
},
0);
std::printf("\n%d distinct errors observed.\n", distinctErrorCount);
}
catch (const CommandOptionException& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
cp.displayOptionsHelp(std::cerr);
return -1;
}
catch (const SourcedException& e)
{
std::cerr << "FAILED: " << e.what() << " : " << e.where() << std::endl;
return -1;
}
catch (const std::exception& e)
{
std::cerr << "FAILED: " << e.what() << " : " << std::endl;
return -1;
}
return 0;
}