./ 0000755 0000041 0000041 00000000000 13070664454 011254 5 ustar www-data www-data ./CMakeLists.txt 0000644 0000041 0000041 00000015233 13070664454 014020 0 ustar www-data www-data cmake_minimum_required(VERSION 2.8.10)
# Default install location. Must be set here, before setting the project.
if (NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "" FORCE)
endif()
project(unity-api C CXX)
if(${PROJECT_BINARY_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
message(FATAL_ERROR "In-tree build attempt detected, aborting. Set your build dir outside your source dir, delete CMakeCache.txt from source root and try again.")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lower) # Build types should always be lowercase but sometimes they are not.
include(PrecompiledHeaders)
include(EnableCoverageReport)
#####################################################################
# Enable code coverage calculation with gcov/gcovr/lcov
# Usage:
# * Switch build type to coverage (use ccmake or cmake-gui)
# * Invoke make, make test, make coverage (or ninja if you use that backend)
# * Find html report in subdir coveragereport
# * Find xml report suitable for jenkins in coverage.xml
#####################################################################
if(cmake_build_type_lower MATCHES coverage)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage" )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage" )
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --coverage" )
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage" )
# We add -g when building with coverage so valgrind reports line numbers.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g" )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g" )
# This allows us to skip the file descriptor closing test in Daemon_test
# when coverage is enabled. (Closing file descriptors
# in the test messes with coverage reporting.)
add_definitions(-DCOVERAGE_ENABLED)
endif()
# Make sure we have all the needed symbols
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-z,defs")
# Static C++ checks
find_program(CPPCHECK_COMMAND NAMES cppcheck)
if (CPPCHECK_COMMAND)
set(CPPCHECK_COMMAND_OPTIONS --check-config --inline-suppr --enable=all -q --error-exitcode=2)
set(CPPCHECK_COMMAND_OPTIONS ${CPPCHECK_COMMAND_OPTIONS} --template "{file}({line}): {severity} ({id}): {message}")
add_custom_target(cppcheck COMMAND ${CPPCHECK_COMMAND} ${CPPCHECK_COMMAND_OPTIONS}
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/test
${CMAKE_BINARY_DIR}/test
VERBATIM
)
else()
message(WARNING "Cannot find cppcheck: cppcheck target will not be available")
endif()
#
# Definitions for testing with valgrind.
#
configure_file(CTestCustom.cmake.in CTestCustom.cmake) # Tests in CTestCustom.cmake are skipped for valgrind
find_program(MEMORYCHECK_COMMAND NAMES valgrind)
if (MEMORYCHECK_COMMAND)
set(MEMORYCHECK_COMMAND_OPTIONS
"--suppressions=${CMAKE_SOURCE_DIR}/valgrind-suppress --leak-check=full --num-callers=40 --error-exitcode=3"
)
add_custom_target(valgrind DEPENDS NightlyMemCheck)
else()
message(WARNING "Cannot find valgrind: valgrind target will not be available")
endif()
include(FindPkgConfig)
pkg_check_modules(GLIB glib-2.0 REQUIRED)
# Standard install paths
include(GNUInstallDirs)
# Shell install paths
set(SHELL_PLUGINDIR ${CMAKE_INSTALL_LIBDIR}/unity8/qml)
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
)
# When building the library, we set the default symbol visibility
# to "hidden", so we don't export things by default.
# Exported functions and classes are prefixed by a UNITY_API macro,
# which explicitly exports a symbol if UNITY_DLL_EXPORTS is defined.
add_definitions(-DUNITY_DLL_EXPORTS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pedantic -Wall -Wextra")
# -fno-permissive causes warnings with clang, so we only enable it for gcc
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-permissive")
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override" )
endif()
endif()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "release" OR "${CMAKE_BUILD_TYPE}" STREQUAL "relwithdebinfo")
option(Werror "Treat warnings as errors" ON)
else()
option(Werror "Treat warnings as errors" OFF)
endif()
if (Werror)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif()
# API version
set(UNITY_API_MAJOR 0)
set(UNITY_API_MINOR 1)
set(UNITY_API_MICRO 6)
set(UNITY_API_VERSION "${UNITY_API_MAJOR}.${UNITY_API_MINOR}.${UNITY_API_MICRO}")
# API library
set(UNITY_API_LIB unity-api)
# Static version for testing
set(UNITY_API_STATIC_LIB unity-api-static)
# Other libraries we depend on
set(OTHER_API_LIBS)
# All the libraries we need to link a normal executable that uses the Unity API
set(LIBS ${UNITY_API_LIB} ${OTHER_API_LIBS})
# All the libraries we need to link a gtest executable. (We link the tests against a static version
# so we can do whitebox testing on internal classes.
set(TESTLIBS ${UNITY_API_STATIC_LIB} ${OTHER_API_LIBS})
# Library install prefix
set(LIB_INSTALL_PREFIX lib/${CMAKE_LIBRARY_ARCHITECTURE})
# Tests
if (NOT NO_TESTS)
include(CTest)
enable_testing()
add_subdirectory(test)
else()
message(STATUS "Tests disabled")
endif()
# add subdirectories to build
add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(data)
if (cmake_build_type_lower MATCHES coverage)
ENABLE_COVERAGE_REPORT(TARGETS ${UNITY_API_LIB} FILTER /usr/include ${CMAKE_SOURCE_DIR}/test/* ${CMAKE_BINARY_DIR}/*)
endif()
#
# Documentation
#
find_package(Doxygen)
find_program(DOT_EXECUTABLE dot /usr/bin)
if (NOT DOXYGEN_FOUND OR NOT DOT_EXECUTABLE)
message(WARNING "Cannot generate documentation: doxygen and/or graphviz not found")
else()
configure_file(${PROJECT_SOURCE_DIR}/doc/Doxyfile.in ${PROJECT_BINARY_DIR}/doc/Doxyfile @ONLY IMMEDIATE)
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/doc/lib${UNITY_API_LIB}/index.html
COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/doc/Doxyfile
DEPENDS ${PROJECT_BINARY_DIR}/doc/Doxyfile
${UNITY_API_LIB_SRC}
${UNITY_API_LIB_HDRS})
add_custom_target(doc ALL
DEPENDS ${PROJECT_BINARY_DIR}/doc/lib${UNITY_API_LIB}/index.html)
install(DIRECTORY ${PROJECT_BINARY_DIR}/doc/lib${UNITY_API_LIB}
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc)
endif()
./CTestCustom.cmake.in 0000644 0000041 0000041 00000001402 13070664454 015075 0 ustar www-data www-data #
# Tests listed here will not be run by the valgrind target.
#
SET(CTEST_CUSTOM_MEMCHECK_IGNORE
cleanincludes
stand-alone-unity-headers
stand-alone-unity-internal-headers
stand-alone-unity-api-headers
stand-alone-unity-api-internal-headers
stand-alone-unity-scopes-headers
stand-alone-unity-scopes-internal-headers
stand-alone-unity-util-headers
stand-alone-unity-util-internal-headers
clean-public-unity-headers
clean-public-unity-internal-headers
clean-public-unity-api-headers
clean-public-unity-api-internal-headers
clean-public-unity-scopes-headers
clean-public-unity-scopes-internal-headers
clean-public-unity-util-headers
clean-public-unity-util-internal-headers
copyright
whitespace)
./INSTALL 0000644 0000041 0000041 00000010025 13070664454 012303 0 ustar www-data www-data #
# Copyright (C) 2013 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
#
# Authored by: Michi Henning
#
-------------------------------------------------------------------------------------
NOTE: Before making changes to the code, please read the README file in its entirety!
-------------------------------------------------------------------------------------
Build dependencies
------------------
See debian/control for the list of packages required to build and test the code.
Building the code
-----------------
The simplest case is:
$ mkdir build
$ cd build
$ cmake ..
By default, the code is built in release mode. To build a debug version, use
$ mkdir builddebug
$ cd builddebug
$ cmake -DCMAKE_BUILD_TYPE=debug ..
$ make
For a release version, use -DCMAKE_BUILD_TYPE=release
To build with the flags for coverage testing enabled:
$ mkdir buildcoverage
$ cd buildcoverage
$ cmake -DCMAKE_BUILD_TYPE=coverage
$ make
Running the tests
-----------------
$ make
$ make test
Note that "make test" alone is dangerous because it does not rebuild
any tests if either the library or the test files themselves need
rebuilding. It's not possible to fix this with cmake because cmake cannot
add build dependencies to built-in targets. To make sure that everything
is up-to-date, run "make" before running "make test"!
To run the tests with valgrind:
$ make valgrind
To get coverage output:
$ make test
$ make coverage-html
This drops the coverage tests into the coveragereport directory. (The coverage-html target is available
only if the code was built with -DCMAKE_BUILD_TYPE=coverage.)
Note that, with gcc 4.7.2 and cmake 2.8.10, you may get a bunch of
warnings. To fix this, you can build cmake 2.8.10 with the following patch:
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=61ace1df2616e472d056b302e4269cbf112fb020#patch1
Unfortunately, it is not possibly to get 100% coverage for some files,
mainly due to gcc's generation of two destructors for dynamic and non-
dynamic instances. For abstract base classes and for classes that
prevent stack and static allocation, this causes one of the destructors
to be reported as uncovered.
There are also issues with some functions in header files that are
incorrectly reported as uncovered due to inlining, as well as
the impossibility of covering defensive assert(false) statements,
such as an assert in the default branch of a switch, where the
switch is meant to handle all possible cases explicitly.
If you run a binary and get lots of warnings about a "merge mismatch for summaries",
this is caused by having made changes to the source that add or remove code
that was previously run, so the new coverage output cannot sensibly be merged
into the old coverage output. You can get rid of this problem by running
$ make clean-coverage
This deletes all the .gcda files, allowing the merge to succeed again.
If lcov complains about unrecognized lines involving '=====',
you can patch geninfo and gcovr as explained here:
https://bugs.launchpad.net/gcovr/+bug/1086695/comments/2
To run the static C++ checks:
$ make cppcheck
Installation
------------
To get files that form part of an installation, run a "make install"
in the build directory. By default, this installs them in the "install"
subdirectory of the build directory. If you want to install into a
different directory, use
$ cmake -DCMAKE_INSTALL_PREFIX=/usr/local # Or wherever...
$ make release
$ make install
./unity-api.qmlproject 0000644 0000041 0000041 00000000660 13070664454 015277 0 ustar www-data www-data /* File generated by Qt Creator, version 2.7.0 */
import QmlProject 1.1
Project {
mainFile: ""
/* Include .qml, .js, and image files from current directory and subdirectories */
QmlFiles {
directory: "."
}
JavaScriptFiles {
directory: "."
}
ImageFiles {
directory: "."
}
/* List of plugin directories passed to QML runtime */
importPaths: [ "build/modules" ]
}
./README 0000644 0000041 0000041 00000023126 13070664454 012140 0 ustar www-data www-data #
# Copyright (C) 2013 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
#
# Authored by: Michi Henning
#
This is an explanation of the layout of the source tree, and the
conventions used by this library. Please read this before making changes
to the source!
For instructions on how to build the code, see the INSTALL file.
Build targets
-------------
The build produces the Unity API library (libunity-api).
TODO: Flesh this out
Source tree layout
------------------
At the top level, we have src, include, and test, which contain what
they suggest.
Underneath src and include, we have subdirectories that correspond to
namespaces, that is, if we have src/internal, that automatically means
that there is a namespace unity::scopes::internal. This one-to-one correspondence
makes it easier to work out what is defined where.
Namespaces
----------
The library maintains a compilation firewall, strictly separating
external API and internal implementation. This reduces the chance of
breaking the API, and it makes it clear what parts of the API are for
public consumption.
Anything that is not public is implemented in a namespace called "internal".
TODO: More explanation of the namespaces used and for what.
Header file conventions
-----------------------
All header files are underneath include/unity. Source code always includes
headers using the full pathname, for example:
#include
All source code uses angle brackets (<...>) for #include
directives. Double quotes ("...") are never used because the lookup
semantics can be surprising if there are any headers with the same name
in the tree. (Not that this should happen, but it's better to be safe. If
there are no duplicate names, inclusion with angle brackets behaves the
same way as inclusion with double quotes.)
All headers that are for public consumption appear in include/unity/*
(provided the path does not include "internal").
Public header directories contain a private header directory called
"internal". This directory contains all the headers that are private
and specific to the implementation.
No public header file is allowed to include any header from one of the
internal directories. (Doing so would break the compilation firewall
and also prevent API clients from compiling because the internal headers
are not installed when unity is deployed. (This is enforced by the tests.)
All header files, whether public or internal, compile stand-alone, that
is, no header relies on another header being included first in order to
compile. (This is enforced by the tests.)
Compilation firewall
--------------------
Public classes use the pimpl (pointer-to-implemtation) idiom, also
known as "envelope-letter idiom", "Cheshire Cat", or "Compiler firewall
idiom". This makes it less likely that an update to the code will break
the ABI.
Many classes that are part of the public API contain only one private data
member, namely the pimpl. No other data members (public, protected,
or private) are permitted.
For public classes with shallow-copy semantics (classes that are
immutable after instantiation), the code uses std::shared_ptr as the
pimpl type because std::shared_ptr provides the correct semantics. (See
unity::Exception and its derived classes for an example.)
For classes that are non-copyable, std::unique_ptr is used as the
pimpl type.
If classes form derivation hierarchies, by convention, the pimpl is a
private data member of the root base class. Derived classes can access the
pimpl by calling the protected pimpl() method of the root base class. This
avoids redundantly storing a separated pimpl to the derived type in each
derived class. Instead, polymorphic dispatch to virtual methods in the
derived classes is achieved by using a dynamic_cast to the derived
type to forward an invocation to the corresponding virtual method in
the derived implementation class.
Error handling
--------------
No error codes, period. All errors are reported via exceptions. All
exceptions thrown by the library are derived from unity::Exception (which
is abstract). unity::Exception provides a to_string() method. This method
returns the exception history and prints all exceptions that were raised
along a particular throw path, even if a low-level exception was caught
and translated into a higher level exception. This works for exceptions
derived from std::nested_exception. (The exception chaining ends when it
encounters an exception that does not derive from std::nested_exception.)
If API clients intercept unity exceptions and rethrow their own exceptions,
it is recommended that API clients derive their exceptions from
unity::Exception or, alternatively, derive them from std::nested_exception
and implement a similar to_string() operation that, if it encounters a
unity::Exception while following a chain, calls the to_string() method on
unity::Exception. That way, the entire exception history will be returned
from to_string().
Functions that throw exceptions should, if at all possible, provide
the strong exception guarantee. Otherwise, they must provide the basic
(weak) exception guarantee. If it is impossible to maintain even the basic
guarantee, the code must call abort() instead of throwing an exception.
Resource management
-------------------
The code uses the RAII (resource acquisition is initialization)
idiom extensively. If you find yourself writing free, delete, Xfree,
XCloseResource, or any other kind of clean-up function, your code has a
problem. Instead of explictly cleaning up in destructors, *immediately*
assign the resource to a unique_ptr or shared_ptr with a custom deleter.
This guarantees that the resource will be released without having to
remember anything. In particular, it guarantees that the resource
will be released even if allocated in a constructor near the beginning
and something called by the constructor throws before the constructor
completes.
For resources that cannot be managed by unique_ptr or shared_ptr
(because the allocator does not return a pointer or returns a
pointer to an opaque type), use the RAII helper class in ResourcePtr.h.
It does much the same thing as unique_ptr, but is more permissive
in the types it can manage.
Note the naming convention established by util/DefinesPtrs.h. All
classes that return or accept smart pointers derive from DefinesPtrs,
which is a code injection template that creates typedefs for Ptr and
UPtr (shared_ptr and unique_ptr, respectively) as well as CPtr and UCPtr
(shared_ptr and unique_ptr to constant instances).
Ideally, classes are fully initialized by their constructor so it is
impossible for a class to exist but not being in a usable state.
For some classes, it is unavoidable to provide a default constructor (for
example, if we want to put instances into an array). It is also sometimes
impossible to fully construct an instance immediately, for example if
the instance is member variable and the necessary initialization data
is not available until some time afterwards.
In this case, the default constructor must initialize the class to
a fail-safe state, that is, it must behave sanely in the face of
methods being invoked on it. This means that calling a method on a
default-constructed instance should throw a logic exception to
indicate to the caller that the instance is not fully initialized yet.
Note that turning method calls on not-yet-initialized instances into
no-ops is usually a bad idea: the caller thinks that everything worked
fine when, in fact, it did nothing. If such no-op methods do something
sensible (that is, they can do their job even on an incompletely
initialized instance), this begs the question of why the instance wasn't
default-constructible in the first place...
To sum it up: try to enforce complete initialization from the
constructor wherever possible. If it is impossible to do that, follow
the principle of least surprise for the caller if a method is called on
a not-yet-initialized instance.
Loose ends
----------
Things that need fixing or checking are marked with a TODO comment in
the code.
Things that are work-arounds for bugs in the compiler or libraries are
marked with a BUGFIX comment.
Things that are dubious in some way with no better solution available
are marked with a HACK comment.
Style
-----
Consider running astyle over the code before checking it in.
See astyle-config for more details.
Versioning
----------
When adding API, remember to both bump:
- the debian/changelog version and
- the VERSION field in the relevant CMakeLists.txt file
Test suite
----------
The test suite lives underneath the test directory.
test/headers contains tests relating to header file integrity.
test/gtest contains the C++ tests (which use Google test).
The Google gtest authors are adamant that it is a bad idea to just
link with a pre-installed version of libgtest.a. Therefore, libgtest.a
(and libgtest_main.a) are created as part of the build and can be found
in test/gtest/libgtest.
See the INSTALL file for how to run the tests, particularly the caveat
about "make test" not rebuilding the tests!
Building and installing the code
--------------------------------
See the INSTALL file.
./include/ 0000755 0000041 0000041 00000000000 13070664454 012677 5 ustar www-data www-data ./include/CMakeLists.txt 0000644 0000041 0000041 00000000161 13070664454 015435 0 ustar www-data www-data set(HDR_INSTALL_DIR include)
add_subdirectory(unity)
set(UNITY_API_LIB_HDRS ${UNITY_API_LIB_HDRS} PARENT_SCOPE)
./include/unity/ 0000755 0000041 0000041 00000000000 13070664454 014047 5 ustar www-data www-data ./include/unity/util/ 0000755 0000041 0000041 00000000000 13070664521 015017 5 ustar www-data www-data ./include/unity/util/CMakeLists.txt 0000644 0000041 0000041 00000000434 13070664454 017565 0 ustar www-data www-data file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
file(GLOB internal_headers "${CMAKE_CURRENT_SOURCE_DIR}/internal/*.h")
install(FILES ${headers} DESTINATION ${HDR_INSTALL_DIR}/unity/util)
set(UNITY_API_LIB_HDRS ${UNITY_API_LIB_HDRS} ${headers} ${internal_headers} PARENT_SCOPE)
./include/unity/util/FileIO.h 0000644 0000041 0000041 00000002060 13070664454 016302 0 ustar www-data www-data /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#ifndef UNITY_UTIL_FILEIO_H
#define UNITY_UTIL_FILEIO_H
#include
#include
#include
namespace unity
{
namespace util
{
UNITY_API std::string read_text_file(std::string const& filename);
UNITY_API std::vector read_binary_file(std::string const& filename);
} // namespace util
} // namespace unity
#endif
./include/unity/util/IniParser.h 0000644 0000041 0000041 00000013406 13070664454 017075 0 ustar www-data www-data /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Jussi Pakkanen
*/
#ifndef UNITY_UTIL_INIPARSER_H
#define UNITY_UTIL_INIPARSER_H
#include
#include
#include
#include
namespace unity
{
namespace util
{
namespace internal
{
struct IniParserPrivate;
}
/**
\brief Helper class to read and write configuration files.
This class reads configuration files in the .ini format
and provides for a simple and type safe way of extracting
and inserting information. A typical ini file looks like this:
~~~
[group1]
key1 = value1
key2 = value2
[group2]
key1 = othervalue1
key2 = othervalue2
~~~
To extract/insert a value, simply specify the group and key
names to the get/set methods of this class, respectively.
The array methods use a semicolon as a separator.
To write unsaved changes back to the configuration file, call
sync(). The sync() method will throw a FileException if it
fails to write to file.
The get methods indicate errors by throwing LogicException.
All methods are thread-safe.
*/
class UNITY_API IniParser final {
public:
/** Parse the given file. */
IniParser(const char* filename);
~IniParser() noexcept;
/// @cond
UNITY_DEFINES_PTRS(IniParser);
IniParser(const IniParser& ip) = delete;
IniParser() = delete;
/// @endcond
//{@
/** @name Read Methods
* These member functions provide read access to configuration entries by group and key.
* Attempts to retrieve a value as the wrong type (such as retrieving a string value as an
* integer) or to retrieve a value for a non-existent group or key throw LogicException.
**/
bool has_group(const std::string& group) const noexcept;
bool has_key(const std::string& group, const std::string& key) const;
std::string get_string(const std::string& group, const std::string& key) const;
std::string get_locale_string(const std::string& group,
const std::string& key,
const std::string& locale = std::string()) const;
bool get_boolean(const std::string& group, const std::string& key) const;
int get_int(const std::string& group, const std::string& key) const;
double get_double(const std::string& group, const std::string& key) const;
std::vector get_string_array(const std::string& group, const std::string& key) const;
std::vector get_locale_string_array(const std::string& group,
const std::string& key,
const std::string& locale = std::string()) const;
std::vector get_boolean_array(const std::string& group, const std::string& key) const;
std::vector get_int_array(const std::string& group, const std::string& key) const;
std::vector get_double_array(const std::string& group, const std::string& key) const;
std::string get_start_group() const;
std::vector get_groups() const;
std::vector get_keys(const std::string& group) const;
/** @name Write Methods
* These member functions provide write access to configuration entries by group and key.
* Attempts to remove groups or keys that do not exist throw LogicException.
* The set methods replace the value for a key if the key exists. Calling a set method for a
* non-existent group and/or key creates the group and/or key.
**/
bool remove_group(const std::string& group);
bool remove_key(const std::string& group, const std::string& key);
void set_string(const std::string& group, const std::string& key, const std::string& value);
void set_locale_string(const std::string& group,
const std::string& key,
const std::string& value,
const std::string& locale = std::string());
void set_boolean(const std::string& group, const std::string& key, bool value);
void set_int(const std::string& group, const std::string& key, int value);
void set_double(const std::string& group, const std::string& key, double value);
void set_string_array(const std::string& group, const std::string& key, const std::vector& value);
void set_locale_string_array(const std::string& group,
const std::string& key,
const std::vector& value,
const std::string& locale = std::string());
void set_boolean_array(const std::string& group, const std::string& key, const std::vector& value);
void set_int_array(const std::string& group, const std::string& key, const std::vector& value);
void set_double_array(const std::string& group, const std::string& key, const std::vector& value);
/** @name Sync Method
* This member function writes unsaved changes back to the configuration file.
* A failure to write to the file throws a FileException.
**/
void sync();
//@}
private:
internal::IniParserPrivate* p;
};
} // namespace util
} // namespace unity
#endif
./include/unity/util/NonCopyable.h 0000644 0000041 0000041 00000003076 13070664454 017414 0 ustar www-data www-data /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
//
// Simple class to disable copy and assignment. (Provided here to avoid having to use
// the equivalent boost version.)
//
// Use like this:
//
// class MyClass : private util::NonCopyable
// {
// // ...
// };
//
#ifndef UNITY_UTIL_NONCOPYABLE_H
#define UNITY_UTIL_NONCOPYABLE_H
#include
/**
\brief Helper macro to prevent a class from being copied.
This helper macro disables the copy constructor and assignment operator of a class to prevent it
from being copied. This is a macro rather than a base class to reduce clutter on the class
hierarchy.
Use it like this:
class MyClass
{
public: // not necessary, but the error message is more explicit with this
NONCOPYABLE(MyClass)
...
};
*/
#define NONCOPYABLE(ClassName) /** Deleted */ ClassName(ClassName const&) = delete; /** Deleted */ ClassName& operator=(ClassName const&) = delete
#endif
./include/unity/util/GObjectMemory.h 0000644 0000041 0000041 00000013053 13070664503 017700 0 ustar www-data www-data /*
* Copyright (C) 2013-2017 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Jussi Pakkanen
* Pete Woods
*/
#ifndef UNITY_UTIL_GOBJECTMEMORY_H
#define UNITY_UTIL_GOBJECTMEMORY_H
#include
#include
#include
#include
namespace unity
{
namespace util
{
namespace
{
inline static void check_floating_gobject(gpointer t)
{
if (G_IS_OBJECT(t) && g_object_is_floating(G_OBJECT(t)))
{
throw std::invalid_argument("cannot manage floating GObject reference - call g_object_ref_sink(o) first");
}
}
}
/**
\brief Used by the make_gobject, unique_gobject and share_gobject as the deleter.
Useful if for some reason the normal helper methods are not suitable for your needs.
Example:
\code{.cpp}
GObjectDeleter d;
auto shared = shared_ptr(foo_bar_new("name"), d);
auto unique = unique_ptr(foo_bar_new("name"), d);
\endcode
*/
struct GObjectDeleter
{
void operator()(gpointer ptr) noexcept
{
if (G_IS_OBJECT(ptr))
{
g_object_unref(ptr);
}
}
};
template using GObjectSPtr = std::shared_ptr;
template using GObjectUPtr = std::unique_ptr;
namespace internal
{
template
class GObjectAssigner
{
public:
typedef typename SP::element_type ElementType;
GObjectAssigner(SP& smart_ptr) noexcept:
smart_ptr_(smart_ptr)
{
}
GObjectAssigner(const GObjectAssigner& other) = delete;
GObjectAssigner(GObjectAssigner&& other) noexcept:
ptr_(other.ptr_), smart_ptr_(other.smart_ptr_)
{
other.ptr_ = nullptr;
}
~GObjectAssigner() noexcept
{
smart_ptr_ = SP(ptr_, GObjectDeleter());
}
GObjectAssigner& operator=(const GObjectAssigner& other) = delete;
operator ElementType**() noexcept
{
return &ptr_;
}
private:
ElementType* ptr_ = nullptr;
SP& smart_ptr_;
};
template
struct GObjectSignalUnsubscriber
{
void operator()(gulong handle) noexcept
{
if (handle != 0 && G_IS_OBJECT(obj_.get()))
{
g_signal_handler_disconnect(obj_.get(), handle);
}
}
GObjectSPtr obj_;
};
}
/**
\brief Helper method to wrap a unique_ptr around an existing GObject.
Useful if the GObject class you are constructing already has a
dedicated factory from the C library it comes from, and you
intend to have a unique instance of it.
Example:
\code{.cpp}
auto obj = unique_gobject(foo_bar_new("name"));
\endcode
*/
template
inline GObjectUPtr unique_gobject(T* ptr)
{
check_floating_gobject(ptr);
GObjectDeleter d;
return GObjectUPtr(ptr, d);
}
/**
\brief Helper method to wrap a shared_ptr around an existing GObject.
Useful if the GObject class you are constructing already has a
dedicated factory from the C library it comes from, and you
intend to share it.
Example:
\code{.cpp}
auto obj = share_gobject(foo_bar_new("name"));
\endcode
*/
template
inline GObjectSPtr share_gobject(T* ptr)
{
check_floating_gobject(ptr);
GObjectDeleter d;
return GObjectSPtr(ptr, d);
}
/**
\brief Helper method to construct a gobj_ptr-wrapped GObject class.
Uses the same signature as the g_object_new() method.
Example:
\code{.cpp}
auto obj = make_gobject(FOO_TYPE_BAR, "name", "banana", nullptr);
\endcode
*/
template
inline GObjectUPtr make_gobject(GType object_type, const gchar *first_property_name, Args&&... args) noexcept
{
gpointer ptr = g_object_new(object_type, first_property_name, std::forward(args)...);
if (G_IS_OBJECT(ptr) && g_object_is_floating(ptr))
{
g_object_ref_sink(ptr);
}
return unique_gobject(G_TYPE_CHECK_INSTANCE_CAST(ptr, object_type, T));
}
/**
\brief Helper method to take ownership of GObjects assigned from a reference.
Example:
\code{.cpp}
GObjectUPtr o;
method_that_assigns_a_foobar(assign_gobject(o));
\endcode
*/
template
inline internal::GObjectAssigner assign_gobject(SP& smart_ptr) noexcept
{
return internal::GObjectAssigner(smart_ptr);
}
template
using GObjectSignalConnection = ResourcePtr>;
/**
\brief Simple wrapper to manage the lifecycle of GObject signal connections.
When 'nameConnection_' goes out of scope or is dealloc'ed, the source will be removed:
\code{.cpp}
GObjectSignalConnection nameConnection_;
nameConnection_ = gobject_signal_connection(g_signal_connect(o.get(), "notify::name", G_CALLBACK(on_notify_name), this), o);
\endcode
*/
template
inline GObjectSignalConnection gobject_signal_connection(gulong id, const GObjectSPtr& obj)
{
return GObjectSignalConnection(id, internal::GObjectSignalUnsubscriber{obj});
}
} // namespace until
} // namespace unity
#endif
./include/unity/util/GlibMemory.h 0000644 0000041 0000041 00000013027 13070664503 017241 0 ustar www-data www-data /*
* Copyright (C) 2017 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Pete Woods
* Michi Henning
* James Henstridge
*/
#ifndef UNITY_UTIL_GLIBMEMORY_H
#define UNITY_UTIL_GLIBMEMORY_H
#include
#include
#include
namespace unity
{
namespace util
{
namespace internal
{
template struct GlibDeleter;
template using GlibSPtr = std::shared_ptr;
template using GlibUPtr = std::unique_ptr>;
/**
* \brief Adapter class to assign to smart pointers from functions that take a reference.
*
* Adapter class that allows passing a shared_ptr or unique_ptr where glib
* expects a parameter of type ElementType** (such as GError**), by providing
* a default conversion operator to ElementType**. This allows the glib method
* to assign to the ptr_ member. From the destructor, we assign to the
* provided smart pointer.
*/
template
class GlibAssigner
{
public:
typedef typename SP::element_type ElementType;
GlibAssigner(SP& smart_ptr) noexcept :
smart_ptr_(smart_ptr)
{
}
GlibAssigner(const GlibAssigner& other) = delete;
GlibAssigner(GlibAssigner&& other) noexcept:
ptr_(other.ptr_), smart_ptr_(other.smart_ptr_)
{
other.ptr_ = nullptr;
}
~GlibAssigner() noexcept
{
smart_ptr_ = SP(ptr_, GlibDeleter());
}
GlibAssigner& operator=(const GlibAssigner& other) = delete;
operator ElementType**() noexcept
{
return &ptr_;
}
private:
ElementType* ptr_ = nullptr;
SP& smart_ptr_;
};
struct GSourceUnsubscriber
{
void operator()(guint tag) noexcept
{
if (tag != 0)
{
g_source_remove(tag);
}
}
};
}
#define UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(TypeName, func) \
using TypeName##Deleter = internal::GlibDeleter; \
using TypeName##SPtr = internal::GlibSPtr; \
using TypeName##UPtr = internal::GlibUPtr; \
namespace internal \
{ \
template<> struct GlibDeleter \
{ \
void operator()(TypeName* ptr) noexcept \
{ \
if (ptr) \
{ \
::func(ptr); \
} \
} \
}; \
}
/**
\brief Helper method to wrap a shared_ptr around a Glib type.
Example:
\code{.cpp}
auto gkf = shared_glib(g_key_file_new());
\endcode
*/
template
inline internal::GlibSPtr share_glib(T* ptr) noexcept
{
return internal::GlibSPtr(ptr, internal::GlibDeleter());
}
/**
\brief Helper method to wrap a unique_ptr around a Glib type.
Example:
\code{.cpp}
auto gkf = unique_glib(g_key_file_new());
\endcode
*/
template
inline internal::GlibUPtr unique_glib(T* ptr) noexcept
{
return internal::GlibUPtr(ptr, internal::GlibDeleter());
}
/**
\brief Helper method to take ownership of glib types assigned from a reference.
Example:
\code{.cpp}
GErrorUPtr error;
if (!g_key_file_get_boolean(gkf.get(), "group", "key", assign_glib(error)))
{
std::cerr << error->message << std::endl;
throw some_exception();
}
\endcode
Another example:
\code{.cpp}
gcharUPtr name;
g_object_get(obj, "name", assign_glib(name), nullptr);
\endcode
*/
template
inline internal::GlibAssigner assign_glib(SP& smart_ptr) noexcept
{
return internal::GlibAssigner(smart_ptr);
}
using GSourceManager = ResourcePtr;
/**
\brief Simple wrapper to manage the lifecycle of sources.
When 'timer' goes out of scope or is dealloc'ed, the source will be removed:
\code{.cpp}
auto timer = g_source_manager(g_timeout_add(5000, on_timeout, nullptr));
\endcode
*/
inline GSourceManager g_source_manager(guint id)
{
return GSourceManager(id, internal::GSourceUnsubscriber());
}
/**
* Below here is some hackery to extract the matching deleters for all built in glib types.
*/
#pragma push_macro("G_DEFINE_AUTOPTR_CLEANUP_FUNC")
#undef G_DEFINE_AUTOPTR_CLEANUP_FUNC
#define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func) UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(TypeName, func)
#pragma push_macro("G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC")
#undef G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC
#define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func)
#pragma push_macro("G_DEFINE_AUTO_CLEANUP_FREE_FUNC")
#undef G_DEFINE_AUTO_CLEANUP_FREE_FUNC
#define G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none)
#define __GLIB_H_INSIDE__
#include
#undef __GLIB_H_INSIDE__
#pragma pop_macro("G_DEFINE_AUTOPTR_CLEANUP_FUNC")
#pragma pop_macro("G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC")
#pragma pop_macro("G_DEFINE_AUTO_CLEANUP_FREE_FUNC")
/**
* Manually add extra definitions for gchar* and gchar**
*/
UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(gchar, g_free)
typedef gchar* gcharv;
UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(gcharv, g_strfreev)
} // namespace until
} // namespace unity
#endif
./include/unity/util/SnapPath.h 0000644 0000041 0000041 00000001476 13070664521 016716 0 ustar www-data www-data /*
* Copyright (C) 2016-2017 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
*/
#pragma once
#include
namespace unity
{
namespace util
{
std::string prepend_snap_path(const std::string& path);
} // namespace util
} // namespace unity
./include/unity/util/ResourcePtr.h 0000644 0000041 0000041 00000053131 13070664503 017450 0 ustar www-data www-data /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#ifndef UNITY_UTIL_RESOURCEPTR_H
#define UNITY_UTIL_RESOURCEPTR_H
#include
#include
namespace unity
{
namespace util
{
namespace
{
// Simple helper class so we can adopt a lock without inconvenient syntax.
template
class LockAdopter
{
public:
LockAdopter(T& mutex) noexcept
: m_(mutex, std::adopt_lock)
{
assert(!mutex.try_lock()); // Mutex must be locked to be adoptable.
}
private:
std::unique_lock m_;
};
} // namespace
/**
\brief Class to guarantee deallocation of arbitrary resources.
ResourcePtr is a generalized resource pointer that guarantees deallocation.
It is intended for arbitrary pairs of allocate/deallocate functions, such
as XCreateDisplay
/XDestroyDisplay
.
The resource managed by this class must be default-constructible, copy-constructible, and assignable.
ResourcePtr essentially does what std::unique_ptr
does, but it works with opaque types
and resource allocation functions that do not return a pointer type, such as open()
.
ResourcePtr is thread-safe.
\note Do not use reset() to set the resource to the "no resource allocated" state.
Instead, call dealloc() to do this. ResourcePtr has no idea
what a "not allocated" resource value looks like and therefore cannot test
for it. If you use reset() to install a "no resource allocated" value for
for the resource, the deleter will eventually be called with this value
as its argument. Whether this is benign or not depends on the deleter. For
example, XFree()
must not be called with a nullptr
argument.
\note Do not call get() or release() if no resource is currently allocated.
Doing so throws std::logic_error
.
Here is an example that shows how to use this for a glXCreateContext
/GLXDestroyContext
pair.
The returned GLXContext
is a pointer to an opaque type; std::unique_ptr
cannot be used
for this, even with a custom deleter, because the signatures of the allocator and deallocator
do not match unique_ptr
's expectations.
~~~
ResourcePtr> context =
std::bind(&glXDestroyContext, display_, std::placeholders::_1);
~~~
display_ is declared as
~~~
Display* display_;
~~~
in this case.
The deleter for the resource can return any type (including int, such as returned by XDestroyWindow()
),
and it must accept a single argument of the resource type (GLXContext
in this example).
glXDestroyContext()
expects the display pointer as the first argument so, for this example,
std::bind
converts the binary glXDestroyContext()
function into a
unary function suitable as the deleter.
Rather than mucking around with std::bind
, it is often easier to use a lambda. For example:
~~~
ResourcePtr> context =
[this](GLXContext c) { this->dealloc_GLXContext(c); };
~~~
This calls a member function dealloc_GLXContext()
that, in turn calls glXDestroyContext()
and supplies the display parameter.
\note Even though you can use ResourcePtr to deallocate dynamic memory, doing so is discouraged.
Use std::unique_ptr
instead, which is better suited to the task.
*/
// TODO: Discuss throwing deleters and requirements (copy constructible, etc.) on deleter.
template
class ResourcePtr final
{
public:
/** Deleted */
ResourcePtr(ResourcePtr const &) = delete;
/** Deleted */
ResourcePtr& operator=(ResourcePtr const&) = delete;
/**
\typedef element_type
The type of resource managed by this ResourcePtr.
*/
typedef R element_type;
/**
\typedef deleter_type
A function object or lvalue reference to a function or function object. The ResourcePtr
calls this to deallocate the resource.
*/
typedef D deleter_type;
ResourcePtr();
explicit ResourcePtr(D d);
ResourcePtr(R r, D d);
ResourcePtr(ResourcePtr&& r);
ResourcePtr& operator=(ResourcePtr&& r);
~ResourcePtr() noexcept;
void swap(ResourcePtr& other);
void reset(R r);
R release();
void dealloc();
R get() const;
bool has_resource() const noexcept;
explicit operator bool() const noexcept;
D& get_deleter() noexcept;
D const& get_deleter() const noexcept;
bool operator==(ResourcePtr const& rhs) const;
bool operator!=(ResourcePtr const& rhs) const;
bool operator<(ResourcePtr const& rhs) const;
bool operator<=(ResourcePtr const& rhs) const;
bool operator>(ResourcePtr const& rhs) const;
bool operator>=(ResourcePtr const& rhs) const;
private:
R resource_; // The managed resource.
D delete_; // The deleter to call.
bool initialized_; // True while we have a resource assigned.
mutable std::mutex m_; // Protects this instance.
typedef std::lock_guard AutoLock;
typedef LockAdopter AdoptLock;
};
template
ResourcePtr::ResourcePtr()
: initialized_(false)
{
static_assert(!std::is_pointer::value,
"constructed with null function pointer deleter");
}
/**
Constructs a ResourcePtr with the specified deleter. No resource is held, so a call to has_resource()
after constructing a ResourcePtr this way returns false
.
*/
template
ResourcePtr::ResourcePtr(D d)
: delete_(d), initialized_(false)
{
}
/**
Constructs a ResourcePtr with the specified resource and deleter. has_resource() returns true
after
calling this constructor.
\note It is legal to pass a resource that represents the "not allocated" state. For example, the
following code passes the value -1
to close()
if the call to open()
fails:
~~~
ResourcePtr fd(::open("/somefile", O_RDONLY), ::close);
~~~
When the ResourcePtr goes out of scope, this results in a call to close(-1)
. In this case,
the call with an invalid file descriptor is harmless (but causes noise from diagnostic tools, such as
valgrind
). However, depending on the specific deleter, passing an invalid value to the deleter may
have more serious consequences.
To avoid the problem, you can delay initialization of the ResourcePtr until you know that the
resource was successfully allocated, for example:
~~~
int tmp_fd = ::open(filename.c_str(), O_RDONLY);
if (tmp_fd == -1)
{
throw FileException(filename.c_str());
}
util::ResourcePtr fd(tmp_fd, ::close(fd));
~~~
Alternatively, you can use a deleter function that tests the resource value
for validity and avoids calling the deleter with an invalid value:
~~~
util::ResourcePtr> fd(
::open(filename.c_str(), O_RDONLY),
[](int fd) { if (fd != -1) ::close(fd); }
);
~~~
Note that, with the second approach, a call to get() will succeed and return -1 rather than throwing an
exception, so the first approach is the recommended one.
*/
template
ResourcePtr::ResourcePtr(R r, D d)
: resource_(r), delete_(d), initialized_(true)
{
}
/**
Constructs a ResourcePtr by transferring ownership from r
to this
.
If the resource's move or copy constructor throws, the exception is propagated to the caller.
The strong exception guarantee is preserved if it is provided by the resource.
*/
// TODO: Mark as nothrow if the resource has a nothrow move constructor or nothrow copy constructor
template
ResourcePtr::ResourcePtr(ResourcePtr&& r)
: resource_(std::move(r.resource_)), delete_(r.delete_), initialized_(r.initialized_)
{
r.initialized_ = false; // Stop r from deleting its resource, if it held any. No need to lock: r is a temporary.
}
/**
Assigns the resource held by r
, transferring ownership. After the transfer,
r.has_resource()
returns false
, and this.has_resource()
returns
the value of r.has_resource()
prior to the assignment.
*/
// TODO: document exception safety behavior
template
ResourcePtr& ResourcePtr::operator=(ResourcePtr&& r)
{
AutoLock lock(m_);
if (initialized_) // If we hold a resource, deallocate it first.
{
initialized_ = false; // If the deleter throws, we will not try it again for the same resource.
delete_(resource_); // Delete our own resource.
}
// r is a temporary, so we don't need to lock it.
resource_ = std::move(r.resource_);
initialized_ = r.initialized_;
r.initialized_ = false; // Stop r from deleting its resource, if it held any.
delete_ = r.delete_;
return *this;
}
/**
Destroys the ResourcePtr. If a resource is held, it calls the deleter for the current resource (if any).
*/
template
ResourcePtr::~ResourcePtr() noexcept
{
try
{
dealloc();
}
catch (...)
{
}
}
/**
Swaps the resource and deleter of this
with the resource and deleter of other
using argument dependent lookup (ADL).
If the underlying swap throws an exception, that exception is propagated to the caller, and the resource
held by the ResourcePtr is unchanged.
*/
// TODO Split this into throw and no-throw versions depending on the underlying swap?
template
void ResourcePtr::swap(ResourcePtr& other)
{
if (this == &other) // This is necessary to avoid deadlock for self-swap
{
return;
}
std::lock(m_, other.m_);
AdoptLock left(m_);
AdoptLock right(other.m_);
using std::swap; // Enable ADL
swap(resource_, other.resource_);
swap(delete_, other.delete_);
swap(initialized_, other.initialized_);
}
// The non-member swap() must be in the same namespace as ResourcePtr, so it will work with ADL. And, once it is
// defined here, there is no point in adding a specialization to namespace std any longer, because ADL
// will find it here anyway.
/**
Swaps the resource and deleter of lhs
with the resource and deleter of rhs
by calling lhs.swap(rhs)
.
If the underlying swap throws an exception, that exception is propagated to the caller, and the resource
held by the ResourcePtr is unchanged.
*/
// TODO Split this into throw and no-throw versions depending on the underlying swap?
template
void swap(unity::util::ResourcePtr& lhs, unity::util::ResourcePtr& rhs)
{
lhs.swap(rhs);
}
/**
Assigns a new resource to this
, first deallocating the current resource (if any).
If the deleter for the current resource throws an exception, the exception is propagated to the caller. In this
case, the transfer of r
to this
is still carried out so, after the call to reset(),
this
manages r
, whether the deleter throws or not. (If the deleter does throw,
no attempt is made to call the deleter again for the same resource.)
*/
template
void ResourcePtr::reset(R r)
{
AutoLock lock(m_);
bool has_old = initialized_;
R old_resource;
if (has_old)
{
old_resource = resource_;
}
resource_ = r;
initialized_ = true; // If the deleter throws, we still satisfy the postcondition: resource_ == r.
if (has_old)
{
delete_(old_resource);
}
}
/**
Releases ownership of the current resource without calling the deleter.
\return The current resource.
\throw std::logic_error if has_resource() is false.
*/
template
inline
R ResourcePtr::release()
{
AutoLock lock(m_);
if (!initialized_)
{
throw std::logic_error("release() called on ResourcePtr without resource");
}
initialized_ = false;
return resource_;
}
/**
Calls the deleter for the current resource.
If the deleter throws, the resource is considered in the "not allocated" state,
that is, no attempt is made to call the deleter again for this resource.
*/
template
void ResourcePtr::dealloc()
{
AutoLock lock(m_);
if (!initialized_)
{
return;
}
initialized_ = false; // If the deleter throws, we will not try it again for the same resource.
delete_(resource_);
}
/**
Returns the current resource. If no resource is currently held, get() throws std::logic_error
.
\return The current resource (if any).
If the resource's copy constructor throws an exception, that exception is propagated to the caller.
\throw std::logic_error if has_resource() is false.
*/
template
inline
R ResourcePtr::get() const
{
AutoLock lock(m_);
if (!initialized_)
{
throw std::logic_error("get() called on ResourcePtr without resource");
}
return resource_;
}
/**
\return true
if this
currently manages a resource; false
, otherwise.
*/
template
inline
bool ResourcePtr::has_resource() const noexcept
{
AutoLock lock(m_);
return initialized_;
}
/**
Synonym for has_resource().
*/
template
inline
ResourcePtr::operator bool() const noexcept
{
return has_resource();
}
/**
\return The deleter for the resource.
*/
template
inline
D& ResourcePtr::get_deleter() noexcept
{
AutoLock lock(m_);
return delete_;
}
/**
\return The deleter for the resource.
*/
template
inline
D const& ResourcePtr::get_deleter() const noexcept
{
AutoLock lock(m_);
return delete_;
}
/**
\brief Compares two instances for equality.
Two instances that do not hold a resource are equal. An instance that does not hold a resource is not equal
to any instance that holds a resource.
If the underlying operator==
throws an exception, that exception is propagated to the caller.
\note This operator is available only if the underlying resource provides operator==
.
*/
template
bool ResourcePtr::operator==(ResourcePtr const& rhs) const
{
if (this == &rhs) // This is necessary to avoid deadlock for self-comparison
{
return true;
}
std::lock(m_, rhs.m_);
AdoptLock left(m_);
AdoptLock right(rhs.m_);
if (!initialized_)
{
return !rhs.initialized_; // Equal if both are not initialized
}
else if (!rhs.initialized_)
{
return false; // Not equal if lhs initialized, but rhs not initialized
}
else
{
return resource_ == rhs.resource_;
}
}
/**
\brief Compares two instances for inequality.
If the underlying operator==
throws an exception, that exception is propagated to the caller.
\note This operator is available only if the underlying resource provides operator==
.
*/
template
inline
bool ResourcePtr::operator!=(ResourcePtr const& rhs) const
{
return !(*this == rhs);
}
/**
\brief Returns true
if this
is less than rhs
.
An instance that does not hold a resource is less than any instance that holds a resource.
If the underlying operator\<
throws an exception, that exception is propagated to the caller.
\note This operator is available only if the underlying resource provides operator\<
.
*/
template
bool ResourcePtr::operator<(ResourcePtr const& rhs) const
{
if (this == &rhs) // This is necessary to avoid deadlock for self-comparison
{
return false;
}
std::lock(m_, rhs.m_);
AdoptLock left(m_);
AdoptLock right(rhs.m_);
if (!initialized_)
{
return rhs.initialized_; // Not initialized is less than initialized
}
else if (!rhs.initialized_) // Initialized is not less than not initialized
{
return false;
}
else
{
return resource_ < rhs.resource_;
}
}
/**
\brief Returns true
if this
is less than or equal to rhs
.
An instance that does not hold a resource is less than any instance that holds a resource.
Two instances that do not hold a resource are equal.
If the underlying operator\<
or operator==
throws an exception,
that exception is propagated to the caller.
\note This operator is available only if the underlying resource provides operator\<
and operator==
.
*/
template
bool ResourcePtr::operator<=(ResourcePtr const& rhs) const
{
if (this == &rhs) // This is necessary to avoid deadlock for self-comparison
{
return true;
}
// We can't just write:
//
// return *this < rhs || *this == rhs;
//
// because that creates a race condition: the locks would be released and
// re-aquired in between the two comparisons.
std::lock(m_, rhs.m_);
AdoptLock left(m_);
AdoptLock right(rhs.m_);
return resource_ < rhs.resource_ || resource_ == rhs.resource_;
}
/**
\brief Returns true
if this
is greater than rhs
.
An instance that holds a resource is greater than any instance that does not hold a resource.
If the underlying operator\<
or operator==
throws an exception,
that exception is propagated to the caller.
\note This operator is available only if the underlying resource provides operator\<
and operator==
.
*/
template
inline
bool ResourcePtr::operator>(ResourcePtr const& rhs) const
{
return !(*this <= rhs);
}
/**
\brief Returns true
if this
is greater than or equal to rhs
.
An instance that holds a resource is greater than any instance that does not hold a resource.
Two instances that do not hold a resource are equal.
If the underlying operator\<
throws an exception, that exception is propagated to the caller.
\note This operator is available only if the underlying resource provides operator\<
.
*/
template
inline
bool ResourcePtr::operator>=(ResourcePtr const& rhs) const
{
return !(*this < rhs);
}
} // namespace util
} // namespace unity
// Specializations in namespace std, so we play nicely with STL and metaprogramming.
namespace std
{
/**
\brief Function object for equality comparison.
*/
template
struct equal_to>
{
/**
Invokes operator==
on lhs
.
*/
bool operator()(unity::util::ResourcePtr const& lhs, unity::util::ResourcePtr const& rhs) const
{
return lhs == rhs;
}
};
/**
\brief Function object for inequality comparison.
*/
template
struct not_equal_to>
{
/**
Invokes operator!=
on lhs
.
*/
bool operator()(unity::util::ResourcePtr const& lhs, unity::util::ResourcePtr const& rhs) const
{
return lhs != rhs;
}
};
/**
\brief Function object for less than comparison.
*/
template
struct less>
{
/**
Invokes operator\<
on lhs
.
*/
bool operator()(unity::util::ResourcePtr const& lhs, unity::util::ResourcePtr const& rhs) const
{
return lhs < rhs;
}
};
/**
\brief Function object for less than or equal comparison.
*/
template
struct less_equal>
{
/**
Invokes operator\<=
on lhs
.
*/
bool operator()(unity::util::ResourcePtr const& lhs, unity::util::ResourcePtr const& rhs) const
{
return lhs <= rhs;
}
};
/**
\brief Function object for greater than comparison.
*/
template
struct greater>
{
/**
Invokes operator\>
on lhs
.
*/
bool operator()(unity::util::ResourcePtr const& lhs, unity::util::ResourcePtr const& rhs) const
{
return lhs > rhs;
}
};
/**
\brief Function object for less than or equal comparison.
*/
template
struct greater_equal>
{
/**
Invokes operator\>=
on lhs
.
*/
bool operator()(unity::util::ResourcePtr const& lhs, unity::util::ResourcePtr const& rhs) const
{
return lhs >= rhs;
}
};
// TODO: provide hash if std::hash exists.
} // namespace std
#endif
./include/unity/util/DefinesPtrs.h 0000644 0000041 0000041 00000003312 13070664454 017422 0 ustar www-data www-data /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#ifndef UNITY_UTIL_DEFINESPTRS_H
#define UNITY_UTIL_DEFINESPTRS_H
#include
/**
\file DefinesPtrs.h
\def UNITY_DEFINES_PTRS(classname)
\brief Macro to add smart pointer definitions to a class.
This macro injects type definitions for smart pointer types into a class. It is useful to
establish a common naming convention for smart pointers across a project.
You can use the macro as follows. Note that the macro argument is the name of the class being defined.
~~~
* class MyClass
* {
* public:
* UNITY_DEFINES_PTRS(MyClass);
* // MyClass now provides public typedefs for SPtr, SCPtr, UPtr, and UCPtr.
* // ...
* };
~~~
Callers of MyClass
can now, for example, write
~~~
* MyClass::UPtr p(new MyClass);
~~~
*/
#define UNITY_DEFINES_PTRS(classname) \
typedef std::shared_ptr SPtr; \
typedef std::shared_ptr SCPtr; \
typedef std::unique_ptr UPtr; \
typedef std::unique_ptr UCPtr
#endif
./include/unity/util/GioMemory.h 0000644 0000041 0000041 00000003713 13070664503 017103 0 ustar www-data www-data /*
* Copyright (C) 2013-2017 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Pete Woods
*/
#ifndef UNITY_UTIL_GIOMEMORY_H
#define UNITY_UTIL_GIOMEMORY_H
#include
#include
namespace unity
{
namespace util
{
namespace internal
{
struct GDBusSignalUnsubscriber
{
public:
void operator()(guint handle) noexcept
{
if (handle != 0 && G_IS_OBJECT(bus_.get()))
{
g_dbus_connection_signal_unsubscribe(bus_.get(), handle);
}
}
GObjectSPtr bus_;
};
}
typedef ResourcePtr GDBusSignalConnection;
/**
\brief Simple wrapper to manage the lifecycle of manual GDBus signal connections.
When 'signalConnection_' goes out of scope or is dealloc'ed, the connection will be removed:
\code{.cpp}
GDBusSignalConnection signalConnection_;
signalConnection_ = gdbus_signal_connection(
g_dbus_connection_signal_subscribe(bus.get(), nullptr, "org.does.not.exist", nullptr, "/does/not/exist", nullptr, G_DBUS_SIGNAL_FLAGS_NONE, on_dbus_signal, this, nullptr), bus);
\endcode
*/
inline GDBusSignalConnection gdbus_signal_connection(guint id, GObjectSPtr bus) noexcept
{
return GDBusSignalConnection(id, internal::GDBusSignalUnsubscriber{bus});
}
} // namespace until
} // namespace unity
#endif
./include/unity/util/internal/ 0000755 0000041 0000041 00000000000 13070664454 016640 5 ustar www-data www-data ./include/unity/util/internal/DaemonImpl.h 0000644 0000041 0000041 00000002754 13070664454 021046 0 ustar www-data www-data /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#ifndef UNITY_UTIL_DAEMONIMPL_H
#define UNITY_UTIL_DAEMONIMPL_H
#include
#include
#include
#include
namespace unity
{
namespace util
{
namespace internal
{
class DaemonImpl final
{
public:
NONCOPYABLE(DaemonImpl);
DaemonImpl();
~DaemonImpl() = default;
void close_fds() noexcept;
void reset_signals() noexcept;
void set_umask(mode_t mask) noexcept;
void set_working_directory(std::string const& working_directory);
void daemonize_me();
private:
bool close_fds_;
bool reset_signals_;
bool set_umask_;
mode_t umask_;
std::string working_directory_;
void close_open_files() noexcept;
};
} // namespace internal
} // namespace util
} // namespace unity
#endif
./include/unity/util/Daemon.h 0000644 0000041 0000041 00000011177 13070664454 016407 0 ustar www-data www-data /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#ifndef UNITY_UTIL_DAEMON_H
#define UNITY_UTIL_DAEMON_H
#include
#include
#include
namespace unity
{
namespace util
{
namespace internal
{
class DaemonImpl;
}
/**
\class Daemon
\brief Helper class to turn a process into a daemon.
To turn a process into a daemon, instantiate this class and call daemonize_me().
The new process becomes a session leader without a control terminal. The standard
file descriptors (stdin
, stdout
, and stderr) are closed
and re-opened to /dev/null
.
By default, any file descriptors (other than the standard three) that are open in the process
remain open to the same destinations in the daemon. If you want to have other descriptors closed, call
close_fds() before calling daemonize_me(). This will close all file descriptors > 2.
By default, the signal disposition of the daemon is unchanged. To reset all signals to their
default disposition, call reset_signals() before calling daemonize_me().
By default, the umask of the daemon is unchanged. To set a different umask, call set_umask()
before calling daemonize_me().
By default, the working directory of the daemon is unchanged. To run the daemon with a different
working directory, call set_working_dir() before calling daemonize_me(). Note that the working
directory should be set to a path that is in the root file system. If the working directory
is in any other file system, that file system cannot be unmounted while the daemon is running.
Note: This class is not async signal-safe. Do not call daemonize_me() from a a signal handler.
*/
class UNITY_API Daemon final
{
public:
/// @cond
NONCOPYABLE(Daemon);
UNITY_DEFINES_PTRS(Daemon);
/// @endcond
/**
\brief Create a Daemon instance.
\return A unique_ptr
to the instance.
*/
static UPtr create();
/**
\brief Causes daemonize_me() to close all open file descriptors other than the standard file
descriptors (which are connected /dev/null
).
*/
void close_fds() noexcept;
/**
\brief Causes daemonize_me() to reset all signals to their default behavior.
*/
void reset_signals() noexcept;
/**
\brief Causes daemonize_me() to set the umask.
\param mask The umask for the daemon process.
*/
void set_umask(mode_t mask) noexcept;
/**
\brief Causes daemonize_me() to set the working directory.
\param working_directory The working directory for the daemon process.
\throws SyscallException The process could not change the working directory to the specified directory.
\note Daemon processes should set their working to "/" or to a directory that is part of the root file system.
Otherwise, the file system containing the daemon's working directory cannot be unmounted without first
killing the daemon process.
*/
void set_working_directory(std::string const& working_directory);
/**
\brief Turns the calling process into a daemon.
By default, daemonize_me() leaves open file descriptors, signal disposition, umask, and working
directory unchanged. Call the corresponding member function before calling daemonize_me() to
change this behavior as appropriate.
\note Calling daemonize_me() more than once is safe; any changes to file descriptors, signal disposition,
umask, or working directory as requested by calling the other member functions will be correctly set
for the calling process. However, daemonize_me() is not a cheap call because it calls fork()
;
the normal use pattern is to create a Daemon instance, select the desired settings, call daemonize_me(),
and let the instance go out of scope.
*/
void daemonize_me();
~Daemon() noexcept;
private:
Daemon(); // Class is final, instantiation only via create()
std::unique_ptr p_;
};
} // namespace util
} // namespace unity
#endif
./include/unity/UnityExceptions.h 0000644 0000041 0000041 00000013446 13070664454 017402 0 ustar www-data www-data /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#ifndef UNITY_EXCEPTIONS_H
#define UNITY_EXCEPTIONS_H
#include
namespace unity
{
/**
\brief Exception to indicate that an invalid argument was passed to a function, such as passing nullptr
when the function expects the argument to be non-null.
*/
class UNITY_API InvalidArgumentException : public Exception
{
public:
/**
\brief Constructs the exception.
\param reason Further details about the cause of the exception.
*/
explicit InvalidArgumentException(std::string const& reason);
//! @cond
InvalidArgumentException(InvalidArgumentException const&);
InvalidArgumentException& operator=(InvalidArgumentException const&);
virtual ~InvalidArgumentException() noexcept;
//! @endcond
/**
\brief Returns a std::exception_ptr
to this
.
*/
virtual std::exception_ptr self() const override;
};
/**
\brief Exception to indicate a logic error, such as driving the API incorrectly, such as calling methods
in the wrong worder.
*/
class UNITY_API LogicException : public Exception
{
public:
/**
\brief Constructs the exception.
\param reason Further details about the cause of the exception.
*/
explicit LogicException(std::string const& reason);
//! @cond
LogicException(LogicException const&);
LogicException& operator=(LogicException const&);
virtual ~LogicException() noexcept;
//! @endcond
/**
\brief Returns a std::exception_ptr
to this
.
*/
virtual std::exception_ptr self() const override;
};
/**
\brief Exception to indicate errors during shutdown.
Usually, it is not possible to handle or recover
from errors that arise during shutdown. This exception is thrown once all possible shutdown actions
have been carried out and provides information about anything that went wrong via the exception
chaining mechanism of the unity::Exception base class.
*/
class UNITY_API ShutdownException : public Exception
{
public:
/**
\brief Constructs the exception.
\param reason Further details about the cause of the exception.
*/
explicit ShutdownException(std::string const& reason);
//! @cond
ShutdownException(ShutdownException const&);
ShutdownException& operator=(ShutdownException const&);
virtual ~ShutdownException() noexcept;
//! @endcond
/**
\brief Returns a std::exception_ptr
to this
.
*/
virtual std::exception_ptr self() const override;
};
/**
\brief Exception to indicate file I/O errors, such as failure to open or write to a file.
*/
class UNITY_API FileException : public Exception
{
public:
/**
\brief Constructs the exception.
*/
/**
\brief Constructs the exception from a reason string and and error number.
\param reason Further details about the cause of the exception.
\param err The UNIX errno
value for the error.
*/
FileException(std::string const& reason, int err);
//! @cond
FileException(FileException const&);
FileException& operator=(FileException const&);
virtual ~FileException() noexcept;
//! @endcond
/**
\brief Returns a std::exception_ptr
to this
.
*/
virtual std::exception_ptr self() const override;
/**
\return Returns the error number that was passed to the constructor.
*/
int error() const noexcept;
private:
int err_;
};
/**
\brief Exception to indicate system or library call errors that set errno
.
*/
class UNITY_API SyscallException : public Exception
{
public:
/**
\brief Constructs the exception.
*/
/**
\brief Constructs the exception from a reason string and and error number.
\param reason Further details about the cause of the exception.
\param err The UNIX errno
value for the error.
*/
SyscallException(std::string const& reason, int err);
//! @cond
SyscallException(SyscallException const&);
SyscallException& operator=(SyscallException const&);
virtual ~SyscallException() noexcept;
//! @endcond
/**
\brief Returns a std::exception_ptr
to this
.
*/
virtual std::exception_ptr self() const override;
/**
\return Returns the error number that was passed to the constructor.
*/
int error() const noexcept;
private:
int err_;
};
/**
\brief Exception for miscellaneous errors, such as failure of a third-party library or hitting resource limitations.
*/
class UNITY_API ResourceException : public Exception
{
public:
/**
\brief Constructs the exception.
\param reason Further details about the cause of the exception.
*/
explicit ResourceException(std::string const& reason);
//! @cond
ResourceException(ResourceException const&);
ResourceException& operator=(ResourceException const&);
virtual ~ResourceException() noexcept;
//! @endcond
/**
\brief Returns a std::exception_ptr
to this
.
*/
virtual std::exception_ptr self() const override;
};
} // namespace unity
#endif
./include/unity/CMakeLists.txt 0000644 0000041 0000041 00000000535 13070664454 016612 0 ustar www-data www-data add_subdirectory(api)
add_subdirectory(shell)
add_subdirectory(util)
file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
file(GLOB internal_headers "${CMAKE_CURRENT_SOURCE_DIR}/internal/*.h")
install(FILES ${headers} DESTINATION ${HDR_INSTALL_DIR}/unity)
set(UNITY_API_LIB_HDRS ${UNITY_API_LIB_HDRS} ${headers} ${internal_headers} PARENT_SCOPE)
./include/unity/Exception.h 0000644 0000041 0000041 00000010111 13070664454 016150 0 ustar www-data www-data /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#ifndef UNITY_EXCEPTION_H
#define UNITY_EXCEPTION_H
#include
#include
#include
#include
namespace unity
{
class ExceptionImplBase;
/**
\brief Abstract base class for all Unity exceptions.
This class is the base class for all Unity exceptions. Besides providing a common base class for
structured exception handling, this class provides features to capture nested exceptions (for
exceptions that are re-thrown) and to chain exceptions into an exception history that allows
a number of exceptions to be remembered before throwing a new exception.
The exception nesting is provided by the derivation from std::nested_exception
. If you
catch an exception and throw another exception from the catch handler, the caught exception
is automatically preserved; you can access nested exceptions by calling the nested_ptr()
and
rethrow_nested()
member functions of std::nested_exception
.
In addition, you can remember one or more exceptions by calling remember(). This is useful in situations
where you need to perform a number of actions that may fail with an error code, and you do not want to
throw an exception until all of the actions have been attempted. This is particularly useful in shutdown
scenarios, where it is often impossible to recover from an error, but it is still desirable to try to
shut down as much as possible before reporting or logging the errors:
~~~
void
shutdown()
{
using namespace std;
exception_ptr ep;
try
{
shutdown_action_1();
}
catch (SomeException const&)
{
ep = make_exception_ptr(current_exception());
}
try
{
shutdown_action_2();
}
catch (SomeOtherException const&)
{
ep = e.remember(ep);
}
int err = shutdown_action_3();
if (err != 0)
{
try
{
throw YetAnotherException(err);
}
catch (YetAnotherException const& e)
{
ep = e.remember(ep);
}
}
if (ep)
{
rethrow_exception(ep);
}
}
~~~
Calling what() on a caught exception returns a string with the entire exception history (both nested and
chained).
*/
class UNITY_API Exception : public std::exception, public std::nested_exception
{
public:
//! @cond
Exception(Exception const&);
Exception& operator=(Exception const&);
virtual ~Exception() noexcept;
//! @endcond
char const* what() const noexcept override;
/**
\brief Returns a std::exception_ptr
to this
.
\note Derived exceptions must implement this member function so the implemention of remember()
(provided by this abstract base class) can return a std::exception_ptr
to its own derived exception.
*/
virtual std::exception_ptr self() const = 0;
std::string name() const;
std::string reason() const;
std::string to_string(std::string const& indent = " ") const;
std::string to_string(int indent_level, std::string const& indent) const;
std::exception_ptr remember(std::exception_ptr earlier_exception);
std::exception_ptr get_earlier() const noexcept;
protected:
Exception(std::string const& name, std::string const& reason);
private:
std::string name_;
std::string reason_;
mutable std::string what_;
std::exception_ptr earlier_;
};
} // namespace unity
#endif
./include/unity/SymbolExport.h 0000644 0000041 0000041 00000002007 13070664454 016666 0 ustar www-data www-data /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#ifndef SYMBOL_EXPORT_H
#define SYMBOL_EXPORT_H
#define UNITY_HELPER_DLL_EXPORT __attribute__ ((visibility ("default")))
#ifdef UNITY_DLL_EXPORTS // Defined if we are building the Unity API library
# define UNITY_API UNITY_HELPER_DLL_EXPORT
#else
# define UNITY_API /**/
#endif
#endif
./include/unity/api/ 0000755 0000041 0000041 00000000000 13070664454 014620 5 ustar www-data www-data ./include/unity/api/CMakeLists.txt 0000644 0000041 0000041 00000000631 13070664454 017360 0 ustar www-data www-data file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
file(GLOB internal_headers "${CMAKE_CURRENT_SOURCE_DIR}/internal/*.h")
#
# Generated headers
#
configure_file(Version.h.in Version.h)
set(headers ${headers} ${CMAKE_CURRENT_BINARY_DIR}/Version.h)
install(FILES ${headers} DESTINATION ${HDR_INSTALL_DIR}/unity/api)
set(UNITY_API_LIB_HDRS ${UNITY_API_LIB_HDRS} ${headers} ${internal_headers} PARENT_SCOPE)
./include/unity/api/Version.h.in 0000644 0000041 0000041 00000005652 13070664454 017033 0 ustar www-data www-data //
// DO NOT EDIT Version.h (this file)! It is generated from Version.h.in.
//
/*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include
#ifndef UNITY_API_VERSION_H
#define UNITY_API_VERSION_H
#define UNITY_API_VERSION_MAJOR @UNITY_API_MAJOR@
#define UNITY_API_VERSION_MINOR @UNITY_API_MINOR@
#define UNITY_API_VERSION_MICRO @UNITY_API_MICRO@
#define UNITY_API_VERSION_STRING "@UNITY_API_VERSION@"
/**
\brief Top-level namespace for all things Unity-related.
*/
namespace unity
{
/**
\brief Top-level namespace for public functionality of the Unity API.
*/
namespace api
{
/** @name Version information
Version information is represented as
<major
>.<minor
>.<micro
>.
Releases that differ in the major version number are binary incompatible.
Releases that differ in the minor or micro version number are binary compatible with older releases,
so client code does not need to be recompiled to use the newer library version.
Changes in the micro version number indicate bug fixes.
Changes in the minor version indicate feature additions that are binary compatible.
*/
/**
\brief Returns the major version number of the Unity API library.
The major version number is also available as the macro UNITY_API_VERSION_MAJOR
.
*/
/// @cond
UNITY_API
/// @endcond
int major_version();
/**
\brief Returns the minor version number of the Unity API library.
The minor version number is also available as the macro UNITY_API_VERSION_MINOR
.
*/
/// @cond
UNITY_API
/// @endcond
int minor_version();
/**
\brief Returns the micro version number of the Unity API library.
The micro version number is also available as the macro UNITY_API_VERSION_MICRO
.
*/
/// @cond
UNITY_API
/// @endcond
int micro_version();
/**
\brief Returns the Unity API version as a string in the format
<major
>.<minor
>.<micro
>.
The version string is also available as the macro UNITY_API_VERSION_STRING
.
*/
/// @cond
UNITY_API
/// @endcond
const char* str(); // Returns "major.minor.micro"
/// }@
// TODO: Add methods to report compiler version and compiler flags
} // namespace api
} // namespace unity
#endif
./include/unity/api/internal/ 0000755 0000041 0000041 00000000000 13070664453 016433 5 ustar www-data www-data ./include/unity/shell/ 0000755 0000041 0000041 00000000000 13070664454 015156 5 ustar www-data www-data ./include/unity/shell/CMakeLists.txt 0000644 0000041 0000041 00000000620 13070664454 017714 0 ustar www-data www-data add_subdirectory(notifications)
add_subdirectory(launcher)
add_subdirectory(application)
add_subdirectory(scopes)
file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
file(GLOB internal_headers "${CMAKE_CURRENT_SOURCE_DIR}/internal/*.h")
install(FILES ${headers} DESTINATION ${HDR_INSTALL_DIR}/unity/shell)
set(UNITY_API_LIB_HDRS ${UNITY_API_LIB_HDRS} ${headers} ${internal_headers} PARENT_SCOPE)
./include/unity/shell/notifications/ 0000755 0000041 0000041 00000000000 13070664454 020027 5 ustar www-data www-data ./include/unity/shell/notifications/CMakeLists.txt 0000644 0000041 0000041 00000001400 13070664454 022562 0 ustar www-data www-data set(INCLUDE_INSTALL_DIR include/unity/shell/notifications)
file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
file(GLOB internal_headers "${CMAKE_CURRENT_SOURCE_DIR}/internal/*.h")
install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_DIR})
set(UNITY_API_LIB_HDRS ${UNITY_API_LIB_HDRS} ${headers} ${internal_headers} PARENT_SCOPE)
set(VERSION 3)
set(PKGCONFIG_NAME "unity-shell-notifications")
set(PKGCONFIG_DESCRIPTION "Unity shell Notifications APIs")
set(PKGCONFIG_REQUIRES "Qt5Core")
set(PKGCONFIG_FILE unity-shell-notifications.pc)
configure_file(${CMAKE_SOURCE_DIR}/data/unity-shell-api.pc.in
${CMAKE_BINARY_DIR}/data/${PKGCONFIG_FILE} @ONLY
)
install(FILES ${CMAKE_BINARY_DIR}/data/${PKGCONFIG_FILE}
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
./include/unity/shell/notifications/Enums.h 0000644 0000041 0000041 00000005507 13070664454 021276 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authors:
* Michał Sawicz
*/
#ifndef UNITY_SHELL_NOTIFICATIONS_ENUMS_H
#define UNITY_SHELL_NOTIFICATIONS_ENUMS_H
#include
#include
namespace unity
{
namespace shell
{
namespace notifications
{
/**
\brief Wraps NotificationInterface's urgency enumeration.
*/
class UNITY_API Urgency : public QObject
{
Q_OBJECT
public:
/**
\brief NotificationInterface's urgency enumeration.
This determines the order in which notifications are displayed.
*/
enum class UrgencyEnum
{
Invalid = 0,
Low, /**< Displayed last. */
Normal, /**< Displayed before Low, after Critical. */
Critical /**< Displayed before Low and Normal. */
};
Q_ENUM(UrgencyEnum)
};
/**
\brief Wraps NotificationInterface's type enumeration.
*/
class UNITY_API Type : public QObject
{
Q_OBJECT
public:
/**
\brief NotificationInterface's type enumeration.
This determines the visual and interaction behavior of the displayed notification.
*/
enum class TypeEnum
{
Invalid = 0,
Confirmation, /**< Confirmation (synchronous). */
Ephemeral, /**< Ephemeral (input-transparent). */
Interactive, /**< Interactive (clickable). */
SnapDecision, /**< Snap decision (multi-button). */
Placeholder /**< Non-visible placeholder of default size. */
};
Q_ENUM(TypeEnum)
};
/**
\brief Wraps NotificationInterface's hint flags.
*/
class UNITY_API Hint : public QObject
{
Q_OBJECT
public:
/**
\brief NotificationInterface's hint flags.
This modifies some visual and interactive behavior of the displayed notification.
*/
enum HintEnum
{
Invalid = 1 << 0,
ButtonTint = 1 << 1, /**< Use a colour tint on the positive button in a snap decision. */
IconOnly = 1 << 2 /**< Only display the icon, no summary or body. */
};
Q_FLAG(HintEnum)
Q_DECLARE_FLAGS(Hints, HintEnum)
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Hint::Hints)
} // namespace notifications
} // namespace shell
} // namespace unity
#endif // UNITY_SHELL_NOTIFICATIONS_ENUMS_H
./include/unity/shell/notifications/ModelInterface.h 0000644 0000041 0000041 00000007105 13070664454 023064 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authors:
* Michał Sawicz
*/
#ifndef UNITY_SHELL_NOTIFICATIONS_MODELINTERFACE_H
#define UNITY_SHELL_NOTIFICATIONS_MODELINTERFACE_H
#include
#include
namespace unity
{
namespace shell
{
namespace notifications
{
/**
\brief A list of notifications to be displayed
This model exposes all the notifications that are currently supposed to be on screen.
Not all of them might actually get on screen due to screen size, in which case the
NotificationInterface::displayed() signal will only be emitted after the notification was
actually displayed.
*/
class UNITY_API ModelInterface : public QAbstractListModel
{
Q_OBJECT
/**
\brief Whether a placeholder for confirmation should be kept at the beginning
When this is true, the model should hold a Placeholder type notification at the top
and update its data when an incoming Confirmation type notification is sent.
\accessors %confirmationPlaceholder(), setConfirmationPlaceholder(bool confirmationPlaceholder)
\notifier confirmationPlaceholderChanged(bool confirmationPlaceholder)
*/
Q_PROPERTY(bool confirmationPlaceholder READ confirmationPlaceholder WRITE setConfirmationPlaceholder NOTIFY confirmationPlaceholderChanged)
protected:
/// @cond
explicit ModelInterface(QObject* parent = 0) : QAbstractListModel(parent) { }
/// @endcond
public:
virtual ~ModelInterface() { }
/// @cond
virtual bool confirmationPlaceholder() const = 0;
virtual void setConfirmationPlaceholder(bool confirmationPlaceholder) = 0;
/// @endcond
/**
\brief NotificationModel's data-role enumeration.
The different data-entries of a notification element in the model.
*/
enum Roles {
RoleType = Qt::UserRole + 1, /** type of notification */
RoleUrgency = Qt::UserRole + 2, /** urgency of notification */
RoleId = Qt::UserRole + 3, /** internal id set by daemon */
RoleSummary = Qt::UserRole + 4, /** summary-text */
RoleBody = Qt::UserRole + 5, /** body-text */
RoleValue = Qt::UserRole + 6, /** 0..100 value */
RoleIcon = Qt::UserRole + 7, /** main icon */
RoleSecondaryIcon = Qt::UserRole + 8, /** optional 2nd icon */
RoleActions = Qt::UserRole + 9, /** attached optional actions */
RoleHints = Qt::UserRole + 10, /** attached hints */
RoleNotification = Qt::UserRole + 11 /** notification object */
};
Q_ENUM(Roles)
Q_SIGNALS:
/**
Emitted when value of the confirmationPlaceholder property has changed.
\param confirmationPlaceholder New value of the confirmationPlaceholder property.
*/
void confirmationPlaceholderChanged(bool confirmationPlaceholder);
};
} // namespace notifications
} // namespace shell
} // namespace unity
#endif // UNITY_SHELL_NOTIFICATIONS_MODELINTERFACE_H
./include/unity/shell/notifications/NotificationInterface.h 0000644 0000041 0000041 00000004335 13070664454 024454 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authors:
* Michał Sawicz
*/
#ifndef UNITY_SHELL_NOTIFICATIONS_NOTIFICATIONINTERFACE_H
#define UNITY_SHELL_NOTIFICATIONS_NOTIFICATIONINTERFACE_H
#include
#include
namespace unity
{
namespace shell
{
namespace notifications
{
/**
\brief A Notification object
This class exposes signals used by the UI to communicate the state
of a notification.
*/
class UNITY_API NotificationInterface : public QObject
{
Q_OBJECT
protected:
/// @cond
explicit NotificationInterface(QObject* parent = 0) : QObject(parent) { }
/// @endcond
public:
virtual ~NotificationInterface() { }
Q_SIGNALS:
/**
Will be called whenever the mouse hover status of a notification changes.
\param hovered Mouse hover status of this notification.
*/
void hovered(bool hovered);
/**
Will be called whenever the display status of a notification changes.
\param displayed Visible/hidden status of this notification.
*/
void displayed(bool displayed);
/**
Will be called whenever the notification was dismissed. This can be called internally
by the notification implementation (e.g. timeout) or from the UI when the user dismisses
a notification.
*/
void dismissed();
/**
Will be called whenever an action of this notification is to be invoked.
\param id Id of the invoked action.
*/
void actionInvoked(const QString& id);
};
} // namespace notifications
} // namespace shell
} // namespace unity
#endif // UNITY_SHELL_NOTIFICATIONS_NOTIFICATIONINTERFACE_H
./include/unity/shell/notifications/SourceInterface.h 0000644 0000041 0000041 00000004026 13070664454 023263 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authors:
* Michał Sawicz
*/
#ifndef UNITY_SHELL_NOTIFICATIONS_SOURCEINTERFACE_H
#define UNITY_SHELL_NOTIFICATIONS_SOURCEINTERFACE_H
#include
#include
namespace unity
{
namespace shell
{
namespace notifications
{
class ModelInterface;
/**
\brief A source of notifications
This should feed the model with new notifications from an implementation-specific
source.
*/
class UNITY_API SourceInterface : public QObject
{
Q_OBJECT
/**
\brief The model to which to send incoming notifications.
\accessors %model(), setModel(ModelInterface* model)
\notifier modelChanged(ModelInterface* model)
*/
Q_PROPERTY(unity::shell::notifications::ModelInterface* model READ model WRITE setModel NOTIFY modelChanged)
protected:
/// @cond
explicit SourceInterface(QObject* parent = 0) : QObject(parent) { }
/// @endcond
public:
virtual ~SourceInterface() { }
/// @cond
virtual ModelInterface* model() const = 0;
virtual void setModel(ModelInterface* model) = 0;
/// @endcond
Q_SIGNALS:
/**
Emitted when value of the model property has changed.
\param model New value of the model property.
*/
void modelChanged(ModelInterface* model);
};
} // namespace notifications
} // namespace shell
} // namespace unity
#endif // UNITY_SHELL_NOTIFICATIONS_SOURCEINTERFACE_H
./include/unity/shell/application/ 0000755 0000041 0000041 00000000000 13070664454 017461 5 ustar www-data www-data ./include/unity/shell/application/CMakeLists.txt 0000644 0000041 0000041 00000001367 13070664454 022230 0 ustar www-data www-data set(INCLUDE_INSTALL_DIR include/unity/shell/application)
file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
file(GLOB internal_headers "${CMAKE_CURRENT_SOURCE_DIR}/internal/*.h")
install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_DIR})
set(UNITY_API_LIB_HDRS ${UNITY_API_LIB_HDRS} ${headers} ${internal_headers} PARENT_SCOPE)
set(VERSION 27)
set(PKGCONFIG_NAME "unity-shell-application")
set(PKGCONFIG_DESCRIPTION "Unity shell Application APIs")
set(PKGCONFIG_REQUIRES "Qt5Core")
set(PKGCONFIG_FILE unity-shell-application.pc)
configure_file(${CMAKE_SOURCE_DIR}/data/unity-shell-api.pc.in
${CMAKE_BINARY_DIR}/data/${PKGCONFIG_FILE} @ONLY
)
install(FILES ${CMAKE_BINARY_DIR}/data/${PKGCONFIG_FILE}
DESTINATION ${LIB_INSTALL_PREFIX}/pkgconfig
)
./include/unity/shell/application/MirMousePointerInterface.h 0000644 0000041 0000041 00000006144 13070664454 024561 0 ustar www-data www-data /*
* Copyright (C) 2015-2016 Canonical, Ltd.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3, as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#ifndef MIR_MOUSE_POINTER_INTERFACE_H
#define MIR_MOUSE_POINTER_INTERFACE_H
#include
/**
* @brief The QML mouse pointer
*
* FIXME: Get this out of unity-api
*
* This QML item drives the position of the Mir mouse pointer on the scene
*/
class MirMousePointerInterface : public QQuickItem {
Q_OBJECT
/**
* @brief Name of the cursor
* Defines the look of the mouse pointer along with themeName
*/
Q_PROPERTY(QString cursorName READ cursorName NOTIFY cursorNameChanged)
/**
* @brief Name of the cursor theme
* Defines the look of the mouse pointer along with cursorName
* Its default value is "default".
*/
Q_PROPERTY(QString themeName READ themeName NOTIFY themeNameChanged)
public:
/**
* @brief The constructor
*/
MirMousePointerInterface(QQuickItem *parent = nullptr) : QQuickItem(parent) {}
/// @cond
virtual void setCursorName(const QString &cursorName) = 0;
virtual QString cursorName() const = 0;
virtual void setThemeName(const QString &themeName) = 0;
virtual QString themeName() const = 0;
/// @endcond
/**
* @brief Sets the custom cursor
*
* If it's not a pixmap cursor it will be ignored.
*
* To use it, cursorName must be set to "custom". themeName is ignored in this case.
*/
virtual void setCustomCursor(const QCursor &) = 0;
Q_SIGNALS:
/// @cond
void cursorNameChanged(QString name);
void themeNameChanged(QString name);
/// @endcond
public Q_SLOTS:
/**
* @brief Handler for Mir mouse events
* The implementation should respond to Mir mouse events by moving itself along its parent
* area.
* This is called by Mir's platform cursor.
*
* Note that we get only relative mouse movement, since the mouse pointer position is defined
* by this very item. Ie., it's up to this class to decide whether or not it (the mouse pointer)
* should move (and how much) due to movement in a mouse device.
*
* @param movement Movement vector
*/
virtual void handleMouseEvent(ulong timestamp, QPointF movement, Qt::MouseButtons buttons,
Qt::KeyboardModifiers modifiers) = 0;
/**
* @brief Handler for Mir mouse wheel events
* This is called by Mir's platform cursor.
*/
virtual void handleWheelEvent(ulong timestamp, QPoint angleDelta, Qt::KeyboardModifiers modifiers) = 0;
};
#endif // MIR_MOUSE_POINTER_INTERFACE_H
./include/unity/shell/application/ApplicationManagerInterface.h 0000644 0000041 0000041 00000013721 13070664454 025215 0 ustar www-data www-data /*
* Copyright 2013,2016 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authors:
* Michael Zanetti
*/
#ifndef UNITY_SHELL_APPLICATION_APPLICATIONMANAGERINTERFACE_H
#define UNITY_SHELL_APPLICATION_APPLICATIONMANAGERINTERFACE_H
#include
#include
#include
namespace unity
{
namespace shell
{
namespace application
{
class ApplicationInfoInterface;
class MirSurfaceInterface;
/**
* @brief The Application manager
*
* This is the main class to interact with Applications
*/
class UNITY_API ApplicationManagerInterface: public QAbstractListModel
{
Q_OBJECT
/**
* @brief The count of the applications known to the manager.
*
* This is the same as rowCount, added in order to keep compatibility with QML ListModels.
*/
Q_PROPERTY(int count READ count NOTIFY countChanged)
/**
* @brief The currently focused application.
*
* Use focusApplication() and unfocusCurrentApplication() to modify this.
*/
Q_PROPERTY(QString focusedApplicationId READ focusedApplicationId NOTIFY focusedApplicationIdChanged)
protected:
/// @cond
ApplicationManagerInterface(QObject* parent = 0): QAbstractListModel(parent)
{
m_roleNames.insert(RoleAppId, "appId");
m_roleNames.insert(RoleName, "name");
m_roleNames.insert(RoleComment, "comment");
m_roleNames.insert(RoleIcon, "icon");
m_roleNames.insert(RoleState, "state");
m_roleNames.insert(RoleFocused, "focused");
m_roleNames.insert(RoleIsTouchApp, "isTouchApp");
m_roleNames.insert(RoleExemptFromLifecycle, "exemptFromLifecycle");
m_roleNames.insert(RoleApplication, "application");
connect(this, SIGNAL(rowsInserted(QModelIndex, int, int)), SIGNAL(countChanged()));
connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)), SIGNAL(countChanged()));
connect(this, SIGNAL(modelReset()), SIGNAL(countChanged()));
connect(this, SIGNAL(layoutChanged()), SIGNAL(countChanged()));
}
/// @endcond
public:
/**
* @brief The Roles supported by the model
*
* See ApplicationInfoInterface properties for details.
*/
enum Roles {
RoleAppId = Qt::UserRole,
RoleName,
RoleComment,
RoleIcon,
RoleState,
RoleFocused,
RoleIsTouchApp,
RoleExemptFromLifecycle,
RoleApplication,
};
Q_ENUM(Roles)
/// @cond
virtual ~ApplicationManagerInterface() {}
QHash roleNames() const override
{
return m_roleNames;
}
int count() const {
return rowCount();
}
virtual QString focusedApplicationId() const = 0;
/// @endcond
/**
* @brief Get an ApplicationInfo item (using stack index).
*
* Note: QML requires the full namespace in the return value.
*
* @param index the index of the item to get
* @returns The item, or null if not found.
*/
Q_INVOKABLE virtual unity::shell::application::ApplicationInfoInterface *get(int index) const = 0;
/**
* @brief Get an ApplicationInfo item (using the appId).
*
* Note: QML requires the full namespace in the return value.
*
* @param appId the appId of the item to get
* @returns The item, or null if not found.
*/
Q_INVOKABLE virtual unity::shell::application::ApplicationInfoInterface *findApplication(const QString &appId) const = 0;
/*
* @brief Returns the AplicationInfo with the given surface
*/
virtual ApplicationInfoInterface *findApplicationWithSurface(MirSurfaceInterface* surface) const = 0;
/**
* @brief Request to focus a given application
*
* This will request the shell to focus the given application.
*
* @param appId The appId of the app to be focused.
* @returns True if the request will processed, false if it was discarded (i.e. the given appid could not be found)
*/
Q_INVOKABLE virtual bool requestFocusApplication(const QString &appId) = 0;
/**
* @brief Start an application.
*
* @param appId The appId for the application to be spawned.
* @param arguments Any arguments to be passed to the process.
* @returns The created application item if start successful, else null.
*/
Q_INVOKABLE virtual unity::shell::application::ApplicationInfoInterface *startApplication(const QString &appId, const QStringList &arguments) = 0;
/**
* @brief Stops an application.
*
* @param appId The application to be stopped.
* @returns True if application stop successful, else false (i.e. false if application was not running).
*/
Q_INVOKABLE virtual bool stopApplication(const QString &appId) = 0;
Q_SIGNALS:
/// @cond
void countChanged();
/// @endcond
/**
* @brief Will be emitted right before the focused application changes.
*
* This can be used to prepare for an upcoming focus change. For example starting
* an animation.
*/
void focusRequested(const QString &appId);
/**
* @brief Will be emitted whenever the focused application changes.
*/
void focusedApplicationIdChanged();
protected:
/// @cond
QHash m_roleNames;
/// @endcond
};
} // namespace application
} // namespace shell
} // namespace unity
#endif // UNITY_SHELL_APPLICATIONMANAGER_APPLICATIONINFO_H
./include/unity/shell/application/MirSurfaceInterface.h 0000644 0000041 0000041 00000022065 13070664454 023520 0 ustar www-data www-data /*
* Copyright (C) 2015-2016 Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef UNITY_SHELL_APPLICATION_MIRSURFACE_H
#define UNITY_SHELL_APPLICATION_MIRSURFACE_H
#include
#include
#include
#include "Mir.h"
namespace unity
{
namespace shell
{
namespace application
{
class MirSurfaceListInterface;
/**
@brief Holds a Mir surface. Pretty much an opaque class.
All surface manipulation is done by giving it to a MirSurfaceItem and then
using MirSurfaceItem's properties.
*/
class MirSurfaceInterface : public QObject
{
Q_OBJECT
/**
* @brief The surface type
*/
Q_PROPERTY(Mir::Type type READ type NOTIFY typeChanged)
/**
* @brief Name of the surface, given by the client application
*/
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
/**
* @brief Persistent Id of the surface
*/
Q_PROPERTY(QString persistentId READ persistentId CONSTANT)
/**
* @brief App Id of the app this surface belongs to
*/
Q_PROPERTY(QString appId READ appId CONSTANT)
/**
* @brief Position of the current surface buffer, in pixels.
*/
Q_PROPERTY(QPoint position READ position NOTIFY positionChanged)
/**
* @brief Requested position of the current surface buffer, in pixels.
*/
Q_PROPERTY(QPoint requestedPosition READ requestedPosition WRITE setRequestedPosition NOTIFY requestedPositionChanged)
/**
* @brief Size of the current surface buffer, in pixels.
*/
Q_PROPERTY(QSize size READ size NOTIFY sizeChanged)
/**
* @brief State of the surface
*/
Q_PROPERTY(Mir::State state READ state NOTIFY stateChanged)
/**
* @brief True if it has a mir client bound to it.
* A "zombie" (live == false) surface never becomes alive again.
*/
Q_PROPERTY(bool live READ live NOTIFY liveChanged)
/**
* @brief Visibility of the surface
*/
Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
/**
* @brief Orientation angle of the surface
*
* How many degrees, clockwise, the UI in the surface has to rotate to match shell's UI orientation
*/
Q_PROPERTY(Mir::OrientationAngle orientationAngle READ orientationAngle WRITE setOrientationAngle
NOTIFY orientationAngleChanged DESIGNABLE false)
/**
* @brief The requested minimum width for the surface
* Zero if not set
*/
Q_PROPERTY(int minimumWidth READ minimumWidth NOTIFY minimumWidthChanged)
/**
* @brief The requested minimum height for the surface
* Zero if not set
*/
Q_PROPERTY(int minimumHeight READ minimumHeight NOTIFY minimumHeightChanged)
/**
* @brief The requested maximum width for the surface
* Zero if not set
*/
Q_PROPERTY(int maximumWidth READ maximumWidth NOTIFY maximumWidthChanged)
/**
* @brief The requested maximum height for the surface
* Zero if not set
*/
Q_PROPERTY(int maximumHeight READ maximumHeight NOTIFY maximumHeightChanged)
/**
* @brief The requested width increment for the surface
* Zero if not set
*/
Q_PROPERTY(int widthIncrement READ widthIncrement NOTIFY widthIncrementChanged)
/**
* @brief The requested height increment for the surface
* Zero if not set
*/
Q_PROPERTY(int heightIncrement READ heightIncrement NOTIFY heightIncrementChanged)
/**
* @brief The Shell chrome mode
*/
Q_PROPERTY(Mir::ShellChrome shellChrome READ shellChrome NOTIFY shellChromeChanged)
/**
* @brief The requested keymap for this surface
* Its format is "layout+variant".
*/
Q_PROPERTY(QString keymap READ keymap WRITE setKeymap NOTIFY keymapChanged)
/**
* @brief Whether the surface is focused
*
* It will be true if this surface is MirFocusControllerInterface::focusedSurface
*/
Q_PROPERTY(bool focused READ focused NOTIFY focusedChanged)
/**
* @brief Input bounds
*
* Bounding rectangle of the surface region that accepts input.
*/
Q_PROPERTY(QRect inputBounds READ inputBounds NOTIFY inputBoundsChanged)
/**
* @brief Whether the surface wants to confine the mouse pointer within its boundaries
*
* If true, the surface doesn't want the mouse pointer to leave its boundaries while it's focused.
*/
Q_PROPERTY(bool confinesMousePointer READ confinesMousePointer NOTIFY confinesMousePointerChanged)
/**
* @brief Whether to comply to resize requests coming from the client side
*
* It's true by default
*/
Q_PROPERTY(bool allowClientResize READ allowClientResize WRITE setAllowClientResize NOTIFY allowClientResizeChanged)
/**
* @brief The parent MirSurface or null if this is a top-level surface
*/
Q_PROPERTY(MirSurfaceInterface* parentSurface READ parentSurface CONSTANT)
/**
* @brief The list of child surfaces
*
* Ordered from top-most (index=0) to bottom (index=count-1)
* So the Z value for an item in this model would be z: count - index
*/
Q_PROPERTY(unity::shell::application::MirSurfaceListInterface* childSurfaceList READ childSurfaceList CONSTANT)
public:
/// @cond
MirSurfaceInterface(QObject *parent = nullptr) : QObject(parent) {}
virtual ~MirSurfaceInterface() {}
virtual Mir::Type type() const = 0;
virtual QString name() const = 0;
virtual QString persistentId() const = 0;
virtual QString appId() const = 0;
virtual QPoint position() const = 0;
virtual QSize size() const = 0;
virtual void resize(int width, int height) = 0;
virtual void resize(const QSize &size) = 0;
virtual Mir::State state() const = 0;
virtual bool live() const = 0;
virtual bool visible() const = 0;
virtual Mir::OrientationAngle orientationAngle() const = 0;
virtual void setOrientationAngle(Mir::OrientationAngle angle) = 0;
virtual int minimumWidth() const = 0;
virtual int minimumHeight() const = 0;
virtual int maximumWidth() const = 0;
virtual int maximumHeight() const = 0;
virtual int widthIncrement() const = 0;
virtual int heightIncrement() const = 0;
virtual void setKeymap(const QString &) = 0;
virtual QString keymap() const = 0;
virtual Mir::ShellChrome shellChrome() const = 0;
virtual bool focused() const = 0;
virtual QRect inputBounds() const = 0;
virtual bool confinesMousePointer() const = 0;
virtual bool allowClientResize() const = 0;
virtual void setAllowClientResize(bool) = 0;
virtual QPoint requestedPosition() const = 0;
virtual void setRequestedPosition(const QPoint &) = 0;
virtual MirSurfaceInterface* parentSurface() const = 0;
virtual unity::shell::application::MirSurfaceListInterface* childSurfaceList() const = 0;
/// @endcond
/**
* @brief Sends a close request
*
*/
Q_INVOKABLE virtual void close() = 0;
/**
* @brief Activates this surface
*
* It will get focused and raised
*/
Q_INVOKABLE virtual void activate() = 0;
public Q_SLOTS:
/**
* @brief Requests a change to the specified state
*/
virtual void requestState(Mir::State state) = 0;
Q_SIGNALS:
/// @cond
void typeChanged(Mir::Type value);
void liveChanged(bool value);
void visibleChanged(bool visible);
void stateChanged(Mir::State value);
void orientationAngleChanged(Mir::OrientationAngle value);
void positionChanged(QPoint position);
void requestedPositionChanged(QPoint position);
void sizeChanged(const QSize &value);
void nameChanged(const QString &name);
void minimumWidthChanged(int value);
void minimumHeightChanged(int value);
void maximumWidthChanged(int value);
void maximumHeightChanged(int value);
void widthIncrementChanged(int value);
void heightIncrementChanged(int value);
void shellChromeChanged(Mir::ShellChrome value);
void keymapChanged(const QString &value);
void focusedChanged(bool value);
void inputBoundsChanged(QRect value);
void confinesMousePointerChanged(bool value);
void allowClientResizeChanged(bool value);
/// @endcond
/**
* @brief Emitted in response to a requestFocus() call
*
* If shell agrees with it, it should call activate() on this surface
*/
void focusRequested();
/**
* @brief Emitted when close() is called
*/
void closeRequested();
};
} // namespace application
} // namespace shell
} // namespace unity
Q_DECLARE_METATYPE(unity::shell::application::MirSurfaceInterface*)
#endif // UNITY_SHELL_APPLICATION_MIRSURFACE_H
./include/unity/shell/application/MirPlatformCursor.h 0000644 0000041 0000041 00000002136 13070664454 023266 0 ustar www-data www-data /*
* Copyright (C) 2015 Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MIR_PLATFORM_CURSOR_H
#define MIR_PLATFORM_CURSOR_H
#include
class MirMousePointerInterface;
/**
* @brief Cursor interface for Mir platform
*
* FIXME: Get this out of unity-api
*/
class MirPlatformCursor : public QPlatformCursor
{
public:
/**
* @brief Set the QML mouse pointer that this platform cursor will talk to
*/
virtual void setMousePointer(MirMousePointerInterface *mousePointer) = 0;
};
#endif // MIR_PLATFORM_CURSOR_H
./include/unity/shell/application/SurfaceManagerInterface.h 0000644 0000041 0000041 00000002734 13070664454 024344 0 ustar www-data www-data /*
* Copyright (C) 2016 Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef UNITY_SHELL_APPLICATION_SURFACEMANAGERINTERFACE_H
#define UNITY_SHELL_APPLICATION_SURFACEMANAGERINTERFACE_H
#include
#include
namespace unity {
namespace shell {
namespace application {
class MirSurfaceInterface;
class SurfaceManagerInterface : public QObject
{
Q_OBJECT
public:
virtual ~SurfaceManagerInterface() {}
virtual void raise(MirSurfaceInterface *surface) = 0;
virtual void activate(MirSurfaceInterface *surface) = 0;
Q_SIGNALS:
void surfaceCreated(unity::shell::application::MirSurfaceInterface *surface);
void surfacesRaised(const QVector &surfaces);
void modificationsStarted();
void modificationsEnded();
};
} // namespace application
} // namespace shell
} // namespace unity
#endif // UNITY_SHELL_APPLICATION_SURFACEMANAGERINTERFACE_H
./include/unity/shell/application/ApplicationInfoInterface.h 0000644 0000041 0000041 00000026376 13070664454 024550 0 ustar www-data www-data /*
* Copyright 2013,2015,2016 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#ifndef UNITY_SHELL_APPLICATION_APPLICATIONINFOINTERFACE_H
#define UNITY_SHELL_APPLICATION_APPLICATIONINFOINTERFACE_H
#include
#include
#include
#include
#include
namespace unity
{
namespace shell
{
namespace application
{
class MirSurfaceListInterface;
/**
* @brief A class that holds information about applications
*
* The items hold all the information required for the visual representation
* in the launcher.
*/
class UNITY_API ApplicationInfoInterface: public QObject
{
Q_OBJECT
/**
* @brief The appId of the application.
*
* Holds the appId for the application. For example (com.ubuntu.camera-app).
* The appId is derived from the filename of the .desktop file.
*/
Q_PROPERTY(QString appId READ appId CONSTANT)
/**
* @brief The name of the application.
*
* Holds the name of the application. Localized to current language.
*/
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
/**
* @brief The comment for the application.
*
* Holds the comment of the application as obtained from the .desktop file. Localized
* to current language.
*/
Q_PROPERTY(QString comment READ comment NOTIFY commentChanged)
/**
* @brief The application's icon.
*
* Holds a path to the icon for the application. Can be a file or a gicon url.
*/
Q_PROPERTY(QUrl icon READ icon NOTIFY iconChanged)
/**
* @brief The application's state.
*
* Holds the current application state.
*/
Q_PROPERTY(State state READ state NOTIFY stateChanged)
/**
* @brief The application's requested running state
*/
Q_PROPERTY(RequestedState requestedState READ requestedState WRITE setRequestedState NOTIFY requestedStateChanged)
/**
* @brief The application's focus state.
*
* Holds the current application focus state. True if focused, false otherwise.
*/
Q_PROPERTY(bool focused READ focused NOTIFY focusedChanged)
/**
* @brief Splash screen title
*
* @see splashShowHeader
* Title of the splash screen, to be displayed on its header.
*
* A splash screen is shown while the application is loading,
* before it has drawn its first frame.
*/
Q_PROPERTY(QString splashTitle READ splashTitle CONSTANT)
/**
* @brief Splash image
*
* Url of the splash image to be shown while the application is loading,
* before it has drawn its first frame.
*
* The splash image is centered on the splash screen and displayed in
* its actual size (ie, it's not stretched or shrinked and aspect ratio
* is kept).
*/
Q_PROPERTY(QUrl splashImage READ splashImage CONSTANT)
/**
* @brief Whether an application header should be shown on the splash screen
*
* We offer 2 kinds of splash screens for applications:
* 1. A splash with a gradient background and image
* 2. A splash faking a MainView with header text set. So it is possible to
* arrange things so that once the app starts up, this splash and the app's
* first frame are identical.
*
* This property is the switch to select between these.
*
* The header will display the splashTitle, if defined, or the application
* name otherwise.
*
* @see name, splashTitle
*/
Q_PROPERTY(bool splashShowHeader READ splashShowHeader CONSTANT)
/**
* @brief Background color of the splash screen
*
* Any color that is not fully opaque (having an alpha value of less than
* 1.0) is ignored and the default background color will be used instead.
*
* A splash screen is shown while the application is loading,
* before it has drawn its first frame.
*/
Q_PROPERTY(QColor splashColor READ splashColor CONSTANT)
/**
* @brief Color of the splash screen header
*
* Any color that is not fully opaque (having an alpha value of less than
* 1.0) is ignored and the splashColor will be used instead.
*
* A splash screen is shown while the application is loading,
* before it has drawn its first frame.
*
* @see splashColor
*/
Q_PROPERTY(QColor splashColorHeader READ splashColorHeader CONSTANT)
/**
* @brief Color of the splash screen footer
*
* Any color that is not fully opaque (having an alpha value of less than
* 1.0) is ignored and the splashColor will be used instead.
*
* A splash screen is shown while the application is loading,
* before it has drawn its first frame.
*
* @see splashColor
*/
Q_PROPERTY(QColor splashColorFooter READ splashColorFooter CONSTANT)
/**
* @brief The orientations supported by the application UI
* @see rotatesContents
*/
Q_PROPERTY(Qt::ScreenOrientations supportedOrientations READ supportedOrientations CONSTANT)
/**
* @brief Whether the application UI will rotate itself to match the screen orientation
*
* Returns true if the application will rotate the UI in its windows to match the screen
* orientation.
*
* If false, it means that the application never rotates its UI, so it will
* rely on the window manager to appropriately rotate his windows to match the screen
* orientation instead.
*
* @see supportedOrientations
*/
Q_PROPERTY(bool rotatesWindowContents READ rotatesWindowContents CONSTANT)
/**
* @brief Whether the application is an app targeting the Ubuntu Touch platform.
*/
Q_PROPERTY(bool isTouchApp READ isTouchApp CONSTANT)
/**
* @brief Whether this app is exempt from lifecycle management
*
* If true, this app will never entirely suspend its process.
*/
Q_PROPERTY(bool exemptFromLifecycle READ exemptFromLifecycle WRITE setExemptFromLifecycle NOTIFY exemptFromLifecycleChanged)
/**
* @brief The size to be given for new surfaces created by this application
*/
Q_PROPERTY(QSize initialSurfaceSize READ initialSurfaceSize WRITE setInitialSurfaceSize NOTIFY initialSurfaceSizeChanged)
/**
* @brief List of the top-level surfaces created by this application
*/
Q_PROPERTY(unity::shell::application::MirSurfaceListInterface* surfaceList READ surfaceList CONSTANT)
/**
* @brief The list of top-level prompt surfaces for this application
*/
Q_PROPERTY(unity::shell::application::MirSurfaceListInterface* promptSurfaceList READ promptSurfaceList CONSTANT)
/**
* @brief Count of application's surfaces
*
* This is a convenience property and will always be the same as surfaceList->count().
* It allows to connect to an application and listen for surface creations/removals for
* that particular application without having to keep track of the
* application <-> surfaceList relationship.
*/
Q_PROPERTY(int surfaceCount READ surfaceCount NOTIFY surfaceCountChanged)
protected:
/// @cond
ApplicationInfoInterface(const QString &appId, QObject* parent = 0): QObject(parent) { Q_UNUSED(appId) }
/// @endcond
public:
/**
* @brief A enum that defines a stage.
*
* MainStage: The main stage, which is the normal place for applications in
* traditional desktop environments.
* SideStage: The side stage, a panel on the right to place phone form factor
* applications.
*/
enum Stage {
MainStage,
SideStage
};
Q_ENUM(Stage)
/**
* @brief An application's state.
*
* Starting: The application was launched and is currently starting up.
* Running: The application is running and ready to be used.
* Suspended: The application is in the background and has been suspended by
* the system in order to save resources.
* Stopped: The application is in the background and has been stopped by
* the system in order to save resources. From a programmers point of view,
* the application is closed, but it's state has been stored to disk and
* can be restored upon next launch.
*/
enum State {
Starting,
Running,
Suspended,
Stopped
};
Q_ENUM(State)
/**
* @brief The desired state of an application
*
* RequestedRunning: If state is Suspended or Stopped, the application will be resumed
* or restarted, respectively.
* RequestedSuspended: If state is Running, the application will be suspended.
*/
enum RequestedState {
RequestedRunning = Running,
RequestedSuspended = Suspended
};
Q_ENUM(RequestedState)
/**
* @brief Closes the application
*/
virtual void close() = 0;
/// @cond
virtual ~ApplicationInfoInterface() {}
virtual QString appId() const = 0;
virtual QString name() const = 0;
virtual QString comment() const = 0;
virtual QUrl icon() const = 0;
virtual State state() const = 0;
virtual RequestedState requestedState() const = 0;
virtual void setRequestedState(RequestedState) = 0;
virtual bool focused() const = 0;
virtual QString splashTitle() const = 0;
virtual QUrl splashImage() const = 0;
virtual bool splashShowHeader() const = 0;
virtual QColor splashColor() const = 0;
virtual QColor splashColorHeader() const = 0;
virtual QColor splashColorFooter() const = 0;
virtual Qt::ScreenOrientations supportedOrientations() const = 0;
virtual bool rotatesWindowContents() const = 0;
virtual bool isTouchApp() const = 0;
virtual bool exemptFromLifecycle() const = 0;
virtual void setExemptFromLifecycle(bool) = 0;
virtual QSize initialSurfaceSize() const = 0;
virtual void setInitialSurfaceSize(const QSize &size) = 0;
virtual MirSurfaceListInterface* surfaceList() const = 0;
virtual MirSurfaceListInterface* promptSurfaceList() const = 0;
virtual int surfaceCount() const = 0;
/// @endcond
Q_SIGNALS:
/// @cond
void nameChanged(const QString &name);
void commentChanged(const QString &comment);
void iconChanged(const QUrl &icon);
void stateChanged(State state);
void requestedStateChanged(RequestedState value);
void focusedChanged(bool focused);
void exemptFromLifecycleChanged(bool exemptFromLifecycle);
void initialSurfaceSizeChanged(const QSize &size);
void surfaceCountChanged(int surfaceCount);
/// @endcond
/**
* @brief The application is requesting focus
*/
void focusRequested();
};
} // namespace application
} // namespace shell
} // namespace unity
Q_DECLARE_METATYPE(unity::shell::application::ApplicationInfoInterface*)
#endif // UNITY_SHELL_APPLICATIONMANAGER_APPLICATIONINFOINTERFACE_H
./include/unity/shell/application/MirSurfaceItemInterface.h 0000644 0000041 0000041 00000012673 13070664454 024343 0 ustar www-data www-data /*
* Copyright (C) 2015 Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef UNITY_SHELL_APPLICATION_MIRSURFACEITEM_H
#define UNITY_SHELL_APPLICATION_MIRSURFACEITEM_H
#include "Mir.h"
#include
namespace unity
{
namespace shell
{
namespace application
{
class MirSurfaceInterface;
/**
@brief Renders a MirSurface in a QML scene and forwards the input events it receives to it.
You can have multiple MirSurfaceItems displaying the same MirSurface. But care must
be taken that only one of them feeds the MirSurface with input events and also only
one resizes it.
*/
class MirSurfaceItemInterface : public QQuickItem
{
Q_OBJECT
/**
* @brief The surface to be displayed
*/
Q_PROPERTY(unity::shell::application::MirSurfaceInterface* surface READ surface WRITE setSurface NOTIFY surfaceChanged)
/**
* @brief Type of the given surface or Mir.UnknownType if no surface is set
*/
Q_PROPERTY(Mir::Type type READ type NOTIFY typeChanged)
/**
* @brief State of the given surface or Mir.UnknownState if no surface is set
*/
Q_PROPERTY(Mir::State surfaceState READ surfaceState NOTIFY surfaceStateChanged)
/**
* @brief Name of the given surface or an empty string if no surface is set
*/
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
/**
* @brief True if the item has a surface and that surface has a mir client bound to it.
* A "zombie" (live == false) surface never becomes alive again.
*/
Q_PROPERTY(bool live READ live NOTIFY liveChanged)
/**
* @brief Orientation angle of the given surface
*
* How many degrees, clockwise, the UI in the surface has to rotate to match shell's UI orientation
*/
Q_PROPERTY(Mir::OrientationAngle orientationAngle READ orientationAngle WRITE setOrientationAngle
NOTIFY orientationAngleChanged DESIGNABLE false)
/**
* @brief Whether the item will forward activeFocus, touch events, mouse events and key events to its surface.
* It's false by default.
* Only one item should have this property enabled for a given surface.
*/
Q_PROPERTY(bool consumesInput READ consumesInput
WRITE setConsumesInput
NOTIFY consumesInputChanged)
/**
* @brief The desired width for the contained MirSurface.
* It's ignored if set to zero or a negative number
* The default value is zero
*/
Q_PROPERTY(int surfaceWidth READ surfaceWidth
WRITE setSurfaceWidth
NOTIFY surfaceWidthChanged)
/**
* @brief The desired height for the contained MirSurface.
* It's ignored if set to zero or a negative number
* The default value is zero
*/
Q_PROPERTY(int surfaceHeight READ surfaceHeight
WRITE setSurfaceHeight
NOTIFY surfaceHeightChanged)
Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
/**
* @brief The Shell chrome mode
*/
Q_PROPERTY(Mir::ShellChrome shellChrome READ shellChrome NOTIFY shellChromeChanged)
public:
enum FillMode {
Stretch,
PadOrCrop
};
Q_ENUM(FillMode)
/// @cond
MirSurfaceItemInterface(QQuickItem *parent = 0) : QQuickItem(parent) {}
virtual ~MirSurfaceItemInterface() {}
virtual Mir::Type type() const = 0;
virtual QString name() const = 0;
virtual bool live() const = 0;
virtual Mir::State surfaceState() const = 0;
virtual Mir::OrientationAngle orientationAngle() const = 0;
virtual void setOrientationAngle(Mir::OrientationAngle angle) = 0;
virtual MirSurfaceInterface* surface() const = 0;
virtual void setSurface(MirSurfaceInterface*) = 0;
virtual bool consumesInput() const = 0;
virtual void setConsumesInput(bool value) = 0;
virtual int surfaceWidth() const = 0;
virtual void setSurfaceWidth(int value) = 0;
virtual int surfaceHeight() const = 0;
virtual void setSurfaceHeight(int value) = 0;
virtual FillMode fillMode() const = 0;
virtual void setFillMode(FillMode value) = 0;
virtual Mir::ShellChrome shellChrome() const = 0;
/// @endcond
Q_SIGNALS:
/// @cond
void typeChanged(Mir::Type);
void surfaceStateChanged(Mir::State);
void liveChanged(bool live);
void orientationAngleChanged(Mir::OrientationAngle angle);
void surfaceChanged(unity::shell::application::MirSurfaceInterface* surface);
void consumesInputChanged(bool value);
void surfaceWidthChanged(int value);
void surfaceHeightChanged(int value);
void nameChanged(const QString &name);
void fillModeChanged(FillMode value);
void shellChromeChanged(Mir::ShellChrome value);
/// @endcond
};
} // namespace application
} // namespace shell
} // namespace unity
#endif // UNITY_SHELL_APPLICATION_MIRSURFACEITEM_H
./include/unity/shell/application/MirSurfaceListInterface.h 0000644 0000041 0000041 00000005377 13070664454 024363 0 ustar www-data www-data /*
* Copyright (C) 2016 Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef UNITY_SHELL_APPLICATION_MIRSURFACELISTINTERFACE_H
#define UNITY_SHELL_APPLICATION_MIRSURFACELISTINTERFACE_H
#include
namespace unity {
namespace shell {
namespace application {
class MirSurfaceInterface;
/**
* @brief Interface for a list model of MirSurfaces
*/
class MirSurfaceListInterface : public QAbstractListModel
{
Q_OBJECT
/**
* @brief Number of surfaces in this model
*
* This is the same as rowCount, added in order to keep compatibility with QML ListModels.
*/
Q_PROPERTY(int count READ count NOTIFY countChanged)
/**
* @brief The first (index 0) surface in this model
*
* Will always match the result of get(0). But being a property, it's more appropriate
* for use in qml bindinds (JS expression gets reevaluated when it changes)
*/
Q_PROPERTY(unity::shell::application::MirSurfaceInterface* first READ first NOTIFY firstChanged)
public:
/**
* @brief The Roles supported by the model
*
* SurfaceRole - A MirSurfaceInterface.
*/
enum Roles {
SurfaceRole = Qt::UserRole,
};
/// @cond
MirSurfaceListInterface(QObject *parent = 0) : QAbstractListModel(parent) {}
virtual ~MirSurfaceListInterface() {}
/// @endcond
/**
* @brief Returns the surface at the specified index
*
*/
Q_INVOKABLE virtual MirSurfaceInterface *get(int index) = 0;
/// @cond
// QAbstractItemModel methods
QHash roleNames() const override {
QHash roleNames;
roleNames.insert(SurfaceRole, "surface");
return roleNames;
}
int count() const { return rowCount(); }
MirSurfaceInterface *first() {
if (rowCount() > 0) {
return get(0);
} else {
return nullptr;
}
}
/// @endcond
Q_SIGNALS:
/// @cond
void countChanged(int count);
void firstChanged();
/// @endcond
};
} // namespace application
} // namespace shell
} // namespace unity
Q_DECLARE_METATYPE(unity::shell::application::MirSurfaceListInterface*)
#endif // UNITY_SHELL_APPLICATION_MIRSURFACELISTINTERFACE_H
./include/unity/shell/application/Mir.h 0000644 0000041 0000041 00000006504 13070664454 020366 0 ustar www-data www-data /*
* Copyright (C) 2015-2016 Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see