// Land tells drone to come in for landing.
335100
func (d Driver) Land() {
	d.mutex.Lock()
	d.cmd[9] = 0x80
	d.cmd[10] = checksum(d.cmd)
	d.mutex.Unlock()
	time.Sleep(500 * time.Millisecond)
	d.mutex.Lock()
	d.cmd[9] = 0x04
	d.cmd[10] = checksum(d.cmd)
	d.mutex.Unlock()
}
696085
func (c *client) Push(p *drone.Payload) error {
	uri := fmt.Sprintf(pathPush, c.base, p.Job.ID)
	err := c.post(uri, p, nil)
	return err
}
257910
func (mod *SpaceAPIBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "status":
		type SpaceAPIResult struct {
			State struct {
				Open bool `json:"open"`
			} `json:"state"`
		}
		apiState := new(SpaceAPIResult)

		// get json data
		resp, err := http.Get(mod.url)
		if err != nil {
			mod.Logln("Error: SpaceAPI instance @ " + mod.url + " not reachable")
		} else {
			defer resp.Body.Close()
			body, _ := ioutil.ReadAll(resp.Body)

			err = json.Unmarshal(body, apiState)
			if err != nil {
				mod.Logln("Sorry, couldn't unmarshal the JSON data from SpaceAPI Instance @ " + mod.url)
				apiState.State.Open = false
			}
		}

		ev := bees.Event{
			Bee:  mod.Name(),
			Name: "result",
			Options: []bees.Placeholder{
				{
					Name:  "open",
					Type:  "bool",
					Value: apiState.State.Open,
				},
			},
		}
		mod.evchan <- ev

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
1308131
func (a *Airport) startArrivals() {
	for i := 0; i < flightSlots/2+1; i++ {
		if err := a.newArrival(); err != nil {
			a.log.Error(err)
		}
	}

	for {
		if err := a.newArrival(); err != nil {
			a.log.Error(err)
		}
		time.Sleep(randomDuration(1000000000, 5000000000))
	}
}
190152
func (mod *HTMLExtractBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "extract":
		var url string
		action.Options.Bind("url", &url)
		if start := strings.Index(url, "http"); start >= 0 {
			url = url[start:]
			if end := strings.Index(url, " "); end >= 0 {
				url = url[:end]
			}
		}

		g := goose.New()
		article, _ := g.ExtractFromURL(url)
		article.Title = strings.TrimSpace(strings.Replace(article.TitleUnmodified, "\n", " ", -1))
		if strings.HasPrefix(article.TopImage, "http://data:image") {
			article.TopImage = ""
		}
		if len(article.Title) > 0 {
			ev := bees.Event{
				Bee:  mod.Name(),
				Name: "info_extracted",
				Options: []bees.Placeholder{
					{
						Name:  "title",
						Type:  "string",
						Value: article.Title,
					},
					{
						Name:  "domain",
						Type:  "string",
						Value: article.Domain,
					},
					{
						Name:  "top_image",
						Type:  "url",
						Value: article.TopImage,
					},
					{
						Name:  "final_url",
						Type:  "url",
						Value: article.FinalURL,
					},
					{
						Name:  "meta_description",
						Type:  "string",
						Value: article.MetaDescription,
					},
					{
						Name:  "meta_keywords",
						Type:  "string",
						Value: article.MetaKeywords,
					},
				},
			}
			mod.evchan <- ev
		}

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
385967
func (mod *EFABee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "directions":
		var originParam, destParam string
		action.Options.Bind("origin", &originParam)
		action.Options.Bind("destination", &destParam)

		origin, err := mod.efa.FindStop(originParam)
		if err != nil {
			mod.Logln("Origin does not exist or name is not unique!")
			return outs
		}
		mod.Logf("Selected origin: %s (%d)", origin[0].Name, origin[0].ID)

		destination, err := mod.efa.FindStop(destParam)
		if err != nil {
			mod.Logln("Destination does not exist or name is not unique!")
			return outs
		}
		mod.Logf("Selected destination: %s (%d)", destination[0].Name, destination[0].ID)

		routes, err := mod.efa.Route(origin[0].ID, destination[0].ID, time.Now())
		for _, route := range routes {
			mod.Logf("Trip duration: %s, %d transfers\n", route.ArrivalTime.Sub(route.DepartureTime), len(route.Trips)-1)
			for _, trip := range route.Trips {
				origin, err := mod.efa.Stop(trip.OriginID)
				if err != nil {
					mod.LogErrorf("%s", err)
					return outs
				}
				dest, err := mod.efa.Stop(trip.DestinationID)
				if err != nil {
					mod.LogErrorf("%s", err)
					return outs
				}

				ev := bees.Event{
					Bee:  mod.Name(),
					Name: "trip",
					Options: []bees.Placeholder{
						{
							Name:  "mottype",
							Type:  "string",
							Value: trip.MeansOfTransport.MotType.String(),
						},
						{
							Name:  "arrival_time",
							Type:  "string",
							Value: trip.ArrivalTime.Format("15:04"),
						},
						{
							Name:  "departure_time",
							Type:  "string",
							Value: trip.DepartureTime.Format("15:04"),
						},
						{
							Name:  "route",
							Type:  "string",
							Value: trip.MeansOfTransport.Number,
						},
						{
							Name:  "origin",
							Type:  "string",
							Value: origin.Name,
						},
						{
							Name:  "destination",
							Type:  "string",
							Value: dest.Name,
						},
						{
							Name:  "origin_platform",
							Type:  "string",
							Value: trip.OriginPlatform,
						},
						{
							Name:  "destination_platform",
							Type:  "string",
							Value: trip.DestinationPlatform,
						},
					},
				}
				mod.eventChan <- ev
			}

			// only post one trip for now
			break
		}

	case "departures":
		stop := ""
		amount := 3
		action.Options.Bind("stop", &stop)
		action.Options.Bind("amount", &amount)

		//FIXME get departures
		station, err := mod.efa.FindStop(stop)
		if err != nil {
			mod.Logln("Stop does not exist or name is not unique!")
			return outs
		}
		mod.Logf("Selected stop: %s (%d)", station[0].Name, station[0].ID)

		departures, err := station[0].Departures(time.Now(), amount)
		if err != nil {
			mod.Logln("Could not retrieve departure times!")
			return outs
		}
		for _, departure := range departures {
			destStop, err := mod.efa.Stop(departure.ServingLine.DestStopID)
			if err != nil {
				mod.Logln("Could not retrieve destination stop")
				return outs
			}

			mod.Logf("Route %-5s due in %-2d minute%s --> %s",
				departure.ServingLine.Number,
				departure.CountDown,
				"s",
				destStop.Name)

			ev := bees.Event{
				Bee:  mod.Name(),
				Name: "departure",
				Options: []bees.Placeholder{
					{
						Name:  "mottype",
						Type:  "string",
						Value: departure.ServingLine.MotType.String(),
					},
					{
						Name:  "eta",
						Type:  "int",
						Value: departure.CountDown,
					},
					{
						Name:  "etatime",
						Type:  "string",
						Value: departure.DateTime.Format("15:04"),
					},
					{
						Name:  "route",
						Type:  "string",
						Value: departure.ServingLine.Number,
					},
					{
						Name:  "destination",
						Type:  "string",
						Value: destStop.Name,
					},
				},
			}
			mod.eventChan <- ev
		}

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
1023081
func (f *FlagClause) Action(action Action) *FlagClause {
	f.addAction(action)
	return f
}
1163295
func (op *Operator) AutopilotGetConfiguration(q *QueryOptions) (*AutopilotConfiguration, error) {
	r := op.c.newRequest("GET", "/v1/operator/autopilot/configuration")
	r.setQueryOptions(q)
	_, resp, err := requireOK(op.c.doRequest(r))
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	var out AutopilotConfiguration
	if err := decodeBody(resp, &out); err != nil {
		return nil, err
	}

	return &out, nil
}
877552
func (op *Operator) AutopilotSetConfiguration(args *structs.AutopilotSetConfigRequest, reply *bool) error {
	if done, err := op.srv.forward("Operator.AutopilotSetConfiguration", args, args, reply); done {
		return err
	}

	// This action requires operator write access.
	rule, err := op.srv.ResolveToken(args.AuthToken)
	if err != nil {
		return err
	}
	if rule != nil && !rule.AllowOperatorWrite() {
		return structs.ErrPermissionDenied
	}

	// All servers should be at or above 0.8.0 to apply this operatation
	if !ServersMeetMinimumVersion(op.srv.Members(), minAutopilotVersion, false) {
		return fmt.Errorf("All servers should be running version %v to update autopilot config", minAutopilotVersion)
	}

	// Apply the update
	resp, _, err := op.srv.raftApply(structs.AutopilotRequestType, args)
	if err != nil {
		op.logger.Error("failed applying AutoPilot configuration", "error", err)
		return err
	}
	if respErr, ok := resp.(error); ok {
		return respErr
	}

	// Check if the return type is a bool.
	if respBool, ok := resp.(bool); ok {
		*reply = respBool
	}
	return nil
}
303976
func (c *SearchController) Show(ctx *app.ShowSearchContext) error {
	offset, limit := computePagingLimits(ctx.PageOffset, ctx.PageLimit)
	// TODO: Keep URL registeration central somehow.
	hostString := ctx.Request.Host
	if hostString == "" {
		hostString = c.configuration.GetHTTPAddress()
	}
	urlRegexString := fmt.Sprintf("(?P<domain>%s)(?P<path>/work-item/list/detail/)(?P<id>\\d*)", hostString)
	search.RegisterAsKnownURL(search.HostRegistrationKeyForListWI, urlRegexString)
	urlRegexString = fmt.Sprintf("(?P<domain>%s)(?P<path>/work-item/board/detail/)(?P<id>\\d*)", hostString)
	search.RegisterAsKnownURL(search.HostRegistrationKeyForBoardWI, urlRegexString)

	if ctx.FilterExpression != nil {
		var result []workitem.WorkItem
		var count int
		var ancestors link.AncestorList
		var childLinks link.WorkItemLinkList
		err := application.Transactional(c.db, func(appl application.Application) error {
			var err error
			result, count, ancestors, childLinks, err = appl.SearchItems().Filter(ctx.Context, *ctx.FilterExpression, ctx.FilterParentexists, &offset, &limit)
			if err != nil {
				cause := errs.Cause(err)
				switch cause.(type) {
				case errors.BadParameterError:
					return goa.ErrBadRequest(fmt.Sprintf("error listing work items for expression '%s': %s", *ctx.FilterExpression, err))
				default:
					log.Error(ctx, map[string]interface{}{
						"err":               err,
						"filter_expression": *ctx.FilterExpression,
					}, "unable to list the work items")
					return goa.ErrInternal(fmt.Sprintf("unable to list the work items: %s", err))
				}
			}
			return nil

		})
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		matchingWorkItemIDs := make(id.Slice, len(result))
		for i, wi := range result {
			matchingWorkItemIDs[i] = wi.ID
		}
		hasChildren := workItemIncludeHasChildren(ctx, c.db, childLinks)
		includeParent := includeParentWorkItem(ctx, ancestors, childLinks)
		// Load all work item types
		wits, err := loadWorkItemTypesFromArr(ctx.Context, c.db, result)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "failed to load work item types"))
		}

		wis, err := ConvertWorkItems(ctx.Request, wits, result, hasChildren, includeParent)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		response := app.SearchWorkItemList{
			Links: &app.PagingLinks{},
			Meta: &app.WorkItemListResponseMeta{
				TotalCount: count,
			},
			Data: wis,
		}
		err = c.enrichWorkItemList(ctx, ancestors, matchingWorkItemIDs, childLinks, &response, hasChildren) // append parentWI and ancestors (if not empty) in response
		if err != nil {
			return errs.Wrap(err, "failed to enrich work item list")
		}
		setPagingLinks(response.Links, buildAbsoluteURL(ctx.Request), len(result), offset, limit, count, "filter[expression]="+*ctx.FilterExpression)

		// Sort "data" by name or ID if no title given
		var data WorkItemPtrSlice = response.Data
		sort.Sort(data)
		response.Data = data

		// Sort work items in the "included" array by ID or title
		var included WorkItemInterfaceSlice = response.Included
		sort.Sort(included)
		response.Included = included

		// build up list of sorted ancestor IDs from already sorted work items
		ancestorIDs := ancestors.GetDistinctAncestorIDs().ToMap()
		sortedAncestorIDs := make(id.Slice, len(ancestorIDs))
		i := 0
		for _, wi := range response.Data {
			if len(ancestorIDs) <= 0 {
				break
			}
			_, ok := ancestorIDs[*wi.ID]
			if ok {
				sortedAncestorIDs[i] = *wi.ID
				i++
				delete(ancestorIDs, *wi.ID)
			}
		}
		for _, ifObj := range response.Included {
			if len(ancestorIDs) <= 0 {
				break
			}
			var wi *app.WorkItem
			switch v := ifObj.(type) {
			case app.WorkItem:
				wi = &v
			case *app.WorkItem:
				wi = v
			default:
				continue
			}
			_, ok := ancestorIDs[*wi.ID]
			if ok {
				sortedAncestorIDs[i] = *wi.ID
				i++
				delete(ancestorIDs, *wi.ID)
			}
		}
		response.Meta.AncestorIDs = sortedAncestorIDs
		return ctx.OK(&response)
	}
	var result []workitem.WorkItem
	var count int
	err := application.Transactional(c.db, func(appl application.Application) error {
		if ctx.Q == nil || *ctx.Q == "" {
			return goa.ErrBadRequest("empty search query not allowed")
		}
		var err error
		result, count, err = appl.SearchItems().SearchFullText(ctx.Context, *ctx.Q, &offset, &limit, ctx.SpaceID)
		if err != nil {
			log.Error(ctx, map[string]interface{}{
				"err":        err,
				"expression": *ctx.Q,
			}, "unable to list the work items")
			return errs.Wrapf(err, "unable to list the work items for expression: %s", *ctx.Q)
		}
		return nil
	})
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	wits, err := loadWorkItemTypesFromArr(ctx.Context, c.db, result)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	wis, err := ConvertWorkItems(ctx.Request, wits, result)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	response := app.SearchWorkItemList{
		Links: &app.PagingLinks{},
		Meta:  &app.WorkItemListResponseMeta{TotalCount: count},
		Data:  wis,
	}
	setPagingLinks(response.Links, buildAbsoluteURL(ctx.Request), len(result), offset, limit, count, "q="+*ctx.Q)
	return ctx.OK(&response)
}
1324638
func (op *Operator) AutopilotSetConfiguration(conf *AutopilotConfiguration, q *WriteOptions) error {
	r := op.c.newRequest("PUT", "/v1/operator/autopilot/configuration")
	r.setWriteOptions(q)
	r.obj = conf
	_, resp, err := requireOK(op.c.doRequest(r))
	if err != nil {
		return err
	}
	resp.Body.Close()
	return nil
}
844002
func (r FutureEstimateFeeResult) Receive() (float64, error) {
	res, err := receiveFuture(r)
	if err != nil {
		return -1, err
	}

	// Unmarshal result as a getinfo result object.
	var fee float64
	err = json.Unmarshal(res, &fee)
	if err != nil {
		return -1, err
	}

	return fee, nil
}
812335
func (c *SpaceController) Show(ctx *app.ShowSpaceContext) error {
	var s *space.Space
	err := application.Transactional(c.db, func(appl application.Application) error {
		var err error
		s, err = appl.Spaces().Load(ctx.Context, ctx.SpaceID)
		if err != nil {
			log.Error(ctx, map[string]interface{}{
				"err":      err,
				"space_id": ctx.SpaceID,
			}, "unable to load the space by ID")
		}
		return err
	})
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	return ctx.ConditionalRequest(*s, c.config.GetCacheControlSpace, func() error {
		spaceData, err := ConvertSpaceFromModel(ctx.Request, *s, IncludeBacklogTotalCount(ctx.Context, c.db))
		if err != nil {
			log.Error(ctx, map[string]interface{}{
				"err":      err,
				"space_id": ctx.SpaceID,
			}, "unable to convert the space object")
			return err
		}
		result := &app.SpaceSingle{
			Data: spaceData,
		}
		return ctx.OK(result)
	})
}
437692
func (mod *HTTPBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	u := ""
	action.Options.Bind("url", &u)

	switch action.Name {
	case "get":
		resp, err := http.Get(u)
		if err != nil {
			mod.LogErrorf("Error: %s", err)
			return outs
		}
		defer resp.Body.Close()

		b, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			mod.LogErrorf("Error: %s", err)
			return outs
		}

		ev, err := mod.prepareResponseEvent(b)
		if err == nil {
			ev.Name = "get"
			ev.Options.SetValue("url", "url", u)
			mod.eventChan <- ev
		}

	case "post":
		var err error
		var b []byte
		var j string
		var form url.Values
		var resp *http.Response

		action.Options.Bind("json", &j)
		action.Options.Bind("form", &form)

		if j != "" {
			buf := strings.NewReader(j)
			resp, err = http.Post(u, "application/json", buf)
		} else {
			resp, err = http.PostForm(u, form)
		}
		if err != nil {
			mod.LogErrorf("Error: %s", err)
			return outs
		}
		defer resp.Body.Close()

		b, err = ioutil.ReadAll(resp.Body)
		if err != nil {
			mod.LogErrorf("Error: %s", err)
			return outs
		}

		ev, err := mod.prepareResponseEvent(b)
		if err == nil {
			ev.Name = "post"
			ev.Options.SetValue("url", "url", u)
			mod.eventChan <- ev
		}

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
383817
func landing(w http.ResponseWriter, r *http.Request) {
	http.Redirect(w, r, config.AuthCodeURL("foo"), http.StatusFound)
}
781240
func (a *Driver) Backward(speed int) {
	a.adaptor().drone.Backward(speed)
}
150083
func (self *SimplePageMapper) LogoutLandingPage(conn OauthConnector) string {
	v := url.Values{
		"service": []string{conn.Name()},
	}
	return fmt.Sprintf("%s?%s", self.logoutOk, v.Encode())
}