Git Product home page Git Product logo

cpp_plugin_architecture's Introduction

C++ Plugin Architecture Demo

Introduction

This project implements the plugin architecture in the C++ programming language. The plugin architecture usage is demonstrated through a simple calculator engine, which can be expanded with additional operations as plugins. The engine source code is originally shipped with two plugins: one for the addition operation, and another one for the subtraction operation.

Build Instructions

The project build has been tested in Ubuntu 16.04 LTS.

From a terminal, navigate to the project root directory and type:

mkdir build && cd build
cmake ..
make

The following directories and contents should be created upon successful build:

~/Desktop/calculator_engine/lib/libapi.so
~/Desktop/calculator_engine/lib/libengine.so
~/Desktop/calculator_engine/plugins/libaddition_plugin.so
~/Desktop/calculator_engine/plugins/libsubtraction_plugin.so

Demo Execution

While in build directory, type:

./calculator

Example input/output

The following is an example of the input and output of the calculator application:

Attempting to open lib libsubtraction_plugin.so ...
Added plugin (type=operation, name=sub)
Attempting to open lib libaddition_plugin.so ...
Added plugin (type=operation, name=add)
Calculator engine started
Enter operation: add
operandA: 1
operandB: 2
Loading library libaddition_plugin.so
Result: 3
Enter operation: mul
Operation not supported
Enter operation: sub
operandA: 4
operandB: 3
Loading library libsubtraction_plugin.so
Result: 1
Enter operation: exit
Calculator engine stopped
Clearing plugin registry

Plugin Development

For example, to create a plugin for the multiplication operation:

  1. Create a plugin_multiplication directory under src
  2. Create CMakeLists.txt, multiplication_plugin.h and multiplication_plugin.cpp under plugin_multiplication
  3. Implement those files in a similar way as e.g. the contents of plugin_addition folder
  4. Open top-level src/CMakeLists.txt and add:
add_subdirectory("src/plugin_multiplication")
  1. Re-build the project
  2. The plugin should be now available to the calculator engine

cpp_plugin_architecture's People

Contributors

michaelpantazoglou avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.