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