Skip to content

Commit

Permalink
Add castings and defines to reduce the amount of warnings (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoHolztrattner authored and eddyStreamlabs committed Nov 8, 2018
1 parent e8af3a4 commit cafea03
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 95 deletions.
8 changes: 4 additions & 4 deletions obs-studio-client/source/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,11 @@ Nan::NAN_METHOD_RETURN_TYPE osn::Input::GetPublicSources(Nan::NAN_METHOD_ARGS_TY
if (!ValidateResponse(response))
return;

v8::Local<v8::Array> arr = Nan::New<v8::Array>(response.size() - 1);
v8::Local<v8::Array> arr = Nan::New<v8::Array>(int(response.size() - 1));
for (size_t idx = 1; idx < response.size(); idx++) {
osn::Input* obj = new osn::Input(response[idx - 1].value_union.ui64);
auto object = osn::Input::Store(obj);
Nan::Set(arr, idx, object);
Nan::Set(arr, uint32_t(idx), object);
}

info.GetReturnValue().Set(arr);
Expand Down Expand Up @@ -750,11 +750,11 @@ Nan::NAN_METHOD_RETURN_TYPE osn::Input::Filters(Nan::NAN_METHOD_ARGS_TYPE info)
if (!ValidateResponse(response))
return;

v8::Local<v8::Array> arr = Nan::New<v8::Array>(response.size() - 1);
v8::Local<v8::Array> arr = Nan::New<v8::Array>(int(response.size()) - 1);
for (size_t idx = 1; idx < response.size(); idx++) {
osn::Filter* obj = new osn::Filter(response[idx].value_union.ui64);
auto object = osn::Filter::Store(obj);
Nan::Set(arr, idx - 1, object);
Nan::Set(arr, uint32_t(idx) - 1, object);
}

info.GetReturnValue().Set(arr);
Expand Down
2 changes: 1 addition & 1 deletion obs-studio-client/source/isource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void osn::ISource::callback_handler(void* data, std::shared_ptr<std::vector<Sour
v8::String::NewFromUtf8(isolate, "hotkeyDescription"),
v8::String::NewFromUtf8(isolate, hotkeyInfo.hotkeyDesc.c_str()));
argv->ToObject()->Set(
v8::String::NewFromUtf8(isolate, "hotkeyId"), v8::Number::New(isolate, hotkeyInfo.hotkeyId));
v8::String::NewFromUtf8(isolate, "hotkeyId"), v8::Number::New(isolate, double(hotkeyInfo.hotkeyId)));
args[0] = argv;

Nan::Call(m_callback_function, 1, args);
Expand Down
57 changes: 30 additions & 27 deletions obs-studio-client/source/nodeobs_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ std::vector<settings::SubCategory>
std::vector<settings::SubCategory> category;

uint32_t indexData = 0;
for (int i = 0; i < subCategoriesCount; i++) {
for (int i = 0; i < int(subCategoriesCount); i++) {
settings::SubCategory sc;

size_t* sizeMessage = reinterpret_cast<size_t*>(buffer.data() + indexData);
indexData += sizeof(size_t);

std::string name(buffer.data() + indexData, *sizeMessage);
indexData += *sizeMessage;
indexData += uint32_t(*sizeMessage);

size_t* paramsCount = reinterpret_cast<size_t*>(buffer.data() + indexData);
indexData += sizeof(size_t);
Expand All @@ -33,25 +33,25 @@ std::vector<settings::SubCategory>
indexData += sizeof(size_t);

std::string name(buffer.data() + indexData, *sizeName);
indexData += *sizeName;
indexData += uint32_t(*sizeName);

size_t* sizeDescription = reinterpret_cast<std::size_t*>(buffer.data() + indexData);
indexData += sizeof(size_t);

std::string description(buffer.data() + indexData, *sizeDescription);
indexData += *sizeDescription;
indexData += uint32_t(*sizeDescription);

size_t* sizeType = reinterpret_cast<std::size_t*>(buffer.data() + indexData);
indexData += sizeof(size_t);

std::string type(buffer.data() + indexData, *sizeType);
indexData += *sizeType;
indexData += uint32_t(*sizeType);

size_t* sizeSubType = reinterpret_cast<std::size_t*>(buffer.data() + indexData);
indexData += sizeof(size_t);

std::string subType(buffer.data() + indexData, *sizeSubType);
indexData += *sizeSubType;
indexData += uint32_t(*sizeSubType);

bool* enabled = reinterpret_cast<bool*>(buffer.data() + indexData);
indexData += sizeof(bool);
Expand All @@ -68,7 +68,7 @@ std::vector<settings::SubCategory>
std::vector<char> currentValue;
currentValue.resize(*sizeOfCurrentValue);
memcpy(currentValue.data(), buffer.data() + indexData, *sizeOfCurrentValue);
indexData += *sizeOfCurrentValue;
indexData += uint32_t(*sizeOfCurrentValue);

size_t* sizeOfValues = reinterpret_cast<size_t*>(buffer.data() + indexData);
indexData += sizeof(size_t);
Expand All @@ -79,7 +79,7 @@ std::vector<settings::SubCategory>
std::vector<char> values;
values.resize(*sizeOfValues);
memcpy(values.data(), buffer.data() + indexData, *sizeOfValues);
indexData += *sizeOfValues;
indexData += uint32_t(*sizeOfValues);

param.name = name;
param.description = description;
Expand All @@ -95,7 +95,7 @@ std::vector<settings::SubCategory>
sc.params.push_back(param);
}
sc.name = name;
sc.paramsCount = *paramsCount;
sc.paramsCount = uint32_t(*paramsCount);
category.push_back(sc);
}
return category;
Expand All @@ -119,8 +119,8 @@ void settings::OBS_settings_getSettings(const v8::FunctionCallbackInfo<v8::Value
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::Local<v8::Array> rval = v8::Array::New(isolate);

std::vector<settings::SubCategory> categorySettings =
serializeCategory(response[1].value_union.ui64, response[2].value_union.ui64, response[3].value_bin);
std::vector<settings::SubCategory> categorySettings = serializeCategory(
uint32_t(response[1].value_union.ui64), uint32_t(response[2].value_union.ui64), response[3].value_bin);

for (int i = 0; i < categorySettings.size(); i++) {
v8::Local<v8::Object> subCategory = v8::Object::New(isolate);
Expand Down Expand Up @@ -161,12 +161,12 @@ void settings::OBS_settings_getSettings(const v8::FunctionCallbackInfo<v8::Value
else if (params.at(j).type.compare("OBS_PROPERTY_INT") == 0) {
int64_t *value = reinterpret_cast<int64_t*>(params.at(j).currentValue.data());
parameter->Set(v8::String::NewFromUtf8(isolate, "currentValue"),
v8::Integer::New(isolate, *value));
v8::Integer::New(isolate, int32_t(*value)));
}
else if (params.at(j).type.compare("OBS_PROPERTY_UINT") == 0) {
uint64_t *value = reinterpret_cast<uint64_t*>(params.at(j).currentValue.data());
parameter->Set(v8::String::NewFromUtf8(isolate, "currentValue"),
v8::Integer::New(isolate, *value));
v8::Integer::New(isolate, int32_t(*value)));
}
else if (params.at(j).type.compare("OBS_PROPERTY_BOOL") == 0) {
bool *value = reinterpret_cast<bool*>(params.at(j).currentValue.data());
Expand All @@ -182,7 +182,7 @@ void settings::OBS_settings_getSettings(const v8::FunctionCallbackInfo<v8::Value
if (params.at(j).subType.compare("OBS_COMBO_FORMAT_INT") == 0) {
int64_t *value = reinterpret_cast<int64_t*>(params.at(j).currentValue.data());
parameter->Set(v8::String::NewFromUtf8(isolate, "currentValue"),
v8::Integer::New(isolate, *value));
v8::Integer::New(isolate, int32_t(*value)));
}
else if (params.at(j).subType.compare("OBS_COMBO_FORMAT_FLOAT") == 0) {
double *value = reinterpret_cast<double*>(params.at(j).currentValue.data());
Expand Down Expand Up @@ -212,21 +212,21 @@ void settings::OBS_settings_getSettings(const v8::FunctionCallbackInfo<v8::Value
size_t* sizeName = reinterpret_cast<std::size_t*>(params.at(j).values.data() + indexData);
indexData += sizeof(size_t);
std::string name(params.at(j).values.data() + indexData, *sizeName);
indexData += *sizeName;
indexData += uint32_t(*sizeName);

int64_t* value = reinterpret_cast<int64_t*>(params.at(j).values.data() + indexData);

indexData += sizeof(int64_t);

valueObject->Set(v8::String::NewFromUtf8(isolate, name.c_str()),
v8::Integer::New(isolate, *value));
v8::Integer::New(isolate, int32_t(*value)));
}
else if (params.at(j).subType.compare("OBS_COMBO_FORMAT_FLOAT") == 0) {
size_t *sizeName =
reinterpret_cast<std::size_t*>(params.at(j).values.data() + indexData);
indexData += sizeof(size_t);
std::string name(params.at(j).values.data() + indexData, *sizeName);
indexData += *sizeName;
indexData += uint32_t(*sizeName);

double* value = reinterpret_cast<double*>(params.at(j).values.data() + indexData);

Expand All @@ -240,12 +240,12 @@ void settings::OBS_settings_getSettings(const v8::FunctionCallbackInfo<v8::Value
reinterpret_cast<std::size_t*>(params.at(j).values.data() + indexData);
indexData += sizeof(size_t);
std::string name(params.at(j).values.data() + indexData, *sizeName);
indexData += *sizeName;
indexData += uint32_t(*sizeName);

size_t* sizeValue = reinterpret_cast<std::size_t*>(params.at(j).values.data() + indexData);
indexData += sizeof(size_t);
std::string value(params.at(j).values.data() + indexData, *sizeValue);
indexData += *sizeValue;
indexData += uint32_t(*sizeValue);

valueObject->Set(
v8::String::NewFromUtf8(isolate, name.c_str()),
Expand Down Expand Up @@ -287,7 +287,7 @@ std::vector<char> deserializeCategory(uint32_t* subCategoriesCount, uint32_t* si

std::vector<settings::SubCategory> sucCategories;
int sizeSettings = settings->Length();
for (int i = 0; i < settings->Length(); i++) {
for (int i = 0; i < int(settings->Length()); i++) {
settings::SubCategory sc;

v8::Local<v8::Object> subCategoryObject = v8::Local<v8::Object>::Cast(settings->Get(i));
Expand All @@ -301,7 +301,7 @@ std::vector<char> deserializeCategory(uint32_t* subCategoriesCount, uint32_t* si

sc.paramsCount = parameters->Length();
int sizeParams = parameters->Length();
for (int j = 0; j < parameters->Length(); j++) {
for (int j = 0; j < int(parameters->Length()); j++) {
settings::Parameter param;

v8::Local<v8::Object> parameterObject = v8::Local<v8::Object>::Cast(parameters->Get(j));
Expand All @@ -322,19 +322,22 @@ std::vector<char> deserializeCategory(uint32_t* subCategoriesCount, uint32_t* si
param.currentValue.resize(strlen(*value));
memcpy(param.currentValue.data(), *value, strlen(*value));
} else if (param.type.compare("OBS_PROPERTY_INT") == 0) {
int64_t value = parameterObject->Get(v8::String::NewFromUtf8(isolate, "currentValue"))->NumberValue();
int64_t value =
int64_t(parameterObject->Get(v8::String::NewFromUtf8(isolate, "currentValue"))->NumberValue());

param.sizeOfCurrentValue = sizeof(value);
param.currentValue.resize(sizeof(value));
memcpy(param.currentValue.data(), &value, sizeof(value));
} else if (param.type.compare("OBS_PROPERTY_UINT") == 0) {
uint64_t value = parameterObject->Get(v8::String::NewFromUtf8(isolate, "currentValue"))->NumberValue();
uint64_t value =
uint64_t(parameterObject->Get(v8::String::NewFromUtf8(isolate, "currentValue"))->NumberValue());

param.sizeOfCurrentValue = sizeof(value);
param.currentValue.resize(sizeof(value));
memcpy(param.currentValue.data(), &value, sizeof(value));
} else if (param.type.compare("OBS_PROPERTY_BOOL") == 0) {
uint64_t value = parameterObject->Get(v8::String::NewFromUtf8(isolate, "currentValue"))->NumberValue();
uint64_t value =
uint64_t(parameterObject->Get(v8::String::NewFromUtf8(isolate, "currentValue"))->NumberValue());

param.sizeOfCurrentValue = sizeof(value);
param.currentValue.resize(sizeof(value));
Expand All @@ -352,7 +355,7 @@ std::vector<char> deserializeCategory(uint32_t* subCategoriesCount, uint32_t* si

if (subType.compare("OBS_COMBO_FORMAT_INT") == 0) {
int64_t value =
parameterObject->Get(v8::String::NewFromUtf8(isolate, "currentValue"))->NumberValue();
int64_t(parameterObject->Get(v8::String::NewFromUtf8(isolate, "currentValue"))->NumberValue());

param.sizeOfCurrentValue = sizeof(value);
param.currentValue.resize(sizeof(value));
Expand Down Expand Up @@ -382,8 +385,8 @@ std::vector<char> deserializeCategory(uint32_t* subCategoriesCount, uint32_t* si
buffer.insert(buffer.end(), serializedBuf.begin(), serializedBuf.end());
}

*subCategoriesCount = sucCategories.size();
*sizeStruct = buffer.size();
*subCategoriesCount = uint32_t(sucCategories.size());
*sizeStruct = uint32_t(buffer.size());

return buffer;
}
Expand Down
14 changes: 7 additions & 7 deletions obs-studio-client/source/nodeobs_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ namespace settings
*reinterpret_cast<size_t*>(buffer.data() + indexBuffer) = name.length();
indexBuffer += sizeof(size_t);
memcpy(buffer.data() + indexBuffer, name.data(), name.length());
indexBuffer += name.length();
indexBuffer += uint32_t(name.length());

*reinterpret_cast<size_t*>(buffer.data() + indexBuffer) = description.length();
indexBuffer += sizeof(size_t);
memcpy(buffer.data() + indexBuffer, description.data(), description.length());
indexBuffer += description.length();
indexBuffer += uint32_t(description.length());

*reinterpret_cast<size_t*>(buffer.data() + indexBuffer) = type.length();
indexBuffer += sizeof(size_t);
memcpy(buffer.data() + indexBuffer, type.data(), type.length());
indexBuffer += type.length();
indexBuffer += uint32_t(type.length());

*reinterpret_cast<size_t*>(buffer.data() + indexBuffer) = subType.length();
indexBuffer += sizeof(size_t);
memcpy(buffer.data() + indexBuffer, subType.data(), subType.length());
indexBuffer += subType.length();
indexBuffer += uint32_t(subType.length());

*reinterpret_cast<bool*>(buffer.data() + indexBuffer) = enabled;
indexBuffer += sizeof(bool);
Expand All @@ -58,7 +58,7 @@ namespace settings
indexBuffer += sizeof(size_t);

memcpy(buffer.data() + indexBuffer, currentValue.data(), sizeOfCurrentValue);
indexBuffer += sizeOfCurrentValue;
indexBuffer += uint32_t(sizeOfCurrentValue);

*reinterpret_cast<size_t*>(buffer.data() + indexBuffer) = sizeOfValues;
indexBuffer += sizeof(size_t);
Expand All @@ -67,7 +67,7 @@ namespace settings
indexBuffer += sizeof(size_t);

memcpy(buffer.data() + indexBuffer, values.data(), sizeOfValues);
indexBuffer += sizeOfValues;
indexBuffer += uint32_t(sizeOfValues);

return buffer;
}
Expand All @@ -90,7 +90,7 @@ namespace settings
*reinterpret_cast<size_t*>(buffer.data()) = name.length();
indexBuffer += sizeof(size_t);
memcpy(buffer.data() + indexBuffer, name.data(), name.length());
indexBuffer += name.length();
indexBuffer += uint32_t(name.length());

*reinterpret_cast<uint32_t*>(buffer.data() + indexBuffer) = paramsCount;
indexBuffer += sizeof(uint32_t);
Expand Down
8 changes: 4 additions & 4 deletions obs-studio-client/source/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ Nan::NAN_METHOD_RETURN_TYPE osn::Scene::GetItems(Nan::NAN_METHOD_ARGS_TYPE info)
if (!ValidateResponse(response))
return;

auto arr = Nan::New<v8::Array>(response.size() - 1);
auto arr = Nan::New<v8::Array>(int(response.size()) - 1);

for (size_t i = 1; i < response.size(); i++) {
osn::SceneItem* obj = new osn::SceneItem(response[i].value_union.ui64);
Nan::Set(arr, i - 1, osn::SceneItem::Store(obj));
Nan::Set(arr, uint32_t(i - 1), osn::SceneItem::Store(obj));
}

info.GetReturnValue().Set(arr);
Expand Down Expand Up @@ -387,11 +387,11 @@ Nan::NAN_METHOD_RETURN_TYPE osn::Scene::GetItemsInRange(Nan::NAN_METHOD_ARGS_TYP
if (!ValidateResponse(response))
return;

auto arr = Nan::New<v8::Array>(response.size() - 1);
auto arr = Nan::New<v8::Array>(int(response.size() - 1));

for (size_t i = 1; i < response.size(); i++) {
osn::SceneItem* obj = new osn::SceneItem(response[i].value_union.ui64);
Nan::Set(arr, i - 1, osn::SceneItem::Store(obj));
Nan::Set(arr, uint32_t(i - 1), osn::SceneItem::Store(obj));
}

info.GetReturnValue().Set(arr);
Expand Down
11 changes: 11 additions & 0 deletions obs-studio-client/source/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,19 @@

// This is from enc-amf
#if (defined _WIN32) || (defined _WIN64) // Windows

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#ifdef WINVER
#undef WINVER
#endif
#define WINVER 0x601

#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x601
#include <windows.h>

Expand Down
7 changes: 7 additions & 0 deletions obs-studio-server/source/nodeobs_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#include "util/lexer.h"

#ifdef _WIN32

#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif

#define _WIN32_WINNT 0x0502

#include <ShlObj.h>
Expand All @@ -18,7 +23,9 @@
#define getcwd _getcwd
#endif

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include <audiopolicy.h>
#include <mmdeviceapi.h>
Expand Down
Loading

0 comments on commit cafea03

Please sign in to comment.