/
configuration.cpp
76 lines (70 loc) · 2.53 KB
/
configuration.cpp
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
68
69
70
71
72
73
74
75
76
#include <omero/client.h>
#include <iostream>
int main(int argc, char* argv[]) {
// All configuration in file pointed to by
// --Ice.Config=file.config
// No username, password entered
try {
omero::client client1(argc, argv);
client1.createSession();
client1.closeSession();
} catch (const Glacier2::PermissionDeniedException& pd) {
// Bad password?
} catch (const Ice::ConnectionRefusedException& cre) {
// Bad address or port?
}
// Most basic configuration.
// Uses default port 4064
// createSession needs username and password
try {
omero::client client2("localhost");
client2.createSession("root", "ome");
client2.closeSession();
} catch (const Glacier2::PermissionDeniedException& pd) {
// Bad password?
} catch (const Ice::ConnectionRefusedException& cre) {
// Bad address or port?
}
// Configuration with port information
try {
omero::client client3("localhost", 24063);
client3.createSession("root", "ome");
client3.closeSession();
} catch (const Glacier2::PermissionDeniedException& pd) {
// Bad password?
} catch (const Ice::ConnectionRefusedException& cre) {
// Bad address or port?
}
// Advanced configuration in C++ takes place
// via an InitializationData instance.
try {
Ice::InitializationData data;
data.properties = Ice::createProperties();
data.properties->setProperty("omero.host", "localhost");
omero::client client4(data);
client4.createSession("root", "ome");
client4.closeSession();
} catch (const Glacier2::PermissionDeniedException& pd) {
// Bad password?
} catch (const Ice::ConnectionRefusedException& cre) {
// Bad address or port?
}
// std::map to be added (ticket:1278)
try {
Ice::InitializationData data;
data.properties = Ice::createProperties();
data.properties->setProperty("omero.host", "localhost");
data.properties->setProperty("omero.user", "root");
data.properties->setProperty("omero.pass", "ome");
omero::client client5(data);
// Again, no username or password needed
// since present in the data. But they *can*
// be overridden.
client5.createSession();
client5.closeSession();
} catch (const Glacier2::PermissionDeniedException& pd) {
// Bad password?
} catch (const Ice::ConnectionRefusedException& cre) {
// Bad address or port?
}
}