Server.cpp
1.43 KB
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
62
63
64
65
66
67
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
#include <Ice/Ice.h>
#include <Printer.h>
#include "EvictorBase.h"
using namespace std;
using namespace Demo;
class PrinterI : public Printer
{
std::string name;
public:
PrinterI(const std::string& a) : name(a) {};
virtual void printString(string s, const Ice::Current&) override;
void shutdown(const Ice::Current& c) override
{
cout << "Shutting down..." << endl;
c.adapter->getCommunicator()->shutdown();
}
};
void
PrinterI::printString(string s, const Ice::Current&)
{
cout << name << ":" << s << endl;
}
class myEvictor: public EvictorBase
{
virtual std::shared_ptr<Ice::Object> add(const Ice::Current& c, std::shared_ptr<void>&) override
{
cout << "Adding new servant" << endl;
return make_shared<PrinterI>(c.id.name);
}
virtual void evict(const std::shared_ptr<Ice::Object>&, const std::shared_ptr<void>&) override
{
}
};
int
main(int argc, char* argv[])
{
try
{
Ice::CommunicatorHolder ich(argc, argv);
auto adapter = ich->createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -p 10000");
auto evictor = make_shared<myEvictor>();
adapter->addServantLocator(evictor,"");
adapter->activate();
ich->waitForShutdown();
}
catch(const std::exception& e)
{
cerr << e.what() << endl;
return 1;
}
return 0;
}