diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 14:18:43 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 14:18:43 +0000 |
commit | 662c532f6f415060501f33261203100ff044fe8b (patch) | |
tree | 7447546af8a1095c31ec7f6fbfd0b68b97cf97a1 /vos/inc |
initial import
Diffstat (limited to 'vos/inc')
-rw-r--r-- | vos/inc/vos/conditn.hxx | 178 | ||||
-rw-r--r-- | vos/inc/vos/diagnose.hxx | 90 | ||||
-rw-r--r-- | vos/inc/vos/execabl.hxx | 195 | ||||
-rw-r--r-- | vos/inc/vos/istream.hxx | 112 | ||||
-rw-r--r-- | vos/inc/vos/macros.hxx | 206 | ||||
-rw-r--r-- | vos/inc/vos/module.hxx | 123 | ||||
-rw-r--r-- | vos/inc/vos/mutex.hxx | 224 | ||||
-rw-r--r-- | vos/inc/vos/object.hxx | 240 | ||||
-rw-r--r-- | vos/inc/vos/pipe.hxx | 313 | ||||
-rw-r--r-- | vos/inc/vos/process.hxx | 349 | ||||
-rw-r--r-- | vos/inc/vos/ref.hxx | 223 | ||||
-rw-r--r-- | vos/inc/vos/ref.inl | 226 | ||||
-rw-r--r-- | vos/inc/vos/refernce.hxx | 153 | ||||
-rw-r--r-- | vos/inc/vos/refobj.hxx | 129 | ||||
-rw-r--r-- | vos/inc/vos/refobj.inl | 120 | ||||
-rw-r--r-- | vos/inc/vos/runnable.hxx | 109 | ||||
-rw-r--r-- | vos/inc/vos/security.hxx | 165 | ||||
-rw-r--r-- | vos/inc/vos/signal.hxx | 152 | ||||
-rw-r--r-- | vos/inc/vos/socket.hxx | 1178 | ||||
-rw-r--r-- | vos/inc/vos/stream.hxx | 330 | ||||
-rw-r--r-- | vos/inc/vos/thread.hxx | 287 | ||||
-rw-r--r-- | vos/inc/vos/timer.hxx | 246 | ||||
-rw-r--r-- | vos/inc/vos/types.hxx | 77 | ||||
-rw-r--r-- | vos/inc/vos/xception.hxx | 125 |
24 files changed, 5550 insertions, 0 deletions
diff --git a/vos/inc/vos/conditn.hxx b/vos/inc/vos/conditn.hxx new file mode 100644 index 000000000000..93e66e4776cc --- /dev/null +++ b/vos/inc/vos/conditn.hxx @@ -0,0 +1,178 @@ +/************************************************************************* + * + * $RCSfile: conditn.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:11 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _VOS_CONDITN_HXX_ +#define _VOS_CONDITN_HXX_ + +#ifndef _OSL_CONDITN_H_ +# include <osl/conditn.h> +#endif +#ifndef _VOS_OBJECT_HXX_ +# include <vos/object.hxx> +#endif + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + + +/** ICondition + + Interface for a thread-spanning condition. If a condition-object + is created, its initial condition is False. You can check the + condition nonblocking with "check()" or wait for it to become set + with "wait()". The methods "set()" and "reset()" are used to change + the conditions state. + + @author Bernd Hofner + @version 1.0 +*/ +class ICondition +{ +public: + + ICondition() { } + virtual ~ICondition() { } + + + + enum TResult + { + result_ok = osl_cond_result_ok, + result_error = osl_cond_result_error, + result_timeout = osl_cond_result_timeout + }; + + /** set condition to True => + wait() will not block, check() returns True + */ + virtual void SAL_CALL set()= 0; + + /** set condition to False => + wait() will block, check() returns False + */ + virtual void SAL_CALL reset()= 0; + + /** Blocks if condition is not set<BR> + If condition has been destroyed prematurely, wait() will + return with False. + */ + virtual TResult SAL_CALL wait(const TimeValue* pTimeout = 0)= 0; + + /** True: condition is set <BR> + False: condition is not set <BR> + does not block + */ + virtual sal_Bool SAL_CALL check()= 0; +}; + + +/** OCondition + + Implements the ICondition interface. + + @author Bernd Hofner + @version 1.0 + +*/ +class OCondition : public OObject, public ICondition +{ + + VOS_DECLARE_CLASSINFO(VOS_NAMESPACE(OCondition, vos)); + +public: + + /// initial state of condition is not set + OCondition(); + virtual ~OCondition(); + + /// set condition to True => wait() will not block, check() returns True + virtual void SAL_CALL set(); + + /// set condition to False => wait() will block, check() returns False + virtual void SAL_CALL reset(); + + /** Blocks if condition is not set<BR> + If condition has been destroyed prematurely, wait() will + return with False. + */ + TResult SAL_CALL wait(const TimeValue* pTimeout = 0); + + /** True: condition is set <BR> + False: condition is not set <BR> + does not block + */ + virtual sal_Bool SAL_CALL check(); + +protected: + + oslCondition m_Condition; + +}; + +#ifdef _USE_NAMESPACE +} +#endif + +#endif // _VOS_CONDITN_HXX_ + diff --git a/vos/inc/vos/diagnose.hxx b/vos/inc/vos/diagnose.hxx new file mode 100644 index 000000000000..dcae8ed1e8be --- /dev/null +++ b/vos/inc/vos/diagnose.hxx @@ -0,0 +1,90 @@ +/************************************************************************* + * + * $RCSfile: diagnose.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:12 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _VOS_DIAGNOSE_H_ +#define _VOS_DIAGNOSE_H_ + + +#ifndef _OSL_DIAGNOSE_H_ + #include <osl/diagnose.h> +#endif + + +/* + Diagnostic support +*/ + +#define VOS_THIS_FILE __FILE__ + +#define VOS_DEBUG_ONLY(s) _OSL_DEBUG_ONLY(s) +#define VOS_TRACE _OSL_TRACE +#define VOS_ASSERT(c) _OSL_ASSERT(c, VOS_THIS_FILE, __LINE__) +#define VOS_VERIFY(c) _OSL_VERIFY(c, VOS_THIS_FILE, __LINE__) +#define VOS_ENSHURE(c, m) _OSL_ENSHURE(c, VOS_THIS_FILE, __LINE__, m) +#define VOS_ENSURE(c, m) _OSL_ENSURE(c, VOS_THIS_FILE, __LINE__, m) + +#define VOS_PRECOND(c, m) VOS_ENSHURE(c, m) +#define VOS_POSTCOND(c, m) VOS_ENSHURE(c, m) + +#endif /* _VOS_DIAGNOSE_H_ */ + + diff --git a/vos/inc/vos/execabl.hxx b/vos/inc/vos/execabl.hxx new file mode 100644 index 000000000000..aeaa25863808 --- /dev/null +++ b/vos/inc/vos/execabl.hxx @@ -0,0 +1,195 @@ +/************************************************************************* + * + * $RCSfile: execabl.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:12 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _VOS_EXECABL_HXX_ +#define _VOS_EXECABL_HXX_ + +#ifndef _VOS_TYPES_HXX_ +# include <vos/types.hxx> +#endif +#ifndef _VOS_REFERNCE_HXX_ +# include <vos/refernce.hxx> +#endif + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + + +/** IExecutable + + The IExecutable-interface is to be understood as wrapper around + your application-code, which allows it to be executed asynchronously. + + Wether you want real asynchronous behaviour or just pseudo-multitasking + depends on which kind of execution-service you use to execute your executable. + + (E.g. Threadpool/Fiberpool) + + @author Bernd Hofner + @version 0.1 +*/ + +class IExecutable : public NAMESPACE_VOS(IReference) +{ +public: + + /** Overload to implement your functionality. + Return True, if you want "execute()" to be called again. + */ + virtual sal_Bool SAL_CALL execute()= 0; + + + /** If you use blocking calls within your execute-function, + you should provide here a means to unblock cleanly. + @Return False if you are not able to unblock the + thread. + + */ + virtual sal_Bool SAL_CALL unblock()= 0; + + /** + STL demands this operators if you want to place + IExecutables per value in collections. + */ + virtual sal_Bool SAL_CALL operator<(const IExecutable&) const= 0; + virtual sal_Bool SAL_CALL operator>(const IExecutable&) const= 0; + virtual sal_Bool SAL_CALL operator==(const IExecutable&) const= 0; + virtual sal_Bool SAL_CALL operator!=(const IExecutable&) const= 0; +}; + + +/** OExecutable + added default impl. of IReferenceCounter +*/ +class OExecutable : public NAMESPACE_VOS(IExecutable), + public NAMESPACE_VOS(OReference) + +{ +public: + + virtual ~OExecutable() + { + } + + /* + Since the dominance of the OReferenceCounter impl. + of the IReferenceCounter is not granted, delegate + the methods to this branch of the diamond-shaped + inheritance tree. + */ + + virtual RefCount SAL_CALL acquire() + { + return OReference::acquire(); + } + virtual RefCount SAL_CALL release() + { + return OReference::release(); + } + virtual RefCount SAL_CALL referenced() const + { + return OReference::referenced(); + } + + + /** Default implementation of unblock does nothing. + */ + virtual sal_Bool SAL_CALL unblock() { return sal_True; } + + + /** + STL demands this operators if you want to place + IExecutables per value in collections. + Use a default implementation of the comparison-operators + here without a correct semantic. + */ + virtual sal_Bool SAL_CALL operator<(const IExecutable&) const + { + return sal_False; + } + + virtual sal_Bool SAL_CALL operator>(const IExecutable&) const + { + return sal_False; + } + + virtual sal_Bool SAL_CALL operator==(const IExecutable&) const + { + return sal_True; + } + + virtual sal_Bool SAL_CALL operator!=(const IExecutable&) const + { + return sal_False; + } +}; + + +#ifdef _USE_NAMESPACE +} +#endif + + +#endif // _VOS_EXECABL_HXX_ + diff --git a/vos/inc/vos/istream.hxx b/vos/inc/vos/istream.hxx new file mode 100644 index 000000000000..a6d7ee7d18a5 --- /dev/null +++ b/vos/inc/vos/istream.hxx @@ -0,0 +1,112 @@ +/************************************************************************* + * + * $RCSfile: istream.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:12 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VOS_ISTREAM_HXX_ +#define _VOS_ISTREAM_HXX_ + +#ifndef _VOS_TYPES_HXX_ +# include <vos/types.hxx> +#endif + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + +/** Interface for a stream of data, on that you can read and write blocks of bytes. +*/ +class IStream +{ +public: + + IStream() { } + virtual ~IStream() { } + + + /** Retrieve n bytes from the stream and copy them into pBuffer. + @param pBuffer receives the read data. + @param n the number of bytes to read. pBuffer must be large enough + to hold the n bytes! + @return the number of read bytes + */ + virtual sal_Int32 SAL_CALL read(void* pBuffer, + sal_uInt32 n) const= 0; + + /** Write n bytes from pBuffer to the stream. + @param pBuffer contains the data to be written. + @param n the number of bytes to write. + @return the number of written bytes + */ + virtual sal_Int32 SAL_CALL write(const void* pBuffer, + sal_uInt32 n)= 0; + + /** Checks if stream is closed for further reading. + @return True is stream has ended (e.g. was closed). + */ + virtual sal_Bool SAL_CALL isEof() const = 0; +}; + +#ifdef _USE_NAMESPACE +} +#endif + +#endif // _VOS_ISTREAM_HXX_ + diff --git a/vos/inc/vos/macros.hxx b/vos/inc/vos/macros.hxx new file mode 100644 index 000000000000..7169277dda35 --- /dev/null +++ b/vos/inc/vos/macros.hxx @@ -0,0 +1,206 @@ +/************************************************************************* + * + * $RCSfile: macros.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:12 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _VOS_MACROS_HXX_ +#define _VOS_MACROS_HXX_ + +#ifndef _OSL_TYPES_H_ +# include <osl/types.h> +#endif + +// ********************************************************************* +// Macro definitions + +#ifndef VOS_CAST +# define VOS_CAST(type,value) (*((type*)&(value))) +#endif + +#ifndef VOS_UNUSED +# define VOS_UNUSED(x) (x=x) +#endif + +#ifndef VOS_FOREVER +# define VOS_FOREVER for(;;) +#endif + +#ifndef VOS_MAX +# define VOS_MAX(a,b) (((a) > (b)) ? (a) : (b)) +#endif +#ifndef VOS_MIN +# define VOS_MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#ifndef VOS_ABS +# define VOS_ABS(a) (((a) < 0) ? (-(a)) : (a)) +#endif +#ifndef VOS_SIGN +# define VOS_SIGN(a) ( ((a) < 0) ? (-1) : (((a) > 0) ? (1) : (0)) ) +#endif + +#ifndef VOS_BOUND +# define VOS_BOUND(x,l,h) ((x) <= (l) ? (l) : ((x) >= (h) ? (h) : (x))) +#endif + +#ifndef VOS_SWAP +# define VOS_SWAP(a,b) ((a) ^= (b) ^= (a) ^= (b)) +#endif + +#ifndef VOS_BYTEBOUND +# define VOS_BYTEBOUND(a) (((a) + 7) / 8) +#endif + +#ifndef VOS_WORDBOUND +# define VOS_WORDBOUND(a) ((((a) + 15) / 16) * 2) +#endif + +#ifndef VOS_DWORDBOUND +# define VOS_DWORDBOUND(a) ((((a) + 31) / 32) * 4) +#endif + +#ifndef VOS_MAKEDWORD +# define VOS_MAKEDWORD(wl, wh) ((sal_uInt32)((wl) & 0xFFFF) | (((sal_uInt32)(wh) & 0xFFFF) << 16)) +#endif +#ifndef VOS_LOWORD +# define VOS_LOWORD(d) ((sal_uInt16)((sal_uInt32)(d) & 0xFFFF)) +#endif +#ifndef VOS_HIWORD +# define VOS_HIWORD(d) ((sal_uInt16)(((sal_uInt32)(d) >> 16) & 0xFFFF)) +#endif +#ifndef VOS_MAKEWORD +# define VOS_MAKEWORD(bl, bh) ((sal_uInt16)((bl) & 0xFF) | (((sal_uInt16)(bh) & 0xFF) << 8)) +#endif +#ifndef VOS_LOBYTE +# define VOS_LOBYTE(w) ((sal_uInt8)((sal_uInt16)(w) & 0xFF)) +#endif +#ifndef VOS_HIBYTE +# define VOS_HIBYTE(w) ((sal_uInt8)(((sal_uInt16)(w) >> 8) & 0xFF)) +#endif +#ifndef VOS_MAKEBYTE +# define VOS_MAKEBYTE(nl, nh) ((sal_uInt8)(((nl) & 0x0F) | (((nh) & 0x0F) << 4))) +#endif +#ifndef VOS_LONIBBLE +# define VOS_LONIBBLE(b) ((sal_uInt8)((b) & 0x0F)) +#endif +#ifndef VOS_HINIBBLE +# define VOS_HINIBBLE(b) ((sal_uInt8)(((b) >> 4) & 0x0F)) +#endif + +#ifndef VOS_SWAPWORD +# define VOS_SWAPWORD(w) VOS_MAKEWORD(VOS_HIBYTE(w),VOS_LOBYTE(w)) +#endif +#ifndef VOS_SWAPDWORD +# define VOS_SWAPDWORD(d) VOS_MAKEDWORD(VOS_SWAPWORD(VOS_HIWORD(d)),VOS_SWAPWORD(VOS_LOWORD(d))) +#endif + +#ifdef OSL_BIGENDIAN +#ifndef VOS_NETWORD +# define VOS_NETWORD(w) (sal_uInt16)(w) +#endif +#ifndef VOS_NETDWORD +# define VOS_NETDWORD(d) (sal_uInt32)(d) +#endif +#else // OSL_LITENDIAN +#ifndef VOS_NETWORD +# define VOS_NETWORD(w) VOS_MAKEWORD(VOS_HIBYTE(w),VOS_LOBYTE(w)) +#endif +#ifndef VOS_NETDWORD +# define VOS_NETDWORD(d) VOS_MAKEDWORD(VOS_NETWORD(VOS_HIWORD(d)),VOS_NETWORD(VOS_LOWORD(d))) +#endif +#endif // OSL_BIGENDIAN + +#ifdef _OSL_MEMSEG +# define VOS_MAKEPTR(base, off) ((void _far *)VOS_MAKEDWORD((off), (base))) +# define VOS_BASEOF(ptr) VOS_HIWORD(ptr) +# define VOS_OFSTOF(ptr) VOS_LOWORD(ptr) +#else +# define VOS_MAKEPTR(base, off) ((void *)((base) + (off))) +# define VOS_BASEOF(ptr) (ptr) +# define VOS_OFSTOF(ptr) 0 +#endif + +#ifndef VOS_FIELDOFFSET +# define VOS_FIELDOFFSET(type, field) ((sal_Int32)(&((type *)1)->field) - 1) +#endif + +// def. for arbitrary namespace +#ifdef _USE_NAMESPACE +# define VOS_NAMESPACE(class_name, name_space) name_space::class_name +#else +# define VOS_NAMESPACE(class_name, name_space) class_name +#endif + +// sal_Int16 def. for namespace vos +#ifdef _USE_NAMESPACE +# define NAMESPACE_VOS(class_name) vos::class_name +#else +# define NAMESPACE_VOS(class_name) class_name +#endif + +// sal_Int16 def. for namespace std +#ifdef _USE_NAMESPACE +# define NAMESPACE_STD(class_name) std::class_name +#else +# define NAMESPACE_STD(class_name) class_name +#endif + +#endif //_VOS_MACROS_HXX_ + diff --git a/vos/inc/vos/module.hxx b/vos/inc/vos/module.hxx new file mode 100644 index 000000000000..a3e793cf87e4 --- /dev/null +++ b/vos/inc/vos/module.hxx @@ -0,0 +1,123 @@ +/************************************************************************* + * + * $RCSfile: module.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:12 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _VOS_MODULE_HXX_ +#define _VOS_MODULE_HXX_ + +#ifndef _VOS_OBJECT_HXX_ +# include <vos/object.hxx> +#endif +#ifndef _RTL_USTRING_ +# include <rtl/ustring> +#endif +#ifndef _OSL_MODULE_H_ +# include <osl/module.h> +#endif + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + +class OModule : public OObject +{ + VOS_DECLARE_CLASSINFO(VOS_NAMESPACE(OModule, vos)); + +public: + + /// default c'tor + OModule(); + + /// this c'tor is a combination of the default c'tor and load() + OModule(const NAMESPACE_RTL(OUString)& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT); + virtual ~OModule(); + + /// loads the specified module + sal_Bool SAL_CALL load(const NAMESPACE_RTL(OUString)& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT); + + /// unloads the currently loaded module + void SAL_CALL unload(); + + /// returns sal_True, if a module is loaded, sal_False otherwise + sal_Bool SAL_CALL isLoaded(); + +#if 0 + // not implemented yet + // returns the name of the currently loaded module or an empty string if none. + NAMESPACE_RTL(OUString) SAL_CALL getModuleName(); +#endif + + /// returns a pointer to the specified Symbol if found, NULL otherwise + void* SAL_CALL getSymbol(const NAMESPACE_RTL(OUString)& strSymbolName); + +protected: + + oslModule m_Module; +}; + +#ifdef _USE_NAMESPACE +} +#endif + +#endif + + diff --git a/vos/inc/vos/mutex.hxx b/vos/inc/vos/mutex.hxx new file mode 100644 index 000000000000..c4ebe6036335 --- /dev/null +++ b/vos/inc/vos/mutex.hxx @@ -0,0 +1,224 @@ +/************************************************************************* + * + * $RCSfile: mutex.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:12 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VOS_MUTEX_HXX_ +#define _VOS_MUTEX_HXX_ + +#ifndef _VOS_TYPES_HXX_ +# include <vos/types.hxx> +#endif +#ifndef _VOS_OBJECT_HXX_ +# include <vos/object.hxx> +#endif +#ifndef _OSL_MUTEX_H_ +# include <osl/mutex.h> +#endif + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + + +/** IMutex interface + + @author Bernd Hofner + @version 1.0 +*/ + +class IMutex +{ +public: + + /// Blocks if Mutex is already in use + virtual void SAL_CALL acquire()= 0; + + // Tries to get the mutex without blocking. + virtual sal_Bool SAL_CALL tryToAcquire()= 0; + + /// releases the mutex. + virtual void SAL_CALL release()= 0; + +protected: + IMutex() { } + virtual ~IMutex() { } + +}; + +// ---------------------------------------------------------- + +/** OMutex + + @author Bernd Hofner + @version 1.0 +*/ + +class OMutex : public OObject, public IMutex +{ + VOS_DECLARE_CLASSINFO(VOS_NAMESPACE(OMutex, vos)); + +public: + static IMutex& SAL_CALL getGlobalMutex(); + + /// Creates mutex + OMutex(); + /// Implicitly destroys mutex + virtual ~OMutex(); + + /// Blocks if Mutex is already in use + virtual void SAL_CALL acquire(); + + /** Tries to get the mutex without blocking. + @return True if mutex could be obtained, otherwise False + */ + virtual sal_Bool SAL_CALL tryToAcquire(); + + /// releases the mutex. + virtual void SAL_CALL release(); + +protected: + oslMutex m_Impl; + +private: + // disable copy/assignment + OMutex(const OMutex&); + OMutex& SAL_CALL operator= (const OMutex&); +}; + +// ********************************************************************************* + +/** OGuard + + @author Bernd Hofner + @version 1.0 +*/ + +class OGuard +{ +public: + /** Acquires mutex + @param pMutex pointer to mutex which is to be acquired */ + OGuard(IMutex* pMutex) + : m_rMutex( *pMutex ) + { // only for compatible reasons + m_rMutex.acquire(); + } + OGuard(IMutex & rMutex) + : m_rMutex( rMutex ) + { + m_rMutex.acquire(); + } + + /** Releases mutex. */ + virtual ~OGuard() + { + m_rMutex.release(); + } + +protected: + IMutex& m_rMutex; +}; + +/** A guard that can release the mutex with the clear method. + + @author Bernd Hofner + @version 1.0 +*/ +class OClearableGuard +{ +public: + /** Acquires mutex + @param pMutex pointer to mutex which is to be acquired */ + OClearableGuard(IMutex & rMutex) + : m_pMutex( &rMutex ) + { + m_pMutex->acquire(); + } + + /** Releases mutex. */ + virtual ~OClearableGuard() + { + if( m_pMutex ) + m_pMutex->release(); + } + + /** Releases mutex. */ + void SAL_CALL clear() + { + if( m_pMutex ) + { + m_pMutex->release(); + m_pMutex = NULL; + } + } +protected: + IMutex* m_pMutex; +}; + + +#ifdef _USE_NAMESPACE +} +#endif + + +#endif //_VOS_MUTEX_HXX_ + + diff --git a/vos/inc/vos/object.hxx b/vos/inc/vos/object.hxx new file mode 100644 index 000000000000..4326bd58b72c --- /dev/null +++ b/vos/inc/vos/object.hxx @@ -0,0 +1,240 @@ +/************************************************************************* + * + * $RCSfile: object.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:12 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _VOS_OBJECT_HXX_ +#define _VOS_OBJECT_HXX_ + +#ifndef _VOS_TYPES_HXX_ +# include <vos/types.hxx> +#endif +#ifndef _VOS_MACROS_HXX_ +# include <vos/macros.hxx> +#endif + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + +// *************************************** +// Object super class + +struct OClassInfo; +struct OCreateParam; + +/** OObject + common base class for all framework classes. Used for memory-management + and runtime type-info. +*/ +class OObject +{ +public: + + /// + OObject(); + + /// + OObject(const OCreateParam& rParam); + + // Disable the copy constructor and assignment by default so you will get + // compiler errors instead of unexpected behaviour if you pass objects + // by value or assign objects. +private: + OObject(const OObject& objectSrc); // no implementation + void SAL_CALL operator=(const OObject& objectSrc); // no implementation + +public: + virtual ~OObject(); + +public: + + /** Define private new and delete operator because of compiler bug, + when allocating and deleteing a exported class + */ +#if defined MACOS || defined MACOSX + void* SAL_CALL operator new(size_t size); + void* SAL_CALL operator new(size_t size, void* p); +#else + void* SAL_CALL operator new(unsigned int size); + void* SAL_CALL operator new(unsigned int size, void* p); +#endif + + void SAL_CALL operator delete(void* p); + +// Attributes +public: + + /// + virtual const OClassInfo& SAL_CALL getClassInfo() const; + + /// + sal_Bool SAL_CALL isKindOf(const OClassInfo& rClass) const; + +// Implementation +public: + static const OClassInfo& SAL_CALL classInfo(); + +public: + static OClassInfo __ClassInfo__; +}; + + +/** + Basic class information +*/ +struct OCreateParam +{ + sal_uInt32 m_Size; + void* m_pParam; + + /// + OCreateParam(void *pParam) + { + m_Size = sizeof(OCreateParam); + m_pParam = pParam; + } +}; + +/** +*/ +struct OClassInfo +{ + /// + const sal_Char *m_pClassName; + /// + sal_Int32 m_nObjectSize; + /// schema number of the loaded class + sal_uInt32 m_wSchema; + + /// + OObject* (SAL_CALL * m_pfnCreateObject)(const OCreateParam&); // NULL => abstract class + + /// linked list of registered classes + const OClassInfo* m_pBaseClass; + /// linked list of registered classes + const OClassInfo* m_pNextClass; + + /// + OObject* SAL_CALL createObject(const OCreateParam& rParam) const; + + /// + sal_Bool SAL_CALL isDerivedFrom(const OClassInfo& rBaseClass) const; + + /// + static const OClassInfo* SAL_CALL getClassInfo(const sal_Char* pClassName); + + /// + OClassInfo(const sal_Char *pClassName, sal_Int32 ObjectSize, + const OClassInfo* pBaseClass = NULL, sal_uInt32 Schema = (sal_uInt32)-1, + OObject* (SAL_CALL * fnCreateObject)(const OCreateParam&) = NULL); +}; + +// ***************************************************************** +// Helper macros for declaring OClassInfo data + + +#define VOS_STRINGIZE(name) #name + +#define VOS_CLASSNAME(class_name, domain_name) VOS_STRINGIZE(domain_name.class_name) + +#define VOS_CLASSINFO(class_name) (class_name::classInfo()) + +// generate static object constructor for class registration +struct VOS_CLASSINIT +{ VOS_CLASSINIT(VOS_NAMESPACE(OClassInfo, vos)* pNewClass); }; + +#define VOS_CLASSDATA(class_spec, class_name, base_class_name, wSchema, constructor) \ + VOS_NAMESPACE(OClassInfo, vos) class_name::__ClassInfo__(class_spec, \ + sizeof(class_name), &VOS_CLASSINFO(base_class_name), wSchema, constructor); \ + const VOS_NAMESPACE(VOS_CLASSINIT, vos) class_name::__ClassInit__(&class_name::__ClassInfo__); \ + const VOS_NAMESPACE(OClassInfo, vos)& SAL_CALL class_name::getClassInfo() const \ + { return (VOS_CLASSINFO(class_name)); } \ + const VOS_NAMESPACE(OClassInfo, vos)& SAL_CALL class_name::classInfo() \ + { return (__ClassInfo__); } + +#define VOS_DECLARE_CLASSINFO(class_name) \ +public: \ + static const VOS_NAMESPACE(VOS_CLASSINIT, vos) __ClassInit__; \ + static VOS_NAMESPACE(OClassInfo, vos) __ClassInfo__; \ +public: \ + virtual const VOS_NAMESPACE(OClassInfo, vos)& SAL_CALL getClassInfo() const; \ + static const VOS_NAMESPACE(OClassInfo, vos)& SAL_CALL classInfo() + +#define VOS_IMPLEMENT_CLASSINFO(class_spec, class_name, base_class_name, wSchema) \ + VOS_CLASSDATA(class_spec, class_name, base_class_name, wSchema, NULL) + +#define VOS_DECLARE_CLASSTYPE(class_name) \ + VOS_DECLARE_CLASSINFO(class_name); \ +public: \ + static VOS_NAMESPACE(OObject, vos)* SAL_CALL createObject(const VOS_NAMESPACE(OCreateParam, vos)& rParam); + +#define VOS_IMPLEMENT_CLASSTYPE(class_spec, class_name, base_class_name, wSchema) \ + VOS_CLASSDATA(class_spec, class_name, base_class_name, wSchema, class_name::createObject) \ + VOS_NAMESPACE(OObject, vos)* class_name::createObject(const VOS_NAMESPACE(OCreateParam, vos)& rParam) \ + { return new class_name(rParam); } + +#ifdef _USE_NAMESPACE +} +#endif + +#endif // _VOS_OBJECT_HXX_ + diff --git a/vos/inc/vos/pipe.hxx b/vos/inc/vos/pipe.hxx new file mode 100644 index 000000000000..f79540cf4f45 --- /dev/null +++ b/vos/inc/vos/pipe.hxx @@ -0,0 +1,313 @@ +/************************************************************************* + * + * $RCSfile: pipe.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:12 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _VOS_PIPE_HXX_ +#define _VOS_PIPE_HXX_ + +#ifndef _OSL_PIPE_H_ +# include <osl/pipe.h> +#endif +#ifndef _VOS_TYPES_HXX_ +# include <vos/types.hxx> +#endif +#ifndef _VOS_OBJECT_HXX_ +# include <vos/object.hxx> +#endif +#ifndef _VOS_ISTREAM_HXX_ +# include <vos/istream.hxx> +#endif +#ifndef _VOS_REFERMCE_HXX_ +# include <vos/refernce.hxx> +#endif +#ifndef _VOS_REFOBJ_HXX_ +# include <vos/refobj.hxx> +#endif +#ifndef _VOS_SECURITY_HXX_ +# include <vos/security.hxx> +#endif +#ifndef _RTL_USTRING_ +# include <rtl/ustring> +#endif + + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + + +class OStreamPipe; + +/** Represents a pipe. +*/ +class OPipe : public NAMESPACE_VOS(OReference), + public NAMESPACE_VOS(OObject) +{ + VOS_DECLARE_CLASSINFO(NAMESPACE_VOS(OPipe)); + +public: + /* + Represents pipe-options + */ + enum TPipeOption { + TOption_Open = osl_Pipe_OPEN, /* open existing pipe */ + TOption_Create = osl_Pipe_CREATE /* create pipe and open it, */ + /* fails if already existst */ + }; + + enum TPipeError { + E_None = osl_Pipe_E_None, /* no error */ + E_NotFound = osl_Pipe_E_NotFound, /* Pipe could not be found */ + E_AlreadyExists = osl_Pipe_E_AlreadyExists, /* Pipe already exists */ + E_NoProtocol = osl_Pipe_E_NoProtocol, /* Protocol not available */ + E_NetworkReset = osl_Pipe_E_NetworkReset, /* Network dropped connection because of reset */ + E_ConnectionAbort = osl_Pipe_E_ConnectionAbort, /* Software caused connection abort */ + E_ConnectionReset = osl_Pipe_E_ConnectionReset, /* Connection reset by peer */ + E_NoBufferSpace = osl_Pipe_E_NoBufferSpace, /* No buffer space available */ + E_TimedOut = osl_Pipe_E_TimedOut, /* Connection timed out */ + E_ConnectionRefused = osl_Pipe_E_ConnectionRefused, /* Connection refused */ + E_invalidError = osl_Pipe_E_invalidError /* unmapped error */ + }; + +protected: + typedef ORefObj<oslPipe> PipeRef; + + PipeRef* m_pPipeRef; + +public: + + /** Does not create a pipe. Use assignment operator to + make this a useable pipe. + */ + OPipe(); + + /** Creates a pipe. + @param strName + @param Options + */ + OPipe(const NAMESPACE_RTL(OUString)& strName, TPipeOption Options = TOption_Open); + + /** Creates a pipe. + @param strName + @param Options + @param Security + */ + OPipe(const NAMESPACE_RTL(OUString)& strName, TPipeOption Options, + const NAMESPACE_VOS(OSecurity)& rSecurity); + + /** Copy constructor. + */ + OPipe(const OPipe& pipe); + + /** Creates pipe as wrapper around the underlying oslPipe. + @param Pipe + */ + OPipe(oslPipe Pipe); + + /** Destructor. Destroys the underlying oslPipe. + */ + virtual ~OPipe(); + + /** Create a pipe with the given attributes. + If socket was already created, the old one will be discarded. + @param strName + @param Options + @return True if socket was successfully created. + */ + sal_Bool SAL_CALL create(const NAMESPACE_RTL(OUString)& strName, TPipeOption Options = TOption_Open); + + /** Create a pipe with the given attributes. + If socket was already created, the old one will be discarded. + @param strName + @param Options + @param Security + @return True if socket was successfully created. + */ + sal_Bool SAL_CALL create(const NAMESPACE_RTL(OUString)& strName, TPipeOption Options, + const NAMESPACE_VOS(OSecurity)& rSecurity); + + /** Assignment operator. If pipe was already created, the old one will + be discarded. + */ + OPipe& SAL_CALL operator= (const OPipe& pipe); + + /** Allow cast to underlying oslPipe. + */ + SAL_CALL operator oslPipe() const; + + /** Checks if the pipe is valid. + @return True if the object represents a valid pipe. + */ + sal_Bool SAL_CALL isValid() const; + + sal_Bool SAL_CALL operator==( const OPipe& rPipe ) + { + return m_pPipeRef == rPipe.m_pPipeRef; + } + + /** Closes the pipe. + */ + virtual void SAL_CALL close(); + + /** Accept connection on an existing pipe + */ + TPipeError SAL_CALL accept(OStreamPipe& Connection); + + /** Tries to receives BytesToRead data from the connected pipe, + + @param pBuffer [out] Points to a buffer that will be filled with the received + data. + @param BytesToRead [in] The number of bytes to read. pBuffer must have at least + this size. + @return the number of received bytes. + */ + sal_Int32 SAL_CALL recv(void* pBuffer, sal_uInt32 BytesToRead); + + /** Tries to sends BytesToSend data from the connected pipe. + + @param pBuffer [in] Points to a buffer that contains the send-data. + @param BytesToSend [in] The number of bytes to send. pBuffer must have at least + this size. + @return the number of transfered bytes. + */ + sal_Int32 SAL_CALL send(const void* pBuffer, sal_uInt32 BytesToSend); + + /** Delivers a constant decribing the last error for the pipe system. + @return ENONE if no error occured, invalid_PipeError if + an unknown (unmapped) error occured, otherwise an enum describing the + error. + */ + TPipeError SAL_CALL getError() const; + +}; + +/** A pipe to send or receive a stream of data. +*/ +class OStreamPipe : public NAMESPACE_VOS(OPipe), + public NAMESPACE_VOS(IStream) +{ + VOS_DECLARE_CLASSINFO(NAMESPACE_VOS(OStreamPipe)); +public: + + /** Creates an unattached pipe. You must attach the pipe to an oslPipe + e.g. by using the operator=(oslPipe), before you can use the stream- + functionality of the object. + */ + OStreamPipe(); + + /** Creates pipe as wrapper around the underlying oslPipe. + @param Pipe + */ + OStreamPipe(oslPipe Pipe); + + /** Copy constructor. + @param Pipe + */ + OStreamPipe(const OStreamPipe& Pipe); + + /** Destructor. Calls shutdown(readwrite) and close(). + */ + virtual ~OStreamPipe(); + + /** Attaches the oslPipe to this object. If the object + already was attached to an oslPipe, the old one will + be closed and destroyed. + @param Pipe. + */ + OStreamPipe& SAL_CALL operator=(oslPipe Pipe); + + /** Assignment operator + */ + OStreamPipe& SAL_CALL operator=(const OPipe& pipe); + + /** Retrieves n bytes from the stream and copies them into pBuffer. + The method avoids incomplete reads due to packet boundaries. + @param pBuffer receives the read data. + @param n the number of bytes to read. pBuffer must be large enough + to hold the n bytes! + @return the number of read bytes. The number will only be smaller than + n if an exceptional condition (e.g. connection closed) occurs. + */ + virtual sal_Int32 SAL_CALL read(void* pBuffer, sal_uInt32 n) const; + + /** Writes n bytes from pBuffer to the stream. The method avoids + incomplete writes due to packet boundaries. + @param pBuffer contains the data to be written. + @param n the number of bytes to write. + @return the number of written bytes. The number will only be smaller than + n if an exceptional condition (e.g. connection closed) occurs. + */ + virtual sal_Int32 SAL_CALL write(const void* pBuffer, sal_uInt32 n); + + /** Checks if pipe is closed. + @return True if pipe is closed. + */ + virtual sal_Bool SAL_CALL isEof() const; +}; + + +#ifdef _USE_NAMESPACE +} +#endif + +#endif // _VOS_PIPE_HXX_ + diff --git a/vos/inc/vos/process.hxx b/vos/inc/vos/process.hxx new file mode 100644 index 000000000000..81dd06211cd3 --- /dev/null +++ b/vos/inc/vos/process.hxx @@ -0,0 +1,349 @@ +/************************************************************************* + * + * $RCSfile: process.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:12 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VOS_PROCESS_HXX_ +#define _VOS_PROCESS_HXX_ + +#ifndef _RTL_USTRING_ +# include <rtl/ustring> +#endif +#ifndef _VOS_MUTEX_HXX_ +# include <vos/mutex.hxx> +#endif +#ifndef _VOS_SECURITY_HXX_ +# include <vos/security.hxx> +#endif +#ifndef _VOS_OBJECT_HXX_ +# include <vos/object.hxx> +#endif +#ifndef _VOS_SOCKET_HXX_ +# include <vos/socket.hxx> +#endif +#ifndef _OSL_PROCESS_H_ +# include <osl/process.h> +#endif + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + +class OProcess; + +/** helper class to fill a vector of command line arguments + */ +class OArgumentList +{ + sal_uInt32 n_Args; + rtl_uString** m_aVec; + +public: + + OArgumentList(); + OArgumentList( sal_uInt32 nArgs, const NAMESPACE_RTL(OUString)* aArgument1, ... ); + // switched argument list to avoid ambiguity with previous constructor. + OArgumentList( const NAMESPACE_RTL(OUString) aArgumentList[], sal_uInt32 nArgs ); + + OArgumentList( const OArgumentList& rOther); + + OArgumentList& operator=( const OArgumentList& rOther); + + virtual ~OArgumentList(); + + friend class OProcess; +}; + +/** helper class to fill a vector of environment settings + */ +class OEnvironment +{ + sal_Int32 n_Vars; + rtl_uString** m_aVec; + +public: + + OEnvironment(); + OEnvironment( sal_uInt32 nVars, const NAMESPACE_RTL(OUString)* aVariable1, ... ); + // switched argument list to avoid ambiguity with previous constructor. + OEnvironment( const NAMESPACE_RTL(OUString) aVariableList[], sal_uInt32 nVars ); + + OEnvironment( const OEnvironment& rOther ); + + OEnvironment& operator=( const OEnvironment& rOther ); + + virtual ~OEnvironment(); + + friend class OProcess; +}; + + +/** startup child processes. + @see OStartupInfo + Used for starting an monitoring child processes with special features: + <ul><li>setting enviroments, + <li>setting working directories, + <li>setting user rights and security, + <li>providing ioresources like file descriptors and sockets.</ul> +*/ +class OProcess : public OObject +{ + VOS_DECLARE_CLASSINFO(VOS_NAMESPACE(OProcess, vos)); + +public: + + /** Options for execution mode: + */ + enum TProcessOption + { + TOption_Wait = osl_Process_WAIT, // wait for completion + TOption_SearchPath = osl_Process_SEARCHPATH, // search path for executable + TOption_Detached = osl_Process_DETACHED, // run detached + TOption_Normal = osl_Process_NORMAL, // run in normal window + TOption_Hidden = osl_Process_HIDDEN, // run hidden + TOption_Minimized = osl_Process_MINIMIZED, // run in minimized window + TOption_Maximized = osl_Process_MAXIMIZED, // run in maximized window + TOption_FullScreen = osl_Process_FULLSCREEN // run in fullscreen window + }; + + /** Errorcodes: + */ + enum TProcessError { + E_None = osl_Process_E_None, /* no error */ + E_NotFound = osl_Process_E_NotFound, /* image not found */ + E_TimedOut = osl_Process_E_TimedOut, /* timout occured */ + E_NoPermission = osl_Process_E_NoPermission, /* permission denied */ + E_Unknown = osl_Process_E_Unknown, /* unknown error */ + E_InvalidError = osl_Process_E_InvalidError /* unmapped error */ + }; + + enum TDescriptorFlags + { + TFlags_None = osl_Process_DFNONE, + TFlags_Wait = osl_Process_DFWAIT + }; + + enum TProcessData + { + TData_Identifier = osl_Process_IDENTIFIER, + TData_ExitCode = osl_Process_EXITCODE, + TData_CpuTimes = osl_Process_CPUTIMES, + TData_HeapUsage = osl_Process_HEAPUSAGE + }; + + struct TProcessInfo : public oslProcessInfo + { + TProcessInfo() { Size = sizeof(*this); } + }; + + typedef oslProcessIdentifier TProcessIdentifier; + + /** Creating a process object by naming the executable. + Does not yet start the process. + @see execute + */ + + OProcess( ); + + OProcess(const NAMESPACE_RTL(OUString)& strImageName); + + OProcess(const NAMESPACE_RTL(OUString)& strImageName, + const NAMESPACE_RTL(OUString)& strWorkingDirectory); + + /// destroying a process object + virtual ~OProcess(); + + SAL_CALL operator oslProcess() + { return m_Process; } + + SAL_CALL operator oslProcess() const + { return m_Process; } + + static OProcess* SAL_CALL getProcess(TProcessIdentifier Identifier); + + /** execute the given process. + This process becomes a child of the caller. + If there are any ioresources provided from the calling process, this + function returns only, if the child process calls OStartupInfo::acceptIOResource(). + @param Options [in] describes the execution mode. + @return only not eNONE, if too much enviroments are added. + @see OStartupInfo::acceptIOResource + */ + TProcessError SAL_CALL execute(TProcessOption Options, + const OArgumentList& aArgumentList = OArgumentList(), + const OEnvironment& aEnvironment = OEnvironment() + ); + + /** execute the given process with the specified security. + This process becomes a child of the caller. + The process is executed with the rights of the user, for whom the security object is created. + If there are any ioresources provided from the calling process, this + function returns only, if the child process calls OStartupInfo::acceptIOResource(). + @param Options [in] describes the execution mode. + @param Security [in] is a given security object for one logged in user. + @return eNONE, if the proccess could be executed, otherwise an errorcode. + @see OStartupInfo::acceptIOResource + */ + TProcessError SAL_CALL execute(TProcessOption Options, + const OSecurity &Security, + const OArgumentList& aArgumentList = OArgumentList(), + const OEnvironment& aEnvironment = OEnvironment() + ); + + TProcessError SAL_CALL terminate(); + + TProcessError SAL_CALL getInfo(TProcessData Data, TProcessInfo* pInfo) const; + + static TProcessError SAL_CALL getCurrentInfo(TProcessData Data, TProcessInfo* pInfo); + + /** wait for the completation of this child process + @return eNONE if child process exits, otherwise nothing. + */ + TProcessError SAL_CALL join(); + + /** provide a socket as ioresource for the child process. + The child has to call OStartUpInfo::acceptIOResources() if any + ioresources are provided by calling this method, otherwise execute() + will not return. + This method should only be called before execute(). + @see OStartupInfo::acceptIOResource + */ + void SAL_CALL provideIOResource(oslSocket Socket, TDescriptorFlags Flags = TFlags_Wait); + +protected: + const NAMESPACE_RTL(OUString) m_strImageName; + const NAMESPACE_RTL(OUString) m_strDirectory; + + oslIOResource* m_IoResources; + sal_Int32 m_NoResources; + oslProcess m_Process; +}; + +/** informations for client processes provided by the parent. + @see OProcess +*/ + + +class OStartupInfo : public OObject +{ + VOS_DECLARE_CLASSINFO(VOS_NAMESPACE(OStartupInfo, vos)); + +public: + /** Errorcodes: + */ + enum TStartupError { + E_None = osl_Process_E_None, /* no error */ + E_NotFound = osl_Process_E_NotFound, /* image not found */ + E_TimedOut = osl_Process_E_TimedOut, /* timout occured */ + E_NoPermission = osl_Process_E_NoPermission, /* permission denied */ + E_Unknown = osl_Process_E_Unknown, /* unknown error */ + E_InvalidError = osl_Process_E_InvalidError /* unmapped error */ + }; + + /** Constructor. + */ + OStartupInfo(); + + /** Destructor + */ + ~OStartupInfo(); + + /** get one ioresource from the parent process. + The recieved socket has been opened by the parent process and will be + duplicated for the calling process, wich has full read-write access to + this socket. + @param rSocket [out] returns the recieved socket. + @return True, if the parent process provides resources for the caller, otherwise no return. + @see OProcess::provideIOResource + */ + sal_Bool SAL_CALL acceptIOResource(OSocket& rSocket); + + /** @return the number of command line arguments. + */ + sal_uInt32 SAL_CALL getCommandArgCount(); + + /** get the nArg-th command argument passed to the main-function of this process. + @param nArg [in] the number of arguments to return. + @param strCommandArg [out] the string that receives the argument. + @return eNONE + */ + TStartupError SAL_CALL getCommandArg(sal_uInt32 nArg, NAMESPACE_RTL(OUString)& strCommandArg); + + TStartupError SAL_CALL getExecutableFile(NAMESPACE_RTL(OUString)& strImageName); + + /** Get the value of one enviroment variable. + @param Name [in] denotes the name of the variable to get. + @param Buffer [out] is the buffer where the value of this variable is returned. + @param Max [in] is the size of this buffer. + @return eNONE, if the variable exist in the enviroment, otherwise False. + */ + TStartupError SAL_CALL getEnvironment(const NAMESPACE_RTL(OUString)& strVar, NAMESPACE_RTL(OUString)& strValue); + +protected: + oslIOResource* m_IoResources; + sal_Int32 m_NoResources; +}; + +#ifdef _USE_NAMESPACE +} +#endif + +#endif // _VOS_PROCESS_HXX_ + diff --git a/vos/inc/vos/ref.hxx b/vos/inc/vos/ref.hxx new file mode 100644 index 000000000000..70409932325b --- /dev/null +++ b/vos/inc/vos/ref.hxx @@ -0,0 +1,223 @@ +/************************************************************************* + * + * $RCSfile: ref.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:12 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _VOS_REF_HXX_ +#define _VOS_REF_HXX_ + +/** + ORef<T> + + template type to implement handle/body behaviour + with reference-counting. + + Note that the template-type T MUST implement IReferenceCounter. + +*/ + +#ifndef _VOS_REFERNCE_HXX_ +# include <vos/refernce.hxx> +#endif +#ifndef _VOS_DIAGNOSE_HXX_ +# include <vos/diagnose.hxx> +#endif + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + + +template <class T> +class ORef +{ +public: + + /** Creates an "empty" reference, use "create()" or + assignment/copy-operator to make it a valid reference. + */ + ORef(); + + /** Creates a reference which points to pBody. + pBodys reference is not changed!. (like create(...)). + */ + ORef(T* pBody); + + /** Overload copy-constr. to implement ref-counting. + As a result of the following code: + + ORef<x> h1, h2; + + h1.create(); + h2= h1; + + h1 and h2 will represent the same body. + + */ + ORef(const ORef<T>& handle); + + /** Decreases ref-count of underlying body. + */ + inline ~ORef(); + + /** Overload assignment-operator to implement ref-counting. + Unbinds this instance from its body (if bound) and + bind it to the body represented by the handle. + */ + ORef<T>& SAL_CALL operator= (const ORef<T>& handle); + + + + /** Binds the body to this handle. + The "pBody"s reference-count is increased. + + If you call bind() on an existing body, + the old body is unbound before the new one is + assigned. + + */ + void SAL_CALL bind(T* pBody); + + /** Unbind the body from this handle. + Note that for a handle representing a large body, + "handle.unbind().bind(new body());" _might_ + perform a little bit better than "handle.bind(new body());", + since in the second case two large objects exist in memory + (the old body and the new body). + */ + ORef<T>& SAL_CALL unbind(); + + /** Same as bind(). + */ + void SAL_CALL operator= (T* pBody); + + /** Just in case you want to call handle().someBodyOp()... + */ + T& SAL_CALL operator() () const; + + /** Allows (*handle).someBodyOp(). + */ + T& SAL_CALL operator* () const; + + /** Probably most common used: handle->someBodyOp(). + */ + T* SAL_CALL operator->() const; + + /** Gives access to the handles body. + */ + T& SAL_CALL getBody() const; + + /** Can be used instead of operator->. + I.e. handle->someBodyOp() and handle.getBodyPtr()->someBodyOp() + are the same. + */ + T* SAL_CALL getBodyPtr() const; + + /** Returns True is the body is empty (the handle + does not point to a valid body). + */ + sal_Bool SAL_CALL isEmpty() const; + + /** Returns True is the body is "full" (the handle + does point to a valid body). + */ + sal_Bool SAL_CALL isValid() const; + + /** Returns True is handle points to the same body. + */ + sal_Bool SAL_CALL isEqualBody(const ORef<T>& handle) const; + + /** Delegates comparison to the body. + */ + sal_Bool SAL_CALL operator== (const ORef<T>& handle) const; + + /** Delegates comparison to the body. + */ + sal_Bool SAL_CALL operator!= (const ORef<T>& handle) const; + + /** Returns True is "this" points to pBody. + */ + sal_Bool SAL_CALL operator== (const T* pBody) const; + + /** Needed to place ORefs into STL collection. + Delegates comparison to the body. + */ + sal_Bool SAL_CALL operator< (const ORef<T>& handle) const; + + /** Needed to place ORefs into STL collection. + Delegates comparison to the body. + */ + sal_Bool SAL_CALL operator> (const ORef<T>& handle) const; + +protected: + + T* m_refBody; +}; + +// include template implementation +#include <vos/ref.inl> + +#ifdef _USE_NAMESPACE +} +#endif + + +#endif // _VOS_REF_HXX_ diff --git a/vos/inc/vos/ref.inl b/vos/inc/vos/ref.inl new file mode 100644 index 000000000000..d289e3acd0f7 --- /dev/null +++ b/vos/inc/vos/ref.inl @@ -0,0 +1,226 @@ +/************************************************************************* + * + * $RCSfile: ref.inl,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:12 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRUNTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRUNTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#if (defined(OS2) && defined(ICC)) +#define CAST_TO_IREFERENCE(p) ((IReference*)(p)) +#else +#define CAST_TO_IREFERENCE(p) (p) +#endif + +template <class T> +inline ORef<T>::ORef() +{ + m_refBody= 0; +} + +template <class T> +inline ORef<T>::ORef(T* pBody) +{ + m_refBody= pBody; + + if (m_refBody) + CAST_TO_IREFERENCE(m_refBody)->acquire(); +} + +template <class T> +inline ORef<T>::ORef(const ORef<T>& handle) +{ + m_refBody= handle.m_refBody; + + if (m_refBody) + CAST_TO_IREFERENCE(m_refBody)->acquire(); +} + +template <class T> +inline ORef<T>::~ORef() +{ + if (m_refBody) + CAST_TO_IREFERENCE(m_refBody)->release(); +} + +template <class T> +inline ORef<T>& ORef<T>::operator= (const ORef<T>& handle) +{ + if (m_refBody) + CAST_TO_IREFERENCE(m_refBody)->release(); + + m_refBody= handle.m_refBody; + + if (m_refBody) + CAST_TO_IREFERENCE(m_refBody)->acquire(); + + return *this; +} + +template <class T> +inline void ORef<T>::bind(T* pBody) +{ + if (m_refBody) + CAST_TO_IREFERENCE(m_refBody)->release(); + + m_refBody= pBody; + + if (m_refBody) + CAST_TO_IREFERENCE(m_refBody)->acquire(); +} + +template <class T> +inline ORef<T>& ORef<T>::unbind() +{ + if (m_refBody) + { + CAST_TO_IREFERENCE(m_refBody)->release(); + m_refBody = 0; + } + return *this; +} + +template <class T> +inline void ORef<T>::operator= (T* pBody) +{ + bind(pBody); +} + +template <class T> +inline T& ORef<T>::operator() () const +{ + VOS_PRECOND(m_refBody, "ORef::operator(): can't deref nil body!"); + return *m_refBody; +} + +template <class T> +inline T& ORef<T>::operator* () const +{ + VOS_PRECOND(m_refBody, "ORef::operator*: can't deref nil body!"); + return *m_refBody; +} + +template <class T> +inline T* ORef<T>::operator->() const +{ + VOS_PRECOND(m_refBody, "ORef::operator->: nil body!"); + return m_refBody; +} + +template <class T> +inline T& ORef<T>::getBody() const +{ + VOS_PRECOND(m_refBody, "ORef::getBody(): can't deref nil body!"); + return *m_refBody; +} + +template <class T> +inline T* ORef<T>::getBodyPtr() const +{ + // might be nil + return m_refBody; +} + +template <class T> +inline sal_Bool ORef<T>::isEmpty() const +{ + return m_refBody == 0; +} + +template <class T> +inline sal_Bool ORef<T>::isValid() const +{ + return m_refBody != 0; +} + +template <class T> +inline sal_Bool ORef<T>::isEqualBody(const ORef<T>& handle) const +{ + return m_refBody == handle.m_refBody; +} + +template <class T> +inline sal_Bool ORef<T>::operator== (const ORef<T>& handle) const +{ + return m_refBody == handle.m_refBody; +} + +template <class T> +inline sal_Bool ORef<T>::operator!= (const ORef<T>& handle) const +{ + return m_refBody != handle.m_refBody; +} + +template <class T> +inline sal_Bool ORef<T>::operator== (const T* pBody) const +{ + return m_refBody == pBody; +} + +template <class T> +inline sal_Bool ORef<T>::operator< (const ORef<T>& handle) const +{ + return m_refBody < handle.m_refBody; +} + +template <class T> +inline sal_Bool ORef<T>::operator> (const ORef<T>& handle) const +{ + return m_refBody > handle.m_refBody; +} + + diff --git a/vos/inc/vos/refernce.hxx b/vos/inc/vos/refernce.hxx new file mode 100644 index 000000000000..9d66e6b65594 --- /dev/null +++ b/vos/inc/vos/refernce.hxx @@ -0,0 +1,153 @@ +/************************************************************************* + * + * $RCSfile: refernce.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VOS_REFERNCE_HXX_ +#define _VOS_REFERNCE_HXX_ + +#ifndef _VOS_TYPES_HXX_ +# include <vos/types.hxx> +#endif +#ifndef _OSL_INTERLCK_H_ +# include <osl/interlck.h> +#endif +#ifndef _VOS_OBJECT_HXX_ +# include <vos/object.hxx> +#endif + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + +/** Interface for refernce-counting +*/ +class IReference +{ +public: + + IReference() { } + virtual ~IReference() { } + + typedef oslInterlockedCount RefCount; + + virtual RefCount SAL_CALL acquire()=0; + virtual RefCount SAL_CALL release()=0; + + virtual RefCount SAL_CALL referenced() const=0; +}; + +class ORefCount +{ +public: + typedef IReference::RefCount RefCount; + + ORefCount() { m_RefCount = 0; } + ORefCount(RefCount n) { m_RefCount = n; } + virtual ~ORefCount(); + + RefCount SAL_CALL acquire() { return (osl_incrementInterlockedCount(&m_RefCount)); }; + RefCount SAL_CALL release() { return (osl_decrementInterlockedCount(&m_RefCount)); }; + + RefCount SAL_CALL operator++() { return acquire(); } + // don't implement the postfix operator, it won't function this way! + + RefCount SAL_CALL operator--() { return release(); } + // don't implement the postfix operator, it won't function this way! + + RefCount SAL_CALL referenced() const + { return (m_RefCount); } + +protected: + RefCount m_RefCount; + +private: + // disable copy/assignment + ORefCount(const ORefCount&); + ORefCount& SAL_CALL operator= (const ORefCount&); +}; + +class OReference : public NAMESPACE_VOS(IReference) +{ +public: + OReference(); + virtual ~OReference(); + + virtual RefCount SAL_CALL acquire(); + virtual RefCount SAL_CALL release(); + + virtual RefCount SAL_CALL referenced() const + { return (m_RefCount.referenced()); } + +protected: + ORefCount m_RefCount; + +private: + // disable copy/assignment + OReference(const OReference&); + OReference& SAL_CALL operator= (const OReference&); +}; + +#ifdef _USE_NAMESPACE +} +#endif + +#endif // _VOS_REFERNCE_HXX_ + diff --git a/vos/inc/vos/refobj.hxx b/vos/inc/vos/refobj.hxx new file mode 100644 index 000000000000..748dff4d93f4 --- /dev/null +++ b/vos/inc/vos/refobj.hxx @@ -0,0 +1,129 @@ +/************************************************************************* + * + * $RCSfile: refobj.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _VOS_REFOBJ_HXX_ +#define _VOS_REFOBJ_HXX_ + +/** + ORefObj<T> + + template type to implement handle/body behaviour + with reference-counting. +*/ + +#ifndef _VOS_REFERNCE_HXX_ +# include <vos/refernce.hxx> +#endif +#ifndef _VOS_DIAGNOSE_HXX_ +# include <vos/diagnose.hxx> +#endif + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + +template <class T> +class ORefObj : public IReference +{ +public: + ORefObj(const T& Obj); + + inline ~ORefObj(); + + virtual RefCount SAL_CALL acquire() + { return (m_RefCount.acquire()); } + virtual RefCount SAL_CALL release() + { return (m_RefCount.release()); } + virtual RefCount SAL_CALL referenced() const + { return (m_RefCount.referenced()); } + + T& SAL_CALL operator=(const T& Obj); + + SAL_CALL operator T&(); + SAL_CALL operator const T&() const; + + T& SAL_CALL operator() (); + const T& SAL_CALL operator() () const; + + const T& SAL_CALL getObj() const; + T& SAL_CALL getObj(); + +protected: + T m_Obj; + ORefCount m_RefCount; + +private: + ORefObj(const ORefObj<T>& handle); + ORefObj<T>& SAL_CALL operator= (const ORefObj<T>& handle); +}; + +// include template implementation +#include <vos/refobj.inl> + +#ifdef _USE_NAMESPACE +} +#endif + + +#endif // _VOS_REF_HXX_ + diff --git a/vos/inc/vos/refobj.inl b/vos/inc/vos/refobj.inl new file mode 100644 index 000000000000..ec3796a0cc2e --- /dev/null +++ b/vos/inc/vos/refobj.inl @@ -0,0 +1,120 @@ +/************************************************************************* + * + * $RCSfile: refobj.inl,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRUNTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRUNTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +template <class T> +ORefObj<T>::ORefObj(const T& Obj) +{ + m_Obj = Obj; + + m_RefCount.acquire(); +} + +template <class T> +inline ORefObj<T>::~ORefObj() +{ + VOS_ASSERT(m_RefCount.referenced() == 0); +} + +template <class T> +inline T& ORefObj<T>::operator=(const T& Obj) +{ + m_Obj = Obj; + + return m_Obj; +} + +template <class T> +inline ORefObj<T>::operator T&() +{ + return m_Obj; +} + +template <class T> +inline ORefObj<T>::operator const T&() const +{ + return m_Obj; +} + +template <class T> +inline T& ORefObj<T>::operator() () +{ + return m_Obj; +} + +template <class T> +inline const T& ORefObj<T>::operator() () const +{ + return m_Obj; +} + +template <class T> +inline T& ORefObj<T>::getObj() +{ + return m_Obj; +} + +template <class T> +inline const T& ORefObj<T>::getObj() const +{ + return m_Obj; +} + diff --git a/vos/inc/vos/runnable.hxx b/vos/inc/vos/runnable.hxx new file mode 100644 index 000000000000..39acf50f8428 --- /dev/null +++ b/vos/inc/vos/runnable.hxx @@ -0,0 +1,109 @@ +/************************************************************************* + * + * $RCSfile: runnable.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VOS_RUNNABLE_HXX_ +#define _VOS_RUNNABLE_HXX_ + +#ifndef _VOS_TYPES_HXX_ +# include <vos/types.hxx> +#endif +#ifndef _VOS_REFERNCE_HXX_ +# include <vos/refernce.hxx> +#endif + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + + +/** IRunnable + + The IRunnable-interface is to be understood as wrapper around + your application-code, which allows it to be executed asynchronously. + + + @author Bernd Hofner + @version 0.1 +*/ + +class IRunnable +{ +public: + + IRunnable() { } + virtual ~IRunnable() { } + + + /** overload to implement your functionality. + */ + virtual void SAL_CALL run()= 0; + +}; + + +#ifdef _USE_NAMESPACE +} +#endif + + +#endif // _VOS_RUNNABLE_HXX_ + diff --git a/vos/inc/vos/security.hxx b/vos/inc/vos/security.hxx new file mode 100644 index 000000000000..c7544811255d --- /dev/null +++ b/vos/inc/vos/security.hxx @@ -0,0 +1,165 @@ +/************************************************************************* + * + * $RCSfile: security.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VOS_SECURITY_HXX_ +#define _VOS_SECURITY_HXX_ + +#ifndef _VOS_OBJECT_HXX_ +# include <vos/object.hxx> +#endif +#ifndef _RTL_USTRING_ +# include <rtl/ustring> +#endif +#ifndef _OSL_SECURITY_H_ +# include <osl/security.h> +#endif + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + +/** capsulate security informations for one user. + A object of this class is used to execute a process with the rights an + security options of a scecified user. + @see OProcess::executeProcess + @author Bernd Hofner + @version 1.0 + +*/ +class OSecurity : public OObject +{ + VOS_DECLARE_CLASSINFO(VOS_NAMESPACE(OSecurity, vos)); + +public: + /// constructor + OSecurity(); + /// destructor + virtual ~OSecurity(); + /** get the security information for one user. + The underlying operating system is asked for this information. + @param strName [in] denotes the name of the user + @param strPasswd [in] denotes the password of this user + @return True, if the specified user is known by the underlying operating system, + otherwise False + */ + sal_Bool SAL_CALL logonUser(const NAMESPACE_RTL(OUString)& strName, + const NAMESPACE_RTL(OUString)& strPasswd); + /** get the security information for one user. + This method will try to login the user at the denoted file server. + If a network resource named \\server\username exists and this resource + could be connected by this user, the methos will return true and getHomeDir + will return \\server\username. + @param strName [in] denotes the name of the user + @param strPasswd [in] denotes the password of this user + @return True, if the specified user is known by file server and the + could be connected, otherwise False + */ + sal_Bool SAL_CALL logonUser(const NAMESPACE_RTL(OUString)& strName, + const NAMESPACE_RTL(OUString)& strPasswd, + const NAMESPACE_RTL(OUString)& strFileServer); + + /** get the ident of the logged in user. + @param strName [out] is the buffer which returns the name + @param max [in] is the size of this buffer + @return True, if any user is successfuly logged in, otherwise False + */ + sal_Bool SAL_CALL getUserIdent(NAMESPACE_RTL(OUString)& strIdent) const; + + /** get the name of the logged in user. + @param strName [out] is the buffer which returns the name + @param max [in] is the size of this buffer + @return True, if any user is successfuly logged in, otherwise False + */ + sal_Bool SAL_CALL getUserName(NAMESPACE_RTL(OUString)& strName) const; + + /** get the home directory of the logged in user. + @param strDirectory [out] is the buffer which returns the directory name + @param max [in] is the size of this buffer + @return True, if any user is successfuly logged in, otherwise False + */ + sal_Bool SAL_CALL getHomeDir(NAMESPACE_RTL(OUString)& strDirectory) const; + + /** get the directory for configuration data of the logged in user. + @param strDirectory [out] is the buffer which returns the directory name + @param max [in] is the size of this buffer + @return True, if any user is successfuly logged in, otherwise False + */ + sal_Bool SAL_CALL getConfigDir(NAMESPACE_RTL(OUString)& strDirectory) const; + + /** Query if the user who is logged inhas administrator rigths. + @return True, if the user has administrator rights, otherwise false. + */ + sal_Bool SAL_CALL isAdministrator() const; + + virtual SAL_CALL operator oslSecurity() const; + +protected: + + oslSecurity m_oslSecurity; +}; + +#ifdef _USE_NAMESPACE +} +#endif + +#endif // _VOS_SECURITY_HXX_ + diff --git a/vos/inc/vos/signal.hxx b/vos/inc/vos/signal.hxx new file mode 100644 index 000000000000..35fe46470f5c --- /dev/null +++ b/vos/inc/vos/signal.hxx @@ -0,0 +1,152 @@ +/************************************************************************* + * + * $RCSfile: signal.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _VOS_SIGNAL_HXX_ +#define _VOS_SIGNAL_HXX_ + +#ifndef _VOS_TYPES_HXX_ +# include <vos/types.hxx> +#endif +#ifndef _VOS_OBJECT_HXX_ +# include <vos/object.hxx> +#endif +#ifndef _OSL_SIGNAL_H_ +# include <osl/signal.h> +#endif + +extern oslSignalAction SAL_CALL _OSignalHandler_Function(void* pthis, oslSignalInfo* pInfo); + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + +#if defined ( _USE_NAMESPACE ) && !defined ( WNT ) +oslSignalAction SAL_CALL _cpp_OSignalHandler_Function(void* pthis, oslSignalInfo* pInfo); +#endif + +/** OSignalHandler is an objectoriented interface for signal handlers. + + @author Ralf Hofmann + @version 1.0 +*/ + +class OSignalHandler : public NAMESPACE_VOS(OObject) +{ + VOS_DECLARE_CLASSINFO(VOS_NAMESPACE(OSignalHandler, vos)); + +public: + + enum TSignal + { + TSignal_System = osl_Signal_System, + TSignal_Terminate = osl_Signal_Terminate, + TSignal_AccessViolation = osl_Signal_AccessViolation, + TSignal_IntegerDivideByZero = osl_Signal_IntegerDivideByZero, + TSignal_FloatDivideByZero = osl_Signal_FloatDivideByZero, + TSignal_DebugBreak = osl_Signal_DebugBreak, + TSignal_SignalUser = osl_Signal_User + }; + + enum TSignalAction + { + TAction_CallNextHandler = osl_Signal_ActCallNextHdl, + TAction_Ignore = osl_Signal_ActIgnore, + TAction_AbortApplication = osl_Signal_ActAbortApp, + TAction_KillApplication = osl_Signal_ActKillApp + }; + + typedef oslSignalInfo TSignalInfo; + + /// Constructor + OSignalHandler(); + + /// Destructor kills thread if neccessary + virtual ~OSignalHandler(); + + static TSignalAction SAL_CALL raise(sal_Int32 Signal, void *pData = 0); + +protected: + + /// Working method which should be overridden. + virtual TSignalAction SAL_CALL signal(TSignalInfo *pInfo) = 0; + +protected: + oslSignalHandler m_hHandler; + +#if defined ( _USE_NAMESPACE ) && defined ( WNT ) + friend oslSignalAction SAL_CALL ::_OSignalHandler_Function(void* pthis, oslSignalInfo* pInfo); +#elif defined ( _USE_NAMESPACE ) + friend oslSignalAction SAL_CALL _cpp_OSignalHandler_Function(void* pthis, oslSignalInfo* pInfo); +#else + friend oslSignalAction SAL_CALL _OSignalHandler_Function(void* pthis, oslSignalInfo* pInfo); +#endif + + +}; + +#ifdef _USE_NAMESPACE +} +#endif + +#endif // _VOS_SIGNAL_HXX_ + diff --git a/vos/inc/vos/socket.hxx b/vos/inc/vos/socket.hxx new file mode 100644 index 000000000000..250666e6046b --- /dev/null +++ b/vos/inc/vos/socket.hxx @@ -0,0 +1,1178 @@ +/************************************************************************* + * + * $RCSfile: socket.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VOS_SOCKET_HXX_ +#define _VOS_SOCKET_HXX_ + +#ifndef _VOS_TYPES_HXX_ +# include <vos/types.hxx> +#endif +#ifndef _VOS_OBJECT_HXX_ +# include <vos/object.hxx> +#endif +#ifndef _VOS_ISTREAM_HXX_ +# include <vos/istream.hxx> +#endif +#ifndef _VOS_REFERMCE_HXX_ +# include <vos/refernce.hxx> +#endif +#ifndef _VOS_REFOBJ_HXX_ +# include <vos/refobj.hxx> +#endif +#ifndef _RTL_USTRING_ +# include <rtl/ustring> +#endif +#ifndef _OSL_SOCKET_H_ +# include <osl/socket.h> +#endif + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + +/** Base data types +*/ +class ISocketTypes +{ +public: + + ISocketTypes() { } + virtual ~ISocketTypes() { } + + /* + Represents the address-family of a socket + */ + enum TAddrFamily { + TFamily_Inet = osl_Socket_FamilyInet, /* IP */ + TFamily_Ipx = osl_Socket_FamilyIpx, /* Novell IPX/SPX */ + TFamily_Invalid = osl_Socket_FamilyInvalid + }; + + /* + represent a specific protocol within a address-family + */ + enum TProtocol { + TProtocol_Ip = osl_Socket_ProtocolIp, /* for all af_inet */ + TProtocol_Ipx = osl_Socket_ProtocolIpx, /* af_ipx datagram sockets (IPX) */ + TProtocol_Spx = osl_Socket_ProtocolSpx, /* af_ipx seqpacket or stream for SPX */ + TProtocol_SpxII = osl_Socket_ProtocolSpxII, /* af_ipx seqpacket or stream for SPX II */ + TProtocol_Invalid = osl_Socket_ProtocolInvalid + }; + + /* + Represents the type of a socket + */ + enum TSocketType { + TType_Stream = osl_Socket_TypeStream, + TType_Dgram = osl_Socket_TypeDgram, + TType_Raw = osl_Socket_TypeRaw, + TType_Rdm = osl_Socket_TypeRdm, + TType_SeqPacket = osl_Socket_TypeSeqPacket, + TType_Invalid = osl_Socket_TypeInvalid + }; + + /* + Represents socket-options + */ + enum TSocketOption { + TOption_Debug = osl_Socket_OptionDebug, + TOption_AcceptConn = osl_Socket_OptionAcceptConn, + TOption_ReuseAddr = osl_Socket_OptionReuseAddr, + TOption_KeepAlive = osl_Socket_OptionKeepAlive, + TOption_DontRoute = osl_Socket_OptionDontRoute, + TOption_Broadcast = osl_Socket_OptionBroadcast, + TOption_UseLoopback = osl_Socket_OptionUseLoopback, + TOption_Linger = osl_Socket_OptionLinger, + TOption_OOBinLine = osl_Socket_OptionOOBinLine, + TOption_SndBuf = osl_Socket_OptionSndBuf, + TOption_RcvBuf = osl_Socket_OptionRcvBuf, + TOption_SndLowat = osl_Socket_OptionSndLowat, + TOption_RcvLowat = osl_Socket_OptionRcvLowat, + TOption_SndTimeo = osl_Socket_OptionSndTimeo, + TOption_RcvTimeo = osl_Socket_OptionRcvTimeo, + TOption_Error = osl_Socket_OptionError, + TOption_Type = osl_Socket_OptionType, + TOption_TcpNoDelay = osl_Socket_OptionTcpNoDelay, + TOption_Invalid = osl_Socket_OptionInvalid + }; + + /* + Represents the different socket-option levels + */ + enum TSocketOptionLevel { + TLevel_Socket = osl_Socket_LevelSocket, + TLevel_Tcp = osl_Socket_LevelTcp, + TLevel_Invalid = osl_Socket_LevelInvalid + }; + + /* + Represents flags to be used with send/recv-calls. + */ + enum TSocketMsgFlag { + TMsg_Normal = osl_Socket_MsgNormal, + TMsg_OOB = osl_Socket_MsgOOB, + TMsg_Peek = osl_Socket_MsgPeek, + TMsg_DontRoute = osl_Socket_MsgDontRoute, + TMsg_MaxIOVLen = osl_Socket_MsgMaxIOVLen, + TMsg_Invalid = osl_Socket_MsgInvalid + }; + + /* + Used by shutdown to denote which end of the socket to "close". + */ + enum TSocketDirection { + TDirection_Read = osl_Socket_DirRead, + TDirection_Write = osl_Socket_DirWrite, + TDirection_ReadWrite = osl_Socket_DirReadWrite, + TDirection_Invalid = osl_Socket_DirInvalid + }; + + enum TSocketError { + E_None = osl_Socket_E_None, /* no error */ + E_NotSocket = osl_Socket_E_NotSocket, /* Socket operation on non-socket */ + E_DestAddrReq = osl_Socket_E_DestAddrReq, /* Destination address required */ + E_MsgSize = osl_Socket_E_MsgSize, /* Message too sal_Int32 */ + E_Prototype = osl_Socket_E_Prototype, /* Protocol wrong type for socket */ + E_NoProtocol = osl_Socket_E_NoProtocol, /* Protocol not available */ + E_ProtocolNoSupport = osl_Socket_E_ProtocolNoSupport, /* Protocol not supported */ + E_TypeNoSupport = osl_Socket_E_TypeNoSupport, /* Socket type not supported */ + E_OpNotSupport = osl_Socket_E_OpNotSupport, /* Operation not supported on socket */ + E_PfNoSupport = osl_Socket_E_PfNoSupport, /* Protocol family not supported */ + E_AfNoSupport = osl_Socket_E_AfNoSupport, /* Address family not supported by */ + /* protocol family */ + E_AddrInUse = osl_Socket_E_AddrInUse, /* Address already in use */ + E_AddrNotAvail = osl_Socket_E_AddrNotAvail, /* Can't assign requested address */ + E_NetDown = osl_Socket_E_NetDown, /* Network is down */ + E_NetUnreachable = osl_Socket_E_NetUnreachable, /* Network is unreachable */ + E_NetReset = osl_Socket_E_NetReset, /* Network dropped connection because */ + /* of reset */ + E_ConnAborted = osl_Socket_E_ConnAborted, /* Software caused connection abort */ + E_ConnReset = osl_Socket_E_ConnReset, /* Connection reset by peer */ + E_NoBufferSpace = osl_Socket_E_NoBufferSpace, /* No buffer space available */ + E_IsConnected = osl_Socket_E_IsConnected, /* Socket is already connected */ + E_NotConnected = osl_Socket_E_NotConnected, /* Socket is not connected */ + E_Shutdown = osl_Socket_E_Shutdown, /* Can't send after socket shutdown */ + E_TooManyRefs = osl_Socket_E_TooManyRefs, /* Too many references: can't splice */ + E_TimedOut = osl_Socket_E_TimedOut, /* Connection timed out */ + E_ConnRefused = osl_Socket_E_ConnRefused, /* Connection refused */ + E_HostDown = osl_Socket_E_HostDown, /* Host is down */ + E_HostUnreachable = osl_Socket_E_HostUnreachable, /* No route to host */ + E_WouldBlock = osl_Socket_E_WouldBlock, /* call would block on non-blocking socket */ + E_Already = osl_Socket_E_Already, /* operation already in progress */ + E_InProgress = osl_Socket_E_InProgress, /* operation now in progress */ + + E_Invalid = osl_Socket_E_InvalidError /* unmapped error */ + }; + + enum TResult { + TResult_Ok = osl_Socket_Ok, /* successful completion */ + TResult_Error = osl_Socket_Error, /* error occured, check osl_getLastSocketError() for details */ + TResult_TimedOut = osl_Socket_TimedOut, /* blocking operation timed out */ + TResult_Interrupted = osl_Socket_Interrupted, /* blocking operation was interrupted */ + TResult_InProgress = osl_Socket_InProgress /* nonblocking operation is in progress */ + }; +}; + + +/** Base class for socket addresses. +*/ +class ISocketAddr : public NAMESPACE_VOS(ISocketTypes) +{ +public: + virtual ~ISocketAddr() { } + + + virtual TAddrFamily SAL_CALL getFamily() const= 0; + virtual TResult SAL_CALL getHostname(NAMESPACE_RTL(OUString)& strHostName) const= 0; + virtual SAL_CALL operator oslSocketAddr() const= 0; + virtual void SAL_CALL operator= (oslSocketAddr Addr)= 0; + virtual sal_Bool SAL_CALL operator== (oslSocketAddr Addr)= 0; +}; + +class OSocketAddr : public NAMESPACE_VOS(ISocketAddr), + public NAMESPACE_VOS(OObject) + +{ + VOS_DECLARE_CLASSINFO(NAMESPACE_VOS(OSocketAddr)); +public: + + /** Creates socket address of unknown type. + */ + OSocketAddr(); + + /** Copy constructor. + */ + OSocketAddr(const OSocketAddr& Addr); + + /** + */ + OSocketAddr(oslSocketAddr Addr); + + /** destroys underlying oslSocketAddress + */ + virtual ~OSocketAddr(); + + /** Queries the socket for its address family. + @return the address family of the socket. + */ + virtual TAddrFamily SAL_CALL getFamily() const; + + /** Cast Object to the underlying oslSocketAddr. + */ + virtual SAL_CALL operator oslSocketAddr() const; + + /** Converts the address to a (human readable) domain-name. + @return the hostname represented by the address. + On failure returns the empty string. + */ + virtual TResult SAL_CALL getHostname(NAMESPACE_RTL(OUString)& strHostName) const; + + /** Get the hostname for the local interface. + @return the hostname or an error. + */ + static TResult SAL_CALL getLocalHostname(NAMESPACE_RTL(OUString)& strLocalHostName); + + /** Tries to find an address for a host. + @return A new created socket-address or 0 if the name could not be found. + */ + static oslSocketAddr SAL_CALL resolveHostname(const NAMESPACE_RTL(OUString)& strHostName); + + /** Wraps itself around the osl Socket-Address. + The object assumes ownership of the Addr, it + will be destroyed by destructor(). If the socket is already attached to + an oslSocketAddr, the existing one will be destroyed. + */ + virtual void SAL_CALL operator= (oslSocketAddr Addr); + + /** Compares to Addr + */ + virtual sal_Bool SAL_CALL operator== (oslSocketAddr Addr); + + /** Makes a copy of Addr. + */ + OSocketAddr& SAL_CALL operator= (const OSocketAddr& Addr); + + +protected: + + oslSocketAddr m_SockAddr; +}; + + +/** Represents an internet-address. +*/ +class OInetSocketAddr : public NAMESPACE_VOS(OSocketAddr) +{ + VOS_DECLARE_CLASSINFO(NAMESPACE_VOS(OInetSocketAddr)); +public: + + /** Creates an empty internet-address (INADDR_ANY). + */ + OInetSocketAddr(); + + /** Wraps itself around the osl Socket-Address. + The object assumes ownership of the Addr, it + will be destroyed by ~OInetSocketAddr(). + */ + OInetSocketAddr(oslSocketAddr Addr); + + /** + Create a socket address either from a dotted decimal address + (e.g. 141.99.128.50) or a hostname (e.g. www.stardiv.de). + */ + OInetSocketAddr(const NAMESPACE_RTL(OUString)& strAddrOrHostName, sal_Int32 Port); + + /** + Copy constructor. + */ + OInetSocketAddr(const OInetSocketAddr& Addr); + + /** + */ + OInetSocketAddr(const OSocketAddr& Addr); + + + virtual ~OInetSocketAddr(); + + /** + */ + virtual void SAL_CALL operator= (oslSocketAddr Addr); + + /** + */ + virtual sal_Bool SAL_CALL operator== (oslSocketAddr Addr); + + /** + */ + OInetSocketAddr& SAL_CALL operator= (const OInetSocketAddr& Addr); + + /** + */ + OInetSocketAddr& SAL_CALL operator= (const OSocketAddr& Addr); + + /** + Tries to find the port associated with the given service/protocol- + pair (e.g. "ftp"/"tcp"). + @return the port number in host-byte order or CVOS_PORT_NONE + if no service/protocol pair could be found. + */ + static sal_Int32 SAL_CALL getServicePort(const NAMESPACE_RTL(OUString)& strServiceName, + const NAMESPACE_RTL(OUString)& strProtocolName= ::rtl::OUString::createFromAscii( "tcp" ) ); + + + /** Delivers the port number of the address. + @return the port in host-byte order or or OSL_INVALID_PORT on errors. + */ + sal_Int32 SAL_CALL getPort() const; + + /** Sets the port number of the address. + @return False if the port couldn't be set + (e.g because the address is not of family TFamily_Inet). + */ + sal_Bool SAL_CALL setPort(sal_Int32 Port); + + /** @return the dotted-address-form (141.99.128.90) of this address. + On failure returns the empty string. + */ + TResult SAL_CALL getDottedAddr(NAMESPACE_RTL(OUString)& strDottedAddr) const; + + /** Sets the host-part of the address from the dotted-address-form (141.99.128.90) + or from a hostname. + @param strDottedAddrOrHostname the address in dotted form or a hostname. + */ + sal_Bool SAL_CALL setAddr(const NAMESPACE_RTL(OUString)& strDottedAddrOrHostname); + +}; + +/** Represents an IPX/SPX address. +*/ +class OIpxSocketAddr : public NAMESPACE_VOS(OSocketAddr) +{ + VOS_DECLARE_CLASSINFO(NAMESPACE_VOS(OIpxSocketAddr)); +public: + + typedef oslSocketIpxNetNumber TIpxNetNumber; + typedef oslSocketIpxNodeNumber TIpxNodeNumber; + + /** Creates an empty ipx-address. + */ + OIpxSocketAddr(); + + /** Wraps itself around the osl Socket-Address. + The object assumes ownership of the Addr, it + will be destroyed by the destructor. + */ + OIpxSocketAddr(oslSocketAddr Addr); + + /** Create an IPX/SPX socketaddress from native parameters. + */ + OIpxSocketAddr(const NAMESPACE_RTL(OUString)& strNetNumber, + const NAMESPACE_RTL(OUString)& strNodeNumber, + sal_uInt32 SocketNumber); + + /** Copy constructor. + */ + OIpxSocketAddr(const OIpxSocketAddr& Addr); + + /** + */ + OIpxSocketAddr(const OSocketAddr& Addr); + + virtual ~OIpxSocketAddr(); + + /** + */ + virtual void SAL_CALL operator= (oslSocketAddr Addr); + + /** + */ + virtual sal_Bool SAL_CALL operator== (oslSocketAddr Addr); + + /** + */ + OIpxSocketAddr& SAL_CALL operator= (const OIpxSocketAddr& Addr); + + /** + */ + OIpxSocketAddr& SAL_CALL operator= (const OSocketAddr& Addr); + + /** + */ + TResult SAL_CALL getNetNumber(TIpxNetNumber& NetNumber) const; + + /** + */ + TResult SAL_CALL getNodeNumber(TIpxNodeNumber& NodeNumber) const; + + /** + */ + sal_uInt32 SAL_CALL getSocketNumber() const; + + /** Builds a human readable string in the format network.node:socket. + The numbers are given in hexadecimal form. + */ + void SAL_CALL getAddressString(NAMESPACE_RTL(OUString)& strAddressString) const; +}; + + +/** Represents a socket. +*/ +class OSocket : public NAMESPACE_VOS(ISocketTypes), + public NAMESPACE_VOS(OReference), + public NAMESPACE_VOS(OObject) +{ + VOS_DECLARE_CLASSINFO(NAMESPACE_VOS(OSocket)); + +protected: + typedef ORefObj<oslSocket> SockRef; + + SockRef* m_pSockRef; + + TimeValue* m_pSendTimeout; + TimeValue* m_pRecvTimeout; + +public: + + /** Does not create a socket. Use assignment operator to + make this a useable socket. + */ + OSocket(); + + /** Creates a socket. + @param Family + @param Type + @param Protocol + */ + OSocket(TSocketType Type, + TAddrFamily Family = TFamily_Inet, + TProtocol Protocol = TProtocol_Ip); + + /** Copy constructor. + */ + OSocket(const OSocket& sock); + + /** Creates socket as wrapper around the underlying oslSocket. + @param Socket + */ + OSocket(oslSocket Socket); + + /** Destructor. Destroys the underlying oslSocket. + */ + virtual ~OSocket(); + + /** Create a socket with the given attributes. + If socket was already created, the old one will be discarded. + @param Type + @param Family + @param Protocol + @return True if socket was successfully created. + */ + sal_Bool SAL_CALL create(TSocketType Type, + TAddrFamily Family = TFamily_Inet, + TProtocol Protocol = TProtocol_Ip); + + /** Assignment operator. If socket was already created, the old one will + be discarded. + */ + OSocket& SAL_CALL operator= (const OSocket& sock); + + /** Allow cast to underlying oslSocket. + */ + SAL_CALL operator oslSocket() const; + + /** Checks if the socket is valid. + @return True if the object represents a valid socket. + */ + sal_Bool SAL_CALL isValid() const; + + sal_Bool SAL_CALL operator==( const OSocket& rSocket ) + { + return m_pSockRef == rSocket.m_pSockRef; + } + + /** Closes the socket. + */ + virtual void SAL_CALL close(); + + /** Retrieves the address of the local interface of this socket. + @param Addr [out] receives the address. + */ + void SAL_CALL getLocalAddr(OSocketAddr& Addr) const; + + /** Get the local port of the socket. + @return the port number or OSL_INVALID_PORT on errors. + */ + sal_Int32 SAL_CALL getLocalPort() const; + + /** Get the hostname for the local interface. + @return the hostname or an empty string (""). + */ + TResult SAL_CALL getLocalHost(NAMESPACE_RTL(OUString)& strLocalHost) const; + + /** Retrieves the address of the remote host of this socket. + @param Addr [out] receives the address. + */ + void SAL_CALL getPeerAddr(OSocketAddr& Addr) const; + + /** Get the remote port of the socket. + @return the port number or OSL_INVALID_PORT on errors. + */ + sal_Int32 SAL_CALL getPeerPort() const; + + /** Get the hostname for the remote interface. + @return the hostname or an empty string (""). + */ + TResult SAL_CALL getPeerHost(NAMESPACE_RTL(OUString)& strPeerHost) const; + + /** Binds the socket to the specified (local) interface. + @param LocalInterface Address of the Interface + @return True if bind was successful. + */ + sal_Bool SAL_CALL bind(const OSocketAddr& LocalInterface); + + + /** Blocking send operations will unblock after the send-timeout. + @return 0 for disables timeout else timeout value. + */ + const TimeValue* SAL_CALL getSendTimeout() const + { return m_pSendTimeout; } + + /** Blocking receive operations will unblock after the send-timeout. + @return 0 for disables timeout else timeout value. + */ + const TimeValue* SAL_CALL getRecvTimeout() const + { return m_pRecvTimeout; } + + /** Blocking send operations will unblock after the send-timeout. + @param time pTimeout == 0 disables timeout. pTimeout != 0 sets timeout value. + */ + void SAL_CALL setSendTimeout(const TimeValue* pTimeout = 0); + + /** Blocking receive operations will unblock after the send-timeout. + @param time pTimeout == 0 disables timeout. pTimeout != 0 sets timeout value. + */ + void SAL_CALL setRecvTimeout(const TimeValue* pTimeout = 0); + + /** Checks if read operations will block. + You can specify a timeout-value in seconds/nanoseconds that denotes + how sal_Int32 the operation will block if the Socket is not ready. + @return True if read operations (recv, recvFrom, accept) on the Socket + will NOT block; False if it would block or if an error occured. + + @param pTimeout if 0, the operation will block without a timeout. Otherwise + the specified amout of time. + */ + sal_Bool SAL_CALL isRecvReady(const TimeValue* pTimeout = 0) const; + + /** Checks if send operations will block. + You can specify a timeout-value in seconds/nanoseconds that denotes + how sal_Int32 the operation will block if the Socket is not ready. + @return True if send operations (send, sendTo) on the Socket + will NOT block; False if it would block or if an error occured. + + @param pTimeout if 0, the operation will block without a timeout. Otherwise + the specified amout of time. + */ + sal_Bool SAL_CALL isSendReady(const TimeValue* pTimeout = 0) const; + + /** Checks if a request for out-of-band data will block. + You can specify a timeout-value in seconds/nanoseconds that denotes + how sal_Int32 the operation will block if the Socket has no pending OOB data. + + @return True if OOB-request operations (recv with appropriate flags) + on the Socket will NOT block; False if it would block or if an error occured. + + @param pTimeout if 0, the operation will block without a timeout. Otherwise + the specified amout of time. + */ + sal_Bool SAL_CALL isExceptionPending(const TimeValue* pTimeout = 0) const; + + /** Retrieves option-attributes associated with the socket. + @param Option The attribute to query. + Valid values (depending on the Level) are: + <ul> + <li> TOption_Debug + <li> TOption_AcceptConn + <li> TOption_ReuseAddr + <li> TOption_KeepAlive + <li> TOption_DontRoute + <li> TOption_Broadcast + <li> TOption_UseLoopback + <li> TOption_Linger + <li> TOption_OOBinLine + <li> TOption_SndBuf + <li> TOption_RcvBuf + <li> TOption_SndLowat + <li> TOption_RcvLowat + <li> TOption_SndTimeo + <li> TOption_RcvTimeo + <li> TOption_Error + <li> TOption_Type + <li> TOption_TcpNoDelay + </ul> + If not above mentioned otherwise, the options are only valid for + level TLevel_Socket. + + @param pBuffer The Buffer will be filled with the attribute. + + @param BufferSize The size of pBuffer. + + @param Level The option level. Valid values are: + <ul> + <li> TLevel_Socket : Socket Level + <li> TLevel_Tcp : Level of Transmission Control Protocol + </ul> + + @return The size of the attribute copied into pBuffer ot -1 if an error + occured. + */ + sal_Int32 SAL_CALL getOption(TSocketOption Option, + void* pBuffer, + sal_uInt32 BufferLen, + TSocketOptionLevel Level= TLevel_Socket) const; + + /** Sets the sockets attributes. + + @param Option denotes the option to modify. + Valid values (depending on the Level) are: + <ul> + <li> TOption_Debug + <li> TOption_AcceptConn + <li> TOption_ReuseAddr + <li> TOption_KeepAlive + <li> TOption_DontRoute + <li> TOption_Broadcast + <li> TOption_UseLoopback + <li> TOption_Linger + <li> TOption_OOBinLine + <li> TOption_SndBuf + <li> TOption_RcvBuf + <li> TOption_SndLowat + <li> TOption_RcvLowat + <li> TOption_SndTimeo + <li> TOption_RcvTimeo + <li> TOption_Error + <li> TOption_Type + <li> TOption_TcpNoDelay + </ul> + If not above mentioned otherwise, the options are only valid for + level TLevel_Socket. + + @param pBuffer Pointer to a Buffer which contains the attribute-value. + + @param BufferSize contains the length of the Buffer. + + @param Level selects the level for which an option should be changed. + Valid values are: + <ul> + <li> TLevel_Socket : Socket Level + <li> TLevel_Tcp : Level of Transmission Control Protocol + </ul> + + @return True if the option could be changed. + */ + sal_Bool SAL_CALL setOption(TSocketOption Option, + void* pBuffer, + sal_uInt32 BufferLen, + TSocketOptionLevel Level= TLevel_Socket) const; + + + /** Enables/disables non-blocking mode of the socket. + @param On If True, non-blocking mode will be switched on, if False + socket will become a blocking socket, which is the default behaviour of a + socket. + @return True if mode could be set. + */ + sal_Bool SAL_CALL enableNonBlockingMode(sal_Bool On= sal_True); + + /** Query non-blocking mode of the socket. + @return True if non-blocking mode is set. + */ + sal_Bool SAL_CALL isNonBlockingMode() const; + + /** Queries the socket for its type. + @return one of: + <ul> + <li> TType_Stream + <li> TType_Dgram + <li> TType_Raw + <li> TType_Rdm + <li> TType_SeqPacket + <li> TType_Invalid + </ul> + */ + TSocketType SAL_CALL getType() const; + + + /** Gets and clears the error status of the socket. + @returns the current error state. + */ + sal_Int32 SAL_CALL clearError() const; + + /** Enables/Disables debugging. + @param opt 1 sets, 0 resets, -1 won't change anything + @return the previous setting + */ + sal_Int32 SAL_CALL setDebug(sal_Int32 opt = -1) const; + + /** Allow the socket to be bound to an address that is already in use. + @param opt 1 sets, 0 resets, -1 won't change anything + @return the previous setting + */ + sal_Int32 SAL_CALL setReuseAddr(sal_Int32 opt = -1) const; + + /** Send keepalive-packets. + @param opt 1 sets, 0 resets, -1 won't change anything + @return the previous setting + */ + sal_Int32 SAL_CALL setKeepAlive(sal_Int32 opt = -1) const; + + /** Do not route: send directly to interface. + @param opt 1 sets, 0 resets, -1 won't change anything + @return the previous setting + */ + sal_Int32 SAL_CALL setDontRoute(sal_Int32 opt = -1) const; + + + /** Allow transmission of broadcast messages on the socket. + @param opt 1 sets, 0 resets, -1 won't change anything + @return the previous setting + */ + sal_Int32 SAL_CALL setBroadcast(sal_Int32 opt = -1) const; + + /** Receive out-of-band data in the normal data stream. + @param opt 1 sets, 0 resets, -1 won't change anything + @return the previous setting + */ + sal_Int32 SAL_CALL setOobinline(sal_Int32 opt = -1) const; + + /** Linger on close if unsent data is present. + @param time values > 0 enable lingering with a timeout of time in seconds. + If time is 0, lingering will be disabled. If time is -1 no changes will occur. + @return the previous setting (0 == off, > 0 timeout-value in seconds). + */ + sal_Int32 SAL_CALL setLinger(sal_Int32 time = -1) const; + + /** Specify buffer size for sends. + You might want to use getOption() to check if the size changes were + really successful. + @param size Size >= 0 sets the size, -1 won't change anything. + @return the previous setting + */ + sal_Int32 SAL_CALL setSendBufSize(sal_Int32 size =-1) const; + + /** Specify buffer size for receives. + You might want to use getOption() to check if the size changes were + really successful. + @param size Size >= 0 sets the size, -1 won't change anything. + @return the previous setting + */ + sal_Int32 SAL_CALL setRecvBufSize(sal_Int32 size =-1) const; + + /** Disables the Nagle algorithm for send coalescing. (Do not + collect data until a packet is full, instead send immediatly. + This increases network traffic but might improve response-times.) + @param opt 1 sets, 0 resets, -1 won't change anything + @return the previous setting + */ + sal_Int32 SAL_CALL setTcpNoDelay(sal_Int32 sz =-1) const; + + /** Builds a string with the last error-message for the socket. + @param pBuffer is filled with the error message. + @param nSize the size of pBuffer. The message will be cut + sal_Int16 if the buffer isn't large enough, but still remains + a valid zero-terminated string. + */ + void SAL_CALL getError(NAMESPACE_RTL(OUString)& strError) const; + + /** Delivers a constant decribing the last error for the socket system. + @return ENONE if no error occured, invalid_SocketError if + an unknown (unmapped) error occured, otherwise an enum describing the + error. + */ + TSocketError SAL_CALL getError() const; + +}; + +/** A socket to send or receive a stream of data. +*/ +class OStreamSocket : public NAMESPACE_VOS(OSocket), + public NAMESPACE_VOS(IStream) +{ + VOS_DECLARE_CLASSINFO(NAMESPACE_VOS(OStreamSocket)); +public: + + /** Creates an unattached socket. You must attach the socket to an oslSocket + e.g. by using the operator=(oslSocket), before you can use the stream- + functionality of the object. + */ + OStreamSocket(); + + + + /** Creates socket as wrapper around the underlying oslSocket. + @param Socket + */ + OStreamSocket(oslSocket Socket); + + + /** Copy constructor. + @param Socket + */ + OStreamSocket(const OStreamSocket& Socket); + + + /** + */ + OStreamSocket(const OSocket& Socket); + + /** Destructor. Calls shutdown(readwrite) and close(). + */ + virtual ~OStreamSocket(); + + /** Closes the socket after calling shutdown. + */ + virtual void SAL_CALL close(); + + /** Attaches the oslSocket to this object. If the object + already was attached to an oslSocket, the old one will + be closed and destroyed. + @param Socket. + */ + OStreamSocket& SAL_CALL operator=(oslSocket Socket); + + /** + */ + OStreamSocket& SAL_CALL operator=(const OSocket& Socket); + + /** + */ + OStreamSocket& SAL_CALL operator=(const OStreamSocket& Socket); + + /** Retrieves n bytes from the stream and copies them into pBuffer. + The method avoids incomplete reads due to packet boundaries. + @param pBuffer receives the read data. + @param n the number of bytes to read. pBuffer must be large enough + to hold the n bytes! + @return the number of read bytes. The number will only be smaller than + n if an exceptional condition (e.g. connection closed) occurs. + */ + virtual sal_Int32 SAL_CALL read(void* pBuffer, sal_uInt32 n) const; + + /** Writes n bytes from pBuffer to the stream. The method avoids + incomplete writes due to packet boundaries. + @param pBuffer contains the data to be written. + @param n the number of bytes to write. + @return the number of written bytes. The number will only be smaller than + n if an exceptional condition (e.g. connection closed) occurs. + */ + virtual sal_Int32 SAL_CALL write(const void* pBuffer, sal_uInt32 n); + + /** Checks if socket is closed. + @return True if socket is closed. + */ + virtual sal_Bool SAL_CALL isEof() const; + + /** Tries to receives BytesToRead data from the connected socket, + + @param pBuffer [out] Points to a buffer that will be filled with the received + data. + @param BytesToRead [in] The number of bytes to read. pBuffer must have at least + this size. + @param Flag [in] Modifier for the call. Valid values are: + <ul> + <li> TMsg_Normal + <li> TMsg_OOB + <li> TMsg_Peek + <li> TMsg_DontRoute + <li> TMsg_MaxIOVLen + </ul> + + @return the number of received bytes. + */ + sal_Int32 SAL_CALL recv(void* pBuffer, + sal_uInt32 BytesToRead, + TSocketMsgFlag Flag= TMsg_Normal); + + + /** Tries to sends BytesToSend data from the connected socket. + + @param pBuffer [in] Points to a buffer that contains the send-data. + @param BytesToSend [in] The number of bytes to send. pBuffer must have at least + this size. + @param Flag [in] Modifier for the call. Valid values are: + <ul> + <li> TMsg_Normal + <li> TMsg_OOB + <li> TMsg_Peek + <li> TMsg_DontRoute + <li> TMsg_MaxIOVLen + </ul> + + @return the number of transfered bytes. + */ + sal_Int32 SAL_CALL send(const void* pBuffer, + sal_uInt32 BytesToSend, + TSocketMsgFlag Flag= TMsg_Normal); + + /** Closes a connection in a controlled manner. + @param Direction Says which "end" of the socket is to be closed. + */ + sal_Bool SAL_CALL shutdown(TSocketDirection Direction= TDirection_ReadWrite); +protected: + + /** Creates a socket. This constructor is used only by derived classes + (e.g. OConnectorSocket). + @param Family + @param Protocol + @param Type For some protocols it might be desirable to + use a different type than sock_stream (like sock_seqpacket). + Therefore we do not hide this parameter here. + */ + OStreamSocket(TAddrFamily Family, + TProtocol Protocol, + TSocketType Type= TType_Stream); + + +}; + + +/** A socket to accept incoming connections. +*/ +class OAcceptorSocket : public NAMESPACE_VOS(OSocket) +{ + VOS_DECLARE_CLASSINFO(NAMESPACE_VOS(OAcceptorSocket)); +public: + + /** Creates a socket that can accept connections. + @param Type For some protocols it might be desirable to + use a different type than sock_stream (like sock_seqpacket). + Therefore we do not hide this parameter here. + */ + OAcceptorSocket(TAddrFamily Family= TFamily_Inet, + TProtocol Protocol= TProtocol_Ip, + TSocketType Type= TType_Stream); + + /** Copy constructor. + */ + OAcceptorSocket(const OAcceptorSocket& Socket); + + /** Destructor. Closes the socket and destroys the underlying oslSocket. + */ + virtual ~OAcceptorSocket(); + + /** Closes the socket. Also calls shutdown, needed to unblock + accept on some systems. + */ + virtual void SAL_CALL close(); + + /** Prepare a socket for the accept-call. + @param MaxPendingConnections The maximum number of pending + connections (waiting to be accepted) on this socket. If you use + -1, a system default value is used. + @return True if call was successful. + */ + sal_Bool SAL_CALL listen(sal_Int32 MaxPendingConnections= -1); + + /** Accepts incoming connections on the socket. You must + precede this call with bind() and listen(). + @param Connection receives the incoming connection. + @return result_ok: if a connection has been accepted, + result_timeout: if m_RecvTimeout milliseconds passed without connect, + result_error: on errors. + */ + TResult SAL_CALL acceptConnection(OStreamSocket& Connection); + + /** Accepts incoming connections on the socket. You must + precede this call with bind() and listen(). + @param PeerAddr receives the address of the connecting entity + (your communication partner). + @param Connection receives the incoming connection. + @return True if a connection has been accepted, False on errors. + @return result_ok: if a connection has been accepted, + result_timeout: if m_RecvTimeout milliseconds passed without connect, + result_error: on errors. + */ + TResult SAL_CALL acceptConnection(OStreamSocket& Connection, + OSocketAddr& PeerAddr); + +}; + + +/** A socket to initiate a conenction. +*/ +class OConnectorSocket : public NAMESPACE_VOS(OStreamSocket) +{ + VOS_DECLARE_CLASSINFO(NAMESPACE_VOS(OConnectorSocket)); +public: + + /** Creates a socket that can accept connections. + @param Type For some protocols it might be desirable to + use a different type than sock_stream (like sock_seqpacket). + Therefore we do not hide this parameter here. + */ + OConnectorSocket(TAddrFamily Family= TFamily_Inet, + TProtocol Protocol= TProtocol_Ip, + TSocketType Type= TType_Stream); + + /** Copy constructor. Doesn't duplicate oslSocket. + */ + OConnectorSocket(const OConnectorSocket& Socket); + + /** Destructor. Relies on ~OStreamSocket to close down connection gracefully. + */ + virtual ~OConnectorSocket(); + + /** Connects the socket to a (remote) host. + @param TargetHost The address of the target. + @param msTimeout The timeout in milliseconds. Use -1 to block. + @return result_ok if connected successfully, + result_timeout on timeout, + result_interrupted if unblocked forcefully (by close()), + result_error if connect failed. + */ + TResult SAL_CALL connect(const OSocketAddr& TargetHost, const TimeValue* pTimeout = 0); +}; + + +/** A connectionless socket to send and receive datagrams. +*/ +class ODatagramSocket : public NAMESPACE_VOS(OSocket) +{ + VOS_DECLARE_CLASSINFO(NAMESPACE_VOS(ODatagramSocket)); +public: + + /** Creates a datagram socket. + @param Type is sock_dgram by default. + */ + ODatagramSocket(TAddrFamily Family= TFamily_Inet, + TProtocol Protocol= TProtocol_Ip, + TSocketType Type= TType_Dgram); + + /** Copy constructor. + */ + ODatagramSocket(const ODatagramSocket& Socket); + + /** Destructor. Closes the socket. + */ + virtual ~ODatagramSocket(); + + + /** Tries to receives BufferSize data from the socket, if no error occurs. + + @param pSenderAddr [out] You must provide pointer to a SocketAddr. + It will be filled with the address of the datagrams sender. + If pSenderAddr is 0, it is ignored. + @param pBuffer [out] Points to a buffer that will be filled with the received + datagram. + @param BufferSize [in] The size of pBuffer. + @param Flag [in] Modifier for the call. Valid values are: + <ul> + <li> TMsg_Normal + <li> TMsg_OOB + <li> TMsg_Peek + <li> TMsg_DontRoute + <li> TMsg_MaxIOVLen + </ul> + + @return the number of received bytes. + */ + sal_Int32 SAL_CALL recvFrom(void* pBuffer, + sal_uInt32 BufferSize, + OSocketAddr* pSenderAddr= 0, + TSocketMsgFlag Flag= TMsg_Normal); + + /** Tries to send one datagram with BytesToSend data to the given ReceiverAddr. + Since we only send one packet, we don't need to concern ourselfes here with + incomplete sends due to packet boundaries. + + @param ReceiverAddr [in] A SocketAddr that contains + the destination address for this send. + + @param pBuffer [in] Points to a buffer that contains the send-data. + @param BufferSize [in] The number of bytes to send. pBuffer must have at least + this size. + @param Flag [in] Modifier for the call. Valid values are: + <ul> + <li> TMsg_Normal + <li> TMsg_OOB + <li> TMsg_Peek + <li> TMsg_DontRoute + <li> TMsg_MaxIOVLen + </ul> + + @return the number of transfered bytes. + */ + sal_Int32 SAL_CALL sendTo(const OSocketAddr& ReceiverAddr, + const void* pBuffer, + sal_uInt32 BufferSize, + TSocketMsgFlag Flag= TMsg_Normal); +}; + + + +#ifdef _USE_NAMESPACE +} +#endif + +#endif // _VOS_SOCKET_HXX_ + diff --git a/vos/inc/vos/stream.hxx b/vos/inc/vos/stream.hxx new file mode 100644 index 000000000000..4df9382a9b6e --- /dev/null +++ b/vos/inc/vos/stream.hxx @@ -0,0 +1,330 @@ +/************************************************************************* + * + * $RCSfile: stream.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VOS_STREAM_HXX_ +#define _VOS_STREAM_HXX_ + +#ifndef _VOS_TYPES_HXX_ +# include <vos/types.hxx> +#endif +#ifndef _VOS_OBJECT_HXX_ +# include <vos/object.hxx> +#endif +#ifndef _VOS_ISTREAM_HXX_ +# include <vos/istream.hxx> +#endif + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + + +/** Adds seeking capabilities to IStream +*/ +class IPositionableStream : public NAMESPACE_VOS(IStream) +{ + +public: + + typedef sal_Int32 Offset; + +public: + + /// + virtual sal_Bool SAL_CALL seekTo(Offset position) const = 0; + + /// + virtual sal_Bool SAL_CALL seekRelative(Offset change) const = 0; + + /// + virtual sal_Bool SAL_CALL seekToEnd() const = 0; + + /// + virtual sal_Bool SAL_CALL changeSize(sal_uInt32 new_size) = 0; + + /// + virtual sal_uInt32 SAL_CALL getSize() const = 0; + + + /// + virtual Offset SAL_CALL getOffset() const = 0; + + +protected: + IPositionableStream() { } + virtual ~IPositionableStream() { } + +}; + + +/** Implements IPositionableStream +*/ +class OStream : public NAMESPACE_VOS(OObject), + public NAMESPACE_VOS(IPositionableStream) +{ + VOS_DECLARE_CLASSINFO(VOS_NAMESPACE(OStream, vos)); + +public: + + /// + OStream(IPositionableStream& rStream); + + /// + virtual ~OStream (); + + // ----------------- Read operations ------------------------- + + /// + virtual sal_Int32 SAL_CALL read(void* pbuffer, sal_uInt32 n) const; + + /// + sal_Int32 SAL_CALL read(IPositionableStream::Offset offset, + void* pbuffer, + sal_uInt32 n) const; + + /// + inline sal_Bool SAL_CALL read(sal_Int32& value) const; + + /// + inline sal_Bool SAL_CALL read(sal_Int16& value) const; + + /// + inline sal_Bool SAL_CALL read(sal_Char& value) const; + + /// + inline sal_Bool SAL_CALL read(sal_uInt8& value) const; + + // ----------------- Write operations ------------------------ + + /// + virtual sal_Int32 SAL_CALL write(const void* pbuffer, sal_uInt32 n); + + /// + sal_Int32 SAL_CALL write(IPositionableStream::Offset offset, + const void* pbuffer, + sal_uInt32 n); + /// + inline sal_Bool SAL_CALL write(sal_Int32 value); + + /// + inline sal_Bool SAL_CALL write(sal_Int16 value); + + /// + inline sal_Bool SAL_CALL write(sal_Char value); + + /// + inline sal_Bool SAL_CALL write(sal_uInt8 value); + + /// + sal_Bool SAL_CALL append(void* pbuffer, sal_uInt32 n); // Write at the end of the Stream. + + // ------------- Positioning and sizing operations ---------- + + /// + inline sal_Bool SAL_CALL seekToBegin() const; + + // ----------------- Stream interface ------------------------ + + /// + virtual sal_Bool SAL_CALL seekTo(IPositionableStream::Offset pos) const; + + /// + virtual sal_Bool SAL_CALL seekToEnd() const; + + /// + virtual sal_Bool SAL_CALL seekRelative(IPositionableStream::Offset change) const; + + /// + virtual sal_Bool SAL_CALL changeSize(sal_uInt32 new_size); + + /// + virtual sal_uInt32 SAL_CALL getSize() const; + + /// + virtual sal_Bool SAL_CALL isEof() const; + + /// + virtual IPositionableStream::Offset SAL_CALL getOffset() const; + +protected: + IPositionableStream& m_rStream; + + // ----------------- Stream operators ------------------------ + + friend const OStream& operator>> (OStream& rStream, sal_Int32& value); + friend const OStream& operator>> (OStream& rStream, sal_Int16& value); + friend const OStream& operator>> (OStream& rStream, sal_uInt8& value); + friend const OStream& operator>> (OStream& rStream, sal_Char& value); + friend OStream& operator<< (OStream& rStream, sal_Int32 value); + friend OStream& operator<< (OStream& rStream, sal_Int16 value); + friend OStream& operator<< (OStream& rStream, sal_uInt8 value); + friend OStream& operator<< (OStream& rStream, sal_Char value); +}; + +inline sal_Bool OStream::read(sal_Int32& value) const +{ + return (read(&value, sizeof(value)) == sizeof(value)); +} + +inline sal_Bool OStream::read(sal_Int16& value) const +{ + return (read(&value, sizeof(value)) == sizeof(value)); +} + +inline sal_Bool OStream::read(sal_Char& value) const +{ + return (read(&value, sizeof(value)) == sizeof(value)); +} + +inline sal_Bool OStream::read(sal_uInt8& value) const +{ + return (read(&value, sizeof(value)) == sizeof(value)); +} + +inline sal_Bool OStream::write(sal_Int32 value) +{ + return (write(&value, sizeof(value)) == sizeof(value)); +} + +inline sal_Bool OStream::write(sal_Int16 value) +{ + return (write(&value, sizeof(value)) == sizeof(value)); +} + +inline sal_Bool OStream::write(sal_Char value) +{ + return (write(&value, sizeof(value)) == sizeof(value)); +} + +inline sal_Bool OStream::write(sal_uInt8 value) +{ + return (write((sal_uInt8*)&value, sizeof(value)) == sizeof(value)); +} + +inline sal_Bool OStream::seekToBegin() const +{ + return (seekTo(0L)); +} + +inline const OStream& operator>> (OStream& rStream, sal_Int32& value) +{ + rStream.read(value); + + return (rStream); +} + +inline const OStream& operator>> (OStream& rStream, sal_Int16& value) +{ + rStream.read(value); + + return (rStream); +} + +inline const OStream& operator>> (OStream& rStream, sal_uInt8& value) +{ + rStream.read(value); + + return (rStream); +} + +inline const OStream& operator>> (OStream& rStream, sal_Char& value) +{ + rStream.read(value); + + return (rStream); +} + +inline OStream& operator<< (OStream& rStream, sal_Int32 value) +{ + rStream.write(value); + + return (rStream); +} + +inline OStream& operator<< (OStream& rStream, sal_Int16 value) +{ + rStream.write(value); + + return (rStream); +} + +inline OStream& operator<< (OStream& rStream, sal_uInt8 value) +{ + rStream.write(value); + + return (rStream); +} + +inline OStream& operator<< (OStream& rStream, sal_Char value) +{ + rStream.write(value); + + return (rStream); +} + +#ifdef _USE_NAMESPACE +} +#endif + +#endif // _VOS_STREAM_HXX_ + + diff --git a/vos/inc/vos/thread.hxx b/vos/inc/vos/thread.hxx new file mode 100644 index 000000000000..9f09a294a1db --- /dev/null +++ b/vos/inc/vos/thread.hxx @@ -0,0 +1,287 @@ +/************************************************************************* + * + * $RCSfile: thread.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VOS_THREAD_HXX_ +#define _VOS_THREAD_HXX_ + +#ifndef _VOS_TYPES_HXX_ +# include <vos/types.hxx> +#endif +#ifndef _VOS_OBJECT_HXX_ +# include <vos/object.hxx> +#endif +#ifndef _OSL_THREAD_H_ +# include <osl/thread.h> +#endif +#ifndef _VOS_RUNNABLE_HXX_ +# include <vos/runnable.hxx> +#endif + +extern void SAL_CALL _OThread_WorkerFunction(void* pthis); + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + +#if defined ( _USE_NAMESPACE ) && defined ( UNX ) +void SAL_CALL _cpp_OThread_WorkerFunction(void* pthis); +#endif + +/** OThread is an objectoriented interface for threads. + This class should be the base class for all objects using threads. The + main working function is the run() method and should be overriden in the + derived class. To support soft termination of a thread, yield() should + be called in regular intervalls and the return value should be checked. + If yield returned False the run method should return. + + @author Bernd Hofner + @version 1.0 +*/ + +class OThread : public NAMESPACE_VOS(IRunnable), + public NAMESPACE_VOS(OObject) +{ + + VOS_DECLARE_CLASSINFO(VOS_NAMESPACE(OThread, vos)); + +public: + /** priority of thread. + */ + enum TThreadPriority + { + TPriority_Highest = osl_Thread_PriorityHighest, + TPriority_AboveNormal = osl_Thread_PriorityAboveNormal, + TPriority_Normal = osl_Thread_PriorityNormal, + TPriority_BelowNormal = osl_Thread_PriorityBelowNormal, + TPriority_Lowest = osl_Thread_PriorityLowest, + TPriority_Unknown = osl_Thread_PriorityUnknown + }; + + /** + */ + enum TThreadSleep + { + TSleep_Normal = osl_Thread_SleepNormal, + TSleep_Cancel = osl_Thread_SleepCancel, + TSleep_Pending = osl_Thread_SleepPending, + TSleep_Active = osl_Thread_SleepActive, + TSleep_Error = osl_Thread_SleepError, + TSleep_Unknown = osl_Thread_SleepUnknown + }; + + typedef oslThreadIdentifier TThreadIdentifier; + + /// Constructor + OThread(); + + /// Destructor kills thread if neccessary + virtual ~OThread(); + + /** Create running instance of a thread. + @returns True if thread could be created. + */ + sal_Bool SAL_CALL create(); + + /** Create suspended instance of a thread. + @returns True if thread could be created. + */ + sal_Bool SAL_CALL createSuspended(); + + /// Suspend a runnng thread + void SAL_CALL suspend(); + + /// Resume a suspended thread + void SAL_CALL resume(); + + /** Tries to kill the thread. + will not block and might not succeed when run() won't heed isTerminationRequested(). + */ + virtual void SAL_CALL terminate(); + + /// Kill thread hard and block until it is actually gone + virtual void SAL_CALL kill(); + + /// Block till thread is terminated + void SAL_CALL join(); + + /// Check if thread is running. + sal_Bool SAL_CALL isRunning(); + + /** Change thread priority. + The valid priority levels are: + <ul> + <li>ThreadPriorityHighest, + <li>ThreadPriorityAboveNormal, + <li>ThreadPriorityNormal, + <li>ThreadPriorityBelowNormal, + <li>ThreadPriorityLowest, + </ul> + */ + void SAL_CALL setPriority(TThreadPriority Priority); + + /** Query thread priority. + Valid return values are: + <ul> + <li>ThreadPriorityHighest, + <li>ThreadPriorityAboveNormal, + <li>ThreadPriorityNormal, + <li>ThreadPriorityBelowNormal, + <li>ThreadPriorityLowest, + <li>ThreadPriorityUnknown (returned if thread is killed) + </ul> + */ + TThreadPriority SAL_CALL getPriority(); + + TThreadIdentifier SAL_CALL getIdentifier() const; + + static TThreadIdentifier SAL_CALL getCurrentIdentifier(); + + /** Let thread sleep a specified amout of time. + @param Delay specifies the number of time to sleep. + */ + TThreadSleep SAL_CALL sleep(const TimeValue& Delay); + + /** Awake the sleeping thread. + @returns False if at least one of the handles is invalid + or the thread is not sleeping. + */ + sal_Bool SAL_CALL awake(); + + /** Let current thread wait a specified amout of time. + @param Delay specifies the number of time + to wait. Note, if you need to interrupt the waiting operation + use sleep instead. + */ + static void SAL_CALL wait(const TimeValue& Delay); + + /** Reschedules threads. + Call within your loop if you + want other threads offer some processing time. + This method is static, so it might be used by the + main-thread. + */ + static void SAL_CALL yield(); + +protected: + + /// Working method which should be overridden. + virtual void SAL_CALL run() = 0; + + /** Checks if thread should terminate. + isTerminationRequested() will return True if someone called + terminate(). + @return True if thread should terminate, False if he can continue. + */ + virtual sal_Bool SAL_CALL schedule(); + + /** Called when run() is done. + You might want to override it to do some cleanup. + */ + virtual void SAL_CALL onTerminated(); + +protected: + oslThread m_hThread; + sal_Bool m_bTerminating; + +#if defined ( _USE_NAMESPACE ) && defined ( WNT ) && !defined(GCC) + friend static void ::_OThread_WorkerFunction(void* pthis); +#elif defined ( _USE_NAMESPACE ) + friend void _cpp_OThread_WorkerFunction(void* pthis); +#else + friend void _OThread_WorkerFunction(void* pthis); +#endif + + +}; + +class OThreadData : public NAMESPACE_VOS(OObject) +{ + VOS_DECLARE_CLASSINFO(VOS_NAMESPACE(OThreadData, vos)); + +public: + /// Create a thread specific local data key + OThreadData(); + + /// Destroy a thread specific local data key + virtual ~OThreadData(); + + /** Set the data associated with the data key. + @returns True if operation was successfull + */ + sal_Bool SAL_CALL setData(void *pData); + + /** Get the data associated with the data key. + @returns The data asscoitaed with the data key or + NULL if no data was set + */ + void* SAL_CALL getData(); + +protected: + oslThreadKey m_hKey; +}; + +#ifdef _USE_NAMESPACE +} +#endif + +#endif // _VOS_THREAD_HXX_ + diff --git a/vos/inc/vos/timer.hxx b/vos/inc/vos/timer.hxx new file mode 100644 index 000000000000..103287a0265c --- /dev/null +++ b/vos/inc/vos/timer.hxx @@ -0,0 +1,246 @@ +/************************************************************************* + * + * $RCSfile: timer.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _VOS_TIMER_HXX_ +#define _VOS_TIMER_HXX_ + +#ifndef _VOS_REFERNCE_HXX_ +# include <vos/refernce.hxx> +#endif +#ifndef _VOS_MUTEX_HXX_ +# include <vos/mutex.hxx> +#endif +#ifndef _OSL_TIME_H_ +# include <osl/time.h> +#endif + + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + + +///////////////////////////////////////////////////////////////////////////// +// +// TTimeValue +// + +/** <code> struct TTimeValue </code> : class for times. Times are seconds in UTC since 01.01.1970 + */ +struct TTimeValue : public TimeValue +{ + TTimeValue() + { Seconds = 0; Nanosec = 0; } + + TTimeValue(sal_uInt32 Seconds, sal_uInt32 Nano); + + TTimeValue(sal_uInt32 MilliSecs) + { Seconds = MilliSecs / 1000L; Nanosec = (MilliSecs % 1000) * 1000000L; } + + TTimeValue(const TTimeValue& rTimeValue) + { Seconds = rTimeValue.Seconds; Nanosec = rTimeValue.Nanosec; } + + TTimeValue(const TimeValue& rTimeValue) + { Seconds = rTimeValue.Seconds; Nanosec = rTimeValue.Nanosec; } + + void SAL_CALL normalize(); + + void SAL_CALL addTime(const TTimeValue& Delta); + + sal_Bool SAL_CALL isEmpty() const; +}; + +inline void TTimeValue::normalize() +{ + if (Nanosec > 1000000000) + { + Seconds += Nanosec / 1000000000; + Nanosec %= 1000000000; + } +} + +inline TTimeValue::TTimeValue(sal_uInt32 Secs, sal_uInt32 Nano) +{ + Seconds = Secs; + Nanosec = Nano; + + normalize(); +} + +inline void TTimeValue::addTime(const TTimeValue& Time) +{ + Seconds += Time.Seconds; + Nanosec += Time.Nanosec; + + normalize(); +} + +inline sal_Bool TTimeValue::isEmpty() const +{ + return ((Seconds == 0) && (Nanosec == 0)); +} + +inline sal_Bool operator<(const TTimeValue& rTimeA, const TTimeValue& rTimeB) +{ + if (rTimeA.Seconds < rTimeB.Seconds) + return sal_True; + else if (rTimeA.Seconds > rTimeB.Seconds) + return sal_False; + else + return (rTimeA.Nanosec < rTimeB.Nanosec); +} + +inline sal_Bool operator>(const TTimeValue& rTimeA, const TTimeValue& rTimeB) +{ + if (rTimeA.Seconds > rTimeB.Seconds) + return sal_True; + else if (rTimeA.Seconds < rTimeB.Seconds) + return sal_False; + else + return (rTimeA.Nanosec > rTimeB.Nanosec); +} + +inline sal_Bool operator==(const TTimeValue& rTimeA, const TTimeValue& rTimeB) +{ + return ((rTimeA.Seconds == rTimeB.Seconds) && + (rTimeA.Nanosec == rTimeB.Nanosec)); +} + + +///////////////////////////////////////////////////////////////////////////// +// +// Timer class +// + +class OTimerManager; + +/** <code> class OTimer </code> : Interface for the Timer and handling the event +*/ +class OTimer : virtual public OReference , virtual public OObject +{ + VOS_DECLARE_CLASSINFO(VOS_NAMESPACE(OTimer, vos)); + +public: + + /// constructor + OTimer(); + /// constructor + OTimer(const TTimeValue& Time); + /// constructor + OTimer(const TTimeValue& Time, const TTimeValue& RepeatTime); + /// start timer. + void SAL_CALL start(); + /// abort timer prematurely. + void SAL_CALL stop(); + /// returns <code> sal_True </code> if timer is running. + sal_Bool SAL_CALL isTicking() const; + /// is the timer expired? + sal_Bool SAL_CALL isExpired() const; + /// does <code> pTimer </code> expires before us? + sal_Bool SAL_CALL expiresBefore(const OTimer* pTimer) const; + /// set the absolute time when the timer should fire + void SAL_CALL setAbsoluteTime(const TTimeValue& Time); + /// set the time to fire to 'now' + <code> Remaining </code> + void SAL_CALL setRemainingTime(const TTimeValue& Remaining); + /// set the time to fire to 'now' + <code> Remaining </code> with repeat interveal <code> Repeat </code> + void SAL_CALL setRemainingTime(const TTimeValue& Remaining, const TTimeValue& Repeat); + /// adds <code> Time </code> to the 'fire time' + void SAL_CALL addTime(const TTimeValue& Time); + /// returns the remaining time before timer expiration relative to now + TTimeValue SAL_CALL getRemainingTime() const; + +protected: + + /// destructor + virtual ~OTimer(); + /// what should be done when the 'timer fires' + virtual void SAL_CALL onShot() = 0; + + /// holds (initial) exparation time of this timer + TTimeValue m_TimeOut; + /// holds the time of exparation of this timer + TTimeValue m_Expired; + /// holds the time interveal of successive exparations + TTimeValue m_RepeatDelta; + /// Pointer to the next timer (to fire) + OTimer* m_pNext; + +private: + + /// copy constructor disabled + OTimer(const OTimer& rTimer); + /// assignment operator disabled + void SAL_CALL operator=(const OTimer& rTimer); + + friend class OTimerManager; +}; + + +#ifdef _USE_NAMESPACE +} +#endif + + +#endif //_VOS_TIMER_HXX_ + + diff --git a/vos/inc/vos/types.hxx b/vos/inc/vos/types.hxx new file mode 100644 index 000000000000..e68f3051751c --- /dev/null +++ b/vos/inc/vos/types.hxx @@ -0,0 +1,77 @@ +/************************************************************************* + * + * $RCSfile: types.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _VOS_TYPES_HXX_ +#define _VOS_TYPES_HXX_ + +#ifndef _OSL_TYPES_H_ +# include <osl/types.h> +#endif + +/* disable some warnings for MS-C */ +#ifdef _MSC_VER +# pragma warning (disable : 4786) // 4786: truncated names (longer 255 chars) +# pragma warning (disable : 4355) // 4355: this used in initializer-list +#endif + +#endif //_VOS_TYPES_HXX_ + diff --git a/vos/inc/vos/xception.hxx b/vos/inc/vos/xception.hxx new file mode 100644 index 000000000000..4a9ade245e22 --- /dev/null +++ b/vos/inc/vos/xception.hxx @@ -0,0 +1,125 @@ +/************************************************************************* + * + * $RCSfile: xception.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _XCEPTION_HXX_ +#define _XCEPTION_HXX_ + +#ifndef _VOS_OBJECT_HXX_ +#include <vos/object.hxx> +#endif + +#ifdef SAL_W32 +#pragma warning( disable : 4290 ) +#endif + +#ifdef _USE_NAMESPACE +namespace vos +{ +#endif + +/* avoid clashes with <vos/exception.hxx> */ +#define OException OBaseException + +/* + * Macros for true try/catch based Exception Handling (public) + * based on true rtti type checking + */ + +#define TRY try +#define CATCH( Class, Exception ) catch( Class& Exception ) +#define CATCH_ALL() catch( ... ) +#define AND_CATCH( Class, Exception ) catch( Class& Exception ) +#define AND_CATCH_ALL() catch( ... ) +#define THROW_AGAIN throw; +#define END_CATCH +#define THROW( Constructor ) throw Constructor; + +/* + * declaration of the exceptions that may be thrown by a function + * (e.g.) void myfunction(sal_Int32 a) throw ( std::bad_alloc ); + * is not fully supported by all compilers + */ + +#define THROWS( ARG ) throw ARG + +/* + * just a base class for further exceptions + */ + +class OException : public OObject +{ + VOS_DECLARE_CLASSINFO(VOS_NAMESPACE(OException, vos)); + +public: + virtual ~OException(); + OException() {} + OException( const OException &aPattern ) {} + + OException& SAL_CALL operator=(const OException& excp) + { return *this; } +}; + +#ifdef _USE_NAMESPACE +} +#endif + +#endif /* _XCEPTION_HXX_ */ + |