Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / mozab / mozillasrc / MQueryHelper.hxx
blob47f8032d2542f7f6165077663f140971aa2c4486
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_MOZILLASRC_MQUERYHELPER_HXX
21 #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_MOZILLASRC_MQUERYHELPER_HXX
23 #include <sal/config.h>
25 #include <vector>
27 #include <MNSInclude.hxx>
28 #include "MErrorResource.hxx"
29 #include <sal/types.h>
30 #include <rtl/ustring.hxx>
31 #include <osl/mutex.hxx>
32 #include <osl/conditn.hxx>
33 #include <osl/thread.hxx>
35 #include <boost/unordered_map.hpp>
37 namespace connectivity
39 namespace mozab
41 class MQueryHelperResultEntry
43 private:
44 typedef ::boost::unordered_map< OString, OUString, OStringHash > FieldMap;
46 mutable ::osl::Mutex m_aMutex;
47 FieldMap m_Fields;
48 nsCOMPtr<nsIAbCard> m_Card;
49 sal_Int32 m_RowStates;
51 public:
52 MQueryHelperResultEntry();
53 ~MQueryHelperResultEntry();
55 void insert( const OString &key, OUString &value );
56 OUString getValue( const OString &key ) const;
57 void setValue( const OString &key, const OUString & rValue);
59 void setCard(nsIAbCard *card);
60 nsIAbCard *getCard();
61 sal_Bool setRowStates(sal_Int32 state){m_RowStates = state; return sal_True;};
62 sal_Int32 getRowStates() const { return m_RowStates;};
65 class MQueryHelper : public nsIAbDirectoryQueryResultListener
67 private:
68 typedef std::vector< MQueryHelperResultEntry* > resultsArray;
70 mutable ::osl::Mutex m_aMutex;
71 ::osl::Condition m_aCondition;
72 resultsArray m_aResults;
73 sal_uInt32 m_nIndex;
74 sal_Bool m_bHasMore;
75 sal_Bool m_bAtEnd;
76 sal_Bool m_bErrorCondition;
77 sal_Bool m_bQueryComplete;
78 ErrorDescriptor m_aError;
80 void append(MQueryHelperResultEntry* resEnt );
82 void clear_results();
84 void clearResultOrComplete();
85 void notifyResultOrComplete();
86 sal_Bool waitForResultOrComplete( );
87 void getCardValues(nsIAbCard *card,sal_uInt32 rowIndex=0);
88 #if OSL_DEBUG_LEVEL > 0
89 oslThreadIdentifier m_oThreadID;
90 #endif
92 public:
93 NS_DECL_ISUPPORTS
94 NS_DECL_NSIABDIRECTORYQUERYRESULTLISTENER
96 MQueryHelper();
97 virtual ~MQueryHelper();
99 void reset();
101 MQueryHelperResultEntry* next( );
103 MQueryHelperResultEntry* getByIndex( sal_uInt32 nRow );
105 const ErrorDescriptor& getError() const { return m_aError; }
107 sal_Bool isError() const;
109 sal_Bool queryComplete() const;
111 sal_Bool waitForQueryComplete( );
112 sal_Bool waitForRow( sal_Int32 rowNum );
114 sal_Int32 getResultCount() const;
115 sal_uInt32 getRealCount() const;
116 sal_Int32 createNewCard(); //return Row count number
117 sal_Bool resyncRow(sal_uInt32 rowIndex);
119 void notifyQueryError() ;
120 sal_Bool setCardValues(const sal_uInt32 rowIndex);
121 sal_Int32 commitCard(const sal_uInt32 rowIndex, nsIAbDirectory * directory);
122 sal_Int32 deleteCard(const sal_uInt32 rowIndex, nsIAbDirectory * directory);
126 #endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_MOZILLASRC_MQUERYHELPER_HXX
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */