From 95e1c55437699aee29235e5ba2c919adbf51145e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 3 Sep 2014 06:44:56 +0200 Subject: libgamma_group_gid and libgamma_group_name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libgamma-error.hh | 72 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/test.cc | 16 ++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/libgamma-error.hh b/src/libgamma-error.hh index a30b2c7..5fe1cbc 100644 --- a/src/libgamma-error.hh +++ b/src/libgamma-error.hh @@ -24,8 +24,28 @@ #include "libgamma-native.hh" + +#ifndef __WIN32__ +# define libgamma_gid_t gid_t +#else +# define libgamma_gid_t short +#endif + + + namespace libgamma { + /** + * Class for `group_gid`. + */ + class GroupGid; + + /** + * Class for `group_name`. + */ + class GroupName; + + /** * Prints an error to stderr in a `perror` fashion, * however this function will not translate the `libgamma` @@ -64,8 +84,56 @@ namespace libgamma int value_of_error(const std::string* name); - /* TODO libgamma_group_gid */ - /* TODO libgamma_group_name */ + /** + * Class for `group_gid`. + */ + class GroupGid + { + public: + const GroupGid& operator =(const libgamma_gid_t& value) const + { + libgamma_group_gid = value; + return *this; + } + + operator libgamma_gid_t() const + { + return libgamma_group_gid; + } + }; + + /** + * Group that the user needs to be a member of if + * `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. + */ + extern GroupGid group_gid; + + + /** + * Class for `group_name`. + */ + class GroupName + { + public: + const GroupName& operator =(const char* value) const + { + libgamma_group_name = value; + return *this; + } + + operator char*() const + { + return (char*)libgamma_group_name; + } + }; + + /** + * Group that the user needs to be a member of if + * `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, + * `nullptr` if the name of the group + * `libgamma::group_gid` cannot be determined. + */ + extern GroupName group_name; } diff --git a/src/test.cc b/src/test.cc index fabaa00..c802c71 100644 --- a/src/test.cc +++ b/src/test.cc @@ -155,6 +155,22 @@ int main(void) std::cout << "fake: " << caps.fake << std::endl; std::cout << std::endl; + std::cout << libgamma::group_gid << std::endl; + libgamma::group_gid = 10; + std::cout << libgamma::group_gid << std::endl; + std::cout << std::endl; + + if (libgamma::group_name == nullptr) + std::cout << "(nullptr)" << std::endl; + else + std::cout << libgamma::group_name << std::endl; + libgamma::group_name = "test-group"; + if (libgamma::group_name == nullptr) + std::cout << "(nullptr)" << std::endl; + else + std::cout << libgamma::group_name << std::endl; + std::cout << std::endl; + delete crtc; delete partition; delete site; -- cgit v1.2.3-70-g09d2