Fresco/Berlin/include/Berlin GraphDebugger.hh,NONE,1.1 GraphicDictionary.hh,NONE,1.1 KitImpl.hh,1.14,1.15
Tobias Hunger <[email protected]>
| Newsgroups | gmane.comp.video.fresco.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvs/fresco/Fresco/Berlin/include/Berlin
In directory purcel:/tmp/cvs-serv1225/Berlin/include/Berlin
Modified Files:
KitImpl.hh
Added Files:
GraphDebugger.hh GraphicDictionary.hh
Log Message:
Initial checkin of a scene graph debugging framework.
To activate run the server with the -D option (and -l if you want to
see the log output of course). To get a dot-file of the current
scene graph send a USR1 signal to the server process. It will then
dump the graph into /tmp/debug.dot. Use graphviz's dot-tool to turn that
file into a PS-drawing of the scene graph (cat /tmp/debug.dot | dot -Tps).
TODO: * add more information to the output (transformation, allocation, etc.)
* make sure all graphics get registered. We have a couple of "unknowns"
in the dump as of now.
--- NEW FILE: GraphDebugger.hh ---
/*$Id: GraphDebugger.hh,v 1.1 2003/02/26 00:19:05 tobias Exp $
*
* This source file is a part of the Fresco Project.
* Copyright (C) 2003 Tobias Hunger <[email protected]>
* http://www.fresco.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
* MA 02139, USA.
*/
#ifndef _Berlin_GraphDebugger_hh
#define _Berlin_GraphDebugger_hh
#include <Fresco/Graphic.hh>
#include <string>
#include <vector>
class GraphicImpl;
namespace Berlin
{
class GraphDebugger
{
public:
//. This implizitly activates the GraphicDictionary.
GraphDebugger(Fresco::Graphic_ptr);
~GraphDebugger();
//. Starts the debugging session. For now all this does is
//. to dump the scenegraph in graphviz's dot-file format into
//. /tmp/debug.dot.
//. You can turn this file into a Postscript drawing of the
//. SceneGraph by running "dot -Tps /tmp/debug.dot".
void debug();
private:
GraphDebugger(const GraphDebugger &) { }
void dump_graphic(Fresco::Graphic_ptr, std::ostream &);
Fresco::Graphic_ptr my_root;
struct graphic_info
{
Fresco::Graphic_var graphic;
GraphicImpl * impl;
unsigned long hash;
unsigned long id;
bool dumped;
std::string name;
graphic_info(Fresco::Graphic_ptr g, const GraphicImpl * const im,
unsigned long h, unsigned long i,
std::string n, bool d = false) :
graphic(Fresco::Graphic::_duplicate(g)),
impl(const_cast<GraphicImpl *>(im)),
hash(h),
id(i),
name(n),
dumped(d)
{ }
};
graphic_info & find_or_insert(Fresco::Graphic_ptr);
static unsigned long my_current_id;
std::vector<graphic_info> my_known_graphics;
};
} // namespace
#endif
--- NEW FILE: GraphicDictionary.hh ---
/*$Id: GraphicDictionary.hh,v 1.1 2003/02/26 00:19:05 tobias Exp $
*
* This source file is a part of the Berlin Project.
* Copyright (C) 2003 Tobias Hunger <[email protected]>
* http://www.fresco.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
* MA 02139, USA.
*/
#ifndef _Berlin_GraphicDictionary_hh
#define _Berlin_GraphicDictionary_hh
#include <Prague/Sys/Thread.hh>
#include <Berlin/GraphicImpl.hh>
#include <Fresco/Graphic.hh>
#include <string>
#include <vector>
namespace Berlin
{
typedef std::vector<std::string> name_vector;
class GraphicDictionary
{
public:
GraphicDictionary();
~GraphicDictionary();
//. This member function causes the Dictionary to go active.
//. It will simply forget all registered Graphics, thus
//. conserving memory. You need to call this member on the dictionary
//. *before* registering any Graphic ro avoid losing information.
void activate();
//. Finds the current dictionary.
//. If no dictionary exists it will create one.
static GraphicDictionary * instance();
//. Register a new Graphic with the given name. This function
//. returns the total number of times this Graphic was registered
// (including this try).
void add(const Fresco::Graphic_ptr, const GraphicImpl * const,
const std::string &);
//. Remove a Graphic from the Dictionary.
//.
//. Returns the number of times this Graphic used to be registered
//. BEFORE this one is removed.
void remove(const GraphicImpl * const);
//. Query the Dictionary
std::string name(const Fresco::Graphic_ptr) const;
//. Get the implementation of the CORBA Object.
const GraphicImpl * const implementation(const Fresco::Graphic_ptr) const;
private:
// We will never assign/copy this object, so there is no need
// to implement these:
GraphicDictionary(const GraphicDictionary &);
GraphicDictionary & operator = (const GraphicDictionary &);
//. A dictionary contains words...
struct word
{
std::string name;
Fresco::Graphic_var graphic;
unsigned int hash;
GraphicImpl * impl;
word();
word(const Fresco::Graphic_ptr, const GraphicImpl * const,
const std::string &);
word(const word &);
word & operator = (const word &);
};
class word_equal
{
public:
word_equal(const Fresco::Graphic_ptr g,
const GraphicImpl * i);
bool operator() (const Berlin::GraphicDictionary::word & w);
private:
const unsigned int my_hash;
const GraphicImpl * my_impl;
const Fresco::Graphic_ptr my_graphic;
};
typedef std::vector<word> dictionary_type;
dictionary_type my_dictionary;
bool my_active;
mutable Prague::Mutex my_mutex;
static GraphicDictionary * my_self;
static Prague::Mutex my_singleton_mutex;
};
} // namespace
#endif
Index: KitImpl.hh
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/include/Berlin/KitImpl.hh,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- KitImpl.hh 18 Feb 2003 07:26:23 -0000 1.14
+++ KitImpl.hh 26 Feb 2003 00:19:05 -0000 1.15
@@ -27,6 +27,10 @@
#include <Fresco/Kit.hh>
#include <Fresco/Graphic.hh>
#include <Berlin/DefaultPOA.hh>
+#include <Berlin/GraphicImpl.hh>
+#include <Berlin/GraphicDictionary.hh>
+
+#include <string>
class ServerImpl;
class ServerContextImpl;
@@ -38,11 +42,16 @@
{
friend class ServerImpl;
public:
- KitImpl(const std::string &, const Fresco::Kit::PropertySeq &, ServerContextImpl *);
+ KitImpl(const std::string &,
+ const Fresco::Kit::PropertySeq &, ServerContextImpl *);
~KitImpl();
- virtual KitImpl *clone(const Fresco::Kit::PropertySeq &, ServerContextImpl *) = 0;
+ virtual KitImpl *clone(const Fresco::Kit::PropertySeq &,
+ ServerContextImpl *) = 0;
const std::string &repo_id() const { return my_repo_id;}
- virtual Fresco::Kit::PropertySeq *properties() { return new Fresco::Kit::PropertySeq(*my_props);}
+ virtual Fresco::Kit::PropertySeq *properties()
+ {
+ return new Fresco::Kit::PropertySeq(*my_props);
+ }
virtual void bind(Fresco::ServerContext_ptr) {}
virtual CORBA::Boolean supports(const Fresco::Kit::PropertySeq &);
@@ -54,22 +63,39 @@
virtual void decrement();
protected:
+
template <typename I, typename Im>
typename I::_ptr_type create(Im *impl)
{
- activate(impl);
- return impl->_this();
+ return private_create<I>(impl);
+ }
+
+ template <typename I, typename Im>
+ typename I::_ptr_type create(Im * impl, std::string n)
+ {
+ typename I::_ptr_type var = private_create<I>(impl);
+ Berlin::GraphicDictionary::instance()->add(var, impl, n);
+ return var;
}
-
+
template <typename I, typename Im>
- typename I::_ptr_type create_and_set_body(Im *impl, Fresco::Graphic_ptr g)
- {
- activate(impl);
- impl->body(g);
- return impl->_this();
+ typename I::_ptr_type create_and_set_body(Im *impl,
+ Fresco::Graphic_ptr g,
+ std::string n)
+ {
+ typename I::_ptr_type var = create<I>(impl, n);
+ var->body(g);
+ return var;
}
private:
+ template <typename I, typename Im>
+ typename I::_ptr_type private_create(Im *impl)
+ {
+ activate(impl);
+ return impl->_this();
+ }
+
void activate(PortableServer::POA_ptr);
void deactivate();
PortableServer::POA_var my_poa;
@@ -79,8 +105,14 @@
ServerContextImpl *my_context;
};
+// no implementation: If Graphics are given, then we need a string!
+template <>
+Fresco::Graphic_ptr
+KitImpl::create<Fresco::Graphic, GraphicImpl>(GraphicImpl * impl);
+
template <typename T>
-inline T *create_prototype(const std::string &repo, std::string props[], size_t n)
+inline T *create_prototype(const std::string &repo, std::string props[],
+ size_t n)
{
Fresco::Kit::PropertySeq properties;
properties.length(n/2);