Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

mdconfiguration.cpp 4.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // mdconfiguration.cpp
  2. // SNF MDaemon Plugin: Platform Configuration Module
  3. // Copyright (C) 2007-2008, ARM Research Labs, LLC.
  4. #include "mdconfiguration.hpp"
  5. MDConfiguration::MDConfiguration(snf_RulebaseHandler& R, string& C) : // Default constructor.
  6. MyCFGReader("mdaemon"), // The top element is "mdaemon"
  7. MyGeneration(-1), // Our first real gen will be 0.
  8. MyMessageIPFuncOn(true), // By default the IP func is on.
  9. MyConfiguratorCommand("start notepad"), // By default we start notepad to
  10. MyAppendConfigurationFileOn(true), // edit our config and pass it the path.
  11. MyConfigurationPath(C), // This is the config file path.
  12. MyRulebase(R) { // This is the rulebase manager.
  13. // Here we construct the configuration elements that will parse the platform
  14. // configuration data from our rulebase manager.
  15. MyCFGReader
  16. .Element("ip-test")
  17. .Attribute("on-off", MyMessageIPFuncOn, false)
  18. .End("ip-test")
  19. .Element("configurator")
  20. .Attribute("command", MyConfiguratorCommand, "")
  21. .Attribute("append-path", MyAppendConfigurationFileOn, true)
  22. .End("configurator")
  23. .End("mdaemon");
  24. }
  25. int MDConfiguration::Generation() { // When checking our generation we
  26. return MyGeneration; // need only return what we have.
  27. }
  28. bool MDConfiguration::MessageIPFuncOn() { // Are we using the MessageIP function?
  29. ScopeMutex EverybodyFreeze(MyMutex); // Freeze the mutex.
  30. updateConfig(); // Update the configuration if needed.
  31. return MyMessageIPFuncOn; // Return the IP Func On/Off value.
  32. }
  33. string MDConfiguration::ConfiguratorCommand() { // Return proper configurator command.
  34. ScopeMutex EverybodyFreeze(MyMutex); // Freeze the mutex.
  35. updateConfig(); // Update the configuration.
  36. string ConfiguratorCommandString = ""; // Keep this in scope.
  37. if(0 < MyConfiguratorCommand.length()) { // If we have a command configured:
  38. ConfiguratorCommandString = MyConfiguratorCommand; // capture that command.
  39. if(MyAppendConfigurationFileOn) { // If we are supposed to append the
  40. ConfiguratorCommandString.append(" "); // configuration file path then
  41. ConfiguratorCommandString.append(MyConfigurationPath); // tack that on the end.
  42. } // If the configure command string was
  43. } // configured empty we will return "".
  44. return ConfiguratorCommandString; // Send back what we got.
  45. }
  46. void MDConfiguration::updateConfig() { // Parse & update the config if needed.
  47. if(MyGeneration != MyRulebase.Generation()) { // If our config is out of sync:
  48. try { // Catch any parsing errors.
  49. string NewConfiguration = MyRulebase.PlatformConfiguration(); // Grab the configuration string.
  50. ConfigurationData MyConfigData( // Load the configuration string
  51. NewConfiguration.c_str(), NewConfiguration.length()); // into a configuration data object.
  52. MyCFGReader.initialize(); // Initialize the parser and
  53. MyCFGReader.interpret(MyConfigData); // feed it the object.
  54. MyGeneration = MyRulebase.Generation(); // Grab the new generation tag.
  55. }
  56. catch(...) { } // Eat any thrown exceptions.
  57. } // If we're in sync we don't budge.
  58. }