explicit xplc_ptr(const xplc_ptr& aObj):
ptr(aObj) {
if(ptr)
ptr->addRef();
}
~xplc_ptr() {
if(ptr)
ptr->release();
}
/**
* Provide an operator->. This allows you to invoke methods on the
* interface pointed at by the xplc_ptr. As with a raw pointer, if
* the xplc_ptr is NULL, this will cause a crash. The interface is
* wrapped in some basic protection, to avoid accidental addRef or
* release.
*/
ProtectedPtr* operator->() const {
return static_cast(ptr);
}
/**
* Provide an operator*. This is so you can use "*foo" with an
* xplc_ptr like you could with the raw pointer. It also applies
* some basic protection.
*/
operator ProtectedPtr*() const {
return static_cast(ptr);
}
/**
* Assign a raw pointer to an xplc_ptr. This will addRef the
* interface, and release the interface previously pointed at by the
* xplc_ptr, if any.
*/
xplc_ptr& operator=(T* _ptr) {
if(_ptr)
_ptr->addRef();
if(ptr)
ptr->release();
ptr = _ptr;
return *this;
}
};
/**
* Used to addRef an object before passing it to something that would
* otherwise "steal" the reference.
*/
template
T* do_addRef(T* obj) {
if (obj)
obj->addRef();
return obj;
}
#endif /* __XPLC_PTR_H__ */
xplc-0.3.13/include/xplc/trace.h 0100644 0002043 0002043 00000005037 10331515666 016606 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2002, Pierre Phaneuf
* Copyright (C) 2002, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* As a special exception, you may use this file as part of a free
* software library without restriction. Specifically, if other files
* instantiate templates or use macros or inline functions from this
* file, or you compile this file and link it with other files to
* produce an executable, this file does not by itself cause the
* resulting executable to be covered by the GNU Lesser General Public
* License. This exception does not however invalidate any other
* reasons why the executable file might be covered by the GNU Lesser
* General Public License.
*/
#ifndef __XPLC_TRACE_H__
#define __XPLC_TRACE_H__
#if defined(__GNUC__) && __GNUC__ > 3
# pragma GCC system_header
#endif
#ifdef DEBUG
#include
/*
* Mix-in template that trace constructors, destructors and refcount
* to stderr.
*/
template
class TraceComponent: public Component {
public:
TraceComponent() {
fprintf(stderr, "%s: instantiated (%p)\n", __PRETTY_FUNCTION__, this);
}
virtual unsigned int addRef() {
unsigned int refcount = Component::addRef();
fprintf(stderr, "%s = %i (%p)\n", __PRETTY_FUNCTION__, refcount, this);
return refcount;
}
virtual unsigned int release() {
unsigned int refcount = Component::release();
fprintf(stderr, "%s = %i (%p)\n", __PRETTY_FUNCTION__, refcount, this);
return refcount;
}
virtual ~TraceComponent() {
fprintf(stderr, "%s: destroyed (%p)\n", __PRETTY_FUNCTION__, this);
}
};
#else /* DEBUG */
#error "this header should not be used other than for debugging"
#endif /* else DEBUG */
#endif /* __XPLC_TRACE_H__ */
xplc-0.3.13/include/xplc/utils.h 0100644 0002043 0002043 00000014244 10331515666 016650 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2000-2003, Pierre Phaneuf
* Copyright (C) 2001, Stéphane Lajoie
* Copyright (C) 2002-2004, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* As a special exception, you may use this file as part of a free
* software library without restriction. Specifically, if other files
* instantiate templates or use macros or inline functions from this
* file, or you compile this file and link it with other files to
* produce an executable, this file does not by itself cause the
* resulting executable to be covered by the GNU Lesser General Public
* License. This exception does not however invalidate any other
* reasons why the executable file might be covered by the GNU Lesser
* General Public License.
*/
#ifndef __XPLC_UTILS_H__
#define __XPLC_UTILS_H__
#if defined(__GNUC__) && __GNUC__ > 3
# pragma GCC system_header
#endif
/** \file
*
* Various utility functions, macros and templates.
*/
#include
#include
#include
/**
* Utility structure used for the interface map.
*/
struct UUID_Info {
//@{
const UUID* iid;
ptrdiff_t delta;
//@}
};
/**
* Start the interface map for "component".
*/
#define UUID_MAP_BEGIN(component) const UUID_Info component::xplc_iobject_uuids[] = {
/**
* Add an entry to an interface map.
*/
#define UUID_MAP_ENTRY(iface) { &iface##_IID, reinterpret_cast(static_cast(reinterpret_cast(1))) - 1 },
/**
* Add an entry to an interface map for an ambiguous interface. The
* second parameter is the interface that should be used to
* disambiguate.
*/
#define UUID_MAP_ENTRY_2(iface, iface2) { &iface##_IID, reinterpret_cast(static_cast(reinterpret_cast(1))) - 1 },
/**
* Marks the end of an interface map.
*/
#define UUID_MAP_END { 0, 0 } };
class WeakRef;
/**
* Helper internal structure. Used for implementing IMPLEMENT_IOBJECT.
*/
struct IObjectImplInternal {
/**
* Holds the reference count.
*/
unsigned int refcount;
/**
* Pointer to a weak reference object. This object is lazily
* instantiated, so the pointer is NULL until a weak reference is
* needed.
*/
WeakRef* weakref;
IObjectImplInternal(): refcount(1), weakref(0) {
}
/**
* Used to implement IObject::getInterface().
*/
IObject* getInterface(void* self, const UUID& uuid,
const UUID_Info* uuidlist);
};
#ifndef xplcdelete
/**
* Internal macro. This macro is needed to cooperate correctly with
* the "delete detector".
*/
#define xplcdelete delete
#endif
/**
* Helper macro to implement the IObject methods automatically. Put
* this at the beginning of your class, specifiying the class name as
* the parameter, and it will automatically implement all the IObject
* methods. You also need to define an interface map.
*
* \sa UUID_MAP_BEGIN, UUID_MAP_ENTRY, UUID_MAP_ENTRY_2, UUID_MAP_END
*/
#define IMPLEMENT_IOBJECT(component) \
private: \
IObjectImplInternal xplc_iobject_internal; \
static const UUID_Info xplc_iobject_uuids[]; \
typedef component ThisXPLCComponent; \
public: \
virtual unsigned int addRef() { \
return ++xplc_iobject_internal.refcount; \
} \
virtual unsigned int release() { \
if(--xplc_iobject_internal.refcount) \
return xplc_iobject_internal.refcount; \
/* protect against re-entering the destructor */ \
xplc_iobject_internal.refcount = 1; \
if(xplc_iobject_internal.weakref) { \
xplc_iobject_internal.weakref->release(); \
xplc_iobject_internal.weakref->object = 0; \
} \
xplcdelete this; \
return 0; \
} \
virtual IObject* getInterface(const UUID& uuid) { \
return xplc_iobject_internal.getInterface(this, uuid, xplc_iobject_uuids); \
} \
virtual IWeakRef* getWeakRef() { \
if(!xplc_iobject_internal.weakref) \
xplc_iobject_internal.weakref = new WeakRef(reinterpret_cast(reinterpret_cast(this) + xplc_iobject_uuids->delta)); \
xplc_iobject_internal.weakref->addRef(); \
return xplc_iobject_internal.weakref; \
}
/** \class WeakRef
*
* Common implementation of a weak reference.
*/
class WeakRef: public IWeakRef {
IMPLEMENT_IOBJECT(WeakRef);
public:
/** The object that the weak reference is pointing at. */
IObject* object;
virtual IObject* getObject() {
if(object)
object->addRef();
return object;
}
/**
* Initialize a weak reference.
*/
WeakRef(IObject* aObj):
object(aObj) {
}
};
/**
* %XPLC equivalent to dynamic_cast. This templated function is a
* typesafe way to call the getInterface method of a component and
* cast it properly. If the component does not support the interface,
* a NULL pointer will be returned.
*/
template
Interface* get(IObject* aObj) {
if(!aObj)
return 0;
return static_cast(aObj->getInterface(XPLC_IID::get()));
}
/**
* A version of get() that releases its parameter. This templated
* function is very similar to the "get" one, except that it
* automatically releases the inbound reference, without regard
* whether the getInterface actually yielded something.
*/
template
Interface* mutate(IObject* aObj) {
Interface* rv;
if(!aObj)
return 0;
rv = static_cast(aObj->getInterface(XPLC_IID::get()));
aObj->release();
return rv;
}
#endif /* __XPLC_UTILS_H__ */
xplc-0.3.13/include/xplc/xplc.h 0100644 0002043 0002043 00000007155 10331515666 016461 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2000-2003, Pierre Phaneuf
* Copyright (C) 2002, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* As a special exception, you may use this file as part of a free
* software library without restriction. Specifically, if other files
* instantiate templates or use macros or inline functions from this
* file, or you compile this file and link it with other files to
* produce an executable, this file does not by itself cause the
* resulting executable to be covered by the GNU Lesser General Public
* License. This exception does not however invalidate any other
* reasons why the executable file might be covered by the GNU Lesser
* General Public License.
*/
#ifndef __XPLC_XPLC_H__
#define __XPLC_XPLC_H__
#if defined(__GNUC__) && __GNUC__ > 3
# pragma GCC system_header
#endif
/** \file
*
* The XPLC helper class for the C++ binding.
*/
#include
#include
#include
/** \class XPLC xplc.h xplc/xplc.h
*
* The XPLC helper class. This class is part of the XPLC C++ binding
* in order to provide a more natural C++ feel to the use of XPLC.
*/
class XPLC {
private:
xplc_ptr servmgr;
public:
XPLC(): servmgr(XPLC_getServiceManager()) {}
/**
* Create an XPLC object using an existing service manager
* reference.
*/
XPLC(IServiceManager* _servmgr): servmgr(do_addRef(_servmgr)) {}
/**
* Adds a directory to the module loader path.
*/
void addModuleDirectory(const char* directory);
/**
* Obtain an XPLC object. Obtains an object with the provided UUID
* from the service manager.
*/
IObject* get(const UUID& uuid) {
return servmgr->getObject(uuid);
}
/**
* Templated variant of XPLC::get() that will do a getInterface()
* for you.
*/
template
Interface* get(const UUID& uuid) {
return mutate(servmgr->getObject(uuid));
}
/**
* Object creation helper. Obtains an object with the provided UUID
* from the service manager, tries to get the IFactory interface
* from the object and calls its createObject() method.
*/
IObject* create(const UUID& cid);
/**
* Templated variant of XPLC::create() that will do a getInterface()
* for you.
*/
template
Interface* create(const UUID& cid) {
return mutate(create(cid));
}
/**
* Object creation helper that operates from a moniker. Works like
* XPLC::create(const UUID&), but finds the object using a moniker
* instead.
*/
IObject* create(const char*);
/**
* Templated variant of XPLC::create(const char*) that will do a
* getInterface() for you.
*/
template
Interface* create(const char* aMoniker) {
return mutate(create(aMoniker));
}
};
#endif /* __XPLC_XPLC_H__ */
xplc-0.3.13/include/xplc/IModuleManagerFactory.h 0100644 0002043 0002043 00000002613 10331515666 021666 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2004, Pierre Phaneuf
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifndef __XPLC_IMODULEMANAGERFACTORY_H__
#define __XPLC_IMODULEMANAGERFACTORY_H__
#if defined(__GNUC__) && __GNUC__ > 3
# pragma GCC system_header
#endif
#include
class IModuleManagerFactory: public IObject {
UNSTABLE_INTERFACE
public:
virtual IServiceHandler* createModuleManager(const char* directory) = 0;
};
DEFINE_IID(IModuleManagerFactory,{0x9c88d2d0, 0xc61f, 0x41b7,
{0x9d, 0x4d, 0xd2, 0xc6, 0xc0, 0x97, 0x94, 0x55}});
#endif /* __XPLC_IMODULEMANAGERFACTORY_H__ */
xplc-0.3.13/include/autoconf.h.in 0100644 0002043 0002043 00000006147 10331517632 016763 0 ustar pphaneuf pphaneuf /* include/autoconf.h.in. Generated from configure.ac by autoheader. */
/* Define if you want to enable dynamic loading. */
#undef ENABLE_LOADER
/* Define to 1 if you have the header file, and it defines `DIR'.
*/
#undef HAVE_DIRENT_H
/* Define to 1 if you have the header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if you have the header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the header file. */
#undef HAVE_LIMITS_H
/* Define to 1 if you have the header file. */
#undef HAVE_MACH_O_DYLD_H
/* Define to 1 if you have the header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the header file, and it defines `DIR'. */
#undef HAVE_NDIR_H
/* Define to 1 if you have the header file. */
#undef HAVE_NETINET_IN_H
/* Define to 1 if you have the header file. */
#undef HAVE_NET_IF_DL_H
/* Define to 1 if you have the header file. */
#undef HAVE_NET_IF_H
/* Define if struct sockaddr contains sa_len */
#undef HAVE_SA_LEN
/* Define to 1 if you have the `srandom' function. */
#undef HAVE_SRANDOM
/* Define to 1 if you have the header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the header file, and it defines `DIR'.
*/
#undef HAVE_SYS_DIR_H
/* Define to 1 if you have the header file. */
#undef HAVE_SYS_IOCTL_H
/* Define to 1 if you have the header file, and it defines `DIR'.
*/
#undef HAVE_SYS_NDIR_H
/* Define to 1 if you have the header file. */
#undef HAVE_SYS_SOCKET_H
/* Define to 1 if you have the header file. */
#undef HAVE_SYS_SOCKIO_H
/* Define to 1 if you have the header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the header file. */
#undef HAVE_UUID_UUID_H
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* The size of a `int', as computed by sizeof. */
#undef SIZEOF_INT
/* The size of a `long', as computed by sizeof. */
#undef SIZEOF_LONG
/* The size of a `long long', as computed by sizeof. */
#undef SIZEOF_LONG_LONG
/* The size of a `short', as computed by sizeof. */
#undef SIZEOF_SHORT
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define if you have dlopen. */
#undef WITH_DLOPEN
/* Define if you have dyld. */
#undef WITH_DYLD
xplc-0.3.13/include/.cvsignore 0100644 0002043 0002043 00000000031 10030322223 016333 0 ustar pphaneuf pphaneuf autoconf.h
autoconf.h.in
xplc-0.3.13/include/config.h 0100644 0002043 0002043 00000002234 10030322223 015760 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2002, Pierre Phaneuf
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifndef __XPLC_CONFIG_H__
#define __XPLC_CONFIG_H__
/*
* Platforms that do not support Autoconf should skip including that
* file.
*/
#if !defined(WIN32)
#include "autoconf.h"
#else
#ifdef WIN32
#define ENABLE_LOADER
#endif
#endif
#endif /* __XPLC_CONFIG_H__ */
xplc-0.3.13/configure.ac 0100644 0002043 0002043 00000015476 10331523207 015232 0 ustar pphaneuf pphaneuf # Process this file with autoconf to produce a configure script.
#
# XPLC - Cross-Platform Lightweight Components
# Copyright (C) 2000-2002, Pierre Phaneuf
# Copyright (C) 2002-2004, Net Integration Technologies, Inc.
#
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
AC_INIT(XPLC, 0.3.13, pp@ludusdesign.com)
AC_REVISION($Id: configure.ac,v 1.41 2005/10/31 23:19:35 pphaneuf Exp $)
AC_CANONICAL_HOST
AC_ARG_ENABLE(debug,
AC_HELP_STRING([--enable-debug],
[debugging options]))
AC_ARG_ENABLE(fatal-warnings,
AC_HELP_STRING([--enable-fatal-warnings],
[turn warnings into errors]))
AC_ARG_ENABLE(optimization,
AC_HELP_STRING([--disable-optimization],
[optimization options]))
AC_ARG_ENABLE(warnings,
AC_HELP_STRING([--disable-warnings],
[extra warnings]))
AC_ARG_ENABLE(unstable,
AC_HELP_STRING([--enable-unstable],
[allow unstable interfaces in stable version]))
AC_ARG_ENABLE(rtti,
AC_HELP_STRING([--enable-rtti],
[C++ run-time type identification (compiler)]))
AC_ARG_ENABLE(exceptions,
AC_HELP_STRING([--enable-exceptions],
[C++ exceptions (compiler)]))
AC_ARG_ENABLE(pic,
AC_HELP_STRING([--disable-pic],
[generation of position-independent code]))
AC_ARG_ENABLE(loader,
AC_HELP_STRING([--disable-loader],
[dynamic loading]))
AC_ARG_WITH(dlopen,
AC_HELP_STRING([--with-dlopen],
[dlopen]))
AC_ARG_WITH(dyld,
AC_HELP_STRING([--with-dyld],
[dyld]))
AC_ARG_WITH(libuuid,
AC_HELP_STRING([--with-libuuid],
[libuuid]))
AC_CONFIG_SRCDIR([include/xplc/xplc.h])
AC_LANG(C++)
AC_PROG_CC
AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_LN_S
AC_HEADER_DIRENT
AC_CHECK_HEADERS([limits.h])
AC_CHECK_PROGS([CVS2CL], [cvs2cl.pl cvs2cl], [no])
case "$host_os" in
darwin*|rhapsody*)
so_style=darwin
;;
*)
so_style=sysv
;;
esac
# Make sure we link in libc.
LDFLAGS="$LDFLAGS -lc"
if test "$with_dlopen" != "no"; then
AC_CHECK_HEADERS(dlfcn.h)
AC_SEARCH_LIBS(dlopen, dl, with_dlopen=$ac_cv_search_dlopen, with_dlopen=no)
test "$with_dlopen" = "none required" && with_dlopen=
test "$with_dlopen" = "no" || AC_DEFINE(WITH_DLOPEN, 1, [Define if you have dlopen.])
fi
if test "$with_dyld" != "no"; then
AC_CHECK_HEADERS(mach-o/dyld.h)
AC_SEARCH_LIBS(NSCreateObjectFileImageFromFile, System, with_dyld=$ac_cv_search_NSCreateObjectFileImageFromFile, with_dyld=no)
test "$with_dyld" = "none required" && with_dyld=
test "$with_dyld" = "no" || AC_DEFINE(WITH_DYLD, 1, [Define if you have dyld.])
fi
# dyld not really supported yet
if test "$with_dlopen" = "no" && test "$with_dyld" = "no"; then
enable_loader=no
fi
if test "$enable_loader" != "no"; then
AC_DEFINE(ENABLE_LOADER, 1, [Define if you want to enable dynamic loading.])
fi
dnl Do some checks for uuid/ since no native library is available
with_uuid=no
if test "$with_uuid" == "no" && test "$with_libuuid" != "no"; then
AC_CHECK_HEADERS(uuid/uuid.h,
AC_CHECK_LIB(uuid, uuid_unparse,
with_uuid=-luuid))
fi
if test "$with_uuid" == "no"; then
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long long)
SIZEOF_SHORT=$ac_cv_sizeof_short
SIZEOF_INT=$ac_cv_sizeof_int
SIZEOF_LONG=$ac_cv_sizeof_long
SIZEOF_LONG_LONG=$ac_cv_sizeof_long_long
AC_SUBST(SIZEOF_SHORT)
AC_SUBST(SIZEOF_INT)
AC_SUBST(SIZEOF_LONG)
AC_SUBST(SIZEOF_LONG_LONG)
AC_CHECK_HEADERS([inttypes.h stdlib.h unistd.h])
AC_CHECK_HEADERS([net/if.h net/if_dl.h netinet/in.h])
AC_CHECK_HEADERS([sys/ioctl.h sys/socket.h sys/sockio.h])
AC_CHECK_FUNCS(srandom)
AC_CHECK_MEMBER(struct sockaddr.sa_len,
AC_DEFINE_UNQUOTED(HAVE_SA_LEN,
1,
[Define if struct sockaddr contains sa_len]),,
[#include
#include ])
with_uuid=
with_uuid_static=uuid/libuuid.a
fi
if test "$enable_optimization" != "no"; then
CFLAGS="$CFLAGS -O2"
fi
if test -z "$enable_debug"; then
enable_debug=no
fi
if test "$enable_debug" != "no"; then
CFLAGS="$CFLAGS -ggdb -DDEBUG"
if test "$enable_debug" != "yes"; then
CFLAGS="$CFLAGS -DDEBUG_$enable_debug"
fi
else
CFLAGS="$CFLAGS -DNDEBUG"
fi
if test "$enable_fatal_warnings" = "yes"; then
CFLAGS="$CFLAGS -Werror"
fi
if test "$enable_warnings" != "no"; then
CFLAGS="$CFLAGS -Wall"
CXXFLAGS="$CXXFLAGS -Woverloaded-virtual"
if test "$enable_warnings" = "yes"; then
CXXFLAGS="$CXXFLAGS -Wold-style-cast"
fi
fi
if test "$enable_rtti" != "yes"; then
CXXFLAGS="$CXXFLAGS -fno-rtti"
fi
if test "$enable_exceptions" != "yes"; then
CXXFLAGS="$CXXFLAGS -fno-exceptions"
fi
if test "$enable_pic" != "no"; then
CFLAGS="$CFLAGS -fpic"
fi
pc_version=
xplcdir_version=
lib_prefix_version=
if test "$(echo $PACKAGE_VERSION | awk -F. '{ print $2 % 2}')" -eq 1; then
enable_unstable=yes
pc_version="-${PACKAGE_VERSION}"
xplcdir_version="/xplc-${PACKAGE_VERSION}"
lib_prefix_version="../"
fi
if test "$enable_unstable" = "yes"; then
CFLAGS="$CFLAGS -DUNSTABLE"
fi
CXXFLAGS="$CXXFLAGS $CFLAGS"
AC_SUBST(pc_version)
AC_SUBST(xplcdir_version)
AC_SUBST(lib_prefix_version)
AC_SUBST(enable_loader)
AC_SUBST(with_dlopen)
AC_SUBST(so_style)
AC_SUBST(with_uuid)
AC_SUBST(with_uuid_static)
AC_SUBST(CVS2CL)
AC_CONFIG_FILES([config/config.mk])
AC_CONFIG_FILES([dist/xplc.pc dist/xplc-uninstalled.pc])
AC_CONFIG_FILES([examples/simple-module/Makefile])
AC_CONFIG_FILES([examples/simple-module-user/Makefile])
AC_CONFIG_FILES([uuid/uuid_types.h])
AC_CONFIG_HEADERS([include/autoconf.h])
AC_OUTPUT
if test "$(echo $PACKAGE_VERSION | awk -F. '{ print $2 % 2}')" -eq 1; then
AC_MSG_WARN([Unstable release, the API might change in the next release.])
fi
if test "$enable_loader" = "no"; then
AC_MSG_WARN([Dynamic loading is disabled.])
fi
xplc-0.3.13/tests/ 0040755 0002043 0002043 00000000000 10331536343 014101 5 ustar pphaneuf pphaneuf xplc-0.3.13/tests/CVS/ 0040755 0002043 0002043 00000000000 10331535776 014545 5 ustar pphaneuf pphaneuf xplc-0.3.13/tests/CVS/Repository 0100644 0002043 0002043 00000000013 10075346773 016640 0 ustar pphaneuf pphaneuf xplc/tests
xplc-0.3.13/tests/CVS/Entries 0100644 0002043 0002043 00000001504 10331535776 016076 0 ustar pphaneuf pphaneuf /.cvsignore/1.4/Fri Oct 18 22:32:23 2002//
/vars.mk/1.12/Fri Nov 22 23:03:37 2002//
/test.h/1.26/Sat Jul 31 03:31:25 2004//
/test000.cpp/1.11/Sat Jul 31 03:31:25 2004//
/test001.cpp/1.13/Sat Jul 31 03:31:25 2004//
/test002.cpp/1.13/Sat Jul 31 03:31:25 2004//
/test003.cpp/1.8/Sat Jul 31 03:31:25 2004//
/test004.cpp/1.12/Sat Jul 31 03:31:25 2004//
/test005.cpp/1.16/Sat Jul 31 03:31:25 2004//
/test006.cpp/1.8/Sat Jul 31 03:31:25 2004//
/test008.cpp/1.7/Sat Jul 31 03:31:25 2004//
/test009.cpp/1.12/Sat Jul 31 03:31:25 2004//
/test011.cpp/1.3/Sat Jul 31 03:31:25 2004//
/testmain.cpp/1.11/Wed Jan 5 23:17:56 2005//
/rules.mk/1.21/Wed Jan 5 23:21:12 2005//
/test007.cpp/1.7/Wed Jan 5 23:50:22 2005//
/test010.cpp/1.11/Wed Apr 27 21:38:09 2005//
/testobj.cpp/1.16/Wed Apr 27 21:38:09 2005//
/testobj.h/1.5/Wed Apr 27 21:38:09 2005//
D
xplc-0.3.13/tests/CVS/Root 0100644 0002043 0002043 00000000065 10331536343 015400 0 ustar pphaneuf pphaneuf :pserver:anonymous@cvs.sourceforge.net:/cvsroot/xplc
xplc-0.3.13/tests/.cvsignore 0100644 0002043 0002043 00000000032 07554105767 016110 0 ustar pphaneuf pphaneuf .*.d
testmain
testobj.dll
xplc-0.3.13/tests/test000.cpp 0100644 0002043 0002043 00000002506 10102611215 015770 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2000-2002, Pierre Phaneuf
* Copyright (C) 2001, Stéphane Lajoie
* Copyright (C) 2002, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "test.h"
/*
* test000
*
* Verifies that shutdown properly releases all the involved objects.
*/
void test000() {
IServiceManager* serv;
serv = XPLC_getServiceManager();
ASSERT(serv != 0, "could not obtain service manager");
VERIFY(serv->release() == 0, "service manager has non-zero refcount after release");
}
xplc-0.3.13/tests/test.h 0100644 0002043 0002043 00000014304 10102611215 015214 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2000-2003, Pierre Phaneuf
* Copyright (C) 2001, Stéphane Lajoie
* Copyright (C) 2002-2004, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifndef __TESTS_TEST_H__
#define __TESTS_TEST_H__
#include
#include
#include
#include
void test000();
void test001();
void test002();
void test003();
void test004();
void test005();
void test006();
void test007();
void test008();
void test009();
void test010();
void test011();
void test_assert(const char* file,
unsigned int line,
bool test,
const char* reason);
void test_verify(const char* file,
unsigned int line,
bool test,
const char* reason);
#define ASSERT(cond, desc) test_assert(__FILE__, __LINE__, cond, desc)
#define VERIFY(cond, desc) test_verify(__FILE__, __LINE__, cond, desc)
#ifndef xplcdelete
#define xplcdelete delete
#endif
class ITestInterface: public IObject {
public:
virtual unsigned int getRefCount() = 0;
virtual void setRefCount(unsigned int) = 0;
};
DEFINE_IID(ITestInterface, {0x794e20af, 0x5d35, 0x4d7a,
{0x8f, 0x23, 0xf8, 0x53, 0xd7, 0x34, 0xb3, 0xa7}});
class ITestInterface2: public ITestInterface {
public:
virtual unsigned int getAnswer() = 0;
};
DEFINE_IID(ITestInterface2, {0xdb0f1055, 0x805d, 0x4ad7,
{0x98, 0xaa, 0xd0, 0x84, 0x59, 0xb5, 0x2f, 0xac}});
class TestWeakRef: public IWeakRef {
private:
unsigned int refcount;
bool destroyed;
TestWeakRef* weakref;
public:
IObject* object;
TestWeakRef(IObject* aObject): refcount(1), destroyed(false),
weakref(0), object(aObject) {
}
virtual ~TestWeakRef() {
}
virtual unsigned int addRef() {
return ++refcount;
}
virtual unsigned int release() {
if(--refcount)
return refcount;
ASSERT(!destroyed, "test object destroyed more than once");
refcount = 1;
destroyed = true;
if(weakref)
weakref->object = 0;
xplcdelete this;
return 0;
}
virtual IObject* getInterface(const UUID& uuid) {
ASSERT(!destroyed, "using destroyed test object");
if(uuid == IObject_IID) {
addRef();
return static_cast(this);
}
if(uuid == IWeakRef_IID) {
addRef();
return static_cast(this);
}
return 0;
}
virtual IWeakRef* getWeakRef() {
if(!weakref) {
weakref = new TestWeakRef(this);
}
return weakref;
}
virtual IObject* getObject() {
if(object)
object->addRef();
return object;
}
};
class TestObject: public ITestInterface2 {
private:
unsigned int refcount;
bool destroyed;
bool deletethis;
TestWeakRef* weakref;
public:
TestObject(const bool _deletethis = false): refcount(1), destroyed(false),
deletethis(_deletethis), weakref(0) {
}
virtual ~TestObject() {
VERIFY(destroyed, "test object leaked");
}
virtual unsigned int addRef() {
ASSERT(!destroyed, "using destroyed test object");
return ++refcount;
}
virtual unsigned int release() {
ASSERT(!destroyed, "test object destroyed more than once");
if(--refcount)
return refcount;
refcount = 1;
destroyed = true;
if(deletethis)
xplcdelete this;
return 0;
}
virtual IObject* getInterface(const UUID& uuid) {
ASSERT(!destroyed, "using destroyed test object");
if(uuid == IObject_IID) {
addRef();
return static_cast(this);
}
if(uuid == ITestInterface_IID) {
addRef();
return static_cast(this);
}
return 0;
}
virtual IWeakRef* getWeakRef() {
if(!weakref) {
weakref = new TestWeakRef(this);
}
return weakref;
}
virtual unsigned int getRefCount() {
ASSERT(!destroyed, "using destroyed test object");
return refcount;
}
virtual void setRefCount(unsigned int aRefCount) {
ASSERT(!destroyed, "using destroyed test object");
refcount = aRefCount;
if(!refcount) {
refcount = 1;
destroyed = true;
}
}
virtual unsigned int getAnswer() {
return 42;
}
};
static const UUID TestObject_CID = {0xfa8ebece, 0x047e, 0x4372, {0xb7, 0x34, 0x30, 0x10, 0x05, 0x32, 0x45, 0x47}};
class TestObjectFactory: public IFactory {
private:
unsigned int refcount;
bool destroyed;
TestWeakRef* weakref;
public:
TestObjectFactory(): refcount(1), destroyed(false), weakref(0) {
}
virtual ~TestObjectFactory() {
}
virtual unsigned int addRef() {
return ++refcount;
}
virtual unsigned int release() {
if(--refcount)
return refcount;
ASSERT(!destroyed, "test object factory destroyed more than once");
refcount = 1;
destroyed = true;
xplcdelete this;
return 0;
}
virtual IObject* getInterface(const UUID& uuid) {
if(uuid == IObject_IID) {
addRef();
return static_cast(this);
}
if(uuid == IFactory_IID) {
addRef();
return static_cast(this);
}
return 0;
}
virtual IWeakRef* getWeakRef() {
if(!weakref) {
weakref = new TestWeakRef(this);
weakref->addRef();
}
return weakref;
}
virtual IObject* createObject() {
return new TestObject(true);
}
};
static const UUID TestObjectFactory_CID = {0x9cacf26d, 0xd362, 0x4543, {0xb0, 0x42, 0x10, 0xe8, 0xcb, 0xa3, 0xfd, 0xab}};
#endif /* __TESTS_TEST_H__ */
xplc-0.3.13/tests/test001.cpp 0100644 0002043 0002043 00000011110 10102611215 015760 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2000-2002, Pierre Phaneuf
* Copyright (C) 2001, Stéphane Lajoie
* Copyright (C) 2002, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "test.h"
#include
/*
* test001
*
* Verifies that the service manager queries handlers properly.
*/
const UUID obj1 = {0xd60530d8, 0x9a3d, 0x4c8e, {0xaa, 0x0b, 0x48, 0x32, 0xc6, 0x9c, 0xf0, 0x1a}};
const UUID obj2 = {0x862adfe4, 0x0821, 0x4f88, {0x85, 0x4a, 0xb9, 0xbf, 0xb9, 0xdc, 0x8a, 0x29}};
const UUID obj3 = {0xe1eabacb, 0x0795, 0x4c6d, {0x81, 0x8e, 0x7a, 0xab, 0x2c, 0x5a, 0x82, 0x25}};
class Handler1: public IServiceHandler {
IMPLEMENT_IOBJECT(Handler1);
public:
static Handler1* create() {
return new Handler1;
}
virtual IObject* getObject(const UUID& uuid) {
if(uuid == obj1) {
return reinterpret_cast(1);
}
return 0;
}
};
class Handler2: public IServiceHandler {
IMPLEMENT_IOBJECT(Handler2);
public:
static Handler2* create() {
return new Handler2;
}
virtual IObject* getObject(const UUID& uuid) {
VERIFY(uuid != obj1, "request for the first object reached second handler");
if(uuid == obj2) {
return reinterpret_cast(2);
}
return 0;
}
};
class Handler3: public IServiceHandler {
IMPLEMENT_IOBJECT(Handler3);
public:
static Handler3* create() {
return new Handler3;
}
virtual IObject* getObject(const UUID& uuid) {
VERIFY(uuid != obj1, "request for the first object reached third handler");
VERIFY(uuid != obj2, "request for the second object reached third handler");
if(uuid == obj3) {
return reinterpret_cast(3);
}
return 0;
}
};
UUID_MAP_BEGIN(Handler1)
UUID_MAP_ENTRY(IObject)
UUID_MAP_ENTRY(IServiceHandler)
UUID_MAP_END
UUID_MAP_BEGIN(Handler2)
UUID_MAP_ENTRY(IObject)
UUID_MAP_ENTRY(IServiceHandler)
UUID_MAP_END
UUID_MAP_BEGIN(Handler3)
UUID_MAP_ENTRY(IObject)
UUID_MAP_ENTRY(IServiceHandler)
UUID_MAP_END
void test001() {
IServiceManager* serv;
IServiceHandler* handler1;
IServiceHandler* handler2;
IServiceHandler* handler3;
IObject* obj;
serv = XPLC_getServiceManager();
ASSERT(serv != 0, "could not obtain service manager");
handler1 = Handler1::create();
ASSERT(handler1 != 0, "could not instantiate test handler 1");
serv->addFirstHandler(handler1);
handler2 = Handler2::create();
ASSERT(handler2 != 0, "could not instantiate test handler 2");
serv->addHandler(handler2);
handler3 = Handler3::create();
ASSERT(handler3 != 0, "could not instantiate test handler 2");
serv->addLastHandler(handler3);
obj = serv->getObject(obj1);
VERIFY(obj != 0, "object 1 was not found");
VERIFY(obj == reinterpret_cast(1), "asked for object 1 and got another one");
obj = serv->getObject(obj2);
VERIFY(obj != 0, "object 2 was not found");
VERIFY(obj == reinterpret_cast(2), "asked for object 2 and got another one");
obj = serv->getObject(obj3);
VERIFY(obj != 0, "object 3 was not found");
VERIFY(obj == reinterpret_cast(3), "asked for object 3 and got another one");
serv->removeHandler(handler1);
serv->removeHandler(handler2);
serv->removeHandler(handler3);
obj = serv->getObject(obj1);
VERIFY(!obj, "object 1 still returned after removing handler 1");
obj = serv->getObject(obj2);
VERIFY(!obj, "object 2 still returned after removing handler 2");
obj = serv->getObject(obj3);
VERIFY(!obj, "object 3 still returned after removing handler 3");
VERIFY(handler1->release() == 0, "incorrect refcount on handler 1");
VERIFY(handler2->release() == 0, "incorrect refcount on handler 2");
VERIFY(handler3->release() == 0, "incorrect refcount on handler 3");
VERIFY(serv->release() == 0, "service manager has non-zero refcount after release");
}
xplc-0.3.13/tests/test002.cpp 0100644 0002043 0002043 00000005254 10102611215 015775 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2000-2003, Pierre Phaneuf
* Copyright (C) 2001, Stéphane Lajoie
* Copyright (C) 2002-2004, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "test.h"
#include
#include "../xplc/statichandler.h"
/*
* test002
*
* Verifies the static service handler.
*/
void test002() {
IStaticServiceHandler* handler;
TestObject* test;
IObject* obj;
ITestInterface *itest;
handler = new StaticServiceHandler;
ASSERT(handler != 0, "could not instantiate static service handler");
test = new TestObject;
ASSERT(test != 0, "could not instantiate test object");
VERIFY(test->getRefCount() == 1, "the test object has an incorrect refcount");
handler->addObject(TestObject_CID, test);
VERIFY(test->getRefCount() == 2, "static service handler did not addRef the test component");
obj = handler->getObject(TestObject_CID);
ASSERT(obj != 0, "could not get test component from static service handler");
itest = mutate(obj);
ASSERT(itest != 0, "test component does not have the expected interface");
VERIFY(test->getRefCount() == 3, "the test object has an incorrect refcount");
itest->setRefCount(10);
itest->addRef();
VERIFY(itest->getRefCount() == 11, "test component has unexpected behavior");
itest->setRefCount(3);
VERIFY(itest->release() == 2, "test component has incorrect refcount");
handler->removeObject(TestObject_CID);
VERIFY(test->getRefCount() == 1, "static service handler did not release the test component");
obj = handler->getObject(TestObject_CID);
VERIFY(!obj, "static service handler did not remove the test component");
if(obj)
obj->release();
VERIFY(handler->release() == 0, "static service handler has non-zero refcount after release");
VERIFY(test->release() == 0, "test object has non-zero refcount after release");
xplcdelete test;
}
xplc-0.3.13/tests/test003.cpp 0100644 0002043 0002043 00000003516 10102611215 015775 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2000-2003, Pierre Phaneuf
* Copyright (C) 2001, Stéphane Lajoie
* Copyright (C) 2002-2004, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "test.h"
#include
#include
/*
* test003
*
* Verifies the generic factory.
*/
IObject* testfactory() {
return new TestObject;
}
void test003() {
IFactory* factory;
IObject* obj;
ITestInterface* test;
obj = new GenericFactory(testfactory);
ASSERT(obj != 0, "could not instantiate generic factory");
factory = mutate(obj);
ASSERT(factory != 0, "factory does not have expected interface");
obj = factory->createObject();
ASSERT(obj != 0, "factory did not create test object");
test = mutate(obj);
ASSERT(test != 0, "test object does not have expected interface");
VERIFY(test->release() == 0, "test object has non-zero refcount after release");
VERIFY(factory->release() == 0, "factory has non-zero refcount after release");
xplcdelete test;
}
xplc-0.3.13/tests/test004.cpp 0100644 0002043 0002043 00000004464 10102611215 016001 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2000-2004, Pierre Phaneuf
* Copyright (C) 2001, Stéphane Lajoie
* Copyright (C) 2002-2004, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "test.h"
#include "config.h"
#include
#include
#include "testobj.h"
/*
* test004
*
* Verifies the module loader.
*/
void test004() {
#ifdef ENABLE_LOADER
IServiceManager* servmgr;
IModuleLoader* loader;
IModule* module;
IObject* obj;
ITestComponent* test;
servmgr = XPLC_getServiceManager();
ASSERT(servmgr != 0, "could not obtain service manager");
obj = servmgr->getObject(XPLC_moduleLoader);
ASSERT(obj != 0, "could not obtain the module loader component");
loader = mutate(obj);
ASSERT(loader != 0, "module loader does not have expected interface");
module = loader->loadModule("./testobj.dll");
ASSERT(module, "could not load module");
VERIFY(loader->release() == 1, "module loader factory has wrong refcount");
obj = module->getObject(TestComponent_CID);
ASSERT(obj != 0, "could not create test object");
test = mutate(obj);
ASSERT(test != 0, "test object did not have expected interface");
ASSERT(test->getAnswer() == 42, "test object did not have expected behavior");
VERIFY(test->release() == 0, "test object has wrong refcount");
VERIFY(module->release() == 0, "module has wrong refcount");
VERIFY(servmgr->release() == 0, "service manager has non-zero refcount after release");
#endif
}
xplc-0.3.13/tests/test005.cpp 0100644 0002043 0002043 00000010401 10102611215 015766 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2001-2003, Pierre Phaneuf
* Copyright (C) 2002-2004, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "test.h"
#include
#include "../xplc/statichandler.h"
/*
* test005
*
* Verifies the generic component template.
*/
class IFoo: public IObject {
public:
virtual unsigned int getFoo() = 0;
virtual void setFoo(unsigned int) = 0;
};
DEFINE_IID(IFoo, {0xdacffda8, 0x5eb4, 0x4c9b,
{0xb5, 0xd4, 0x6d, 0xc5, 0x95, 0x5e, 0x4f, 0x74}});
class IBar: public IObject {
public:
virtual unsigned int getBar() = 0;
virtual void setBar(unsigned int) = 0;
};
DEFINE_IID(IBar, {0xa1520c1d, 0xcf44, 0x4830,
{0xa9, 0xb2, 0xb1, 0x80, 0x9b, 0x1e, 0xe7, 0xa2}});
class MyTestObject: public IFoo, public IBar {
IMPLEMENT_IOBJECT(MyTestObject);
private:
bool destroyed;
unsigned int foo;
unsigned int bar;
public:
static MyTestObject* create();
MyTestObject(): destroyed(false), foo(0), bar(0) {
}
virtual ~MyTestObject() {
ASSERT(!destroyed, "test object destroyed twice");
destroyed = true;
}
virtual unsigned int getFoo() {
return foo;
}
virtual void setFoo(unsigned int aFoo) {
foo = aFoo;
}
virtual unsigned int getBar() {
return bar;
}
virtual void setBar(unsigned int aBar) {
bar = aBar;
}
};
UUID_MAP_BEGIN(MyTestObject)
UUID_MAP_ENTRY_2(IObject, IFoo)
UUID_MAP_ENTRY(IFoo)
UUID_MAP_ENTRY(IBar)
UUID_MAP_END
MyTestObject* MyTestObject::create() {
return new MyTestObject;
}
void test005() {
MyTestObject* test = 0;
IObject* iobj = 0;
IFoo* ifoo = 0;
IBar* ibar = 0;
IWeakRef* weak1 = 0;
IWeakRef* weak2 = 0;
IObject* itest = 0;
test = MyTestObject::create();
ASSERT(test, "could not instantiate test object");
iobj = static_cast(test)->getInterface(IObject_IID);
VERIFY(iobj, "getInterface(IObject::getIID()) failed on test object");
VERIFY(reinterpret_cast(iobj) == reinterpret_cast(test), "identity test failed");
weak1 = iobj->getWeakRef();
ASSERT(weak1, "could not obtain first weak reference");
weak2 = iobj->getWeakRef();
ASSERT(weak2, "could not obtain second weak reference");
VERIFY(weak1 == weak2, "the two weak references are different");
ifoo = get(iobj);
VERIFY(ifoo, "get failed on test object");
ibar = get(ifoo);
VERIFY(ibar, "get failed on test object");
ifoo->setFoo(10);
ibar->setBar(20);
itest = weak1->getObject();
ASSERT(itest, "could not strengthen the weak reference");
VERIFY(itest->release() == 4, "incorrect refcount");
VERIFY(ifoo->getFoo() == 10, "test object has unexpected behavior");
VERIFY(ibar->getBar() == 20, "test object has unexpected behavior");
VERIFY(iobj->addRef() == 5, "incorrect refcount");
VERIFY(ifoo->addRef() == 6, "incorrect refcount");
VERIFY(ibar->addRef() == 7, "incorrect refcount");
VERIFY(iobj->release() == 6, "incorrect refcount");
VERIFY(ifoo->release() == 5, "incorrect refcount");
VERIFY(ibar->release() == 4, "incorrect refcount");
VERIFY(iobj->release() == 3, "incorrect refcount");
VERIFY(ifoo->release() == 2, "incorrect refcount");
VERIFY(ibar->release() == 1, "incorrect refcount");
VERIFY(static_cast(test)->release() == 0, "incorrect refcount");
itest = weak1->getObject();
VERIFY(!itest, "weak->getObject gave us something when it shouldn't");
VERIFY(weak1->release() == 1, "incorrect refcount");
VERIFY(weak2->release() == 0, "incorrect refcount");
}
xplc-0.3.13/tests/rules.mk 0100644 0002043 0002043 00000002433 10167073150 015562 0 ustar pphaneuf pphaneuf # XPLC - Cross-Platform Lightweight Components
# Copyright (C) 2000-2002, Pierre Phaneuf
# Copyright (C) 2002, Net Integration Technologies, Inc.
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
#
# $Id: rules.mk,v 1.21 2005/01/05 23:21:12 pphaneuf Exp $
.PHONY: tests
ifeq ("$(enable_loader)", "no")
tests: default tests/testmain
else
tests: default tests/testmain tests/testobj.dll
endif
@echo "Running tests:"
@cd tests && ./testmain $(TESTS)
tests/testmain: tests/testmain.o $(patsubst %.cpp,%.o,$(wildcard tests/test[0-9][0-9][0-9].cpp)) libxplc.a libxplc-cxx.a $(LIBS)
tests/testobj.dll: tests/testobj.o libxplc-cxx.a
xplc-0.3.13/tests/test006.cpp 0100644 0002043 0002043 00000006437 10102611215 016005 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2001-2002, Pierre Phaneuf
* Copyright (C) 2002-2004, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "test.h"
#include
#include
#include
/*
* test006
*
* Verifies the moniker facility
*/
void test006() {
IServiceManager* servmgr;
IStaticServiceHandler* handler;
IMonikerService* monikers;
IObject* testobj;
IObject* obj;
servmgr = XPLC_getServiceManager();
ASSERT(servmgr != 0, "could not obtain service manager");
obj = servmgr->getObject(XPLC_staticServiceHandler);
ASSERT(obj != 0, "could not obtain static service handler");
handler = mutate(obj);
ASSERT(handler != 0, "static service handler does not have the IStaticServiceHandler interface");
testobj = new TestObject;
ASSERT(testobj != 0, "could not create TestObject");
handler->addObject(TestObject_CID, testobj);
VERIFY(servmgr->getObject(TestObject_CID) == testobj, "adding the test object did not work");
VERIFY(testobj->release() == 2, "incorrect refcount on test object");
obj = servmgr->getObject(XPLC_monikers);
ASSERT(obj != 0, "could not obtain moniker component");
monikers = mutate(obj);
ASSERT(monikers != 0, "moniker service does not have the IMoniker interface");
monikers->registerObject("moniker", XPLC_monikers);
monikers->registerObject("testobject", TestObject_CID);
obj = monikers->resolve("testobject");
ASSERT(obj != 0, "resolving the test object returned nothing");
ASSERT(obj == testobj, "the testobject moniker resolved to something else than the test object");
VERIFY(obj->release() == 2, "refcount is wrong on the test object");
obj = monikers->resolve("moniker:testobject");
ASSERT(obj != 0, "resolving the test object indirectly returned nothing");
ASSERT(obj == testobj, "the testobject moniker indirectly resolved to something else than the test object");
VERIFY(obj->release() == 2, "refcount is wrong on the test object");
obj = monikers->resolve("moniker:");
VERIFY(obj == 0, "resolving an empty sub-moniker returned something");
VERIFY(monikers->release() == 1, "incorrect refcount on moniker service");
VERIFY(handler->release() == 2, "incorrect refcount on static service handler");
VERIFY(servmgr->release() == 0, "service manager has non-zero refcount after release");
VERIFY(testobj->release() == 0, "refcount is wrong on the test object");
xplcdelete testobj;
}
xplc-0.3.13/tests/test007.cpp 0100644 0002043 0002043 00000005367 10167076476 016040 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2002-2003, Pierre Phaneuf
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "test.h"
#include
#include
/*
* test007
*
* Verifies the UUID stringification and parsing.
*/
#ifdef WIN32
#define snprintf _snprintf
#endif
void test007() {
const UUID u0 = {0xe87db3a0, 0x109a, 0x4ecb, {0x86, 0x64, 0x66, 0x85,
0x45, 0x20, 0xa6, 0xcc}};
UUID u1;
const char u2[] = "e87db3a0-109a-4ecb-8664-66854520a6cc";
char u3[39];
char u4[39];
char u5[39];
char u6[38];
int rv;
ASSERT(sizeof(u0) == 16, "UUID structure is of unexpected size");
ASSERT(sizeof(u2) == 37, "u2 is of unexpected size");
u1 = UUID_null;
u1 = UuidFromString(u2);
VERIFY(u1 == u0, "u2 was not parsed properly into u1");
rv = snprintf(u3, 39, "{%s}", u2);
ASSERT(rv == 38, "copying u2 into u3 with curly braces failed");
u1 = UUID_null;
VERIFY(u1 == UUID_null, "u1 is not equal to UUID_null after resetting");
u1 = UuidFromString(u3);
VERIFY(u1 == u0, "u3 was not parsed properly into u1");
rv = snprintf(u4, 39, "{%x-%x-%x-%x%x-%x%x%x%x%x%x}",
u0.Data1, u0.Data2, u0.Data3,
u0.Data4[0],
u0.Data4[1],
u0.Data4[2],
u0.Data4[3],
u0.Data4[4],
u0.Data4[5],
u0.Data4[6],
u0.Data4[7]);
ASSERT(rv == 38, "formatting u0 into u4 (with snprintf) failed");
VERIFY(strncmp(u3, u4, 39) == 0, "result of formatting u0 into u4 was different from u3");
UuidToString(u0, u5);
VERIFY(strncmp(u3, u5, 39) == 0, "result of using toString on u0 was different from u3");
rv = snprintf(u6, 38, "{%s", u2);
ASSERT(rv == 37, "copying u2 into u6 with starting curly brace failed");
u1 = u0;
u1 = UuidFromString(u6);
VERIFY(u1 == UUID_null, "fromString wrongfully accepted u6 into u1");
rv = snprintf(u6, 38, "%s}", u2);
ASSERT(rv == 37, "copying u2 into u6 with ending curly brace failed");
u1 = u0;
u1 = UuidFromString(u6);
VERIFY(u1 == UUID_null, "fromString wrongfully accepted u6 into u1");
}
xplc-0.3.13/tests/test008.cpp 0100644 0002043 0002043 00000005550 10102611215 016002 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2001-2002, Pierre Phaneuf
* Copyright (C) 2002, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "test.h"
#include
#include
#include
/*
* test008
*
* Verifies the "new" moniker
*/
void test008() {
IServiceManager* servmgr;
IStaticServiceHandler* handler;
IMonikerService* monikers;
ITestInterface* test;
TestObjectFactory* factory;
IObject* obj;
servmgr = XPLC_getServiceManager();
ASSERT(servmgr != 0, "could not obtain service manager");
obj = servmgr->getObject(XPLC_staticServiceHandler);
ASSERT(obj != 0, "could not obtain static service handler");
handler = mutate(obj);
ASSERT(handler != 0, "static service handler does not have the IStaticServiceHandler interface");
factory = new TestObjectFactory;
ASSERT(factory != 0, "could not instantiate test object factory");
handler->addObject(TestObjectFactory_CID, factory);
VERIFY(servmgr->getObject(TestObjectFactory_CID) == factory, "adding the test object factory did not work");
VERIFY(factory->release() == 2, "incorrect refcount on test object factory");
VERIFY(handler->release() == 2, "incorrect refcount on static service handler");
monikers = mutate(servmgr->getObject(XPLC_monikers));
ASSERT(monikers != 0, "could not obtain correct moniker service");
monikers->registerObject("testobject", TestObjectFactory_CID);
obj = monikers->resolve("new:testobject");
ASSERT(obj != 0, "could not obtain test object");
VERIFY(monikers->release() == 1, "incorrect refcount on moniker service");
test = get(obj);
VERIFY(test != 0, "test object does not have ITestInterface");
VERIFY(test->release() == 1, "incorrect refcount on test object");
VERIFY(obj->release() == 0, "incorrect refcount on test object");
VERIFY(servmgr->release() == 0, "service manager has non-zero refcount after release");
VERIFY(factory->release() == 0, "incorrect refcount on test object factory");
}
xplc-0.3.13/tests/test009.cpp 0100644 0002043 0002043 00000004561 10102611215 016004 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2002-2004, Pierre Phaneuf
* Copyright (C) 2002-2004, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "config.h"
#include
#include
#include
#include "test.h"
#include "testobj.h"
/*
* test009
*
* Verifies the module manager.
*/
void test009() {
#ifdef ENABLE_LOADER
IServiceManager* servmgr;
IObject* obj;
IModuleManagerFactory* mgrfactory;
IServiceHandler* modulemgr;
ITestComponent* test;
servmgr = XPLC_getServiceManager();
ASSERT(servmgr != 0, "could not obtain service manager");
obj = servmgr->getObject(XPLC_moduleManagerFactory);
ASSERT(obj != 0, "could not obtain module manager factory");
mgrfactory = mutate(obj);
ASSERT(mgrfactory != 0, "factory does not have expected interface");
modulemgr = mgrfactory->createModuleManager(".");
ASSERT(modulemgr, "could not create module manager");
VERIFY(mgrfactory->release() == 1, "factory has wrong refcount");
obj = modulemgr->getObject(TestComponent_CID);
ASSERT(obj != 0, "could not create test object");
test = mutate(obj);
ASSERT(test != 0, "test object did not have expected interface");
ASSERT(test->getAnswer() == 42, "test object did not have expected behavior");
VERIFY(test->release() == 0, "test object has wrong refcount");
VERIFY(modulemgr->release() == 0, "incorrect refcount on module loader");
VERIFY(servmgr->release() == 0, "service manager has non-zero refcount after release");
#endif
}
xplc-0.3.13/tests/test010.cpp 0100644 0002043 0002043 00000011570 10234003101 015765 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2003, Pierre Phaneuf
* Copyright (C) 2003, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include
#include
#include
#include
#include "test.h"
#include "testobj.h"
#include "config.h"
/*
* test010
*
* Tests categories.
*/
static const UUID myComponent1 = {0xb4a924ca, 0x0b81, 0x48de,
{0xb6, 0x61, 0x5c, 0x63,
0x54, 0xcc, 0xa0, 0xac}};
static const UUID myComponent2 = {0x02080213, 0x37f7, 0x4961,
{0x85, 0x2e, 0x78, 0x97,
0x51, 0x9c, 0xfa, 0x49}};
static const UUID myComponent3 = {0xea511e95, 0x5be4, 0x4b08,
{0x86, 0xca, 0xad, 0xd5,
0x9a, 0xf7, 0xe2, 0x94}};
#ifdef ENABLE_LOADER
#define NUM_CATITEM 4
#else
#define NUM_CATITEM 3
#endif
void test010() {
IServiceManager* servmgr;
IObject* obj;
ICategoryManager* catmgr;
ICategory* cat;
ICategoryIterator* iter;
unsigned int num;
bool seen[NUM_CATITEM];
#ifdef ENABLE_LOADER
IModuleManagerFactory* mgrfactory;
IServiceHandler* modulemgr;
#endif
servmgr = XPLC_getServiceManager();
ASSERT(servmgr != 0, "could not obtain service manager");
obj = servmgr->getObject(XPLC_categoryManager);
ASSERT(obj != 0, "could not obtain category manager");
catmgr = mutate(obj);
ASSERT(catmgr != 0, "category manager does not have expected interface");
#ifdef ENABLE_LOADER
obj = servmgr->getObject(XPLC_moduleManagerFactory);
ASSERT(obj != 0, "could not obtain module manager factory");
mgrfactory = mutate(obj);
ASSERT(mgrfactory != 0, "factory does not have expected interface");
modulemgr = mgrfactory->createModuleManager(".");
ASSERT(modulemgr, "could not create module manager");
VERIFY(mgrfactory->release() == 1, "factory has wrong refcount");
#endif
catmgr->registerComponent(testCategory, myComponent1, "myComponent1");
catmgr->registerComponent(testCategory, myComponent2, "myComponent2");
catmgr->registerComponent(testCategory, myComponent3, 0);
cat = catmgr->getCategory(testCategory);
ASSERT(cat, "could not obtain the category");
for(num = 0; num < NUM_CATITEM; ++num) {
seen[num] = false;
}
iter = cat->getIterator();
ASSERT(iter, "could not obtain the category iterator");
num = 0;
for(; !iter->done(); iter->next()) {
++num;
if(iter->getUuid() == myComponent1) {
VERIFY(!seen[0], "myComponent1 already seen");
VERIFY(iter->getString()
&& strcmp(iter->getString(), "myComponent1") == 0,
"incorrect string for myComponent1");
seen[0] = true;
} else if(iter->getUuid() == myComponent2) {
VERIFY(!seen[1], "myComponent2 already seen");
VERIFY(iter->getString()
&& strcmp(iter->getString(), "myComponent2") == 0,
"incorrect string for myComponent2");
seen[1] = true;
} else if(iter->getUuid() == myComponent3) {
VERIFY(!seen[2], "myComponent3 already seen");
VERIFY(!iter->getString(), "incorrect string for myComponent3");
seen[2] = true;
#ifdef ENABLE_LOADER
} else if(iter->getUuid() == TestComponent_CID) {
VERIFY(!seen[3], "TestComponent already seen");
VERIFY(iter->getString()
&& strcmp(iter->getString(), "TestComponent") == 0,
"incorrect string for TestComponent");
seen[3] = true;
#endif
} else {
VERIFY(false, "got an unknown component");
}
}
VERIFY(iter->release() == 0, "category iterator has wrong refcount");
VERIFY(num == NUM_CATITEM, "the category has an incorrect number of items");
VERIFY(cat->release() == 0, "category has wrong refcount");
#ifdef ENABLE_LOADER
VERIFY(modulemgr->release() == 0, "incorrect refcount on module loader");
#endif
VERIFY(catmgr->release() == 1, "category manager has wrong refcount");
VERIFY(servmgr->release() == 0, "service manager has non-zero refcount after release");
}
xplc-0.3.13/tests/test011.cpp 0100644 0002043 0002043 00000005616 10102611215 015777 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2004, Pierre Phaneuf
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "test.h"
#include
/*
* test011
*
* Tests xplc_ptr<>.
*/
void test011() {
TestObject* testobj1 = new TestObject(false);
TestObject* testobj2 = new TestObject(false);
IObject* obj;
ITestInterface* testiface;
ITestInterface2* testiface2;
testobj1->addRef();
testobj2->addRef();
{
xplc_ptr ptr1(testobj1);
xplc_ptr ptr2(testobj2);
xplc_ptr ptr3(ptr1);
VERIFY(ptr1->getRefCount() == 3, "incorrect refcount on test object 1");
VERIFY(ptr2->getRefCount() == 2, "incorrect refcount on test object 2");
VERIFY(ptr1, "test for truth");
VERIFY(!(!ptr1), "test for falseness");
VERIFY(ptr1 == ptr1, "test for self-equality");
VERIFY(!(ptr1 == ptr2), "test for broken equality");
VERIFY(ptr1 != ptr2, "test for broken non-equality");
if(testobj1 < testobj2) {
VERIFY(ptr1 < ptr2, "test for less-than operator");
VERIFY(!(ptr2 < ptr1), "test for less-than operator");
VERIFY(ptr2 > ptr1, "test for greater-than operator");
VERIFY(!(ptr1 > ptr2), "test for greater-than operator");
} else {
VERIFY(ptr2 < ptr1, "test for less-than operator");
VERIFY(!(ptr1 < ptr2), "test for less-than operator");
VERIFY(ptr1 > ptr2, "test for greater-than operator");
VERIFY(!(ptr2 > ptr1), "test for greater-than operator");
}
ptr1 = 0;
VERIFY(testobj1->getRefCount() == 2, "incorrect refcount on test object");
ptr1 = testobj1;
obj = ptr1;
VERIFY(obj == testobj1, "assignment to IObject");
testiface = ptr1;
VERIFY(testiface == testobj1, "assignment to ITestInterface");
testiface2 = ptr1;
VERIFY(testiface2 == testobj1, "assignment to ITestInterface2");
VERIFY(testobj1->getRefCount() == 3, "incorrect refcount on test object 1");
}
VERIFY(testobj1->release() == 0, "incorrect refcount on test object 1");
VERIFY(testobj2->release() == 0, "incorrect refcount on test object 2");
delete testobj1;
delete testobj2;
}
xplc-0.3.13/tests/testmain.cpp 0100644 0002043 0002043 00000005531 10167072644 016440 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2000-2002, Pierre Phaneuf
* Copyright (C) 2001, Stéphane Lajoie
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include
#include
#include
#include
#include "test.h"
static unsigned int passed;
static unsigned int failed;
struct Test {
const char* name;
void (*test)();
};
static char* prog;
#define ADD_TEST(testname) { #testname, testname }
static Test tests[] = {
ADD_TEST(test000),
ADD_TEST(test001),
ADD_TEST(test002),
ADD_TEST(test003),
ADD_TEST(test004),
ADD_TEST(test005),
ADD_TEST(test006),
ADD_TEST(test007),
ADD_TEST(test008),
ADD_TEST(test009),
ADD_TEST(test010),
ADD_TEST(test011),
{ 0, 0 }
};
void test_assert(const char* file,
unsigned int line,
bool test,
const char* reason) {
if(test) {
passed++;
} else {
failed++;
fprintf(stderr, "%s:%i: %s\n", file, line, reason);
fprintf(stderr, "%s: %i failed, %i passed\n", prog, failed, passed);
exit(1);
}
}
void test_verify(const char* file,
unsigned int line,
bool test,
const char* reason) {
if(test) {
passed++;
} else {
failed++;
fprintf(stderr, "%s:%i: %s\n", file, line, reason);
}
}
int main(int argc, char* argv[]) {
Test* test = tests;
unsigned int total_passed = 0;
unsigned int total_failed = 0;
prog = argv[0];
for(test = tests; test && test->test; ++test) {
assert(test->name);
if(argc > 1) {
int argsleft = argc;
for(argsleft = argc;
argsleft > 1 && strcmp(argv[argsleft - 1], test->name) != 0;
--argsleft) {
}
if(argsleft <= 1)
continue;
}
passed = 0;
failed = 0;
test->test();
total_passed += passed;
total_failed += failed;
}
if((total_failed + total_passed) == 0) {
fprintf(stderr, "%s: BAD TEST\n", prog);
exit(1);
}
fprintf(stderr, "%s: %i failed, %i passed\n",
prog, total_failed, total_passed);
return (total_failed != 0);
}
xplc-0.3.13/tests/testobj.cpp 0100644 0002043 0002043 00000003744 10234003101 016243 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2000-2002, Pierre Phaneuf
* Copyright (C) 2002, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include
#include
#include
#include "testobj.h"
/*
* testobj
*
* Contains a small test object.
*/
class TestComponent: public ITestComponent {
IMPLEMENT_IOBJECT(TestComponent);
public:
/* ITestComponent */
virtual int getAnswer();
};
int TestComponent::getAnswer() {
/*
* The Answer to Life, Universe and Everything.
*/
return 42;
}
static IObject* factory() {
static TestComponent* component = 0;
if(!component)
component = new TestComponent;
return component;
}
UUID_MAP_BEGIN(TestComponent)
UUID_MAP_ENTRY(IObject)
UUID_MAP_ENTRY(ITestComponent)
UUID_MAP_END
const XPLC_ComponentEntry components[] = {
{ TestComponent_CID, &factory },
{ UUID_null, 0 }
};
const XPLC_CategoryEntry categories[] = {
{ testCategory, TestComponent_CID, "TestComponent" },
{ UUID_null, UUID_null, 0 }
};
const XPLC_ModuleInfo XPLC_Module = {
XPLC_MODULE_MAGIC,
XPLC_MODULE_VERSION_MAJOR,
XPLC_MODULE_VERSION_MINOR,
"Test Module",
components,
categories
};
xplc-0.3.13/tests/testobj.h 0100644 0002043 0002043 00000003201 10234003101 015674 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2000-2002, Pierre Phaneuf
* Copyright (C) 2002, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifndef __TESTS_TESTOBJ_H__
#define __TESTS_TESTOBJ_H__
#include
class ITestComponent: public IObject {
public:
virtual int getAnswer() = 0;
};
DEFINE_IID(ITestComponent, {0x1db2ab25, 0xc54f, 0x4374,
{0x8b, 0x52, 0xc1, 0x85, 0xe7, 0xeb, 0x83, 0x91}});
static const UUID TestComponent_CID = {0x746d2ba8, 0x0a52, 0x4156,
{0xb9, 0x20, 0x05, 0x85,
0x3f, 0xf1, 0x73, 0x43}};
static const UUID testCategory = {0xeb1babb7, 0xebbf, 0x415f,
{0xa5, 0x3b, 0xc0, 0xda,
0x3b, 0x6d, 0xad, 0x99}};
#endif /* __TESTS_TESTOBJ_H__ */
xplc-0.3.13/tests/vars.mk 0100644 0002043 0002043 00000001714 07567533711 015422 0 ustar pphaneuf pphaneuf # XPLC - Cross-Platform Lightweight Components
# Copyright (C) 2000-2002, Pierre Phaneuf
# Copyright (C) 2002, Net Integration Technologies, Inc.
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
#
# $Id: vars.mk,v 1.12 2002/11/22 23:03:37 pphaneuf Exp $
CLEAN+=tests/testmain tests/testobj.dll
xplc-0.3.13/xplc/ 0040755 0002043 0002043 00000000000 10331536343 013705 5 ustar pphaneuf pphaneuf xplc-0.3.13/xplc/CVS/ 0040755 0002043 0002043 00000000000 10234003101 014317 5 ustar pphaneuf pphaneuf xplc-0.3.13/xplc/CVS/Repository 0100644 0002043 0002043 00000000012 10075346774 016444 0 ustar pphaneuf pphaneuf xplc/xplc
xplc-0.3.13/xplc/CVS/Entries 0100644 0002043 0002043 00000002256 10234003101 015655 0 ustar pphaneuf pphaneuf /.cvsignore/1.1/Fri Oct 18 22:32:23 2002//
/handlernode.h/1.7/Mon Nov 18 07:10:41 2002//
/loader.h/1.4/Fri Jan 30 22:59:37 2004//
/monikernode.h/1.4/Sat Nov 30 07:53:59 2002//
/monikers.cpp/1.9/Sun Oct 19 05:28:04 2003//
/monikers.h/1.6/Wed Apr 7 16:43:53 2004//
/new.cpp/1.12/Sun Oct 19 05:28:04 2003//
/new.h/1.7/Wed Apr 7 16:43:53 2004//
/objectnode.h/1.4/Mon Nov 18 04:52:41 2002//
/rules.mk/1.19/Fri May 21 20:21:35 2004//
/servmgr.h/1.23/Wed Apr 7 16:43:53 2004//
/statichandler.cpp/1.14/Fri Jun 25 18:23:30 2004//
/statichandler.h/1.9/Wed Dec 31 18:44:17 2003//
/vars.mk/1.13/Thu Dec 5 03:48:19 2002//
/modulemgr.h/1.1/Tue Jul 20 14:35:44 2004//
/modulemgr.cpp/1.4/Thu Sep 30 21:09:54 2004//
/category.cpp/1.4/Sat Feb 12 01:15:24 2005//
/category.h/1.5/Sat Feb 12 01:15:35 2005//
/categorynode.h/1.2/Sat Feb 12 01:15:35 2005//
/catiter.cpp/1.2/Sat Feb 12 01:15:35 2005//
/catiter.h/1.2/Sat Feb 12 01:15:35 2005//
/catmgr.cpp/1.10/Sat Feb 12 01:15:35 2005//
/catmgr.h/1.7/Sat Feb 12 01:15:36 2005//
/servmgr.cpp/1.34/Fri Apr 8 20:45:21 2005//
/loader.cpp/1.14/Fri Apr 8 22:44:09 2005//
/moduleloader.h/1.14/Wed Mar 9 21:02:21 2005//
/moduleloader.cpp/1.30/Wed Apr 27 21:38:09 2005//
D
xplc-0.3.13/xplc/CVS/Root 0100644 0002043 0002043 00000000065 10331536343 015204 0 ustar pphaneuf pphaneuf :pserver:anonymous@cvs.sourceforge.net:/cvsroot/xplc
xplc-0.3.13/xplc/.cvsignore 0100644 0002043 0002043 00000000005 07554105767 015714 0 ustar pphaneuf pphaneuf .*.d
xplc-0.3.13/xplc/statichandler.cpp 0100644 0002043 0002043 00000004666 10067066642 017255 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2000-2003, Pierre Phaneuf
* Copyright (C) 2002, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include
#include
#include
#include "statichandler.h"
UUID_MAP_BEGIN(StaticServiceHandler)
UUID_MAP_ENTRY(IObject)
UUID_MAP_ENTRY(IServiceHandler)
UUID_MAP_ENTRY(IStaticServiceHandler)
UUID_MAP_END
StaticServiceHandler::~StaticServiceHandler() {
ObjectNode* node;
ObjectNode* ptr;
node = objects;
while(node) {
ptr = node;
node = node->next;
delete ptr;
}
objects = 0;
}
IObject* StaticServiceHandler::getObject(const UUID& aUuid) {
ObjectNode* node;
node = objects;
while(node) {
if(node->uuid == aUuid) {
node->obj->addRef();
return node->obj;
}
node = node->next;
}
/*
* No match was found, we return empty-handed.
*/
return 0;
}
void StaticServiceHandler::addObject(const UUID& aUuid, IObject* aObj) {
ObjectNode* node;
/* No object given? */
if(!aObj)
return;
node = objects;
while(node) {
if(node->uuid == aUuid)
break;
node = node->next;
}
/*
* FIXME: maybe add a "replace" bool parameter? Or would this
* encourage UUID hijacking too much?
*/
if(node)
return;
node = new ObjectNode(aUuid, aObj, objects);
objects = node;
}
void StaticServiceHandler::removeObject(const UUID& aUuid) {
ObjectNode* node;
ObjectNode** ptr;
node = objects;
ptr = &objects;
while(node) {
if(node->uuid == aUuid) {
*ptr = node->next;
delete node;
break;
}
ptr = &node->next;
node = *ptr;
}
}
xplc-0.3.13/xplc/category.cpp 0100644 0002043 0002043 00000002653 10203254254 016225 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2003, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include
#include "category.h"
#include "catiter.h"
UUID_MAP_BEGIN(Category)
UUID_MAP_ENTRY(IObject)
UUID_MAP_ENTRY(ICategory)
UUID_MAP_END
Category::Category(ICategoryManager* aMgr, CategoryEntryNode* aEntries):
mgr(aMgr),
entries(aEntries) {
/*
* Prevent the category manager from dying (which would free the
* list).
*/
mgr->addRef();
}
ICategoryIterator* Category::getIterator() {
return new CategoryIterator(this, entries);
}
Category::~Category() {
mgr->release();
}
xplc-0.3.13/xplc/category.h 0100644 0002043 0002043 00000002521 10203254267 015670 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2003, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifndef __XPLC_CATEGORY_H__
#define __XPLC_CATEGORY_H__
#include
#include "categorynode.h"
class Category: public ICategory {
IMPLEMENT_IOBJECT(Category);
private:
ICategoryManager* mgr;
CategoryEntryNode* entries;
public:
Category(ICategoryManager*, CategoryEntryNode*);
/* ICategory */
virtual ICategoryIterator* getIterator();
virtual ~Category();
};
#endif /* __XPLC_CATEGORY_H__ */
xplc-0.3.13/xplc/categorynode.h 0100644 0002043 0002043 00000003562 10203254267 016544 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2000, Pierre Phaneuf
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifndef __XPLC_CATEGORYNODE_H__
#define __XPLC_CATEGORYNODE_H__
#include
#include
class CategoryEntryNode {
public:
CategoryEntryNode* next;
UUID entry;
char* str;
CategoryEntryNode(const UUID& aUuid,
const char* aStr,
CategoryEntryNode* aNext): next(aNext),
entry(aUuid),
str(aStr ? strdup(aStr) : 0) {
}
~CategoryEntryNode() {
if(next)
delete next;
if(str)
free(str);
}
};
class CategoryNode {
public:
CategoryNode* next;
UUID category;
CategoryEntryNode* entries;
CategoryNode(const UUID& aUuid,
CategoryNode* aNext): next(aNext),
category(aUuid),
entries(0) {
}
~CategoryNode() {
if(entries)
delete entries;
if(next)
delete next;
}
};
#endif /* __XPLC_CATEGORYNODE_H__ */
xplc-0.3.13/xplc/catiter.cpp 0100644 0002043 0002043 00000003442 10203254267 016044 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2004, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include
#include "catiter.h"
UUID_MAP_BEGIN(CategoryIterator)
UUID_MAP_ENTRY(IObject)
UUID_MAP_ENTRY(ICategoryIterator)
UUID_MAP_END
CategoryIterator::CategoryIterator(ICategory* aCategory,
CategoryEntryNode* aEntries):
category(aCategory),
current(aEntries) {
/*
* Prevent the category from dying, which in turn prevents the
* category manager from dying (which would free the list).
*/
category->addRef();
}
const UUID& CategoryIterator::getUuid() {
if(current)
return current->entry;
return UUID_null;
}
const char* CategoryIterator::getString() {
if(current)
return current->str;
return 0;
}
void CategoryIterator::next() {
if(current)
current = current->next;
}
bool CategoryIterator::done() {
return current == 0;
}
CategoryIterator::~CategoryIterator() {
category->release();
}
xplc-0.3.13/xplc/catiter.h 0100644 0002043 0002043 00000002700 10203254267 015505 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2004, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifndef __XPLC_CATITER_H__
#define __XPLC_CATEITER_H__
#include
#include
#include "categorynode.h"
class CategoryIterator: public ICategoryIterator {
IMPLEMENT_IOBJECT(CategoryIterator);
private:
ICategory* category;
CategoryEntryNode* current;
public:
CategoryIterator(ICategory*, CategoryEntryNode*);
virtual const UUID& getUuid();
virtual const char* getString();
virtual void next();
virtual bool done();
virtual ~CategoryIterator();
};
#endif /* __XPLC_CATEITER_H__ */
xplc-0.3.13/xplc/catmgr.cpp 0100644 0002043 0002043 00000004266 10203254267 015673 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2003, Net Integration Technologies, Inc.
* Copyright (C) 2003, Pierre Phaneuf
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include
#include
#include
#include "catmgr.h"
#include "category.h"
UUID_MAP_BEGIN(CategoryManager)
UUID_MAP_ENTRY(IObject)
UUID_MAP_ENTRY(ICategoryManager)
UUID_MAP_END
CategoryManager::CategoryManager():
categories(0) {
}
CategoryManager::~CategoryManager() {
if(categories)
delete categories;
}
void CategoryManager::registerComponent(const UUID& aCatid,
const UUID& aUuid,
const char* aString) {
CategoryNode* cat;
CategoryEntryNode* entry;
for(cat = categories; cat; cat = cat->next) {
if(cat->category == aCatid)
break;
}
if(!cat) {
cat = new CategoryNode(aCatid, categories);
categories = cat;
}
assert(cat);
for(entry = cat->entries; entry; entry = entry->next) {
if(entry->entry == aUuid)
return;
}
entry = new CategoryEntryNode(aUuid, aString, cat->entries);
assert(entry);
cat->entries = entry;
}
ICategory* CategoryManager::getCategory(const UUID& aUuid) {
CategoryNode* cat;
for(cat = categories; cat; cat = cat->next) {
if(cat->category == aUuid)
return new Category(this, cat->entries);
}
return new Category(this, NULL);
}
xplc-0.3.13/xplc/catmgr.h 0100644 0002043 0002043 00000002647 10203254270 015333 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2003, Net Integration Technologies, Inc.
* Copyright (C) 2003, Pierre Phaneuf
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifndef __XPLC_CATMGR_H__
#define __XPLC_CATMGR_H__
#include
#include "categorynode.h"
class CategoryManager: public ICategoryManager {
IMPLEMENT_IOBJECT(CategoryManager);
private:
CategoryNode* categories;
public:
CategoryManager();
virtual ~CategoryManager();
/* ICategoryManager */
virtual void registerComponent(const UUID&, const UUID&, const char*);
virtual ICategory* getCategory(const UUID&);
};
#endif /* __XPLC_CATMGR_H__ */
xplc-0.3.13/xplc/handlernode.h 0100644 0002043 0002043 00000002653 07566111161 016347 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2000-2002, Pierre Phaneuf
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifndef __XPLC_HANDLERNODE_H__
#define __XPLC_HANDLERNODE_H__
#include
class HandlerNode {
public:
HandlerNode* next;
IServiceHandler* handler;
bool intercept;
HandlerNode(IServiceHandler* aHandler,
HandlerNode* aNext,
bool aIntercept): next(aNext),
handler(aHandler),
intercept(aIntercept) {
handler->addRef();
}
~HandlerNode() {
handler->release();
}
};
#endif /* __XPLC_HANDLERNODE_H__ */
xplc-0.3.13/xplc/loader.cpp 0100644 0002043 0002043 00000012021 10225604471 015650 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2002, Net Integration Technologies, Inc.
* Copyright (C) 2002-2004, Pierre Phaneuf
* Copyright (C) 2002-2004, Stéphane Lajoie
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include
#include
#include "config.h"
#include "loader.h"
#ifdef HAVE_DLFCN_H
#include
#endif
#ifdef HAVE_MACH_O_DYLD_H
#include
#endif
#if defined(WITH_DLOPEN) && defined(ENABLE_LOADER)
const char* loaderOpen(const char* aFilename,
void** aHandle) {
const char* rv = 0;
/* clear out dl error */
static_cast(dlerror());
*aHandle = dlopen(aFilename, RTLD_NOW);
if(!*aHandle)
rv = dlerror();
return rv;
}
const char* loaderSymbol(void* aHandle,
const char* aSymbol,
void** aPointer) {
/* clear out dl error */
static_cast(dlerror());
*aPointer = dlsym(aHandle, aSymbol);
return dlerror();
}
bool loaderClose(void*& aHandle) {
bool rv;
rv = dlclose(aHandle) == 0;
aHandle = 0;
return rv;
}
#elif defined(WITH_DYLD) && defined(ENABLE_LOADER)
const char* loaderOpen(const char* aFilename,
void** aHandle) {
NSObjectFileImage ofi = 0;
NSObjectFileImageReturnCode ofirc;
ofirc = NSCreateObjectFileImageFromFile(aFilename, &ofi);
switch(ofirc) {
case NSObjectFileImageSuccess:
*aHandle = NSLinkModule(ofi, aFilename,
NSLINKMODULE_OPTION_RETURN_ON_ERROR
| NSLINKMODULE_OPTION_PRIVATE
| NSLINKMODULE_OPTION_BINDNOW);
NSDestroyObjectFileImage(ofi);
break;
case NSObjectFileImageInappropriateFile:
*aHandle =
const_cast(reinterpret_cast(NSAddImage(aFilename, NSADDIMAGE_OPTION_RETURN_ON_ERROR)));
break;
default:
return "could not open dynamic library";
break;
}
return 0;
}
const char* loaderSymbol(void* aHandle,
const char* aSymbol,
void** aPointer) {
int len = strlen(aSymbol);
char* sym = static_cast(malloc(len + 2));
NSSymbol* nssym = 0;
snprintf(sym, len + 2, "_%s", aSymbol);
/* Check for both possible magic numbers depending on x86/ppc byte order */
if ((((struct mach_header *)aHandle)->magic == MH_MAGIC) ||
(((struct mach_header *)aHandle)->magic == MH_CIGAM)) {
if (NSIsSymbolNameDefinedInImage((struct mach_header *)aHandle, sym)) {
nssym = (NSModule *)NSLookupSymbolInImage((struct mach_header *)aHandle,
sym,
NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
| NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
}
} else {
nssym = (NSModule *)NSLookupSymbolInModule(aHandle, sym);
}
free(sym);
if(!nssym) {
*aPointer = 0;
return "symbol not found";
}
return 0;
}
bool loaderClose(void*& aHandle) {
aHandle = 0;
return false;
}
#elif defined(WIN32)
#include
const char* getErrorMessage() {
static char error[1024];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), 0, error, sizeof(error), 0);
return error;
}
const char* loaderOpen(const char* aFilename,
void** aHandle) {
const char* rv = 0;
UINT oldErrorMode = SetErrorMode(0);
SetErrorMode(oldErrorMode | SEM_FAILCRITICALERRORS);
*aHandle = LoadLibrary(aFilename);
SetErrorMode(oldErrorMode);
if(!*aHandle)
rv = getErrorMessage();
return rv;
}
const char* loaderSymbol(void* aHandle,
const char* aSymbol,
void** aPointer) {
const char* rv = 0;
*aPointer = GetProcAddress(static_cast(aHandle), aSymbol);
if(!aPointer)
rv = getErrorMessage();
return rv;
}
bool loaderClose(void*& aHandle) {
bool rv;
rv = FreeLibrary(static_cast(aHandle)) != 0;
aHandle = 0;
return rv;
}
#else
const char* loaderOpen(const char* aFilename,
void** aHandle) {
*aHandle = 0;
return "dynamic loading not supported on this platform";
}
const char* loaderSymbol(void* aHandle,
const char* aSymbol,
void** aPointer) {
*aPointer = 0;
return "dynamic loading not supported on this platform";
}
bool loaderClose(void*& aHandle) {
aHandle = 0;
return false;
}
#endif
xplc-0.3.13/xplc/loader.h 0100644 0002043 0002043 00000002363 10006560731 015322 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2002, Net Integration Technologies, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifndef __XPLC_LOADER_H__
#define __XPLC_LOADER_H__
const char* loaderOpen(const char* aFilename,
void** aHandle);
const char* loaderSymbol(void* aHandle,
const char* aSymbol,
void** aPointer);
bool loaderClose(void*& aHandle);
#endif /* __XPLC_LOADER_H__ */
xplc-0.3.13/xplc/moduleloader.cpp 0100644 0002043 0002043 00000006622 10234003101 017047 0 ustar pphaneuf pphaneuf /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* XPLC - Cross-Platform Lightweight Components
* Copyright (C) 2002-2004, Net Integration Technologies, Inc.
* Copyright (C) 2002-2004, Pierre Phaneuf
* Copyright (C) 2002-2004, Stéphane Lajoie
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include
#include
#include