Your SlideShare is downloading. ×
0
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Python Bindings for the SAF-AIS APIs 5.18.2011
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Python Bindings for the SAF-AIS APIs 5.18.2011

3,496

Published on

Python bindings for SAF-AIS APIs offer many advantages to middleware developers, application developers, tool developers and testers. The bindings help to speed up the software development lifecycle …

Python bindings for SAF-AIS APIs offer many advantages to middleware developers, application developers, tool developers and testers. The bindings help to speed up the software development lifecycle and enable rapid deployment of architecture-independent components and services.

This session will describe main principles guiding Python bindings implementation, and will have extensive in-depth application Python code examples using SAF-AIS services.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
3,496
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
22
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Python Bindings for the SAF-AIS APIs Currie Reid Linux Product Division Wind River
  • 2. Outline of Presentation• Requirements• What is Python?• Mapping Python to Requirements• Demo setup• How Python bindings are implemented• Demonstration• Future Works
  • 3. Requirements• Enable testing in all phases of the software lifecycle.• Simplify development across different architectures.• Simplify presentation to developers and engineers.• Quickly create tools that make it easy to investigate and monitor the system.• Make it easy to create and modify prototypes.
  • 4. What is Python?• General purpose, high-level, interpreted language.• Design philosophy emphasizes code readability.• Large, comprehensive standard library.• Supports object-oriented, imperative, and (lesser degree) functional programming paradigms.• Dynamic type system, automatic memory management.• Free, open-source, many 3rd party packages.
  • 5. Enable testing in all phases of softwarelifecycle• Test coverage more complete if easy to write tests; test-driven development encouraged!• Tests are portable across architectures.• Built-in modules for testing include unittest and doctest.• Modules available for unit testing, mock testing, fuzz testing, web testing, gui testing, etc.• i.e.: nose, py.test, zope.testing.
  • 6. Simplify development across differentarchitectures• Python scripts are portable across different architectures.• Edit-compile-run cycle is greatly reduced.• Python code can be edited on the target system if required.• Huge collection of native and 3rd-party bindings available to aid/speed development.
  • 7. Simplify presentation to developers andengineers• Python syntax reads like pseudo-code.• Most Python programs much smaller than lower- level implementations.• Easier to examine the problem domain when you abstract-away programming details and challenges associated with the machine.
  • 8. Make it easy to create and modifyprototypes• Components and applications can be rapidly prototyped in Python.• Designs can then be hardened in another implementation language.• Ideal glue language.• Working code can be developed much faster than lower-level languages.
  • 9. What Will be Demonstrated• Unit tests written for every interface except SMF.• AMF demo component written in Python.• Admin-commands written in Python.• Server implemented in Python: receives NTF notifications, queries IMM and updates web- client.• Alarms resulting from admin-commands.• Logging from AMF demo component.
  • 10. Explanation of Demonstration System• Virtual appliance; 2 system controllers• OpenSAF framework• Amf_demo: saAmf, saLog• Immwebsocket: saImmOm, saNtf• Immwebclient: HTML5 websockets, CSS, Javascript, JSON
  • 11. Ctypes module: Wrap Libraries in Python• Advanced FFI (Foreign Function Interface) for Python 2.3 and higher.• Included in Python 2.5.• Call functions from DLLs (shared libraries).• Create, access and manipulate simple and complicated C data types in Python.• Enables C callbacks to be implemented in Python.
  • 12. Python Implementation• Conversion of SAF types to ctypes• Definition of Const• Definition of Enumeration• Definition of Structs• Definition of Unions• Dynamic Loading of Libraries and CDLL• Definition of Functions• Definition of callbacks and CFUNCTYPE
  • 13. Conversion of SAF types to ctypesSaInt8T = c_charSaInt16T = c_shortSaInt32T = c_intSaInt64T = c_longlongSaUint8T = c_ubyteSaUint16T = c_ushortSaUint32T = c_uintSaUint64T = c_ulonglong...myuint = SaUint64T(12)
  • 14. Definition of ConstsaAis = Const()saAis.SA_TIME_END = 0x7FFFFFFFFFFFFFFFsaAis.SA_TIME_BEGIN = 0x0saAis.SA_TIME_UNKNOWN = 0x8000000000000000time_start = saAis.SA_TIME_BEGINsaAis.SA_TIME_BEGIN = 5 #ERROR: EXCEPTION
  • 15. Definition of EnumerationSaDispatchFlagsT = SaEnumTeSaDispatchFlagsT = Enumeration(( (SA_DISPATCH_ONE, 1), (SA_DISPATCH_ALL, 2), (SA_DISPATCH_BLOCKING, 3),))flag = eSaDispatchFlagsT.SA_DISPATCH_ALLflag_str = eSaDispatchFlagsT.whatis(flag)
  • 16. Definition of Structsclass SaNameT(Structure): _fields_ = [(length, SaUint16T), (value,(SaInt8T*saAis.SA_MAX_NAME_LENGTH))] def __init__(self, name=): super(SaNameT, self).__init__(len(name), name)dn = SaNameT(‘safApp=OpenSAF’)
  • 17. Definition of Unionsclass SaLimitValueT(Union): _fields_ = [(int64Value, SaInt64T), (uint64Value, SaUint64T), (timeValue, SaTimeT), (floatValue, SaFloatT), (doubleValue, SaDoubleT)]un = SaLimitValueT()un.timeValue = 5000000000
  • 18. Dynamic Loading of Libraries and CDLLamfdll = CDLL(libSaAmf.so.0)amfHandle = SaAmfHandleT()amfCallbacks = Noneversion = SaVersionT(‘B’, 1, 1)rc = saAmfInitialize(amfHandle, amfCallbacks, version)
  • 19. Definition of Functionsdef saAmfInitialize(amfHandle, amfCallbacks, version): return amfdll.saAmfInitialize( BYREF(amfHandle), BYREF(amfCallbacks), BYREF(version))
  • 20. Definition of callbacks and CFUNCTYPESaAmfCSISetCallbackT = CFUNCTYPE(None, SaInvocationT, POINTER(SaNameT), SaAmfHAStateT, SaAmfCSIDescriptorT)def myCSISetCallback(invoc, comp, hastate, descr): …callbacks = SaAmfCallbacksT()callbacks.saAmfCSISetCallbackT( SaAmfCSISetCallbackT(myCSISetCallback))
  • 21. Concluding Demonstations• Unit tests written for every interface except SMF.• AMF demo component written in Python.• Admin-commands written in Python.• Server implemented in Python: receives NTF notification, queries IMM and updates web- client.• Alarms resulting from admin-commands.• Logging from AMF demo component.
  • 22. Future Work• Complete unit tests for all interfaces.• Bind Python admin-commands into CLI.• Complete SMF bindings.• Create more tools to enhance system useability.• Consider Pythonic interfaces, similar as what was done for Java.• Consider code-generation for Python bindings.• Consider compiled Python: Cython, Psyco, etc.
  • 23. Questions?

×