I got a very strange request from one of my customers (at least according to my current knowledge). I have to build an iOS framework, which main purpose is to wrap a C/C++ library with Obj-C code, to hide some of its general API and expose only what my customer want me to expose via Obj-C. Now, here comes the tricky part. This framework is going to be a dependency for an application (objects/methods/functions/whatever should be accessible from , i.e. view controllers) and for another framework. Is it possible to build this framework in a way that expose only part of an API to an application and part of API to another framework which is going to use it internally?
According to my knowledge it is impossible and framework can expose only one API, which is common to every possible consumer/user. However my knowledge might not be complete in this topic.
Additional question: can I expose both Obj-C and C API from a single framework. I assume I can, but just want to make sure.
Please don't ask about rationale behind this idea. This is a requirement I got and have to investigate so I can't provide any sensible justification at the moment.
Thanks!
Related
We have a lot of business logic written in cross-platform C++. We want to write cross-platform UI for our application and use this business logic to create whole cross-platfrom application.
Is it possible to expose native module purely written in C++ to react-native?
We don't want to create wrappers around C++ code in native language (Java or Objective-C). Such wrappers will add more complexity it will make debugging and investigation much harder.
I am also looking for a way to do this directly in C++ without writing JNI for Android and Obj-C for iOS. I have found the CxxNativeModule class in the react native source. See the sample implementation SampleCxxModule.
The last thing to figure out is how to register that module in C++. In the JNI for React Native Android, implementation of NativeModule says
NativeModules whose implementation is written in C++ must not provide
any Java code (so they can be reused on other platforms), and instead
should register themselves using CxxModuleWrapper.
Then implementation of CxxModuleWrapper says
This does nothing interesting, except avoid breaking existing code.
So, this may help you get started. The last thing to figure out is how to register a CxxNativeModule so that it can be used in JS.
It seems as though you would need to find the code which is os dependent and write different versions of this code for different operating systems.
Here is a link which suggests how this might be done:
How do I check OS with a preprocessor directive?
I intend to put/get file to/from an iRODS server. iRODS provides well documented JAVA and PHP APIs, however I'm looking for a C/C++ library providing such functions.
Are there libraries or examples of code I could use ?
Not exactly what you've requested, but you might be interested in Baton, which uses the iRODS C API, and has had a lot of work put into it, so you might be able to use it as-is, depending on your use case, rather than writing your own from scratch. Failing that, it provides a lot of examples of using the API.
If you have reasons that you must write your own, then in 4.x the the iRODS docs for the C API are much improved from the earlier 3.3.1 code path.
Good luck and do try the mailing list as a previous commenter mentioned - the developers respond often.
I want to write a native application that can be extended with plugins, perferabily in the form of dynamic libraries. I have an idea of what to do, but I would like some ideas, especially best practice tips on what to do and not to do. I worked with similar things on java and php, so I hope I don't bring any bad habits in to my C++.
I'm thinking of allowing developers to implement certain functions like "on_recieve_data(App* app, void* data)" and my application will load all the plugins and call their on_recieve_data function with a pointer to itself (dlsym?).
There are a few things that I consider very important for plugins:
Language support
If you want to reach the most number of platforms/languages/compilers then you should write the plugin interface in C and not in C++. The plugin developers can still write their functions in C++, of course, it is just the interface that is C. The problem is that each C++ compiler mangles symbol names in its own way, so if you use C++ you will be forcing plugin developers to use the same compilers and tools that you use. On the other side, there is only one way to export C symbols, so using a C interface for the plugin will allow developers to pick whatever tools they like, and as long as they can produce standard .so/.dll libraries they'll be fine.
Memory allocation
In some platforms there are problems when memory allocated by the application is released by a DLL or viceversa. If the plugin has functions that are supposed to allocate memory, then make sure you also require the plugin to provide a corresponding function to release that memory. Likewise, if the plugin can call a function in the application to allocate memory, you should also expose a release function for that memory.
Versioning
It is likely that you will have to revise the plugin API after plugins have been written. So your application needs to be prepared to load plugins developed for an older version. You should require an 'init' function in the plugin that the application calls to determine what version of the API the plugin implements and any other information the app might need to know, like the plugin type (if there are different types), what is implemented and what isn't, etc.
Also you have to be very careful when you have to revise the plugin API. You can't change existing functions, since that would break older plugins. Instead you will need to add alternative versions of those functions that have the improvements. Then the problem comes of how to name the new version of an existing function. Typically they'll get the same name plus some suffix ('Ex', a number, etc.). I haven't seen this problem solved in a way that I like.
Likewise, you have to take precautions for structures that are passed between the application and plugins. A common approach is to make the first member of all structures the size of the structure. This works as sort of a versioning mechanism, so that the application can determine what the structure looks like from its size.
Here are a few links that might be of interest:
C-Pluff, a general purpose plug-in framework in C (MIT license)
lighttpd's plugin.h header file
This page has a discussion on how to implement a plugin architecture under Mac OS X, including a short overview of a how to create a C interface for plugins.
Blender is an interesting one. The application is written in C++, but plugins are written in Python. Not a bad idea really, it makes it a lot easier for developer to write plugins.
There are plenty of applications written in scripting languages that support plugins (Wordpress, Drupal, Django, and many more). You can look at any of those that are closer to the kind of application you are writing for ideas.
I believe that this post -> Design Pattern for implementing plugins in your application? does answer your question I guess. It has a lot of refernce for plugin model.
Perhapse, the Eclipse architecture can serve as example:
http://www.eclipse.org/articles/Article-Plug-in-architecture/plugin_architecture.html
I'm pretty there is a book from Eclipse's creator, but I can't remember neither the author nor the name of the book.
I'm about to write a program in C++, but I'm unsure as to how to go about it. I want to create a program that can be used with a command line frontend but also a GUI frontend as I don't want to bind a user to a specific interface such as a widget toolkit for dependencies' sake.
How would be the best way to do this? I know some programs like RSync and SSH have frontends in GUIs, but I'm not sure how this is done. Wouldn't it be hacky to have a program that just uses system() to run it all while having a pretty GUI?
You implement your program's algorithms in a library, carefully avoiding any UI stuff. The API to your algorithms is specified in header files.
Then you can write several applications that use this library, one implementing a GUI front end and one a command line interface. They include the headers and compile against the API, and you link the library to it.
Be careful to not to compile the library and the GUI with inconsistent settings.
IME the separation of algorithms from UI can be achieved best when you first implement a command line UI. You might have to employ callbacks for that separation.
Without knowing any other requirements, the simplest answer is just to compile your "backend" as a library, and then link your various "frontends" against it.
More complex answers involve setting your backend up as a daemon/server.
You shouldn't need system-calls to do any of this (unless you have very specific requirements).
You can inspire yourself on the MVC design pattern. The differing front-ends are the views on your model-controller. The controller can be a library which will factor the common tasks of your application. The GUI part and the shell part (or another language integration part for example) all use this "headless" library. Having a clear separation from the start will help enforcing modularity and decoupling.
You could use QT for the GUI front end. But I'd actually just write your library first. Then do your GUI last.
Some helpful advice
Be sure to write unit tests WHILE writing your code.
Be sure to use a code coverage tool to evaluate your unit tests while writing your code.
Be sure to avoid BOOL types since those are usually defined in the platform API (like win32). Use bool instead.
Forward declare as many types as you can in your header files. Include as few as possible header files in each library header file.
Expose as minimal an interface as possible.
Be sure to follow good coding practices for c++. Herb Sutters Book C++ coding standards is excellent in this regard.
Once you do write your gui, put as little business logic in your GUI event handlers as possible. Basically you want your library to be agnostic towards your GUI. Someone else mentioned the MVC pattern here. That is excellent advice.
We have an old application which has a FORTRAN API to be called from other applications. After some time they built a ( C ) wrapper for the FORTRAN API.Then I'm now building a c++ wrapper , with a little data handling , for the C API.
So I'm thinking what is the best way of building an API that can be called from any programming language.
Now I'm planning to bulde RPC server from my c++ API. Then any client using any programming language can call it.
I found that the XML-RPC is a good one. But it needs HTTP server for connection.
The problem is that the applications that call our API are desktop applications.And I found that XML-RPC can not manipulate complex objects.
Is SOAP a good solution? Can the client side be easily implemented?
So what is the best technical solution for my situation? Which technology should I use?
comment: I do not have a permission for changing the Fortran API and the C API. And I need the c++ API because I'm adding to it new methods , and enhancing the code so the user can call the methods easily.
Best Regards,
The best way is to leave it alone and just use the C API. virtually all programming languages can directly call a C API, so there's no reason to create wrappers unless a particular language's programming model makes more sense a different way.
To clarify what I mean, look at GTK+. It is a C API and is usable in virtually any language. Wrappers exist in object-oriented languages that provide a pure-OOP approach to the GTK+ API because it makes sense for those languages, given the domain of the API.
Does an objectified interface make sense for your application? If not, there is no reason to bother making a C++ wrapper.
As to RPC, why doesn't a simple message-passing interface with shared memory suffice?
Any decent language has a foreign function API. Just call the Fortran functions directly. The compiler documentation will tell you how - calling Fortran in a shared library is very similar to calling C in a shared library, except different compliers may normalise the function names to lower case or not, or may add an underscore. Some FFIs may require some C wrapper code - Java for example - but many can just take a function name and parameter types and the name of the library to load.
Failing that, you can implement a streaming interface to the Fortran (read and write to standard output) and just pipe input to and from it - I've done that when quickly porting interactive ISPF Fortran applications to PC.
Since you want to expose the C++ API and extensions rather than the Fortran API, then look at SWIG, which automates the process for a variety of languages, as long as the C++ isn't too complicated.
SOAP, XML-RPC ect are normally used for computer to computer communication, is this what you want? Or is this all just running on one comuputer?
If it's just on one computer, just stick with C API, most systems can use that
If you model the C API as a REST style service, then you can also provide a HTTP service for applications that can't use the C API without, but only have one system to document