1/* 2 * Copyright (C) 2014-2017 Christian Muehlhaeuser 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU Affero General Public License as published 6 * by the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Affero General Public License for more details. 13 * 14 * You should have received a copy of the GNU Affero General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * 17 * Authors: 18 * Christian Muehlhaeuser <muesli@gmail.com> 19 */ 20 21// Package bees is Beehive's central module system. 22package bees 23 24// EventDescriptor describes an Event provided by a Bee. 25type EventDescriptor struct { 26 Namespace string 27 Name string 28 Description string 29 Options []PlaceholderDescriptor 30} 31 32// ActionDescriptor describes an Action provided by a Bee. 33type ActionDescriptor struct { 34 Namespace string 35 Name string 36 Description string 37 Options []PlaceholderDescriptor 38} 39 40// A PlaceholderDescriptor shows which in & out values a module expects and returns. 41type PlaceholderDescriptor struct { 42 Name string 43 Description string 44 Type string 45 Mandatory bool 46} 47 48// A BeeOptionDescriptor shows which config values a module expects. 49type BeeOptionDescriptor struct { 50 Name string 51 Description string 52 Type string 53 Default interface{} 54 Mandatory bool 55} 56 57// StateDescriptor describes a State provided by a Bee. 58type StateDescriptor struct { 59 Name string 60 Description string 61 Type string 62} 63 64// GetActionDescriptor returns the ActionDescriptor matching an action. 65func GetActionDescriptor(action *Action) ActionDescriptor { 66 bee := GetBee(action.Bee) 67 if bee == nil { 68 panic("Bee " + action.Bee + " not registered") 69 } 70 factory := (*GetFactory((*bee).Namespace())) 71 for _, ac := range factory.Actions() { 72 if ac.Name == action.Name { 73 return ac 74 } 75 } 76 77 return ActionDescriptor{} 78} 79 80// GetEventDescriptor returns the EventDescriptor matching an event. 81func GetEventDescriptor(event *Event) EventDescriptor { 82 bee := GetBee(event.Bee) 83 if bee == nil { 84 panic("Bee " + event.Bee + " not registered") 85 } 86 factory := (*GetFactory((*bee).Namespace())) 87 for _, ev := range factory.Events() { 88 if ev.Name == event.Name { 89 return ev 90 } 91 } 92 93 return EventDescriptor{} 94} 95