{"action":"created","issue":{"url":"https://api.github.com/repos/BOINC/boinc/issues/1205","labels_url":"https://api.github.com/repos/BOINC/boinc/issues/1205/labels{/name}","comments_url":"https://api.github.com/repos/BOINC/boinc/issues/1205/comments","events_url":"https://api.github.com/repos/BOINC/boinc/issues/1205/events","html_url":"https://github.com/BOINC/boinc/issues/1205","id":56210118,"number":1205,"title":"Code using reply->insert_message could be simplified","user":{"login":"romw","id":985772,"avatar_url":"https://avatars.githubusercontent.com/u/985772?v=3","gravatar_id":"","url":"https://api.github.com/users/romw","html_url":"https://github.com/romw","followers_url":"https://api.github.com/users/romw/followers","following_url":"https://api.github.com/users/romw/following{/other_user}","gists_url":"https://api.github.com/users/romw/gists{/gist_id}","starred_url":"https://api.github.com/users/romw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/romw/subscriptions","organizations_url":"https://api.github.com/users/romw/orgs","repos_url":"https://api.github.com/users/romw/repos","events_url":"https://api.github.com/users/romw/events{/privacy}","received_events_url":"https://api.github.com/users/romw/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"davidpanderson","id":985729,"avatar_url":"https://avatars.githubusercontent.com/u/985729?v=3","gravatar_id":"","url":"https://api.github.com/users/davidpanderson","html_url":"https://github.com/davidpanderson","followers_url":"https://api.github.com/users/davidpanderson/followers","following_url":"https://api.github.com/users/davidpanderson/following{/other_user}","gists_url":"https://api.github.com/users/davidpanderson/gists{/gist_id}","starred_url":"https://api.github.com/users/davidpanderson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidpanderson/subscriptions","organizations_url":"https://api.github.com/users/davidpanderson/orgs","repos_url":"https://api.github.com/users/davidpanderson/repos","events_url":"https://api.github.com/users/davidpanderson/events{/privacy}","received_events_url":"https://api.github.com/users/davidpanderson/received_events","type":"User","site_admin":false},"milestone":null,"comments":2,"created_at":"2015-02-02T08:53:35Z","updated_at":"2015-02-03T02:12:04Z","closed_at":"2015-02-02T08:53:46Z","body":"**Reported by Nicolas on 5 Aug 39036372 08:26 UTC**\nCurrently, to add a ```USER_MESSAGE``` to the scheduler reply, you always need code like this:\r\n```c++\r\nsprintf(message,\r\n    \"%s is not available for your type of computer.\",\r\n    app->user_friendly_name\r\n);\r\nUSER_MESSAGE um(message, \"high\");\r\ng_wreq->insert_no_work_message(um);\r\n```\r\nThe 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.\r\n\r\nBy making the arguments ```const```, for example:\r\n```diff\r\n-void WORK_REQ::insert_no_work_message(USER_MESSAGE& um) {\r\n+void WORK_REQ::insert_no_work_message(const USER_MESSAGE& um) {\r\n```\r\n\r\nyou can now add messages using a single statement, with no temporary variable needed:\r\n```c++\r\n\r\ng_reply->insert_message(USER_MESSAGE(\r\n    \"Unable to send work to Vista with BOINC installed in protected mode\", \"high\"\r\n));\r\ng_reply->insert_message(USER_MESSAGE(\r\n    \"Please reinstall BOINC and uncheck 'Protected application execution'\", \"high\"\r\n));\r\n```\r\n\r\nBut 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.\r\n\r\n```c++\r\nvoid SCHEDULER_REPLY::insert_message(const char* message, const char* priority) {\r\n    USER_MESSAGE um(message, priority);\r\n    messages.push_back(um);\r\n}\r\n...\r\ng_reply->insert_message(\"No work available\", \"low\");\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/BOINC/boinc/issues/comments/72579528","html_url":"https://github.com/BOINC/boinc/issues/1205#issuecomment-72579528","issue_url":"https://api.github.com/repos/BOINC/boinc/issues/1205","id":72579528,"user":{"login":"romw","id":985772,"avatar_url":"https://avatars.githubusercontent.com/u/985772?v=3","gravatar_id":"","url":"https://api.github.com/users/romw","html_url":"https://github.com/romw","followers_url":"https://api.github.com/users/romw/followers","following_url":"https://api.github.com/users/romw/following{/other_user}","gists_url":"https://api.github.com/users/romw/gists{/gist_id}","starred_url":"https://api.github.com/users/romw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/romw/subscriptions","organizations_url":"https://api.github.com/users/romw/orgs","repos_url":"https://api.github.com/users/romw/repos","events_url":"https://api.github.com/users/romw/events{/privacy}","received_events_url":"https://api.github.com/users/romw/received_events","type":"User","site_admin":false},"created_at":"2015-02-03T02:12:04Z","updated_at":"2015-02-03T02:12:04Z","body":"**Commented by davea on 12 Dec 39159483 00:53 UTC**\nfixed in [17395]"}}