Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,23 @@ t = Thread(target=client.listen)
t.start()
```

The client supports setting a custom generator that produces sequence numbers for the PDU packages. Per default a simple in memory generator is used which in conclusion is reset on (re)instantiation of the client, e.g. by an application restart. If you want to keep the sequence number to be persisted across restarts you can implement your own storage backed generator.
A simple in memory generator that produces sequence numbers for the PDU packages is used, which is reset on (re)instantiation of the client, e.g. by an application restart. It starts by default with sequence number 0x00000001 but you may set the starting sequence yourself by declaring the generator beforehand and passing it to the Client:
```python
import smpplib.client

generator = smpplib.client.SimpleSequenceGenerator(start_sequence=1234)
client = smpplib.client.Client('example.com', SOMEPORTNUMBER, sequence_generator=generator)
...
```

Example:

The client supports setting a custom generator, so if you need more/different features associated with it, you can implement your own:
```python
import smpplib.client

import mymodule

generator = mymodule.PersistentSequenceGenerator()
generator = mymodule.MyAwesomeSequenceGenerator()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please elaborate a little about the interface such a Generator has to have

Copy link
Member

@code-of-kpp code-of-kpp Aug 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't have time for this, also please let us know and @eigenein will merge it as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@podshumok @eigenein Feel free to add this info to the readme if you wish, I don't think I will have time to.

client = smpplib.client.Client('example.com', SOMEPORTNUMBER, sequence_generator=generator)
...
```
15 changes: 13 additions & 2 deletions smpplib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,19 @@ class SimpleSequenceGenerator(object):
MIN_SEQUENCE = 0x00000001
MAX_SEQUENCE = 0x7FFFFFFF

def __init__(self):
self._sequence = self.MIN_SEQUENCE
def __init__(self, start_sequence=None):
if start_sequence is not None:
if not isinstance(start_sequence, int):
raise TypeError('start_sequence must be an int, {} provided'.format(
type(start_sequence)
))
if start_sequence < self.MIN_SEQUENCE or start_sequence > self.MAX_SEQUENCE:
raise ValueError('start_sequence must be between {} and {}'.format(
self.MIN_SEQUENCE, self.MAX_SEQUENCE
))
self._sequence = start_sequence
else:
self._sequence = self.MIN_SEQUENCE

@property
def sequence(self):
Expand Down