#824 closed Enhancement (fixed)
Code using reply->insert_message could be simplified
| Reported by: | Nicolas | Owned by: | davea |
|---|---|---|---|
| Priority: | Minor | Milestone: | Undetermined |
| Component: | Server - Scheduler | Version: | |
| Keywords: | Cc: | Pepo |
Description
Currently, to add a USER_MESSAGE to the scheduler reply, you always need code like this:
sprintf(message, "%s is not available for your type of computer.", app->user_friendly_name ); USER_MESSAGE um(message, "high"); g_wreq->insert_no_work_message(um);
The separate um variable is required, otherwise it doesn't compile. The reason is that insert_no_work_message and others take a non-const USER_MESSAGE&. Since you can't modify temporary objects (a non-const reference implies the object will be modified, which actually isn't the case), you need a separate variable.
By making the arguments const, for example:
-void WORK_REQ::insert_no_work_message(USER_MESSAGE& um) { +void WORK_REQ::insert_no_work_message(const USER_MESSAGE& um) {
you can now add messages using a single statement, with no temporary variable needed:
g_reply->insert_message(USER_MESSAGE( "Unable to send work to Vista with BOINC installed in protected mode", "high" )); g_reply->insert_message(USER_MESSAGE( "Please reinstall BOINC and uncheck 'Protected application execution'", "high" ));
But on second thought, it would be even better if insert_message took two const char*s as arguments and created the USER_MESSAGE object, so "client code" doesn't have to do it.
void SCHEDULER_REPLY::insert_message(const char* message, const char* priority) { USER_MESSAGE um(message, priority); messages.push_back(um); } ... g_reply->insert_message("No work available", "low");
Change History (5)
comment:1 Changed 17 years ago by
comment:2 Changed 17 years ago by
| Cc: | Pepo added |
|---|
comment:3 Changed 17 years ago by
| Owner: | changed from Bruce Allen to davea |
|---|

And priorities should be part of an enum, not strings.