Skip to content

Commit

Permalink
Add 'destroy' method to service classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mhoyer-streamlabs committed Mar 5, 2025
1 parent c28ea64 commit 6d6bd9c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions js/module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ export declare function getSourcesSize(sourcesNames: string[]): ISourceSize[];
export interface IServiceFactory {
types(): string[];
create(id: string, name: string, settings?: ISettings): IService;
destroy(stream: IService): void;
legacySettings: IService;
}
export interface IService {
Expand Down
1 change: 1 addition & 0 deletions js/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,7 @@ export function getSourcesSize(sourcesNames: string[]): ISourceSize[] {
export interface IServiceFactory {
types(): string[];
create(id: string, name: string, settings?: ISettings): IService;
destroy(stream: IService): void;
legacySettings: IService;
}
/**
Expand Down
20 changes: 19 additions & 1 deletion obs-studio-client/source/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Napi::Object osn::Service::Init(Napi::Env env, Napi::Object exports)
Napi::HandleScope scope(env);
Napi::Function func = DefineClass(
env, "Service",
{StaticMethod("types", &osn::Service::Types), StaticMethod("create", &osn::Service::Create), InstanceMethod("update", &osn::Service::Update),
{StaticMethod("types", &osn::Service::Types), StaticMethod("destroy", &osn::Service::Destroy), StaticMethod("create", &osn::Service::Create),
InstanceMethod("update", &osn::Service::Update),

InstanceAccessor("name", &osn::Service::GetName, nullptr), InstanceAccessor("properties", &osn::Service::GetProperties, nullptr),
InstanceAccessor("settings", &osn::Service::GetSettings, nullptr),
Expand Down Expand Up @@ -127,6 +128,23 @@ Napi::Value osn::Service::Create(const Napi::CallbackInfo &info)
return instance;
}

void osn::Service::Destroy(const Napi::CallbackInfo &info)
{
if (info.Length() != 1)
return;

auto service = Napi::ObjectWrap<osn::Service>::Unwrap(info[0].ToObject());

auto conn = GetConnection(info);
if (!conn)
return;

std::vector<ipc::value> response = conn->call_synchronous_helper("Service", "Destroy", {ipc::value(service->uid)});

if (!ValidateResponse(info, response))
return;
}

Napi::Value osn::Service::GetName(const Napi::CallbackInfo &info)
{
auto conn = GetConnection(info);
Expand Down
1 change: 1 addition & 0 deletions obs-studio-client/source/service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Service : public Napi::ObjectWrap<osn::Service> {

static Napi::Value Types(const Napi::CallbackInfo &info);
static Napi::Value Create(const Napi::CallbackInfo &info);
static void Destroy(const Napi::CallbackInfo &info);

Napi::Value GetName(const Napi::CallbackInfo &info);
Napi::Value GetProperties(const Napi::CallbackInfo &info);
Expand Down
16 changes: 16 additions & 0 deletions obs-studio-server/source/osn-service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void osn::Service::Register(ipc::server &srv)
std::make_shared<ipc::function>("Create", std::vector<ipc::type>{ipc::type::String, ipc::type::String, ipc::type::String}, Create));
cls->register_function(std::make_shared<ipc::function>(
"Create", std::vector<ipc::type>{ipc::type::String, ipc::type::String, ipc::type::String, ipc::type::String}, Create));
cls->register_function(std::make_shared<ipc::function>("Destroy", std::vector<ipc::type>{ipc::type::UInt64}, Destroy));
cls->register_function(std::make_shared<ipc::function>("CreatePrivate", std::vector<ipc::type>{ipc::type::String, ipc::type::String}, CreatePrivate));
cls->register_function(std::make_shared<ipc::function>("CreatePrivate", std::vector<ipc::type>{ipc::type::String, ipc::type::String, ipc::type::String},
CreatePrivate));
Expand Down Expand Up @@ -93,6 +94,21 @@ void osn::Service::Create(void *data, const int64_t id, const std::vector<ipc::v
AUTO_DEBUG;
}

void osn::Service::Destroy(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval)
{
obs_service_t *service = static_cast<obs_service_t *>(osn::Service::Manager::GetInstance().find(args[0].value_union.ui64));
if (!service) {
PRETTY_ERROR_RETURN(ErrorCode::InvalidReference, "Service reference is not valid.");
}

osn::Service::Manager::GetInstance().free(service);

obs_service_release(service);

rval.push_back(ipc::value((uint64_t)ErrorCode::Ok));
AUTO_DEBUG;
}

void osn::Service::CreatePrivate(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval)
{
std::string serviceId, name;
Expand Down
1 change: 1 addition & 0 deletions obs-studio-server/source/osn-service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Service {

static void GetTypes(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval);
static void Create(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval);
static void Destroy(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval);
static void CreatePrivate(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval);
static void GetName(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval);
static void GetProperties(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval);
Expand Down

0 comments on commit 6d6bd9c

Please sign in to comment.