1*37adc4f0SAndrew Rist /**************************************************************
2*37adc4f0SAndrew Rist  *
3*37adc4f0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*37adc4f0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*37adc4f0SAndrew Rist  * distributed with this work for additional information
6*37adc4f0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*37adc4f0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*37adc4f0SAndrew Rist  * "License"); you may not use this file except in compliance
9*37adc4f0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*37adc4f0SAndrew Rist  *
11*37adc4f0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*37adc4f0SAndrew Rist  *
13*37adc4f0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*37adc4f0SAndrew Rist  * software distributed under the License is distributed on an
15*37adc4f0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*37adc4f0SAndrew Rist  * KIND, either express or implied.  See the License for the
17*37adc4f0SAndrew Rist  * specific language governing permissions and limitations
18*37adc4f0SAndrew Rist  * under the License.
19*37adc4f0SAndrew Rist  *
20*37adc4f0SAndrew Rist  *************************************************************/
21*37adc4f0SAndrew Rist 
22*37adc4f0SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "sal/config.h"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
27cdf0e10cSrcweir #include "rtl/byteseq.hxx"
28cdf0e10cSrcweir #include "osl/mutex.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "lessoperators.hxx"
31cdf0e10cSrcweir #include "outgoingrequest.hxx"
32cdf0e10cSrcweir #include "outgoingrequests.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace binaryurp {
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace {
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace css = com::sun::star;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir }
41cdf0e10cSrcweir 
OutgoingRequests()42cdf0e10cSrcweir OutgoingRequests::OutgoingRequests() {}
43cdf0e10cSrcweir 
~OutgoingRequests()44cdf0e10cSrcweir OutgoingRequests::~OutgoingRequests() {}
45cdf0e10cSrcweir 
push(rtl::ByteSequence const & tid,OutgoingRequest const & request)46cdf0e10cSrcweir void OutgoingRequests::push(
47cdf0e10cSrcweir     rtl::ByteSequence const & tid, OutgoingRequest const & request)
48cdf0e10cSrcweir {
49cdf0e10cSrcweir     osl::MutexGuard g(mutex_);
50cdf0e10cSrcweir     map_[tid].push_back(request);
51cdf0e10cSrcweir }
52cdf0e10cSrcweir 
top(rtl::ByteSequence const & tid)53cdf0e10cSrcweir OutgoingRequest OutgoingRequests::top(rtl::ByteSequence const & tid) {
54cdf0e10cSrcweir     osl::MutexGuard g(mutex_);
55cdf0e10cSrcweir     Map::iterator i(map_.find(tid));
56cdf0e10cSrcweir     if (i == map_.end()) {
57cdf0e10cSrcweir         throw css::uno::RuntimeException(
58cdf0e10cSrcweir             rtl::OUString(
59cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("URP: reply for unknown TID")),
60cdf0e10cSrcweir             css::uno::Reference< css::uno::XInterface >());
61cdf0e10cSrcweir     }
62cdf0e10cSrcweir     OSL_ASSERT(!i->second.empty());
63cdf0e10cSrcweir     return i->second.back();
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
pop(rtl::ByteSequence const & tid)66cdf0e10cSrcweir void OutgoingRequests::pop(rtl::ByteSequence const & tid) throw () {
67cdf0e10cSrcweir     osl::MutexGuard g(mutex_);
68cdf0e10cSrcweir     Map::iterator i(map_.find(tid));
69cdf0e10cSrcweir     OSL_ASSERT(i != map_.end());
70cdf0e10cSrcweir     i->second.pop_back();
71cdf0e10cSrcweir     if (i->second.empty()) {
72cdf0e10cSrcweir         map_.erase(i);
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir }
77