Skip to content

Commit 6d543a3

Browse files
author
Alexandre Colucci
committed
CPU 1.2 source code
0 parents  commit 6d543a3

File tree

4,702 files changed

+565034
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,702 files changed

+565034
-0
lines changed

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License
2+
3+
Copyright 2018 Corsair Memory, Inc
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
`CPU` is a sample plugin demonstrating the [Stream Deck SDK](https://developer.elgato.com/documentation/stream-deck/).
3+
4+
5+
# Description
6+
7+
`CPU` is a plugin that displays the CPU usage on a key.
8+
9+
Features:
10+
11+
- code written in C++
12+
- cross-platform (macOS, Windows)
13+
- localized
14+
15+
16+
# Installation
17+
18+
In the Release folder, you can find the file `com.elgato.cpu.streamDeckPlugin`. If you double-click this file on your machine, Stream Deck will install the plugin.
19+
20+
21+
# Source code
22+
23+
The Sources folder contains the source code of the plugin.
457 KB
Binary file not shown.

Sources/Common/EPLJSONUtils.h

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
//==============================================================================
2+
/**
3+
@file EPLJSONUtils.h
4+
5+
@brief Utility methods for JSON parser from N.Lohmann
6+
https://github.com/nlohmann/json
7+
8+
@copyright (c) 2018, Corsair Memory, Inc.
9+
This source code is licensed under the MIT-style license found in the LICENSE file.
10+
11+
**/
12+
//==============================================================================
13+
14+
#pragma once
15+
16+
//------------------------------------------------------------------------------
17+
// Includes
18+
//------------------------------------------------------------------------------
19+
20+
#include "../Vendor/json/src/json.hpp"
21+
using json = nlohmann::json;
22+
23+
class EPLJSONUtils
24+
{
25+
26+
public:
27+
28+
//! Get object by name
29+
static bool GetObjectByName(const json& inJSON, const std::string& inName, json& outObject)
30+
{
31+
// Check desired value exists
32+
json::const_iterator iter(inJSON.find(inName));
33+
if (iter == inJSON.end())
34+
return false;
35+
36+
// Check value is an array
37+
if (!iter->is_object())
38+
return false;
39+
40+
// Assign value
41+
outObject = *iter;
42+
43+
return true;
44+
}
45+
46+
//! Get array by name
47+
static bool GetArrayByName(const json& inJSON, const std::string& inName, json& outArray)
48+
{
49+
// Check desired value exists
50+
json::const_iterator iter(inJSON.find(inName));
51+
if (iter == inJSON.end())
52+
return false;
53+
54+
// Check value is an array
55+
if (!iter->is_array())
56+
return false;
57+
58+
// Assign value
59+
outArray = *iter;
60+
61+
return true;
62+
}
63+
64+
//! Get string by name
65+
static std::string GetStringByName(const json& inJSON, const std::string& inName, const std::string& defaultValue = "")
66+
{
67+
// Check desired value exists
68+
json::const_iterator iter(inJSON.find(inName));
69+
if (iter == inJSON.end())
70+
return defaultValue;
71+
72+
// Check value is a string
73+
if (!iter->is_string())
74+
return defaultValue;
75+
76+
// Return value
77+
return *iter;
78+
}
79+
80+
//! Get string
81+
static std::string GetString(const json& j, const std::string& defaultString = "")
82+
{
83+
// Check value is a string
84+
if (!j.is_string())
85+
return defaultString;
86+
87+
return j;
88+
}
89+
90+
//! Get bool by name
91+
static bool GetBoolByName(const json& inJSON, const std::string& inName, bool defaultValue = false)
92+
{
93+
// Check desired value exists
94+
json::const_iterator iter(inJSON.find(inName));
95+
if (iter == inJSON.end())
96+
return defaultValue;
97+
98+
// Check value is a bool
99+
if (!iter->is_boolean())
100+
return defaultValue;
101+
102+
// Return value
103+
return *iter;
104+
}
105+
106+
//! Get integer by name
107+
static int GetIntByName(const json& inJSON, const std::string& inName, int defaultValue = 0)
108+
{
109+
// Check desired value exists
110+
json::const_iterator iter(inJSON.find(inName));
111+
if (iter == inJSON.end())
112+
return defaultValue;
113+
114+
// Check value is an integer
115+
if (!iter->is_number_integer())
116+
return defaultValue;
117+
118+
// Return value
119+
return *iter;
120+
}
121+
122+
//! Get unsigned integer by name
123+
static unsigned int GetUnsignedIntByName(const json& inJSON, const std::string& inName, unsigned int defaultValue = 0)
124+
{
125+
// Check desired value exists
126+
json::const_iterator iter(inJSON.find(inName));
127+
if (iter == inJSON.end())
128+
return defaultValue;
129+
130+
// Check value is an unsigned integer
131+
if (!iter->is_number_unsigned())
132+
return defaultValue;
133+
134+
// Return value
135+
return *iter;
136+
}
137+
138+
//! Get float by name
139+
static float GetFloatByName(const json& inJSON, const std::string& inName, float defaultValue = 0.0)
140+
{
141+
// Check desired value exists
142+
json::const_iterator iter(inJSON.find(inName));
143+
if (iter == inJSON.end())
144+
return defaultValue;
145+
146+
// Check value is an integer
147+
if (!iter->is_number_float() && !iter->is_number_integer())
148+
return defaultValue;
149+
150+
// Return value
151+
return *iter;
152+
}
153+
};

Sources/Common/ESDBasePlugin.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//==============================================================================
2+
/**
3+
@file ESDBasePlugin.h
4+
5+
@brief Plugin base class
6+
7+
@copyright (c) 2018, Corsair Memory, Inc.
8+
This source code is licensed under the MIT-style license found in the LICENSE file.
9+
10+
**/
11+
//==============================================================================
12+
13+
#pragma once
14+
15+
class ESDConnectionManager;
16+
17+
class ESDBasePlugin
18+
{
19+
public:
20+
ESDBasePlugin() { }
21+
virtual ~ESDBasePlugin() { }
22+
23+
void SetConnectionManager(ESDConnectionManager * inConnectionManager) { mConnectionManager = inConnectionManager; }
24+
25+
virtual void KeyDownForAction(const std::string& inAction, const std::string& inContext, const json &inPayload, const std::string& inDeviceID) = 0;
26+
virtual void KeyUpForAction(const std::string& inAction, const std::string& inContext, const json &inPayload, const std::string& inDeviceID) = 0;
27+
28+
virtual void WillAppearForAction(const std::string& inAction, const std::string& inContext, const json &inPayload, const std::string& inDeviceID) = 0;
29+
virtual void WillDisappearForAction(const std::string& inAction, const std::string& inContext, const json &inPayload, const std::string& inDeviceID) = 0;
30+
31+
virtual void DeviceDidConnect(const std::string& inDeviceID, const json &inDeviceInfo) = 0;
32+
virtual void DeviceDidDisconnect(const std::string& inDeviceID) = 0;
33+
34+
protected:
35+
ESDConnectionManager *mConnectionManager = nullptr;
36+
37+
};

0 commit comments

Comments
 (0)