summaryrefslogtreecommitdiff
path: root/cpp/demo/IceGrid/icebox/HelloI.cpp
blob: 1e96d635ba9c6b2f4ef2b07e9fa6d494a81bd80d (plain)
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
// **********************************************************************
//
// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#include <Ice/Ice.h>
#include <HelloI.h>

using namespace std;

HelloI::HelloI(const string& serviceName) :
    _serviceName(serviceName)
{
}

void
HelloI::sayHello(const Ice::Current&)
{
#ifdef _WIN32
    vector<wchar_t> buf;
    buf.resize(1024);
    DWORD val = GetEnvironmentVariableW(L"LANG", &buf[0], static_cast<DWORD>(buf.size()));
    string lang = (val > 0 && val < buf.size()) ?
        IceUtil::wnativeToNative(IceUtil::getProcessStringConverter(), 0, &buf[0]) : string("en");
#else
    char* val = getenv("LANG");
    string lang = val ? string(val) : "en";
#endif

    string greeting = "Hello, ";
    if(lang == "fr")
    {
        greeting = "Bonjour, ";
    }
    else if(lang == "de")
    {
        greeting = "Hallo, ";
    }
    else if(lang == "es")
    {
        greeting = "Hola, ";
    }
    else if(lang == "it")
    {
        greeting = "Ciao, ";
    }
    cout << greeting << _serviceName << endl;
}