Permalink
Browse files

working dotnet bindings addressing memory issues

  • Loading branch information...
1 parent b660082 commit 5311ae33bcfe8a33b6c9bf9fcbeacb57902f6d96 John Murphy committed Sep 28, 2012
Showing with 497 additions and 549 deletions.
  1. +33 −0 bindings/dotnet/README.txt
  2. BIN bindings/dotnet/deps/czmq/lib/czmq.lib
  3. BIN bindings/dotnet/deps/libmdp/bin/libmdp.dll
  4. BIN bindings/dotnet/deps/libmdp/lib/libmdp.lib
  5. +33 −23 bindings/dotnet/dotnet.sln
  6. +15 −13 bindings/dotnet/{zeromq.majordomo → mdpwrapper}/ReadMe.txt
  7. +19 −0 bindings/dotnet/mdpwrapper/dllmain.cpp
  8. +75 −0 bindings/dotnet/mdpwrapper/mdpwrapper.cpp
  9. +35 −0 bindings/dotnet/mdpwrapper/mdpwrapper.h
  10. +39 −33 bindings/dotnet/{zeromq.majordomo/zeromq.majordomo.vcxproj → mdpwrapper/mdpwrapper.vcxproj}
  11. +9 −17 ...otnet/{zeromq.majordomo/zeromq.majordomo.vcxproj.filters → mdpwrapper/mdpwrapper.vcxproj.filters}
  12. +4 −1 bindings/dotnet/{zeromq.majordomo/Stdafx.cpp → mdpwrapper/stdafx.cpp}
  13. +16 −0 bindings/dotnet/mdpwrapper/stdafx.h
  14. +8 −0 bindings/dotnet/mdpwrapper/targetver.h
  15. +122 −0 bindings/dotnet/zeromq.majordomo.csharp/Client.cs
  16. +3 −3 ...dotnet/{zeromq.majordomo.test.workerconsole → zeromq.majordomo.csharp}/Properties/AssemblyInfo.cs
  17. +44 −0 bindings/dotnet/zeromq.majordomo.csharp/Response.cs
  18. +11 −19 ...omq.majordomo.test.workerconsole.csproj → zeromq.majordomo.csharp/zeromq.majordomo.csharp.csproj}
  19. +0 −25 bindings/dotnet/zeromq.majordomo.test.workerconsole/Program.cs
  20. +16 −8 bindings/dotnet/zeromq.majordomo.testclient/Program.cs
  21. +9 −5 bindings/dotnet/zeromq.majordomo.testclient/zeromq.majordomo.test.clientconsole.csproj
  22. +0 −40 bindings/dotnet/zeromq.majordomo/AssemblyInfo.cpp
  23. +0 −7 bindings/dotnet/zeromq.majordomo/Stdafx.h
  24. BIN bindings/dotnet/zeromq.majordomo/app.ico
  25. BIN bindings/dotnet/zeromq.majordomo/app.rc
  26. +0 −21 bindings/dotnet/zeromq.majordomo/mdp_wrapper.cpp
  27. +0 −8 bindings/dotnet/zeromq.majordomo/mdp_wrapper.h
  28. +0 −3 bindings/dotnet/zeromq.majordomo/resource.h
  29. +0 −252 bindings/dotnet/zeromq.majordomo/zeromq.majordomo.cpp
  30. +0 −66 bindings/dotnet/zeromq.majordomo/zeromq.majordomo.h
  31. +6 −5 builds/msvc/libmdp/libmdp.vcxproj
View
@@ -0,0 +1,33 @@
+.NET Bindings for MajorDomo Client
+
+Dependencies
+-------------------------------
+mdpwrapper depends on zeromq, libmdp and czmq. The libraries and header files for these dependencies
+are in the deps directory under the solution directory.
+
+Projects
+------------------------------
+mdpwrapper is a Windows DLL that wraps libmdp so that we can use some of libmdp's opaque functions
+that would not be available to us in the managed environment.
+
+zeromq.majordomo.csharp is the assembly that provides a facade of the majordomo client. You would
+create an application include a reference to zeromq.majordomo.csharp and go to town. Note that
+libzmq.dll libmdp.dll and mdpwrapper.dll have to be in your applications search path.
+
+Usage Example:
+
+// instantiates client, sends a message and cleans up
+using( Client c = new Client( "tcp://192.168.1.7:5555" ) )
+{
+ c.Send( "my service", "I like cheese" );
+ Response r = c.Recv();
+
+ if( r != null )
+ {
+ r.Print();
+ }
+
+}
+
+zeromq.majordomo.test.clientconsole is an application to test the zeromq.majordomo.csharp assembly
+
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
@@ -1,52 +1,62 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zeromq.majordomo", "zeromq.majordomo\zeromq.majordomo.vcxproj", "{B15631F1-BD9D-4B7C-8FC2-C07E8A7E451F}"
-EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "zeromq.majordomo.test.clientconsole", "zeromq.majordomo.testclient\zeromq.majordomo.test.clientconsole.csproj", "{0B1F4A9C-6356-4E3C-B1E2-329B9832FAFF}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "zeromq.majordomo.test.workerconsole", "zeromq.majordomo.test.workerconsole\zeromq.majordomo.test.workerconsole.csproj", "{2CF539D0-BE03-4B05-BF9E-72B27E4B4A92}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "zeromq.majordomo.csharp", "zeromq.majordomo.csharp\zeromq.majordomo.csharp.csproj", "{19176FD4-132B-4F17-B50C-2D9AD4D15435}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mdpwrapper", "mdpwrapper\mdpwrapper.vcxproj", "{152BBA96-1220-4373-B993-5CD5CA151E62}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2248B071-394A-4611-B1CE-3E024EFCD41B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|Win32 = Debug|Win32
Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|Win32 = Release|Win32
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {B15631F1-BD9D-4B7C-8FC2-C07E8A7E451F}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
- {B15631F1-BD9D-4B7C-8FC2-C07E8A7E451F}.Debug|Mixed Platforms.Build.0 = Debug|Win32
- {B15631F1-BD9D-4B7C-8FC2-C07E8A7E451F}.Debug|Win32.ActiveCfg = Debug|Win32
- {B15631F1-BD9D-4B7C-8FC2-C07E8A7E451F}.Debug|Win32.Build.0 = Debug|Win32
- {B15631F1-BD9D-4B7C-8FC2-C07E8A7E451F}.Debug|x86.ActiveCfg = Debug|Win32
- {B15631F1-BD9D-4B7C-8FC2-C07E8A7E451F}.Release|Mixed Platforms.ActiveCfg = Release|Win32
- {B15631F1-BD9D-4B7C-8FC2-C07E8A7E451F}.Release|Mixed Platforms.Build.0 = Release|Win32
- {B15631F1-BD9D-4B7C-8FC2-C07E8A7E451F}.Release|Win32.ActiveCfg = Release|Win32
- {B15631F1-BD9D-4B7C-8FC2-C07E8A7E451F}.Release|Win32.Build.0 = Release|Win32
- {B15631F1-BD9D-4B7C-8FC2-C07E8A7E451F}.Release|x86.ActiveCfg = Release|Win32
+ {0B1F4A9C-6356-4E3C-B1E2-329B9832FAFF}.Debug|Any CPU.ActiveCfg = Debug|x86
{0B1F4A9C-6356-4E3C-B1E2-329B9832FAFF}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{0B1F4A9C-6356-4E3C-B1E2-329B9832FAFF}.Debug|Mixed Platforms.Build.0 = Debug|x86
{0B1F4A9C-6356-4E3C-B1E2-329B9832FAFF}.Debug|Win32.ActiveCfg = Debug|x86
{0B1F4A9C-6356-4E3C-B1E2-329B9832FAFF}.Debug|x86.ActiveCfg = Debug|x86
{0B1F4A9C-6356-4E3C-B1E2-329B9832FAFF}.Debug|x86.Build.0 = Debug|x86
+ {0B1F4A9C-6356-4E3C-B1E2-329B9832FAFF}.Release|Any CPU.ActiveCfg = Release|x86
{0B1F4A9C-6356-4E3C-B1E2-329B9832FAFF}.Release|Mixed Platforms.ActiveCfg = Release|x86
{0B1F4A9C-6356-4E3C-B1E2-329B9832FAFF}.Release|Mixed Platforms.Build.0 = Release|x86
{0B1F4A9C-6356-4E3C-B1E2-329B9832FAFF}.Release|Win32.ActiveCfg = Release|x86
{0B1F4A9C-6356-4E3C-B1E2-329B9832FAFF}.Release|x86.ActiveCfg = Release|x86
{0B1F4A9C-6356-4E3C-B1E2-329B9832FAFF}.Release|x86.Build.0 = Release|x86
- {2CF539D0-BE03-4B05-BF9E-72B27E4B4A92}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
- {2CF539D0-BE03-4B05-BF9E-72B27E4B4A92}.Debug|Mixed Platforms.Build.0 = Debug|x86
- {2CF539D0-BE03-4B05-BF9E-72B27E4B4A92}.Debug|Win32.ActiveCfg = Debug|x86
- {2CF539D0-BE03-4B05-BF9E-72B27E4B4A92}.Debug|x86.ActiveCfg = Debug|x86
- {2CF539D0-BE03-4B05-BF9E-72B27E4B4A92}.Debug|x86.Build.0 = Debug|x86
- {2CF539D0-BE03-4B05-BF9E-72B27E4B4A92}.Release|Mixed Platforms.ActiveCfg = Release|x86
- {2CF539D0-BE03-4B05-BF9E-72B27E4B4A92}.Release|Mixed Platforms.Build.0 = Release|x86
- {2CF539D0-BE03-4B05-BF9E-72B27E4B4A92}.Release|Win32.ActiveCfg = Release|x86
- {2CF539D0-BE03-4B05-BF9E-72B27E4B4A92}.Release|x86.ActiveCfg = Release|x86
- {2CF539D0-BE03-4B05-BF9E-72B27E4B4A92}.Release|x86.Build.0 = Release|x86
+ {19176FD4-132B-4F17-B50C-2D9AD4D15435}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {19176FD4-132B-4F17-B50C-2D9AD4D15435}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {19176FD4-132B-4F17-B50C-2D9AD4D15435}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {19176FD4-132B-4F17-B50C-2D9AD4D15435}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {19176FD4-132B-4F17-B50C-2D9AD4D15435}.Debug|Win32.ActiveCfg = Debug|Any CPU
+ {19176FD4-132B-4F17-B50C-2D9AD4D15435}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {19176FD4-132B-4F17-B50C-2D9AD4D15435}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {19176FD4-132B-4F17-B50C-2D9AD4D15435}.Release|Any CPU.Build.0 = Release|Any CPU
+ {19176FD4-132B-4F17-B50C-2D9AD4D15435}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {19176FD4-132B-4F17-B50C-2D9AD4D15435}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {19176FD4-132B-4F17-B50C-2D9AD4D15435}.Release|Win32.ActiveCfg = Release|Any CPU
+ {19176FD4-132B-4F17-B50C-2D9AD4D15435}.Release|x86.ActiveCfg = Release|Any CPU
+ {152BBA96-1220-4373-B993-5CD5CA151E62}.Debug|Any CPU.ActiveCfg = Debug|Win32
+ {152BBA96-1220-4373-B993-5CD5CA151E62}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
+ {152BBA96-1220-4373-B993-5CD5CA151E62}.Debug|Mixed Platforms.Build.0 = Debug|Win32
+ {152BBA96-1220-4373-B993-5CD5CA151E62}.Debug|Win32.ActiveCfg = Debug|Win32
+ {152BBA96-1220-4373-B993-5CD5CA151E62}.Debug|Win32.Build.0 = Debug|Win32
+ {152BBA96-1220-4373-B993-5CD5CA151E62}.Debug|x86.ActiveCfg = Debug|Win32
+ {152BBA96-1220-4373-B993-5CD5CA151E62}.Release|Any CPU.ActiveCfg = Release|Win32
+ {152BBA96-1220-4373-B993-5CD5CA151E62}.Release|Mixed Platforms.ActiveCfg = Release|Win32
+ {152BBA96-1220-4373-B993-5CD5CA151E62}.Release|Mixed Platforms.Build.0 = Release|Win32
+ {152BBA96-1220-4373-B993-5CD5CA151E62}.Release|Win32.ActiveCfg = Release|Win32
+ {152BBA96-1220-4373-B993-5CD5CA151E62}.Release|Win32.Build.0 = Release|Win32
+ {152BBA96-1220-4373-B993-5CD5CA151E62}.Release|x86.ActiveCfg = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -1,38 +1,40 @@
========================================================================
- DYNAMIC LINK LIBRARY : zeromq.majordomo Project Overview
+ DYNAMIC LINK LIBRARY : mdpwrapper Project Overview
========================================================================
-AppWizard has created this zeromq.majordomo DLL for you.
+AppWizard has created this mdpwrapper DLL for you.
This file contains a summary of what you will find in each of the files that
-make up your zeromq.majordomo application.
+make up your mdpwrapper application.
-zeromq.majordomo.vcxproj
- This is the main project file for VC++ projects generated using an Application Wizard.
- It contains information about the version of Visual C++ that generated the file, and
+
+mdpwrapper.vcxproj
+ This is the main project file for VC++ projects generated using an Application Wizard.
+ It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.
-zeromq.majordomo.vcxproj.filters
+mdpwrapper.vcxproj.filters
This is the filters file for VC++ projects generated using an Application Wizard.
It contains information about the association between the files in your project
and the filters. This association is used in the IDE to show grouping of files with
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
"Source Files" filter).
-zeromq.majordomo.cpp
+mdpwrapper.cpp
This is the main DLL source file.
-zeromq.majordomo.h
- This file contains a class declaration.
+/////////////////////////////////////////////////////////////////////////////
+Other standard files:
-AssemblyInfo.cpp
- Contains custom attributes for modifying assembly metadata.
+StdAfx.h, StdAfx.cpp
+ These files are used to build a precompiled header (PCH) file
+ named mdpwrapper.pch and a precompiled types file named StdAfx.obj.
/////////////////////////////////////////////////////////////////////////////
Other notes:
-AppWizard uses "TODO:" to indicate parts of the source code you
+AppWizard uses "TODO:" comments to indicate parts of the source code you
should add to or customize.
/////////////////////////////////////////////////////////////////////////////
@@ -0,0 +1,19 @@
+// dllmain.cpp : Defines the entry point for the DLL application.
+#include "stdafx.h"
+
+BOOL APIENTRY DllMain( HMODULE hModule,
+ DWORD ul_reason_for_call,
+ LPVOID lpReserved
+ )
+{
+ switch (ul_reason_for_call)
+ {
+ case DLL_PROCESS_ATTACH:
+ case DLL_THREAD_ATTACH:
+ case DLL_THREAD_DETACH:
+ case DLL_PROCESS_DETACH:
+ break;
+ }
+ return TRUE;
+}
+
@@ -0,0 +1,75 @@
+// mdpwrapper.cpp : Defines the exported functions for the DLL application.
+//
+
+#include "stdafx.h"
+#include "mdpwrapper.h"
+
+
+
+
+mdp_client_t * client_new (char *broker, int verbose)
+{
+ return mdp_client_new( broker, verbose );
+}
+
+void client_destroy (mdp_client_t **self_p)
+{
+ mdp_client_destroy( self_p );
+}
+
+void client_set_timeout (mdp_client_t *self, int timeout)
+{
+ mdp_client_set_timeout( self, timeout );
+}
+
+
+int client_setsockopt (mdp_client_t *self, int option, const void *optval, size_t optvallen)
+{
+ return mdp_client_setsockopt( self, option, optval, optvallen );
+}
+
+int client_getsockopt (mdp_client_t *self, int option, void *optval, size_t *optvallen)
+{
+ return mdp_client_getsockopt( self, option, optval, optvallen );
+}
+
+void client_send_data (mdp_client_t *self, char *service, char *data, int size )
+{
+ zmsg_t* zmsg = zmsg_new();
+ zmsg_addmem( zmsg, data, size );
+ mdp_client_send( self, service, &zmsg );
+}
+
+
+void client_send_string( mdp_client_t *self, char *service, char *msg )
+{
+ zmsg_t* zmsg = zmsg_new();
+ zmsg_addstr( zmsg, msg );
+ mdp_client_send( self, service, &zmsg );
+}
+
+
+void client_recv (mdp_client_t *self, char **service_p, char **response_p )
+{
+ *response_p = NULL;
+ zmsg_t* reply = mdp_client_recv( self, service_p );
+ if( reply ) {
+ size_t buffer_size = zmsg_content_size( reply ) + 1;
+ *response_p = (char*)malloc( buffer_size );
+ memset( *response_p, 0, buffer_size );
+
+ char* p = *response_p;
+
+ while(true) {
+ zframe_t* frame = zmsg_pop( reply );
+ if( frame ) {
+ size_t frame_size = zframe_size(frame);
+ memcpy( p, zframe_data(frame), frame_size );
+ p += frame_size;
+ zframe_destroy(&frame);
+ } else {
+ break;
+ }
+ }
+ }
+}
@@ -0,0 +1,35 @@
+// The following ifdef block is the standard way of creating macros which make exporting
+// from a DLL simpler. All files within this DLL are compiled with the MDPWRAPPER_EXPORTS
+// symbol defined on the command line. This symbol should not be defined on any project
+// that uses this DLL. This way any other project whose source files include this file see
+// MDPWRAPPER_API functions as being imported from a DLL, whereas this DLL sees symbols
+// defined with this macro as being exported.
+#ifdef MDPWRAPPER_EXPORTS
+#define MDPWRAPPER_API __declspec(dllexport)
+#else
+#define MDPWRAPPER_API __declspec(dllimport)
+#endif
+
+/*
+class MDPWRAPPER_API Cmdpwrapper {
+public:
+ Cmdpwrapper(void);
+ // TODO: add your methods here.
+};
+
+extern MDPWRAPPER_API int nmdpwrapper;
+*/
+#include <mdp.h>
+
+//MDPWRAPPER_API int fnmdpwrapper(void);
+
+
+
+MDPWRAPPER_API mdp_client_t * client_new (char *broker, int verbose);
+MDPWRAPPER_API void client_destroy (mdp_client_t **self_p);
+MDPWRAPPER_API void client_set_timeout (mdp_client_t *self, int timeout);
+MDPWRAPPER_API int client_setsockopt (mdp_client_t *self, int option, const void *optval, size_t optvallen);
+MDPWRAPPER_API int client_getsockopt (mdp_client_t *self, int option, void *optval, size_t *optvallen);
+MDPWRAPPER_API void client_send_data (mdp_client_t *self, char *service, char *data, int size );
+MDPWRAPPER_API void client_send_string (mdp_client_t *self, char *service, char *msg );
+MDPWRAPPER_API void client_recv (mdp_client_t *self, char **service_p, char **response_p);
Oops, something went wrong.

0 comments on commit 5311ae3

Please sign in to comment.