1. Homepage
  2. Programming
  3. [2022] VE280 Programming and Elementary Data Structures - LAB 6: Class Inheritance

[2022] VE280 Programming and Elementary Data Structures - LAB 6: Class Inheritance

Engage in a Conversation
SJTUVE280Programming and Elementary Data StructuresClass InheritanceProgramming Help

VE280 LAB 6 Topic: Class Inheritance CourseNana.COM


CourseNana.COM

Only one exercise. It will take most of your time exploring and understanding what needs to be done. The code you need to write is quite simple. CourseNana.COM

In addition of working on class inheritance, you will also practice code reading and learn about the plugin architecture. CourseNana.COM


CourseNana.COM

CourseNana.COM

1. Plugin based software development CourseNana.COM

Most of you use Visual Studio Code or CLion for this course. Both IDEs have a lot of powerful or interesting plugins or gadgets, like Rainbow Bracket on CLion, or Bracket Pair Colorizer on Visual Studio Code. Another example is Google Chrome, with some useful extensions like SwitchyOmega or Tampermonkey. They are all examples of a plugin. CourseNana.COM

From a simplified informal point of view a plugin can be seen as a small piece of software that can be loaded to extend or bring in new features to a host application. For this to work, the host software must expose a plugin API. Then plugins can be developed independently from each others or the main application, i.e., the core software does not need them to compile and run properly. Plugins can hence be implemented following the plugin API, be compiled as shared libraries, and loaded at startup or even at run-time by the host software. CourseNana.COM

API, Application Programming Interface, of an application defines how other applications can access data from this application. CourseNana.COM

For instance when developing a music player one might want to introduce plugins to play various file types such as mp3, wav, and flac. In such a case one will want to have a generic play_file() function which would redirect the job to an appropriate function, for example play_mp3(), or play_wav() depending on the file type. Of course if a file type is not supported, e.g., play_flac() does not exist, the program should not crash but simply report that this file type is not supported. In particular this shows the necessity for each plugin to register itself and present some meta- information about itself to the main program. CourseNana.COM

In a slightly more formal way the plugin architecture is split into four sub-concepts: CourseNana.COM

Discovering: mechanism allowing the host application to discover available plugins. Usually plugins are found in a specific folders. In this lab, the folder is ./plugins . This concept is implemented in PluginManager::discoverPlugin .
Registering: mechanism allowing the host application to potentially accept and register the discovered plugins; At this stage a plugin announces its features, version, and any other information necessary to the well functioning of the application. In this lab, it is
CourseNana.COM

PluginManager::registerPlugin .
Hooking: sometimes called mount points or extension points, application hooks can be seen as the core of the plugin manager; They allow the plugin to “attach” itself to the application; Hence the core application can get control over the plugin. In this lab, all the plugins are stored in a vector
PluginManager::pluginList so that the host application can access and control them.
Exposing: the core application should also expose an API to plugins such that they can call some of its functions; Evidently, not all functions from the core application should be
CourseNana.COM

  CourseNana.COM

accessible. The set of such functions can be seen as the part of the plugin manager API that is exposed to the plugins. This is not covered in this lab. CourseNana.COM

2. Core Applications CourseNana.COM

In this lab you will work on a single program that simulates the described plugin architecture. This program accepts one program argument, which provides the name of the folder that stores all the plugin files. CourseNana.COM

Plugin files are files with extension .so . Such files are dynamic libraries. Dynamic libraries, often mentioned together with static libraries, will be discussed more in EECS 370, EECS/VE 482. CourseNana.COM

When the program starts, it first scans through the folder, find all files with extension .so and load such files as plugins. If the program fails to load one of the plugin file, it will print an error message and continues on the next file. CourseNana.COM

The program is a Read-Eval-Print Loop program. It is like a simple shell. A shell is where you type and execute the Linux commands introduced in Lecture 1. You can also type some commands in this program. The program will execute your command and print a message. CourseNana.COM

Here are commands that you can use CourseNana.COM

1      load <.so filename> remove <plugin name> print <plugin name> exit CourseNana.COM

2      load a plugin by its filename CourseNana.COM

3      remove a plugin by its name CourseNana.COM

4      print the info of the plugin CourseNana.COM

5           exit the program CourseNana.COM

For any other message you type, the program will repeat it. CourseNana.COM

You can try loading the plugin or removing the plugin when the program is running. A plugin here detects certain patterns in your input. If your input matches such patterns or rules, the program will apply this plugin to handle your command. For details about the plugin cat , check the information in the next section 3.1 Cat. CourseNana.COM

1      dadsh > cat 3 CourseNana.COM

2      # and then watch the cat for 3 seconds dadsh > remove cat CourseNana.COM

3      dadsh > cat 3 CourseNana.COM

4      dadsh > load plugins/cat.so CourseNana.COM

5      dadsh > cat 3 CourseNana.COM

  CourseNana.COM

The source code and Makefile of the core applications are provided in the starter files. Build with CourseNana.COM

1      make CourseNana.COM

2      # or CourseNana.COM

3      make l6 CourseNana.COM

  CourseNana.COM

Execute with CourseNana.COM

1      ./l6<plugindirectory> CourseNana.COM

In most cases you will run with CourseNana.COM

3. Plugins CourseNana.COM

Two plugins are provided and they will be loaded when the program starts. CourseNana.COM

3.1 Cat CourseNana.COM

This plugin watches for input in the format below CourseNana.COM

1      dadsh>cat<number> CourseNana.COM

Try it yourself. The number is the execution time (unit: second) of this command. Like for cat 5 , the plugin will show a cat for 5 seconds. CourseNana.COM

Its source files are in plugins/cat . The compiled dynamic library file is at plugins/cat.so You do not need to understand the source code in plugins/cat/cat.cpp . There are some core CourseNana.COM

concepts of EECS/VE 482 in the source code. CourseNana.COM

3.2 Simple CourseNana.COM

This plugin watches for input in the format below CourseNana.COM

1      simple CourseNana.COM

It will print one message.
Its source files are in
plugins/simple . The compiled dynamic library file is at CourseNana.COM

plugins/simple.so CourseNana.COM

Please make sure you understand the source file here before you start writing your code. I suggest you try the input list below CourseNana.COM

1      dadsh > simple CourseNana.COM

2      dadsh > remove simple CourseNana.COM

3      dadsh > simple CourseNana.COM

4      dadsh > load plugins/simple.so dadsh > simple CourseNana.COM

  CourseNana.COM

3.3 Additional Information CourseNana.COM

In the source code shared with you we use some keywords that have not been introduced in the lectures. CourseNana.COM

override: In a member function declaration or definition, override specifier ensures that the function is virtual and is overriding a virtual function from a base class. The program is ill- formed (a compile-time error will be generated) if this is not true. https://en.cppreference.com/w/cpp/language/override
extern "C": In C++, when used with a string, specifies that the linkage conventions of another language are being used for the declarator(s). In short, normally we cannot compile C++ source code and C source code together. But with extern "C" , we can first compile the C++ source code into a library or link file. Then we can compile such file with other C source code. CourseNana.COM

4. TODO CourseNana.COM

Try the program with the provided commands. Try removing one plugin and loading it back. See how such actions change the way that the program handles your input. CourseNana.COM

Read through the code file. Understand how the program registers the plugins and how the program applies the plugins to handle the input. CourseNana.COM

The source code contains some complex Linux functions and also usage of STL containers or algorithms. Take advantage of a search engine and website resources. CourseNana.COM

Write a plugin yourself in styled.cpp CourseNana.COM

name: styled
author : Second Lobster
description: (Just Write anything you like) help: (Just Write anything you like) CourseNana.COM

It should reply to this specific message WhosYourDaddy with CourseNana.COM

1      YouarenotplayingWarcraft3,guys... CourseNana.COM

When using print styled , it should output as below CourseNana.COM

Write a plugin yourself in add.cpp CourseNana.COM

name: add
author : Meual
description: add two integers
help: Usage: add <integer> <integer> CourseNana.COM

It should output the sum of two integers. CourseNana.COM

Assume that all users follow the input format add <integer> <integer> and type valid integers. CourseNana.COM

When using print add , it should output as below CourseNana.COM

1      Addoperationsisgreat --Meual CourseNana.COM

For JOJ to successfully compile your plugins, make sure that your plugin source codes are in the same directory as plugin.h . Namely, you should use CourseNana.COM

1      #include"plugin.h" CourseNana.COM

5. How to compile CourseNana.COM

Follow the format below CourseNana.COM

1      g++<cppfile>-fPIC-shared-o<outputfilename>-Wall-Werror-std=c++11 CourseNana.COM

There are examples in Makefile, check them by yourself. CourseNana.COM

6. Submission CourseNana.COM

Zip your styled.cpp , add.cpp and submit on JOJ. CourseNana.COM

7. Hint CourseNana.COM

·      Read through the code. Though there are some complex functions that you have never learnt, they have comments. CourseNana.COM

·      All plugins should follow a certain kind of standard so that no matter what the plugin will be, the host application can recognize and connect to the plugin. CourseNana.COM

·      The topic of this lab is class inheritance. Make use of what you have learnt about class inheritance. CourseNana.COM

Reference CourseNana.COM

[1] Manuel Charlemagne, VE482 Intro to Operating Systems CourseNana.COM

  CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
SJTU代写,VE280代写,Programming and Elementary Data Structures代写,Class Inheritance代写,Programming Help代写,SJTU代编,VE280代编,Programming and Elementary Data Structures代编,Class Inheritance代编,Programming Help代编,SJTU代考,VE280代考,Programming and Elementary Data Structures代考,Class Inheritance代考,Programming Help代考,SJTUhelp,VE280help,Programming and Elementary Data Structureshelp,Class Inheritancehelp,Programming Helphelp,SJTU作业代写,VE280作业代写,Programming and Elementary Data Structures作业代写,Class Inheritance作业代写,Programming Help作业代写,SJTU编程代写,VE280编程代写,Programming and Elementary Data Structures编程代写,Class Inheritance编程代写,Programming Help编程代写,SJTUprogramming help,VE280programming help,Programming and Elementary Data Structuresprogramming help,Class Inheritanceprogramming help,Programming Helpprogramming help,SJTUassignment help,VE280assignment help,Programming and Elementary Data Structuresassignment help,Class Inheritanceassignment help,Programming Helpassignment help,SJTUsolution,VE280solution,Programming and Elementary Data Structuressolution,Class Inheritancesolution,Programming Helpsolution,