Don't consider a Bluetooth adapter present until it has an address.
[chromium-blink-merge.git] / courgette / ensemble.cc
blobfb9b25b81b2fc6692c1a67d72c5764ab848bf4b1
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "courgette/ensemble.h"
7 #include "base/basictypes.h"
8 #include "base/string_number_conversions.h"
10 #include "courgette/region.h"
11 #include "courgette/streams.h"
12 #include "courgette/simple_delta.h"
14 namespace courgette {
16 Element::Element(ExecutableType kind,
17 Ensemble* ensemble,
18 const Region& region)
19 : kind_(kind), ensemble_(ensemble), region_(region) {
22 Element::~Element() {}
24 std::string Element::Name() const {
25 return ensemble_->name() + "("
26 + base::IntToString(kind()) + ","
27 + base::Uint64ToString(offset_in_ensemble()) + ","
28 + base::Uint64ToString(region().length()) + ")";
31 // Scans the Ensemble's region, sniffing out Elements. We assume that the
32 // elements do not overlap.
33 Status Ensemble::FindEmbeddedElements() {
35 size_t length = region_.length();
36 const uint8* start = region_.start();
38 size_t position = 0;
39 while (position < length) {
40 ExecutableType type;
41 size_t detected_length;
43 Status result = DetectExecutableType(start + position,
44 length - position,
45 &type, &detected_length);
47 if (result == C_OK) {
48 Region region(start + position, detected_length);
50 Element* element = new Element(type, this, region);
51 owned_elements_.push_back(element);
52 elements_.push_back(element);
53 position += region.length();
54 } else {
55 position++;
58 return C_OK;
61 Ensemble::~Ensemble() {
62 for (size_t i = 0; i < owned_elements_.size(); ++i)
63 delete owned_elements_[i];
66 } // namespace