ofs | hex dump | ascii |
---|
0000 | 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 07 80 00 00 04 38 08 06 00 00 00 e8 d3 c1 | .PNG........IHDR.......8........ |
0020 | 43 00 00 00 06 62 4b 47 44 00 ff 00 ff 00 ff a0 bd a7 93 00 00 00 09 70 48 59 73 00 00 0b 12 00 | C....bKGD..............pHYs..... |
0040 | 00 0b 12 01 d2 dd 7e fc 00 00 00 07 74 49 4d 45 07 e3 0a 0f 14 2e 0f ce 40 d4 6a 00 00 20 00 49 | ......~.....tIME........@.j....I |
0060 | 44 41 54 78 da ec bd f9 93 24 b9 71 2e f8 39 22 32 b3 8e be a6 7b 8e 9e 83 33 a4 48 8a 12 b5 3a | DATx.....$.q..9"2....{...3.H...: |
0080 | 56 4f f6 f4 ec d9 da fe 6d fb 9f ad ad ed 5b 93 d9 5b ad 69 a5 95 44 51 14 25 de 33 3d 33 7d 77 | VO......m.....[..[.i..DQ.%.3=3}w |
00a0 | 57 55 66 46 c0 f7 87 88 40 38 00 07 02 91 47 55 eb a9 82 d6 9c ee aa cc 08 04 e0 70 b8 fb e7 fe | WUfF....@8....GU...........p.... |
00c0 | 39 fd e7 ff f4 5f 19 b7 d7 ed 75 7b 1d f5 7a f6 fb 7f 0a 70 6e ab 4d 6c 43 ce fc 80 6d f2 a3 a4 | 9...._....u{..z....pn.MlC...m... |
00e0 | 3d 93 f7 79 6e f8 7b ce 7f 49 f9 bd ff 78 3b 39 77 34 35 06 cb 65 03 e6 69 55 c7 bc e7 7c 4c be | =..yn.{..I...x;9w45..e..iU...|L. |
0100 | 1b 2b ef c7 65 b7 df 7b 6c bc f3 bc 78 df 2e 58 33 f5 fe b6 ec 39 c4 00 28 5e 17 02 45 3f f7 c6 | .+..e..{l...x..X3....9..(^..E?.. |
0120 | c6 3b 1c 65 c3 77 e6 be 53 f1 f3 a8 60 5f 1c 50 e6 dc 33 f3 32 45 b3 e6 8a f3 32 6e c7 4f 10 cd | .;.e.w..S...`_.P..3.2E....2n.O.. |
0140 | 9c c2 39 ba 64 97 ab dd ef fb 7c b8 45 d9 41 b7 da ec f7 98 8e 60 ba 31 77 f7 e7 8c 48 51 a1 cc | ..9.d.....|.E.A......`.1w...HQ.. |
0160 | 92 7f 5b 27 1b 3c 7c 7b fc 10 b9 67 f0 fe 73 c7 00 83 c7 7b 4e 6c 5f 12 ef c8 3c bc aa ed e5 d9 | ..['.<|{...g..s....{Nl_...<..... |
0180 | 4c eb 87 50 5f 59 8e 9f 2b 3e c3 f2 df 9c 19 23 2b 2a 64 a7 cf 8d 93 65 db fe 63 e2 b5 86 57 1c | L..P_Y..+>.....#+*d....e..c...W. |
01a0 | 5f b3 1b 94 fc 79 5a 3c bb 7b 93 21 a7 07 c8 c0 d3 09 fe 18 c6 cf b3 f5 c7 e2 4d 33 6b aa 53 9b | _....yZ<.{.!..............M3k.S. |
01c0 | 2c ed 83 94 d0 d3 36 73 cf cc 42 90 2e 73 b1 ad 40 fd 9d d8 ff 09 c9 61 f4 73 1b ee 0d 69 e8 70 | ,.....6s..B..s..@......a.s...i.p |
01e0 | e6 08 f1 ee e3 7f 20 94 67 4e bd 0a 8d 7b 64 18 73 78 5e 84 f7 20 8a f7 97 7c 47 4e 4c b9 dc f3 | ........gN...{d.sx^......|GNL... |
0200 | a9 29 1e e6 31 54 31 ee 19 ec 0b 38 91 3f 07 a4 dc d4 7f 87 60 83 90 5c 7b 6d a2 14 19 a3 e0 c6 | .)..1T1....8.?......`..\{m...... |
0220 | d1 77 34 fd 60 12 bf 37 d9 fd da bd 9b f5 d7 92 d3 9b 7c 1c ce f8 19 55 be e0 af 39 47 f3 1d cb | .w4.`..7..........|....U...9G... |
0240 | d5 38 d7 fe 7c bb cf 32 ab 36 87 36 56 52 a6 8f 14 81 e5 84 fc 86 eb ae 3d 8f a4 0e 67 a8 6f 98 | .8..|..2.6.6VR..........=...g.o. |
0260 | b5 cb 84 34 b1 7b 26 83 88 46 39 25 52 64 33 35 07 09 85 62 91 19 4f e9 41 a7 bd d3 b0 32 79 7b | ...4.{&..F9%Rd35...b..O.A....2y{ |
0280 | 96 8c 01 db 84 cc f2 1c 59 8e 7f df 3d 7b 9e 6d d2 cd 6f a1 5d c/*
* Copyright (C) 2015, 2016 "IoT.bzh"
* Author "Romain Forlot" <romain.forlot@iot.bzh>
*
* 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.
*/
#include "source.hpp"
#include "signal-composer.hpp"
SourceAPI::SourceAPI()
{}
SourceAPI::SourceAPI(const std::string& api, const std::string& info, CtlActionT* init, CtlActionT* getSignals, CtlActionT* onReceived, int retention):api_(api),
info_(info),
init_(init),
getSignals_(getSignals),
signalsDefault_({onReceived, retention})
{}
void SourceAPI::init()
{
if(init_)
{
CtlSourceT source;
source.uid = init_->uid;
source.api = nullptr; // We use binding v2, no dynamic API.
source.request = {nullptr, nullptr};
ActionExecOne(&source, init_, nullptr);
return;
}
else if(api_ == afbBindingV2.api)
{api_ = Composer::instance().ctlConfig()->api;}
}
std::string SourceAPI::api() const
{
return api_;
}
const struct signalsDefault& SourceAPI::signalsDefault() const
{
return signalsDefault_;
}
void SourceAPI::addSignal(const std::string& id, const std::string& event, std::vector<std::string>& depends, int retention, const std::string& unit, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs)
{
std::shared_ptr<Signal> sig = std::make_shared<Signal>(id, event, depends, unit, retention, frequency, onReceived, getSignalsArgs);
signalsMap_[id] = sig;
}
std::vector<std::shared_ptr<Signal>> SourceAPI::getSignals() const
{
std::vector<std::shared_ptr<Signal>> signals;
for (auto& sig: signalsMap_)
{
signals.push_back(sig.second);
}
return signals;
}
/// @brief Search a signal in a source instance. If an exact signal name is find
/// then it will be returned else it will be search against each signals
/// contained in the map and signal will be deeper evaluated.
///
/// @param[in] name - A signal name to be searched
///
/// @return Returns a vector of found signals.
std::vector<std::shared_ptr<Signal>> SourceAPI::searchSignals(const std::string& name)
{
std::vector<std::shared_ptr<Signal>> signals;
if(signalsMap_.count(name))
{signals.emplace_back(signalsMap_[name]);}
else
{
for (auto& sig: signalsMap_)
{
if(*sig.second == name)
{signals.emplace_back(sig.second);}
}
}
return signals;
}
void SourceAPI::makeSubscription()
{
if(getSignals_)
{
CtlSourceT source;
source.uid = api_.c_str();
source.api = nullptr; // We use binding v2, no dynamic API.
source.request = {nullptr, nullptr};
for(auto& sig: signalsMap_)
{
json_object* signalJ = sig.second->toJSON();
if(!signalJ)
{
AFB_ERROR("Error building JSON query object to subscribe to for signal %s", sig.second->id().c_str());
break;
}
source.uid = sig.first.c_str();
source.context = (void*)sig.second->get_context();
ActionExecOne(&source, getSignals_, signalJ);
// Considerate signal subscribed no matter what
sig.second->subscribed_ = true;
delete((struct signalCBT*)source.context);
}
source.uid = "";
ActionExecOne(&source, getSignals_, nullptr);
}
}
|