~vorlon/platform-api/lp.1465958

« back to all changes in this revision

Viewing changes to src/ubuntu/application/common/mirserver/application_instance_mirserver.cpp

  • Committer: CI bot
  • Author(s): Alberto Aguirre
  • Date: 2014-11-26 17:40:42 UTC
  • mfrom: (283.2.2 stub-mirserver)
  • Revision ID: ps-jenkins@lists.canonical.com-20141126174042-t4fzmnag9rujcppz
Stub out mirserver backend 
Approved by: Gerry Boland, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013 Canonical Ltd
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify
5
 
 * it under the terms of the GNU Lesser General Public License version 3 as
6
 
 * published by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU Lesser General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU Lesser General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 * Authored by: Robert Carr <robert.carr@canonical.com>
17
 
 */
18
 
 
19
 
#include "application_instance_mirserver_priv.h"
20
 
 
21
 
#include "mircommon/application_description_mir_priv.h"
22
 
#include "mircommon/application_options_mir_priv.h"
23
 
#include "mircommon/application_id_mir_priv.h"
24
 
 
25
 
#include <mir/scene/surface.h>
26
 
#include <mir/scene/surface_coordinator.h>
27
 
#include <mir/scene/session.h>
28
 
#include <mir/scene/session_listener.h>
29
 
#include <mir/scene/surface_creation_parameters.h>
30
 
#include <mir/scene/snapshot.h>
31
 
 
32
 
namespace uam = ubuntu::application::mir;
33
 
namespace uams = uam::server;
34
 
 
35
 
namespace mf = mir::frontend;
36
 
namespace ms = mir::scene;
37
 
 
38
 
namespace
39
 
{
40
 
/* A Mir in-process client does not have an associated Session by default. However it is
41
 
 * useful for the shell to be able to position and identify its own surface, so need to
42
 
 * create a mock implementation of Session for that respective Surface.
43
 
 */
44
 
class InProcessClientSession : public ms::Session
45
 
{
46
 
public:
47
 
    virtual void force_requests_to_complete() override {}
48
 
    virtual pid_t process_id() const override { return 0; }
49
 
    virtual void take_snapshot(ms::SnapshotCallback const&) override {}
50
 
    virtual std::shared_ptr<ms::Surface> default_surface() const override { return surface; }
51
 
    virtual void set_lifecycle_state(MirLifecycleState) override {}
52
 
 
53
 
    virtual mf::SurfaceId create_surface(ms::SurfaceCreationParameters const& ) override { return mf::SurfaceId(0); }
54
 
    virtual void destroy_surface(mf::SurfaceId) override {}
55
 
    virtual std::shared_ptr<mf::Surface> get_surface(mf::SurfaceId) const override { return surface; }
56
 
    virtual std::string name() const override { return "Shell"; }
57
 
    virtual void hide() override {}
58
 
    virtual void show() override {}
59
 
    virtual void send_display_config(mir::graphics::DisplayConfiguration const&) override {}
60
 
 
61
 
    virtual void start_prompt_session() override {}
62
 
    virtual void stop_prompt_session() override {}
63
 
private:
64
 
    std::shared_ptr<ms::Surface> const surface;
65
 
};
66
 
 
67
 
InProcessClientSession& global_session()
68
 
{
69
 
    static InProcessClientSession session;
70
 
    return session;
71
 
}
72
 
}
73
 
 
74
 
uams::Instance::Instance(std::shared_ptr<ms::SurfaceCoordinator> const &surface_coordinator,
75
 
                         std::shared_ptr<ms::SessionListener> const &session_listener,
76
 
                         uam::Description* description_,
77
 
                         uam::Options *options_)
78
 
    : surface_coordinator(surface_coordinator),
79
 
      session_listener(session_listener),
80
 
      ref_count(1)
81
 
{
82
 
    description = DescriptionPtr(description_,
83
 
        [] (uam::Description* p)
84
 
        {
85
 
            delete p;
86
 
        });
87
 
    options = OptionsPtr(options_,
88
 
        [] (uam::Options* p)
89
 
        {
90
 
            delete p;
91
 
        });
92
 
}
93
 
 
94
 
UApplicationInstance* uams::Instance::as_u_application_instance()
95
 
{
96
 
    return static_cast<UApplicationInstance*>(this);
97
 
}
98
 
 
99
 
uams::Instance* uams::Instance::from_u_application_instance(UApplicationInstance *u_instance)
100
 
{
101
 
    return static_cast<uams::Instance*>(u_instance);
102
 
}
103
 
 
104
 
void uams::Instance::ref()
105
 
{
106
 
    ref_count++;
107
 
}
108
 
 
109
 
void uams::Instance::unref()
110
 
{
111
 
    ref_count--;
112
 
    if (ref_count == 0)
113
 
        delete this;
114
 
}
115
 
 
116
 
std::shared_ptr<ms::Surface> uams::Instance::create_surface(ms::SurfaceCreationParameters const& parameters)
117
 
{
118
 
    ms::Session& session = global_session();
119
 
    auto surface = surface_coordinator->add_surface(parameters, &session);
120
 
    // Need to call the SessionListener ourselves, else shell not notified of this surface creation
121
 
    session_listener->surface_created(session, surface);
122
 
    return surface;
123
 
}