2 * Copyright (C) 2017-2018 "IoT.bzh"
3 * Author Sebastien Douheret <sebastien@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
23 common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git/golib"
24 "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
25 "github.com/gin-gonic/gin"
28 // eventsList Registering for events that will be send over a WS
29 func (s *APIService) eventsList(c *gin.Context) {
30 c.JSON(http.StatusOK, s.events.GetList())
33 // eventsRegister Registering for events that will be send over a WS
34 func (s *APIService) eventsRegister(c *gin.Context) {
35 var args xsapiv1.EventRegisterArgs
37 if c.BindJSON(&args) != nil || args.Name == "" {
38 common.APIError(c, "Invalid arguments")
42 // TODO: add args.Filter support
44 sess := s.sessions.Get(c)
46 common.APIError(c, "Unknown sessions")
50 // Register to all or to a specific events
51 if err := s.events.Register(args.Name, sess.ID); err != nil {
52 common.APIError(c, err.Error())
56 c.JSON(http.StatusOK, gin.H{"status": "OK"})
59 // eventsRegister Registering for events that will be send over a WS
60 func (s *APIService) eventsUnRegister(c *gin.Context) {
61 var args xsapiv1.EventUnRegisterArgs
63 if c.BindJSON(&args) != nil || args.Name == "" {
64 common.APIError(c, "Invalid arguments")
68 sess := s.sessions.Get(c)
70 common.APIError(c, "Unknown sessions")
74 // Register to all or to a specific events
75 if err := s.events.UnRegister(args.Name, sess.ID); err != nil {
76 common.APIError(c, err.Error())
80 c.JSON(http.StatusOK, gin.H{"status": "OK"})