summaryrefslogtreecommitdiffstats
path: root/include/osl/profile.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/osl/profile.h147
-rw-r--r--include/osl/profile.hxx208
2 files changed, 355 insertions, 0 deletions
diff --git a/include/osl/profile.h b/include/osl/profile.h
new file mode 100644
index 000000000..fc553d545
--- /dev/null
+++ b/include/osl/profile.h
@@ -0,0 +1,147 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_OSL_PROFILE_H
+#define INCLUDED_OSL_PROFILE_H
+
+#include "sal/config.h"
+
+#include "rtl/ustring.h"
+#include "sal/saldllapi.h"
+#include "sal/types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef sal_uInt32 oslProfileOption;
+
+#define osl_Profile_DEFAULT 0x0000
+#define osl_Profile_SYSTEM 0x0001 /* use system depended functionality */
+#define osl_Profile_READLOCK 0x0002 /* lock file for reading */
+#define osl_Profile_WRITELOCK 0x0004 /* lock file for writing */
+#define osl_Profile_FLUSHWRITE 0x0010 /* writing only with flush */
+
+
+typedef void* oslProfile;
+
+/** Deprecated API.
+ Open or create a configuration profile.
+ @retval 0 if the profile could not be created, otherwise a handle to the profile.
+ @deprecated
+*/
+SAL_DLLPUBLIC oslProfile SAL_CALL osl_openProfile(
+ rtl_uString *strProfileName, oslProfileOption Options) SAL_COLD;
+
+/** Deprecated API.
+ Close the opened profile an flush all data to the disk.
+ @param Profile handle to an opened profile.
+ @deprecated
+*/
+SAL_DLLPUBLIC sal_Bool SAL_CALL osl_closeProfile(
+ oslProfile Profile) SAL_COLD;
+
+/** Deprecated API.
+ @deprecated
+*/
+
+SAL_DLLPUBLIC sal_Bool SAL_CALL osl_flushProfile(
+ oslProfile Profile) SAL_COLD;
+/** Deprecated API.
+ @deprecated
+*/
+SAL_DLLPUBLIC sal_Bool SAL_CALL osl_readProfileString(
+ oslProfile Profile,
+ const sal_Char* pszSection, const sal_Char* pszEntry,
+ sal_Char* pszString, sal_uInt32 MaxLen,
+ const sal_Char* pszDefault) SAL_COLD;
+/** Deprecated API.
+ @deprecated
+*/
+SAL_DLLPUBLIC sal_Bool SAL_CALL osl_readProfileBool(
+ oslProfile Profile,
+ const sal_Char* pszSection, const sal_Char* pszEntry,
+ sal_Bool Default) SAL_COLD;
+/** Deprecated API.
+ @deprecated
+*/
+SAL_DLLPUBLIC sal_uInt32 SAL_CALL osl_readProfileIdent(
+ oslProfile Profile,
+ const sal_Char* pszSection, const sal_Char* pszEntry,
+ sal_uInt32 FirstId, const sal_Char* Strings[],
+ sal_uInt32 Default) SAL_COLD;
+
+/** Deprecated API.
+ @deprecated
+*/
+SAL_DLLPUBLIC sal_Bool SAL_CALL osl_writeProfileString(
+ oslProfile Profile,
+ const sal_Char* pszSection, const sal_Char* pszEntry,
+ const sal_Char* pszString) SAL_COLD;
+
+/** Deprecated API.
+ @deprecated
+*/
+SAL_DLLPUBLIC sal_Bool SAL_CALL osl_writeProfileBool(
+ oslProfile Profile,
+ const sal_Char* pszSection, const sal_Char* pszEntry,
+ sal_Bool Value) SAL_COLD;
+
+/** Deprecated API.
+ @deprecated
+*/
+SAL_DLLPUBLIC sal_Bool SAL_CALL osl_writeProfileIdent(
+ oslProfile Profile,
+ const sal_Char* pszSection, const sal_Char* pszEntry,
+ sal_uInt32 FirstId, const sal_Char* Strings[],
+ sal_uInt32 Value) SAL_COLD;
+
+/** Deprecated API.
+ Acquire the mutex, block if already acquired by another thread.
+ @retval False if section or entry could not be found.
+ @deprecated
+*/
+SAL_DLLPUBLIC sal_Bool SAL_CALL osl_removeProfileEntry(
+ oslProfile Profile,
+ const sal_Char *pszSection, const sal_Char *pszEntry) SAL_COLD;
+
+/** Deprecated API.
+ Get all entries belonging to the specified section.
+ @returns Pointer to an array of pointers.
+ @deprecated
+*/
+SAL_DLLPUBLIC sal_uInt32 SAL_CALL osl_getProfileSectionEntries(
+ oslProfile Profile, const sal_Char *pszSection,
+ sal_Char* pszBuffer, sal_uInt32 MaxLen) SAL_COLD;
+
+/** Deprecated API.
+ Get all section entries
+ @retval Pointer to an array of pointers.
+ @deprecated
+*/
+SAL_DLLPUBLIC sal_uInt32 SAL_CALL osl_getProfileSections(
+ oslProfile Profile, sal_Char* pszBuffer, sal_uInt32 MaxLen) SAL_COLD;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // INCLUDED_OSL_PROFILE_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/osl/profile.hxx b/include/osl/profile.hxx
new file mode 100644
index 000000000..0ce69a8ae
--- /dev/null
+++ b/include/osl/profile.hxx
@@ -0,0 +1,208 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_OSL_PROFILE_HXX
+#define INCLUDED_OSL_PROFILE_HXX
+
+#include "osl/profile.h"
+#include "rtl/ustring.hxx"
+
+#include <string.h>
+#include <exception>
+#include <list>
+
+namespace osl {
+
+ typedef oslProfileOption ProfileOption;
+
+ const int Profile_DEFAULT = osl_Profile_DEFAULT;
+ const int Profile_SYSTEM = osl_Profile_SYSTEM; /* use system depended functionality */
+ const int Profile_READLOCK = osl_Profile_READLOCK; /* lock file for reading */
+ const int Profile_WRITELOCK = osl_Profile_WRITELOCK; /* lock file for writing */
+
+ /** Deprecated API.
+ @deprecated
+ */
+ class Profile {
+ oslProfile profile;
+
+ public:
+ /** Open or create a configuration profile.
+ @retval 0 if the profile could not be created, otherwise a handle to the profile.
+ */
+ Profile(const rtl::OUString & strProfileName, oslProfileOption Options = Profile_DEFAULT )
+ {
+ profile = osl_openProfile(strProfileName.pData, Options);
+ if( ! profile )
+ throw std::exception();
+ }
+
+
+ /** Close the opened profile an flush all data to the disk.
+ */
+ ~Profile()
+ {
+ osl_closeProfile(profile);
+ }
+
+
+ bool flush()
+ {
+ return osl_flushProfile(profile);
+ }
+
+ rtl::OString readString( const rtl::OString& rSection, const rtl::OString& rEntry,
+ const rtl::OString& rDefault)
+ {
+ sal_Char aBuf[1024];
+ return osl_readProfileString( profile,
+ rSection.getStr(),
+ rEntry.getStr(),
+ aBuf,
+ sizeof( aBuf ),
+ rDefault.getStr() ) ? rtl::OString( aBuf ) : rtl::OString();
+
+ }
+
+ bool readBool( const rtl::OString& rSection, const rtl::OString& rEntry, bool bDefault )
+ {
+ return osl_readProfileBool( profile, rSection.getStr(), rEntry.getStr(), bDefault );
+ }
+
+ sal_uInt32 readIdent(const rtl::OString& rSection, const rtl::OString& rEntry,
+ sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings,
+ sal_uInt32 nDefault)
+ {
+ size_t nItems = rStrings.size();
+ const sal_Char** pStrings = new const sal_Char*[ nItems+1 ];
+ std::list< rtl::OString >::const_iterator it = rStrings.begin();
+ nItems = 0;
+ while( it != rStrings.end() )
+ {
+ pStrings[ nItems++ ] = it->getStr();
+ ++it;
+ }
+ pStrings[ nItems ] = NULL;
+ sal_uInt32 nRet = osl_readProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nDefault);
+ delete[] pStrings;
+ return nRet;
+ }
+
+ bool writeString(const rtl::OString& rSection, const rtl::OString& rEntry,
+ const rtl::OString& rString)
+ {
+ return osl_writeProfileString(profile, rSection.getStr(), rEntry.getStr(), rString.getStr());
+ }
+
+ bool writeBool(const rtl::OString& rSection, const rtl::OString& rEntry, bool Value)
+ {
+ return osl_writeProfileBool(profile, rSection.getStr(), rEntry.getStr(), Value);
+ }
+
+ bool writeIdent(const rtl::OString& rSection, const rtl::OString& rEntry,
+ sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings,
+ sal_uInt32 nValue)
+ {
+ size_t nItems = rStrings.size();
+ const sal_Char** pStrings = new const sal_Char*[ nItems+1 ];
+ std::list< rtl::OString >::const_iterator it = rStrings.begin();
+ nItems = 0;
+ while( it != rStrings.end() )
+ {
+ pStrings[ nItems++ ] = it->getStr();
+ ++it;
+ }
+ pStrings[ nItems ] = NULL;
+ bool bRet =
+ osl_writeProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nValue );
+ delete[] pStrings;
+ return bRet;
+ }
+
+ /** Remove an entry from a section.
+ @param rSection Name of the section.
+ @param rEntry Name of the entry to remove.
+ @retval False if section or entry could not be found.
+ */
+ bool removeEntry(const rtl::OString& rSection, const rtl::OString& rEntry)
+ {
+ return osl_removeProfileEntry(profile, rSection.getStr(), rEntry.getStr());
+ }
+
+ /** Get all entries belonging to the specified section.
+ @param rSection Name of the section.
+ @return Pointer to an array of pointers.
+ */
+ std::list< rtl::OString > getSectionEntries(const rtl::OString& rSection )
+ {
+ std::list< rtl::OString > aEntries;
+
+ // count buffer size necessary
+ size_t n = osl_getProfileSectionEntries( profile, rSection.getStr(), NULL, 0 );
+ if( n > 1 )
+ {
+ sal_Char* pBuf = new sal_Char[ n+1 ];
+ osl_getProfileSectionEntries( profile, rSection.getStr(), pBuf, n+1 );
+ size_t nLen;
+ for( n = 0; ; n += nLen+1 )
+ {
+ nLen = strlen( pBuf+n );
+ if (!nLen)
+ break;
+ aEntries.push_back( rtl::OString( pBuf+n ) );
+ }
+ delete[] pBuf;
+ }
+
+ return aEntries;
+ }
+
+ /** Get all section entries
+ @return Pointer to an array of pointers.
+ */
+ std::list< rtl::OString > getSections()
+ {
+ std::list< rtl::OString > aSections;
+
+ // count buffer size necessary
+ size_t n = osl_getProfileSections( profile, NULL, 0 );
+ if( n > 1 )
+ {
+ sal_Char* pBuf = new sal_Char[ n+1 ];
+ osl_getProfileSections( profile, pBuf, n+1 );
+ size_t nLen;
+ for( n = 0; ; n += nLen+1 )
+ {
+ nLen = strlen( pBuf+n );
+ if (!nLen)
+ break;
+ aSections.push_back( rtl::OString( pBuf+n ) );
+ }
+ delete[] pBuf;
+ }
+
+ return aSections;
+ }
+ };
+}
+
+#endif // INCLUDED_OSL_PROFILE_HXX
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */