27 t.setNsNameValue(
"alloc",
"tmpid",
"*");
29 context.
setRid(db->find(
t,
nullptr));
31 t.setNsNameValue(
"alloc",
"*",
"free");
32 list<Triple> match = db->query(
t,&context);
34 name = match.begin()->name;
40 t.setNsNameValue(
"alloc",
"tmpid",
"*");
41 list<Triple> lst = db->query(
t,
nullptr);
43 tmpid = atoi(lst.begin()->value.c_str());
51 std::snprintf(buf, 256,
"%d", tmpid);
52 t.setNsNameValue(
"alloc",
"tmpid",buf);
53 db->update(
t,
nullptr);
54 t.setNsNameValue(
"alloc",
"tmpid",
"*");
55 context.
setRid(db->find(
t,
nullptr));
56 std::snprintf(buf, 256,
"/tmp/port/%u", tmpid);
60 t.setNsNameValue(
"alloc",name.c_str(),
"in_use");
61 db->update(
t,&context);
72 return completePortNumber(tmp);
91 t.setNsNameValue(
"alloc",
"regid",
"*");
93 context.
setRid(db->find(
t,
nullptr));
95 t.setNsNameValue(
"prefer",
"*",c.
getName().c_str());
96 list<Triple> match = db->query(
t,&context);
98 npref = match.begin()->name;
99 pref = atoi(npref.c_str());
100 t.setNsNameValue(
"alloc",npref.c_str(),
"in_use");
101 match = db->query(
t,&context);
102 if (match.size()==0) {
112 t.setNsNameValue(
"alloc",
"regid",
"*");
113 list<Triple> lst = db->query(
t,
nullptr);
115 regid = atoi(lst.begin()->value.c_str());
118 regid = config.minPortNumber-1;
121 if (regid>=config.maxPortNumber && config.maxPortNumber!=0) {
123 t.setNsNameValue(
"alloc",
"*",
"free");
124 list<Triple> match = db->query(
t,&context);
125 if (match.size()>0) {
126 nstring = match.begin()->name;
127 number = atoi(nstring.c_str());
131 yCError(ALLOCATORONTRIPLES,
"Ran out of port numbers");
132 yCError(ALLOCATORONTRIPLES,
"* Make sure ports/programs get closed properly.");
133 yCError(ALLOCATORONTRIPLES,
"* If programs terminate without closing ports, run \"yarp clean\" from time to time..");
140 std::snprintf(buf, 256,
"%d", regid);
141 t.setNsNameValue(
"alloc",
"regid",buf);
142 db->update(
t,
nullptr);
143 t.setNsNameValue(
"alloc",
"regid",
"*");
144 context.
setRid(db->find(
t,
nullptr));
149 t.setNsNameValue(
"alloc",nstring.c_str(),
"in_use");
150 db->update(
t,&context);
151 t.setNsNameValue(
"prefer",nstring.c_str(),c.
getName().c_str());
152 db->update(
t,&context);
172 t.setNsNameValue(
"alloc",
"mcastCursor",
"*");
174 context.
setRid(db->find(
t,
nullptr));
175 if (context.
rid>=0) {
176 t.setNsNameValue(
"alloc",
"*",
"free");
177 list<Triple> match = db->query(
t,&context);
178 if (match.size()>0) {
179 name = match.begin()->name;
184 if (mcastCursor==-1) {
185 t.setNsNameValue(
"alloc",
"mcastCursor",
"*");
186 list<Triple> lst = db->query(
t,
nullptr);
188 mcastCursor = atoi(lst.begin()->value.c_str());
190 if (mcastCursor==-1) {
196 std::snprintf(buf, 256,
"%d", mcastCursor);
197 t.setNsNameValue(
"alloc",
"mcastCursor",buf);
198 db->update(
t,
nullptr);
199 t.setNsNameValue(
"alloc",
"mcastCursor",
"*");
200 context.
setRid(db->find(
t,
nullptr));
202 int v1 = mcastCursor%255;
203 int v2 = mcastCursor/255;
205 yCError(ALLOCATORONTRIPLES,
"Ran out of mcast addresses");
208 std::snprintf(buf, 256,
"224.1.%d.%d", v2+1, v1+1);
212 t.setNsNameValue(
"alloc",name.c_str(),
"in_use");
213 db->update(
t,&context);
228 t.setNsNameValue(
"alloc",
"tmpid",
"*");
230 context.
setRid(db->find(
t,
nullptr));
231 t.setNsNameValue(
"alloc",portName.c_str(),
"in_use");
232 if (db->find(
t,&context)>=0) {
233 t.setNsNameValue(
"alloc",portName.c_str(),
"free");
234 db->update(
t,&context);
237 t.setNsNameValue(
"alloc",
"regid",
"*");
238 context.
setRid(db->find(
t,
nullptr));
240 std::snprintf(buf, 256,
"%d", portNumber);
241 t.setNsNameValue(
"alloc",buf,
"in_use");
242 if (db->find(
t,&context)>=0) {
243 t.setNsNameValue(
"alloc",buf,
"free");
244 db->update(
t,&context);
247 t.setNsNameValue(
"alloc",
"mcastCursor",
"*");
248 context.
setRid(db->find(
t,
nullptr));
249 t.setNsNameValue(
"alloc",hostName.c_str(),
"in_use");
250 if (db->find(
t,&context)>=0) {
251 t.setNsNameValue(
"alloc",hostName.c_str(),
"free");
252 db->update(
t,&context);