GitHub PullRequestReviewCommentEvent at 2014-06-20 03:39:35
Repository: gousb
Actor: kylelemons
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/kylelemons/gousb/pulls/comments/14006056","id":14006056,"diff_hunk":"@@ -0,0 +1,102 @@\n+package usb\n+\n+/*\n+#include <libusb-1.0/libusb.h>\n+\n+extern int attachCallback(\n+\tlibusb_context* ctx,\n+\tlibusb_hotplug_event events,\n+\tlibusb_hotplug_flag flags,\n+\tint vid,\n+\tint pid,\n+\tint dev_class,\n+\tvoid* user_data,\n+\tlibusb_hotplug_callback_handle* handle\n+);\n+*/\n+import \"C\"\n+\n+import (\n+\t\"sync\"\n+\t\"unsafe\"\n+)\n+\n+type (\n+\tHotplugEvent    C.int\n+\tHotplugHandle   C.libusb_hotplug_callback_handle\n+\tHotplugCallback func(desc *Descriptor, event HotplugEvent) bool\n+)\n+\n+type hotplugCallbackData struct {\n+\tf HotplugCallback // The user's function pointer\n+\td interface{}     // The user's userdata.\n+\th HotplugHandle   // the handle belonging to this callback\n+}\n+\n+const (\n+\tHOTPLUG_EVENT_DEVICE_ARRIVED HotplugEvent = C.LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED\n+\tHOTPLUG_EVENT_DEVICE_LEFT    HotplugEvent = C.LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT\n+\tHOTPLUG_ANY                  int          = C.LIBUSB_HOTPLUG_MATCH_ANY","path":"usb/hotplug.go","position":39,"original_position":39,"commit_id":"8cbcc9937414d76b448c491381e33720345c7b9e","original_commit_id":"8cbcc9937414d76b448c491381e33720345c7b9e","user":{"login":"kylelemons","id":322213,"avatar_url":"https://avatars.githubusercontent.com/u/322213?","gravatar_id":null,"url":"https://api.github.com/users/kylelemons","html_url":"https://github.com/kylelemons","followers_url":"https://api.github.com/users/kylelemons/followers","following_url":"https://api.github.com/users/kylelemons/following{/other_user}","gists_url":"https://api.github.com/users/kylelemons/gists{/gist_id}","starred_url":"https://api.github.com/users/kylelemons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylelemons/subscriptions","organizations_url":"https://api.github.com/users/kylelemons/orgs","repos_url":"https://api.github.com/users/kylelemons/repos","events_url":"https://api.github.com/users/kylelemons/events{/privacy}","received_events_url":"https://api.github.com/users/kylelemons/received_events","type":"User","site_admin":false},"body":"Why isn't this a HotplugEvent?","created_at":"2014-06-20T03:39:35Z","updated_at":"2014-06-20T03:39:35Z","html_url":"https://github.com/kylelemons/gousb/pull/9#discussion_r14006056","pull_request_url":"https://api.github.com/repos/kylelemons/gousb/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/kylelemons/gousb/pulls/comments/14006056"},"html":{"href":"https://github.com/kylelemons/gousb/pull/9#discussion_r14006056"},"pull_request":{"href":"https://api.github.com/repos/kylelemons/gousb/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/kylelemons/gousb/pulls/9","id":16865140,"html_url":"https://github.com/kylelemons/gousb/pull/9","diff_url":"https://github.com/kylelemons/gousb/pull/9.diff","patch_url":"https://github.com/kylelemons/gousb/pull/9.patch","issue_url":"https://api.github.com/repos/kylelemons/gousb/issues/9","number":9,"state":"open","title":"Hotplug","user":{"login":"nkovacs","id":2269242,"avatar_url":"https://avatars.githubusercontent.com/u/2269242?","gravatar_id":"f8447d0ae4e15d8a97515e4d14d4ab75","url":"https://api.github.com/users/nkovacs","html_url":"https://github.com/nkovacs","followers_url":"https://api.github.com/users/nkovacs/followers","following_url":"https://api.github.com/users/nkovacs/following{/other_user}","gists_url":"https://api.github.com/users/nkovacs/gists{/gist_id}","starred_url":"https://api.github.com/users/nkovacs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nkovacs/subscriptions","organizations_url":"https://api.github.com/users/nkovacs/orgs","repos_url":"https://api.github.com/users/nkovacs/repos","events_url":"https://api.github.com/users/nkovacs/events{/privacy}","received_events_url":"https://api.github.com/users/nkovacs/received_events","type":"User","site_admin":false},"body":"You can use it like this:\r\n\r\n```go\r\nfunc Hotplugged(desc *usb.Descriptor, event usb.HotplugEvent) bool {\r\n\treturn false\r\n}\r\n\r\nhandle, err := ctx.RegisterHotplugCallback(usb.HOTPLUG_ANY, usb.HOTPLUG_ANY, usb.HOTPLUG_ANY,\r\n\tHotplugged,\r\n\tusb.HOTPLUG_EVENT_DEVICE_ARRIVED | usb.HOTPLUG_EVENT_DEVICE_LEFT,\r\n\ttrue,\r\n)\r\n```\r\n\r\nReturning true in the callback will deregister it.\r\n\r\nI also added a HandleEvents method to Context, because if your main loop is an infinite loop, the scheduler will never schedule to goroutine inside usb.go. Alternatively, you can use runtime.Gosched to give it a chance to run.","created_at":"2014-06-08T18:06:17Z","updated_at":"2014-06-20T03:39:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4b2bb0461e437f1a619abd45860e341bf09d47e7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/kylelemons/gousb/pulls/9/commits","review_comments_url":"https://api.github.com/repos/kylelemons/gousb/pulls/9/comments","review_comment_url":"https://api.github.com/repos/kylelemons/gousb/pulls/comments/{number}","comments_url":"https://api.github.com/repos/kylelemons/gousb/issues/9/comments","statuses_url":"https://api.github.com/repos/kylelemons/gousb/statuses/8cbcc9937414d76b448c491381e33720345c7b9e","head":{"label":"nkovacs:hotplug","ref":"hotplug","sha":"8cbcc9937414d76b448c491381e33720345c7b9e","user":{"login":"nkovacs","id":2269242,"avatar_url":"https://avatars.githubusercontent.com/u/2269242?","gravatar_id":"f8447d0ae4e15d8a97515e4d14d4ab75","url":"https://api.github.com/users/nkovacs","html_url":"https://github.com/nkovacs","followers_url":"https://api.github.com/users/nkovacs/followers","following_url":"https://api.github.com/users/nkovacs/following{/other_user}","gists_url":"https://api.github.com/users/nkovacs/gists{/gist_id}","starred_url":"https://api.github.com/users/nkovacs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nkovacs/subscriptions","organizations_url":"https://api.github.com/users/nkovacs/orgs","repos_url":"https://api.github.com/users/nkovacs/repos","events_url":"https://api.github.com/users/nkovacs/events{/privacy}","received_events_url":"https://api.github.com/users/nkovacs/received_events","type":"User","site_admin":false},"repo":{"id":20622447,"name":"gousb","full_name":"nkovacs/gousb","owner":{"login":"nkovacs","id":2269242,"avatar_url":"https://avatars.githubusercontent.com/u/2269242?","gravatar_id":"f8447d0ae4e15d8a97515e4d14d4ab75","url":"https://api.github.com/users/nkovacs","html_url":"https://github.com/nkovacs","followers_url":"https://api.github.com/users/nkovacs/followers","following_url":"https://api.github.com/users/nkovacs/following{/other_user}","gists_url":"https://api.github.com/users/nkovacs/gists{/gist_id}","starred_url":"https://api.github.com/users/nkovacs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nkovacs/subscriptions","organizations_url":"https://api.github.com/users/nkovacs/orgs","repos_url":"https://api.github.com/users/nkovacs/repos","events_url":"https://api.github.com/users/nkovacs/events{/privacy}","received_events_url":"https://api.github.com/users/nkovacs/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nkovacs/gousb","description":"Idiomatic Go bindings for libusb-1.0","fork":true,"url":"https://api.github.com/repos/nkovacs/gousb","forks_url":"https://api.github.com/repos/nkovacs/gousb/forks","keys_url":"https://api.github.com/repos/nkovacs/gousb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nkovacs/gousb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nkovacs/gousb/teams","hooks_url":"https://api.github.com/repos/nkovacs/gousb/hooks","issue_events_url":"https://api.github.com/repos/nkovacs/gousb/issues/events{/number}","events_url":"https://api.github.com/repos/nkovacs/gousb/events","assignees_url":"https://api.github.com/repos/nkovacs/gousb/assignees{/user}","branches_url":"https://api.github.com/repos/nkovacs/gousb/branches{/branch}","tags_url":"https://api.github.com/repos/nkovacs/gousb/tags","blobs_url":"https://api.github.com/repos/nkovacs/gousb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nkovacs/gousb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nkovacs/gousb/git/refs{/sha}","trees_url":"https://api.github.com/repos/nkovacs/gousb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nkovacs/gousb/statuses/{sha}","languages_url":"https://api.github.com/repos/nkovacs/gousb/languages","stargazers_url":"https://api.github.com/repos/nkovacs/gousb/stargazers","contributors_url":"https://api.github.com/repos/nkovacs/gousb/contributors","subscribers_url":"https://api.github.com/repos/nkovacs/gousb/subscribers","subscription_url":"https://api.github.com/repos/nkovacs/gousb/subscription","commits_url":"https://api.github.com/repos/nkovacs/gousb/commits{/sha}","git_commits_url":"https://api.github.com/repos/nkovacs/gousb/git/commits{/sha}","comments_url":"https://api.github.com/repos/nkovacs/gousb/comments{/number}","issue_comment_url":"https://api.github.com/repos/nkovacs/gousb/issues/comments/{number}","contents_url":"https://api.github.com/repos/nkovacs/gousb/contents/{+path}","compare_url":"https://api.github.com/repos/nkovacs/gousb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nkovacs/gousb/merges","archive_url":"https://api.github.com/repos/nkovacs/gousb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nkovacs/gousb/downloads","issues_url":"https://api.github.com/repos/nkovacs/gousb/issues{/number}","pulls_url":"https://api.github.com/repos/nkovacs/gousb/pulls{/number}","milestones_url":"https://api.github.com/repos/nkovacs/gousb/milestones{/number}","notifications_url":"https://api.github.com/repos/nkovacs/gousb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nkovacs/gousb/labels{/name}","releases_url":"https://api.github.com/repos/nkovacs/gousb/releases{/id}","created_at":"2014-06-08T17:42:51Z","updated_at":"2014-06-08T19:04:55Z","pushed_at":"2014-06-08T19:04:55Z","git_url":"git://github.com/nkovacs/gousb.git","ssh_url":"git@github.com:nkovacs/gousb.git","clone_url":"https://github.com/nkovacs/gousb.git","svn_url":"https://github.com/nkovacs/gousb","homepage":"http://gopkgdoc.appspot.com/pkg/github.com/kylelemons/gousb/usb","size":3250,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"kylelemons:master","ref":"master","sha":"992853faa28abbaba0300d4ce9cc72f1fe76dcbc","user":{"login":"kylelemons","id":322213,"avatar_url":"https://avatars.githubusercontent.com/u/322213?","gravatar_id":null,"url":"https://api.github.com/users/kylelemons","html_url":"https://github.com/kylelemons","followers_url":"https://api.github.com/users/kylelemons/followers","following_url":"https://api.github.com/users/kylelemons/following{/other_user}","gists_url":"https://api.github.com/users/kylelemons/gists{/gist_id}","starred_url":"https://api.github.com/users/kylelemons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylelemons/subscriptions","organizations_url":"https://api.github.com/users/kylelemons/orgs","repos_url":"https://api.github.com/users/kylelemons/repos","events_url":"https://api.github.com/users/kylelemons/events{/privacy}","received_events_url":"https://api.github.com/users/kylelemons/received_events","type":"User","site_admin":false},"repo":{"id":3840932,"name":"gousb","full_name":"kylelemons/gousb","owner":{"login":"kylelemons","id":322213,"avatar_url":"https://avatars.githubusercontent.com/u/322213?","gravatar_id":null,"url":"https://api.github.com/users/kylelemons","html_url":"https://github.com/kylelemons","followers_url":"https://api.github.com/users/kylelemons/followers","following_url":"https://api.github.com/users/kylelemons/following{/other_user}","gists_url":"https://api.github.com/users/kylelemons/gists{/gist_id}","starred_url":"https://api.github.com/users/kylelemons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylelemons/subscriptions","organizations_url":"https://api.github.com/users/kylelemons/orgs","repos_url":"https://api.github.com/users/kylelemons/repos","events_url":"https://api.github.com/users/kylelemons/events{/privacy}","received_events_url":"https://api.github.com/users/kylelemons/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kylelemons/gousb","description":"Idiomatic Go bindings for libusb-1.0","fork":false,"url":"https://api.github.com/repos/kylelemons/gousb","forks_url":"https://api.github.com/repos/kylelemons/gousb/forks","keys_url":"https://api.github.com/repos/kylelemons/gousb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kylelemons/gousb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kylelemons/gousb/teams","hooks_url":"https://api.github.com/repos/kylelemons/gousb/hooks","issue_events_url":"https://api.github.com/repos/kylelemons/gousb/issues/events{/number}","events_url":"https://api.github.com/repos/kylelemons/gousb/events","assignees_url":"https://api.github.com/repos/kylelemons/gousb/assignees{/user}","branches_url":"https://api.github.com/repos/kylelemons/gousb/branches{/branch}","tags_url":"https://api.github.com/repos/kylelemons/gousb/tags","blobs_url":"https://api.github.com/repos/kylelemons/gousb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kylelemons/gousb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kylelemons/gousb/git/refs{/sha}","trees_url":"https://api.github.com/repos/kylelemons/gousb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kylelemons/gousb/statuses/{sha}","languages_url":"https://api.github.com/repos/kylelemons/gousb/languages","stargazers_url":"https://api.github.com/repos/kylelemons/gousb/stargazers","contributors_url":"https://api.github.com/repos/kylelemons/gousb/contributors","subscribers_url":"https://api.github.com/repos/kylelemons/gousb/subscribers","subscription_url":"https://api.github.com/repos/kylelemons/gousb/subscription","commits_url":"https://api.github.com/repos/kylelemons/gousb/commits{/sha}","git_commits_url":"https://api.github.com/repos/kylelemons/gousb/git/commits{/sha}","comments_url":"https://api.github.com/repos/kylelemons/gousb/comments{/number}","issue_comment_url":"https://api.github.com/repos/kylelemons/gousb/issues/comments/{number}","contents_url":"https://api.github.com/repos/kylelemons/gousb/contents/{+path}","compare_url":"https://api.github.com/repos/kylelemons/gousb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kylelemons/gousb/merges","archive_url":"https://api.github.com/repos/kylelemons/gousb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kylelemons/gousb/downloads","issues_url":"https://api.github.com/repos/kylelemons/gousb/issues{/number}","pulls_url":"https://api.github.com/repos/kylelemons/gousb/pulls{/number}","milestones_url":"https://api.github.com/repos/kylelemons/gousb/milestones{/number}","notifications_url":"https://api.github.com/repos/kylelemons/gousb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kylelemons/gousb/labels{/name}","releases_url":"https://api.github.com/repos/kylelemons/gousb/releases{/id}","created_at":"2012-03-27T06:09:15Z","updated_at":"2014-05-31T12:32:03Z","pushed_at":"2013-11-22T08:38:14Z","git_url":"git://github.com/kylelemons/gousb.git","ssh_url":"git@github.com:kylelemons/gousb.git","clone_url":"https://github.com/kylelemons/gousb.git","svn_url":"https://github.com/kylelemons/gousb","homepage":"http://gopkgdoc.appspot.com/pkg/github.com/kylelemons/gousb/usb","size":3060,"stargazers_count":24,"watchers_count":24,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":11,"mirror_url":null,"open_issues_count":2,"forks":11,"open_issues":2,"watchers":24,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kylelemons/gousb/pulls/9"},"html":{"href":"https://github.com/kylelemons/gousb/pull/9"},"issue":{"href":"https://api.github.com/repos/kylelemons/gousb/issues/9"},"comments":{"href":"https://api.github.com/repos/kylelemons/gousb/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/kylelemons/gousb/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/kylelemons/gousb/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/kylelemons/gousb/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/kylelemons/gousb/statuses/8cbcc9937414d76b448c491381e33720345c7b9e"}}}}