1*c9157d92SDimitry Andric //===-- SBProcessInfoList.cpp ---------------------------------------------===//
2*c9157d92SDimitry Andric //
3*c9157d92SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*c9157d92SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*c9157d92SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*c9157d92SDimitry Andric //
7*c9157d92SDimitry Andric //===----------------------------------------------------------------------===//
8*c9157d92SDimitry Andric 
9*c9157d92SDimitry Andric #include "lldb/API/SBProcessInfoList.h"
10*c9157d92SDimitry Andric #include "lldb/API/SBProcessInfo.h"
11*c9157d92SDimitry Andric #include "lldb/Utility/Instrumentation.h"
12*c9157d92SDimitry Andric #include "lldb/Utility/ProcessInfo.h"
13*c9157d92SDimitry Andric 
14*c9157d92SDimitry Andric #include "Utils.h"
15*c9157d92SDimitry Andric 
16*c9157d92SDimitry Andric using namespace lldb;
17*c9157d92SDimitry Andric using namespace lldb_private;
18*c9157d92SDimitry Andric 
19*c9157d92SDimitry Andric SBProcessInfoList::SBProcessInfoList() = default;
20*c9157d92SDimitry Andric 
21*c9157d92SDimitry Andric SBProcessInfoList::~SBProcessInfoList() = default;
22*c9157d92SDimitry Andric 
SBProcessInfoList(const ProcessInfoList & impl)23*c9157d92SDimitry Andric SBProcessInfoList::SBProcessInfoList(const ProcessInfoList &impl)
24*c9157d92SDimitry Andric     : m_opaque_up(std::make_unique<ProcessInfoList>(impl)) {
25*c9157d92SDimitry Andric   LLDB_INSTRUMENT_VA(this, impl);
26*c9157d92SDimitry Andric }
27*c9157d92SDimitry Andric 
SBProcessInfoList(const lldb::SBProcessInfoList & rhs)28*c9157d92SDimitry Andric SBProcessInfoList::SBProcessInfoList(const lldb::SBProcessInfoList &rhs) {
29*c9157d92SDimitry Andric 
30*c9157d92SDimitry Andric   LLDB_INSTRUMENT_VA(this, rhs);
31*c9157d92SDimitry Andric 
32*c9157d92SDimitry Andric   m_opaque_up = clone(rhs.m_opaque_up);
33*c9157d92SDimitry Andric }
34*c9157d92SDimitry Andric 
35*c9157d92SDimitry Andric const lldb::SBProcessInfoList &
operator =(const lldb::SBProcessInfoList & rhs)36*c9157d92SDimitry Andric SBProcessInfoList::operator=(const lldb::SBProcessInfoList &rhs) {
37*c9157d92SDimitry Andric 
38*c9157d92SDimitry Andric   LLDB_INSTRUMENT_VA(this, rhs);
39*c9157d92SDimitry Andric 
40*c9157d92SDimitry Andric   if (this != &rhs)
41*c9157d92SDimitry Andric     m_opaque_up = clone(rhs.m_opaque_up);
42*c9157d92SDimitry Andric   return *this;
43*c9157d92SDimitry Andric }
44*c9157d92SDimitry Andric 
GetSize() const45*c9157d92SDimitry Andric uint32_t SBProcessInfoList::GetSize() const {
46*c9157d92SDimitry Andric   LLDB_INSTRUMENT_VA(this);
47*c9157d92SDimitry Andric 
48*c9157d92SDimitry Andric   if (m_opaque_up)
49*c9157d92SDimitry Andric     return m_opaque_up->GetSize();
50*c9157d92SDimitry Andric 
51*c9157d92SDimitry Andric   return 0;
52*c9157d92SDimitry Andric }
53*c9157d92SDimitry Andric 
Clear()54*c9157d92SDimitry Andric void SBProcessInfoList::Clear() {
55*c9157d92SDimitry Andric   LLDB_INSTRUMENT_VA(this);
56*c9157d92SDimitry Andric 
57*c9157d92SDimitry Andric   if (m_opaque_up)
58*c9157d92SDimitry Andric     m_opaque_up->Clear();
59*c9157d92SDimitry Andric }
60*c9157d92SDimitry Andric 
GetProcessInfoAtIndex(uint32_t idx,SBProcessInfo & info)61*c9157d92SDimitry Andric bool SBProcessInfoList::GetProcessInfoAtIndex(uint32_t idx,
62*c9157d92SDimitry Andric                                               SBProcessInfo &info) {
63*c9157d92SDimitry Andric   LLDB_INSTRUMENT_VA(this, idx, info);
64*c9157d92SDimitry Andric 
65*c9157d92SDimitry Andric   if (m_opaque_up) {
66*c9157d92SDimitry Andric     lldb_private::ProcessInstanceInfo process_instance_info;
67*c9157d92SDimitry Andric     if (m_opaque_up->GetProcessInfoAtIndex(idx, process_instance_info)) {
68*c9157d92SDimitry Andric       info.SetProcessInfo(process_instance_info);
69*c9157d92SDimitry Andric       return true;
70*c9157d92SDimitry Andric     }
71*c9157d92SDimitry Andric   }
72*c9157d92SDimitry Andric 
73*c9157d92SDimitry Andric   return false;
74*c9157d92SDimitry Andric }
75