I have a very poor understanding of inheritance and I can't seem to find the answer I'm looking for. I apologize for the length of this post but I feel I need to be very specific.
I have a base class "ProgCtl" which can send signals to processes. I have a simple program called "Beeper" which just runs forever, giving a "beep!" message every 10 seconds until interrupted. The derived class which I'm tasked with making, "BeepCtrl", is meant to specifically send signals and make changes to the beeper program.
My problem is: I can't figure out how to access the methods and variables of ProgCtl from the methods in BeepCtrl. Mainly in BeepCtrl.cpp where I have to use ProgCtl's alive and send method's to check if the process exists and to end it.
are my beep constructor's ProgCtl extension even doing anything? My notes only say that this allows me to set the attribute values. I'm really sorry. I know it's bad etiquette to try to get more than one question (and broad ones) on here but I'm truly lost.
ProgCtl.hpp
#ifndef PROGCTL_HPP
#define PROGCTL_HPP
#include <stdlib.h>
#include <unistd.h>
#include <string>
class ProgCtl {
private:
std::string m_program;
pid_t m_pid;
void find_pid();
public:
// Constructors
ProgCtl():m_program(""),m_pid(-1){}
ProgCtl(std::string prog):m_program(prog),m_pid(-1){}
ProgCtl(char *prog):m_pid(-1) {
m_program = std::string(prog);
}
// Setters
void setName(std::string prog);
void setName(char *prog);
void setPid(pid_t pid){m_pid = pid;}
// Other
bool alive();
int send(int sig);
int start();
};
#endif
BeepCtrl.hpp; far from complete due to this fundamental issue
#ifndef BeepCtrl_HPP
#define BeepCtrl_HPP
#include "ProgCtl.hpp"
#include <string>
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <iostream>
class BeepCtrl: public ProgCtl{
public:
BeepCtrl(std::string name):ProgCtl(name){};
BeepCtrl():ProgCtl(){};
BeepCtrl(char *prog):ProgCtl(prog){};
void stop(); //if alive, send kill
void beep_faster(); //test if beeper is alive then decrement inveral
void beep_slower(); // increment interval
};
#endif
BeepCtrl.cpp
#include "BeepCtrl.hpp"
void stop() //if alive, send kill
{
//std::set_terminate(std::cerr << "terminate handler called\n");
if(alive()){//---alive and send not declared in this scope---
send(9);
}
else{
throw 0;
}
}
void beep_faster() //test if beeper is alive then decrement inveral
{
//throw if an invalid value
}
void beep_slower() // increment interval
{
//throw if an invalid value
}