SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
Python Bindings for the SAF-AIS APIs

                      Currie Reid
                     Linux Product Division
                          Wind River
Outline of Presentation

•   Requirements
•   What is Python?
•   Mapping Python to Requirements
•   Demo setup
•   How Python bindings are implemented
•   Demonstration
•   Future Works
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.
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.
Enable testing in all phases of software
lifecycle
• 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.
Simplify development across different
architectures
• 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.
Simplify presentation to developers and
engineers
• 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.
Make it easy to create and modify
prototypes
• 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.
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.
Explanation of Demonstration System

•   Virtual appliance; 2 system controllers
•   OpenSAF framework
•   Amf_demo: saAmf, saLog
•   Immwebsocket: saImmOm, saNtf
•   Immwebclient: HTML5 websockets, CSS,
    Javascript, JSON
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.
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
Conversion of SAF types to ctypes

SaInt8T     =   c_char
SaInt16T    =   c_short
SaInt32T    =   c_int
SaInt64T    =   c_longlong
SaUint8T    =   c_ubyte
SaUint16T   =   c_ushort
SaUint32T   =   c_uint
SaUint64T   =   c_ulonglong
...

myuint = SaUint64T(12)
Definition of Const

saAis = Const()

saAis.SA_TIME_END = 0x7FFFFFFFFFFFFFFF
saAis.SA_TIME_BEGIN = 0x0
saAis.SA_TIME_UNKNOWN = 0x8000000000000000




time_start = saAis.SA_TIME_BEGIN
saAis.SA_TIME_BEGIN = 5 #ERROR: EXCEPTION
Definition of Enumeration

SaDispatchFlagsT = SaEnumT
eSaDispatchFlagsT = Enumeration((
  ('SA_DISPATCH_ONE', 1),
  ('SA_DISPATCH_ALL', 2),
  ('SA_DISPATCH_BLOCKING', 3),
))




flag = eSaDispatchFlagsT.SA_DISPATCH_ALL
flag_str = eSaDispatchFlagsT.whatis(flag)
Definition of Structs
class 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’)
Definition of Unions

class SaLimitValueT(Union):
   _fields_ = [('int64Value', SaInt64T),
      ('uint64Value', SaUint64T),
      ('timeValue', SaTimeT),
      ('floatValue', SaFloatT),
      ('doubleValue', SaDoubleT)]




un = SaLimitValueT()
un.timeValue = 5000000000
Dynamic Loading of Libraries and CDLL

amfdll = CDLL('libSaAmf.so.0')




amfHandle = SaAmfHandleT()
amfCallbacks = None
version = SaVersionT(‘B’, 1, 1)

rc = saAmfInitialize(amfHandle,
   amfCallbacks, version)
Definition of Functions

def saAmfInitialize(amfHandle,
   amfCallbacks, version):




  return amfdll.saAmfInitialize(
    BYREF(amfHandle),
    BYREF(amfCallbacks),
    BYREF(version))
Definition of callbacks and CFUNCTYPE

SaAmfCSISetCallbackT = CFUNCTYPE(None,
   SaInvocationT, POINTER(SaNameT),
   SaAmfHAStateT, SaAmfCSIDescriptorT)

def myCSISetCallback(invoc,
   comp, hastate, descr):
   …
callbacks = SaAmfCallbacksT()
callbacks.saAmfCSISetCallbackT(
   SaAmfCSISetCallbackT(myCSISetCallback))
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.
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.
Questions?

Contenu connexe

En vedette

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

En vedette (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Python Bindings for the SAF-AIS APIs 5.18.2011

  • 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 software lifecycle • 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 different architectures • 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 and engineers • 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 modify prototypes • 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 ctypes SaInt8T = c_char SaInt16T = c_short SaInt32T = c_int SaInt64T = c_longlong SaUint8T = c_ubyte SaUint16T = c_ushort SaUint32T = c_uint SaUint64T = c_ulonglong ... myuint = SaUint64T(12)
  • 14. Definition of Const saAis = Const() saAis.SA_TIME_END = 0x7FFFFFFFFFFFFFFF saAis.SA_TIME_BEGIN = 0x0 saAis.SA_TIME_UNKNOWN = 0x8000000000000000 time_start = saAis.SA_TIME_BEGIN saAis.SA_TIME_BEGIN = 5 #ERROR: EXCEPTION
  • 15. Definition of Enumeration SaDispatchFlagsT = SaEnumT eSaDispatchFlagsT = Enumeration(( ('SA_DISPATCH_ONE', 1), ('SA_DISPATCH_ALL', 2), ('SA_DISPATCH_BLOCKING', 3), )) flag = eSaDispatchFlagsT.SA_DISPATCH_ALL flag_str = eSaDispatchFlagsT.whatis(flag)
  • 16. Definition of Structs class 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 Unions class SaLimitValueT(Union): _fields_ = [('int64Value', SaInt64T), ('uint64Value', SaUint64T), ('timeValue', SaTimeT), ('floatValue', SaFloatT), ('doubleValue', SaDoubleT)] un = SaLimitValueT() un.timeValue = 5000000000
  • 18. Dynamic Loading of Libraries and CDLL amfdll = CDLL('libSaAmf.so.0') amfHandle = SaAmfHandleT() amfCallbacks = None version = SaVersionT(‘B’, 1, 1) rc = saAmfInitialize(amfHandle, amfCallbacks, version)
  • 19. Definition of Functions def saAmfInitialize(amfHandle, amfCallbacks, version): return amfdll.saAmfInitialize( BYREF(amfHandle), BYREF(amfCallbacks), BYREF(version))
  • 20. Definition of callbacks and CFUNCTYPE SaAmfCSISetCallbackT = 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.