linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #06385
[Branch ~dcplusplus-team/dcpp-plugin-sdk-c/trunk] Rev 3: add a skeleton & a makefile
------------------------------------------------------------
revno: 3
committer: poy <poy@xxxxxxxxxx>
branch nick: dcpp-plugin-sdk-c
timestamp: Thu 2012-12-27 15:49:19 +0100
message:
add a skeleton & a makefile
added:
projects/
projects/make/
projects/make/Makefile
src/
src/Plugin.c
src/Plugin.h
src/main.c
src/resource.h
src/resource.rc
src/stdafx.c
src/stdafx.h
src/version.h
modified:
pluginsdk/Config.c
pluginsdk/Config.h
--
lp:dcpp-plugin-sdk-c
https://code.launchpad.net/~dcplusplus-team/dcpp-plugin-sdk-c/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcpp-plugin-sdk-c.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcpp-plugin-sdk-c/trunk/+edit-subscription
=== modified file 'pluginsdk/Config.c'
--- pluginsdk/Config.c 2012-11-15 18:29:04 +0000
+++ pluginsdk/Config.c 2012-12-27 14:49:19 +0000
@@ -23,15 +23,21 @@
#include <stdlib.h>
#include <string.h>
-DCConfigPtr config = NULL;
+DCConfigPtr config;
+char* guid;
-Bool DCAPI init_cfg(DCCorePtr core) {
+Bool DCAPI init_cfg(DCCorePtr core, const char* pluginGuid) {
config = (DCConfigPtr)core->query_interface(DCINTF_CONFIG, DCINTF_CONFIG_VER);
+
+ int len = strlen(pluginGuid) + 1;
+ guid = (char*)memset(malloc(len), 0, len);
+ strncpy(guid, pluginGuid, len);
+
return config ? True : False;
}
char* DCAPI get_cfg(const char* name) {
- ConfigStrPtr val = (ConfigStrPtr)config->get_cfg(PLUGIN_GUID, name, CFG_TYPE_STRING);
+ ConfigStrPtr val = (ConfigStrPtr)config->get_cfg(guid, name, CFG_TYPE_STRING);
int len = strlen(val->value) + 1;
char* value = (char*)memset(malloc(len), 0, len);
@@ -42,7 +48,7 @@
}
int32_t DCAPI get_cfg_int(const char* name) {
- ConfigIntPtr val = (ConfigIntPtr)config->get_cfg(PLUGIN_GUID, name, CFG_TYPE_INT);
+ ConfigIntPtr val = (ConfigIntPtr)config->get_cfg(guid, name, CFG_TYPE_INT);
int32_t value = val->value;
config->release((ConfigValuePtr)val);
@@ -51,7 +57,7 @@
}
int64_t DCAPI get_cfg_int64(const char* name) {
- ConfigInt64Ptr val = (ConfigInt64Ptr)config->get_cfg(PLUGIN_GUID, name, CFG_TYPE_INT64);
+ ConfigInt64Ptr val = (ConfigInt64Ptr)config->get_cfg(guid, name, CFG_TYPE_INT64);
int64_t value = val->value;
config->release((ConfigValuePtr)val);
@@ -65,7 +71,7 @@
val.type = CFG_TYPE_STRING;
val.value = value;
- config->set_cfg(PLUGIN_GUID, name, (ConfigValuePtr)&val);
+ config->set_cfg(guid, name, (ConfigValuePtr)&val);
}
void DCAPI set_cfg_int(const char* name, int32_t value) {
@@ -74,7 +80,7 @@
val.type = CFG_TYPE_INT;
val.value = value;
- config->set_cfg(PLUGIN_GUID, name, (ConfigValuePtr)&val);
+ config->set_cfg(guid, name, (ConfigValuePtr)&val);
}
void DCAPI set_cfg_int64(const char* name, int64_t value) {
@@ -83,7 +89,7 @@
val.type = CFG_TYPE_INT64;
val.value = value;
- config->set_cfg(PLUGIN_GUID, name, (ConfigValuePtr)&val);
+ config->set_cfg(guid, name, (ConfigValuePtr)&val);
}
ConfigValuePtr DCAPI get_core_cfg(const char* name) { return config->get_cfg("CoreSetup", name, CFG_TYPE_UNKNOWN); }
=== modified file 'pluginsdk/Config.h'
--- pluginsdk/Config.h 2012-11-15 18:29:04 +0000
+++ pluginsdk/Config.h 2012-12-27 14:49:19 +0000
@@ -23,7 +23,7 @@
#include <pluginsdk/PluginDefs.h>
-Bool DCAPI init_cfg(DCCorePtr core);
+Bool DCAPI init_cfg(DCCorePtr core, const char* pluginGuid);
char* DCAPI get_cfg(const char* name);
int32_t DCAPI get_cfg_int(const char* name);
=== added directory 'projects'
=== added directory 'projects/make'
=== added file 'projects/make/Makefile'
--- projects/make/Makefile 1970-01-01 00:00:00 +0000
+++ projects/make/Makefile 2012-12-27 14:49:19 +0000
@@ -0,0 +1,46 @@
+# This is a rudimentary Makefile that compiles files from the pluginsdk & src directories into a
+# shared library. Adapt to your needs.
+
+TARGET = MyPlugin # Rename to your plugin's name.
+
+CPPFLAGS += -march=i686 # Remove if your target architecture is not x86.
+
+CPPFLAGS += -Wall -Wextra -g -pipe -O3 -I../../
+LINKFLAGS += -static-libgcc -g -O3 -shared -Wl,--add-stdcall-alias
+
+VPATH = ../../
+
+OUTPUT_DIR = build
+OUTPUT_OPTION = -o $(OUTPUT_DIR)/$@
+
+OBJS = \
+ pluginsdk/Config.o \
+ src/main.o \
+ src/Plugin.o \
+ src/stdafx.o
+
+ifeq ($(OS), Windows_NT)
+ CPPFLAGS += -D_WIN32_WINNT=0x502 -DWINVER=0x502 -D_WIN32_IE=0x600 \
+ -DNOMINMAX -DSTRICT -DWIN32_LEAN_AND_MEAN \
+ -DWIN32 -D_WIN32 -DUNICODE -D_UNICODE
+ OBJS += src/resource.o
+ LIBEXT = .dll
+else
+ LIBEXT = .so
+endif
+
+all: \
+ ensure-dirs \
+ $(TARGET)
+
+$(TARGET): $(OBJS)
+ cd $(OUTPUT_DIR); $(CC) $^ $(LINKFLAGS) -o $@$(LIBEXT)
+
+ensure-dirs:
+ mkdir -p $(OUTPUT_DIR)/pluginsdk $(OUTPUT_DIR)/src
+
+src/resource.o:
+ windres ../../src/resource.rc $(OUTPUT_OPTION)
+
+clear:
+ $(RM) -r $(OUTPUT_DIR)
=== added directory 'src'
=== added file 'src/Plugin.c'
--- src/Plugin.c 1970-01-01 00:00:00 +0000
+++ src/Plugin.c 2012-12-27 14:49:19 +0000
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2012 Jacek Sieka, arnetheduck on gmail point com
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "stdafx.h"
+#include "Plugin.h"
+
+/* Include plugin SDK helpers from the pluginsdk directory. */
+#include <pluginsdk/Config.h>
+
+/* Variables */
+DCCorePtr dcpp;
+
+DCHooksPtr hooks;
+DCLogPtr logging;
+
+/* Hook subscription store - set this to the amount of hooks you require. */
+#define HOOKS_SUBSCRIBED 0
+
+const char* hookGuids[HOOKS_SUBSCRIBED] = {
+ /* List hook identifiers here. Check pluginsdk/PluginDefs.h for available hooks. */
+};
+
+DCHOOK hookFuncs[HOOKS_SUBSCRIBED] = {
+ /* List event handlers here (should be in sync with the hookGuids list). */
+};
+
+subsHandle subs[HOOKS_SUBSCRIBED];
+
+/* Forward declarations */
+Bool onLoad(DCCorePtr core, Bool install);
+Bool onUnload();
+
+/* Plugin main function */
+Bool DCAPI pluginMain(PluginState state, DCCorePtr core, dcptr_t pData) {
+ switch(state) {
+ case ON_INSTALL:
+ case ON_LOAD:
+ {
+ return onLoad(core, state == ON_INSTALL);
+ }
+
+ case ON_UNINSTALL:
+ case ON_UNLOAD:
+ {
+ return onUnload();
+ }
+
+ default:
+ {
+ return False;
+ }
+ }
+}
+
+Bool onLoad(DCCorePtr core, Bool install) {
+ /* Initialization phase. Initiate plugin SDK interfaces here. */
+
+ uint32_t i = 0;
+
+ dcpp = core;
+
+ hooks = (DCHooksPtr)core->query_interface(DCINTF_HOOKS, DCINTF_HOOKS_VER);
+ logging = (DCLogPtr)core->query_interface(DCINTF_LOGGING, DCINTF_LOGGING_VER);
+
+ if(!init_cfg(core, PLUGIN_GUID) || !hooks || !logging) {
+ return False;
+ }
+
+ if(install) {
+ /* This only executes when the plugin has been installed for the first time. */
+ }
+
+ /* Register events. */
+ while(i < HOOKS_SUBSCRIBED) {
+ subs[i] = hooks->bind_hook(hookGuids[i], hookFuncs[i], NULL);
+ ++i;
+ }
+
+ /* Start the plugin logic here. */
+
+ return True;
+}
+
+Bool onUnload() {
+ uint32_t i = 0;
+ while(i < HOOKS_SUBSCRIBED) {
+ if(subs[i]) hooks->release_hook(subs[i]);
+ ++i;
+ }
+ return True;
+}
=== added file 'src/Plugin.h'
--- src/Plugin.h 1970-01-01 00:00:00 +0000
+++ src/Plugin.h 2012-12-27 14:49:19 +0000
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2012 Jacek Sieka, arnetheduck on gmail point com
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef PLUGIN_PLUGIN_H
+#define PLUGIN_PLUGIN_H
+
+/* Plugin main function */
+Bool DCAPI pluginMain(PluginState state, DCCorePtr core, dcptr_t pData);
+
+#endif
=== added file 'src/main.c'
--- src/main.c 1970-01-01 00:00:00 +0000
+++ src/main.c 2012-12-27 14:49:19 +0000
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2012 Jacek Sieka, arnetheduck on gmail point com
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "stdafx.h"
+#include "Plugin.h"
+#include "version.h"
+
+/* Plugin loader */
+DCEXP DCMAIN DCAPI pluginInit(MetaDataPtr info) {
+ info->name = PLUGIN_NAME;
+ info->author = PLUGIN_AUTHOR;
+ info->description = PLUGIN_DESC;
+ info->version = PLUGIN_VERSION;
+ info->web = PLUGIN_WEB;
+ info->apiVersion = DCAPI_CORE_VER;
+ info->guid = PLUGIN_GUID;
+
+ return &pluginMain;
+}
+
+#ifdef _WIN32
+BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
+ UNREFERENCED_PARAMETER(hinstDLL);
+ UNREFERENCED_PARAMETER(fdwReason);
+ UNREFERENCED_PARAMETER(lpvReserved);
+ return TRUE;
+}
+#endif
=== added file 'src/resource.h'
--- src/resource.h 1970-01-01 00:00:00 +0000
+++ src/resource.h 2012-12-27 14:49:19 +0000
@@ -0,0 +1,16 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by resource.rc
+//
+#define VERSION_INFO 1
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 102
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1002
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
=== added file 'src/resource.rc'
--- src/resource.rc 1970-01-01 00:00:00 +0000
+++ src/resource.rc 2012-12-27 14:49:19 +0000
@@ -0,0 +1,100 @@
+// Microsoft Visual C++ generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "afxres.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (United States) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE
+BEGIN
+ "#include ""afxres.h""\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+VERSION_INFO VERSIONINFO
+ FILEVERSION 1,0,0,0
+ PRODUCTVERSION 1,0,0,0
+ FILEFLAGSMASK 0x17L
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "080004b0"
+ BEGIN
+ VALUE "Comments", "..."
+ VALUE "FileDescription", "..."
+ VALUE "FileVersion", "1, 0, 0, 0"
+ VALUE "InternalName", "..."
+ VALUE "LegalCopyright", "..."
+ VALUE "OriginalFilename", "..."
+ VALUE "ProductName", "..."
+ VALUE "ProductVersion", "1, 0, 0, 0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x800, 1200
+ END
+END
+
+#endif // English (United States) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
=== added file 'src/stdafx.c'
--- src/stdafx.c 1970-01-01 00:00:00 +0000
+++ src/stdafx.c 2012-12-27 14:49:19 +0000
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2012 Jacek Sieka, arnetheduck on gmail point com
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "stdafx.h"
=== added file 'src/stdafx.h'
--- src/stdafx.h 1970-01-01 00:00:00 +0000
+++ src/stdafx.h 2012-12-27 14:49:19 +0000
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2012 Jacek Sieka, arnetheduck on gmail point com
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef PLUGIN_STDAFX_H
+#define PLUGIN_STDAFX_H
+
+#ifdef _WIN32
+
+#include <windows.h>
+#include <tchar.h>
+
+#else
+
+#include <unistd.h>
+
+#endif
+
+#include <pluginsdk/PluginDefs.h>
+
+#include "version.h"
+
+#endif
=== added file 'src/version.h'
--- src/version.h 1970-01-01 00:00:00 +0000
+++ src/version.h 2012-12-27 14:49:19 +0000
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2012 Jacek Sieka, arnetheduck on gmail point com
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* Information about the plugin - fill this out! Don't forget to edit the resource file as well. */
+
+#error Version information not set! Remove this error once you have filled version.h and the resource file.
+
+#ifndef PLUGIN_VERSION_H
+#define PLUGIN_VERSION_H
+
+/* UUID/GUID for this plugin project */
+#define PLUGIN_GUID "..."
+
+/* Name of the plugin */
+#define PLUGIN_NAME "..."
+
+/* Author of the plugin */
+#define PLUGIN_AUTHOR "..."
+
+/* Short description of the plugin */
+#define PLUGIN_DESC "..."
+
+/* Version of the plugin (note: not API version) */
+#define PLUGIN_VERSION 1.0
+
+/* Plugin website, set to "N/A" if none */
+#define PLUGIN_WEB "N/A"
+
+#endif