to set the path you have to create the Mib using either one of the constructors with persistentObjectsPath parameter or you can set it using the Mib::set_persistent_objects_path() function.
The default is to only save the data when the Mib object is destroyed. Then the files are updated with the current data. You can manually call Mib::save_all() if needed.
How about if the it never happens that Mib object is destroyed? Like if the is a system crash or application terminate abruptly?
I know that I can catch some set of signals and call call Mib::save_all() if needed.
Is there any way to get a global notification that any Leaf has changed and save changes in the files as they happening?
Everything is saved in that virtual database ‘Mib’ and handled by a common Request list. so any SET request would be possible to detect and have callback to do a user required action. Is there something like this implemented already?
AGENT++ cannot randomly write objects, but it can write the content of a MibGroup individually.
Unlike in SNMP4J-Agent(-DB) there is no generic mechanism in AGENT++ to persistent changes immediately.
I recommend writing a subclasses of MibLeaf and MibTable to accomplish that in their commit_set_request methods.
Thank you for the help. One more question here: is there any way after processing a request by ‘Mib’ class to know if there where changes done and just simple call save-all if any?
’
req = reqList->receive(2);
if (req) {
mib->process_request(req);
-------------> Check for changes and save-all <---------------------------------------------
’
During the configuring an agent this could be a bit of overhead, but after it during run time mostly will be read request.
if you’re using threads, the mib->process_request() function returns while the request is still being executed.
There is no information if something was changed through a request. I would suggest the following in the main loop: If the request req is a set request, remember that you should save the mib and call save_all() after some time.
If you’re just interested in changes of your own mib table / leaf classes, you could set a global flag whenever a set was processed successfully. So in the main loop it could be checked if a save is needed.
That would work for me as for now I am interested only in capturing changes in common SNMP MIBs included in my project.
What would be the best way to check if a request is a set request? Would it be get_type()?
In addition to the code you use, you should also make sure that you synchronise your write operation(s) with possible read/write operations of the AGENT++ framework.