1 : // Copyright 2012 Google Inc.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Declares utility functions used by the call trace client and its unit
16 : // tests.
17 :
18 : #include "syzygy/trace/rpc/rpc_helpers.h"
19 :
20 : #include <windows.h>
21 :
22 : #include "base/logging.h"
23 : #include "sawbuck/common/com_utils.h"
24 :
25 : namespace trace {
26 : namespace client {
27 :
28 : bool CreateRpcBinding(const base::StringPiece16& protocol,
29 : const base::StringPiece16& endpoint,
30 E : handle_t* out_handle) {
31 E : DCHECK(!protocol.empty());
32 E : DCHECK(!endpoint.empty());
33 E : DCHECK(out_handle != NULL);
34 :
35 E : std::wstring protocol_temp(protocol.begin(), protocol.end());
36 E : std::wstring endpoint_temp(endpoint.begin(), endpoint.end());
37 E : RPC_WSTR string_binding = NULL;
38 :
39 : RPC_STATUS status = ::RpcStringBindingCompose(
40 : NULL, // UUID.
41 : reinterpret_cast<RPC_WSTR>(&protocol_temp[0]),
42 : NULL, // Address.
43 : reinterpret_cast<RPC_WSTR>(&endpoint_temp[0]),
44 : NULL, // Options.
45 E : &string_binding);
46 E : if (status != RPC_S_OK) {
47 i : LOG(ERROR) << "Can't compose RPC binding: " << com::LogWe(status) << ".";
48 i : return false;
49 : }
50 :
51 E : handle_t binding = NULL;
52 E : status = ::RpcBindingFromStringBinding(string_binding, &binding);
53 :
54 E : ignore_result(::RpcStringFree(&string_binding));
55 :
56 E : if (status != RPC_S_OK) {
57 i : LOG(ERROR) << "Can't create RPC binding: " << com::LogWe(status) << ".";
58 i : return false;
59 : }
60 :
61 E : *out_handle = binding;
62 E : return true;
63 E : }
64 :
65 : } // namespace trace::client
66 : } // namespace trace
|