~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to cpp/demo/book/map_filesystem/Server.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cleto Martin Angelina
  • Date: 2011-04-25 18:44:24 UTC
  • mfrom: (6.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110425184424-sep9i9euu434vq4c
Tags: 3.4.1-7
* Bug fix: "libdb5.1-java.jar was renamed to db.jar", thanks to Ondřej
  Surý (Closes: #623555).
* Bug fix: "causes noise in php5", thanks to Jayen Ashar (Closes:
  #623533).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// **********************************************************************
 
2
//
 
3
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
 
4
//
 
5
// This copy of Ice is licensed to you under the terms described in the
 
6
// ICE_LICENSE file included in this distribution.
 
7
//
 
8
// **********************************************************************
 
9
 
 
10
#include <FilesystemI.h>
 
11
#include <IdentityFileEntryMap.h>
 
12
#include <IdentityDirectoryEntryMap.h>
 
13
#include <Ice/Application.h>
 
14
#include <Freeze/Freeze.h>
 
15
 
 
16
using namespace std;
 
17
using namespace Filesystem;
 
18
using namespace FilesystemDB;
 
19
 
 
20
class FilesystemApp : public virtual Ice::Application
 
21
{
 
22
public:
 
23
 
 
24
    FilesystemApp(const string& envName)
 
25
        : _envName(envName)
 
26
    {
 
27
    }
 
28
 
 
29
    virtual int run(int, char*[])
 
30
    {
 
31
        //
 
32
        // Terminate cleanly on receipt of a signal
 
33
        //
 
34
        shutdownOnInterrupt();
 
35
 
 
36
        //
 
37
        // Create an object adapter
 
38
        //
 
39
        Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("MapFilesystem");
 
40
 
 
41
        //
 
42
        // Open a connection to the files and directories database. This should remain open
 
43
        // for the duration of the application for performance reasons.
 
44
        //
 
45
        const Freeze::ConnectionPtr connection(Freeze::createConnection(communicator(), _envName));
 
46
        const IdentityFileEntryMap fileDB(connection, FileI::filesDB());
 
47
        const IdentityDirectoryEntryMap dirDB(connection, DirectoryI::directoriesDB());
 
48
 
 
49
        //
 
50
        // Add default servants for the file and directory.
 
51
        //
 
52
        adapter->addDefaultServant(new FileI(communicator(), _envName), "file");
 
53
        adapter->addDefaultServant(new DirectoryI(communicator(), _envName), "");
 
54
 
 
55
        //
 
56
        // Ready to accept requests now
 
57
        //
 
58
        adapter->activate();
 
59
 
 
60
        //
 
61
        // Wait until we are done
 
62
        //
 
63
        communicator()->waitForShutdown();
 
64
 
 
65
        //
 
66
        // Clean up
 
67
        //
 
68
        if(interrupted())
 
69
        {
 
70
            cerr << appName() << ": received signal, shutting down" << endl;
 
71
        }
 
72
 
 
73
        return 0;
 
74
    }
 
75
 
 
76
private:
 
77
 
 
78
    string _envName;
 
79
};
 
80
 
 
81
int
 
82
main(int argc, char* argv[])
 
83
{
 
84
    FilesystemApp app("db");
 
85
    return app.main(argc, argv, "config.server");
 
86
}