Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / chip-tool / commands / clusters / ModelCommand.cpp
1 /*
2  *   Copyright (c) 2020 Project CHIP Authors
3  *   All rights reserved.
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  *
17  */
18
19 #include "ModelCommand.h"
20
21 #include <inttypes.h>
22
23 using namespace ::chip;
24
25 namespace {
26 constexpr uint16_t kWaitDurationInSeconds = 10;
27 } // namespace
28
29 CHIP_ERROR ModelCommand::Run(PersistentStorage & storage, NodeId localId, NodeId remoteId)
30 {
31     CHIP_ERROR err = CHIP_NO_ERROR;
32
33     err = mCommissioner.SetUdpListenPort(storage.GetListenPort());
34     VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure! Commissioner: %s", ErrorStr(err)));
35
36     err = mCommissioner.Init(localId, &storage);
37     VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure! Commissioner: %s", ErrorStr(err)));
38
39     err = mCommissioner.ServiceEvents();
40     VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure! Run Loop: %s", ErrorStr(err)));
41
42     err = mCommissioner.GetDevice(remoteId, &mDevice);
43     VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(chipTool, "Init failure! No pairing for device: %" PRIu64, localId));
44
45     err = SendCommand(mDevice, mEndPointId);
46     VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(chipTool, "Failed to send message: %s", ErrorStr(err)));
47
48     UpdateWaitForResponse(true);
49     WaitForResponse(kWaitDurationInSeconds);
50
51     VerifyOrExit(GetCommandExitStatus(), err = CHIP_ERROR_INTERNAL);
52
53 exit:
54     mCommissioner.ServiceEventSignal();
55     mCommissioner.Shutdown();
56     return err;
57 }