User Tools

Site Tools


native-libraries

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
native-libraries [2018/08/02 05:13]
barryfp
native-libraries [2018/08/09 06:21] (current)
barryfp
Line 18: Line 18:
  
 <code d> <code d>
-library ​interface MyLib{+interface MyLib{
    void libFunction()    void libFunction()
    }    }
  
-component provides MyWrapper, Service ​requires ​NativeLoader loader ​+component provides MyWrapper requires ​native MyLib myLib 
-   static library MyLib myLib +    
-   implementation MyWrapper { +   void MyWrapper:​doSomething() { 
-      ​void MyWrapper:​doSomething() { +      myLib.libFunction()
-         ​myLib.libFunction() +
-         } +
-      } +
- +
-   ​implementation Service { +
-      void Service:​start() { +
-         myLib = new MyLib() from loader.load("​mylib"​) :< MyLib +
-         } +
- +
-      void Service:​stop() { +
-         }+
       }       }
 +   
    }    }
 </​code>​ </​code>​
Line 45: Line 35:
 Finally we create the native library itself. Finally we create the native library itself.
  
-Create a new file mylib.c in the libraries repository. In this file, write the following code:+Create a new file MyLib.c in the libraries repository. In this file, write the following code:
  
 <code c> <code c>
Line 82: Line 72:
 </​code>​ </​code>​
  
-Assuming that you saved your component in a file called MyWrapper.dn. This will create a new text file called MyLib_dni.c. Copy this file to the libraries repository (i.e. the same folder as your library code).+Assuming that you saved your component in a file called MyWrapper.dn. This will create a new text file called MyLib_dni.c. Copy this file to the libraries repository (i.e. the same folder as your library code). You will need to re-run the above compiler command any time you change the definition of the interface type which interacts with the native library.
 Now we create a makerule for this library in the Makefile of the libraries repository. Open Makefile in a text editor and add the rule: Now we create a makerule for this library in the Makefile of the libraries repository. Open Makefile in a text editor and add the rule:
  
 <​code>​ <​code>​
 my_new_lib: my_new_lib:
- $(CC) -Os -s MyLib_dni.c vmi_util.c ​mylib.c -o mylib[$(PLATFORM).$(CHIP)].dnl $(STD_INCLUDE) $(CCFLAGS) + $(CC) -Os -s MyLib_dni.c vmi_util.c ​MyLib.c -o MyLib[$(PLATFORM).$(CHIP)].dnl $(STD_INCLUDE) $(CCFLAGS) 
- $(CP_CMD) ​mylib[$(PLATFORM).$(CHIP)].dnl "​$(DANA_HOME)/​resources-ext"​+ $(CP_CMD) ​MyLib[$(PLATFORM).$(CHIP)].dnl "​$(DANA_HOME)/​resources-ext"​
 </​code>​ </​code>​
  
Line 97: Line 87:
 </​code>​ </​code>​
  
-Now, if you write a quick test program to call your wrapper component'​s doSomething() function, you should see the text printed from the native library. Simple :-)+Now, if you write a quick test program to call your wrapper component'​s ​''​doSomething()'' ​function, you should see the text printed from the native library. Simple :-)
  
 The creation of every native library follows the same procedure. The creation of every native library follows the same procedure.
Line 108: Line 98:
  
 <code d> <code d>
-library ​interface MyLib{+interface MyLib{
    void libFunction(char input[], int value)    void libFunction(char input[], int value)
    }    }
Line 133: Line 123:
  
 <code d> <code d>
-library ​interface MyLib{+interface MyLib{
    ​char[] libFunction(char input[], int value)    ​char[] libFunction(char input[], int value)
    }    }
native-libraries.txt · Last modified: 2018/08/09 06:21 by barryfp