1 // ServerQueryIterator.cpp
2
3 #include "ServerQueryIterator.h"
4
5 #include <new>
6
7 // constructor
ServerQueryIterator(Volume * volume)8 ServerQueryIterator::ServerQueryIterator(Volume* volume)
9 : QueryIterator(volume),
10 fRemoteCookie(-1),
11 fShareVolumeIDs(NULL),
12 fShareVolumeCount(0),
13 fShareVolumeIndex(0)
14 {
15 }
16
17 // destructor
~ServerQueryIterator()18 ServerQueryIterator::~ServerQueryIterator()
19 {
20 }
21
22 // SetRemoteCookie
23 void
SetRemoteCookie(int32 cookie)24 ServerQueryIterator::SetRemoteCookie(int32 cookie)
25 {
26 fRemoteCookie = cookie;
27 }
28
29 // GetRemoteCookie
30 int32
GetRemoteCookie() const31 ServerQueryIterator::GetRemoteCookie() const
32 {
33 return fRemoteCookie;
34 }
35
36 // SetEntry
37 status_t
SetEntry(const int32 * shareVolumeIDs,int32 shareVolumeCount,const NodeInfo & dirInfo,const EntryInfo & entryInfo)38 ServerQueryIterator::SetEntry(const int32* shareVolumeIDs,
39 int32 shareVolumeCount, const NodeInfo& dirInfo,
40 const EntryInfo& entryInfo)
41 {
42 UnsetEntry();
43
44 if (!shareVolumeIDs || shareVolumeCount <= 0)
45 return B_BAD_VALUE;
46
47 // copy volume IDs
48 if (shareVolumeCount <= IN_OBJECT_ID_COUNT)
49 fShareVolumeIDs = fInObjectIDs;
50 else
51 fShareVolumeIDs = new(std::nothrow) int32[shareVolumeCount];
52 if (!fShareVolumeIDs)
53 return B_NO_MEMORY;
54 fShareVolumeCount = shareVolumeCount;
55 memcpy(fShareVolumeIDs, shareVolumeIDs, shareVolumeCount * 4);
56
57 // copy entry name
58 if (!fEntryName.SetTo(entryInfo.name.GetString())) {
59 UnsetEntry();
60 return B_NO_MEMORY;
61 }
62
63 fDirectoryInfo = dirInfo;
64 fEntryInfo = entryInfo;
65 fEntryInfo.name.SetTo(fEntryName.GetString());
66
67 return B_OK;
68 }
69
70 // UnsetEntry
71 void
UnsetEntry()72 ServerQueryIterator::UnsetEntry()
73 {
74 if (fShareVolumeIDs && fShareVolumeIDs != fInObjectIDs)
75 delete[] fShareVolumeIDs;
76 fShareVolumeIDs = NULL;
77
78 fShareVolumeCount = 0;
79 fShareVolumeIndex = 0;
80 fEntryName.Unset();
81 fEntryInfo.name.SetTo(NULL);
82 }
83
84 // GetShareVolumeIDs
85 const int32*
GetShareVolumeIDs() const86 ServerQueryIterator::GetShareVolumeIDs() const
87 {
88 return fShareVolumeIDs;
89 }
90
91 // CountShareVolumes
92 int32
CountShareVolumes() const93 ServerQueryIterator::CountShareVolumes() const
94 {
95 return fShareVolumeCount;
96 }
97
98 // GetDirectoryInfo
99 const NodeInfo&
GetDirectoryInfo() const100 ServerQueryIterator::GetDirectoryInfo() const
101 {
102 return fDirectoryInfo;
103 }
104
105 // GetEntryInfo
106 const EntryInfo&
GetEntryInfo() const107 ServerQueryIterator::GetEntryInfo() const
108 {
109 return fEntryInfo;
110 }
111
112 // HasNextShareVolumeID
113 bool
HasNextShareVolumeID() const114 ServerQueryIterator::HasNextShareVolumeID() const
115 {
116 return (fShareVolumeIDs && fShareVolumeIndex < fShareVolumeCount);
117 }
118
119 // NextShareVolumeID
120 int32
NextShareVolumeID()121 ServerQueryIterator::NextShareVolumeID()
122 {
123 if (!fShareVolumeIDs || fShareVolumeIndex >= fShareVolumeCount)
124 return B_ENTRY_NOT_FOUND;
125
126 return fShareVolumeIDs[fShareVolumeIndex++];
127 }
128