| // Copyright (C) 2015 The Android Open Source Project |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| package server |
| |
| import ( |
| "fmt" |
| "net/http" |
| |
| "android.googlesource.com/platform/tools/gpu/builder" |
| "android.googlesource.com/platform/tools/gpu/database" |
| "android.googlesource.com/platform/tools/gpu/log" |
| "android.googlesource.com/platform/tools/gpu/service" |
| ) |
| |
| const captureParamName = "capture" |
| |
| // AtomsHandler is an HTTP request handler that returns a human-readable description |
| // of the atoms for a given capture and context. |
| type atomsHandler struct { |
| database.Database |
| } |
| |
| // ServeHTTP writes to res a human-readable plain text description for each of the |
| // atoms of the capture/context identified by their respective parameters, parsed |
| // from the given req query string. |
| func (h atomsHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) { |
| logger := log.Nop{} |
| |
| captures, err := builder.Captures(h, logger) |
| if err != nil { |
| panic(err) |
| } |
| |
| captureName := req.URL.Query().Get(captureParamName) |
| |
| var capture service.Capture |
| for _, id := range captures { |
| if err := h.Load(id.ID, logger, &capture); err == nil { |
| if capture.Name == captureName { |
| break |
| } |
| } |
| } |
| |
| if capture.Name != captureName { |
| http.NotFound(res, req) |
| return |
| } |
| |
| var stream service.AtomStream |
| if err := h.Load(capture.Atoms.ID, log.Nop{}, &stream); err != nil { |
| panic(err) |
| } |
| |
| atoms, err := stream.List() |
| if err != nil { |
| panic(err) |
| } |
| |
| res.Header().Add("Content-Type", "text/plain;charset=UTF-8") |
| |
| for i, a := range atoms { |
| fmt.Fprintf(res, "%.6d %s\n", i, a) |
| } |
| } |