Savarese Software Research Corporation
BaseMessage.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2006 Savarese Software Research Corporation
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.savarese.com/software/ApacheLicense-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 
19 
21 
22 #ifdef LIBSSRCSPREAD_ENABLE_MEMBERSHIP_INFO
23 
31 void BaseMessage::get_vs_set_members(const Spread::vs_set_info *vs_set,
32  GroupList *members,
33  unsigned int offset) const
34 {
35  int result;
36 
37  members->resize(members->capacity());
38 
39  try_again:
40  result =
41  sp_get_vs_set_members(vs_set, members->groups() + offset,
42  members->size() - offset);
43 
44  if(result == Error::BufferTooShort) {
45  result = vs_set->num_members;
46  if(result > 0) {
47  members->resize(offset + result);
48  goto try_again;
49  } else
50  members->resize(offset);
51  } else if(result > 0)
52  members->resize(offset + result);
53  else
54  members->resize(offset);
55 }
56 
70 void BaseMessage::get_membership_info(MembershipInfo & info) const
71  SSRC_DECL_THROW(Error)
72 {
73  int result = sp_get_membership_info(&info._info);
74 
75  if(result <= 0)
76  throw Error(result);
77 
78  info.set_service(service());
79 
80  get_vs_set_members(&info._info.my_vs_set, &info._local_members);
81 
82  if(info._info.num_vs_sets > 0) {
83  detail::Buffer<Spread::vs_set_info> vs_sets(info._info.num_vs_sets);
84  unsigned int index = 0;
85 
86  vs_sets.resize(info._info.num_vs_sets);
87  result = sp_get_vs_sets_info(&vs_sets[0], vs_sets.size(), &index);
88 
89  if(result > 0) {
90 
91  // Just in case.
92  if(static_cast<unsigned int>(result) != vs_sets.size())
93  vs_sets.resize(result);
94 
95  info._non_local_members.clear();
96 
97  for(int i = 0; i < result; ++i) {
98  if(static_cast<unsigned int>(i) != index)
99  get_vs_set_members(&vs_sets[i], &info._non_local_members,
100  info._non_local_members.size());
101  }
102 
103  } else
104  throw Error(result);
105  }
106 }
107 
108 #endif
109 

Savarese Software Research Corporation
Copyright © 2006-2015 Savarese Software Research Corporation. All rights reserved.