-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnameserver.cc
61 lines (51 loc) · 1.61 KB
/
nameserver.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "nameserver.h"
#include <assert.h>
#include "vendingmachine.h"
#include "printer.h"
using namespace std;
NameServer::NameServer( Printer &prt, unsigned int numVendingMachines, unsigned int numStudents )
:prt(prt),numVendingMachines(numVendingMachines),numStudents(numStudents),matchNext(numVendingMachines-1),fillposition(0)
{
machines=new VendingMachine*[numVendingMachines];
}
NameServer::~NameServer(){
delete []machines;
}
void NameServer::VMregister(VendingMachine* vendingmachine){
//machines.push_back(vendingmachine);
prt.print(Printer::NameServer,'R',fillposition);
machines[fillposition]=vendingmachine;
fillposition++;
assert(fillposition<=numVendingMachines+1);//exceed max amount
}
void NameServer::advance(){
assert(numVendingMachines!=0);
if(matchNext==(numVendingMachines-1)){
matchNext=0;
}
else{
matchNext++;
}
}
VendingMachine* NameServer::getMachine( unsigned int id ){
advance();
assert(matchNext<fillposition);//within position i filled
prt.print(Printer::NameServer,'N',id,matchNext);
return machines[matchNext];
}
VendingMachine** NameServer::getMachineList(){
return machines;
}
void NameServer::main(){
prt.print(Printer::NameServer,'S');
while(true){
//mysize=machines.size();
_Accept(~NameServer) break;
//or _When(==numVendingMachine) _Accept(getMachine,getMachineList);
//or _When(true) _Accept(VMregister);//??? right way?
or _When(matchNext<=fillposition) _Accept(getMachine);
or _When(fillposition==(numVendingMachines)) _Accept(getMachineList);
or _Accept(VMregister);
}
prt.print(Printer::NameServer,'F');
}