mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-04 19:13:30 +01:00
updated tour
This commit is contained in:
parent
f828ae1e1f
commit
e522f90513
Binary file not shown.
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 30 KiB |
@ -50,9 +50,9 @@ Basic support for Unicode text is also available in the form of classes
|
|||||||
that convert text between different character encodings, including UTF-8
|
that convert text between different character encodings, including UTF-8
|
||||||
and UTF-16. Support for formatting and parsing numbers is there,
|
and UTF-16. Support for formatting and parsing numbers is there,
|
||||||
including a typesafe variant of sprintf. Regular expressions based on
|
including a typesafe variant of sprintf. Regular expressions based on
|
||||||
the well-known PCRE library (http://www.pcre.org) are provided as well.
|
the well-known PCRE library (http://www.pcre.org) are provided as well.
|
||||||
|
|
||||||
POCO gives you classes for handling dates and times in various variants.
|
POCO gives you classes for handling dates and times in various variants.
|
||||||
For accessing the file system, POCO has Poco::File and Poco::Path classes, as well as a
|
For accessing the file system, POCO has Poco::File and Poco::Path classes, as well as a
|
||||||
Poco::DirectoryIterator class. In many applications, some parts of the
|
Poco::DirectoryIterator class. In many applications, some parts of the
|
||||||
application need to tell other parts that something has happened. In
|
application need to tell other parts that something has happened. In
|
||||||
@ -67,21 +67,21 @@ and a pointer to a member function. The event can be fired by calling
|
|||||||
#include "Poco/BasicEvent.h"
|
#include "Poco/BasicEvent.h"
|
||||||
#include "Poco/Delegate.h"
|
#include "Poco/Delegate.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using Poco::BasicEvent;
|
using Poco::BasicEvent;
|
||||||
using Poco::Delegate;
|
using Poco::delegate;
|
||||||
|
|
||||||
class Source
|
class Source
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BasicEvent<int> theEvent;
|
BasicEvent<int> theEvent;
|
||||||
|
|
||||||
void fireEvent(int n)
|
void fireEvent(int n)
|
||||||
{
|
{
|
||||||
theEvent(this, n);
|
theEvent(this, n);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Target
|
class Target
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -90,20 +90,18 @@ and a pointer to a member function. The event can be fired by calling
|
|||||||
std::cout << "onEvent: " << arg << std::endl;
|
std::cout << "onEvent: " << arg << std::endl;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
Source source;
|
Source source;
|
||||||
Target target;
|
Target target;
|
||||||
|
|
||||||
source.theEvent += Delegate<Target, int>(
|
source.theEvent += delegate(&target, &Target::onEvent);
|
||||||
&target, &Target::onEvent);
|
|
||||||
|
|
||||||
source.fireEvent(42);
|
source.fireEvent(42);
|
||||||
|
|
||||||
source.theEvent -= Delegate<Target, int>(
|
source.theEvent -= delegate(&target, &Target::onEvent);
|
||||||
&target, &Target::onEvent);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
@ -111,7 +109,7 @@ and a pointer to a member function. The event can be fired by calling
|
|||||||
|
|
||||||
The stream classes available in POCO have already been mentioned. These are
|
The stream classes available in POCO have already been mentioned. These are
|
||||||
augmented by Poco::BinaryReader and Poco::BinaryWriter for writing binary data to
|
augmented by Poco::BinaryReader and Poco::BinaryWriter for writing binary data to
|
||||||
streams, automatically and transparently handling byte order issues.
|
streams, automatically and transparently handling byte order issues.
|
||||||
|
|
||||||
In complex multithreaded applications, the only way to find problems or
|
In complex multithreaded applications, the only way to find problems or
|
||||||
bugs is by writing extensive logging information. POCO provides a
|
bugs is by writing extensive logging information. POCO provides a
|
||||||
@ -120,7 +118,7 @@ routing to different channels, and formatting of log messages. Log
|
|||||||
messages can be written to the console, a file, the Windows Event Log,
|
messages can be written to the console, a file, the Windows Event Log,
|
||||||
the Unix syslog daemon, or to the network. If the channels provided by
|
the Unix syslog daemon, or to the network. If the channels provided by
|
||||||
POCO are not sufficient, it is easy to extend the logging framework with
|
POCO are not sufficient, it is easy to extend the logging framework with
|
||||||
new classes.
|
new classes.
|
||||||
|
|
||||||
For loading (and unloading) shared libraries at runtime,
|
For loading (and unloading) shared libraries at runtime,
|
||||||
POCO has a low-level Poco::SharedLibrary class. Based on it is the Poco::ClassLoader
|
POCO has a low-level Poco::SharedLibrary class. Based on it is the Poco::ClassLoader
|
||||||
@ -128,13 +126,13 @@ class template and supporting framework, allowing dynamic loading and
|
|||||||
unloading of C++ classes at runtime, similar to what's available to Java
|
unloading of C++ classes at runtime, similar to what's available to Java
|
||||||
and .NET developers. The class loader framework also makes it a breeze
|
and .NET developers. The class loader framework also makes it a breeze
|
||||||
to implement plug-in support for applications in a platform-independent
|
to implement plug-in support for applications in a platform-independent
|
||||||
way.
|
way.
|
||||||
|
|
||||||
Finally, POCO Foundation contains multithreading abstractions at
|
Finally, POCO Foundation contains multithreading abstractions at
|
||||||
different levels. Starting with a Poco::Thread class and the usual
|
different levels. Starting with a Poco::Thread class and the usual
|
||||||
synchronization primitives (Poco::Mutex, Poco::ScopedLock, Poco::Event,
|
synchronization primitives (Poco::Mutex, Poco::ScopedLock, Poco::Event,
|
||||||
Poco::Semaphore, Poco::RWLock), a Poco::ThreadPool class and support for
|
Poco::Semaphore, Poco::RWLock), a Poco::ThreadPool class and support for
|
||||||
thread-local storage, also high level abstractions like active objects are
|
thread-local storage, also high level abstractions like active objects are
|
||||||
available. Simply speaking, an active object is an object that has methods executing in
|
available. Simply speaking, an active object is an object that has methods executing in
|
||||||
their own thread. This makes asynchronous member function calls possible
|
their own thread. This makes asynchronous member function calls possible
|
||||||
-- call a member function, while the function executes, do a bunch of
|
-- call a member function, while the function executes, do a bunch of
|
||||||
@ -149,35 +147,35 @@ function's return value.
|
|||||||
#include "Poco/ActiveResult.h"
|
#include "Poco/ActiveResult.h"
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using Poco::ActiveMethod;
|
using Poco::ActiveMethod;
|
||||||
using Poco::ActiveResult;
|
using Poco::ActiveResult;
|
||||||
|
|
||||||
class ActiveAdder
|
class ActiveAdder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ActiveAdder(): add(this, &ActiveAdder::addImpl)
|
ActiveAdder(): add(this, &ActiveAdder::addImpl)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ActiveMethod<int, std::pair<int, int>, ActiveAdder> add;
|
ActiveMethod<int, std::pair<int, int>, ActiveAdder> add;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int addImpl(const std::pair<int, int>& args)
|
int addImpl(const std::pair<int, int>& args)
|
||||||
{
|
{
|
||||||
return args.first + args.second;
|
return args.first + args.second;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
ActiveAdder adder;
|
ActiveAdder adder;
|
||||||
|
|
||||||
ActiveResult<int> sum = adder.add(std::make_pair(1, 2));
|
ActiveResult<int> sum = adder.add(std::make_pair(1, 2));
|
||||||
// do other things
|
// do other things
|
||||||
sum.wait();
|
sum.wait();
|
||||||
std::cout << sum.data() << std::endl;
|
std::cout << sum.data() << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
@ -196,14 +194,14 @@ reads through the XML document and notifies the application whenever it
|
|||||||
encounters an element, character data, or other XML artifact. A SAX
|
encounters an element, character data, or other XML artifact. A SAX
|
||||||
parser does not need to load the complete XML document into memory, so
|
parser does not need to load the complete XML document into memory, so
|
||||||
it can be used to parse huge XML files efficiently. In contrast, DOM
|
it can be used to parse huge XML files efficiently. In contrast, DOM
|
||||||
(Document Object Model, http://www.w3.org/DOM/) gives the application
|
(Document Object Model, http://www.w3.org/DOM/) gives the application
|
||||||
complete access to an XML
|
complete access to an XML
|
||||||
document, using a tree-style object hierarchy. For this to work, the DOM
|
document, using a tree-style object hierarchy. For this to work, the DOM
|
||||||
parser provided by POCO has to load the entire document into memory. To
|
parser provided by POCO has to load the entire document into memory. To
|
||||||
reduce the memory footprint of the DOM document, the POCO DOM
|
reduce the memory footprint of the DOM document, the POCO DOM
|
||||||
implementation uses string pooling, storing frequently occuring strings
|
implementation uses string pooling, storing frequently occuring strings
|
||||||
such as element and attribute names only once. The XML library is based
|
such as element and attribute names only once. The XML library is based
|
||||||
on the Expat open source XML parser library (http://www.libexpat.org).
|
on the Expat open source XML parser library (http://www.libexpat.org).
|
||||||
Built on top of Expat
|
Built on top of Expat
|
||||||
are the SAX interfaces, and built on top of the SAX interfaces is the
|
are the SAX interfaces, and built on top of the SAX interfaces is the
|
||||||
DOM implementation. For strings, the XML library uses <[std::string]>, with
|
DOM implementation. For strings, the XML library uses <[std::string]>, with
|
||||||
@ -220,7 +218,7 @@ Included is support for handling command line arguments (validation,
|
|||||||
binding to configuration properties, etc.) and managing configuration
|
binding to configuration properties, etc.) and managing configuration
|
||||||
information. Different configuration file formats are supported --
|
information. Different configuration file formats are supported --
|
||||||
Windows-style INI files, Java-style property files, XML files and the
|
Windows-style INI files, Java-style property files, XML files and the
|
||||||
Windows registry.
|
Windows registry.
|
||||||
|
|
||||||
For server applications, the framework provides
|
For server applications, the framework provides
|
||||||
transparent support for Windows services and Unix daemons. Every server
|
transparent support for Windows services and Unix daemons. Every server
|
||||||
@ -234,18 +232,18 @@ executed from the command line, which makes testing and debugging easier.
|
|||||||
POCO's Net library makes it easy to write network-based applications. No
|
POCO's Net library makes it easy to write network-based applications. No
|
||||||
matter whether your application simply needs to send data over a plain
|
matter whether your application simply needs to send data over a plain
|
||||||
TCP socket, or whether your application needs a full-fledged built-in
|
TCP socket, or whether your application needs a full-fledged built-in
|
||||||
HTTP server, you will find something useful in the Net library.
|
HTTP server, you will find something useful in the Net library.
|
||||||
|
|
||||||
At the lowest level, the Net library contains socket classes, supporting TCP
|
At the lowest level, the Net library contains socket classes, supporting TCP
|
||||||
stream and server sockets, UDP sockets, multicast sockets, ICMP and raw
|
stream and server sockets, UDP sockets, multicast sockets, ICMP and raw
|
||||||
sockets. If your application needs secure sockets, these are available
|
sockets. If your application needs secure sockets, these are available
|
||||||
in the NetSSL library, implemented using OpenSSL (http://www.openssl.org).
|
in the NetSSL library, implemented using OpenSSL (http://www.openssl.org).
|
||||||
Based on the socket classes are two frameworks for building TCP servers -- one for
|
Based on the socket classes are two frameworks for building TCP servers -- one for
|
||||||
multithreaded servers (one thread per connection, taken from a thread
|
multithreaded servers (one thread per connection, taken from a thread
|
||||||
pool), one for servers based on the Acceptor-Reactor pattern. The
|
pool), one for servers based on the Acceptor-Reactor pattern. The
|
||||||
multithreaded Poco::Net::TCPServer class and its supporting framework are also the
|
multithreaded Poco::Net::TCPServer class and its supporting framework are also the
|
||||||
foundation for POCO's HTTP server implementation (Poco::Net::HTTPServer).
|
foundation for POCO's HTTP server implementation (Poco::Net::HTTPServer).
|
||||||
On the client side, the Net library provides classes for talking to HTTP servers,
|
On the client side, the Net library provides classes for talking to HTTP servers,
|
||||||
for sending and receiving files using the FTP protocol, for sending mail
|
for sending and receiving files using the FTP protocol, for sending mail
|
||||||
messages (including attachments) using SMTP and for receiving mail from
|
messages (including attachments) using SMTP and for receiving mail from
|
||||||
a POP3 server.
|
a POP3 server.
|
||||||
@ -289,7 +287,7 @@ server.
|
|||||||
#include "Poco/Util/OptionSet.h"
|
#include "Poco/Util/OptionSet.h"
|
||||||
#include "Poco/Util/HelpFormatter.h"
|
#include "Poco/Util/HelpFormatter.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using Poco::Net::ServerSocket;
|
using Poco::Net::ServerSocket;
|
||||||
using Poco::Net::HTTPRequestHandler;
|
using Poco::Net::HTTPRequestHandler;
|
||||||
using Poco::Net::HTTPRequestHandlerFactory;
|
using Poco::Net::HTTPRequestHandlerFactory;
|
||||||
@ -307,27 +305,26 @@ server.
|
|||||||
using Poco::Util::OptionSet;
|
using Poco::Util::OptionSet;
|
||||||
using Poco::Util::OptionCallback;
|
using Poco::Util::OptionCallback;
|
||||||
using Poco::Util::HelpFormatter;
|
using Poco::Util::HelpFormatter;
|
||||||
|
|
||||||
class TimeRequestHandler: public HTTPRequestHandler
|
class TimeRequestHandler: public HTTPRequestHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TimeRequestHandler(const std::string& format): _format(format)
|
TimeRequestHandler(const std::string& format): _format(format)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleRequest(HTTPServerRequest& request,
|
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
|
||||||
HTTPServerResponse& response)
|
|
||||||
{
|
{
|
||||||
Application& app = Application::instance();
|
Application& app = Application::instance();
|
||||||
app.logger().information("Request from "
|
app.logger().information("Request from %s",
|
||||||
+ request.clientAddress().toString());
|
request.clientAddress().toString());
|
||||||
|
|
||||||
Timestamp now;
|
Timestamp now;
|
||||||
std::string dt(DateTimeFormatter::format(now, _format));
|
std::string dt(DateTimeFormatter::format(now, _format));
|
||||||
|
|
||||||
response.setChunkedTransferEncoding(true);
|
response.setChunkedTransferEncoding(true);
|
||||||
response.setContentType("text/html");
|
response.setContentType("text/html");
|
||||||
|
|
||||||
std::ostream& ostr = response.send();
|
std::ostream& ostr = response.send();
|
||||||
ostr << "<html><head><title>HTTPTimeServer powered by "
|
ostr << "<html><head><title>HTTPTimeServer powered by "
|
||||||
"POCO C++ Libraries</title>";
|
"POCO C++ Libraries</title>";
|
||||||
@ -337,11 +334,11 @@ server.
|
|||||||
ostr << dt;
|
ostr << dt;
|
||||||
ostr << "</p></body></html>";
|
ostr << "</p></body></html>";
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string _format;
|
std::string _format;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TimeRequestHandlerFactory: public HTTPRequestHandlerFactory
|
class TimeRequestHandlerFactory: public HTTPRequestHandlerFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -349,47 +346,32 @@ server.
|
|||||||
_format(format)
|
_format(format)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTPRequestHandler* createRequestHandler(
|
HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request)
|
||||||
const HTTPServerRequest& request)
|
|
||||||
{
|
{
|
||||||
if (request.getURI() == "/")
|
if (request.getURI() == "/")
|
||||||
return new TimeRequestHandler(_format);
|
return new TimeRequestHandler(_format);
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string _format;
|
std::string _format;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HTTPTimeServer: public Poco::Util::ServerApplication
|
class HTTPTimeServer: public Poco::Util::ServerApplication
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
HTTPTimeServer(): _helpRequested(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~HTTPTimeServer()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void initialize(Application& self)
|
void initialize(Application& self)
|
||||||
{
|
{
|
||||||
loadConfiguration();
|
loadConfiguration();
|
||||||
ServerApplication::initialize(self);
|
ServerApplication::initialize(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitialize()
|
|
||||||
{
|
|
||||||
ServerApplication::uninitialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
void defineOptions(OptionSet& options)
|
void defineOptions(OptionSet& options)
|
||||||
{
|
{
|
||||||
ServerApplication::defineOptions(options);
|
ServerApplication::defineOptions(options);
|
||||||
|
|
||||||
options.addOption(
|
options.addOption(
|
||||||
Option("help", "h", "display argument help information")
|
Option("help", "h", "display argument help information")
|
||||||
.required(false)
|
.required(false)
|
||||||
@ -397,9 +379,8 @@ server.
|
|||||||
.callback(OptionCallback<HTTPTimeServer>(
|
.callback(OptionCallback<HTTPTimeServer>(
|
||||||
this, &HTTPTimeServer::handleHelp)));
|
this, &HTTPTimeServer::handleHelp)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleHelp(const std::string& name,
|
void handleHelp(const std::string& name, const std::string& value)
|
||||||
const std::string& value)
|
|
||||||
{
|
{
|
||||||
HelpFormatter helpFormatter(options());
|
HelpFormatter helpFormatter(options());
|
||||||
helpFormatter.setCommand(commandName());
|
helpFormatter.setCommand(commandName());
|
||||||
@ -410,19 +391,20 @@ server.
|
|||||||
stopOptionsProcessing();
|
stopOptionsProcessing();
|
||||||
_helpRequested = true;
|
_helpRequested = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(const std::vector<std::string>& args)
|
int main(const std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
if (!_helpRequested)
|
if (!_helpRequested)
|
||||||
{
|
{
|
||||||
unsigned short port = (unsigned short)
|
unsigned short port = static_cast<unsigned short>(
|
||||||
config().getInt("HTTPTimeServer.port", 9980);
|
config().getInt("HTTPTimeServer.port", 9980));
|
||||||
std::string format(
|
std::string format(config().getString(
|
||||||
config().getString("HTTPTimeServer.format",
|
"HTTPTimeServer.format",
|
||||||
DateTimeFormat::SORTABLE_FORMAT));
|
DateTimeFormat::SORTABLE_FORMAT));
|
||||||
|
|
||||||
ServerSocket svs(port);
|
ServerSocket svs(port);
|
||||||
HTTPServer srv(new TimeRequestHandlerFactory(format),
|
HTTPServer srv(
|
||||||
|
new TimeRequestHandlerFactory(format),
|
||||||
svs, new HTTPServerParams);
|
svs, new HTTPServerParams);
|
||||||
srv.start();
|
srv.start();
|
||||||
waitForTerminationRequest();
|
waitForTerminationRequest();
|
||||||
@ -430,11 +412,11 @@ server.
|
|||||||
}
|
}
|
||||||
return Application::EXIT_OK;
|
return Application::EXIT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _helpRequested;
|
bool _helpRequested = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
HTTPTimeServer app;
|
HTTPTimeServer app;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user