1 // ServerQueryIterator.cpp 2 3 #include "ServerQueryIterator.h" 4 5 #include <new> 6 7 // constructor 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 18 ServerQueryIterator::~ServerQueryIterator() 19 { 20 } 21 22 // SetRemoteCookie 23 void 24 ServerQueryIterator::SetRemoteCookie(int32 cookie) 25 { 26 fRemoteCookie = cookie; 27 } 28 29 // GetRemoteCookie 30 int32 31 ServerQueryIterator::GetRemoteCookie() const 32 { 33 return fRemoteCookie; 34 } 35 36 // SetEntry 37 status_t 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 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* 86 ServerQueryIterator::GetShareVolumeIDs() const 87 { 88 return fShareVolumeIDs; 89 } 90 91 // CountShareVolumes 92 int32 93 ServerQueryIterator::CountShareVolumes() const 94 { 95 return fShareVolumeCount; 96 } 97 98 // GetDirectoryInfo 99 const NodeInfo& 100 ServerQueryIterator::GetDirectoryInfo() const 101 { 102 return fDirectoryInfo; 103 } 104 105 // GetEntryInfo 106 const EntryInfo& 107 ServerQueryIterator::GetEntryInfo() const 108 { 109 return fEntryInfo; 110 } 111 112 // HasNextShareVolumeID 113 bool 114 ServerQueryIterator::HasNextShareVolumeID() const 115 { 116 return (fShareVolumeIDs && fShareVolumeIndex < fShareVolumeCount); 117 } 118 119 // NextShareVolumeID 120 int32 121 ServerQueryIterator::NextShareVolumeID() 122 { 123 if (!fShareVolumeIDs || fShareVolumeIndex >= fShareVolumeCount) 124 return B_ENTRY_NOT_FOUND; 125 126 return fShareVolumeIDs[fShareVolumeIndex++]; 127 } 128