|
From: stephan b. <st...@s1...> - 2004-12-18 01:37:43
|
Yo again...
random notes...
i've implemented IODevice::read(std::string&,size_t) as non-virtual in
IODevice.
Anyway... it looks like this:
Add the decl in piodevice.h:
//! Same as read(char*,size_t) but writes to the given std::string
size_t read( std::string & buffer, size_t count ) throw(IOError);
Implement in piodevice.common.cpp:
size_t
IODevice::read( std::string & buffer, size_t count ) throw(IOError)
{
typedef std::vector<char> VC;
VC v(count,'\0');
size_t ret = this->read( &v[0], count );
buffer = (0 == ret)
? ""
: std::string( v.begin(), v.begin() + ret );
return ret;
}
And (unfortunately) copy/paste that for IORequest_Get, but renaming the
function to receive().
A test app is attached, BUT... i can't test it, because i'm always
getting an abort() somewhere in PIO:
stephan@owl:~/src/pclasses-1.0.0beta1/demo> gdb --args .libs/httpclient
http://s11n
GNU gdb 6.2.1
<snip>
Starting
program: /home/stephan/src/pclasses-1.0.0beta1/demo/.libs/httpclient
http://s11n
[Thread debugging using libthread_db enabled]
[New Thread 1078314848 (LWP 16516)]
URL=[http://s11n/]
Program received signal SIGABRT, Aborted.
[Switching to Thread 1078314848 (LWP 16516)]
0xffffe410 in ?? ()
(gdb) bt
#0 0xffffe410 in ?? ()
#1 0xbfffed88 in ?? ()
#2 0x00000006 in ?? ()
#3 0x00004084 in ?? ()
#4 0x40364d41 in raise () from /lib/tls/libc.so.6
#5 0x40366529 in abort () from /lib/tls/libc.so.6
#6 0x40063eaf in P::CrashHandler::terminate ()
from /home/stephan/lib/libpcore.so.1
#7 0x402f2c25 in __cxxabiv1::__terminate ()
from /usr/lib/libstdc++.so.5
#8 0x402f2c62 in std::terminate () from /usr/lib/libstdc++.so.5
#9 0x402f2da2 in __cxa_throw () from /usr/lib/libstdc++.so.5
#10 0x40028ac9 in P::IOManager::findCreateHandler ()
from /home/stephan/lib/libpio.so.1
#11 0x400287d5 in P::IOManager::get ()
from /home/stephan/lib/libpio.so.1
#12 0x08049137 in main ()
where http://s11n/ is a copy of s11n.net on my local box.
i can't believe how long i had to fight with autotools to get
demo/Makefile to pick up my test app, though (i hate the autotools). i
ended up having to sed demo/Makefile and replace httpclient.cpp with my
test.
Here's my plan for P vis-a-vis s11n:
i'd like to implement an i/o layer for s11n which uses P streams, so we
can do this:
typedef MySerializableType ST;
ST s;
// ... use s ...
P::s11n::serialize( s, "url" );
or:
P::s11n::serialize( s, IODevice & )
and:
MyType * o = P::s11n::deserialize<MyType>( IODevice & | url );
That mirrors the current s11nlite API, and actually isn't much work. i
just found the std::iostream compat P code, and now i'm a Very Happy
Camper :). i see how the API would work for P::FileStream, but i don't
see an IOStream connection to, e.g., an arbitrary IODevice.
Integration of s11n support will be trivial, at least for FileStream
objects. Essentially all that is needed is that i write a wrapper very
similar to the existing "s11nlite" layer. (Or implement the dynamic
stream support i wrote about earlier and re-implement s11n's stream
handler in terms of that.) With that in place, any type of
s11n-supported object can be de/serialized via PStreams and,
potentially, arbitrary IODevices. That means network-transparent
de/serialization, which would be Really Cool! Save your objects over
ftp:
P::s11n::serialize( myobject, "ftp://server/path/to/file" );
This empowers all sorts of web-based support, too, like reading/writing
db-based data via an http proxy:
P::s11n::serialize( myobject,
"http://s11n.myserver.net/save?node_name=MyObjectName" );
where 'save' is a CGI script that reads myobject (which is serialized to
an arbitrary s11n-supported format) and converts that to/from db data
(perhaps using the existing s11n::io::mysql_serializer). Likewise:
MyType * o =
P::s11n::deserialize<MyType>("http://.../load?node_name=...");
The implications of this in P's "generic application framework" are
tremendous!!! :)
--
----- st...@s1... http://s11n.net
"...pleasure is a grace and is not obedient to the commands
of the will." -- Alan W. Watts
|