1 /* 2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include <Application.h> 7 #include <TokenSpace.h> 8 9 #include "AppInfoListMessagingTargetSet.h" 10 #include "RosterAppInfo.h" 11 12 // constructor 13 AppInfoListMessagingTargetSet::AppInfoListMessagingTargetSet( 14 AppInfoList &list, bool skipRegistrar) 15 : fList(list), 16 fIterator(list.It()), 17 fSkipRegistrar(skipRegistrar) 18 { 19 _SkipFilteredOutInfos(); 20 } 21 22 // destructor 23 AppInfoListMessagingTargetSet::~AppInfoListMessagingTargetSet() 24 { 25 } 26 27 // HasNext 28 bool 29 AppInfoListMessagingTargetSet::HasNext() const 30 { 31 return fIterator.IsValid(); 32 } 33 34 // Next 35 bool 36 AppInfoListMessagingTargetSet::Next(port_id &port, int32 &token) 37 { 38 if (!fIterator.IsValid()) 39 return false; 40 41 port = (*fIterator)->port; 42 token = B_PREFERRED_TOKEN; 43 44 ++fIterator; 45 _SkipFilteredOutInfos(); 46 47 return true; 48 } 49 50 // Rewind 51 void 52 AppInfoListMessagingTargetSet::Rewind() 53 { 54 fIterator = fList.It(); 55 } 56 57 // Filter 58 bool 59 AppInfoListMessagingTargetSet::Filter(const RosterAppInfo *info) 60 { 61 if (!fSkipRegistrar) 62 return true; 63 64 return (!fSkipRegistrar || info->team != be_app->Team()); 65 } 66 67 // _SkipFilteredOutInfos 68 void 69 AppInfoListMessagingTargetSet::_SkipFilteredOutInfos() 70 { 71 while (fIterator.IsValid() && !Filter(*fIterator)) 72 ++fIterator; 73 } 74 75