summaryrefslogtreecommitdiff
path: root/print/XPSDrvSmpl/src/ui/xdsmplptprov.cpp
blob: 5e0f521f1864d65018af23e3ca3cb8a4d6bc035a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
/*++

Copyright (c) 2005 Microsoft Corporation

All rights reserved.

THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

File Name:

   xdsmplptprov.cpp

Abstract:

   Implementation of the PrintTicket provider plugin. This is responsible for
   handling PrintTicket features that are too complex for the GPD->PrintTicket
   automapping facility.

--*/

#include "precomp.h"
#include "debug.h"
#include "globals.h"
#include "xdexcept.h"
#include "xdstring.h"
#include "xdsmplptprov.h"
#include "wmdmptcnv.h"
#include "pgscdmptcnv.h"
#include "bkdmptcnv.h"
#include "nupptcnv.h"
#include "coldmptcnv.h"
#include "pthndlr.h"
#include "pchndlr.h"

static LPCWSTR PRIVATE_URI = L"http://schemas.microsoft.com/windows/2003/08/printing/XPSDrv_Feature_Sample";


/*++

Routine Name:

    CXDSmplPTProvider::CXDSmplPTProvider

Routine Description:

    CXDSmplPTProvider class constructor

Arguments:

    None

Return Value:

    None
    Throws CXDException(HRESULT) on an error

--*/
CXDSmplPTProvider::CXDSmplPTProvider() :
    CUnknown<IPrintOemPrintTicketProvider>(IID_IPrintOemPrintTicketProvider),
    m_hPrinterCached(NULL),
    m_pCoreHelper(NULL),
    m_bstrPrivateNS(PRIVATE_URI)
{
    HRESULT hr = S_OK;
    IFeatureDMPTConvert* pHandler = NULL;

//
// This Prefast warning indicates that memory could be leaked
// in the event of an exception. We suppress this false positive because we
// know that the local try/catch block will clean up a single
// IFeatureDMPTConvert, and the destructor will clean up any that are
// successfully added to the vector.
//
#pragma prefast(push)
#pragma prefast(disable:__WARNING_ALIASED_MEMORY_LEAK_EXCEPTION)
    try
    {
        //
        // Populate the feature DM<->PT conversion vector
        //
        pHandler = new(std::nothrow) CWatermarkDMPTConv();

        hr = AddConverter(pHandler);

        if (SUCCEEDED(hr))
        {
            pHandler = new(std::nothrow) CPageScalingDMPTConv();

            hr = AddConverter(pHandler);
        }

        if (SUCCEEDED(hr))
        {
            pHandler = new(std::nothrow) CBookletDMPTConv();

            hr = AddConverter(pHandler);
        }

        if (SUCCEEDED(hr))
        {
            pHandler = new(std::nothrow) CNUpDMPTConv();

            hr = AddConverter(pHandler);
        }

        if (SUCCEEDED(hr))
        {
            pHandler = new(std::nothrow) CColorProfileDMPTConv();

            hr = AddConverter(pHandler);
        }
    }
    catch (exception& DBG_ONLY(e))
    {
        ERR(e.what());

        hr = E_FAIL;
    }

    if (FAILED(hr))
    {
        //
        // If we successfully created a handler but failed to push it onto
        // the handler vector we need to free the allocated handler
        //
        if (pHandler != NULL)
        {
            delete pHandler;
            pHandler = NULL;
        }

        //
        // Delete any DM<->PT converters that were successfully instantiated
        //
        DeleteConverters();

        throw CXDException(hr);
    }
#pragma prefast(pop)
}

/*++

Routine Name:

    CXDSmplPTProvider::~CXDSmplPTProvider

Routine Description:

    CXDSmplPTProvider class destructor

Arguments:

    None

Return Value:

    None

--*/
CXDSmplPTProvider::~CXDSmplPTProvider()
{
    //
    // Clean up all DM<->PT converters
    //
    DeleteConverters();
}

/*++

Routine Name:

    CXDSmplPTProvider::GetSupportedVersions

Routine Description:

    The routine returns major versions of Printschema schema supported by the plug-in Provider.

Arguments:

    hPrinter - Printer Handle
    ppVersions - OUT pointer to array of version numbers to be filled in by the plug-in
    cVersions - OUT pointer to count of Number of versions supported by plug-in

Return Value:

    HRESULT
    S_OK - On success
    E_* - On error

--*/
HRESULT STDMETHODCALLTYPE
CXDSmplPTProvider::GetSupportedVersions(
    _In_                            HANDLE,
    _Outptr_result_buffer_(*pcVersions) INT* ppVersions[],
    _Out_                           INT* pcVersions
    )
{
    HRESULT hr = S_OK;

    //
    // Check if input parameters are valid
    //
    if (SUCCEEDED(hr = CHECK_POINTER(ppVersions, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(pcVersions, E_POINTER)))
    {
        *pcVersions = 0;

        //
        // The Plug-in Provider need to allocate memory for the input version array and
        // then fill it with version information
        //
        *ppVersions = static_cast<INT*>(CoTaskMemAlloc(sizeof(INT)));

        if (*ppVersions != NULL)
        {
            //
            // version number 1 is the only version supported currently
            //
            *pcVersions = 1;
            (*ppVersions)[0] = PRINTSCHEMA_VERSION_NUMBER;
        }
        else
        {
            hr = E_OUTOFMEMORY;
        }
    }

    ERR_ON_HR(hr);
    return hr;
}

/*++

Routine Name:

    CXDSmplPTProvider::BindPrinter

Routine Description:

    Bind Printer is the part of the Unidrv's activity to bind to a device. It allows the plug-in to cache
    certain information that can be used later on such as the private namespaces used by the plug-in.

Arguments:

    hPrinter     - Printer Handle supplied by Unidrv
    version      - version of Printschema
    pOptions     - Flags passed out to set configurable options supported by caller
    cNamespaces  - Count of private namespaces of plug-in
    ppNamespaces - OUT pointer to the array of Namespace URIs filled in by plug-in

Return Value:

    HRESULT
    S_OK - On success
    E_VERSION_NOT_SUPPORTED - if printer version specified is not supported by plug-in
    E_* - On any other failure

--*/
HRESULT STDMETHODCALLTYPE
CXDSmplPTProvider::BindPrinter(
    _In_                                  HANDLE     hPrinter,
                                          INT        version,
    _Out_                                 POEMPTOPTS pOptions,
    _Out_                                 INT*       pcNamespaces,
    _Outptr_result_buffer_maybenull_(*pcNamespaces) BSTR**     ppNamespaces
    )
{
    HRESULT hr = S_OK;

    //
    // Printer Handle should be provided by Unidrv in this call, which is cached by plug-in provider and
    // is later on used while making calls to Plug-in Helper Interface methods.
    //
    if (SUCCEEDED(hr = CHECK_POINTER(pOptions, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(pcNamespaces, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(ppNamespaces, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(hPrinter, E_HANDLE)))
    {
        *ppNamespaces = NULL;
        *pcNamespaces = 0;

        //
        // Agree on the Printschema version with Unidrv Version 1 is the only
        // version currently supported
        //
        if (PRINTSCHEMA_VERSION_NUMBER == version)
        {
            //
            // Cache the printer handle for further use
            //
            m_hPrinterCached = hPrinter;

            //
            // Flags to set configurable options, OEMPT_DEFAULT defined in prcomoem.h
            //
            *pOptions = OEMPT_NOSNAPSHOT;

            //
            // Publish the private namespace
            //
            *pcNamespaces = 1;
            *ppNamespaces = static_cast<BSTR*>(CoTaskMemAlloc(sizeof(BSTR)));

            if (SUCCEEDED(hr = CHECK_POINTER(*ppNamespaces, E_OUTOFMEMORY)))
            {
                hr = m_bstrPrivateNS.CopyTo(*ppNamespaces);
            }
        }
        else
        {
            hr =  E_VERSION_NOT_SUPPORTED;
        }
    }

    ERR_ON_HR_EXC(hr, E_VERSION_NOT_SUPPORTED);
    return hr;
}

/*++

Routine Name:

    CXDSmplPTProvider::PublishPrintTicketHelperInterface

Routine Description:

    For a number of operations, the plug-in needs to use the Helper Interface utilities provided by
    Unidrv. Unidrv uses this method to publish the PrintTicket Helper Interface, IPrintCoreHelper.
    Plug-in should return SUCCESS after successfully incrementing the reference count of the interface.

Arguments:

    pHelper - IPrintCoreHelper interface pointer

Return Value:

    HRESULT
    S_OK - On success
    E_* - On error

--*/
HRESULT STDMETHODCALLTYPE
CXDSmplPTProvider::PublishPrintTicketHelperInterface(
    _In_ IUnknown *pHelper
    )
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(pHelper, E_POINTER)))
    {
        //
        // Need to store pointer to Driver Helper functions, if we already haven't.
        //
        if (m_pCoreHelper == NULL)
        {
            hr = pHelper->QueryInterface(IID_IPrintCoreHelperUni, reinterpret_cast<VOID**>(&m_pCoreHelper));
        }

        //
        // It's possible that this routine will publish other interfaces in the future.
        // If the object published did not support the desired interface, this routine
        // should still succeed.
        //
        // If the helper interface is needed, but for some reason was not published
        // (this would be an error on the OS's part), you should detect this and fail
        // during the call-back where you intended to use the helper interface.
        //
        if (E_NOINTERFACE == hr)
        {
            hr = S_OK;
        }
        else
        {
            try
            {
               //
               // Iterate over all PrintTicket feature converters publishing the helper interface
               //
               DMPTConvCollection::iterator iterConverters =  m_vectFtrDMPTConverters.begin();

               for (; iterConverters != m_vectFtrDMPTConverters.end() && SUCCEEDED(hr); iterConverters++)
               {
                   hr = (*iterConverters)->PublishPrintTicketHelperInterface(m_pCoreHelper);
               }
            }
            catch (exception& DBG_ONLY(e))
            {
                ERR(e.what());
                hr = E_FAIL;
            }
        }
    }

    ERR_ON_HR(hr);
    return hr;
}

/*++

Routine Name:

    CXDSmplPTProvider::QueryDeviceDefaultNamespace

Routine Description:

    This method provides the plug-in with the opportunity to specify the name of the
    Private namespace URI that Unidrv should be using to handle any features defined
    in the GPD that Unidrv does not recognize. The plug-in may specify a set of
    namespaces as a result of the call to BindPrinter method, and Unidrv needs to know
    which of them is to be used as default namespace so that, for all the features that
    Unidrv does not recognize, it will put them under this namespace in the PrintTicket.

    Note: It is Unidrv's responsibility to add the private namespace URI that plug-in
    has specified through this call in the root node of the DOM document, and also define
    a prefix for it so that plug-in should use the prefix defined by Unidrv when it wishes
    to add any new node to the PrintTicket under its private namespace. Plug-in should
    not define its own prefix for this default private namespace URI.

Arguments:

    pbstrNamespaceUri - OUT Pointer to namespace URI to be filled in and returned by plug-in

Return Value:

    HRESULT
    S_OK - On success
    E_NOTIMPL - The plugin does not require a private namespace
    E_* - On error

--*/
HRESULT STDMETHODCALLTYPE
CXDSmplPTProvider::QueryDeviceDefaultNamespace(
    _Out_ BSTR* pbstrNamespaceUri
    )
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(pbstrNamespaceUri, E_POINTER)))
    {
        hr = m_bstrPrivateNS.CopyTo(pbstrNamespaceUri);
    }

    ERR_ON_HR(hr);
    return hr;
}

/*++

Routine Name:

    CXDSmplPTProvider::ConvertPrintTicketToDevMode

Routine Description:

    Unidrv will call this routine before it performs its part of PT->DM
    conversion. The plug-in is passed with an input PrintTicket that is
    fully populated, and Devmode which has default settings in it.

    This routine merely passes the call on to the individual feature handlers.

Arguments:

    pPrintTicket - pointer to input PrintTicket
    cbDevmode - size in bytes of input full devmode
    pDevmode - pointer to input full devmode buffer
    cbDrvPrivateSize - buffer size in bytes of plug-in private devmode
    pPrivateDevmode - pointer to plug-in private devmode buffer


Return Value:

    HRESULT
    S_OK - On success
    E_* - On error

--*/
HRESULT STDMETHODCALLTYPE
CXDSmplPTProvider::ConvertPrintTicketToDevMode(
    _In_    IXMLDOMDocument2* pPrintTicket,
            ULONG             cbDevmode,
    _Inout_updates_bytes_(cbDevmode) 
            PDEVMODE          pDevmode,
            ULONG             cbDrvPrivateSize,
    _Inout_ PVOID             pPrivateDevmode
    )
{
    HRESULT hr = S_OK;

    //
    // Validate parameters
    //
    if (SUCCEEDED(hr = CHECK_POINTER(pDevmode, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(pPrivateDevmode, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(pPrintTicket, E_POINTER)))
    {
        if (cbDevmode < sizeof(DEVMODE) ||
            cbDrvPrivateSize == 0)
        {
            hr = E_INVALIDARG;
        }
    }

    try
    {
        if (SUCCEEDED(hr))
        {
            //
            // Iterate over all PrintTicket feature converters letting them
            // provide the conversion
            //
            DMPTConvCollection::iterator iterConverters =  m_vectFtrDMPTConverters.begin();

            for (; iterConverters != m_vectFtrDMPTConverters.end() && SUCCEEDED(hr); iterConverters++)
            {
                hr = (*iterConverters)->ConvertPrintTicketToDevMode(pPrintTicket, cbDevmode, pDevmode, cbDrvPrivateSize, pPrivateDevmode);
            }
        }
    }
    catch (exception& DBG_ONLY(e))
    {
        ERR(e.what());
        hr = E_FAIL;
    }

    ERR_ON_HR(hr);
    return hr;
}

/*++

Routine Name:

    CXDSmplPTProvider::ConvertDevModeToPrintTicket

Routine Description:

    Unidrv will call the routine with an Input PrintTicket that is populated
    with public and Unidrv private features. For those features in the GPD that
    Unidrv does not understand, it puts them in the PT under the private namespace
    (either specified by the plug-in through QueryDeviceDefaultNamespace or created
    by itself). It is the plug-in's responsibility to read the corresponding features
    from the input PT and put them in public printschema namespace, so that any higher
    level application making use of a PrintTicket can read and interpret these settings.

    This routine merely passes the call on to the individual feature handlers.


Arguments:

    cbDevmode - size in bytes of input full devmode
    pDevmode - pointer to input full devmode buffer
    cbDrvPrivateSize - buffer size in bytes of plug-in private devmode
    pPrivateDevmode - pointer to plug-in private devmode buffer
    pPrintTicket - pointer to input PrintTicket

Return Value:

    HRESULT
    S_OK - On success
    E_* - On error

--*/
HRESULT STDMETHODCALLTYPE
CXDSmplPTProvider::ConvertDevModeToPrintTicket(
            ULONG             cbDevmode,
    _Inout_updates_bytes_(cbDevmode) 
            PDEVMODE          pDevmode,
            ULONG             cbDrvPrivateSize,
    _Inout_ PVOID             pPrivateDevmode,
    _Inout_ IXMLDOMDocument2* pPrintTicket
    )
{
    HRESULT hr = S_OK;

    //
    // Validate parameters
    //
    if (SUCCEEDED(hr = CHECK_POINTER(pDevmode, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(pPrivateDevmode, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(pPrintTicket, E_POINTER)))
    {
        if (cbDevmode < sizeof(DEVMODE) ||
            cbDrvPrivateSize == 0)
        {
            hr = E_INVALIDARG;
        }
    }

    try
    {
        if (SUCCEEDED(hr))
        {
            //
            // Iterate over all PrintTicket feature converters letting them
            // provide the conversion
            //
            DMPTConvCollection::iterator iterConverters =  m_vectFtrDMPTConverters.begin();

            for (; iterConverters != m_vectFtrDMPTConverters.end() && SUCCEEDED(hr); iterConverters++)
            {
                hr = (*iterConverters)->ConvertDevModeToPrintTicket(cbDevmode, pDevmode, cbDrvPrivateSize, pPrivateDevmode, pPrintTicket);
            }

            //
            // Delete all the private features generated by the Unidrv parser from the GPD.
            // These are not required in the PrintTicket as they are only used to control
            // features in the public PrintSchema and have no meaning outside the config
            // module.
            //
            if (SUCCEEDED(hr))
            {
                CPTHandler ptHandler(pPrintTicket);
                hr = ptHandler.DeletePrivateFeatures(m_bstrPrivateNS);
            }
        }
    }
    catch (exception& DBG_ONLY(e))
    {
        ERR(e.what());
        hr = E_FAIL;
    }

    ERR_ON_HR(hr);
    return hr;
}

/*++

Routine Name:

    CXDSmplPTProvider::CompletePrintCapabilities

Routine Description:

    Unidrv calls this routine with an input Device Capabilities Document
    that is partially populated with Device capabilities information
    filled in by Unidrv for features that it understands. The plug-in
    needs to read any private features in the input PrintTicket, delete
    them and add them back under Printschema namespace so that higher
    level applications can understand them and make use of them.

    The XPSDrv sample driver does not define any private device capabilities
    so this method merely returns S_OK

Arguments:

    pPrintTicket - pointer to input PrintTicket
    pCapabilities - pointer to Device Capabilities Document.

Return Value:

    HRESULT
    S_OK - Always

--*/
HRESULT STDMETHODCALLTYPE
CXDSmplPTProvider::CompletePrintCapabilities(
    _In_opt_ IXMLDOMDocument2* pPrintTicket,
    _Inout_  IXMLDOMDocument2* pPrintCapabilities
    )
{
    HRESULT hr = S_OK;

    //
    // Validate parameters
    //
    if (SUCCEEDED(hr = CHECK_POINTER(pPrintCapabilities, E_POINTER)))
    {
        try
        {
            //
            // Iterate over all PrintTicket feature converters letting them
            // provide the conversion
            //
            DMPTConvCollection::iterator iterConverters =  m_vectFtrDMPTConverters.begin();

            for (; iterConverters != m_vectFtrDMPTConverters.end() && SUCCEEDED(hr); iterConverters++)
            {
                hr = (*iterConverters)->CompletePrintCapabilities(pPrintTicket, pPrintCapabilities);
            }

            //
            // Delete all the private features generated by the Unidrv parser from the GPD.
            // These are not required in the PrintCapabilities as they are only used to control
            // features in the public PrintSchema and have no meaning outside the config
            // module.
            //
            if (SUCCEEDED(hr))
            {
                CPCHandler pcHandler(pPrintCapabilities);
                hr = pcHandler.DeletePrivateFeatures(m_bstrPrivateNS);
            }
        }
        catch (exception& DBG_ONLY(e))
        {
            ERR(e.what());
            hr = E_FAIL;
        }
    }

    ERR_ON_HR(hr);
    return hr;
}

/*++

Routine Name:

    CXDSmplPTProvider::ExpandIntentOptions

Routine Description:

    As part of its Merge and Validate Procedure, the Unidrv/Postscript driver
    will call this routine to give the plug-in a chance to expand options
    which represent intent into their individual settings in other features
    in the PrintTicket.  This has two important effects: the client sees the
    results of the intent expansion, and unidrv resolves constraints against
    the individual features which are affected by the intent.

    The XPSDrv sample driver plug-in does not support any intent features, therefore
    simply returns S_OK.

Arguments:

    pPrintTicket - Pointer to input PrintTicket.

Return Value:

    HRESULT
    S_OK - Always

--*/
HRESULT STDMETHODCALLTYPE
CXDSmplPTProvider::ExpandIntentOptions(
    _Inout_ IXMLDOMDocument2 *
    )
{
    return S_OK;
}

/*++

Routine Name:

    CXDSmplPTProvider::ValidatePrintTicket

Routine Description:

    The plug-in might need to delete any feature under private namespace
    from input PT that are also in the public namespace because of Merge
    and Validate.

    The Validate method should also perform any conflict resolution if
    necessary looking at the settings made in public and unidrv private
    part of PrintTicket, to make sure that the resultant PrintTicket is a
    valid one, and has all constraints resolved.

    This routine merely passes the validate call on to the feature handlers

Arguments:

    pPrintTicket - Pointer to input PrintTicket.

Return Value:

    HRESULT
    S_NO_CONFLICT/S_CONFLICT_RESOLVED - On success
    E_* - On error

--*/
HRESULT STDMETHODCALLTYPE
CXDSmplPTProvider::ValidatePrintTicket(
    _Inout_ IXMLDOMDocument2* pPrintTicket
    )
{
    HRESULT hr = S_NO_CONFLICT;

    //
    // Validate parameters
    //
    if (pPrintTicket != NULL)
    {
        try
        {
            //
            // Iterate over all PrintTicket feature converters letting them
            // provide the validation
            //
            DMPTConvCollection::iterator iterConverters =  m_vectFtrDMPTConverters.begin();

            for (; iterConverters != m_vectFtrDMPTConverters.end() && SUCCEEDED(hr); iterConverters++)
            {
                HRESULT hrConverter = (*iterConverters)->ValidatePrintTicket(pPrintTicket);

                if (FAILED(hrConverter) ||
                    hrConverter == static_cast<HRESULT>(S_CONFLICT_RESOLVED))
                {
                    hr = hrConverter;
                }
            }
        }
        catch (...)
        {
            hr = E_FAIL;
        }
    }
    else
    {
        hr = E_POINTER;
    }

    ERR_ON_HR(hr);
    return hr;
}

/*++

Routine Name:

    CXDSmplPTProvider::DeleteConverters

Routine Description:

    This routine cleans up the vector of DM <-> PT converters.

Arguments:

    NONE

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CXDSmplPTProvider::DeleteConverters(
    VOID
    )
{
    HRESULT hr = S_OK;

    try
    {
        while (!m_vectFtrDMPTConverters.empty())
        {
            if (m_vectFtrDMPTConverters.back() != NULL)
            {
                delete m_vectFtrDMPTConverters.back();
                m_vectFtrDMPTConverters.back() = NULL;
            }

            m_vectFtrDMPTConverters.pop_back();
        }
    }
    catch (exception& DBG_ONLY(e))
    {
        ERR(e.what());
        hr = E_FAIL;
    }

    ERR_ON_HR(hr);
    return hr;
}

//
// Use __drv_aliasesMem annotation to avoid PREfast warning 28197: Possibly leaking memory,
//
HRESULT
// Prefast warning 28194: The function was declared as aliasing the value in variable and exited without doing so.
// We suppress this false positive because STL vector does not have annotation, and we know the pointer has been saved
// to STL vector, which is released in DeleteConverters().
#pragma warning(suppress: 28194)
CXDSmplPTProvider::AddConverter(
    _In_opt_ __drv_aliasesMem IFeatureDMPTConvert *pHandler
    )
{
    HRESULT hr = CHECK_POINTER(pHandler, E_OUTOFMEMORY);

    if (SUCCEEDED(hr))
    {
        m_vectFtrDMPTConverters.push_back(pHandler);
    }

    return hr;
}