/* * Copyright (C) 2017 Mentor Graphics Development (Deutschland) GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include "util.hpp" #include "wayland.hpp" #include "hmi-debug.h" // _ // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___ __ _| | // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / | // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/ \ V V /| | // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| \_/\_/ |_| // |_| namespace wl { // _ _ _ // __| (_)___ _ __ | | __ _ _ _ // / _` | / __| '_ \| |/ _` | | | | // | (_| | \__ \ |_) | | (_| | |_| | // \__,_|_|___/ .__/|_|\__,_|\__, | // |_| |___/ display::display() : d(std::unique_ptr( wl_display_connect(nullptr), &wl_display_disconnect)), r(d.get()) {} bool display::ok() const { return d && wl_display_get_error(d.get()) == 0; } void display::roundtrip() { wl_display_roundtrip(this->d.get()); } int display::dispatch() { return wl_display_dispatch(this->d.get()); } int display::dispatch_pending() { return wl_display_dispatch_pending(this->d.get()); } int display::read_events() { ST(); // XXX: uhm, how?! while (wl_display_prepare_read(this->d.get()) == -1) { STN(pending_events_dispatch); if (wl_display_dispatch_pending(this->d.get()) == -1) { return -1; } } if (wl_display_flush(this->d.get()) == -1) { return -1; } if (wl_display_read_events(this->d.get()) == -1) { wl_display_cancel_read(this->d.get()); } return 0; } void display::flush() { wl_display_flush(this->d.get()); } int display::get_fd() const { return wl_display_get_fd(this->d.get()); } int display::get_error() { return wl_display_get_error(this->d.get()); } // _ _ // _ __ ___ __ _(_)___| |_ _ __ _ _ // | '__/ _ \/ _` | / __| __| '__| | | | // | | | __/ (_| | \__ \ |_| | | |_| | // |_| \___|\__, |_|___/\__|_| \__, | // |___/ |___/ namespace { void registry_global(void *data, struct wl_registry * /*r*/, uint32_t name, char const *iface, uint32_t v) { static_cast(data)->global(name, iface, v); } void registry_global_remove(void *data, struct wl_registry * /*r*/, uint32_t name) { static_cast(data)->global_remove(name); } constexpr struct wl_registry_listener registry_listener = { registry_global, registry_global_remove}; } // namespace registry::registry(struct wl_display *d) : wayland_proxy(d == nullptr ? nullptr : wl_display_get_registry(d)) { if (this->proxy != nullptr) { wl_registry_add_listener(this->proxy.get(), ®istry_listener, this); } } void registry::add_global_handler(char const *iface, binder bind) { this->bindings[iface] = std::move(bind); } void registry::global(uint32_t name, char const *iface, uint32_t v) { auto b = this->bindings.find(iface); if (b != this->bindings.end()) { b->second(this->proxy.get(), name, v); } HMI_DEBUG("wm", "wl::registry @ %p global n %u i %s v %u", this->proxy.get(), name, iface, v); } void registry::global_remove(uint32_t /*name*/) {} // _ _ // ___ _ _| |_ _ __ _ _| |_ // / _ \| | | | __| '_ \| | | | __| // | (_) | |_| | |_| |_) | |_| | |_ // \___/ \__,_|\__| .__/ \__,_|\__| // |_| namespace { void output_geometry(void *data, struct wl_output * /*wl_output*/, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char *make, const char *model, int32_t transform) { static_cast(data)->geometry( x, y, physical_width, physical_height, subpixel, make, model, transform); } void output_mode(void *data, struct wl_output * /*wl_output*/, uint32_t flags, int32_t width, int32_t height, int32_t refresh) { static_cast(data)->mode(flags, width, height, refresh); } void output_done(void *data, struct wl_output * /*wl_output*/) { static_cast(data)->done(); } void output_scale(void *data, struct wl_output * /*wl_output*/, int32_t factor) { static_cast(data)->scale(factor); } constexpr struct wl_output_listener output_listener = { output_geometry, output_mode, output_done, output_scale}; } // namespace output::output(struct wl_registry *r, uint32_t name, uint32_t v) : wayland_proxy(wl_registry_bind(r, name, &wl_output_interface, v)) { wl_output_add_listener(this->proxy.get(), &output_listener, this); } void output::geometry(int32_t x, int32_t y, int32_t pw, int32_t ph, int32_t subpel, char const *make, char const *model, int32_t tx) { HMI_DEBUG("wm", "wl::output %s @ %p x %i y %i w %i h %i spel %x make %s model %s tx %i", __func__, this->proxy.get(), x, y, pw, ph, subpel, make, model, tx); this->transform = tx; } void output::mode(uint32_t flags, int32_t w, int32_t h, int32_t r) { HMI_DEBUG("wm", "wl::output %s @ %p f %x w %i h %i r %i", __func__, this->proxy.get(), flags, w, h, r); if ((flags & WL_OUTPUT_MODE_CURRENT) != 0u) { this->width = w; this->height = h; this->refresh = r; } } void output::done() { HMI_DEBUG("wm", "wl::output %s @ %p done", __func__, this->proxy.get()); // Let's just disregard the flipped ones... if (this->transform == WL_OUTPUT_TRANSFORM_90 || this->transform == WL_OUTPUT_TRANSFORM_270) { std::swap(this->width, this->height); } } void output::scale(int32_t factor) { HMI_DEBUG("wm", "wl::output %s @ %p f %i", __func__, this->proxy.get(), factor); } } // namespace wl // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___ // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/ // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| // |_| // _ _ // __ _ ___ _ __ (_)_ _(_) // / _` |/ _ \ '_ \| \ \ / / | // | (_| | __/ | | | |\ V /| | // \__, |\___|_| |_|_| \_/ |_| // |___/ namespace genivi { // _ _ _ // ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __ // / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__| // | (_| (_) | | | | |_| | | (_) | | | __/ | // \___\___/|_| |_|\__|_| \___/|_|_|\___|_| // namespace { void controller_screen(void *data, struct ivi_controller * /*ivi_controller*/, uint32_t id_screen, struct ivi_controller_screen *screen) { static_cast(data)->controller_screen(id_screen, screen); } void controller_layer(void *data, struct ivi_controller * /*ivi_controller*/, uint32_t id_layer) { static_cast(data)->controller_layer(id_layer); } void controller_surface(void *data, struct ivi_controller * /*ivi_controller*/, uint32_t id_surface) { static_cast(data)->controller_surface(id_surface); } void controller_error(void *data, struct ivi_controller * /*ivi_controller*/, int32_t object_id, int32_t object_type, int32_t error_code, const char *error_text) { static_cast(data)->controller_error( object_id, object_type, error_code, error_text); } constexpr struct ivi_controller_listener listener = { controller_screen, controller_layer, controller_surface, controller_error}; } // namespace controller::controller(struct wl_registry *r, uint32_t name, uint32_t version) : wayland_proxy( wl_registry_bind(r, name, &ivi_controller_interface, version)), output_size{} { ivi_controller_add_listener(this->proxy.get(), &listener, this); } void controller::layer_create(uint32_t id, int32_t w, int32_t h) { this->layers[id] = std::make_unique(id, w, h, this); } void controller::surface_create(uint32_t id) { this->surfaces[id] = std::make_unique(id, this); } void controller::controller_
dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4:
;---------------------------------------------------------------------------------
;----         M A I N    P A R T    O F   T H E   S E R V I C E               ----
;---------------------------------------------------------------------------------
%begin systemd-unit

# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}}
%nl

%systemd-unit system
%systemd-unit service UNIT_NAME_BASE

[Unit]
Description={{description}}
X-AFM-description={{description}}
X-AFM-name={{name.content}}
X-AFM-shortname={{name.short}}
X-AFM-id=TARGET
X-AFM-version={{:version}}
X-AFM-author={{author.content}}
X-AFM-author-email={{author.email}}
X-AFM-width={{width}}
X-AFM-height={{height}}
{{#icon}}
X-AFM-icon={{:#metadata.install-dir}}/{{:src}}
{{/icon}}
X-AFM--ID={{:id}}
X-AFM--target-name={{:#target}}
X-AFM--content={{content.src}}
X-AFM--type={{content.type}}
X-AFM--wgtdir={{:#metadata.install-dir}}
X-AFM--workdir=APP_DATA_DIR/{{:id}}
%nl

Requires=afm-user-session@%i.target
After=user@%i.service

# Adds check to smack
ConditionSecurity=smack
%nl

# Automatic bound to required api
{{#required-api}}
{{#value=auto|ws}}
BindsTo=UNIT_NAME_SOCKET_FOR({{name}})
After=UNIT_NAME_SOCKET_FOR({{name}})
{{/value=auto|ws}}
{{/required-api}}
{{#provided-api}}
{{#value=ws|auto}}
Requires=UNIT_NAME_SOCKET_FOR({{name}})
After=UNIT_NAME_SOCKET_FOR({{name}})
{{/value=ws|auto}}
{{/provided-api}}

%nl

[Service]
EnvironmentFile=-AFM_CONFIG_DIR/unit.env.d/*
SmackProcessLabel=User::App::{{:id}}
SuccessExitStatus=0 SIGKILL

User=%i
Slice=user-%i.slice

#CapabilityBoundingSet=
#AmbientCapabilities=

ON_PERM(:platform:no-oom,   OOMScoreAdjust=-500)
ON_PERM(:partner:real-time, IOSchedulingClass=realtime)
ON_PERM(:public:display,    SupplementaryGroups=display)
ON_PERM(:public:syscall:clock, , SystemCallFilter=~@clock)
%nl

WorkingDirectory=-APP_DATA_DIR/{{:id}}
ExecStartPre=/bin/mkdir -p APP_DATA_DIR/{{:id}}
Environment=AFM_APP_INSTALL_DIR={{:#metadata.install-dir}}
Environ