Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New API to handle LWM2M Data. #981

Open
sbernard31 opened this issue Mar 9, 2021 · 3 comments
Open

New API to handle LWM2M Data. #981

sbernard31 opened this issue Mar 9, 2021 · 3 comments
Labels
core Impact core of Leshan housekeeping Refactoring, cleaning code or API

Comments

@sbernard31
Copy link
Contributor

The current Leshan API to handle LWM2M Data is based on those classes :

The data structure is a kind of Tree :

Root
    ├── Object
    │   └── ObjectInstance
    │       ├── MultipleResource 
    │       │   ├── ResourceInstance
    │       │   └── ResourceInstance
    │       └── SingleResource
    └── Object
        ├── ObjectInstance
        │   ├── SingleResource
        │   └── SingleResource
        └── ObjectInstance
            ├── SingleResource
            └── ...
    └── ...

This designed was mainly inspired by the LWM2M Resource Model and also by the first multi-value Data format : TLV.

This was not a eccentric idea but at usage the current API is a bit verbose and maybe we could do better.

At current stage this is only an idea but maybe we should move from "the tree model" to a "path->value model". This would be more inspired by the SENML DataFormat.

But using the same idea as TreeMap we could still keep the Tree hierarchy with a more comfortable way to access data by path.

The new API could looks like :

public class LwM2mData implements Iterable<Entry<LwM2mPath, LwM2mValue> {
    //e.g. from "/3/0/2" to "/3/0/10 or for composite data from /2 to /3
    LwM2mData getValues(String from, String to); 
    LwM2mData getValues(String objectOrInstanceOrMultiResourcePath); 
    LwM2mValue getValue(String singleResourceOrResourceInstancePath);
    Lwm2mNode getNode(String nodePath); // for backward compatibility
}
public class LwM2mValue {

    Type value.getType()
    Object value.getValue()
}

(I guess implementation will be based on TreeMap )

@sbernard31 sbernard31 added new feature New feature from LWM2M specification client Impact LWM2M client server Impact LWM2M server bsserver Impact LWM2M bootstrap server labels Mar 9, 2021
@sbernard31
Copy link
Contributor Author

This is something I have in mind since a long time ago but API issues raised by Read-Composite(#958), Write-Composite(#959) and Send-Operation(#971) make feel that maybe this could be the right move.

@sbernard31 sbernard31 added core Impact core of Leshan housekeeping Refactoring, cleaning code or API and removed bsserver Impact LWM2M bootstrap server client Impact LWM2M client new feature New feature from LWM2M specification server Impact LWM2M server labels Jul 1, 2021
@sbernard31 sbernard31 added this to the 2.0.0 milestone Jul 1, 2021
@Michal-Wadowski
Copy link
Contributor

Michal-Wadowski commented Feb 11, 2022

In current implementation we have interface LwM2mResource which provide a few methods that are implemented with NoSuchElementException. What do you think to split LwM2mResource into separate interfaces that allow to avoid sub implementation. For example we can split current LwM2mResource interface into:

interface LwM2mResource extends LwM2mNode {
  Type getType();
}

interface LwM2mSingleResource extends LwM2mResource {
  Object getValue();
}

interface LwM2mMultipleResource extends LwM2mResource {
  Object getValue(int id);
  LwM2mResourceInstance getInstance(int id);
  Map<Integer, LwM2mResourceInstance> getInstances();
}

We can drop isMultiInstances() method because we can distinguish between LwM2mSingleResource and LwM2mMultipleResource using instanceof. In that way we can add other interfaces that helps to handle timestamps (#1192).

@sbernard31
Copy link
Contributor Author

I guess this was mainly to avoid some instanceof / cast ?
Hard to me to know if this is something which should be removed or not. 🤔

In that way we can add other interfaces that helps to handle timestamps

As explained in #1192 (comment)
I think the LwM2mNode hierarchy should really match the LWM2M Object Tree concept so don't sure to see how it could allow to add timestamped value.

I feel this is not directly linked to the new LwM2mData, so if you want to talk more about this maybe we should create a dedicated issue ?

@sbernard31 sbernard31 removed this from the 2.0.0 milestone Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Impact core of Leshan housekeeping Refactoring, cleaning code or API
Projects
None yet
Development

No branches or pull requests

2 participants