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 "gerrit.automotivelinux.org/gerrit/src/xds/xds-agent.git/lib/xaapiv1"
24 common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git"
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 xaapiv1.EventRegisterArgs
37 if c.BindJSON(&args) != nil || args.Name == "" {
38 common.APIError(c, "Invalid arguments")
42 sess := s.webServer.sessions.Get(c)
44 common.APIError(c, "Unknown sessions")
48 // Register to all or to a specific events
49 if err := s.events.Register(args.Name, sess.ID); err != nil {
50 common.APIError(c, err.Error())
54 c.JSON(http.StatusOK, gin.H{"status": "OK"})
57 // eventsRegister Registering for events that will be send over a WS
58 func (s *APIService) eventsUnRegister(c *gin.Context) {
59 var args xaapiv1.EventUnRegisterArgs
61 if c.BindJSON(&args) != nil || args.Name == "" {
62 common.APIError(c, "Invalid arguments")
66 sess := s.webServer.sessions.Get(c)
68 common.APIError(c, "Unknown sessions")
72 // Register to all or to a specific events
73 if err := s.events.UnRegister(args.Name, sess.ID); err != nil {
74 common.APIError(c, err.Error())
78 c.JSON(http.StatusOK, gin.H{"status": "OK"})