File indexing completed on 2024-04-21 04:20:22

0001 /********************************************************************
0002  KolorServer - color server based on the X Color Management Specification
0003  This file is part of the KDE project.
0004 
0005 Copyright (C) 2012 Casian Andrei <skeletk13@gmail.com>
0006 
0007 Redistribution and use in source and binary forms, with or without
0008 modification, are permitted provided that the following conditions
0009 are met:
0010 
0011 1. Redistributions of source code must retain the above copyright
0012    notice, this list of conditions and the following disclaimer.
0013 2. Redistributions in binary form must reproduce the above copyright
0014    notice, this list of conditions and the following disclaimer in the
0015    documentation and/or other materials provided with the distribution.
0016 
0017 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0018 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0019 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0020 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0021 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0022 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0024 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0025 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0026 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0027 *********************************************************************/
0028 
0029 #include <KPluginFactory>
0030 #include <KPluginLoader>
0031 #include <KDebug>
0032 
0033 #include "kolor-server.h"
0034 
0035 #include "color-lookup-table.h"
0036 #include "screen.h"
0037 
0038 #include "display.h"
0039 
0040 #include <stdio.h>
0041 #include <string.h>
0042 #include <stdarg.h>
0043 
0044 #include <oyranos_core.h>
0045 #include <oyStruct_s.h>
0046 
0047 K_PLUGIN_FACTORY(KolorServerFactory, registerPlugin<KolorServer::Server>();)
0048 K_EXPORT_PLUGIN(KolorServerFactory("kolorserver"))
0049 
0050 /* allow debug output from Oyranos */
0051 extern "C" {
0052 int ksOyMessage ( int/*oyMSG_e*/      code,
0053                                        const oyPointer     context_object,
0054                                        const char        * format,
0055                                        ... )
0056 {
0057   char * text = 0, * msg = 0;
0058   int error = 0;
0059   va_list list;
0060   size_t sz = 0;
0061   int len = 0,
0062       l;
0063   oyStruct_s * c = (oyStruct_s*) context_object;
0064 
0065   va_start( list, format);
0066   len = vsnprintf( text, sz, format, list);
0067   va_end  ( list );
0068 
0069   {
0070     text = (char*) calloc( sizeof(char), len + 1 );
0071     va_start( list, format);
0072     l = vsnprintf( text, len+1, format, list);
0073     if(l != len)
0074       fprintf(stderr, "vsnprintf lengths differ: %d %d\n", l,len );
0075     va_end  ( list );
0076   }
0077 
0078   error = oyMessageFormat( &msg, code, c, text );
0079 
0080   if(msg)
0081   {
0082     if(code == oyMSG_ERROR)
0083       kError() << msg;
0084     else
0085     if(code == oyMSG_WARN)
0086       kWarning() << msg;
0087     else
0088       kDebug() << msg;
0089   }
0090 
0091   free( text ); text = 0;
0092   if(msg) free( msg ); msg = 0;
0093 
0094   return error;
0095 }
0096 }
0097 
0098 namespace KolorServer
0099 {
0100 
0101 /*
0102  * Server
0103  */
0104 
0105 Server::Server(QObject *parent, const QList<QVariant> &)
0106     : KDEDModule(parent)
0107 {
0108     oyMessageFuncSet( ksOyMessage );
0109 
0110     qDBusRegisterMetaType< Clut >();
0111     qDBusRegisterMetaType< ClutList >();
0112     qDBusRegisterMetaType< RegionalClut >();
0113     qDBusRegisterMetaType< RegionalClutMap >();
0114 
0115     Display::getInstance();
0116 
0117     new ServerDBusAdaptor(this);
0118 }
0119 
0120 Server::~Server()
0121 {
0122     Display::cleanup();
0123     kDebug() << "going to leave";
0124 }
0125 
0126 
0127 /*
0128  * Server D-Bus Adaptor
0129  */
0130 
0131 ServerDBusAdaptor::ServerDBusAdaptor(Server *server)
0132     : QDBusAbstractAdaptor(server)
0133     , m_server(server)
0134 {
0135     Display *d = Display::getInstance();
0136     connect(d->screen(), SIGNAL(outputClutsChanged()), this, SIGNAL(outputClutsChanged()));
0137 }
0138 
0139 void ServerDBusAdaptor::getVersionInfo(const QDBusMessage &message)
0140 {
0141     //message.setDelayedReply(true);
0142     QDBusMessage reply = message.createReply(QVariant((uint) 0x00000001));
0143     QDBusConnection::sessionBus().send(reply);
0144 }
0145 
0146 void ServerDBusAdaptor::getOutputCluts(const QDBusMessage &message)
0147 {
0148     QDBusMessage reply = message.createReply(
0149         QVariant::fromValue< ClutList >(Display::getInstance()->screen()->outputCluts()));
0150     QDBusConnection::sessionBus().send(reply);
0151 }
0152 
0153 void ServerDBusAdaptor::getRegionCluts(const QDBusMessage &message)
0154 {
0155     QDBusMessage reply = message.createReply(
0156         QVariant::fromValue< RegionalClutMap >(Display::getInstance()->screen()->regionCluts()));
0157     QDBusConnection::sessionBus().send(reply);
0158 }
0159 
0160 } // KolorServer namespace
0161 
0162 #include "moc_kolor-server.cpp"