1 /*=============================================================================
2 
3   Library: CTK
4 
5   Copyright (c) German Cancer Research Center,
6     Division of Medical and Biological Informatics
7 
8   Licensed under the Apache License, Version 2.0 (the "License");
9   you may not use this file except in compliance with the License.
10   You may obtain a copy of the License at
11 
12     http://www.apache.org/licenses/LICENSE-2.0
13 
14   Unless required by applicable law or agreed to in writing, software
15   distributed under the License is distributed on an "AS IS" BASIS,
16   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   See the License for the specific language governing permissions and
18   limitations under the License.
19 
20 =============================================================================*/
21 
22 
23 #include "ctkTestPluginS_p.h"
24 
25 #include <ctkPluginContext.h>
26 
27 #include <QStringList>
28 
29 const QString ctkTestPluginS::SERVICE = "org.commontk.pluginStest.TestPluginSService";
30 
31 //----------------------------------------------------------------------------
ctkTestPluginS(ctkPluginContext * pc)32 ctkTestPluginS::ctkTestPluginS(ctkPluginContext* pc)
33   : pc(pc)
34 {
35   for(int i = 0; i <= 3; ++i)
36   {
37     servregs.push_back(ctkServiceRegistration());
38   }
39   sreg = pc->registerService<ctkTestPluginSService0>(this);
40 }
41 
42 //----------------------------------------------------------------------------
controlService(int offset,const QString & operation,long ranking)43 void ctkTestPluginS::controlService(int offset, const QString& operation, long ranking)
44 {
45   if (0 <= offset && offset <= 3)
46   {
47     if (operation == "register")
48     {
49       if (!servregs[offset])
50       {
51         QString servicename = SERVICE + QString::number(offset);
52         ctkProperties props;
53         props.insert(ctkPluginConstants::SERVICE_RANKING, QVariant::fromValue(ranking));
54         servregs[offset] = pc->registerService(QStringList(servicename), this, props);
55       }
56     }
57     if (operation == "unregister")
58     {
59       if (servregs[offset])
60       {
61         ctkServiceRegistration sr1 = servregs[offset];
62         sr1.unregister();
63         servregs[offset] = 0;
64       }
65     }
66   }
67 }
68