BUG#: 7626
[tpot/pegasus/.git] / src / Providers / TestProviders / DeliveryRetryTestProvider / DeliveryRetryTestProvider.cpp
1 //%LICENSE////////////////////////////////////////////////////////////////
2 //
3 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //////////////////////////////////////////////////////////////////////////
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include "DeliveryRetryTestProvider.h"
33
34 PEGASUS_NAMESPACE_BEGIN
35
36 extern "C" PEGASUS_EXPORT CIMProvider* PegasusCreateProvider(
37     const String& providerName)
38 {
39     if(String::equalNoCase(providerName, "DeliveryRetryTestProvider"))
40     {
41         return(new DeliveryRetryTestProvider());
42     }
43     return(0);
44 }
45
46 void DeliveryRetryTestProvider::_sendIndication()
47 {
48     CIMInstance indicationInstance(CIMName("DeliveryRetryTestClass"));
49
50     indicationInstance.setPath(_path);
51
52     CIMDateTime currentDateTime = CIMDateTime::getCurrentDateTime();
53
54     indicationInstance.addProperty(
55         CIMProperty("IndicationTime", currentDateTime));
56
57     indicationInstance.addProperty(
58         CIMProperty("sequenceId", CIMValue(Uint64(_nextIdentifier++))));
59
60     _handler->deliver(indicationInstance);
61 }
62
63 DeliveryRetryTestProvider::DeliveryRetryTestProvider()
64 {
65     _nextIdentifier = 1;
66     _enabled = false;
67     _path.setNameSpace("test/TestProvider");
68     _path.setClassName("DeliveryRetryTestClass");
69 }
70
71 DeliveryRetryTestProvider::~DeliveryRetryTestProvider()
72 {
73 }
74
75 void DeliveryRetryTestProvider::initialize(CIMOMHandle& cimom)
76 {
77     _cimom = cimom;
78 }
79
80 void DeliveryRetryTestProvider::terminate()
81 {
82     delete this;
83 }
84
85 void DeliveryRetryTestProvider::invokeMethod(
86     const OperationContext& context,
87     const CIMObjectPath& objectReference,
88     const CIMName& methodName,
89     const Array<CIMParamValue>& inParameters,
90     MethodResultResponseHandler& handler)
91 {
92     Uint32 count = 0;
93
94     handler.processing();
95
96     if (!objectReference.getClassName().equal("DeliveryRetryTestClass"))
97     {
98         throw CIMNotSupportedException(
99             objectReference.getClassName().getString());
100     }
101
102     if (methodName.equal("resetIdentifier"))
103     {
104         _nextIdentifier = 1;
105     }
106     else if (methodName.equal("generateIndications"))
107     {
108         inParameters[0].getValue().get(count);
109
110         if (!_enabled)
111         {
112             handler.deliver(CIMValue(0));
113         }
114         else
115         {
116             for (Uint32 i = 0; i < count; ++i)
117             {
118                 _sendIndication();
119             }
120             handler.deliver(CIMValue(1));
121         }
122     }
123     else
124     {
125         handler.deliver(CIMValue(0));
126     }
127     handler.complete();
128 }
129
130 void DeliveryRetryTestProvider::enableIndications (
131     IndicationResponseHandler & handler)
132 {
133     _enabled = true;
134     _handler = &handler;
135 }
136
137 void DeliveryRetryTestProvider::disableIndications ()
138 {
139     _enabled = false;
140 }
141
142 void DeliveryRetryTestProvider::createSubscription (
143     const OperationContext & context,
144     const CIMObjectPath & subscriptionName,
145     const Array <CIMObjectPath> & classNames,
146     const CIMPropertyList & propertyList,
147     const Uint16 repeatNotificationPolicy)
148 {
149 }
150
151 void DeliveryRetryTestProvider::modifySubscription (
152     const OperationContext & context,
153     const CIMObjectPath & subscriptionName,
154     const Array <CIMObjectPath> & classNames,
155     const CIMPropertyList & propertyList,
156     const Uint16 repeatNotificationPolicy)
157 {
158 }
159
160
161 void DeliveryRetryTestProvider::deleteSubscription (
162     const OperationContext & context,
163     const CIMObjectPath & subscriptionName,
164     const Array <CIMObjectPath> & classNames)
165 {
166 }
167
168 PEGASUS_NAMESPACE_END