summaryrefslogtreecommitdiff
path: root/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/ServiceViewModel.h
blob: c2fcad0c325590b85db65de19da054b3345b507b (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
#pragma once

#include "RpcClient.h"
#include <memory>

namespace SDKTemplate
{
    [Windows::UI::Xaml::Data::Bindable]
    public ref class ServiceViewModel sealed : Windows::UI::Xaml::Data::INotifyPropertyChanged
    {
    public:
        ServiceViewModel();
        void StartMetering(int sampleRate);
        void SetSamplePeriod(int rate);
        void StopMetering();
        property Platform::String^ ExpectedRpcCallbackRate 
        {
            Platform::String^ get();
            void set(Platform::String^ value);
        }
        property Platform::String^ ActualRpcCallbackRate 
        {
            Platform::String^ get();
            void set(Platform::String^ value);
        }
        property Platform::String^ SampleMessage 
        {
            Platform::String^ get();
            void set(Platform::String^ value);
        }
        property bool StartButtonEnabled 
        {
            bool get();
            void set(bool value);
        }
        property bool StopButtonEnabled 
        {
            bool get();
            void set(bool value);
        }
        property bool SliderEnabled 
        {
            bool get();
            void set(bool value);
        }
        property double SliderValue 
        {
            double get();
            void set(double value);
        }
        virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged;

    private:
        volatile bool meteringOn;
        Windows::UI::Core::ICoreDispatcher^ dispatcher;
        int samplePeriod;
        ULARGE_INTEGER lastUpdateTime;
        __int64 rpcDataCountOld = 0;
        unsigned int sampleRefreshCount = 0;
        std::unique_ptr<RpcClient> rpcclient;
        bool stopMeteringRequested;
        bool NotifyIfAnyError(__int64 errCode);

        // Variables backing UI bindings
        Platform::String^ sampleMessage;
        Platform::String^ expectedRpcCallbackRate;
        Platform::String^ actualRpcCallbackRate;
        bool startButtonEnabled;
        bool stopButtonEnabled;
        bool sliderEnabled;
        double sliderValue;

        void NotifyPropertyChanged(Platform::String^ prop);

        Platform::Array<__int64>^ sampleArray;
    };
}