Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Right now, I\'m working on refactoring a program that calls its parts by polling

ID: 658545 • Letter: R

Question

Right now, I'm working on refactoring a program that calls its parts by polling to a more event-driven structure.

I've created sched and task classes with the sced to become a base class of the current main loop. The tasks will be created for each meter so they can be called off of that instead of polling.

Each of the events main calls are a type of meter that gather info and display it. When the program is coming up, all enabled meters get 'constructed' by a main-sub. In that sub, I want to store off the "this" pointer associated with the meter, as well as the common name for the "action routine.

void MeterMaker::Meter_n_Task (Meter * newmeter,) {
push(newmeter);      // handle non-timed draw events
Task t = new Task(now() + 0.5L);
t.period={0,1U};
t.work_meter = newmeter;    
t.work = [&newmeter](){newmeter.checkevent();};<<--attempt at lambda
t.flags = T_Repeat;
t.enable_task();
_xos->sched_insert(t);
}
A sample call to it:

Meter_n_Task(new CPUMeter(_xos, "CPU "));
've made the scheduler a base class of the main routine (that handles the loop), and I've tried serveral variations to get the task class to be a base of the meter class, but keep running into roadblocks. It's alot like "whack-a-mole" -- pound in something to fix something one place, and then a new probl pops out elsewhere.

Part of the problem, is that the sched.h file that is trying to hold the Task Q, includes the Task header file. The task file Wants to refer to the most "base", Meter class.

The meter class pulls in the main class of the parent as it passes a copy of the parent to the children so they can access the draw routines in the parent.

Two references in the task file are for the 'this' pointer of the meter and the meter's update sub (to be called via this).

void *this_data= NULL;
void (*this_func)() = NULL;
Note -- I didn't really want to store these in the class, as I wanted to use a lamdba in that meter&task routine above to store a routine+context to be used to call the meter's action routine.

Couldn't figure out the syntax.

But am running into other syntax problems trying to store the pointers...such as

g++: COMPILE lsched.cc
In file included from meter.h:13:0,
                 from ltask.h:17,
                 from lsched.h:13,
                 from lsched.cc:13:
xosview.h:30:47: error: expected class-name before

Explanation / Answer

Your main problem appears to be that your design makes your classes know too much about each other, which will give you headaches with cyclic dependencies and inextricable ownership issues

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote