[Fresco-devel] Bug: 'pure virtual method called'
Neil Pilgrim <[email protected]>
| Newsgroups | gmane.comp.video.fresco.devel |
|---|---|
| Message-ID | <[email protected]> |
This crashes the server :( If I *don't* get this bug, then the server just eats up CPU and doesn't seem to let any other clients in. Code enclosed to trigger this (with or without UI #define'd I sometimes get different results). As an aside, the client hangs at resolving the naming context (if its not commented out), which explains why none of the clients work when using the nameservice at the moment! Also, suspending and resuming a client at the command-line (^Z, fg) doesn't cause it to be redrawn on resuming? -- Neil, wondering why tracing is working.
HelloWorld.cc
(text/x-c++src, 4.4 KB)
// Fresco interface, helper code
#include <Fresco/config.hh>
#include <Fresco/resolve.hh>
#include <Fresco/exception.hh>
#include <Fresco/ClientContextImpl.hh>
#include <Fresco/Unicode.hh>
// Fresco interface, generated from IDL
#include <Fresco/Server.hh>
#include <Fresco/ClientContext.hh>
// Kits
#include <Fresco/TextKit.hh>
#include <Fresco/ToolKit.hh>
#include <Fresco/LayoutKit.hh>
#include <Fresco/WidgetKit.hh>
#include <Fresco/DesktopKit.hh>
// Trigger
#include <Fresco/Trigger.hh>
// Command which destroys the orb passed to it; used to shut down the
// application, by exiting the orb->run() loop.
class ORBShutdownCommand: public virtual POA_Fresco::Command,
public virtual PortableServer::RefCountServantBase
{
public:
ORBShutdownCommand(CORBA::ORB_var const & orb) : orb_(orb){}
virtual void execute(CORBA::Any const &)
{ // shutdown the orb, <insert proper reason for using false here>
// ATM if we don't use false, then it blocks the server?
// (this is bug in server?)
// ie. after calling this, the window closes, but we must kill
// this process to let the server continue.
orb_->shutdown(false);
}
virtual void destroy()
{
PortableServer::POA_var poa = _default_POA();
PortableServer::ObjectId *oid = poa->servant_to_id(this);
poa->deactivate_object(*oid);
delete oid;
}
private:
CORBA::ORB_var orb_;
};
#define UI
// main
int main(int argc, char **argv)
{
try
{
// Connect to the ORB
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
PortableServer::POA_var poa =
resolve_init<PortableServer::POA>(orb, "RootPOA");
PortableServer::POAManager_var pman = poa->the_POAManager();
pman->activate();
// Connect to the Berlin Server
// CosNaming::NamingContext_var context =
// resolve_init<CosNaming::NamingContext>(orb, "NameService");
Fresco::Server_var s =
// resolve_name<Fresco::Server>(context, "IDL:fresco.org/Fresco/Server:1.0");
resolve_init<Fresco::Server>(orb,"FrescoServer");
ClientContextImpl client_servant("Hello World application");
Fresco::ClientContext_var client_object_ref = client_servant._this();
Fresco::ServerContext_var server =
s->create_server_context(client_object_ref);
assert(!CORBA::is_nil(server));
// Find the kits we need
Fresco::TextKit_var textkit =
resolve_kit<Fresco::TextKit>(server,"IDL:fresco.org/Fresco/TextKit:1.0");
Fresco::LayoutKit_var layoutkit =
resolve_kit<Fresco::LayoutKit>(server,"IDL:fresco.org/Fresco/LayoutKit:1.0");
Fresco::ToolKit_var toolkit =
resolve_kit<Fresco::ToolKit>(server,"IDL:fresco.org/Fresco/ToolKit:1.0");
Fresco::WidgetKit_var widgetkit =
resolve_kit<Fresco::WidgetKit>(server,"IDL:fresco.org/Fresco/WidgetKit:1.0");
Fresco::DesktopKit_var desktopkit =
resolve_kit<Fresco::DesktopKit>(server,"IDL:fresco.org/Fresco/DesktopKit:1.0");
#ifdef UI
// Construct the UI using the kits
Babylon::String hello_string("Hello World!");
Fresco::Graphic_var hello_graphic =
textkit->chunk(Unicode::to_CORBA(hello_string));
Fresco::Graphic_var red_hello_graphic =
toolkit->rgb(hello_graphic,1,0,0);
Fresco::Graphic_var wide_hello_graphic = layoutkit->hbox();
wide_hello_graphic->append_graphic(Fresco::Graphic_var(layoutkit->hfill()));
wide_hello_graphic->append_graphic(red_hello_graphic);
wide_hello_graphic->append_graphic(Fresco::Graphic_var(layoutkit->hfill()));
ORBShutdownCommand exit_command(orb);
Fresco::Trigger_var close_button =
widgetkit->button(wide_hello_graphic,
Fresco::Command_var(exit_command._this()));
Fresco::Window_var window = desktopkit->shell(close_button,
client_object_ref);
// Hand over control to the ORB...
orb->run();
// ...and reach here when CORBA::ORB::shutdown(...) is called,
// which happens when exit_command is execute()'d
#endif
// Destroy orb, so that CORBA objects are deleted before servants
orb->destroy();
}
catch (CORBA::Exception const & e)
{
cerr << "Uncaught CORBA exception! " << e << endl;
return 1;
}
catch (std::exception const & e)
{
cerr << "Uncaught exception: " << e.what() << endl;
return 2;
}
catch (...)
{
cerr << "Unknown exception! " << endl;
return 3;
}
}