transport: pass correct channel
[abstract.git] / storage / base / aaSqlFilter.cpp
blobb3daae2ad816a4320eabeea84cc46902eaaa4347
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
3 /*
4 * Copyright (C) 2008 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "xpcom-config.h"
24 #include "nsCOMPtr.h"
25 #include "nsStringAPI.h"
26 #include "pldhash.h"
28 /* Project includes */
29 #include "nsStringUtils.h"
30 #include "aaIFlow.h"
31 #include "aaStorageUtils.h"
32 #include "aaSqlFilter.h"
34 aaSqlFilter::aaSqlFilter()
36 mParams.Init();
39 aaSqlFilter::~aaSqlFilter()
43 NS_IMPL_ISUPPORTS2(aaSqlFilter,
44 nsIInterfaceRequestor,
45 aaISqlFilter)
46 /* nsIInterfaceRequestor */
47 NS_IMETHODIMP
48 aaSqlFilter::GetInterface(const nsIID & uuid, void * *result)
50 NS_ENSURE_ARG_POINTER(result);
51 void *tmp = 0;
52 PRInt32 i;
53 for (i = 0; i < mElements.Count(); i++) {
54 mElements[i]->QueryInterface(uuid, &tmp);
55 if (tmp) {
56 *result = tmp;
57 return NS_OK;
61 return NS_NOINTERFACE;
64 /* aaISqlFilter */
65 NS_IMETHODIMP
66 aaSqlFilter::SetInterface(const nsIID & uuid, nsISupports *aInstance)
68 NS_ENSURE_ARG_POINTER(aInstance);
69 void *tmp = 0;
70 PRInt32 i;
71 for (i = 0; i < mElements.Count(); i++) {
72 mElements[i]->QueryInterface(uuid, &tmp);
73 if (tmp) {
74 mElements.ReplaceObjectAt(aInstance, i);
75 return NS_OK;
78 mElements.AppendObject(aInstance);
80 return NS_OK;
83 NS_IMETHODIMP
84 aaSqlFilter::Clear(void)
86 mElements.Clear();
87 mParams.Clear();
88 return NS_OK;
91 NS_IMETHODIMP
92 aaSqlFilter::AddParam(const nsACString& name, nsISupports* aParamInst)
94 NS_ENSURE_ARG_POINTER(aParamInst);
95 NS_ENSURE_TRUE(name.Length() > 0, NS_ERROR_INVALID_ARG);
96 if (mParams.Put(name, aParamInst)) {
97 return NS_OK;
99 return NS_ERROR_FAILURE;
102 NS_IMETHODIMP
103 aaSqlFilter::GetParam(const nsACString& name, nsISupports** _retval)
105 NS_ENSURE_ARG_POINTER(_retval);
106 NS_ENSURE_TRUE(name.Length() > 0, NS_ERROR_INVALID_ARG);
107 if (mParams.Get(name, _retval)) {
108 return NS_OK;
110 return NS_ERROR_FAILURE;
113 PLDHashOperator HashTableEnumerator(const nsACString& name, nsCOMPtr<nsISupports>& ptr, void* userArg)
115 aaIParamObserver* pObserver = static_cast<aaIParamObserver*>(userArg);
116 if (NS_SUCCEEDED(pObserver->Param(name, ptr.get()))) {
117 return PL_DHASH_STOP;
119 return PL_DHASH_NEXT;//PLDHashOperator::PL_DHASH_NEXT;
122 NS_IMETHODIMP
123 aaSqlFilter::Enumerate(aaIParamObserver* pObserver)
125 NS_ENSURE_ARG_POINTER(pObserver);
126 if (mParams.Enumerate(&HashTableEnumerator, static_cast<void*>(pObserver)) > 0) {
127 return NS_OK;
129 return NS_ERROR_FAILURE;