2021-01-10 23:37:09 +01:00
|
|
|
/* Copyright (C) 2015-2021 Andreas Böhler, Andreas Shimokawa, Carsten
|
2019-04-21 18:50:56 +02:00
|
|
|
Pfeiffer, Daniele Gobbetti
|
2017-03-10 14:53:19 +01:00
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.service.btle;
|
2015-04-19 02:37:29 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2019-01-26 15:52:40 +01:00
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
2015-04-19 02:37:29 +02:00
|
|
|
/**
|
|
|
|
* Groups a bunch of {@link BtLEAction actions} together, making sure
|
|
|
|
* that upon failure of one action, all subsequent actions are discarded.
|
2015-04-19 11:28:03 +02:00
|
|
|
*
|
2015-04-19 02:37:29 +02:00
|
|
|
* @author TREND
|
|
|
|
*/
|
2019-02-27 09:21:41 +01:00
|
|
|
public class Transaction extends AbstractTransaction {
|
2015-11-23 23:04:46 +01:00
|
|
|
private final List<BtLEAction> mActions = new ArrayList<>(4);
|
2022-10-22 23:00:01 +02:00
|
|
|
|
2015-09-24 14:45:21 +02:00
|
|
|
private
|
|
|
|
@Nullable
|
|
|
|
GattCallback gattCallback;
|
2015-04-19 02:37:29 +02:00
|
|
|
|
2022-10-22 23:00:01 +02:00
|
|
|
private boolean modifyGattCallback;
|
|
|
|
|
2015-04-19 02:37:29 +02:00
|
|
|
public Transaction(String taskName) {
|
2019-02-27 09:21:41 +01:00
|
|
|
super(taskName);
|
2015-04-19 02:37:29 +02:00
|
|
|
}
|
2015-04-19 11:28:03 +02:00
|
|
|
|
2015-04-19 02:37:29 +02:00
|
|
|
public void add(BtLEAction action) {
|
|
|
|
mActions.add(action);
|
|
|
|
}
|
2015-04-19 11:28:03 +02:00
|
|
|
|
2015-04-19 02:37:29 +02:00
|
|
|
public List<BtLEAction> getActions() {
|
|
|
|
return Collections.unmodifiableList(mActions);
|
|
|
|
}
|
2015-04-19 11:28:03 +02:00
|
|
|
|
2015-04-19 02:37:29 +02:00
|
|
|
public boolean isEmpty() {
|
|
|
|
return mActions.isEmpty();
|
|
|
|
}
|
|
|
|
|
2022-10-15 18:06:01 +02:00
|
|
|
public void setCallback(@Nullable GattCallback callback) {
|
2015-08-05 23:24:58 +02:00
|
|
|
gattCallback = callback;
|
2022-10-22 23:00:01 +02:00
|
|
|
modifyGattCallback = true;
|
2015-08-05 23:24:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the GattCallback for this transaction, or null if none.
|
|
|
|
*/
|
2015-09-24 14:45:21 +02:00
|
|
|
public
|
|
|
|
@Nullable
|
|
|
|
GattCallback getGattCallback() {
|
2015-08-05 23:24:58 +02:00
|
|
|
return gattCallback;
|
|
|
|
}
|
2019-02-27 09:21:41 +01:00
|
|
|
|
2022-10-22 23:00:01 +02:00
|
|
|
/**
|
|
|
|
* Returns whether the gatt callback should be modified for this transaction (either set, or
|
|
|
|
* unset if {@code getGattCallback} is null.
|
|
|
|
*/
|
|
|
|
public boolean isModifyGattCallback() {
|
|
|
|
return modifyGattCallback;
|
|
|
|
}
|
|
|
|
|
2019-02-27 09:21:41 +01:00
|
|
|
@Override
|
2019-02-27 19:07:53 +01:00
|
|
|
public int getActionCount() {
|
2019-02-27 09:21:41 +01:00
|
|
|
return mActions.size();
|
|
|
|
}
|
2015-04-19 02:37:29 +02:00
|
|
|
}
|