Pārlūkot izejas kodu

Update template plugin to use char constants and static log function

PatTheMav 2 gadi atpakaļ
vecāks
revīzija
c59559540c
3 mainītis faili ar 61 papildinājumiem un 12 dzēšanām
  1. 5 6
      src/plugin-main.c
  2. 39 0
      src/plugin-support.c.in
  3. 17 6
      src/plugin-support.h

+ 5 - 6
src/plugin-main.c

@@ -17,20 +17,19 @@ with this program. If not, see <https://www.gnu.org/licenses/>
 */
 
 #include <obs-module.h>
-
-#include "plugin-macros.generated.h"
+#include <plugin-support.h>
 
 OBS_DECLARE_MODULE()
 OBS_MODULE_USE_DEFAULT_LOCALE(PLUGIN_NAME, "en-US")
 
 bool obs_module_load(void)
 {
-	blog(LOG_INFO, "plugin loaded successfully (version %s)",
-	     PLUGIN_VERSION);
+	obs_log(LOG_INFO, "plugin loaded successfully (version %s)",
+		PLUGIN_VERSION);
 	return true;
 }
 
-void obs_module_unload()
+void obs_module_unload(void)
 {
-	blog(LOG_INFO, "plugin unloaded");
+	obs_log(LOG_INFO, "plugin unloaded");
 }

+ 39 - 0
src/plugin-support.c.in

@@ -0,0 +1,39 @@
+/*
+Plugin Name
+Copyright (C) <Year> <Developer> <Email Address>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <https://www.gnu.org/licenses/>
+*/
+
+#include <plugin-support.h>
+
+const char *PLUGIN_NAME = "@CMAKE_PROJECT_NAME@";
+const char *PLUGIN_VERSION = "@CMAKE_PROJECT_VERSION@";
+
+void obs_log(int log_level, const char *format, ...)
+{
+    size_t length = 4 + strlen(PLUGIN_NAME) + strlen(format);
+
+    char *template = malloc(length + 1);
+
+    snprintf(template, length, "[%s] %s", PLUGIN_NAME, format);
+
+    va_list(args);
+
+    va_start(args, format);
+    blogva(log_level, template, args);
+    va_end(args);
+
+    free(template);
+}

+ 17 - 6
src/plugin-macros.h.in → src/plugin-support.h

@@ -16,12 +16,23 @@ You should have received a copy of the GNU General Public License along
 with this program. If not, see <https://www.gnu.org/licenses/>
 */
 
-#ifndef PLUGINNAME_H
-#define PLUGINNAME_H
+#pragma once
 
-#define PLUGIN_NAME "@CMAKE_PROJECT_NAME@"
-#define PLUGIN_VERSION "@CMAKE_PROJECT_VERSION@"
+#ifdef __cplusplus
+extern "C" {
+#endif
 
-#define blog(level, msg, ...) blog(level, "[" PLUGIN_NAME "] " msg, ##__VA_ARGS__)
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
 
-#endif // PLUGINNAME_H
+extern const char *PLUGIN_NAME;
+extern const char *PLUGIN_VERSION;
+
+void obs_log(int log_level, const char *format, ...);
+extern void blogva(int log_level, const char *format, va_list args);
+
+#ifdef __cplusplus
+}
+#endif