repo_name
stringlengths
6
97
path
stringlengths
3
341
text
stringlengths
8
1.02M
TheBadZhang/OJ
usx/special/60/6058.c
#include <string.h> #include <stdio.h> #include <ctype.h> int main () { int n; char str[100]; char sstr [300] = { '\0' }; while (gets(sstr)) { int l = strlen (sstr); int i = 0; int inWord = 0; int words = 0; char maxword[100] = {0}; char word[100] = {0}; for (n = 0; n <= l; n++) { if (isalpha (sstr[n])) { word[i++] = sstr[n]; inWord = 1; } else { if (inWord) { if (strlen (word) > strlen (maxword)) { strcpy (maxword, word); } } memset (word, 0, 100*sizeof(char)); i = 0; inWord = 0; } } printf ("%s\n", maxword); memset (sstr, 0, 300*sizeof(char)); memset (maxword, 0, 100*sizeof(char)); } return 0; }
TheBadZhang/OJ
usx/special/60/6055.c
#include <stdio.h> void strcpy (char* dst, char* src) { while (*dst++ = *src++); } int main () { char str [100]; char dst_str [100]; while (gets (str) != NULL) { strcpy (dst_str, str); printf ("%s\n", dst_str); } }
TheBadZhang/OJ
usx/special/91/9115.c
#include <stdio.h> int main () { int a; scanf ("%d", &a); printf ("%d", (1+a)*a/2); return 0; }
TheBadZhang/OJ
usx/special/60/6007.c
#include <stdio.h> #include <math.h> #define min(a,b) (a<b?a:b) int main () { int a, b, c, d, e; while (~scanf("%d%d%d%d%d", &a, &b, &c, &d, &e)) { printf ("%d\n", min(a,min(b,min(c,min(d,e))))); } return 0; }
TheBadZhang/OJ
usx/special/60/6053.c
<reponame>TheBadZhang/OJ<filename>usx/special/60/6053.c #include <stdio.h> int main () { int n, m; double s[11][8]; int a, b; while (~scanf("%d%d", &a, &b)) { double sum = 0; int maxn = 0, maxm = 1; for (n = 0; n < a; n++) { scanf ("%lf", &s[n][0]); for (m = 1; m < b+1; m++) { scanf ("%lf", &s[n][m]); if (s[n][m] > s[maxn][maxm]) { maxn = n; maxm = m; } sum += s[n][m]; } } printf ("%.0lf %d\n", s[maxn][0], maxm); for (n = 0; n < a; n++) { int flag = 0; for (m = 1; m < b+1; m++) { if (s[n][m] < 60.0) { flag = 1; } } if (flag) { printf ("%.0lf", s[n][0]); for (m = 1; m < b+1; m++) { printf (" %.1lf", s[n][m]); } printf ("\n"); } } printf ("%.2lf\n", sum/(a*b)); } return 0; }
TheBadZhang/OJ
usx/special/60/6050.c
#include <stdio.h> #include <string.h> int main () { char str[100]; while (gets(str)) { int i, l = strlen (str); char ch; scanf ("%c\n", &ch); for (i = 0; i < l; i++) { if (str[i] != ch) printf ("%c", str[i]); } printf ("\n"); } return 0; }
TheBadZhang/OJ
usx/special/60/6027.c
#include <stdio.h> int main () { int n, a, b, t; double s = 0.0; double ar [22]; for (a = 2, b = 1, n = 0; n<20;++n) { s += (double)a/(double)b; ar [n] = s; t = a; a += b; b = t; } while (~scanf("%d", &n)) { printf ("%.6lf\n", ar[n-1]); } return 0; }
TheBadZhang/OJ
usx/special/92/9201.c
#include <stdio.h> int main () { int i; while (~scanf ("%d", &i)) { if (i > 0) { printf ("+\n"); } else { printf ("-\n"); } } return 0; }
TheBadZhang/OJ
usx/special/60/6080.c
<filename>usx/special/60/6080.c<gh_stars>1-10 #include <stdio.h> #include <string.h> void substr (char *str, int pos) { int i = 0, size = strlen (str); for (i = 0; i < size; i++) { if (pos+i <= size) { putchar (str[pos-1+i]); } else { break; } } putchar ('\n'); } int main () { char str[160]; int i; while (gets (str) != NULL) { scanf ("%d", &i); substr (str, i); getchar (); } return 0; }
TheBadZhang/OJ
usx/special/60/6026.c
#include <stdio.h> int main () { int i, t, s; for (i = 2; i < 10000; ++i) { for (s = 0, t = 1; t < i; t++) { if (i%t == 0) { s += t; } } if (i == s) { printf ("%d its factors are ", i); printf ("1"); for (s = 0, t = 2; t < i; t++) { if (i%t == 0) { printf (",%d", t); } } printf ("\n"); } } return 0; }
TheBadZhang/OJ
usx/special/60/6008.c
#include <stdio.h> #include <float.h> int main () { int i; float min=FLT_MIN, t; while (~scanf ("%f", &min)) { for (i = 0; i < 9; ++i) { scanf ("%f", &t); if (t > min) { min = t; } } printf ("%.6f\n", min); } return 0; }
TheBadZhang/OJ
usx/special/92/9213.c
#include <stdio.h> void swap (int* a, int* b) { int t = *a; *a = *b; *b = t; } int main () { int a, b, c, d; while (~scanf ("%d %d %d %d", &a, &b, &c, &d)) { if (a > b) swap (&a, &b); if (a > c) swap (&a, &c); if (a > d) swap (&a, &d); if (b > c) swap (&b, &c); if (b > d) swap (&b, &d); if (c > d) swap (&c, &d); printf ("%d %d %d %d\n", a, b, c, d); } return 0; }
TheBadZhang/OJ
usx/special/60/6037.c
#include <stdio.h> int main () { double max, min, t; int n, i; double list [100]; while (~scanf ("%d", &n)) { // 处理多组输入 for (i = 0; i < n; i ++) { scanf ("%lf", &list[i]); // 输入数据到数组 } max = min = list [0]; for (i = 0; i < n; i ++) { // 遍历数组 if (list[i] > max) { max = list[i]; // 比较、找出最大值 } if (list[i] < min) { min = list[i]; // 比较、找出最小值 } } printf ("%.6lf %.6lf\n", max, min); // 输出 } return 0; }
TheBadZhang/OJ
usx/special/60/6017.c
#include <stdio.h> int main () { unsigned int N [60] = { 1, 1, 1 }; int i; for (i = 3; i < 30; i++) { N [i] = N [i-1] + N [i-3]; } while (~scanf("%d", &i)) { printf ("%d\n", N[i-1]); } return 0; }
TheBadZhang/OJ
usx/special/92/9204.c
<filename>usx/special/92/9204.c #include <stdio.h> void swap (int* a, int* b) { int t = *a; *a = *b; *b = t; } int main () { int a, b, c; while (~scanf ("%d%d%d", &a, &b, &c)) { if (a > b) { swap (&a, &b); } if (a > c) { swap (&a, &c); } if (b > c) { swap (&b, &c); } printf ("%d %d %d\n", a, b, c); } return 0; }
TheBadZhang/OJ
usx/special/60/6061.c
<gh_stars>1-10 #include <stdio.h> int main () { int n; while (~scanf ("%d", &n)) printf ("%d\n", n); return 0; }
TheBadZhang/OJ
usx/special/60/6020.c
#include <stdio.h> #include <math.h> char isPrim (int a) { if (a&1) { int i; for (i = 3; i <= sqrt (a); ++i) { if (a%i == 0) { return 0; } } return 1; } else { return 0; } } int main () { int n; for (n = -39; n <= 40; ++n) { if (!isPrim(n*n-n+41)) { printf ("NO\n"); return 0; } } printf ("YES\n"); return 0; }
TheBadZhang/OJ
usx/special/60/6067.c
<gh_stars>1-10 #include <stdio.h> #include <string.h> #include <ctype.h> int hex2oct (char ch) { int number; if (isdigit (ch)) { number = ch - '0'; } else { number = ch - 'A' + 10; } return number; } int main () { char str[10]; while (~scanf ("%s", str)) { int number = 0; int negtive = 1; int i, s = 0, size = strlen (str); if (str[0] == '-') { negtive = -1; s = 1; } for (i = s; i < size; i++) { number *= 16; number += hex2oct (str[i]); } printf ("%d\n", number * negtive); } return 0; }
TheBadZhang/OJ
usx/special/60/6048.c
#include <stdio.h> int main () { int n; while (~scanf ("%d", &n)) { // 处理多组输入 int i, j; int matrix[100][100]; // 定义一个矩阵(二维数组) for (i = 0; i < n; i ++) { for (j = 0; j < n; j ++) { scanf ("%d", &matrix[i][j]); // 向矩阵输入数据 } } int mainSum = 0, sideSum = 0; // 主对角线和副对角线和 for (i = 0; i < n; i ++) { mainSum += matrix [i][i]; sideSum += matrix [i][n-i-1]; } // 输出结果 printf ("%d %d\n", mainSum, sideSum); } return 0; }
TheBadZhang/OJ
usx/special/60/6071.c
<filename>usx/special/60/6071.c #include <stdio.h> void swap (int** pa, int** pb) { int* pt = *pa; *pa = *pb; *pb = pt; } int main () { int a, b, c; while (~scanf ("%d %d %d", &a, &b, &c)) { int *max = &a, *mid = &b, *min = &c; if (*max < *mid) swap (&max, &mid); if (*max < *min) swap (&max, &min); if (*mid < *min) swap (&mid, &min); printf ("%d %d %d\n", *max, *mid, *min); } return 0; }
TheBadZhang/OJ
usx/special/92/9220.c
#include <stdio.h> int main () { int n, c; while (~scanf ("%d", &n)) { c = 0; while (n>0) { if (n%10 == 4) c ++; n /= 10; } printf ("%d\n", c); } return 0; }
TheBadZhang/OJ
usx/special/60/6090-2.c
<gh_stars>1-10 #include <stdio.h> #include <string.h> #include <stdlib.h> typedef struct { char id[20]; double salary; } employer; int main () { int n, i; char id[20]; employer em[100]; while (~scanf ("%d", &n)) { for (i=0; i < n; i++) { scanf ("%s %lf", em[i].id, &em[i].salary); } scanf ("%s", id); for (i=0; i < n; i++) { if (strcmp (em[i].id, id) != 0) printf ("%s %.2lf\n", em[i].id, em[i].salary); } } return 0; }
TheBadZhang/OJ
usx/special/91/9110.c
#include <stdio.h> int main () { int a = 50, b = 43, c = 13; // scanf ("%d %d %d", &a, &b, &c); b += a/3; c += a/3; a = a/3+a%3; a += b/3; c += b/3; b = b/3+b%3; a += c/3; b += c/3; c = c/3+c%3; printf ("%d %d %d", a, b, c); return 0; }
TheBadZhang/OJ
usx/special/92/9219.c
<gh_stars>1-10 #include <stdio.h> #include <math.h> int main () { int m, n, i, flag, a, b, c; while (~scanf ("%d %d", &m, &n)) { flag = 0; for (i = m; i <= n; i++) { a = i/100; b = (i/10)%10; c = i%10; if (i == a*a*a+b*b*b+c*c*c) { flag = 1; printf ("%d,", i); } } if (!flag) { printf ("no"); } printf ("\n"); } return 0; }
TheBadZhang/OJ
hdu/2000/20xx/2032.c
#include <stdio.h> unsigned long long int list [600]; // 放在全局变量可以自动初始化为 0 int main () { int i, j, k, n, d; for (i = 1, j = 2; i < 600; i += j, j++) { list [i] = 1; list [i-1] = 1; // 将杨辉三角的两边的 1 初始化 for (k = i + 1; k < i+j; k++) { list [k] = list[k-j] + list[k-j+1]; // 计算杨辉三角 } } bool flag = false; while (~scanf("%d", &n)) { // 从单列杨辉三角输出成二维杨辉三角 j = 1; k =0; d = 0; for (i = 0; d < n; i++) { if (j != 1) printf (" "); printf ("%d", list[i]); if (j > k) { printf ("\n"); d ++; k = j; j = 0; } j ++; } printf ("\n"); } return 0; }
TheBadZhang/OJ
usx/special/60/6077.c
#include <stdio.h> void swap (int* a, int* b) { int c = *a; *a = *b; *b = c; } void change (int* l, int n) { int min = 0, max = 0, i; for (i = 0; i < n; i++) { if (l[i] > l[max]) max = i; if (l[i] < l[min]) min = i; } if (max == 0 && min == n-1) { swap (&l[max], &l[min]); } else if (max == 0) { max = min; swap (&l[0], &l[min]); swap (&l[max], &l[n-1]); } else if (min == n-1) { min = max; swap (&l[max], &l[n-1]); swap (&l[0], &l[min]); } else { swap (&l[max], &l[n-1]); swap (&l[0], &l[min]); } } int main () { int l[40]; int n, i; while (~scanf ("%d", &n)) { for (i = 0; i < n; i++) { scanf ("%d", &l[i]); } change (l, n); for (i = 0; i < n; i++) { if (i) printf (" "); printf ("%d", l[i]); } printf ("\n"); } return 0; }
TheBadZhang/OJ
usx/special/60/6022.c
<reponame>TheBadZhang/OJ #include <stdio.h> #include <ctype.h> int space, chars, number, other; void count (char ch) { if (isdigit(ch)) { number ++; } else if (isalpha (ch)) { chars ++; } else if (ch == ' ') { space ++; } else { other ++; } } int main () { char ch, a[128]; int i, l; // while (~scanf("%c", &ch)) { while (gets(a)) { space = 0; chars = 0; number = 0; other = 0; l = strlen (a); // count (ch); // while ((ch = getchar ()) != '\n' && ch != EOF) { // count (ch); // } for (i = 0; i < l; ++i) { count (a[i]); } printf ("%d %d %d %d\n", chars, space, number, other); } return 0; }
TheBadZhang/OJ
usx/special/91/9105.c
<reponame>TheBadZhang/OJ #include <stdio.h> int main () { double ch, math, en, sci, sum; scanf ("%lf %lf %lf %lf", &ch, &math, &en, &sci); sum = ch+math+en+sci; printf ("%.1lf\n%.2lf", sum, sum/4); return 0; }
TheBadZhang/OJ
usx/special/60/6060.c
<filename>usx/special/60/6060.c #include <stdio.h> #include <math.h> int isPrime (int n) { if (n == 2) return 1; if (n&1) { int i; for (i = 3; i <= sqrt (n); i++) { if (n % i == 0) return 0; } return 1; } else return 0; } int main () { int n; while (~scanf ("%d", &n)) { int i = 2; int flag = 0; printf ("%d=",n); while (n/i>1) { // printf ("%d %d\n", n, i); if (isPrime (n)) { if (flag) printf ("*"); printf ("%d", n); i = n; } else { if (isPrime (i) && n%i == 0) { if (flag) printf ("*"); printf ("%d", i); flag = 1; n /= i; } else { i ++; } } } printf ("\n"); } }
TheBadZhang/OJ
usx/special/60/6003.c
<filename>usx/special/60/6003.c #include <stdio.h> #include <math.h> int main () { printf ("%.4f\n%.4f\n%.4f\n", cos(3.5678), log10(90), exp(2.567)); return 0; }
TheBadZhang/OJ
usx/special/60/6062.c
<gh_stars>1-10 #include <stdio.h> int gcd (int m, int n) { return m%n?gcd(n,m%n):n; } int lcm (int m, int n) { return m*n/gcd(m,n); } int main () { int n, m; while (~scanf ("%d %d", &n, &m)) { printf ("%d %d\n", gcd (m,n), lcm(m,n)); } return 0; }
TheBadZhang/OJ
usx/special/60/6063.c
#include <stdio.h> #include <math.h> int main () { double a, b, c; while (~scanf ("%lf %lf %lf", &a, &b, &c)) { double delta = b*b - 4 * a * c; if (fabs(delta) < 1e-6) { printf ("x=%.6lf\n", -b/2/a); } else if (delta < 0) { printf ("x1=%.6lf%+.6lfi x2=%.6lf%-.6lfi\n", -b/2/a, sqrt(-delta)/2/a,-b/2/a,-sqrt(-delta)/2/a); } else { printf ("x1=%.6lf x2=%.6lf\n", (sqrt(delta)-b)/(2*a), (-sqrt(delta)-b)/(2*a)); } } return 0; }
TheBadZhang/OJ
usx/special/60/6009.c
#include <stdio.h> int main () { float a, b, c, t; while (~scanf ("%f%f%f", &a, &b, &c)) { if (a > b) { t = a; a = b; b = t; } if (a > c) { t = a; a = c; c = t; } if (b > c) { t = b; b = c; c = t; } printf ("%.6f %.6f %.6f\n", a, b, c); } return 0; }
TheBadZhang/OJ
usx/special/60/6015-2.c
<filename>usx/special/60/6015-2.c #include <stdio.h> int main () { printf (" 1 2 3 4 5 6 7 8 9\n"); printf (" 1 1\n"); printf (" 2 2 4\n"); printf (" 3 3 6 9\n"); printf (" 4 4 8 12 16\n"); printf (" 5 5 10 15 20 25\n"); printf (" 6 6 12 18 24 30 36\n"); printf (" 7 7 14 21 28 35 42 49 \n"); printf (" 8 8 16 24 32 40 48 56 64 \n"); printf (" 9 9 18 27 36 45 54 63 72 81\n"); return 0; }
TheBadZhang/OJ
usx/special/92/9221.c
<reponame>TheBadZhang/OJ #include <stdio.h> int main () { int w, h, i, j, f = 0; char c; while (~scanf ("%d %d", &w, &h)) { c = 'a'; if (f) printf ("\n\n"); f = 1; for (i = 0; i < h; i++) { if (i>0) printf ("\n"); for (j = 0; j < w; j++) { printf ("%c", c++); } } } return 0; }
TheBadZhang/OJ
usx/special/60/6006.c
<gh_stars>1-10 #include <stdio.h> int main () { int i, c = 0; for (i = 1; i <= 100; ++i) { if (i%2 == 0) { c += i; } } printf ("%d\n", c); return 0; }
TheBadZhang/OJ
usx/special/91/9103.c
<gh_stars>1-10 #include <stdio.h> #include <math.h> int main () { float a, b, c, p; while (~scanf("%f%f%f", &a, &b, &c)) { if (a + b > c && a + c > b && b + c > a) { p = (a+b+c)/2.0; printf ("%.2f\n", sqrt (p*(p-a)*(p-b)*(p-c))); } } return 0; }
TheBadZhang/OJ
usx/special/92/9208.c
<filename>usx/special/92/9208.c<gh_stars>1-10 #include <stdio.h> int main () { int a, sum; while (~scanf ("%d", &a)) { sum = 0; while (a > 0) { sum += (a%10)*(a%10); a /= 10; } printf ("%d\n", sum); } return 0; }
TheBadZhang/OJ
usx/special/60/6035.c
<filename>usx/special/60/6035.c #include <stdio.h> int money [6] = { 1, 2, 5, 10, 20, 50 }; #define for2(v,end) for(v=0;v<=end;v++) int main () { int i, j, k, l, m, n, s = 0; for2(n,2)for2(m,5)for2(l,10)for2(k,20)for2(j,50)for2(i,100) if (i+2*j+5*k+10*l+20*m+50*n==100) { s ++; } printf ("%d\n", s); return 0; }
TheBadZhang/OJ
usx/special/92/9210.c
#include <stdio.h> int main () { int a; while (~scanf ("%d", &a)) { if (a%400==0 || a%100!=0&&a%4==0) { printf ("Yes\n"); } else { printf ("No\n"); } } return 0; }
TheBadZhang/OJ
usx/special/60/6043.c
#include <stdio.h> int main () { int n, a[50], i; while (~scanf ("%d",&n)) { for (i = 0; i < n; i++) { scanf ("%d", &a[i]); } for (i = 0; i < n; i++) { printf ("%3d", a[n-i-1]); } printf ("\n"); } return 0; }
TheBadZhang/OJ
usx/special/91/9117.c
#include <stdio.h> int main () { int a, b, c, d; scanf ("%d %d %d %d", &a, &b, &c, &d); printf ("%.2f\n%.2f", 1.0/(1.0/a+1.0/b), 1.0/(1.0/a+1.0/b+1.0/c+1.0/d)); return 0; }
TheBadZhang/OJ
usx/special/60/6021-2.c
#include<stdio.h> main(){puts("119");}
TheBadZhang/OJ
usx/special/60/6048-2.c
<reponame>TheBadZhang/OJ #include <stdio.h> int main () { int n; while (~scanf ("%d", &n)) { // 处理多组输入 int i, j, num; int mainSum = 0, sideSum = 0; // 主对角线和副对角线和 for (i = 0; i < n; i ++) { for (j = 0; j < n; j ++) { scanf ("%d", &num); // 输入数据 if (j == i) mainSum += num; if (j == (n-i-1)) sideSum += num; } } printf ("%d %d\n", mainSum, sideSum); // 输出结果 } return 0; }
TheBadZhang/OJ
usx/special/60/6083.c
#include <stdio.h> #include <string.h> #include <stdlib.h> // 和 6054 完全一样 int cmp (const void* a, const void* b) { return strcmp ((char*)a, (char*)b); } int main() { int n; char c[20][20]; while (~scanf("%d\n", &n)) { int i; for (i = 0; i < n; i++) { gets(c[i]); // getchar (); } qsort (c, n, sizeof (char[20]), cmp); for (i = 0; i < n; i++) { printf ("%s\n", c[i]); } } return 0; }
TheBadZhang/OJ
usx/special/92/9211.c
#include <stdio.h> #include <math.h> int main () { double a, b, c, delta; while (~scanf ("%lf %lf %lf", &a, &b, &c)) { delta = b*b-4*a*c; if (delta == 0.0) { printf ("%.2f\n", -b/2/a); } else if (delta > 0) { delta = sqrt(delta); printf ("%.2f %.2f\n", (-b+delta)/2/a, (-b-delta)/2/a); } else { printf ("No answer\n"); } } return 0; }
TheBadZhang/OJ
usx/special/92/9212.c
<gh_stars>1-10 #include <stdio.h> int main () { int score; while (~scanf ("%d", &score)) { if (score >= 90) { printf ("outstanding\n"); } else if (score >= 60) { printf ("satisfactory\n"); } else { printf ("unsatisfactory\n"); } } }
TheBadZhang/OJ
usx/special/60/6072.c
#include <stdio.h> void swap (int* a, int* b) { int c = *a; *a = *b; *b = c; } void reverse (int* l, int ns, int n) { int i; for (i = 0; i < n/2; i++) { swap (&l[ns+i-1], &l[ns+n-2-i]); } } int main () { int n, i; int arr [25]; int n1, n2; while (~scanf ("%d", &n)) { for (i = 0; i < n; i++) { scanf ("%d", &arr[i]); } scanf ("%d %d", &n1, &n2); reverse (arr, n1, n2); for (i = 0; i < n; i++) { if (i) putchar (' '); printf ("%d", arr[i]); } printf ("\n"); } return 0; }
TheBadZhang/OJ
usx/special/92/9217-2.c
<reponame>TheBadZhang/OJ #include <stdio.h> #include <string.h> int main () { char str[1024]; while (~scanf ("%s", str)) { printf ("%d\n", strlen(str)); } }
TheBadZhang/OJ
usx/special/60/6030-2.c
<filename>usx/special/60/6030-2.c #include<stdio.h> main(){puts("2.085481");}
coup-de-foudre/teensy-interruptor
interocitor/midi_constants.h
// Midi note LUT (period, us) uint32_t midi_period_us[128] = { /* C C# D D# E F F# G G# A A# B */ /* -1 */ 122312, 115447, 108967, 102849, 97079, 91630, 86487, 81633, 77051, 72727, 68645, 64792, /* 0 */ 61156, 57723, 54483, 51425, 48539, 45815, 43243, 40816, 38525, 36363, 34322, 32396, /* 1 */ 30578, 212861, 27241, 25712, 24269, 22907, 21621, 20408, 19262, 18181, 17161, 16198, /* 2 */ 15289, 14430, 13620, 12856, 12134, 11453, 10810, 10204, 9631, 9090, 8580, 8099, /* 3 */ 7644, 7215, 6810, 6428, 6067, 5726, 5405, 5102, 4815, 4545, 4290, 4049, /* 4 */ 3822, 3607, 3405, 3214, 3033, 2863, 2702, 2551, 2407, 2272, 2145, 2024, /* 5 */ 1911, 1803, 1702, 1607, 1516, 1431, 1351, 1275, 1203, 1136, 1072, 1012, /* 6 */ 955, 901, 851, 803, 758, 715, 675, 637, 601, 568, 536, 506, /* 7 */ 477, 450, 425, 401, 379, 357, 337, 318, 300, 284, 268, 253, /* 8 */ 238, 225, 212, 200, 189, 178, 168, 168, 150, 142, 134, 126, /* 9 */ 119, 112, 106, 100, 94, 89, 84, 79, }; // Frequency-note lookup float midi_freq[128] = { /* C C# D D# E F F# G G# A A# B */ /* -1 */ 8.176, 8.662, 9.177, 9.723, 10.301, 10.913, 11.562, 12.25, 12.979, 13.75, 14.568, 15.434, /* 0 */ 16.35, 17.32, 18.35, 19.45, 20.6, 21.83, 23.12, 24.5, 25.96, 27.50, 29.14, 30.87, /* 1 */ 32.70, 34.65, 36.71, 38.89, 41.20, 43.65, 46.25, 49.00, 51.91, 55.00, 58.27, 61.74, /* 2 */ 65.41, 69.30, 73.42, 77.78, 82.41, 87.31, 92.50, 98.00, 103.83, 110.00, 116.54, 123.47, /* 3 */ 130.81, 138.59, 146.83, 155.56, 164.81, 174.61, 185, 196, 207.65, 220, 233.08, 246.94, /* 4 */ 261.63, 277.18, 293.66, 311.13, 329.63, 349.23, 369.99, 392, 415.3, 440, 466.16, 493.88, /* 5 */ 523.25, 554.37, 587.33, 622.25, 659.25, 698.46, 739.99, 783.99, 830.61, 880, 932.33, 987.77, /* 6 */ 1046.5, 1108.73, 1174.66, 1244.51, 1318.51, 1396.91, 1479.98, 1567.98, 1661.22, 1760, 1864.66, 1975.53, /* 7 */ 2093, 2217.46, 2349.32, 2489.02, 2637.02, 2793.83, 2959.96, 3135.96, 3322.44, 3520, 3729.31, 3951.07, /* 8 */ 4186.01, 4434.92, 4698.63, 4978.03, 5274.04, 5587.65, 5919.91, 6271.93, 6644.88, 7040, 7458.62, 7902.13 }; const char *note_name[12] = {"C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#", "A ", "A#", "B "};
coup-de-foudre/teensy-interruptor
interocitor/entropy.h
uint32_t _rng_state = millis(); #define RNG_MAGIC 75380540 // Roughly: https://en.wikipedia.org/wiki/Xorshift inline void _permute_rng_state() { uint32_t x = _rng_state; x ^= x << 13; x ^= x >> 17; x ^= x << 5; _rng_state = x; } void init_rng() { _rng_state = RNG_MAGIC - millis(); for (int i=0; i<101; i++) _permute_rng_state(); } // A small hack to use all the entropy unsigned char increment = 0; inline uint8_t random_unit8(){ if (increment == 0) _permute_rng_state(); increment = (increment + 1) % 4; return _rng_state >> (increment * 8); }
coup-de-foudre/teensy-interruptor
interocitor/util.h
enum SYS_MODE { SM_MIDI_USB, SM_MIDI_JACK, SM_FREQ_FIXED, SM_FREQ_PINK }; struct MidiNote { uint8_t channel; uint8_t pitch; uint8_t velocity; uint32_t phase_us; uint32_t period_us; uint32_t start_ms; }; enum MUSIC_STATE { SM_NEXT, SM_WAIT, SM_PULSE, };
coup-de-foudre/teensy-interruptor
interocitor/display.h
#include <LiquidCrystal.h> // 1 will have pulse readout in ms, 0 is hz #define READOUT_MS 0 #define DEBUG_BEND false LiquidCrystal vfd(3, 4, 5, 6, 7, 2); // (RS, Enable, D4, D5, D6, D7) void init_display() { vfd.begin(2, 20); // Give time for LCD to init delay(10); vfd.clear(); } void update_top_display_line(const char *contents) { vfd.setCursor(0, 0); vfd.print(" "); // Blank the line vfd.setCursor(0, 0); vfd.print(contents); } unsigned long last_display_millis = 0; void update_bottom_display_line() { // Debounce the call rate of this function to avoid flicker if ((millis() - last_display_millis) < 250) return; vfd.setCursor(0, 1); vfd.print("W< "); vfd.setCursor(2, 1); vfd.print(interrupter_pulsewidth_setpoint); vfd.write(0xE4); // <- mu vfd.print("s "); if ((system_mode == 0) or (system_mode == 4)) { vfd.setCursor(7, 1); vfd.print(" "); vfd.setCursor(8, 1); // NOTE (meawoppl) - This changes the readout between ms and Hz if (READOUT_MS) { vfd.print(pulse_period / 1000); vfd.print("ms "); } else { vfd.print(((float)1 / ((float)(pulse_period / (float)1000000)))); vfd.print("Hz "); } } if ((system_mode == SM_MIDI_USB) or (system_mode == SM_MIDI_JACK)) { vfd.setCursor(8, 1); for (byte i = 0; i < NOTE_ARRAY_SIZE; i++) { if (active_notes[i].velocity == 0) { vfd.print(" "); } else { vfd.print(note_name[active_notes[i].pitch % 12]); } }; } last_display_millis = millis(); }
speckdude/ESP32-Phone
PhoneStart/PhoneLibrary/phone_debug.h
<filename>PhoneStart/PhoneLibrary/phone_debug.h /*Copyright(c) 2021 speckdude ///Permission is hereby granted, free of charge, to any person obtaining a copy ///of this softwareand associated documentation files(the "Software"), to deal ///in the Software without restriction, including without limitation the rights ///to use, copy, modify, merge, publish, distribute, sublicense, and /or sell ///copies of the Software, and to permit persons to whom the Software is ///furnished to do so, subject to the following conditions : /// ///The above copyright noticeand this permission notice shall be included in all ///copies or substantial portions of the Software. /// ///THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ///IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ///FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE ///AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ///LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ///OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ///SOFTWARE. */ // handles all debug printouts #ifndef DEBUG_H #define DEBUG_H //includes #include <stream.h> #include <HardwareSerial.h> #include "constants.h" //defines //check constants file for debug value //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ENUMS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ enum debugLevel { LOGGING, STARTUP, ERROR, TESTING }; //~~~~~~~~~~~~~~~~~~~~~~~~~type definitions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~function prototypes~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void setDebugLevel(debugLevel level); void PRINTS(char *s, debugLevel level); void PRINT(char *s, char *v, debugLevel level); void PRINTX(char *s, char *v, debugLevel level); #endif
speckdude/ESP32-Phone
PhoneStart/PhoneLibrary/textMessages.h
<reponame>speckdude/ESP32-Phone /*Copyright(c) 2021 speckdude ///Permission is hereby granted, free of charge, to any person obtaining a copy ///of this softwareand associated documentation files(the "Software"), to deal ///in the Software without restriction, including without limitation the rights ///to use, copy, modify, merge, publish, distribute, sublicense, and /or sell ///copies of the Software, and to permit persons to whom the Software is ///furnished to do so, subject to the following conditions : /// ///The above copyright noticeand this permission notice shall be included in all ///copies or substantial portions of the Software. /// ///THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ///IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ///FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE ///AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ///LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ///OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ///SOFTWARE. */ /*This header contains text message handling for esp32 cellphone project * * * * * */ //includes //#include <hardwareSerial.h> //for serial support //#include <stream.h> //for serial support #include "phone_debug.h" //for debug support #include "modemManager.h" //for modem handleing //~~~~~~~~~~~~~~~~~~~~~~~~defines & enums~~~~~~~~~~~~~~~~~~~~~~~ enum PDUMode { //defined in modem now PDU_TEXT_MODE = 0, ASCII_TEXT_MODE }; #define LEAVE_BLANK -1 enum CNMI_MODE { //see https://drive.google.com/file/d/1bJ0kEDtORWAzH9LWy8Kefj69SbpKb2wh/view?usp=sharing PG 169 for definition MODE_LEAVE_BLANK = LEAVE_BLANK, //this will leave the whole message blank BUFFER_ALWAYS = 0, DISCARD_IF_BUSY, BUFFER_IF_BUSY }; enum CNMI_MT { //see https://drive.google.com/file/d/1bJ0kEDtORWAzH9LWy8Kefj69SbpKb2wh/view?usp=sharing PG 170 for definition MT_LEAVE_BLANK = LEAVE_BLANK, NO_DELIVER_INDICATIONS = 0, INDICATE_LOCATION, SEND_UNSOLICITED, SEND_CLS_3_UNSOLICITED }; enum CNMI_BM { //see https://drive.google.com/file/d/1bJ0kEDtORWAzH9LWy8Kefj69SbpKb2wh/view?usp=sharing PG 170 for definition BM_LEAVE_BLANK = LEAVE_BLANK, NO_CBM_INDICATIONS = 0, NO_CBM = 0, NEW_CBM_UNSOLICITED = 2 }; enum CNMI_DS { //see https://drive.google.com/file/d/1bJ0kEDtORWAzH9LWy8Kefj69SbpKb2wh/view?usp=sharing PG 170 for definition DS_LEAVE_BLANK = LEAVE_BLANK, NO_STATUS_REPORTS = 0, SMS_STATUS_DIRECT_UNSOLICITED, SMS_STATUS_MEMORY_UNSOLICITED }; enum CNMI_BFR { //see https://drive.google.com/file/d/1bJ0kEDtORWAzH9LWy8Kefj69SbpKb2wh/view?usp=sharing PG 170 for definition BFR_LEAVE_BLANK = LEAVE_BLANK, BFR_FLISH = 0, BFR_CLEAR }; //~~~~~~~~~~~~~~~~~~~~~~~~function prototypes~~~~~~~~~~~~~~~~~~~ //text message modes int configureTextMessaging(); int setPDUMode(PDUMode mode); int setCNMIMode(CNMI_MODE cnmi_mode, CNMI_MT cnmi_mt, CNMI_BM cnmi_bm, CNMI_DS cnmi_ds, CNMI_BFR cnmi_bfr); //send/receive int sendASCIITextMessage(char *phoneNumber, char *message); int readAllUnreadMessages(); int readAllReadMessages(); //int readRecievedMessage(int msgAddrs);
speckdude/ESP32-Phone
PhoneStart/PhoneLibrary/modemCommunications.h
<filename>PhoneStart/PhoneLibrary/modemCommunications.h /*Copyright(c) 2021 speckdude ///Permission is hereby granted, free of charge, to any person obtaining a copy ///of this softwareand associated documentation files(the "Software"), to deal ///in the Software without restriction, including without limitation the rights ///to use, copy, modify, merge, publish, distribute, sublicense, and /or sell ///copies of the Software, and to permit persons to whom the Software is ///furnished to do so, subject to the following conditions : /// ///The above copyright noticeand this permission notice shall be included in all ///copies or substantial portions of the Software. /// ///THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ///IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ///FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE ///AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ///LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ///OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ///SOFTWARE. */ /*This header contains hardware level modem Communications handling for esp32 cellphone project *This file will require changes depending on compiler * * * * */ #ifndef MODEMCOMMUNICATIONS_H #define MODEMCOMMUNICATIONS_H //includes #include <hardwareSerial.h> //for serial support #include <stream.h> #include "phone_debug.h" //for debug support #include "constants.h" //for global constants //type definitions typedef struct modemCommunicationsObj { HardwareSerial *serial; char inBuffer[MODEM_IN_BUFFER_SIZE]; //should I have this buffer for intermediate storage? currently to store data until whole response recieved. }; typedef modemCommunicationsObj *pModemCommunicationsObj; //functions //create references to Modem Communications pModemCommunicationsObj createModemCommunicationsObj(int RXPin, int TXPin); void destroyModemCommunicationsObj(pModemCommunicationsObj myMdmComObj); //send Modem Communications int modemWrite(pModemCommunicationsObj myMdmComObj, char *msg); //check modem int modemDataReady(pModemCommunicationsObj myMdmComObj); //read data from Modem char* modemReadLine(pModemCommunicationsObj myMdmComObj); char* modemReadAllData(pModemCommunicationsObj myMdmComObj); #endif
speckdude/ESP32-Phone
PhoneStart/PhoneLibrary/modem.h
/*Copyright(c) 2021 speckdude ///Permission is hereby granted, free of charge, to any person obtaining a copy ///of this softwareand associated documentation files(the "Software"), to deal ///in the Software without restriction, including without limitation the rights ///to use, copy, modify, merge, publish, distribute, sublicense, and /or sell ///copies of the Software, and to permit persons to whom the Software is ///furnished to do so, subject to the following conditions : /// ///The above copyright noticeand this permission notice shall be included in all ///copies or substantial portions of the Software. /// ///THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ///IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ///FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE ///AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ///LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ///OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ///SOFTWARE. */ /*This header contains modem functions for esp32 cellphone project * * * * * */ #ifndef MODEM_H #define MODEM_H //includes #include <string.h> #include <FreeRTOS.h> //mutex #include "modemCommunications.h" #include "modemManager.h" #include "phone_debug.h" //for debug suppport #include "constants.h" ////~~~~~~~~~~~~~~~~~~~~~~~~enums~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ enum MessageType { COMMAND_RESPONSE, UNSOLICITED_DATA, EMPTY_MESSAGE, UNKNOWN_MESSAGE }; enum CommandResultCode { AT_BUFFER_OVERFLOW = -2, AT_NOT_RESULT = -1, AT_OK, AT_WAITING_FOR_INPUT, AT_ERROR }; enum UnsolicitedDataType { RING, CDS_NOTIFICATION, CDSI_NOTIFICATION, CMT_NOTIFICATION, CMTI_NOTIFICATION, CME_ERROR, CMS_ERROR, UNKNOWN_UNSOLICITED_DATA }; //~~~~~~~~~~~~~~~~~~~~~~~~~type definitions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ typedef struct Modem { //modem object pModemCommunicationsObj mdmComObj; //pointer to modem communications object }; typedef Modem *pModem; typedef struct ModemMessage { MessageType type; union Result { CommandResultCode commandResult; UnsolicitedDataType unsolicited; }result; char* recievedMessage; }; //~~~~~~~~~~~~~~~~~~~~~~~function prototypes~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //create/destroy modem pModem createModem(int RXPin, int TXPin); void destroyModem(); //~~~~~~~~~~modem functions~~~~~~~~~~~~~ //modem write int sendModemData(char* data, bool isCommand); //modem read ModemMessage readModemMessage(char* messageDataStorage, int storageSize); CommandResultCode continueReadModemMessage(char* messageDataStorage, int storageSize); //misc void flushModemOutput(); int checkModem(); #endif
speckdude/ESP32-Phone
PhoneStart/PhoneLibrary/modemManager.h
<filename>PhoneStart/PhoneLibrary/modemManager.h<gh_stars>0 /*Copyright(c) 2021 speckdude ///Permission is hereby granted, free of charge, to any person obtaining a copy ///of this softwareand associated documentation files(the "Software"), to deal ///in the Software without restriction, including without limitation the rights ///to use, copy, modify, merge, publish, distribute, sublicense, and /or sell ///copies of the Software, and to permit persons to whom the Software is ///furnished to do so, subject to the following conditions : /// ///The above copyright noticeand this permission notice shall be included in all ///copies or substantial portions of the Software. /// ///THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ///IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ///FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE ///AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ///LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ///OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ///SOFTWARE. */ /*This header contains modem management for esp32 cellphone project * * * * * */ #ifndef MODEMMANAGER_H #define MODEMMANAGER_H #include <FreeRTOS.h> //for queue and threads #include "modem.h" #include "phone_debug.h" #include "constants.h" #define QUEUE_SIZE 5 ////~~~~~~~~~~~~~~~~~~~~~~~~enums~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ enum ModemDataType { RAW_DATA, //Raw data, Don't expect a modem Response COMMAND_DATA_RESULT_WANTED, //Command, look for a response, and save off COMMAND_DATA_NO_RESULT //command, look for a response, but don't bother saving }; enum ModemQueueResult { MODEM_COMMAND_OVERSIZED = -2, MODEM_QUEUE_TIMEOUT = -1, MODEM_QUEUE_SUCCESS = 0 }; enum ModemCommandState { COMMAND_EMPTY, WAITING_TO_SEND, COMMAND_SENT, READING_RESPONSE, RESPONSE_READY, COMMAND_EXPIRED }; //~~~~~~~~~~~~~~~~~~~~~~~~~type definitions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ typedef short ModemDataLoc; typedef struct Command { ModemDataType modemDataType; int timeout; char* data; }; typedef struct CommandResult { enum ResultCode { SEND_ERROR, RESULT_ERROR = -1, RESULT_OK }commandResult; char* response; }; //~~~~~~~~~~~~~~~~~~~~~~~~Variables~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ extern TaskHandle_t modemReaderManager; //Not sure if other tasks will need these handles rn extern TaskHandle_t modemWriterManager; //~~~~~~~~~~~~~~~~~~~~~~~function prototypes~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void setupModemManager(int RXPin, int TXPin); //send ModemQueueResult sendModemCommand(Command command, ModemDataLoc *commandLoc); ModemQueueResult sendModemCommand(char* data, int timeout, ModemDataType dataType); //ModemQueueResult enqueueCommand(modemCommandLoc modemDataArrayLoc, int timeout); CommandResult sendModemCommandGetResult(Command command); //use this if you want a response //recieve CommandResult getCommandResult(ModemDataLoc responseLoc); //status ModemCommandState checkModemCommandState(ModemDataLoc locToCheck); #endif
UnaNancyOwen/OpenCVDNNSample
sample/Object Detection/MTCNN/mtcnn/pnet.h
/* Acknowledgements ---------------- This mtcnn implementation based on the implementation by <NAME> (@ksachdeva). Thank you for your great implementation! https://github.com/ksachdeva/opencv-mtcnn */ #ifndef __MTCNN_PNET__ #define __MTCNN_PNET__ #include "face.h" #include <opencv2/dnn.hpp> namespace mtcnn { class ProposalNetwork { public: struct Config { std::string prototext; std::string caffemodel; float score_threshold; float overlap_threshold; }; private: cv::dnn::Net net; float score_threshold; float overlap_threshold; private: std::vector<mtcnn::Face> make_faces( const cv::Mat& scores, const cv::Mat& regressions, const float scale_factor, const float threshold ); public: ProposalNetwork( const mtcnn::ProposalNetwork::Config& config ); ~ProposalNetwork(); private: ProposalNetwork( const mtcnn::ProposalNetwork& p_net ) = delete; ProposalNetwork& operator=( const mtcnn::ProposalNetwork& p_net ) = delete; public: std::vector<mtcnn::Face> run( const cv::Mat& image, const float min_size, const float scale_factor ); }; } #endif // __MTCNN_PNET__
UnaNancyOwen/OpenCVDNNSample
sample/Object Detection/MTCNN/mtcnn/helpers.h
/* Acknowledgements ---------------- This mtcnn implementation based on the implementation by <NAME> (@ksachdeva). Thank you for your great implementation! https://github.com/ksachdeva/opencv-mtcnn */ #ifndef __MTCNN_HELPERS__ #define __MTCNN_HELPERS__ #include <cmath> #include <algorithm> #include <opencv2/core.hpp> namespace mtcnn { inline cv::Mat crop( const cv::Mat& image, cv::Rect rectangle ) { cv::Mat crop_image = cv::Mat::zeros( rectangle.height, rectangle.width, image.type() ); const int32_t dx = std::abs( std::min( 0, rectangle.x ) ); if( dx > 0 ){ rectangle.x = 0; } rectangle.width -= dx; const int32_t dy = std::abs( std::min( 0, rectangle.y ) ); if( dy > 0 ){ rectangle.y = 0; } rectangle.height -= dy; int32_t dw = std::abs( std::min( 0, image.cols - 1 - ( rectangle.x + rectangle.width ) ) ); rectangle.width -= dw; int32_t dh = std::abs( std::min( 0, image.rows - 1 - ( rectangle.y + rectangle.height ) ) ); rectangle.height -= dh; if( rectangle.width > 0 && rectangle.height > 0 ){ image( rectangle ).copyTo( crop_image(cv::Range( dy, dy + rectangle.height ), cv::Range( dx, dx + rectangle.width ) ) ); } return crop_image; } } #endif // __MTCNN_HELPERS__
UnaNancyOwen/OpenCVDNNSample
sample/Object Detection/MTCNN/mtcnn/face.h
<gh_stars>10-100 /* Acknowledgements ---------------- This mtcnn implementation based on the implementation by <NAME> (@ksachdeva). Thank you for your great implementation! https://github.com/ksachdeva/opencv-mtcnn */ #ifndef __MTCNN_FACE__ #define __MTCNN_FACE__ #include <numeric> #include <opencv2/opencv.hpp> namespace mtcnn { constexpr int32_t NUM_REGRESSIONS = 4; constexpr int32_t NUM_POINTS = 5; enum LandMark { EYE_RIGHT = 0, EYE_LEFT = 1, NOSE = 2, MOUSE_RIGHT = 3, MOUSE_LEFT = 4 }; class BoundingBox { public: float x1; float y1; float x2; float y2; public: cv::Rect getRect() const { return cv::Rect( static_cast<int32_t>( x1 ), static_cast<int32_t>( y1 ), static_cast<int32_t>( x2 - x1 ), static_cast<int32_t>( y2 - y1 ) ); } BoundingBox getSquare() const { BoundingBox rectangle; const float width = x2 - x1; const float height = y2 - y1; const float side = std::max( width, height ); rectangle.x1 = static_cast<float>( static_cast<int32_t>( x1 + ( width - side ) * 0.5f ) ); rectangle.y1 = static_cast<float>( static_cast<int32_t>( y1 + ( height - side ) * 0.5f ) ); rectangle.x2 = static_cast<float>( static_cast<int32_t>( rectangle.x1 + side ) ); rectangle.y2 = static_cast<float>( static_cast<int32_t>( rectangle.y1 + side ) ); return rectangle; } }; class Point { public: float x; float y; public: cv::Point getPoint() const { return cv::Point( static_cast<int32_t>( x ), static_cast<int32_t>( y ) ); } }; class Face { public: BoundingBox rectangle; Point points[mtcnn::NUM_POINTS]; float regression[mtcnn::NUM_REGRESSIONS]; float score; public: static void apply_regression( std::vector<mtcnn::Face>& faces, const bool add_one = false ) { const float offset = add_one ? 1.0f : 0.0f; for( int32_t i = 0; i < faces.size(); i++ ) { const float width = faces[i].rectangle.x2 - faces[i].rectangle.x1 + offset; const float height = faces[i].rectangle.y2 - faces[i].rectangle.y1 + offset; faces[i].rectangle.x1 = faces[i].rectangle.x1 + faces[i].regression[1] * width; faces[i].rectangle.y1 = faces[i].rectangle.y1 + faces[i].regression[0] * height; faces[i].rectangle.x2 = faces[i].rectangle.x2 + faces[i].regression[3] * width; faces[i].rectangle.y2 = faces[i].rectangle.y2 + faces[i].regression[2] * height; } } static void rectanglees_to_squares( std::vector<mtcnn::Face> &faces ) { for (size_t i = 0; i < faces.size(); ++i) { faces[i].rectangle = faces[i].rectangle.getSquare(); } } static std::vector<mtcnn::Face> nms( std::vector<mtcnn::Face>& faces, const float overlap_threshold, const bool use_min = false ) { std::vector<mtcnn::Face> faces_nms; if( faces.empty() ){ return faces_nms; } std::sort( faces.begin(), faces.end(), []( const mtcnn::Face &f1, const mtcnn::Face &f2 ){ return f1.score > f2.score; } ); std::vector<int32_t> indices( faces.size() ); std::iota( std::begin( indices ), std::end( indices ), 0 ); while( indices.size() > 0 ){ const int32_t index = indices[0]; faces_nms.push_back( faces[index] ); std::vector<int32_t> temporary_indices = indices; indices.clear(); for( int32_t i = 1; i < temporary_indices.size(); i++ ){ const int32_t temporary_index = temporary_indices[i]; const float inter_x1 = std::max( faces[index].rectangle.x1, faces[temporary_index].rectangle.x1 ); const float inter_y1 = std::max( faces[index].rectangle.y1, faces[temporary_index].rectangle.y1 ); const float inter_x2 = std::min( faces[index].rectangle.x2, faces[temporary_index].rectangle.x2 ); const float inter_y2 = std::min( faces[index].rectangle.y2, faces[temporary_index].rectangle.y2 ); const float width = std::max( 0.f, ( inter_x2 - inter_x1 + 1 ) ); const float height = std::max( 0.f, ( inter_y2 - inter_y1 + 1 ) ); const float inter_area = width * height; const float area1 = ( faces[index].rectangle.x2 - faces[index].rectangle.x1 + 1 ) * ( faces[index].rectangle.y2 - faces[index].rectangle.y1 + 1 ); const float area2 = ( faces[temporary_index].rectangle.x2 - faces[temporary_index].rectangle.x1 + 1 ) * ( faces[temporary_index].rectangle.y2 - faces[temporary_index].rectangle.y1 + 1 ); const float overlap = use_min ? inter_area / std::min( area1, area2 ) : inter_area / ( area1 + area2 - inter_area ); if( overlap <= overlap_threshold ){ indices.push_back( temporary_index ); } } } return faces_nms; } }; } #endif // __MTCNN_FACE__
UnaNancyOwen/OpenCVDNNSample
sample/Depth Estimation/MiDaS/util.h
<gh_stars>10-100 #ifndef __UTIL__ #define __UTIL__ #include <vector> #include <string> #include <fstream> #include <opencv2/dnn.hpp> #include <opencv2/core.hpp> #include <opencv2/highgui.hpp> // Get Output Layers Name std::vector<std::string> getOutputsNames( const cv::dnn::Net& net ) { static std::vector<std::string> names; if( names.empty() ){ std::vector<int32_t> out_layers = net.getUnconnectedOutLayers(); std::vector<std::string> layers_names = net.getLayerNames(); names.resize( out_layers.size() ); for( size_t i = 0; i < out_layers.size(); ++i ){ names[i] = layers_names[out_layers[i] - 1]; } } return names; } // Get Output Layer Type std::string getOutputLayerType( cv::dnn::Net& net ) { const std::vector<int32_t> out_layers = net.getUnconnectedOutLayers(); const std::string output_layer_type = net.getLayer( out_layers[0] )->type; return output_layer_type; } // Read Class Name List std::vector<std::string> readClassNameList( const std::string list_path ) { std::vector<std::string> classes; std::ifstream ifs( list_path ); if( !ifs.is_open() ){ return classes; } std::string class_name = ""; while( std::getline( ifs, class_name ) ){ classes.push_back( class_name ); } return classes; } // Get Class Color Table for Visualize std::vector<cv::Scalar> getClassColors( const int32_t number_of_colors ) { cv::RNG random; std::vector<cv::Scalar> colors; for( int32_t i = 0; i < number_of_colors; i++ ){ cv::Scalar color( random.uniform( 0, 255 ), random.uniform( 0, 255 ), random.uniform( 0, 255 ) ); colors.push_back( color ); } return colors; } #endif // __UTIL__
UnaNancyOwen/OpenCVDNNSample
sample/Object Detection/MTCNN/mtcnn/onet.h
/* Acknowledgements ---------------- This mtcnn implementation based on the implementation by <NAME> (@ksachdeva). Thank you for your great implementation! https://github.com/ksachdeva/opencv-mtcnn */ #ifndef __MTCNN_ONET__ #define __MTCNN_ONET__ #include "face.h" #include <opencv2/dnn.hpp> namespace mtcnn { class OutputNetwork { public: struct Config { std::string prototext; std::string caffemodel; float score_threshold; float overlap_threshold; }; private: cv::dnn::Net net; float score_threshold; float overlap_threshold; public: OutputNetwork( const mtcnn::OutputNetwork::Config& config ); OutputNetwork(); private: OutputNetwork( const mtcnn::OutputNetwork& o_net ) = delete; OutputNetwork& operator=( const mtcnn::OutputNetwork& o_net ) = delete; public: std::vector<mtcnn::Face> run( const cv::Mat& image, const std::vector<mtcnn::Face>& faces ); }; } #endif // __MTCNN_ONET__
UnaNancyOwen/OpenCVDNNSample
sample/Object Detection/MTCNN/mtcnn/detector.h
<filename>sample/Object Detection/MTCNN/mtcnn/detector.h /* Acknowledgements ---------------- This mtcnn implementation based on the implementation by <NAME> (@ksachdeva). Thank you for your great implementation! https://github.com/ksachdeva/opencv-mtcnn */ #ifndef __MTCNN_DETECTOR__ #define __MTCNN_DETECTOR__ #include "face.h" #include "onet.h" #include "pnet.h" #include "rnet.h" namespace mtcnn { class Detector { private: std::unique_ptr<mtcnn::ProposalNetwork> p_net; std::unique_ptr<mtcnn::RefineNetwork> r_net; std::unique_ptr<mtcnn::OutputNetwork> o_net; public: Detector( const mtcnn::ProposalNetwork::Config& p_config, const mtcnn::RefineNetwork::Config& r_config, const mtcnn::OutputNetwork::Config& o_config ); std::vector<mtcnn::Face> detect( const cv::Mat& image, const float min_size, const float scale_factor ); }; } #endif // __MTCNN_DETECTOR__
TBSniller/tv-native-apis
libgm/include/gm.h
<gh_stars>1-10 #pragma once #include <stddef.h> #include <stdint.h> typedef struct GM_SURFACE_T { uint32_t dummy0; uint8_t* framebuffer; uint32_t dummy1[4 + 0x101]; uint32_t surfaceID; uint32_t dummy3[2]; } GM_SURFACE; int GM_CreateSurface(uint32_t width, uint32_t height, uint32_t dummy, GM_SURFACE* surface_info); int GM_DestroySurface(uint32_t surfaceID); int GM_CaptureGraphicScreen(uint32_t surfaceID, uint32_t* width, uint32_t* height); int GM_GetGraphicResolution(uint16_t *width, uint16_t *height);
TBSniller/tv-native-apis
samples/gm/capture/capture.c
<filename>samples/gm/capture/capture.c<gh_stars>1-10 #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <gm.h> GM_SURFACE surfaceInfo; unsigned short nativeWidth = 0; unsigned short nativeHeight = 0; int captureWidth = 1920; int captureHeight = 1080; int framerate = 0; int main(int argc, char *argv[]) { int res; // Usage: ./gm-capture [width height] if (argc >= 3) { captureWidth = atoi(argv[1]); captureHeight = atoi(argv[2]); } if (argc >= 4) { framerate = atoi(argv[3]); } if ((res = GM_GetGraphicResolution(&nativeWidth, &nativeHeight)) != 0) { fprintf(stderr, "[GM Capture Sample] GM_GetGraphicResolution Failed: %x\n", res); return 5; } fprintf(stderr, "[GM Capture Sample] Native resolution: %dx%d\n", nativeWidth, nativeHeight); fprintf(stderr, "[GM Capture Sample] Capture resolution: %dx%d\n", captureWidth, captureHeight); if (captureWidth > nativeWidth || captureHeight > nativeHeight) { fprintf(stderr, "[GM Capture Sample] Capture resolution can't exceed native resolution...\n"); return 6; } if ((res = GM_CreateSurface(captureWidth, captureHeight, 0, &surfaceInfo)) != 0) { fprintf(stderr, "[GM Capture Sample] GM_CreateSurface Failed: %x\n", res); return 1; } do { if ((res = GM_CaptureGraphicScreen(surfaceInfo.surfaceID, &captureWidth, &captureHeight)) != 0) { fprintf(stderr, "[GM Capture Sample] GM_CaptureGraphicScreen Failed: %x\n", res); return 2; } if (write(1, surfaceInfo.framebuffer, captureWidth * captureHeight * 4) == -1) { perror("write failed"); return 3; } if (framerate > 0) { usleep (1000000 / framerate); } } while (framerate > 0); fprintf(stderr, "[GM Capture Sample] Capture successful! (%dx%d)\n", captureWidth, captureHeight); if ((res = GM_DestroySurface(surfaceInfo.surfaceID)) != 0) { fprintf(stderr, "[GM Capture Sample] Surface destroy failed: %d\n", res); return 4; } return 0; }
TBSniller/tv-native-apis
libhalgal/src/halgal.c
#include "halgal.h" int HAL_GAL_CreateSurface(uint32_t width, uint32_t height, uint32_t pixelFormat, HAL_GAL_SURFACE* surface_info) { return -1; } int HAL_GAL_DestroySurface(HAL_GAL_SURFACE* surface_info) { return -1; } int HAL_GAL_CaptureFrameBuffer(HAL_GAL_SURFACE* surface_info) { return -1; } int HAL_GAL_FillRectangle(HAL_GAL_SURFACE *surface_info, HAL_GAL_RECT *rect, uint32_t dummy, HAL_GAL_DRAW_FLAGS *flags, HAL_GAL_DRAW_SETTINGS *settings) { return -1; } int HAL_GAL_Init() { return -1; }
TBSniller/tv-native-apis
lgncapi/include/lgnc_system.h
<filename>lgncapi/include/lgnc_system.h #pragma once #include <stddef.h> #include <linux/input.h> #include "lgnc_openapi_types.h" #define LGNC_REMOTE_PRESS 272 #define LGNC_REMOTE_RED 398 #define LGNC_REMOTE_GREEN 399 #define LGNC_REMOTE_YELLOW 400 #define LGNC_REMOTE_BLUE 401 #define LGNC_REMOTE_CH_UP 402 #define LGNC_REMOTE_CH_DOWN 403 #define LGNC_REMOTE_BACK 412 #define LGNC_REMOTE_NUM_1 872 #define LGNC_REMOTE_NUM_2 873 #define LGNC_REMOTE_NUM_3 874 #define LGNC_REMOTE_NUM_4 875 #define LGNC_REMOTE_NUM_5 876 #define LGNC_REMOTE_NUM_6 877 #define LGNC_REMOTE_NUM_7 878 #define LGNC_REMOTE_NUM_8 879 #define LGNC_REMOTE_NUM_9 880 #define LGNC_REMOTE_NUM_10 881 #define LGNC_REMOTE_NUM_11 882 #define LGNC_REMOTE_NUM_12 883 #define LGNC_REMOTE_DATA_HOSO 885 enum LGNC_KEY_COND_T { LGNC_KEY_PRESS = 0, LGNC_KEY_RELEASE = 1, LGNC_KEY_REPEAT = 2, LGNC_KEY_DRAG = 3, LGNC_KEY_POWER = 4, LGNC_KEY_GESTURE = 5, LGNC_KEY_COND_LAST = 6, }; typedef enum LGNC_KEY_COND_T LGNC_KEY_COND_T; enum LGNC_MSG_TYPE_T { LGNC_MSG_NONE = 0, LGNC_MSG_FOCUS_IN = 1, LGNC_MSG_FOCUS_OUT = 2, LGNC_MSG_TERMINATE = 3, LGNC_MSG_HOST_EVENT = 4, LGNC_MSG_PAUSE = 5, LGNC_MSG_RESUME = 6, LGNC_MSG_LAST = -1 }; typedef enum LGNC_MSG_TYPE_T LGNC_MSG_TYPE_T; enum LGNC_CURSOR_SIZE_T { LGNC_CURSOR_SIZE_L = 0, LGNC_CURSOR_SIZE_M = 1, LGNC_CURSOR_SIZE_S = 2, LGNC_CURSOR_SIZE_LASTEST = 3, LGNC_CURSOR_SIZE_LAST = 4 }; typedef enum LGNC_CURSOR_SIZE_T LGNC_CURSOR_SIZE_T; enum LGNC_CURSOR_TYPE_T { LGNC_CURSOR_TYPE_A = 0, LGNC_CURSOR_TYPE_B = 1, LGNC_CURSOR_TYPE_C = 2, LGNC_CURSOR_TYPE_D = 3, LGNC_CURSOR_TYPE_DRAG = 4, LGNC_CURSOR_TYPE_POINT = 5, LGNC_CURSOR_TYPE_HOLD = 6, LGNC_CURSOR_TYPE_GESTURE_POINT = 7, LGNC_CURSOR_TYPE_DISABLE = 8, LGNC_CURSOR_TYPE_CUSTOM_A = 9, LGNC_CURSOR_TYPE_CUSTOM_B = 10, LGNC_CURSOR_TYPE_CUSTOM_C = 11, LGNC_CURSOR_TYPE_CUSTOM_D = 12, LGNC_CURSOR_TYPE_CUSTOM_E = 13, LGNC_CURSOR_TYPE_LASTEST = 14, LGNC_CURSOR_TYPE_EXTERNAL = 15, LGNC_CURSOR_TYPE_LAST = 16 }; enum LGNC_CURSOR_STATE_T { LGNC_CURSOR_STATE_NORMAL = 0, LGNC_CURSOR_STATE_PRESS = 1, LGNC_CURSOR_STATE_LASTEST = 2, LGNC_CURSOR_STATE_LAST = 3, }; enum LGNC_CURSOR_HOTSPOT_T { LGNC_CURSOR_HOTSPOT_LEFTTOP = 0, LGNC_CURSOR_HOTSPOT_USERSETTING = 1, LGNC_CURSOR_HOTSPOT_LAST = 2, }; enum LGNC_INPUT_DEV_TYPE_T { LGNC_INPUT_TYPE_KEYBOARD = 1, LGNC_INPUT_TYPE_MOUSE = 2, LGNC_INPUT_TYPE_JOYSTICK = 4, LGNC_INPUT_TYPE_REMOTE = 8, LGNC_INPUT_TYPE_PS3 = 32768, LGNC_INPUT_TYPE_VIRTUAL = 16, LGNC_INPUT_TYPE_KEY_RETURN = 32, LGNC_INPUT_TYPE_CURSOR_RETURN = 64, LGNC_INPUT_LGE = 128, LGNC_INPUT_TYPE_NLP = 1024, LGNC_INPUT_TYPE_SMARTREMOTE = 2048, LGNC_INPUT_TYPE_XPAD = 4096, LGNC_INPUT_TYPE_HIDPAD = 8192, LGNC_INPUT_TYPE_WIDI = 16384, LGNC_INPUT_TYPE_ALL = 65023, LGNC_INPUT_TYPE_NONE = 0, }; typedef enum LGNC_INPUT_DEV_TYPE_T LGNC_INPUT_DEV_TYPE_T; struct LGNC_ADDITIONAL_INPUT_INFO_T { struct input_event event; int deviceID; LGNC_INPUT_DEV_TYPE_T deviceType; }; typedef struct LGNC_ADDITIONAL_INPUT_INFO_T LGNC_ADDITIONAL_INPUT_INFO_T; struct LGNC_SYSTEM_CALLBACKS_T { LGNC_STATUS_T(*pfnMsgHandler) (LGNC_MSG_TYPE_T msg, unsigned int submsg, char *pData, unsigned short dataSize); unsigned int (*pfnKeyEventCallback)(unsigned int key, LGNC_KEY_COND_T keyCond, LGNC_ADDITIONAL_INPUT_INFO_T *keyInput); unsigned int (*pfnMouseEventCallback)(int posX, int posY, unsigned int key, LGNC_KEY_COND_T keyCond, LGNC_ADDITIONAL_INPUT_INFO_T *keyInput); void (*pfnJoystickEventCallback)(LGNC_ADDITIONAL_INPUT_INFO_T *e); }; typedef struct LGNC_CTRL_INFO LGNC_CTRL_INFO, *PLGNC_CTRL_INFO; struct LGNC_CTRL_INFO { char projectName[32]; char modelName[32]; char hwVer[32]; char swVer[32]; char ESN[32]; char toolTypeName[32]; char serialNumber[32]; char modelInch[8]; char countryGroup[8]; char szDdrRam[8]; }; typedef struct LGNC_CTRL_INFO LGNC_CTRL_INFO_T; typedef enum LGNC_CURSOR_HOTSPOT_T LGNC_CURSOR_HOTSPOT_T; typedef enum LGNC_CURSOR_SIZE_T LGNC_CURSOR_SIZE_T; typedef enum LGNC_CURSOR_STATE_T LGNC_CURSOR_STATE_T; typedef enum LGNC_CURSOR_TYPE_T LGNC_CURSOR_TYPE_T; typedef struct LGNC_CUSTOM_CURSOR LGNC_CUSTOM_CURSOR, *PLGNC_CUSTOM_CURSOR; struct LGNC_CUSTOM_CURSOR { char fileInfo[256]; LGNC_CURSOR_TYPE_T cursorType; LGNC_CURSOR_SIZE_T cursorSize; LGNC_CURSOR_STATE_T cursorState; LGNC_CURSOR_HOTSPOT_T cursorHotSpot; unsigned short gapX; unsigned short gapY; }; typedef struct LGNC_CUSTOM_CURSOR LGNC_CUSTOM_CURSOR_T; typedef struct LGNC_SYSTEM_CALLBACKS_T LGNC_SYSTEM_CALLBACKS_T; int LGNC_SYSTEM_Initialize(int argc, char **argv, LGNC_SYSTEM_CALLBACKS_T *callbacks); int LGNC_SYSTEM_Finalize(void); int LGNC_SYSTEM_GetDisplayId(int *displayId /* very likely to be wl_egl_window */); int LGNC_SYSTEM_GetLanguage(void); int LGNC_SYSTEM_GetSaveDirectory(void); int LGNC_SYSTEM_GetSystemInfo(void); int LGNC_SYSTEM_SetCursorShape(void); int LGNC_SYSTEM_SetCustomCursor(void);
TBSniller/tv-native-apis
libhalgal/include/halgal.h
<filename>libhalgal/include/halgal.h #pragma once #include <stddef.h> #include <stdint.h> typedef struct HAL_GAL_SURFACE_T { uint32_t offset; uint32_t *physicalAddress; uint16_t pitch; uint16_t bpp; uint16_t width; uint16_t height; uint16_t pixelFormat; uint32_t paletteInfo[257]; uint32_t property; uint32_t vendorData; } HAL_GAL_SURFACE; typedef struct HAL_GAL_RECT_T { uint16_t x,y,w,h; } HAL_GAL_RECT; typedef struct HAL_GAL_DRAW_FLAGS_T { uint32_t pflag; } HAL_GAL_DRAW_FLAGS; typedef struct HAL_GAL_DRAW_SETTINGS_T { uint32_t srcblending1; uint32_t dstblending2; uint32_t dstcolor; } HAL_GAL_DRAW_SETTINGS; int HAL_GAL_CreateSurface(uint32_t width, uint32_t height, uint32_t pixelFormat, HAL_GAL_SURFACE *surface_info); int HAL_GAL_DestroySurface(HAL_GAL_SURFACE *surface_info); int HAL_GAL_CaptureFrameBuffer(HAL_GAL_SURFACE *surface_info); int HAL_GAL_FillRectangle(HAL_GAL_SURFACE *surface_info, HAL_GAL_RECT *rect, uint32_t color, HAL_GAL_DRAW_FLAGS *flags, HAL_GAL_DRAW_SETTINGS *settings); int HAL_GAL_Init();
TBSniller/tv-native-apis
libvtcapture/src/vtCaptureApi_c.c
#include "vtcapture/vtCaptureApi_c.h" VT_DRIVER *vtCapture_create() { VT_DRIVER *thi; return thi; } int vtCapture_init(VT_DRIVER *driver, const VT_CALLER_T *caller_id, VT_CLIENTID_T *clientid) { return -1; } int vtCapture_preprocess(VT_DRIVER *driver, VT_CLIENTID_T *clientid, _LibVtCaptureProperties *props) { return -1; } int vtCapture_capabilityInfo(VT_DRIVER *driver, VT_CLIENTID_T *clientid, _LibVtCaptureCapabilityInfo *capinf) { return -1; } int vtCapture_planeInfo(VT_DRIVER *driver, VT_CLIENTID_T *clientid, _LibVtCapturePlaneInfo *planeinf) { return -1; } int vtCapture_process(VT_DRIVER *driver, VT_CLIENTID_T *clientid) { return -1; } int vtCapture_stop(VT_DRIVER *driver, VT_CLIENTID_T *clientid) { return -1; } int vtCapture_currentCaptureBuffInfo(VT_DRIVER *driver, _LibVtCaptureBufferInfo *buff) { return -1; } int vtCapture_postprocess(VT_DRIVER *driver, VT_CLIENTID_T *clientid) { return -1; } int vtCapture_finalize(VT_DRIVER *driver, VT_CLIENTID_T *client_id) { return -1; } int vtCapture_release(VT_DRIVER *driver) { return -1; }
TBSniller/tv-native-apis
libvtcapture/include/vtcapture/vtCaptureApi_c.h
#pragma once #include <stddef.h> #include <stdint.h> typedef char VT_CALLER_T; typedef char VT_CLIENTID_T; typedef int32_t VT_STATUS_T; typedef int32_t VT_DUMP_T; typedef int32_t VT_BUF_T; typedef int32_t VT_FRAMERATE_T; typedef struct VT_DRIVER_T { uint32_t *ms_currentBuffIndex; int *ms_mutex; //p_thread_mutex_t in C = ??, should be wayne anyway } VT_DRIVER; typedef struct VT_LOC { int16_t x, y; } VT_LOC_T; typedef struct VT_RESOLUTION { int16_t w, h; } VT_RESOLUTION_T; typedef struct VT_REGION { int16_t a,b,c,d; } VT_REGION_T; typedef struct _LibVtCaptureProperties { VT_DUMP_T dump; VT_LOC_T loc; VT_RESOLUTION_T reg; VT_BUF_T buf_cnt; VT_FRAMERATE_T frm; } _LibVtCaptureProperties; typedef struct _LibVtCaptureCapabilityInfo { VT_DRIVER *driver; int32_t *dummy1; int16_t *dummy2; int16_t *dummy3; int16_t *dummy4; int16_t *dummy5; //0x14 int16_t *dummy6; int16_t *dummy7; int16_t *dummy8; int16_t *dummy9; int16_t *dummy10; } _LibVtCaptureCapabilityInfo; typedef struct _LibVtCapturePlaneInfo { int32_t stride; VT_REGION_T planeregion; VT_REGION_T activeregion; } _LibVtCapturePlaneInfo; typedef struct _LibVtCaptureBufferInfo { char *start_addr0; char *start_addr1; int32_t size0; int32_t size1; } _LibVtCaptureBufferInfo; VT_DRIVER *vtCapture_create(); int vtCapture_init(VT_DRIVER *driver, const VT_CALLER_T *caller_id, VT_CLIENTID_T *clientid); int vtCapture_preprocess(VT_DRIVER *driver, VT_CLIENTID_T *clientid, _LibVtCaptureProperties *props); int vtCapture_capabilityInfo(VT_DRIVER *driver, VT_CLIENTID_T *clientid, _LibVtCaptureCapabilityInfo *capinf); int vtCapture_planeInfo(VT_DRIVER *driver, VT_CLIENTID_T *clientid, _LibVtCapturePlaneInfo *planeinf); int vtCapture_process(VT_DRIVER *driver, VT_CLIENTID_T *clientid); int vtCapture_currentCaptureBuffInfo(VT_DRIVER *driver, _LibVtCaptureBufferInfo *buff); int vtCapture_stop(VT_DRIVER *driver, VT_CLIENTID_T *clientid); int vtCapture_postprocess(VT_DRIVER *driver, VT_CLIENTID_T *clientid); int vtCapture_finalize(VT_DRIVER *driver, VT_CLIENTID_T *clientid); int vtCapture_release(VT_DRIVER *driver);
TBSniller/tv-native-apis
libgm/src/gm.c
#include "gm.h" int GM_CreateSurface(uint32_t width, uint32_t height, uint32_t dummy, GM_SURFACE* surface_info) { return -1; } int GM_DestroySurface(uint32_t surfaceID) { return -1; } int GM_CaptureGraphicScreen(uint32_t surfaceID, uint32_t* width, uint32_t* height) { return -1; } int GM_GetGraphicResolution(uint16_t *width, uint16_t *height) { return -1; };
TBSniller/tv-native-apis
libgm-wayland/include/gm-wayland/gmw_c.h
<filename>libgm-wayland/include/gm-wayland/gmw_c.h<gh_stars>1-10 #pragma once #include <stddef.h> #include <stdint.h> typedef int32_t HAL_GAL_PIXEL_FORMAT_T; typedef int32_t HAL_GAL_DRAW_FLAGS_T; typedef struct HAL_GAL_DRAW_SETTINGS { int32_t blend1, blend2, blend3; }HAL_GAL_DRAW_SETTINGS_T; typedef struct HAL_GAL_RECT { int16_t x, y, w, h; }HAL_GAL_RECT_T; ; //Pointer of Exitcode from createSurface() typedef struct HAL_GAL_SURFACE_INFO { int32_t *offset; int32_t *physicalAddress; //should be dst framebuffer int16_t pitch; int16_t bpp; int16_t width; int16_t height; int32_t *pixelFormat; int32_t *paletteInfo; int32_t *property; int32_t *vendorData; } HAL_GAL_SURFACE_INFO_T; int GM_CreateSurface(int16_t width, int16_t height, int32_t pixfmt, HAL_GAL_SURFACE_INFO_T *info); //defaultcall pixfmt = 0 int GM_FillRectangle(HAL_GAL_SURFACE_INFO_T *info, HAL_GAL_RECT_T *surfacereturn, int32_t dummy, HAL_GAL_DRAW_FLAGS_T *drawflags, HAL_GAL_DRAW_SETTINGS_T *settings); //defaultcalls int dummy = 0, drawflags = 0, settings = 2(1-10 possible)-blending parameters? //int GM_CaptureFrameBuffer(HAL_GAL_SURFACE_INFO_T *info); int GM_DestroySurface(HAL_GAL_SURFACE_INFO_T *info);
TBSniller/tv-native-apis
samples/vtcapture/capture/capture.c
<reponame>TBSniller/tv-native-apis #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <jpeglib.h> #include <signal.h> #include <vtcapture/vtCaptureApi_c.h> #define CRLF() fwrite("\r\n", 1, 2, stdout) const VT_CALLER_T caller[24] = "com.webos.tbtest.cap"; VT_DRIVER *driver; VT_CLIENTID_T client[128] = "00"; _LibVtCaptureProperties props; _LibVtCapturePlaneInfo plane; int stride, x, y, w, h, xa, ya, wa, ha; VT_REGION_T region; VT_REGION_T activeregion; _LibVtCaptureBufferInfo buff; char *addr0, *addr1; int size0, size1; char *rgbout; int isrunning = 0; void sighandle(int sig); void NV21_TO_RGB24(unsigned char *yuyv, unsigned char *rgb, int width, int height); int stop(); int finalize(); void write_JPEG_stdout(int quality); void sighandle(int sig){ fprintf(stderr, "\nTermination-signal recieved. Terminating.. \n"); int done = 0; if(isrunning == 1){ done = stop(); exit(done); }else{ done = finalize(); exit(done); } } int main(int argc, char *argv[]) { signal(SIGINT, sighandle); int done; int ex; //Capture properties for vtCapture_preprocess - _LibVtCaptureProperties int dumping = 2; int capturex = 0; int capturey = 0; int captureWidth = 960; int captureHeight = 540; int framerate = 30; int buffer_count = 3; VT_DUMP_T dump = dumping; VT_LOC_T loc = {capturex, capturey}; VT_RESOLUTION_T reg = {captureWidth, captureHeight}; VT_FRAMERATE_T frm = framerate; VT_BUF_T buf_cnt = buffer_count; props.dump = dump; props.loc = loc; props.reg = reg; props.buf_cnt = buf_cnt; props.frm = framerate; //End of capture properties for vtCapture_preprocess - _LibVtCaptureProperties printf("HTTP/1.1 200 OK"); CRLF(); printf("Content-Type: multipart/x-mixed-replace; boundary=myboundary"); CRLF(); printf("Cache-Control: no-cache"); CRLF(); printf("Connection: close"); CRLF(); printf("Pragma: no-cache"); CRLF(); CRLF(); fprintf(stderr, "Starting vtCapture using API: %dx%d @%dFPS\n", captureWidth, captureHeight,framerate); fprintf(stderr, "Used settings: dump location: %d, x: %d, y: %d, w: %d, h: %d, framerate: %d, buf_cnt: %d\n", dumping, capturex, capturey, captureWidth, captureHeight, framerate, buffer_count); driver = vtCapture_create(); fprintf(stderr, "Driver created!\n"); done = vtCapture_init(driver, caller, client); if (done != 0) { fprintf(stderr, "vtCapture_init failed: %x\nQuitting...\n", done); ex = finalize(); return ex; } fprintf(stderr, "vtCapture_init done!\nCaller_ID: %s Client ID: %s \n", caller, client); done = vtCapture_preprocess(driver, client, &props); if (done != 0) { fprintf(stderr, "vtCapture_preprocess failed: %x\nQuitting...\n", done); ex = finalize(); return ex; } fprintf(stderr, "vtCapture_preprocess done!\n"); done = vtCapture_planeInfo(driver, client, &plane); if (done == 0 ) { stride = plane.stride; region = plane.planeregion; x = region.a, y = region.b, w = region.c, h = region.d; activeregion = plane.activeregion; xa = activeregion.a, ya = activeregion.b, wa = activeregion.c, ha = activeregion.d; }else{ fprintf(stderr, "vtCapture_planeInfo failed: %x\nQuitting...\n", done); ex = finalize(); return ex; } fprintf(stderr, "vtCapture_planeInfo done!\nstride: %d\nRegion: x: %d, y: %d, w: %d, h: %d\nActive Region: x: %d, y: %d w: %d h: %d\n", stride, x, y, w, h, xa, ya, wa, ha); done = vtCapture_process(driver, client); if (done == 0){ isrunning = 1; }else{ isrunning = 0; fprintf(stderr, "vtCapture_process failed: %x\nQuitting...\n", done); ex = finalize(); return ex; } fprintf(stderr, "vtCapture_process done!\n"); sleep(2); done = vtCapture_currentCaptureBuffInfo(driver, &buff); if (done == 0 ) { addr0 = buff.start_addr0; addr1 = buff.start_addr1; size0 = buff.size0; size1 = buff.size1; }else{ fprintf(stderr, "vtCapture_currentCaptureBuffInfo failed: %x\nQuitting...\n", done); ex = finalize(); return ex; } fprintf(stderr, "vtCapture_currentCaptureBuffInfo done!\naddr0: %p addr1: %p size0: %d size1: %d\n", addr0, addr1, size0, size1); int comsize; comsize = size0+size1; // comsize = size0; // do{ //Combine two Image Buffers to one and convert to RGB24 char *combined = (char *) malloc(comsize); int rgbsize = sizeof(combined)*w*h*3; rgbout = (char *) malloc(rgbsize); memcpy(combined, addr0, size0); memcpy(combined+size0, addr1, size1); // NV21_TO_RGB24(combined, rgbout, w, h); // IplImage *orig = (IplImage *) malloc(comsize*2); // = cvCreateImage(cvSize(w,h),IPL_DEPTH_8U,4); // CvMat mat; // cvInitMatHeader(&mat, (h*1,5), w, IPL_DEPTH_8U, combined,CV_AUTOSTEP); // IplImage *orig = cvDecodeImage(&mat, CV_LOAD_IMAGE_COLOR); IplImage *orig = cvCreateImage(cvSize(w,(h+h/2)),IPL_DEPTH_8U,1); IplImage *dst = cvCreateImage(cvSize(w,h),IPL_DEPTH_8U,4); if(orig) { memcpy(orig->imageData,combined,comsize); cvCvtColor(orig, dst, CV_YUV2RGBA_NV21); cvSaveImage("/tmp/test.png", dst, 0); cvReleaseImage(&orig); cvReleaseImage(&dst); }else{ fprintf(stderr, "ERROR: Create Image failed!\n"); } // cvCvtColor(&mat, rgbout, 96); // write_JPEG_stdout(85); FILE * pFile; pFile = fopen ("/tmp/vtcap.bin","wb"); if (pFile!=NULL) { fwrite(rgbout, rgbsize, sizeof(rgbout), pFile); fclose (pFile); } free(rgbout); free(combined); // }while(1==1); done = stop(); return done; } //Credits: https://www.programmersought.com/article/18954751423/ void NV21_TO_RGB24(unsigned char *yuyv, unsigned char *rgb, int width, int height) { const int nv_start = width * height ; int index = 0, rgb_index = 0; uint8_t y, u, v; int r, g, b, nv_index = 0,i, j; for(i = 0; i < height; i++){ for(j = 0; j < width; j ++){ nv_index = i / 2 * width + j - j % 2; y = yuyv[rgb_index]; u = yuyv[nv_start + nv_index ]; v = yuyv[nv_start + nv_index + 1]; r = y + (140 * (v-128))/100; //r g = y - (34 * (u-128))/100 - (71 * (v-128))/100; //g b = y + (177 * (u-128))/100; //b if(r > 255) r = 255; if(g > 255) g = 255; if(b > 255) b = 255; if(r < 0) r = 0; if(g < 0) g = 0; if(b < 0) b = 0; index = rgb_index % width + (height - i - 1) * width; rgb[index * 3+0] = r; rgb[index * 3+1] = g; rgb[index * 3+2] = b; rgb_index++; } } } int stop() { int done; isrunning = 0; done = vtCapture_stop(driver, client); if (done != 0) { fprintf(stderr, "vtCapture_stop failed: %x\nQuitting...\n", done); done = finalize(); return done; } fprintf(stderr, "vtCapture_stop done!\n"); done = finalize(); return done; } int finalize() { fprintf(stderr, "-- Quit called! --\n"); int done; done = vtCapture_postprocess(driver, client); if (done == 0){ fprintf(stderr, "Quitting: vtCapture_postprocess done!\n"); done = vtCapture_finalize(driver, client); if (done == 0) { fprintf(stderr, "Quitting: vtCapture_finalize done!\n"); vtCapture_release(driver); fprintf(stderr, "Quitting: Driver released!\n"); memset(&client,0,127); fprintf(stderr, "Quitting!\n"); return 0; } fprintf(stderr, "Quitting: vtCapture_finalize failed: %x\n", done); } vtCapture_finalize(driver, client); vtCapture_release(driver); fprintf(stderr, "Quitting with errors: %x!\n", done); return 1; } //Credits: https://github.com/webosbrew/tv-native-apis/blob/main/samples/vt/capture/capture.c void write_JPEG_stdout(int quality) { /* This struct contains the JPEG compression parameters and pointers to * working space (which is allocated as needed by the JPEG library). * It is possible to have several such structures, representing multiple * compression/decompression processes, in existence at once. We refer * to any one struct (and its associated working data) as a "JPEG object". */ struct jpeg_compress_struct cinfo; /* This struct represents a JPEG error handler. It is declared separately * because applications often want to supply a specialized error handler * (see the second half of this file for an example). But here we just * take the easy way out and use the standard error handler, which will * print a message on stderr and call exit() if compression fails. * Note that this struct must live as long as the main JPEG parameter * struct, to avoid dangling-pointer problems. */ struct jpeg_error_mgr jerr; /* More stuff */ JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ int row_stride; /* physical row width in image buffer */ /* Step 1: allocate and initialize JPEG compression object */ /* We have to set up the error handler first, in case the initialization * step fails. (Unlikely, but it could happen if you are out of memory.) * This routine fills in the contents of struct jerr, and returns jerr's * address which we place into the link field in cinfo. */ cinfo.err = jpeg_std_error(&jerr); /* Now we can initialize the JPEG compression object. */ jpeg_create_compress(&cinfo); unsigned long jpegSize = 0; unsigned char *jpegBuf = NULL; /* Step 2: specify data destination (eg, a file) */ /* Note: steps 2 and 3 can be done in either order. */ /* Here we use the library-supplied code to send compressed data to a * stdio stream. You can also write your own code to do something else. * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that * requires it in order to write binary files. */ jpeg_mem_dest(&cinfo, &jpegBuf, &jpegSize); /* Step 3: set parameters for compression */ /* First we supply a description of the input image. * Four fields of the cinfo struct must be filled in: */ cinfo.image_width = w; /* image width and height, in pixels */ cinfo.image_height = h; cinfo.input_components = 3; /* # of color components per pixel */ cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ /* Now use the library's routine to set default compression parameters. * (You must set at least cinfo.in_color_space before calling this, * since the defaults depend on the source color space.) */ jpeg_set_defaults(&cinfo); /* Now you can set any non-default parameters you wish to. * Here we just illustrate the use of quality (quantization table) scaling: */ jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */); /* Step 4: Start compressor */ /* TRUE ensures that we will write a complete interchange-JPEG file. * Pass TRUE unless you are very sure of what you're doing. */ jpeg_start_compress(&cinfo, TRUE); /* Step 5: while (scan lines remain to be written) */ /* jpeg_write_scanlines(...); */ /* Here we use the library's state variable cinfo.next_scanline as the * loop counter, so that we don't have to keep track ourselves. * To keep things simple, we pass one scanline per call; you can pass * more if you wish, though. */ row_stride = w * 3; /* JSAMPLEs per row in image_buffer */ while (cinfo.next_scanline < cinfo.image_height) { /* jpeg_write_scanlines expects an array of pointers to scanlines. * Here the array is only one element long, but you could pass * more than one scanline at a time if that's more convenient. */ row_pointer[0] = &rgbout[(h - cinfo.next_scanline - 1) * row_stride]; (void)jpeg_write_scanlines(&cinfo, row_pointer, 1); } /* Step 6: Finish compression */ jpeg_finish_compress(&cinfo); /* After finish_compress, we can close the output file. */ printf("--myboundary"); CRLF(); printf("Content-Type: image/jpeg"); CRLF(); printf("Content-Length: %d", jpegSize); CRLF(); CRLF(); fwrite(jpegBuf, 1, jpegSize, stdout); // FILE * pFile; // pFile = fopen ("/tmp/myfile.jpg","wb"); // if (pFile!=NULL) // { // fwrite(jpegBuf, 1, jpegSize, pFile); // fclose (pFile); // } CRLF(); /* Step 7: release JPEG compression object */ /* This is an important step since it will release a good deal of memory. */ jpeg_destroy_compress(&cinfo); /* And we're done! */ // Free jpeg memory free(jpegBuf); }
TBSniller/tv-native-apis
samples/halgal/capture/capture_withVideo.c
#include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <stdbool.h> #include <signal.h> #include <unistd.h> #include <pthread.h> #include <string.h> #include <sys/mman.h> #include <jpeglib.h> #include <halgal.h> #include <vtcapture/vtCaptureApi_c.h> #define CRLF() fwrite("\r\n", 1, 2, stdout) //HAL_GAL HAL_GAL_SURFACE surfaceInfo; HAL_GAL_RECT rect; HAL_GAL_DRAW_FLAGS flags; HAL_GAL_DRAW_SETTINGS settings; uint32_t color = 0; //vtCapture const VT_CALLER_T caller[24] = "com.webos.tbtest.cap"; VT_DRIVER *driver; VT_CLIENTID_T client[128] = "00"; _LibVtCaptureProperties props; _LibVtCapturePlaneInfo plane; VT_REGION_T region; VT_REGION_T activeregion; _LibVtCaptureBufferInfo buff; char *addr0, *addr1; int size0, size1; char *gesamt; int comsize; char *combined; int rgbasize; int rgbsize; char *rgbout; char *hal; //All int stride, x, y, w, h, xa, ya, wa, ha; bool app_quit = false; int isrunning = 0; int done; int ex; int file; int rIndex, gIndex, bIndex, aIndex; unsigned int alpha,iAlpha; size_t len; char *addr; int fd; int stop(); int stop_hal(); int stop_vt(); int finalize(); void sighandle(int sig); int blend(unsigned char *result, unsigned char *fg, unsigned char *bg, int leng); void NV21_TO_RGBA(unsigned char *yuyv, unsigned char *rgba, int width, int height); void write_JPEG_stdout(int quality); void sighandle(int signal) { switch (signal) { case SIGINT: app_quit = true; done = stop(); exit(done); break; default: break; } } int main(int argc, char *argv[]) { if (getenv("XDG_RUNTIME_DIR") == NULL) { setenv("XDG_RUNTIME_DIR", "/tmp/xdg", 1); } signal(SIGINT, sighandle); int dumping = 2; int capturex = 0; int capturey = 0; int captureWidth = 360; //both int captureHeight = 180; //both int framerate = 15; int buffer_count = 3; VT_DUMP_T dump = dumping; VT_LOC_T loc = {capturex, capturey}; VT_RESOLUTION_T reg = {captureWidth, captureHeight}; VT_FRAMERATE_T frm = framerate; VT_BUF_T buf_cnt = buffer_count; props.dump = dump; props.loc = loc; props.reg = reg; props.buf_cnt = buf_cnt; props.frm = framerate; if ((done = HAL_GAL_Init()) != 0) { fprintf(stderr, "HAL_GAL_Init failed: %x\n", done); done = stop(); return done; } fprintf(stderr, "HAL_GAL_Init done! Exit: %d\n", done); if ((done = HAL_GAL_CreateSurface(captureWidth, captureHeight, 0, &surfaceInfo)) != 0) { fprintf(stderr, "HAL_GAL_CreateSurface failed: %x\n", done); done = stop(); return done; } fprintf(stderr, "HAL_GAL_CreateSurface done! SurfaceID: %d\n", surfaceInfo.vendorData); fprintf(stderr, "offset: %p\n", surfaceInfo.offset); fprintf(stderr, "physicalAddress: %p\n", surfaceInfo.physicalAddress); fprintf(stderr, "pitch: %d\n", surfaceInfo.pitch); fprintf(stderr, "bpp: %d\n", surfaceInfo.bpp); fprintf(stderr, "width: %d\n", surfaceInfo.width); fprintf(stderr, "height: %d\n", surfaceInfo.height); fprintf(stderr, "pixelFormat: %d\n", surfaceInfo.pixelFormat); fprintf(stderr, "paletteInfo: %d\n", surfaceInfo.paletteInfo); fprintf(stderr, "property: %d\n", surfaceInfo.property); settings.srcblending1 = 2; //default = 2(1-10 possible) - blend? setting settings.dstblending2 = 0; settings.dstcolor = 0; rect.x = 0; rect.y = 0; rect.w = captureWidth; rect.h = captureHeight; flags.pflag = 0; if ((done = HAL_GAL_CaptureFrameBuffer(&surfaceInfo)) != 0) { fprintf(stderr, "HAL_GAL_CaptureFrameBuffer failed: %x\n", done); done = stop(); return done; } fprintf(stderr, "HAL_GAL_CaptureFrameBuffer done! %x\n", done); isrunning = 1; fd = open("/dev/gfx",2); if (fd < 0){ fprintf(stderr, "HAL_GAL: gfx open fail result: %d\n", fd); done = stop(); return done; }else{ fprintf(stderr, "HAL_GAL: gfx open ok result: %d\n", fd); } len = surfaceInfo.property; if (len == 0){ len = surfaceInfo.height * surfaceInfo.pitch; } fprintf(stderr, "HAL_GAL: Surface length: %d || Virtual address: %p\n", len, &addr); fprintf(stderr, "Starting vtCapture using API: %dx%d @%dFPS\n", captureWidth, captureHeight,framerate); fprintf(stderr, "Used settings: dump location: %d, x: %d, y: %d, w: %d, h: %d, framerate: %d, buf_cnt: %d\n", dumping, capturex, capturey, captureWidth, captureHeight, framerate, buffer_count); driver = vtCapture_create(); fprintf(stderr, "Driver created!\n"); done = vtCapture_init(driver, caller, client); if (done != 0) { fprintf(stderr, "vtCapture_init failed: %x\nQuitting...\n", done); ex = finalize(); ex += stop_hal(); return ex; } fprintf(stderr, "vtCapture_init done!\nCaller_ID: %s Client ID: %s \n", caller, client); done = vtCapture_preprocess(driver, client, &props); if (done != 0) { fprintf(stderr, "vtCapture_preprocess failed: %x\nQuitting...\n", done); ex = finalize(); ex += stop_hal(); return ex; } fprintf(stderr, "vtCapture_preprocess done!\n"); done = vtCapture_planeInfo(driver, client, &plane); if (done == 0 ) { stride = plane.stride; region = plane.planeregion; x = region.a, y = region.b, w = region.c, h = region.d; activeregion = plane.activeregion; xa = activeregion.a, ya = activeregion.b, wa = activeregion.c, ha = activeregion.d; }else{ fprintf(stderr, "vtCapture_planeInfo failed: %x\nQuitting...\n", done); ex = finalize(); ex += stop_hal(); return ex; } fprintf(stderr, "vtCapture_planeInfo done!\nstride: %d\nRegion: x: %d, y: %d, w: %d, h: %d\nActive Region: x: %d, y: %d w: %d h: %d\n", stride, x, y, w, h, xa, ya, wa, ha); done = vtCapture_process(driver, client); if (done == 0){ isrunning = 1; }else{ isrunning = 0; fprintf(stderr, "vtCapture_process failed: %x\nQuitting...\n", done); ex = finalize(); ex += stop_hal(); return ex; } fprintf(stderr, "vtCapture_process done!\n"); sleep(2); done = vtCapture_currentCaptureBuffInfo(driver, &buff); if (done == 0 ) { addr0 = buff.start_addr0; addr1 = buff.start_addr1; size0 = buff.size0; size1 = buff.size1; }else{ fprintf(stderr, "vtCapture_currentCaptureBuffInfo failed: %x\nQuitting...\n", done); ex = finalize(); ex += stop_hal(); return ex; } fprintf(stderr, "vtCapture_currentCaptureBuffInfo done!\naddr0: %p addr1: %p size0: %d size1: %d\n", addr0, addr1, size0, size1); comsize = size0+size1; combined = (char *) malloc(comsize); rgbasize = sizeof(combined)*stride*h*4; rgbsize = sizeof(combined)*stride*h*3; rgbout = (char *) malloc(rgbasize); gesamt = (char *) malloc(len); hal = (char *) malloc(len); addr = (char *) mmap(0, len, 3, 1, fd, surfaceInfo.offset); int framecount = 0; do { memcpy(combined, addr0, size0); memcpy(combined+size0, addr1, size1); NV21_TO_RGBA(combined, rgbout, stride, h); if ((done = HAL_GAL_CaptureFrameBuffer(&surfaceInfo)) != 0) { fprintf(stderr, "HAL_GAL_CaptureFrameBuffer failed: %x\n", done); done = stop(); return done; } memcpy(hal,addr,len); blend(gesamt, hal, rgbout, len); write_JPEG_stdout(85); if (framerate > 0) { usleep (1000000 / framerate); } } while (framerate > 0 || app_quit == false); done = stop(); return done; } int stop(){ fprintf(stderr, "-- Quit called! --\n"); int done; if(isrunning == 1){ munmap(addr, len); free(combined); free(rgbout); free(gesamt); done = close(fd); if (done != 0){ fprintf(stderr, "gfx close fail result: %d\n", done); }else{ fprintf(stderr, "gfx close ok result: %d\n", done); } } done = 0; done = stop_vt(); done += stop_hal(); return done; } int stop_vt(){ int done; isrunning = 0; done = vtCapture_stop(driver, client); if (done != 0) { fprintf(stderr, "vtCapture_stop failed: %x\nQuitting...\n", done); done = finalize(); return done; } fprintf(stderr, "vtCapture_stop done!\n"); done = finalize(); return done; } int stop_hal(){ int done = 0; isrunning = 0; if ((done = HAL_GAL_DestroySurface(&surfaceInfo)) != 0) { fprintf(stderr, "Quitting: HAL_GAL_DestroySurface failed: %d\n", done); return done; } fprintf(stderr, "Quitting: HAL_GAL_DestroySurface done! %d\n", done); return done; } int finalize(){ int done; done = vtCapture_postprocess(driver, client); if (done == 0){ fprintf(stderr, "Quitting: vtCapture_postprocess done!\n"); done = vtCapture_finalize(driver, client); if (done == 0) { fprintf(stderr, "Quitting: vtCapture_finalize done!\n"); vtCapture_release(driver); fprintf(stderr, "Quitting: Driver released!\n"); memset(&client,0,127); fprintf(stderr, "Quitting!\n"); return 0; } fprintf(stderr, "Quitting: vtCapture_finalize failed: %x\n", done); } vtCapture_finalize(driver, client); vtCapture_release(driver); fprintf(stderr, "Quitting with errors: %x!\n", done); return 1; } int blend(unsigned char *result, unsigned char *fg, unsigned char *bg, int leng){ for (int i = 0; i < leng; i += 4){ bIndex = i; gIndex = i + 1; rIndex = i + 2; aIndex = i + 3; alpha = fg[aIndex] + 1; iAlpha = 256 - fg[aIndex]; result[bIndex] = (unsigned char)((alpha * fg[bIndex] + iAlpha * bg[bIndex]) >> 8);; result[gIndex] = (unsigned char)((alpha * fg[gIndex] + iAlpha * bg[gIndex]) >> 8);; result[rIndex] = (unsigned char)((alpha * fg[rIndex] + iAlpha * bg[rIndex]) >> 8);; result[aIndex] = 0xff; } } //Credits: https://www.programmersought.com/article/18954751423/ void NV21_TO_RGBA(unsigned char *yuyv, unsigned char *rgba, int width, int height){ const int nv_start = width * height ; int index = 0, rgb_index = 0; uint8_t y, u, v; int r, g, b, nv_index = 0, i, j; int a = 255; for(i = 0; i < height; i++){ for(j = 0; j < width; j ++){ nv_index = i / 2 * width + j - j % 2; y = yuyv[rgb_index]; u = yuyv[nv_start + nv_index ]; v = yuyv[nv_start + nv_index + 1]; r = y + (140 * (v-128))/100; //r g = y - (34 * (u-128))/100 - (71 * (v-128))/100; //g b = y + (177 * (u-128))/100; //b if(r > 255) r = 255; if(g > 255) g = 255; if(b > 255) b = 255; if(r < 0) r = 0; if(g < 0) g = 0; if(b < 0) b = 0; index = rgb_index % width + (height - i - 1) * width; rgba[i * width * 4 + 4 * j + 0] = b; rgba[i * width * 4 + 4 * j + 1] = g; rgba[i * width * 4 + 4 * j + 2] = r; rgba[i * width * 4 + 4 * j + 3] = a; rgb_index++; } } } //Credits: https://github.com/webosbrew/tv-native-apis/blob/main/samples/vt/capture/capture.c void write_JPEG_stdout(int quality){ struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ int row_stride; /* physical row width in image buffer */ cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); unsigned long jpegSize = 0; unsigned char *jpegBuf = NULL; jpeg_mem_dest(&cinfo, &jpegBuf, &jpegSize); cinfo.image_width = w; /* image width and height, in pixels */ cinfo.image_height = h; cinfo.input_components = 4; /* # of color components per pixel */ cinfo.in_color_space = JCS_EXT_BGRX; /* colorspace of input image */ jpeg_set_defaults(&cinfo); jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */); jpeg_start_compress(&cinfo, TRUE); row_stride = stride * 4; /* JSAMPLEs per row in image_buffer */ while (cinfo.next_scanline < cinfo.image_height) { row_pointer[0] = &gesamt[cinfo.next_scanline * row_stride]; (void)jpeg_write_scanlines(&cinfo, row_pointer, 1); } jpeg_finish_compress(&cinfo); printf("--myboundary"); CRLF(); printf("Content-Type: image/jpeg"); CRLF(); printf("Content-Length: %d", jpegSize); CRLF(); CRLF(); fwrite(jpegBuf, 1, jpegSize, stdout); CRLF(); jpeg_destroy_compress(&cinfo); free(jpegBuf); }
TBSniller/tv-native-apis
samples/gm-wayland/capture/capture.c
<filename>samples/gm-wayland/capture/capture.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <jpeglib.h> #include <signal.h> #include <gm-wayland/gmw_c.h> #define CRLF() fwrite("\r\n", 1, 2, stdout) int isrunning = 0; HAL_GAL_SURFACE_INFO_T *surfinfo; HAL_GAL_DRAW_SETTINGS_T *settings; HAL_GAL_RECT_T *rect; HAL_GAL_DRAW_FLAGS_T *drawflags; int32_t *palette; void sighandle(int sig); int stop(); void NV21_TO_RGB24(unsigned char *yuyv, unsigned char *rgb, int width, int height); void write_JPEG_stdout(int quality); void sighandle(int sig){ fprintf(stderr, "\nTermination-signal recieved. Terminating.. \n"); int done = 0; if(isrunning == 1){ // done = stop(); exit(done); }else{ // done = finalize(); exit(done); } } int main(int argc, char *argv[]) { signal(SIGINT, sighandle); int done; int ex; //Pointer of Exitcode from createSurface() drawflags = malloc(sizeof(int)); //default = 0 settings = malloc(3*sizeof(int)); settings->blend1 = 2; //default = 2(1-10 possible) - blend? setting settings->blend2 = 1; settings->blend3 = 0; rect = malloc(4*sizeof(int16_t)); rect->x = 0; rect->y = 0; rect->w = 1280; rect->h = 720; /* int32_t offset = 2; int32_t physicalAddress = 0; //should be dst framebuffer int16_t pitch = 0; int16_t bpp = 0; int32_t pixelFormat = 0; int32_t paletteInfo = 0; int32_t property = 0; int32_t vendorData = 0; */ int32_t width = 1280; int32_t height = 720; palette = malloc(1028); surfinfo = malloc(1056); surfinfo->paletteInfo = palette; /* surfinfo.offset = &offset; surfinfo.physicalAddress = &physicalAddress; surfinfo.pitch = pitch; surfinfo.bpp = bpp; surfinfo.width = width; surfinfo.height = height; surfinfo.pixelFormat = &pixelFormat; surfinfo.paletteInfo = &paletteInfo; surfinfo.property = &property; surfinfo.vendorData = &vendorData; */ done = GM_CreateSurface(width, height, 0, surfinfo); if(done != 0){ fprintf(stderr, "GM_CreateSurface failed: %x\nQuitting...\n", done); ex = stop(); return ex; } fprintf(stderr, "GM_CreateSurface done! Address %p\n", surfinfo->offset); fprintf(stderr, "Surfinfo: Offset: %p, physicalAddress: %p, pitch: %d, bpp: %d, width: %d, height: %d, pixelFormat: %p, paletteInfo: %p, property: %d, vendorData: %d\n", surfinfo->offset, surfinfo->physicalAddress, surfinfo->pitch, surfinfo->bpp, surfinfo->width, surfinfo->height, surfinfo->pixelFormat, surfinfo->paletteInfo, surfinfo->property, surfinfo->vendorData); done = GM_FillRectangle(surfinfo, rect, 0, drawflags, settings); if(done != 0){ fprintf(stderr, "GM_FillRectangle failed: %x | Settings: %d\nQuitting...\n", done, settings->blend1); ex = stop(); return ex; } ex = stop(); free(surfinfo); free(rect); return ex; } int stop() { fprintf(stderr, "-- Quit called! --\n"); int ex; ex = GM_DestroySurface(surfinfo); if(ex == 0){ fprintf(stderr, "Quitting: GM_DestroySurface done!\n"); fprintf(stderr, "Quitting!\n"); return 0; } fprintf(stderr, "Quitting with errors: %x!\n", ex); return 1; } /* printf("HTTP/1.1 200 OK"); CRLF(); printf("Content-Type: multipart/x-mixed-replace; boundary=myboundary"); CRLF(); printf("Cache-Control: no-cache"); CRLF(); printf("Connection: close"); CRLF(); printf("Pragma: no-cache"); CRLF(); CRLF(); */ /* int comsize; comsize = size0+size1; do{ //Combine two Image Buffers to one and convert to RGB24 char *combined = (char *) malloc(comsize); int rgbsize = sizeof(combined)*w*h*3; rgbout = (char *) malloc(rgbsize); memcpy(combined, addr0, size0); memcpy(combined+size0, addr1, size1); NV21_TO_RGB24(combined, rgbout, w, h); write_JPEG_stdout(85); free(rgbout); free(combined); // FILE * pFile; // pFile = fopen ("/tmp/myfile.bin","wb"); // if (pFile!=NULL) // { // fwrite(rgbout, rgbsize, sizeof(rgbout), pFile); // fclose (pFile); // } }while(1==1); done = stop(); return done; } */ // //Credits: https://www.programmersought.com/article/18954751423/ // void NV21_TO_RGB24(unsigned char *yuyv, unsigned char *rgb, int width, int height) // { // const int nv_start = width * height ; // int index = 0, rgb_index = 0; // uint8_t y, u, v; // int r, g, b, nv_index = 0,i, j; // for(i = 0; i < height; i++){ // for(j = 0; j < width; j ++){ // nv_index = i / 2 * width + j - j % 2; // y = yuyv[rgb_index]; // u = yuyv[nv_start + nv_index ]; // v = yuyv[nv_start + nv_index + 1]; // r = y + (140 * (v-128))/100; //r // g = y - (34 * (u-128))/100 - (71 * (v-128))/100; //g // b = y + (177 * (u-128))/100; //b // if(r > 255) r = 255; // if(g > 255) g = 255; // if(b > 255) b = 255; // if(r < 0) r = 0; // if(g < 0) g = 0; // if(b < 0) b = 0; // index = rgb_index % width + (height - i - 1) * width; // rgb[index * 3+0] = r; // rgb[index * 3+1] = g; // rgb[index * 3+2] = b; // rgb_index++; // } // } // } // //Credits: https://github.com/webosbrew/tv-native-apis/blob/main/samples/vt/capture/capture.c // void write_JPEG_stdout(int quality) // { // /* This struct contains the JPEG compression parameters and pointers to // * working space (which is allocated as needed by the JPEG library). // * It is possible to have several such structures, representing multiple // * compression/decompression processes, in existence at once. We refer // * to any one struct (and its associated working data) as a "JPEG object". // */ // struct jpeg_compress_struct cinfo; // /* This struct represents a JPEG error handler. It is declared separately // * because applications often want to supply a specialized error handler // * (see the second half of this file for an example). But here we just // * take the easy way out and use the standard error handler, which will // * print a message on stderr and call exit() if compression fails. // * Note that this struct must live as long as the main JPEG parameter // * struct, to avoid dangling-pointer problems. // */ // struct jpeg_error_mgr jerr; // /* More stuff */ // JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ // int row_stride; /* physical row width in image buffer */ // /* Step 1: allocate and initialize JPEG compression object */ // /* We have to set up the error handler first, in case the initialization // * step fails. (Unlikely, but it could happen if you are out of memory.) // * This routine fills in the contents of struct jerr, and returns jerr's // * address which we place into the link field in cinfo. // */ // cinfo.err = jpeg_std_error(&jerr); // /* Now we can initialize the JPEG compression object. */ // jpeg_create_compress(&cinfo); // unsigned long jpegSize = 0; // unsigned char *jpegBuf = NULL; // /* Step 2: specify data destination (eg, a file) */ // /* Note: steps 2 and 3 can be done in either order. */ // /* Here we use the library-supplied code to send compressed data to a // * stdio stream. You can also write your own code to do something else. // * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that // * requires it in order to write binary files. // */ // jpeg_mem_dest(&cinfo, &jpegBuf, &jpegSize); // /* Step 3: set parameters for compression */ // /* First we supply a description of the input image. // * Four fields of the cinfo struct must be filled in: // */ // cinfo.image_width = w; /* image width and height, in pixels */ // cinfo.image_height = h; // cinfo.input_components = 3; /* # of color components per pixel */ // cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ // /* Now use the library's routine to set default compression parameters. // * (You must set at least cinfo.in_color_space before calling this, // * since the defaults depend on the source color space.) // */ // jpeg_set_defaults(&cinfo); // /* Now you can set any non-default parameters you wish to. // * Here we just illustrate the use of quality (quantization table) scaling: // */ // jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */); // /* Step 4: Start compressor */ // /* TRUE ensures that we will write a complete interchange-JPEG file. // * Pass TRUE unless you are very sure of what you're doing. // */ // jpeg_start_compress(&cinfo, TRUE); // /* Step 5: while (scan lines remain to be written) */ // /* jpeg_write_scanlines(...); */ // /* Here we use the library's state variable cinfo.next_scanline as the // * loop counter, so that we don't have to keep track ourselves. // * To keep things simple, we pass one scanline per call; you can pass // * more if you wish, though. // */ // row_stride = w * 3; /* JSAMPLEs per row in image_buffer */ // while (cinfo.next_scanline < cinfo.image_height) // { // /* jpeg_write_scanlines expects an array of pointers to scanlines. // * Here the array is only one element long, but you could pass // * more than one scanline at a time if that's more convenient. // */ // row_pointer[0] = &rgbout[(h - cinfo.next_scanline - 1) * row_stride]; // (void)jpeg_write_scanlines(&cinfo, row_pointer, 1); // } // /* Step 6: Finish compression */ // jpeg_finish_compress(&cinfo); // /* After finish_compress, we can close the output file. */ // printf("--myboundary"); // CRLF(); // printf("Content-Type: image/jpeg"); // CRLF(); // printf("Content-Length: %d", jpegSize); // CRLF(); // CRLF(); // fwrite(jpegBuf, 1, jpegSize, stdout); // // FILE * pFile; // // pFile = fopen ("/tmp/myfile.jpg","wb"); // // if (pFile!=NULL) // // { // // fwrite(jpegBuf, 1, jpegSize, pFile); // // fclose (pFile); // // } // CRLF(); // /* Step 7: release JPEG compression object */ // /* This is an important step since it will release a good deal of memory. */ // jpeg_destroy_compress(&cinfo); // /* And we're done! */ // // Free jpeg memory // free(jpegBuf); // }
TBSniller/tv-native-apis
libgm-wayland/src/gmw_c.c
<filename>libgm-wayland/src/gmw_c.c #include "gm-wayland/gmw_c.h" int GM_CreateSurface(int16_t width, int16_t height, int32_t pixfmt, HAL_GAL_SURFACE_INFO_T *info) { return -1; } int GM_FillRectangle(HAL_GAL_SURFACE_INFO_T *info, HAL_GAL_RECT_T *surfacereturn, int32_t dummy, HAL_GAL_DRAW_FLAGS_T *drawflags, HAL_GAL_DRAW_SETTINGS_T *settings) { return -1; } //int GM_CaptureFrameBuffer(HAL_GAL_SURFACE_INFO_T *info) { return -1; } int GM_DestroySurface(HAL_GAL_SURFACE_INFO_T *info) { return -1; }
tizenorg/framework.api.location-manager
test/location_test.c
/* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <glib.h> #include <locations.h> location_manager_h manager; void zone_event_cb(location_boundary_state_e state, double latitude, double longitude, double altitude, time_t timestamp, void *user_data) { if (state == LOCATIONS_BOUNDARY_IN) { printf("Entering zone\n"); } else // state == LOCATIONS_BOUNDARY_OUT { printf("Leaving zone\n"); } printf("Latitude: %lf, longitude: %lf, altitude: %lf\n", latitude, longitude, altitude); printf("Time: %s\n", ctime(&timestamp)); } static bool satellites_foreach_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_in_use, void *user_data) { printf("[Satellite information] azimuth : %d, elevation : %d, prn :%d, snr : %d, used: %d\n", azimuth, elevation, prn, snr, is_in_use); return true; } static bool last_satellites_foreach_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_in_use, void *user_data) { printf("[Last Satellite information] azimuth : %d, elevation : %d, prn :%d, snr : %d, used: %d\n", azimuth, elevation, prn, snr, is_in_use); return true; } static void _state_change_cb(location_service_state_e state, void *user_data) { fprintf(stderr, "--------------------------state change %d---------\n", state); location_manager_h lm = (location_manager_h) user_data; if (state == LOCATIONS_SERVICE_ENABLED) { int ret; double altitude; double latitude; double longitude; time_t timestamp; ret = location_manager_get_position(lm, &altitude, &latitude, &longitude, &timestamp); if (ret != LOCATIONS_ERROR_NONE) { printf(" Fail : location_manager_get_position ---> %d \n", ret); } else { printf("[%ld] alt: %g, lat %g, long %g\n", timestamp, altitude, latitude, longitude); } location_accuracy_level_e level; double horizontal; double vertical; ret = location_manager_get_accuracy(lm, &level, &horizontal, &vertical); if (ret != LOCATIONS_ERROR_NONE) { printf(" Fail : location_manager_get_accuracy ---> %d \n", ret); } else { printf("Level : %d, horizontal: %g, vertical %g\n", level, horizontal, vertical); } char *nmea; ret = gps_status_get_nmea(lm, &nmea); if (ret != LOCATIONS_ERROR_NONE) { printf(" Fail : gps_status_get_nmea ---> %d \n", ret); } else { printf("NMEA : %s\n", nmea); free(nmea); } int num_of_view, num_of_active; ret = gps_status_get_satellite(lm, &num_of_active, &num_of_view, &timestamp); if (ret != LOCATIONS_ERROR_NONE) { printf(" Fail : gps_status_get_satellite_count_in_view ---> %d \n", ret); } else { printf("[%ld] Satellite number of active : %d, in view : %d\n", timestamp, num_of_active, num_of_view); } ret = gps_status_foreach_satellites_in_view(lm, satellites_foreach_cb, user_data); if (ret != LOCATIONS_ERROR_NONE) { printf(" Fail : gps_status_foreach_satellites_in_view ---> %d \n", ret); } } } static bool __poly_coords_cb(location_coords_s coords, void *user_data) { printf("location_bounds_foreach_rect_coords(latitude : %lf, longitude: %lf) \n", coords.latitude, coords.longitude); return TRUE; } static bool __location_bounds_cb(location_bounds_h bounds, void *user_data) { if (bounds == NULL) printf("bounds ==NULL\n"); else { location_bounds_type_e type; location_bounds_get_type(bounds, &type); if (type == LOCATION_BOUNDS_CIRCLE) { location_coords_s center; double radius; location_bounds_get_circle_coords(bounds, &center, &radius); printf("location_bounds_get_circle_coords(center : %lf, %lf, radius : %lf) \n", center.latitude, center.longitude, radius); } else if (type == LOCATION_BOUNDS_RECT) { location_coords_s left_top; location_coords_s right_bottom; location_bounds_get_rect_coords(bounds, &left_top, &right_bottom); printf("location_bounds_get_rect_coords(left_top : %lf, %lf - right_bottom : %lf, %lf) \n", left_top.latitude, left_top.longitude, right_bottom.latitude, right_bottom.longitude); } else if (type == LOCATION_BOUNDS_POLYGON) { location_bounds_foreach_polygon_coords(bounds, __poly_coords_cb, NULL); } } return TRUE; } void location_bounds_test() { int ret; location_coords_s center; center.latitude = 37.258; center.longitude = 127.056; double radius = 30; location_bounds_h bounds_circle; ret = location_bounds_create_circle(center, radius, &bounds_circle); if (ret != LOCATION_BOUNDS_ERROR_NONE) { printf("location_bounds_create_circle() failed\n"); } else printf("Bounds(circle) has been created successfully.\n"); ret = location_manager_add_boundary(manager, bounds_circle); if (ret != LOCATIONS_ERROR_NONE) { printf("Setting boundary failed\n"); } else printf("Boundary set\n"); location_coords_s center2; double radius2; ret = location_bounds_get_circle_coords(bounds_circle, &center2, &radius2); if (ret != LOCATIONS_ERROR_NONE) { printf("location_bounds_get_circle_coords() failed\n"); } else printf("location_bounds_get_circle_coords(center : %lf, %lf, radius : %lf) \n", center2.latitude, center2.longitude, radius2); //Add the rect bounds location_coords_s left_top; left_top.latitude = 30; left_top.longitude = 30; location_coords_s right_bottom; right_bottom.latitude = 10; right_bottom.longitude = 50; location_bounds_h bounds_rect; ret = location_bounds_create_rect(left_top, right_bottom, &bounds_rect); if (ret != LOCATION_BOUNDS_ERROR_NONE) { printf("location_bounds_create_rect() failed\n"); } else printf("Bounds(rect) has been created successfully.\n"); ret = location_manager_add_boundary(manager, bounds_rect); if (ret != LOCATIONS_ERROR_NONE) { printf("Setting boundary failed\n"); } else printf("Boundary set\n"); location_coords_s left_top2; location_coords_s right_bottom2; ret = location_bounds_get_rect_coords(bounds_rect, &left_top2, &right_bottom2); if (ret != LOCATIONS_ERROR_NONE) { printf("location_bounds_get_rect_coords() failed\n"); } else printf("location_bounds_get_rect_coords(left_top : %lf, %lf - right_bottom : %lf, %lf) \n", left_top2.latitude, left_top2.longitude, right_bottom2.latitude, right_bottom2.longitude); //Add the polygon bounds int poly_size = 3; location_coords_s coord_list[poly_size]; coord_list[0].latitude = 10; coord_list[0].longitude = 10; coord_list[1].latitude = 20; coord_list[1].longitude = 20; coord_list[2].latitude = 30; coord_list[2].longitude = 30; location_bounds_h bounds_poly; ret = location_bounds_create_polygon(coord_list, poly_size, &bounds_poly); if (ret != LOCATION_BOUNDS_ERROR_NONE) { printf("location_bounds_create_polygon() failed\n"); } else printf("Bounds(polygon) has been created successfully.\n"); ret = location_manager_add_boundary(manager, bounds_poly); if (ret != LOCATIONS_ERROR_NONE) { printf("Setting boundary failed\n"); } else printf("Boundary set\n"); ret = location_bounds_foreach_polygon_coords(bounds_poly, __poly_coords_cb, NULL); if (ret != LOCATIONS_ERROR_NONE) { printf("location_bounds_get_rect_coords() failed\n"); } location_coords_s test_coords; test_coords.latitude = 12; test_coords.longitude = 12; if (location_bounds_contains_coordinates(bounds_poly, test_coords)) printf("location_bounds_contains_coordinates() retrun TRUE \n"); else printf("location_bounds_contains_coordinates() retrun FALSE \n"); //print current bounds ret = location_manager_foreach_boundary(manager, __location_bounds_cb, (void *)manager); if (ret != LOCATIONS_ERROR_NONE) { printf("location_manager_foreach_boundary() failed\n"); } } void location_get_last_information_test() { int ret; double altitude, latitude, longitude; double climb, direction, speed; double horizontal, vertical; location_accuracy_level_e level; time_t timestamp; int num_of_inview, num_of_active; ret = location_manager_get_last_position(manager, &altitude, &latitude, &longitude, &timestamp); if (ret != LOCATIONS_ERROR_NONE) { printf(" Fail : location_manager_get_last_position ---> %d \n", ret); } else { printf("[%ld] alt: %g, lat: %g, long: %g\n", timestamp, altitude, latitude, longitude); } ret = location_manager_get_last_velocity(manager, &climb, &direction, &speed, &timestamp); if (ret != LOCATIONS_ERROR_NONE) { printf(" Fail : location_manager_get_last_velocity ---> %d \n", ret); } else { printf("climb: %f, direction: %f, speed: %f\n", climb, direction, speed); } ret = location_manager_get_last_accuracy(manager, &level, &horizontal, &vertical); if (ret != LOCATIONS_ERROR_NONE) { printf(" Fail : location_manager_get_last_accuracy ---> %d \n", ret); } else { printf("Level : %d, horizontal: %g, vertical : %g\n", level, horizontal, vertical); } ret = gps_status_get_last_satellite(manager, &num_of_active, &num_of_inview, &timestamp); if (ret != LOCATIONS_ERROR_NONE) { printf(" Fail : gps_status_get_last_satellite_count_in_view ---> %d \n", ret); } else { printf("[%ld] Satellite number of active : %d, in view : %d\n", timestamp, num_of_active, num_of_inview); } ret = gps_status_foreach_last_satellites_in_view(manager, last_satellites_foreach_cb, NULL); if (ret != LOCATIONS_ERROR_NONE) { printf(" Fail : gps_status_foreach_last_satellites_in_view ---> %d \n", ret); } } int location_test() { int ret; ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager); printf("create : %d\n", ret); location_bounds_test(); location_get_last_information_test(); //set zone changed callback ret = location_manager_set_zone_changed_cb(manager, zone_event_cb, (void *)manager); printf("set zone callback : %d\n", ret); ret = location_manager_set_service_state_changed_cb(manager, _state_change_cb, (void *)manager); printf("set state callback : %d\n", ret); ret = location_manager_start(manager); printf("start : %d\n", ret); return 1; } static GMainLoop *g_mainloop = NULL; static gboolean exit_program(gpointer data) { if (manager == NULL) { printf("manager == NULL \n"); } else { int ret = location_manager_stop(manager); printf("stop : %d\n", ret); ret = location_manager_destroy(manager); printf("destroy : %d\n", ret); } g_main_loop_quit(g_mainloop); printf("Quit g_main_loop\n"); return FALSE; } int main(int argc, char **argv) { g_setenv("PKG_NAME", "com.samsung.location-test", 1); g_mainloop = g_main_loop_new(NULL, 0); location_test(); g_timeout_add_seconds(90, exit_program, NULL); g_main_loop_run(g_mainloop); return 0; }
tizenorg/framework.api.location-manager
include/location_bounds.h
<reponame>tizenorg/framework.api.location-manager /* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __TIZEN_LOCATION_BOUNDS_H__ #define __TIZEN_LOCATION_BOUNDS_H__ #include <tizen_type.h> #include <tizen_error.h> #ifdef __cplusplus extern "C" { #endif #define LOCATION_BOUNDS_ERROR_CLASS TIZEN_ERROR_LOCATION_CLASS | 0x20 /** * @addtogroup CAPI_LOCATION_BOUNDS_MODULE * @{ */ /** * @brief Represents a coordinates with latitude and longitude. */ typedef struct { double latitude; /**< The latitude [-90.0 ~ 90.0] (degrees) */ double longitude; /**< The longitude [-180.0 ~ 180.0] (degrees) */ } location_coords_s; /** * @brief The location boundary handle. */ typedef void *location_bounds_h; /** * @brief Enumerations of error code for Location manager. */ typedef enum { LOCATION_BOUNDS_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ LOCATION_BOUNDS_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ LOCATION_BOUNDS_ERROR_INCORRECT_TYPE = LOCATION_BOUNDS_ERROR_CLASS | 0x01, /**< Incorrect bounds type for a given call */ } location_bound_error_e; /** * @brief Location boundary type. */ typedef enum { LOCATION_BOUNDS_RECT=1, /**< Rectangular geographical area type. */ LOCATION_BOUNDS_CIRCLE, /**< Circle geographical area type.. */ LOCATION_BOUNDS_POLYGON, /**< Polygon geographical area type.. */ } location_bounds_type_e; /** * @brief Gets called iteratively to notify you of coordinates of polygon. * @param[in] coords The coordinates * @param[in] user_data The user data passed from the foreach function * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop * @pre location_bounds_foreach_polygon_coords() will invoke this callback. * @see location_bounds_foreach_polygon_coords() */ typedef bool (*polygon_coords_cb)(location_coords_s coords, void *user_data); /** * @brief Creates a rect type of new location bounds. * @remarks @a bounds must be released location_bounds_destroy() by you. * @param[in] top_left The top left position * @param[in] bottom_right The bottom right position * @param[out] bounds A location bounds handle to be newly created on success * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_BOUNDS_ERROR_NONE Successful * @retval #LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY Out of memory * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter * @see location_bounds_get_rect_coords() * @see location_bounds_destroy() */ int location_bounds_create_rect(location_coords_s top_left, location_coords_s bottom_right, location_bounds_h* bounds); /** * @brief Creates a circle type of new location bounds. * @remarks @a bounds must be released location_bounds_destroy() by you. * @param[in] center The center position * @param[in] radius The radius of a circle (meters) * @param[out] bounds A location bounds handle to be newly created on success * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_BOUNDS_ERROR_NONE Successful * @retval #LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY Out of memory * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter * @see location_bounds_get_circle_coords() * @see location_bounds_destroy() */ int location_bounds_create_circle(location_coords_s center, double radius, location_bounds_h* bounds); /** * @brief Creates a polygon type of new location bounds. * @remarks @a bounds must be released location_bounds_destroy() by you. * @remarks @a length sholud be over than 3 to represent polygon. * @param[in] coords_list The list of coordinates * @param[in] length The length of the coordinates list * @param[out] bounds A location bounds handle to be newly created on success * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_BOUNDS_ERROR_NONE Successful * @retval #LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY Out of memory * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter * @see location_bounds_foreach_polygon_coords() * @see location_bounds_destroy() */ int location_bounds_create_polygon(location_coords_s* coords_list, int length, location_bounds_h* bounds); /** * @brief Check if the bounds contains the specified coordinates. * @param[in] bounds The location bounds handle * @param[in] coords The coordinates * @param[out] contained The result indicating whether the boundary contains the specified coordinate (@c true = contained, @c false = not contained ) * @return @c true if the bouns contains the specified coordinates. \n else @c false * @see location_bounds_create_rect() * @see location_bounds_create_circle() * @see location_bounds_create_polygon() */ bool location_bounds_contains_coordinates(location_bounds_h bounds, location_coords_s coords); /** * @brief Get the type of location bounds. * @param[in] bounds The location bounds handle * @param[out] type The type of location bounds * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_BOUNDS_ERROR_NONE Successful * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter * @see location_bounds_create_rect() * @see location_bounds_create_circle() * @see location_bounds_create_polygon() */ int location_bounds_get_type(location_bounds_h bounds, location_bounds_type_e *type); /** * @brief Get the center position and radius of circle bounds. * @param[in] bounds The location bounds handle * @param[out] top_left The top left position * @param[out] bottom_right The bottom right position * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_BOUNDS_ERROR_NONE Successful * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter * @retval #LOCATION_BOUNDS_ERROR_INCORRECT_TYPE Incorrect bounds type * @see location_bounds_create_rect() */ int location_bounds_get_rect_coords(location_bounds_h bounds, location_coords_s *top_left, location_coords_s *bottom_right); /** * @brief Get the center position and radius of circle bounds. * @param[in] bounds The location bounds handle * @param[out] center The center position of circle * @param[radius] center The radius of circle * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_BOUNDS_ERROR_NONE Successful * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter * @retval #LOCATION_BOUNDS_ERROR_INCORRECT_TYPE Incorrect bounds type * @see location_bounds_create_circle() */ int location_bounds_get_circle_coords(location_bounds_h bounds, location_coords_s *center, double *radius); /** * @brief Get the coordinates of polygon. * @param[in] bounds The location bounds handle * @param[in] callback The geocoder get positions callback function * @param[in] user_data The user data to be passed to the callback function * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_BOUNDS_ERROR_NONE Successful * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter * @retval #LOCATION_BOUNDS_ERROR_INCORRECT_TYPE Incorrect bounds type * @post It invokes polygon_coords_cb() to get coordinates of polygon. * @see polygon_coords_cb() * @see location_bounds_create_polygon() */ int location_bounds_foreach_polygon_coords(location_bounds_h bounds, polygon_coords_cb callback, void *user_data); /** * @brief Releases the location bounds. * @param[in] bounds The location bounds handle * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_BOUNDS_ERROR_NONE Successful * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter * @see location_bounds_create_rect() * @see location_bounds_create_circle() * @see location_bounds_create_polygon() */ int location_bounds_destroy(location_bounds_h bounds); /** * @} */ #ifdef __cplusplus } #endif #endif /* __TIZEN_LOCATION_BOUNDS_H__ */
tizenorg/framework.api.location-manager
src/location_preference.c
/* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <location_preference.h> #include <dlog.h> #include <location-map-service.h> #include <stdlib.h> #include <string.h> #ifdef LOG_TAG #undef LOG_TAG #endif #define LOG_TAG "TIZEN_N_LOCATION_PREFERENCE" /* * Internal Macros */ #define LOCATION_PREFERENCE_CHECK_CONDITION(condition, error, msg) \ if(condition) {} else \ { LOGE("[%s] %s(0x%08x)", __FUNCTION__, msg, error); return error; }; #define LOCATION_PREFERENCE_NULL_ARG_CHECK(arg) \ LOCATION_PREFERENCE_CHECK_CONDITION(arg != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER") #define LOCATION_PREFERENCE_PRINT_ERROR_CODE(error, msg) \ LOGE("[%s] %s(0x%08x)",__FUNCTION__, msg, error); return error; #define LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service) *((LocationMapObject**)service) /* * Internal Implementation */ static int __convert_error_code(int code, char* func_name) { int ret = LOCATION_PREFERENCE_ERROR_NONE; char* msg = "LOCATION_PREFERENCE_ERROR_NONE"; switch(code) { case LOCATION_ERROR_NONE: ret = LOCATION_PREFERENCE_ERROR_NONE; msg = "LOCATION_PREFERENCE_ERROR_NONE"; break; case LOCATION_ERROR_NETWORK_NOT_CONNECTED: ret = LOCATION_PREFERENCE_ERROR_NETWORK_FAILED; msg = "LOCATION_PREFERENCE_ERROR_NETWORK_FAILED"; break; case LOCATION_ERROR_PARAMETER: ret = LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER; msg = "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"; break; case LOCATION_ERROR_NOT_AVAILABLE: msg = "LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND"; ret = LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND; } LOGE("[%s] %s(0x%08x)", func_name, msg, ret); return ret; } /* * Public Implementation */ int location_preference_foreach_available_property_keys(location_service_h service, location_preference_available_property_key_cb callback, void* user_data) { LocationMapObject* object = NULL; GList* keys = NULL; char* key = NULL; int ret = 0; LOCATION_PREFERENCE_NULL_ARG_CHECK(service); LOCATION_PREFERENCE_NULL_ARG_CHECK(callback); object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service); ret = location_map_get_provider_capability_key(object, MAP_SERVICE_PREF_PROPERTY, &keys); if(ret != LOCATION_ERROR_NONE) { return __convert_error_code(ret, (char*)__FUNCTION__); } else { while(keys) { key = keys->data; if(!callback(key, user_data)) break; keys = keys->next; } return LOCATION_PREFERENCE_ERROR_NONE; } } int location_preference_foreach_available_property_values(location_service_h service, const char* key, location_preference_available_property_value_cb callback, void* user_data) { LOCATION_PREFERENCE_NULL_ARG_CHECK(service); LOCATION_PREFERENCE_NULL_ARG_CHECK(key); LOCATION_PREFERENCE_NULL_ARG_CHECK(callback); return LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND; } int location_preference_foreach_available_languages(location_service_h service, location_preference_available_language_cb callback, void* user_data) { LocationMapObject* object = NULL; GList* keys = NULL; char* key = NULL; int ret = 0; LOCATION_PREFERENCE_NULL_ARG_CHECK(service); LOCATION_PREFERENCE_NULL_ARG_CHECK(callback); object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service); ret = location_map_get_provider_capability_key(object, MAP_SERVICE_PREF_LANGUAGE, &keys); if(ret != LOCATION_ERROR_NONE) { return __convert_error_code(ret, (char*)__FUNCTION__); } else { while(keys) { key = keys->data; if(!callback(key, user_data)) break; keys = keys->next; } return LOCATION_PREFERENCE_ERROR_NONE; } } int location_preference_foreach_properties(location_service_h service, location_preference_property_cb callback, void* user_data) { LocationMapPref* pref = NULL; LocationMapObject* object = NULL; GList* keys = NULL; char* key = NULL; char* value = NULL; LOCATION_PREFERENCE_NULL_ARG_CHECK(service); LOCATION_PREFERENCE_NULL_ARG_CHECK(callback); object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service); pref = location_map_get_service_pref(object); LOCATION_PREFERENCE_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); keys = location_map_pref_get_property_key(pref); while(keys) { key = keys->data; value = (char*)location_map_pref_get_property(pref, key); if(!callback(key, value, user_data)) break; keys = keys->next; } location_map_pref_free(pref); return LOCATION_PREFERENCE_ERROR_NONE; } int location_preference_set(location_service_h service, const char* key, const char* value) { LocationMapPref* pref = NULL; LocationMapObject* object = NULL; LOCATION_PREFERENCE_NULL_ARG_CHECK(service); LOCATION_PREFERENCE_NULL_ARG_CHECK(key); LOCATION_PREFERENCE_NULL_ARG_CHECK(value); object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service); pref = location_map_get_service_pref(object); LOCATION_PREFERENCE_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); location_map_pref_set_property(pref, (gconstpointer)key, (gconstpointer)value); location_map_set_service_pref(object, pref); location_map_pref_free(pref); return LOCATION_PREFERENCE_ERROR_NONE; } int location_preference_get(location_service_h service, const char* key, char** value) { LocationMapPref* pref = NULL; LocationMapObject* object = NULL; char* ret = NULL; LOCATION_PREFERENCE_NULL_ARG_CHECK(service); LOCATION_PREFERENCE_NULL_ARG_CHECK(key); LOCATION_PREFERENCE_NULL_ARG_CHECK(value); object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service); pref = location_map_get_service_pref(object); LOCATION_PREFERENCE_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); ret = (char*)location_map_pref_get_property(pref, (gconstpointer)key); if(ret != NULL) { *value = strdup(ret); location_map_pref_free(pref); } else { *value = NULL; location_map_pref_free(pref); LOCATION_PREFERENCE_PRINT_ERROR_CODE(LOCATION_PREFERENCE_ERROR_INVALID_KEY, "LOCATION_PREFERENCE_ERROR_INVALID_KEY"); } return LOCATION_PREFERENCE_ERROR_NONE; } int location_preference_set_provider(location_service_h service, char* provider) { LOCATION_PREFERENCE_NULL_ARG_CHECK(service); LOCATION_PREFERENCE_NULL_ARG_CHECK(provider); LocationMapObject *object = NULL; LocationMapPref *pref = NULL; gboolean ret = FALSE; object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service); pref = location_map_get_service_pref(object); LOCATION_PREFERENCE_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); ret = location_map_pref_set_provider_name(pref, provider); if (!ret) { location_map_pref_free(pref); LOCATION_PREFERENCE_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_KEY, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); } ret = location_map_set_service_pref(object, pref); if (!ret) { location_map_pref_free(pref); LOCATION_PREFERENCE_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_KEY, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); } location_map_pref_free(pref); return LOCATION_PREFERENCE_ERROR_NONE; } int location_preference_get_provider(location_service_h service, char** provider) { LOCATION_PREFERENCE_NULL_ARG_CHECK(service); LOCATION_PREFERENCE_NULL_ARG_CHECK(provider); LocationMapObject *object = NULL; LocationMapPref *pref = NULL; gchar* current_provider = NULL; object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service); pref = location_map_get_service_pref(object); LOCATION_PREFERENCE_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); current_provider = location_map_pref_get_provider_name(pref); if (!current_provider) { location_map_pref_free(pref); LOCATION_PREFERENCE_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_KEY, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); } *provider = g_strdup (current_provider); location_map_pref_free(pref); return LOCATION_PREFERENCE_ERROR_NONE; } int location_preference_get_default_provider(location_service_h service, char** provider) { LOCATION_PREFERENCE_NULL_ARG_CHECK(service); LOCATION_PREFERENCE_NULL_ARG_CHECK(provider); LocationMapObject *object = NULL; gchar *current_provider = NULL; object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service); current_provider = location_map_get_default_provider(object); LOCATION_PREFERENCE_CHECK_CONDITION(current_provider != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); *provider = g_strdup(current_provider); g_free(current_provider); return LOCATION_PREFERENCE_ERROR_NONE; } int location_preference_foreach_supported_provider(location_service_h service, location_preference_supported_provider_cb callback , void *user_data) { LOCATION_PREFERENCE_NULL_ARG_CHECK(service); LOCATION_PREFERENCE_NULL_ARG_CHECK(callback); LocationMapObject *object = NULL; GList *providers = NULL; gchar *provider = NULL; object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service); providers = location_map_get_supported_providers(object); LOCATION_PREFERENCE_CHECK_CONDITION(providers != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); while(providers) { provider = providers->data; if(!callback(provider, user_data)) break; providers = providers->next; } return LOCATION_PREFERENCE_ERROR_NONE; } int location_preference_get_provider_name(location_service_h service, char** provider) { LocationMapPref* pref = NULL; LocationMapObject* object = NULL; char* ret = NULL; LOCATION_PREFERENCE_NULL_ARG_CHECK(service); LOCATION_PREFERENCE_NULL_ARG_CHECK(provider); object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service); pref = location_map_get_service_pref(object); LOCATION_PREFERENCE_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); ret = location_map_pref_get_provider_name(pref); if(ret != NULL) *provider = strdup(ret); else *provider = NULL; location_map_pref_free(pref); return LOCATION_PREFERENCE_ERROR_NONE; } int location_preference_get_distance_unit(location_service_h service, location_preference_distance_unit_e* unit) { LocationMapPref* pref = NULL; LocationMapObject* object = NULL; char* ret = NULL; LOCATION_PREFERENCE_NULL_ARG_CHECK(service); LOCATION_PREFERENCE_NULL_ARG_CHECK(unit); object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service); pref = location_map_get_service_pref(object); LOCATION_PREFERENCE_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); ret = location_map_pref_get_distance_unit(pref); if(ret != NULL) { switch(ret[0]) { case 'F' : *unit = LOCATION_PREFERENCE_DISTANCE_UNIT_FT; break; case 'K' : *unit = LOCATION_PREFERENCE_DISTANCE_UNIT_KM; break; case 'Y' : *unit = LOCATION_PREFERENCE_DISTANCE_UNIT_YD; break; case 'M' : if(ret[1] == 'I') *unit = LOCATION_PREFERENCE_DISTANCE_UNIT_MI; else *unit = LOCATION_PREFERENCE_DISTANCE_UNIT_M; break; } location_map_pref_free(pref); return LOCATION_PREFERENCE_ERROR_NONE; } else { location_map_pref_free(pref); LOCATION_PREFERENCE_PRINT_ERROR_CODE(LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND, "LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND"); } } int location_preference_set_distance_unit(location_service_h service, location_preference_distance_unit_e unit) { LocationMapPref* pref = NULL; LocationMapObject* object = NULL; char* distance = NULL; LOCATION_PREFERENCE_NULL_ARG_CHECK(service); switch(unit) { case LOCATION_PREFERENCE_DISTANCE_UNIT_FT : distance = "FT"; break; case LOCATION_PREFERENCE_DISTANCE_UNIT_KM : distance = "KM"; break; case LOCATION_PREFERENCE_DISTANCE_UNIT_YD : distance = "YD"; break; case LOCATION_PREFERENCE_DISTANCE_UNIT_MI : distance = "MI"; break; case LOCATION_PREFERENCE_DISTANCE_UNIT_M : distance = "M"; break; default : LOCATION_PREFERENCE_PRINT_ERROR_CODE(LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); } object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service); pref = location_map_get_service_pref(object); LOCATION_PREFERENCE_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); location_map_pref_set_distance_unit(pref, distance); location_map_set_service_pref(object, pref); location_map_pref_free(pref); return LOCATION_PREFERENCE_ERROR_NONE; } int location_preference_get_language(location_service_h service, char** language) { LocationMapPref* pref = NULL; LocationMapObject* object = NULL; char* ret = NULL; LOCATION_PREFERENCE_NULL_ARG_CHECK(service); LOCATION_PREFERENCE_NULL_ARG_CHECK(language); object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service); pref = location_map_get_service_pref(object); LOCATION_PREFERENCE_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); ret = location_map_pref_get_language(pref); if(ret != NULL) *language = strdup(ret); else *language = NULL; location_map_pref_free(pref); return LOCATION_PREFERENCE_ERROR_NONE; } int location_preference_set_language(location_service_h service, const char* language) { LocationMapPref* pref = NULL; LocationMapObject* object = NULL; LOCATION_PREFERENCE_NULL_ARG_CHECK(service); LOCATION_PREFERENCE_NULL_ARG_CHECK(language); object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service); pref = location_map_get_service_pref(object); LOCATION_PREFERENCE_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); location_map_pref_set_language(pref, language); location_map_set_service_pref(object, pref); location_map_pref_free(pref); return LOCATION_PREFERENCE_ERROR_NONE; } int location_preference_get_country_code(location_service_h service, char** country_code) { LocationMapPref* pref = NULL; LocationMapObject* object = NULL; char* ret = NULL; LOCATION_PREFERENCE_NULL_ARG_CHECK(service); LOCATION_PREFERENCE_NULL_ARG_CHECK(country_code); object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service); pref = location_map_get_service_pref(object); LOCATION_PREFERENCE_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); ret = location_map_pref_get_country(pref); if(ret != NULL) *country_code = strdup(ret); else *country_code = NULL; location_map_pref_free(pref); return LOCATION_PREFERENCE_ERROR_NONE; } int location_preference_set_country_code(location_service_h service, const char* country_code) { LocationMapPref* pref = NULL; LocationMapObject* object = NULL; LOCATION_PREFERENCE_NULL_ARG_CHECK(service); LOCATION_PREFERENCE_NULL_ARG_CHECK(country_code); object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service); pref = location_map_get_service_pref(object); LOCATION_PREFERENCE_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER"); location_map_pref_set_country(pref, country_code); location_map_set_service_pref(object, pref); location_map_pref_free(pref); return LOCATION_PREFERENCE_ERROR_NONE; }
tizenorg/framework.api.location-manager
include/location_preference.h
/* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __TIZEN_LOCATION_LOCATION_PREFERENCE_H__ #define __TIZEN_LOCATION_LOCATION_PREFERENCE_H__ #include <tizen_type.h> #include <tizen_error.h> #ifdef __cplusplus extern "C" { #endif /** * @addtogroup CAPI_LOCATION_PREF_MODULE * @{ */ /** * @brief The handle of location service */ typedef void* location_service_h; /** * @brief Gets a handle of location service from x */ #define GET_LOCATION_SERVICE(x) (location_service_h)(x) /** * @brief Enumerations of error code for Location Preference */ typedef enum { LOCATION_PREFERENCE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND = TIZEN_ERROR_LOCATION_CLASS|0x0101, /**< Result not found */ LOCATION_PREFERENCE_ERROR_NETWORK_FAILED = TIZEN_ERROR_LOCATION_CLASS|0x0102, /**< Network unavailable */ LOCATION_PREFERENCE_ERROR_INVALID_KEY = TIZEN_ERROR_LOCATION_CLASS | 0x0103, /**< Invalid key */ } location_preference_error_e; /** * @brief Enumerations of distance unit */ typedef enum { LOCATION_PREFERENCE_DISTANCE_UNIT_M = 0, /**< Meter */ LOCATION_PREFERENCE_DISTANCE_UNIT_KM = 1, /**< Kilometer */ LOCATION_PREFERENCE_DISTANCE_UNIT_FT = 2, /**< Feet */ LOCATION_PREFERENCE_DISTANCE_UNIT_YD = 3, /**< Mile */ LOCATION_PREFERENCE_DISTANCE_UNIT_MI = 4, /**< Mile */ } location_preference_distance_unit_e; /** * @brief Called repeatedly when you get the available property keys. * @param[in] key The property key of location preference * @param[in] user_data The user data passed from foreach function * @pre location_preference_foreach_available_property_keys() will invoke this callback. * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop * @see location_preference_foreach_available_property_keys() */ typedef bool (*location_preference_available_property_key_cb)(const char* key, void* user_data); /** * @brief Called repeatedly when you get the available property values. * @param[in] value The property value of location preference * @param[in] user_data The user data passed from foreach function * @pre location_preference_foreach_available_property_values() will invoke this callback. * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop * @see location_preference_foreach_available_property_values() */ typedef bool (*location_preference_available_property_value_cb)(const char* value, void* user_data); /** * @brief Called repeatedly when you get the available languages. * @param[in] language The language of location preference * @param[in] user_data The user data passed from foreach function * @pre location_preference_foreach_available_languages() will invoke this callback. * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop * @see location_preference_foreach_available_languages() */ typedef bool (*location_preference_available_language_cb)(const char* language, void* user_data); /** * @brief Called repeatedly when you get the properties that was set in location preference. * @param[in] key The property key of location preference * @param[in] value The property value of location preference * @param[in] user_data The user data passed from foreach function * @pre location_preference_foreach_properties() will invoke this callback. * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop * @see location_preference_foreach_properties() */ typedef bool (*location_preference_property_cb)(const char* key, const char* value, void* user_data); /** * @brief Called repeatedly to get each supported providers. * @param[in] provider The supported provider name * @param[in] user_data The user data passed from the foreach function * @return @c true to continue with the next iteration of the loop, \n @c false to break outsp of the loop. * @pre location_preference_foreach_supported_provider() will invoke this callback. * @see location_preference_foreach_supported_provider() */ typedef bool (*location_preference_supported_provider_cb)(const char* provider, void *user_data); /** * @brief Retrieves the available property keys of location preference. * @param[in] location_service The memory pointer of location service handle. * It must be converted into location_service_h by GET_LOCATION_SERVICE(). * @param[in] callback The callback function to be invoked * @param[in] user_data The user data passed to the callback function * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #LOCATION_PREFERENCE_ERROR_NETWORK_FAILED Network unavailable * @retval #LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND Result not found * @post location_preference_available_property_key_cb() will be invoked. * @see GET_LOCATION_SERVICE() * @see location_preference_available_property_key_cb() * @see location_preference_foreach_available_property_values() */ int location_preference_foreach_available_property_keys(location_service_h service, location_preference_available_property_key_cb callback, void* user_data); /** * @brief Retrieves the available property values of location preference. * @param[in] location_service The memory pointer of location service handle. * It must be converted into location_service_h by GET_LOCATION_SERVICE(). * @param[in] key The property of location preference * @param[in] callback The callback function to be invoked * @param[in] user_data The user data passed to the callback function * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #LOCATION_PREFERENCE_ERROR_INVALID_KEY Invalid key * @retval #LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND Result not found * @post location_preference_available_property_value_cb() will be invoked. * @see GET_LOCATION_SERVICE() * @see location_preference_available_property_value_cb() * @see location_preference_foreach_available_property_keys() */ int location_preference_foreach_available_property_values(location_service_h service, const char* key, location_preference_available_property_value_cb callback, void* user_data); /** * @brief Retrieves the available languages of location preference. * @param[in] location_service The memory pointer of location service handle. * It must be converted into location_service_h by GET_LOCATION_SERVICE(). * @param[in] callback The callback function to be invoked * @param[in] user_data The user data passed to the callback function * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #LOCATION_PREFERENCE_ERROR_NETWORK_FAILED Network unavailable * @retval #LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND Result not found * @post location_preference_available_language_cb() will be invoked. * @see GET_LOCATION_SERVICE() * @see location_preference_available_language_cb() */ int location_preference_foreach_available_languages(location_service_h service, location_preference_available_language_cb callback, void* user_data); /** * @brief Gets the location preference that was set in location preference. * @param[in] location_service The memory pointer of location service handle. * It must be converted into location_service_h by GET_LOCATION_SERVICE(). * @param[in] key The property of location preference * @param[in] callback The callback function to be invoked * @param[in] user_data The user data passed to the callback function * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter * @see GET_LOCATION_SERVICE() */ int location_preference_foreach_properties(location_service_h service, location_preference_property_cb callback, void* user_data); /** * @brief Sets the location preference value. * @param[in] location_service The memory pointer of location service handle. * It must be converted into location_service_h by GET_LOCATION_SERVICE(). * @param[in] property The property of location preference * @param[in] value The value of location preference * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter * @see GET_LOCATION_SERVICE() * @see location_preference_foreach_available_property_keys() * @see location_preference_foreach_available_property_values() * @see location_preference_get() */ int location_preference_set(location_service_h service, const char* key, const char* value); /** * @brief Gets the location preference value. * @param[in] location_service The memory pointer of location service handle. * It must be converted into location_service_h by GET_LOCATION_SERVICE(). * @param[in] property The property of location preference * @param[out] value The value of location preference * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #LOCATION_PREFERENCE_ERROR_INVALID_KEY Invalid key * @see GET_LOCATION_SERVICE() * @see location_preference_foreach_available_property_keys() * @see location_preference_set() */ int location_preference_get(location_service_h service, const char* key, char** value); __attribute__ ((deprecated)) int location_preference_get_provider_name(location_service_h service, char** provider); /** * @brief Sets the provider of location service. * @param[in] location_service The memory pointer of location service handle. * It must be converted into location_service_h by GET_LOCATION_SERVICE(). * @param[in] provider The provider name of location service * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter * @see GET_LOCATION_SERVICE() * @see location_preference_get_provider() */ int location_preference_set_provider(location_service_h service, char* provider); /** * @brief Gets the provider of location service. * @remarks The @a provider must be released with free() by you. * @param[in] location_service The memory pointer of location service handle. * It must be converted into location_service_h by GET_LOCATION_SERVICE(). * @param[out] provider The provider name of location service * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter * @see GET_LOCATION_SERVICE() * @see location_preference_set_provider() */ int location_preference_get_provider(location_service_h service, char** provider); /** * @brief Gets the default provider of location service. * @remarks The @a provider must be released with free() by you. * @param[in] location_service The memory pointer of location service handle. * It must be converted into location_service_h by GET_LOCATION_SERVICE(). * @param[out] provider The default provider name of location service * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter * @see GET_LOCATION_SERVICE() */ int location_preference_get_default_provider(location_service_h service, char** provider); /** * @brief Gets the provider of location service. * @param[in] location_service The memory pointer of location service handle. * It must be converted into location_service_h by GET_LOCATION_SERVICE(). * @param[in] callback The callback function to be invoked * @param[in] user_data The user data passed to the callback function * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter * @post This function invokes location_preference_supported_provider_cb() to get all supported providers. * @see GET_LOCATION_SERVICE() * @see location_preference_set_provider() */ int location_preference_foreach_supported_provider(location_service_h service, location_preference_supported_provider_cb callback , void *user_data); /** * @brief Gets the distance unit of location service. * @param[in] location_service The memory pointer of location service handle. * It must be converted into location_service_h by GET_LOCATION_SERVICE(). * @param[out] unit The distance unit * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND Result not found * @see GET_LOCATION_SERVICE() * @see location_preference_set_distance_unit() */ int location_preference_get_distance_unit(location_service_h service, location_preference_distance_unit_e* unit); /** * @brief Sets the distance unit of location service. * @param[in] location_service The memory pointer of location service handle. * It must be converted into location_service_h by GET_LOCATION_SERVICE(). * @param[in] unit The distance unit * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter * @see GET_LOCATION_SERVICE() * @see location_preference_get_distance_unit() */ int location_preference_set_distance_unit(location_service_h service, location_preference_distance_unit_e unit); /** * @brief Gets the language of location service. * @param[in] location_service The memory pointer of location service handle. * It must be converted into location_service_h by GET_LOCATION_SERVICE(). * @param[out] language The language * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter * @see GET_LOCATION_SERVICE() * @see location_preference_set_language() */ int location_preference_get_language(location_service_h service, char** language); /** * @brief Sets the language of location service. * @param[in] location_service The memory pointer of location service handle. * It must be converted into location_service_h by GET_LOCATION_SERVICE(). * @param[in] language The language * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter * @see GET_LOCATION_SERVICE() * @see location_preference_get_language() */ int location_preference_set_language(location_service_h service, const char* language); /** * @brief Sets the country code. * @param[in] location_service The memory pointer of location service handle. * It must be converted into location_service_h by GET_LOCATION_SERVICE(). * @param[in] country_code The country code * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter * @see GET_LOCATION_SERVICE() * @see location_preference_get_country_code() */ int location_preference_set_country_code(location_service_h service, const char* country_code); /** * @brief Gets the country code. * @param[in] location_service The memory pointer of location service handle. * It must be converted into location_service_h by GET_LOCATION_SERVICE(). * @param[out] country_code The country code * @return 0 on success, otherwise a negative error value. * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter * @see GET_LOCATION_SERVICE() * @see location_preference_set_country_code() */ int location_preference_get_country_code(location_service_h service, char** country_code); /** * @} */ #ifdef __cplusplus } #endif #endif /* __TIZEN_LOCATION_LOCATION_PREFERENCE_H__ */
tizenorg/framework.api.location-manager
src/locations.c
/* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <locations_private.h> #include <dlog.h> #ifdef LOG_TAG #undef LOG_TAG #endif #define LOG_TAG "TIZEN_N_LOCATION_MANAGER" /* * Internal Macros */ #define LOCATIONS_CHECK_CONDITION(condition,error,msg) \ if(condition) {} else \ { LOGE("[%s] %s(0x%08x)",__FUNCTION__, msg,error); return error;}; \ #define LOCATIONS_NULL_ARG_CHECK(arg) \ LOCATIONS_CHECK_CONDITION(arg != NULL,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER") \ /* * Internal Implementation */ static int __convert_error_code(int code, char *func_name) { int ret; char *msg = "LOCATIONS_ERROR_NONE"; switch (code) { case LOCATION_ERROR_NONE: ret = LOCATIONS_ERROR_NONE; msg = "LOCATIONS_ERROR_NONE"; break; case LOCATION_ERROR_NETWORK_FAILED: case LOCATION_ERROR_NETWORK_NOT_CONNECTED: ret = LOCATIONS_ERROR_NETWORK_FAILED; msg = "LOCATIONS_ERROR_NETWORK_FAILED"; break; case LOCATION_ERROR_NOT_ALLOWED: ret = LOCATIONS_ERROR_GPS_SETTING_OFF; msg = "LOCATIONS_ERROR_GPS_SETTING_OFF"; break; case LOCATION_ERROR_NOT_AVAILABLE: case LOCATION_ERROR_CONFIGURATION: case LOCATION_ERROR_PARAMETER: case LOCATION_ERROR_UNKNOWN: default: msg = "LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE"; ret = LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } LOGE("[%s] %s(0x%08x) : core fw error(0x%x)", func_name, msg, ret, code); return ret; } static void __cb_service_updated(GObject * self, guint type, gpointer data, gpointer accuracy, gpointer userdata) { LOGI("[%s] Callback function has been invoked. ", __FUNCTION__); location_manager_s *handle = (location_manager_s *) userdata; if (type == VELOCITY_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY]) { LocationVelocity *vel = (LocationVelocity *) data; LOGI("[%s] Current velocity: timestamp : %d, speed: %f, direction : %f, climb : %f", __FUNCTION__, vel->timestamp, vel->speed, vel->direction, vel->climb); ((location_velocity_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY]) (vel->speed, vel->direction, vel->climb, vel->timestamp, handle->user_data [_LOCATIONS_EVENT_TYPE_VELOCITY]); } else if (type == POSITION_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION]) { LocationPosition *pos = (LocationPosition *) data; LOGI("[%s] Current position: timestamp : %d, latitude : %f, altitude: %f, longitude: %f", __FUNCTION__, pos->timestamp, pos->latitude, pos->altitude, pos->longitude); ((location_position_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION]) (pos->latitude, pos->longitude, pos->altitude, pos->timestamp, handle->user_data [_LOCATIONS_EVENT_TYPE_POSITION]); } else if (type == SATELLITE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) { LocationSatellite *sat = (LocationSatellite *)data; LOGI("[%s] Current satellite information: timestamp : %d, number of active : %d, number of inview : %d", __FUNCTION__, sat->timestamp, sat->num_of_sat_used, sat->num_of_sat_inview); ((gps_status_satellite_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) (sat->num_of_sat_used, sat->num_of_sat_inview, sat->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_SATELLITE]); } } static void __cb_service_enabled(GObject * self, guint status, gpointer userdata) { LOGI("[%s] Callback function has been invoked. ", __FUNCTION__); location_manager_s *handle = (location_manager_s *) userdata; if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) { ((location_service_state_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) (LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]); } } static void __cb_service_disabled(GObject * self, guint status, gpointer userdata) { LOGI("[%s] Callback function has been invoked. ", __FUNCTION__); location_manager_s *handle = (location_manager_s *) userdata; if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) ((location_service_state_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) (LOCATIONS_SERVICE_DISABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]); } static void __cb_zone_in(GObject * self, guint type, gpointer position, gpointer accuracy, gpointer userdata) { location_manager_s *handle = (location_manager_s *) userdata; if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) { LocationPosition *pos = (LocationPosition *) position; ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) (LOCATIONS_BOUNDARY_IN, pos->latitude, pos->longitude, pos->altitude, pos->timestamp, handle->user_data [_LOCATIONS_EVENT_TYPE_BOUNDARY]); } } static void __cb_zone_out(GObject * self, guint type, gpointer position, gpointer accuracy, gpointer userdata) { location_manager_s *handle = (location_manager_s *) userdata; if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) { LocationPosition *pos = (LocationPosition *) position; ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) (LOCATIONS_BOUNDARY_OUT, pos->latitude, pos->longitude, pos->altitude, pos->timestamp, handle->user_data [_LOCATIONS_EVENT_TYPE_BOUNDARY]); } } static int __set_callback(_location_event_e type, location_manager_h manager, void *callback, void *user_data) { LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(callback); location_manager_s *handle = (location_manager_s *) manager; handle->user_cb[type] = callback; handle->user_data[type] = user_data; LOGI("[%s] event type : %d. ", __FUNCTION__, type); return LOCATIONS_ERROR_NONE; } static int __unset_callback(_location_event_e type, location_manager_h manager) { LOCATIONS_NULL_ARG_CHECK(manager); location_manager_s *handle = (location_manager_s *) manager; handle->user_cb[type] = NULL; handle->user_data[type] = NULL; LOGI("[%s] event type : %d. ", __FUNCTION__, type); return LOCATIONS_ERROR_NONE; } static void __foreach_boundary(LocationBoundary * boundary, void *user_data) { location_manager_s *handle = (location_manager_s *) user_data; if (handle != NULL && boundary != NULL) { int ret = -1; location_bounds_h bounds; if (boundary->type == LOCATION_BOUNDARY_CIRCLE) { location_coords_s center; center.latitude = boundary->circle.center->latitude; center.longitude = boundary->circle.center->longitude; ret = location_bounds_create_circle(center, boundary->circle.radius, &bounds); } else if (boundary->type == LOCATION_BOUNDARY_RECT) { location_coords_s left_top; location_coords_s right_bottom; left_top.latitude = boundary->rect.left_top->latitude; left_top.longitude = boundary->rect.left_top->longitude; right_bottom.latitude = boundary->rect.right_bottom->latitude; right_bottom.longitude = boundary->rect.right_bottom->longitude; ret = location_bounds_create_rect(left_top, right_bottom, &bounds); } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) { GList *list = boundary->polygon.position_list; int size = g_list_length(list); if (size > 0) { location_coords_s coords[size]; int cnt = 0; while (list) { LocationPosition *pos = list->data; coords[cnt].latitude = pos->latitude; coords[cnt].longitude = pos->longitude; list = g_list_next(list); cnt++; } ret = location_bounds_create_polygon(coords, size, &bounds); } } else { LOGI("[%s] Invalid boundary type : %d", __FUNCTION__, boundary->type); } if (ret != LOCATIONS_ERROR_NONE) { LOGI("[%s] Failed to create location_bounds : (0x%08x) ", __FUNCTION__, ret); } else { if (handle->is_continue_foreach_bounds) { handle->is_continue_foreach_bounds = ((location_bounds_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]) (bounds, handle-> user_data [_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]); } location_bounds_destroy(bounds); } } else { LOGI("[%s] __foreach_boundary() has been failed", __FUNCTION__); } } ///////////////////////////////////////// // Location Manager //////////////////////////////////////// /* * Public Implementation */ bool location_manager_is_supported_method(location_method_e method) { LocationMethod _method = LOCATION_METHOD_NONE; switch (method) { case LOCATIONS_METHOD_HYBRID: _method = LOCATION_METHOD_HYBRID; break; case LOCATIONS_METHOD_GPS: _method = LOCATION_METHOD_GPS; break; case LOCATIONS_METHOD_WPS: _method = LOCATION_METHOD_WPS; break; case LOCATIONS_METHOD_CPS: _method = LOCATION_METHOD_CPS; break; default: _method = LOCATION_METHOD_NONE; break; } return location_is_supported_method(_method); } int location_manager_create(location_method_e method, location_manager_h * manager) { LOCATIONS_NULL_ARG_CHECK(manager); if (location_init() != LOCATION_ERROR_NONE) return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; LocationMethod _method = LOCATION_METHOD_NONE; switch (method) { case LOCATIONS_METHOD_HYBRID: _method = LOCATION_METHOD_HYBRID; break; case LOCATIONS_METHOD_GPS: _method = LOCATION_METHOD_GPS; break; case LOCATIONS_METHOD_WPS: _method = LOCATION_METHOD_WPS; break; case LOCATIONS_METHOD_CPS: _method = LOCATION_METHOD_CPS; break; case LOCATIONS_METHOD_NONE: return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; default: { LOGE("[%s] LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ", __FUNCTION__, LOCATIONS_ERROR_INVALID_PARAMETER, method); return LOCATIONS_ERROR_INVALID_PARAMETER; } } location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s)); if (handle == NULL) { LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, LOCATIONS_ERROR_OUT_OF_MEMORY); return LOCATIONS_ERROR_OUT_OF_MEMORY; } memset(handle, 0, sizeof(location_manager_s)); handle->object = location_new(_method); if (handle->object == NULL) { LOGE("[%s] LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", __FUNCTION__, LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); free(handle); return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } handle->method = method; handle->is_continue_foreach_bounds = TRUE; *manager = (location_manager_h) handle; return LOCATIONS_ERROR_NONE; } int location_manager_destroy(location_manager_h manager) { LOCATIONS_NULL_ARG_CHECK(manager); location_manager_s *handle = (location_manager_s *) manager; int ret = location_free(handle->object); if (ret != LOCATIONS_ERROR_NONE) { return __convert_error_code(ret, (char *)__FUNCTION__); } free(handle); return LOCATIONS_ERROR_NONE; } int location_manager_start(location_manager_h manager) { LOCATIONS_NULL_ARG_CHECK(manager); location_manager_s *handle = (location_manager_s *) manager; g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle); g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle); g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle); g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle); g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle); int ret = location_start(handle->object); if (ret != LOCATION_ERROR_NONE) { return __convert_error_code(ret, (char *)__FUNCTION__); } return LOCATIONS_ERROR_NONE; } int location_manager_stop(location_manager_h manager) { LOCATIONS_NULL_ARG_CHECK(manager); location_manager_s *handle = (location_manager_s *) manager; int ret = location_stop(handle->object); if (ret != LOCATION_ERROR_NONE) { return __convert_error_code(ret, (char *)__FUNCTION__); } return LOCATIONS_ERROR_NONE; } int location_manager_add_boundary(location_manager_h manager, const location_bounds_h bounds) { LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(bounds); location_manager_s *handle = (location_manager_s *) manager; int ret = location_boundary_add(handle->object,(LocationBoundary*)bounds); if (ret != LOCATION_ERROR_NONE) { return __convert_error_code(ret, (char *)__FUNCTION__); } return LOCATIONS_ERROR_NONE; } int location_manager_remove_boundary(location_manager_h manager, const location_bounds_h bounds) { LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(bounds); location_manager_s *handle = (location_manager_s *) manager; int ret = location_boundary_remove(handle->object, (LocationBoundary*)bounds); if (ret != LOCATION_ERROR_NONE) { return __convert_error_code(ret, (char *)__FUNCTION__); } return LOCATIONS_ERROR_NONE; } int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data) { LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(callback); location_manager_s *handle = (location_manager_s *) manager; handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback; handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data; handle->is_continue_foreach_bounds = TRUE; int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle); if (ret != LOCATION_ERROR_NONE) { return __convert_error_code(ret, (char *)__FUNCTION__); } return LOCATIONS_ERROR_NONE; } int location_manager_get_method(location_manager_h manager, location_method_e * method) { LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(method); location_manager_s *handle = (location_manager_s *) manager; LocationMethod _method = LOCATION_METHOD_NONE; g_object_get(handle->object, "method", &_method, NULL); switch (_method) { case LOCATION_METHOD_NONE: *method = LOCATIONS_METHOD_NONE; break; case LOCATION_METHOD_HYBRID: *method = LOCATIONS_METHOD_HYBRID; break; case LOCATION_METHOD_GPS: *method = LOCATIONS_METHOD_GPS; break; case LOCATION_METHOD_WPS: *method = LOCATIONS_METHOD_WPS; break; case LOCATION_METHOD_CPS: *method = LOCATIONS_METHOD_CPS; break; default: { LOGE("[%s] LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ", __FUNCTION__, LOCATIONS_ERROR_INVALID_PARAMETER, method); return LOCATIONS_ERROR_INVALID_PARAMETER; } } //*method = handle->method; return LOCATIONS_ERROR_NONE; } int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t * timestamp) { LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(altitude); LOCATIONS_NULL_ARG_CHECK(latitude); LOCATIONS_NULL_ARG_CHECK(longitude); LOCATIONS_NULL_ARG_CHECK(timestamp); location_manager_s *handle = (location_manager_s *) manager; int ret; LocationPosition *pos = NULL; LocationAccuracy *acc = NULL; ret = location_get_position(handle->object, &pos, &acc); if (ret != LOCATION_ERROR_NONE) { return __convert_error_code(ret, (char *)__FUNCTION__); } if (pos->status == LOCATION_STATUS_NO_FIX) { *altitude = -1; *latitude = -1; *longitude = -1; } else { if (pos->status == LOCATION_STATUS_3D_FIX) { *altitude = pos->altitude; } else { *altitude = -1; } *latitude = pos->latitude; *longitude = pos->longitude; } *timestamp = pos->timestamp; location_position_free(pos); location_accuracy_free(acc); return LOCATIONS_ERROR_NONE; } int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t * timestamp) { LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(climb); LOCATIONS_NULL_ARG_CHECK(direction); LOCATIONS_NULL_ARG_CHECK(speed); LOCATIONS_NULL_ARG_CHECK(timestamp); location_manager_s *handle = (location_manager_s *) manager; int ret; LocationVelocity *vel = NULL; LocationAccuracy *acc = NULL; ret = location_get_velocity(handle->object, &vel, &acc); if (ret != LOCATION_ERROR_NONE) { return __convert_error_code(ret, (char *)__FUNCTION__); } *climb = vel->climb; *direction = vel->direction; *speed = vel->speed; *timestamp = vel->timestamp; location_velocity_free(vel); location_accuracy_free(acc); return LOCATIONS_ERROR_NONE; } int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e * level, double *horizontal, double *vertical) { LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(level); LOCATIONS_NULL_ARG_CHECK(horizontal); LOCATIONS_NULL_ARG_CHECK(vertical); location_manager_s *handle = (location_manager_s *) manager; int ret; LocationPosition *pos = NULL; LocationAccuracy *acc = NULL; ret = location_get_position(handle->object, &pos, &acc); if (ret != LOCATION_ERROR_NONE) { return __convert_error_code(ret, (char *)__FUNCTION__); } *level = acc->level; *horizontal = acc->horizontal_accuracy; *vertical = acc->vertical_accuracy; location_position_free(pos); location_accuracy_free(acc); return LOCATIONS_ERROR_NONE; } int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t * timestamp) { LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(altitude); LOCATIONS_NULL_ARG_CHECK(latitude); LOCATIONS_NULL_ARG_CHECK(longitude); LOCATIONS_NULL_ARG_CHECK(timestamp); location_manager_s *handle = (location_manager_s *) manager; int ret; LocationPosition *last_pos = NULL; LocationAccuracy *last_acc = NULL; ret = location_get_last_position(handle->object, &last_pos, &last_acc); if (ret != LOCATION_ERROR_NONE) { return __convert_error_code(ret, (char *)__FUNCTION__); } if (last_pos->status == LOCATION_STATUS_NO_FIX) { *altitude = -1; *latitude = -1; *longitude = -1; } else { if (last_pos->status == LOCATION_STATUS_3D_FIX) { *altitude = last_pos->altitude; } else { *altitude = -1; } *latitude = last_pos->latitude; *longitude = last_pos->longitude; } *timestamp = last_pos->timestamp; location_position_free(last_pos); location_accuracy_free(last_acc); return LOCATIONS_ERROR_NONE; } int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t * timestamp) { LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(climb); LOCATIONS_NULL_ARG_CHECK(direction); LOCATIONS_NULL_ARG_CHECK(speed); LOCATIONS_NULL_ARG_CHECK(timestamp); location_manager_s *handle = (location_manager_s *) manager; int ret; LocationVelocity *last_vel = NULL; LocationAccuracy *last_acc = NULL; ret = location_get_last_velocity(handle->object, &last_vel, &last_acc); if (ret != LOCATION_ERROR_NONE) { return __convert_error_code(ret, (char *)__FUNCTION__); } *climb = last_vel->climb; *direction = last_vel->direction; *speed = last_vel->speed; *timestamp = last_vel->timestamp; location_velocity_free(last_vel); location_accuracy_free(last_acc); return LOCATIONS_ERROR_NONE; } int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e * level, double *horizontal, double *vertical) { LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(level); LOCATIONS_NULL_ARG_CHECK(horizontal); LOCATIONS_NULL_ARG_CHECK(vertical); location_manager_s *handle = (location_manager_s *) manager; int ret; LocationPosition *last_pos = NULL; LocationAccuracy *last_acc = NULL; ret = location_get_last_position(handle->object, &last_pos, &last_acc); if (ret != LOCATION_ERROR_NONE) { return __convert_error_code(ret, (char *)__FUNCTION__); } *level = last_acc->level; *horizontal = last_acc->horizontal_accuracy; *vertical = last_acc->vertical_accuracy; location_position_free(last_pos); location_accuracy_free(last_acc); return LOCATIONS_ERROR_NONE; } int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data) { LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); LOCATIONS_NULL_ARG_CHECK(manager); location_manager_s *handle = (location_manager_s *) manager; g_object_set(handle->object, "pos-interval", interval, NULL); return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data); } int location_manager_unset_position_updated_cb(location_manager_h manager) { return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager); } int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data) { LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); LOCATIONS_NULL_ARG_CHECK(manager); location_manager_s *handle = (location_manager_s *) manager; g_object_set(handle->object, "vel-interval", interval, NULL); return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data); } int location_manager_unset_velocity_updated_cb(location_manager_h manager) { return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager); } int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback, void *user_data) { return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data); } int location_manager_unset_service_state_changed_cb(location_manager_h manager) { return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager); } int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data) { return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data); } int location_manager_unset_zone_changed_cb(location_manager_h manager) { return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager); } int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance) { LOCATIONS_NULL_ARG_CHECK(distance); LOCATIONS_CHECK_CONDITION(start_latitude>=-90 && start_latitude<=90,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER,"LOCATION_BOUNDS_ERROR_INVALID_PARAMETER"); LOCATIONS_CHECK_CONDITION(start_longitude>=-180 && start_longitude<=180,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER, "LOCATION_BOUNDS_ERROR_INVALID_PARAMETER"); LOCATIONS_CHECK_CONDITION(end_latitude>=-90 && end_latitude<=90,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER, "LOCATION_BOUNDS_ERROR_INVALID_PARAMETER"); LOCATIONS_CHECK_CONDITION(end_longitude>=-180 && end_longitude<=180,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER, "LOCATION_BOUNDS_ERROR_INVALID_PARAMETER"); int ret = LOCATION_ERROR_NONE; ulong u_distance; LocationPosition *start = location_position_new (0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX); LocationPosition *end = location_position_new (0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX); ret = location_get_distance (start, end, &u_distance); if (ret != LOCATION_ERROR_NONE) { return __convert_error_code(ret, (char *)__FUNCTION__); } *distance = (double)u_distance; return LOCATIONS_ERROR_NONE; } int location_manager_send_command(const char *cmd) { LOCATIONS_NULL_ARG_CHECK(cmd); int ret; ret = location_send_command(cmd); if (ret != LOCATION_ERROR_NONE) { return __convert_error_code(ret, (char *)__FUNCTION__); } return LOCATIONS_ERROR_NONE; } ///////////////////////////////////////// // GPS Status & Satellites //////////////////////////////////////// int gps_status_get_nmea(location_manager_h manager, char **nmea) { LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(nmea); location_manager_s *handle = (location_manager_s *) manager; if (handle->method == LOCATIONS_METHOD_HYBRID) { LocationMethod _method = LOCATION_METHOD_NONE; g_object_get(handle->object, "method", &_method, NULL); if (_method != LOCATION_METHOD_GPS) { LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); return LOCATIONS_ERROR_INCORRECT_METHOD; } } else if (handle->method != LOCATIONS_METHOD_GPS) { LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); return LOCATIONS_ERROR_INCORRECT_METHOD; } gchar *nmea_data = NULL; g_object_get(handle->object, "nmea", &nmea_data, NULL); if (nmea_data == NULL) { LOGE("[%s] LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : nmea data is NULL ", __FUNCTION__, LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } *nmea = NULL; *nmea = strdup(nmea_data); if (*nmea == NULL) { LOGE("[%s] LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to strdup ", __FUNCTION__, LOCATIONS_ERROR_OUT_OF_MEMORY); return LOCATIONS_ERROR_OUT_OF_MEMORY; } g_free(nmea_data); return LOCATIONS_ERROR_NONE; } int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp) { LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(num_of_active); LOCATIONS_NULL_ARG_CHECK(num_of_inview); LOCATIONS_NULL_ARG_CHECK(timestamp); location_manager_s *handle = (location_manager_s *) manager; LocationSatellite *sat = NULL; int ret = location_get_satellite (handle->object, &sat); if (ret != LOCATION_ERROR_NONE || sat == NULL) { if (ret == LOCATION_ERROR_NOT_SUPPORTED) { LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); return LOCATIONS_ERROR_INCORRECT_METHOD; } LOGE("[%s] LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", __FUNCTION__, LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } *num_of_active = sat->num_of_sat_used; *num_of_inview = sat->num_of_sat_inview; *timestamp = sat->timestamp; location_satellite_free(sat); sat = NULL; return LOCATIONS_ERROR_NONE; } int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data) { LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); LOCATIONS_NULL_ARG_CHECK(manager); location_manager_s *handle = (location_manager_s *) manager; g_object_set(handle->object, "sat-interval", interval, NULL); return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data); } int gps_status_unset_satellite_updated_cb(location_manager_h manager) { return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager); } int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data) { LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(callback); location_manager_s *handle = (location_manager_s *) manager; LocationSatellite *sat = NULL; int ret = location_get_satellite (handle->object, &sat); if (ret != LOCATION_ERROR_NONE || sat == NULL) { if (ret == LOCATION_ERROR_NOT_SUPPORTED) { LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); return LOCATIONS_ERROR_INCORRECT_METHOD; } LOGE("[%s] LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", __FUNCTION__, LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } int i; for (i = 0; i < sat->num_of_sat_inview; i++) { guint prn; gboolean used; guint elevation; guint azimuth; gint snr; location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr); if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE) break; } location_satellite_free(sat); sat = NULL; return LOCATIONS_ERROR_NONE; } int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp) { LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(num_of_active); LOCATIONS_NULL_ARG_CHECK(num_of_inview); LOCATIONS_NULL_ARG_CHECK(timestamp); location_manager_s *handle = (location_manager_s *) manager; int ret = LOCATION_ERROR_NONE; LocationSatellite *last_sat = NULL; ret = location_get_last_satellite(handle->object, &last_sat); if (ret != LOCATION_ERROR_NONE || last_sat == NULL) { if (ret == LOCATION_ERROR_NOT_SUPPORTED) { LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); return LOCATIONS_ERROR_INCORRECT_METHOD; } LOGE("[%s] LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", __FUNCTION__, LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } *num_of_active = last_sat->num_of_sat_used; *num_of_inview = last_sat->num_of_sat_inview; *timestamp = last_sat->timestamp; location_satellite_free(last_sat); return LOCATIONS_ERROR_NONE; } int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data) { LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(callback); location_manager_s *handle = (location_manager_s *) manager; int ret; LocationSatellite *last_sat = NULL; ret = location_get_last_satellite(handle->object, &last_sat); if (ret != LOCATION_ERROR_NONE || last_sat == NULL) { if (ret == LOCATION_ERROR_NOT_SUPPORTED) { LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); return LOCATIONS_ERROR_INCORRECT_METHOD; } LOGE("[%s] LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", __FUNCTION__, LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } int i; for (i = 0; i < last_sat->num_of_sat_inview; i++) { guint prn; gboolean used; guint elevation; guint azimuth; gint snr; location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr); if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE) { break; } } location_satellite_free(last_sat); return LOCATIONS_ERROR_NONE; }
tizenorg/framework.api.location-manager
TC/testcase/utc_location_location_manager_callback.c
/* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <tet_api.h> #include <locations.h> #include <glib.h> enum { POSITIVE_TC_IDX = 0x01, NEGATIVE_TC_IDX, }; static void startup(void); static void cleanup(void); void (*tet_startup) (void) = startup; void (*tet_cleanup) (void) = cleanup; static void utc_location_location_manager_start_p(void); static void utc_location_location_manager_start_n(void); static void utc_location_location_manager_start_n_02(void); static void utc_location_location_manager_set_position_updated_callback_p(void); static void utc_location_location_manager_set_position_updated_callback_n(void); static void utc_location_location_manager_set_position_updated_callback_n_02(void); static void utc_location_location_manager_set_position_updated_callback_n_03(void); static void utc_location_location_manager_set_position_updated_callback_n_04(void); static void utc_location_location_manager_set_position_updated_callback_n_05(void); static void utc_location_location_manager_unset_position_updated_callback_p(void); static void utc_location_location_manager_unset_position_updated_callback_n(void); static void utc_location_location_manager_set_velocity_updated_callback_p(void); static void utc_location_location_manager_set_velocity_updated_callback_n(void); static void utc_location_location_manager_set_velocity_updated_callback_n_02(void); static void utc_location_location_manager_set_velocity_updated_callback_n_03(void); static void utc_location_location_manager_unset_velocity_updated_callback_p(void); static void utc_location_location_manager_unset_velocity_updated_callback_n(void); static void utc_location_location_manager_set_service_state_changed_callback_p(void); static void utc_location_location_manager_set_service_state_changed_callback_n(void); static void utc_location_location_manager_set_service_state_changed_callback_n_02(void); static void utc_location_location_manager_set_service_state_changed_callback_n_03(void); static void utc_location_location_manager_unset_service_state_changed_callback_p(void); static void utc_location_location_manager_unset_service_state_changed_callback_n(void); static void utc_location_location_manager_set_zone_changed_callback_p(void); static void utc_location_location_manager_set_zone_changed_callback_n(void); static void utc_location_location_manager_set_zone_changed_callback_n_02(void); static void utc_location_location_manager_set_zone_changed_callback_n_03(void); static void utc_location_location_manager_unset_zone_changed_callback_p(void); static void utc_location_location_manager_unset_zone_changed_callback_n(void); static void utc_location_location_manager_stop_p(void); static void utc_location_location_manager_stop_n(void); static void utc_location_location_manager_stop_n_02(void); struct tet_testlist tet_testlist[] = { {utc_location_location_manager_start_p, POSITIVE_TC_IDX}, {utc_location_location_manager_start_n, NEGATIVE_TC_IDX}, // { utc_location_location_manager_start_n_02, NEGATIVE_TC_IDX }, //Can't check address of created location_manager_h {utc_location_location_manager_set_position_updated_callback_p, POSITIVE_TC_IDX}, {utc_location_location_manager_set_position_updated_callback_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_unset_position_updated_callback_p, POSITIVE_TC_IDX}, {utc_location_location_manager_unset_position_updated_callback_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_set_velocity_updated_callback_p, POSITIVE_TC_IDX}, {utc_location_location_manager_set_velocity_updated_callback_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_set_velocity_updated_callback_n_02, NEGATIVE_TC_IDX}, // { utc_location_location_manager_set_velocity_updated_callback_n_03, NEGATIVE_TC_IDX }, //Can't check address of created location_manager_h {utc_location_location_manager_unset_velocity_updated_callback_p, POSITIVE_TC_IDX}, {utc_location_location_manager_unset_velocity_updated_callback_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_set_service_state_changed_callback_p, POSITIVE_TC_IDX}, {utc_location_location_manager_set_service_state_changed_callback_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_set_service_state_changed_callback_n_02, NEGATIVE_TC_IDX}, // { utc_location_location_manager_set_service_state_changed_callback_n_03, NEGATIVE_TC_IDX }, // Can't check address of created location_manager_h {utc_location_location_manager_unset_service_state_changed_callback_p, POSITIVE_TC_IDX}, {utc_location_location_manager_unset_service_state_changed_callback_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_set_zone_changed_callback_p, POSITIVE_TC_IDX}, {utc_location_location_manager_set_zone_changed_callback_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_set_zone_changed_callback_n_02, NEGATIVE_TC_IDX}, // { utc_location_location_manager_set_zone_changed_callback_n_03, NEGATIVE_TC_IDX }, // Can't check address of created location_manager_h {utc_location_location_manager_unset_zone_changed_callback_p, POSITIVE_TC_IDX}, {utc_location_location_manager_unset_zone_changed_callback_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_stop_p, POSITIVE_TC_IDX}, {utc_location_location_manager_stop_n, NEGATIVE_TC_IDX}, // { utc_location_location_manager_stop_n_02, NEGATIVE_TC_IDX }, //Can't check address of created location_manager_h {NULL, 0}, }; static bool service_enabled = false; static void validate_and_next(char *api_name, int act_ret, int ext_ret, char *fail_msg) { dts_message(api_name, "Actual Result : %d, Expected Result : %d", act_ret, ext_ret); if (act_ret != ext_ret) { dts_message(api_name, "Fail Message: %s", fail_msg); dts_fail(api_name); } } static void validate_eq(char *api_name, int act_ret, int ext_ret) { dts_message(api_name, "Actual Result : %d, Expected Result : %d", act_ret, ext_ret); if (act_ret == ext_ret) { dts_pass(api_name); } else { dts_fail(api_name); } } static void validate_neq(char *api_name, int act_ret, int ext_ret) { dts_message(api_name, "Actual Result : %d, N-Expected Result : %d", act_ret, ext_ret); if (act_ret != ext_ret) { dts_pass(api_name); } else { dts_fail(api_name); } } static void unprepare(location_manager_h manager) { location_manager_unset_service_state_changed_cb(manager); location_manager_destroy(manager); service_enabled = false; } static void wait_for_service(char *api_name) { int timeout = 0; for (timeout; timeout < 30; timeout++) { if (service_enabled) { dts_message(api_name, "Location Service Enabled!!!!"); break; } else { dts_message(api_name, "Location Service Disabled!!!!"); sleep(1); } } } static void capi_state_changed_cb(location_service_state_e state, void *user_data) { switch (state) { case LOCATIONS_SERVICE_ENABLED: service_enabled = true; break; case LOCATIONS_SERVICE_DISABLED: service_enabled = false; break; default: break; } } static GMainLoop *g_mainloop = NULL; static GThread *event_thread; gpointer GmainThread(gpointer data) { g_mainloop = g_main_loop_new(NULL, 0); g_main_loop_run(g_mainloop); return NULL; } static location_manager_h manager; static void startup(void) { g_setenv("PKG_NAME", "com.samsung.capi-location-manager-callback-test", 1); g_setenv("LOCATION_TEST_ENABLE", "1", 1); #if !GLIB_CHECK_VERSION (2, 31, 0) if (!g_thread_supported()) { g_thread_init(NULL); } #endif GError *gerr = NULL; event_thread = g_thread_create(GmainThread, NULL, 1, &gerr); } static void cleanup(void) { unprepare(manager); g_main_loop_quit(g_mainloop); g_thread_join(event_thread); } static void capi_position_updated_cb(double latitude, double longitude, double altitude, time_t timestamp, void *user_data) { } static void capi_zone_changed_cb(location_boundary_state_e state, double latitude, double longitude, double altitude, time_t timestamp, void *user_data) { } static void capi_velocity_updated_cb(double speed, double direction, double climb, time_t timestamp, void *user_data) { } static bool capi_geocoder_get_position_cb(double latitude, double longitude, void *user_data) { return true; } static void utc_location_location_manager_start_p(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_create(LOCATIONS_METHOD_HYBRID, &manager); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_create() is failed"); ret = location_manager_set_service_state_changed_cb(manager, capi_state_changed_cb, NULL); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_set_service_state_changed_cb() is failed"); ret = location_manager_start(manager); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_start() is failed"); wait_for_service(__func__); validate_eq(__func__, service_enabled, true); } static void utc_location_location_manager_start_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_start(NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_start_n_02(void) { int ret = LOCATIONS_ERROR_NONE; location_manager_h manager_02; ret = location_manager_start(manager_02); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_set_position_updated_callback_p(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_set_position_updated_cb(manager, capi_position_updated_cb, 1, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_position_updated_callback_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_set_position_updated_cb(manager, NULL, 1, NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_position_updated_callback_n_02(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_set_position_updated_cb(NULL, capi_position_updated_cb, 1, NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_position_updated_callback_n_03(void) { int ret = LOCATIONS_ERROR_NONE; location_manager_h manager_02; ret = location_manager_set_position_updated_cb(manager_02, capi_position_updated_cb, 1, NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_position_updated_callback_n_04(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_set_position_updated_cb(manager, capi_position_updated_cb, 0, NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_position_updated_callback_n_05(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_set_position_updated_cb(manager, capi_position_updated_cb, 121, NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_unset_position_updated_callback_p(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_unset_position_updated_cb(manager); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_unset_position_updated_callback_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_unset_position_updated_cb(NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_velocity_updated_callback_p(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_set_velocity_updated_cb(manager, capi_velocity_updated_cb, 1, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_velocity_updated_callback_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_set_velocity_updated_cb(manager, NULL, 1, NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_velocity_updated_callback_n_02(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_set_velocity_updated_cb(NULL, capi_velocity_updated_cb, 1, NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_velocity_updated_callback_n_03(void) { int ret = LOCATIONS_ERROR_NONE; location_manager_h manager_02; ret = location_manager_set_velocity_updated_cb(manager_02, capi_velocity_updated_cb, 1, NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_unset_velocity_updated_callback_p(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_unset_velocity_updated_cb(manager); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_unset_velocity_updated_callback_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_unset_velocity_updated_cb(NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_service_state_changed_callback_p(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_set_service_state_changed_cb(manager, capi_state_changed_cb, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_service_state_changed_callback_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_set_service_state_changed_cb(manager, NULL, NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_service_state_changed_callback_n_02(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_set_service_state_changed_cb(NULL, capi_state_changed_cb, NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_service_state_changed_callback_n_03(void) { int ret = LOCATIONS_ERROR_NONE; location_manager_h manager_02; ret = location_manager_set_service_state_changed_cb(manager_02, capi_state_changed_cb, NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_unset_service_state_changed_callback_p(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_unset_service_state_changed_cb(manager); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_unset_service_state_changed_callback_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_unset_service_state_changed_cb(NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_zone_changed_callback_p(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_set_zone_changed_cb(manager, capi_zone_changed_cb, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_zone_changed_callback_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_set_zone_changed_cb(manager, NULL, NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_zone_changed_callback_n_02(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_set_zone_changed_cb(NULL, capi_zone_changed_cb, NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_set_zone_changed_callback_n_03(void) { int ret = LOCATIONS_ERROR_NONE; location_manager_h manager_02; ret = location_manager_set_zone_changed_cb(manager_02, capi_zone_changed_cb, NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_unset_zone_changed_callback_p(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_unset_zone_changed_cb(manager); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_unset_zone_changed_callback_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_unset_zone_changed_cb(NULL); validate_neq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_stop_p(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_stop(manager); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_stop_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_stop(NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_stop_n_02(void) { int ret = LOCATIONS_ERROR_NONE; location_manager_h manager_02; ret = location_manager_stop(manager_02); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); }
tizenorg/framework.api.location-manager
src/location_bounds.c
/* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <locations_private.h> #include <dlog.h> #ifdef LOG_TAG #undef LOG_TAG #endif #define LOG_TAG "TIZEN_N_LOCATION_MANAGER" /* * Internal Macros */ #define LOCATIONS_CHECK_CONDITION(condition,error,msg) \ if(condition) {} else \ { LOGE("[%s] %s(0x%08x)",__FUNCTION__, msg,error); return error;}; \ #define LOCATIONS_NULL_ARG_CHECK(arg) \ LOCATIONS_CHECK_CONDITION(arg != NULL,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER,"LOCATION_BOUNDS_ERROR_INVALID_PARAMETER") \ static void __free_position_list(gpointer data) { if (data == NULL) return; LocationPosition *position = (LocationPosition*) data; location_position_free(position); } static location_bounds_type_e __convert_bounds_type(LocationBoundaryType type) { location_bounds_type_e ret; switch(type) { case LOCATION_BOUNDARY_CIRCLE: ret = LOCATION_BOUNDS_CIRCLE; break; case LOCATION_BOUNDARY_POLYGON: ret = LOCATION_BOUNDS_POLYGON; break; case LOCATION_BOUNDARY_NONE: case LOCATION_BOUNDARY_RECT: default: ret = LOCATION_BOUNDS_RECT; break; } return ret; } int location_bounds_create_rect(location_coords_s top_left, location_coords_s bottom_right, location_bounds_h* bounds) { LOCATIONS_NULL_ARG_CHECK(bounds); LOCATIONS_CHECK_CONDITION(top_left.latitude>=-90 && top_left.latitude<=90,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER,"LOCATION_BOUNDS_ERROR_INVALID_PARAMETER"); LOCATIONS_CHECK_CONDITION(top_left.longitude>=-180 && top_left.longitude<=180,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER, "LOCATION_BOUNDS_ERROR_INVALID_PARAMETER"); LOCATIONS_CHECK_CONDITION(bottom_right.latitude>=-90 && bottom_right.latitude<=90,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER, "LOCATION_BOUNDS_ERROR_INVALID_PARAMETER"); LOCATIONS_CHECK_CONDITION(bottom_right.longitude>=-180 && bottom_right.longitude<=180,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER, "LOCATION_BOUNDS_ERROR_INVALID_PARAMETER"); LocationPosition *lt = location_position_new(0, top_left.latitude, top_left.longitude, 0, LOCATION_STATUS_2D_FIX); if (lt ==NULL) { LOGE("[%s] LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", __FUNCTION__, LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY); return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY; } LocationPosition *rb = location_position_new(0, bottom_right.latitude, bottom_right.longitude, 0, LOCATION_STATUS_2D_FIX); if (rb ==NULL) { LOGE("[%s] LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", __FUNCTION__, LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY); location_position_free (lt); return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY; } LocationBoundary *boundary = location_boundary_new_for_rect(lt, rb); location_position_free (rb); location_position_free (lt); if(!boundary) { LOGE("[%s] LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_boundary_new_for_rect", __FUNCTION__, LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY); return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY; } *bounds = (location_bounds_h)boundary; return LOCATION_BOUNDS_ERROR_NONE; } int location_bounds_create_circle(location_coords_s center, double radius, location_bounds_h* bounds) { LOCATIONS_NULL_ARG_CHECK(bounds); LOCATIONS_CHECK_CONDITION(radius>=0,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER,"LOCATION_BOUNDS_ERROR_INVALID_PARAMETER"); LOCATIONS_CHECK_CONDITION(center.latitude>=-90 && center.latitude<=90,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER,"LOCATION_BOUNDS_ERROR_INVALID_PARAMETER"); LOCATIONS_CHECK_CONDITION(center.longitude>=-180 && center.longitude<=180,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER, "LOCATION_BOUNDS_ERROR_INVALID_PARAMETER"); LocationPosition *ct = location_position_new(0, center.latitude, center.longitude, 0, LOCATION_STATUS_2D_FIX); if (ct ==NULL) { LOGE("[%s] LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", __FUNCTION__, LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY); return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY; } LocationBoundary *boundary = location_boundary_new_for_circle(ct,radius); location_position_free (ct); if(!boundary) { LOGE("[%s] LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_boundary_new_for_circle", __FUNCTION__, LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY); return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY; } *bounds = (location_bounds_h)boundary; return LOCATION_BOUNDS_ERROR_NONE; } int location_bounds_create_polygon(location_coords_s* coords_list, int length, location_bounds_h* bounds) { LOCATIONS_NULL_ARG_CHECK(coords_list); LOCATIONS_NULL_ARG_CHECK(bounds); LOCATIONS_CHECK_CONDITION(length>=3,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER,"LOCATION_BOUNDS_ERROR_INVALID_PARAMETER"); int i; GList* position_list = NULL; LocationPosition *position = NULL; bool isValid; for(i=0;i<length;i++) { if(coords_list[i].latitude < -90 || coords_list[i].latitude > 90 || coords_list[i].longitude < -180 || coords_list[i].longitude > 180) { LOGE("[%s] LOCATION_BOUNDS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, LOCATION_BOUNDS_ERROR_INVALID_PARAMETER); isValid = FALSE; break; } position = location_position_new(0, coords_list[i].latitude, coords_list[i].longitude, 0.0, LOCATION_STATUS_2D_FIX); position_list = g_list_append(position_list,position); location_position_free(position); isValid = TRUE; } if(!isValid) { g_list_free_full(position_list, (GDestroyNotify)__free_position_list); return LOCATION_BOUNDS_ERROR_INVALID_PARAMETER; } if (position_list ==NULL) { LOGE("[%s] LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", __FUNCTION__, LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY); return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY; } LocationBoundary *boundary = location_boundary_new_for_polygon(position_list); if(!boundary) { LOGE("[%s] LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_boundary_new_for_rect", __FUNCTION__, LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY); return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY; } *bounds = (location_bounds_h)boundary; return LOCATION_BOUNDS_ERROR_NONE; } bool location_bounds_contains_coordinates(location_bounds_h bounds, location_coords_s coords) { if (!bounds) return FALSE; if (coords.latitude < -90 || coords.latitude > 90 || coords.longitude < -180 || coords.longitude > 180) return FALSE; LocationPosition *pos = location_position_new(0, coords.latitude, coords.longitude, 0, LOCATION_STATUS_2D_FIX); if (!pos) return FALSE; gboolean is_inside = location_boundary_if_inside((LocationBoundary*)bounds, pos); location_position_free (pos); bool result = is_inside?TRUE:FALSE; return result; } int location_bounds_get_type(location_bounds_h bounds, location_bounds_type_e *type) { LOCATIONS_NULL_ARG_CHECK(bounds); LOCATIONS_NULL_ARG_CHECK(type); *type = __convert_bounds_type(((LocationBoundary*)bounds)->type); return LOCATION_BOUNDS_ERROR_NONE; } int location_bounds_get_rect_coords(location_bounds_h bounds, location_coords_s *top_left, location_coords_s *bottom_right) { LOCATIONS_NULL_ARG_CHECK(bounds); LOCATIONS_NULL_ARG_CHECK(top_left); LOCATIONS_NULL_ARG_CHECK(bottom_right); if( __convert_bounds_type(((LocationBoundary*)bounds)->type) != LOCATION_BOUNDS_RECT) { LOGE("[%s] LOCATION_BOUNDS_ERROR_INCORRECT_TYPE(0x%08x)", __FUNCTION__, LOCATION_BOUNDS_ERROR_INCORRECT_TYPE); } top_left->latitude = ((LocationBoundary*)bounds)->rect.left_top->latitude; top_left->longitude = ((LocationBoundary*)bounds)->rect.left_top->longitude; bottom_right->latitude =((LocationBoundary*)bounds)->rect.right_bottom->latitude; bottom_right->longitude = ((LocationBoundary*)bounds)->rect.right_bottom->longitude; return LOCATION_BOUNDS_ERROR_NONE; } int location_bounds_get_circle_coords(location_bounds_h bounds, location_coords_s *center, double *radius) { LOCATIONS_NULL_ARG_CHECK(bounds); LOCATIONS_NULL_ARG_CHECK(center); LOCATIONS_NULL_ARG_CHECK(radius); if( __convert_bounds_type(((LocationBoundary*)bounds)->type) != LOCATION_BOUNDS_CIRCLE) { LOGE("[%s] LOCATION_BOUNDS_ERROR_INCORRECT_TYPE(0x%08x)", __FUNCTION__, LOCATION_BOUNDS_ERROR_INCORRECT_TYPE); } center->latitude = ((LocationBoundary*)bounds)->circle.center->latitude; center->longitude =((LocationBoundary*)bounds)->circle.center->longitude; *radius = ((LocationBoundary*)bounds)->circle.radius; return LOCATION_BOUNDS_ERROR_NONE; } int location_bounds_foreach_polygon_coords(location_bounds_h bounds, polygon_coords_cb callback, void *user_data) { LOCATIONS_NULL_ARG_CHECK(bounds); LOCATIONS_NULL_ARG_CHECK(callback); if( __convert_bounds_type(((LocationBoundary*)bounds)->type) != LOCATION_BOUNDS_POLYGON) { LOGE("[%s] LOCATION_BOUNDS_ERROR_INCORRECT_TYPE(0x%08x)", __FUNCTION__, LOCATION_BOUNDS_ERROR_INCORRECT_TYPE); } GList *list = ((LocationBoundary*)bounds)->polygon.position_list; while(list) { LocationPosition *pos = list->data; location_coords_s coords; coords.latitude = pos->latitude; coords.longitude = pos->longitude; if ( callback(coords, user_data) != TRUE ) { LOGI("[%s] User quit the loop ", __FUNCTION__); break; } list = g_list_next(list); } return LOCATION_BOUNDS_ERROR_NONE; } int location_bounds_destroy(location_bounds_h bounds) { LOCATIONS_NULL_ARG_CHECK(bounds); location_boundary_free((LocationBoundary*)bounds); return LOCATION_BOUNDS_ERROR_NONE; }
tizenorg/framework.api.location-manager
TC/testcase/utc_location_preference.c
/* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <tet_api.h> #include <location_preference.h> #include <geocoder.h> enum { POSITIVE_TC_IDX = 0x01, NEGATIVE_TC_IDX, }; static void startup(void); static void cleanup(void); void (*tet_startup) (void) = startup; void (*tet_cleanup) (void) = cleanup; static void utc_location_location_preference_foreach_available_property_keys_p(void); static void utc_location_location_preference_foreach_available_property_keys_n(void); static void utc_location_location_preference_foreach_available_property_values_p(void); static void utc_location_location_preference_foreach_available_property_values_n(void); static void utc_location_location_preference_foreach_available_languages_p(void); static void utc_location_location_preference_foreach_available_languages_n(void); static void utc_location_location_preference_foreach_properties_p(void); static void utc_location_location_preference_foreach_properties_n(void); static void utc_location_location_preference_set_p(void); static void utc_location_location_preference_set_n(void); static void utc_location_location_preference_get_p(void); static void utc_location_location_preference_get_n(void); static void utc_location_location_preference_get_provider_name_p(void); static void utc_location_location_preference_get_provider_name_n(void); static void utc_location_location_preference_get_distance_unit_p(void); static void utc_location_location_preference_get_distance_unit_n(void); static void utc_location_location_preference_set_distance_unit_p(void); static void utc_location_location_preference_set_distance_unit_n(void); static void utc_location_location_preference_get_language_p(void); static void utc_location_location_preference_get_language_n(void); static void utc_location_location_preference_set_language_p(void); static void utc_location_location_preference_set_language_n(void); struct tet_testlist tet_testlist[] = { // { utc_location_location_preference_foreach_available_property_keys_p, POSITIVE_TC_IDX }, {utc_location_location_preference_foreach_available_property_keys_n, NEGATIVE_TC_IDX}, // { utc_location_location_preference_foreach_available_property_values_p, POSITIVE_TC_IDX }, {utc_location_location_preference_foreach_available_property_values_n, NEGATIVE_TC_IDX}, {utc_location_location_preference_foreach_available_languages_p, POSITIVE_TC_IDX}, {utc_location_location_preference_foreach_available_languages_n, NEGATIVE_TC_IDX}, {utc_location_location_preference_set_p, POSITIVE_TC_IDX}, {utc_location_location_preference_set_n, NEGATIVE_TC_IDX}, {utc_location_location_preference_foreach_properties_p, POSITIVE_TC_IDX}, {utc_location_location_preference_foreach_properties_n, NEGATIVE_TC_IDX}, {utc_location_location_preference_get_p, POSITIVE_TC_IDX}, {utc_location_location_preference_get_n, NEGATIVE_TC_IDX}, {utc_location_location_preference_get_provider_name_p, POSITIVE_TC_IDX}, {utc_location_location_preference_get_provider_name_n, NEGATIVE_TC_IDX}, {utc_location_location_preference_set_distance_unit_p, POSITIVE_TC_IDX}, {utc_location_location_preference_set_distance_unit_n, NEGATIVE_TC_IDX}, {utc_location_location_preference_get_distance_unit_p, POSITIVE_TC_IDX}, {utc_location_location_preference_get_distance_unit_n, NEGATIVE_TC_IDX}, {utc_location_location_preference_set_language_p, POSITIVE_TC_IDX}, {utc_location_location_preference_set_language_n, NEGATIVE_TC_IDX}, {utc_location_location_preference_get_language_p, POSITIVE_TC_IDX}, {utc_location_location_preference_get_language_n, NEGATIVE_TC_IDX}, {NULL, 0}, }; static geocoder_h geocoder; static char *available_language; static char *available_key; static char *available_value; static void startup(void) { g_setenv("PKG_NAME", "com.samsung.capi-location-preference", 1); g_setenv("LOCATION_TEST_ENABLE", "1", 1); tet_printf("TC start"); int ret = geocoder_create(&geocoder); available_language = NULL; available_key = NULL; available_value = NULL; if (ret != GEOCODER_ERROR_NONE) { tet_printf("Creating the handle of geocoder failed"); return; } else { tet_printf("Creating the handle of geocoder succeeded"); } } static void cleanup(void) { geocoder_destroy(geocoder); } bool location_preference_available_property_key_cb_impl(const char *key, void *user_data) { tet_printf("key : %s", key); available_key = strdup(key); return false; } bool location_preference_available_property_value_cb_impl(const char *value, void *user_data) { tet_printf("value : %s", value); available_value = strdup(value); return false; } bool location_preference_available_language_cb_impl(const char *language, void *user_data) { available_language = strdup(language); tet_printf("available language : %s", available_language); return false; } bool location_preference_property_cb_impl(const char *key, const char *value, void *user_data) { tet_printf("key : %s", key); tet_printf("value : %s", value); return false; } static void utc_location_location_preference_foreach_available_property_keys_p(void) { int ret = location_preference_foreach_available_property_keys(GET_LOCATION_SERVICE(geocoder), location_preference_available_property_key_cb_impl, NULL); if (ret == LOCATION_PREFERENCE_ERROR_NONE) { dts_pass(__func__, "location_preference_foreach_available_property_keys passed"); } else { dts_fail(__func__, "location_preference_foreach_available_property_keys failed"); } } static void utc_location_location_preference_foreach_available_property_keys_n(void) { int ret = location_preference_foreach_available_property_keys(GET_LOCATION_SERVICE(geocoder), NULL, NULL); dts_check_eq(__func__, ret, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER was not returned."); } static void utc_location_location_preference_foreach_available_property_values_p(void) { int ret = location_preference_foreach_available_property_values(GET_LOCATION_SERVICE(geocoder), available_key, location_preference_available_property_value_cb_impl, NULL); if (ret == LOCATION_PREFERENCE_ERROR_NONE) { dts_pass(__func__, "location_preference_foreach_available_property_values passed"); } else { dts_fail(__func__, "location_preference_foreach_available_property_values failed"); } } static void utc_location_location_preference_foreach_available_property_values_n(void) { int ret = location_preference_foreach_available_property_values(GET_LOCATION_SERVICE(geocoder), NULL, NULL, NULL); dts_check_eq(__func__, ret, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER was not returned."); } static void utc_location_location_preference_foreach_available_languages_p(void) { int ret = location_preference_foreach_available_languages(GET_LOCATION_SERVICE(geocoder), location_preference_available_language_cb_impl, NULL); if (ret == LOCATION_PREFERENCE_ERROR_NONE) { dts_pass(__func__, "location_preference_foreach_available_languages passed"); } else { dts_fail(__func__, "location_preference_foreach_available_languages failed"); } } static void utc_location_location_preference_foreach_available_languages_n(void) { int ret = location_preference_foreach_available_languages(GET_LOCATION_SERVICE(geocoder), NULL, NULL); dts_check_eq(__func__, ret, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER was not returned."); } static void utc_location_location_preference_foreach_properties_p(void) { int ret = location_preference_foreach_properties(GET_LOCATION_SERVICE(geocoder), location_preference_property_cb_impl, NULL); dts_check_eq(__func__, ret, LOCATION_PREFERENCE_ERROR_NONE, "location_preference_foreach_properties failed."); } static void utc_location_location_preference_foreach_properties_n(void) { int ret = location_preference_foreach_properties(GET_LOCATION_SERVICE(geocoder), NULL, NULL); dts_check_eq(__func__, ret, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER was not returned."); } static void utc_location_location_preference_set_p(void) { if (available_key == NULL) { available_key = strdup("test_key"); available_value = strdup("test_value"); } int ret = location_preference_set(GET_LOCATION_SERVICE(geocoder), available_key, available_value); dts_check_eq(__func__, ret, LOCATION_PREFERENCE_ERROR_NONE, "location_preference_set failed."); } static void utc_location_location_preference_set_n(void) { int ret = location_preference_set(GET_LOCATION_SERVICE(geocoder), NULL, NULL); dts_check_eq(__func__, ret, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER was not returned."); } static void utc_location_location_preference_get_p(void) { int ret = 0; char *value = NULL; ret = location_preference_get(GET_LOCATION_SERVICE(geocoder), available_key, &value); if (value != NULL) { tet_printf("value: %s", value); } dts_check_eq(__func__, ret, LOCATION_PREFERENCE_ERROR_NONE, "location_preference_get failed."); } static void utc_location_location_preference_get_n(void) { int ret = location_preference_get(GET_LOCATION_SERVICE(geocoder), NULL, NULL); dts_check_eq(__func__, ret, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER was not returned."); } static void utc_location_location_preference_get_provider_name_p(void) { int ret = 0; char *name = NULL; ret = location_preference_get_provider_name(GET_LOCATION_SERVICE(geocoder), &name); if (ret == LOCATION_PREFERENCE_ERROR_NONE) { if (name != NULL) { tet_printf("provider name: %s", name); } dts_pass(__func__, "location_preference_get_provider_name passed"); } else dts_fail(__func__, "location_preference_get_provider_name failed"); } static void utc_location_location_preference_get_provider_name_n(void) { int ret = location_preference_get_provider_name(GET_LOCATION_SERVICE(geocoder), NULL); dts_check_eq(__func__, ret, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER was not returned."); } static void utc_location_location_preference_set_distance_unit_p(void) { int ret = location_preference_set_distance_unit(GET_LOCATION_SERVICE(geocoder), LOCATION_PREFERENCE_DISTANCE_UNIT_FT); dts_check_eq(__func__, ret, LOCATION_PREFERENCE_ERROR_NONE, "location_preference_set_distance_unit failed."); } static void utc_location_location_preference_set_distance_unit_n(void) { int ret = location_preference_set_distance_unit(GET_LOCATION_SERVICE(geocoder), -1); dts_check_eq(__func__, ret, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER was not returned."); } static void utc_location_location_preference_get_distance_unit_p(void) { int ret = 0; location_preference_distance_unit_e unit = LOCATION_PREFERENCE_DISTANCE_UNIT_FT; ret = location_preference_get_distance_unit(GET_LOCATION_SERVICE(geocoder), &unit); if (ret == LOCATION_PREFERENCE_ERROR_NONE) { dts_pass(__func__, "location_preference_get_distance_unit passed"); } else { dts_fail(__func__, "location_preference_get_distance_unit failed"); } } static void utc_location_location_preference_get_distance_unit_n(void) { int ret = location_preference_get_distance_unit(GET_LOCATION_SERVICE(geocoder), NULL); dts_check_eq(__func__, ret, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER was not returned."); } static void utc_location_location_preference_set_language_p(void) { if (available_language == NULL) { available_language = strdup("KR"); } int ret = location_preference_set_language(GET_LOCATION_SERVICE(geocoder), available_language); dts_check_eq(__func__, ret, LOCATION_PREFERENCE_ERROR_NONE, "location_preference_set_language_unit failed."); } static void utc_location_location_preference_set_language_n(void) { int ret = location_preference_set_language(GET_LOCATION_SERVICE(geocoder), NULL); dts_check_eq(__func__, ret, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER was not returned."); } static void utc_location_location_preference_get_language_p(void) { int ret = 0; char *language = NULL; ret = location_preference_get_language(GET_LOCATION_SERVICE(geocoder), &language); if (ret == LOCATION_PREFERENCE_ERROR_NONE) { dts_pass(__func__, "location_preference_get_distance_unit passed"); } else { dts_fail(__func__, "location_preference_get_distance_unit failed"); } } static void utc_location_location_preference_get_language_n(void) { int ret = location_preference_get_language(GET_LOCATION_SERVICE(geocoder), NULL); dts_check_eq(__func__, ret, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER was not returned."); }
tizenorg/framework.api.location-manager
include/locations.h
/* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __TIZEN_LOCATION_LOCATIONS_H__ #define __TIZEN_LOCATION_LOCATIONS_H__ #include <tizen_type.h> #include <tizen_error.h> #include <location_bounds.h> #ifdef __cplusplus extern "C" { #endif /** * @addtogroup CAPI_LOCATION_MANAGER_MODULE * @{ */ /** * @brief Enumerations of error code for Location manager. */ typedef enum { LOCATIONS_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ LOCATIONS_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ LOCATIONS_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ LOCATIONS_ERROR_INCORRECT_METHOD = TIZEN_ERROR_LOCATION_CLASS | 0x01, /**< Location manager contains incorrect method for a given call */ LOCATIONS_ERROR_NETWORK_FAILED = TIZEN_ERROR_LOCATION_CLASS | 0x02, /**< Network unavailable */ LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE = TIZEN_ERROR_LOCATION_CLASS | 0x03, /**< Service unavailable */ LOCATIONS_ERROR_GPS_SETTING_OFF = TIZEN_ERROR_LOCATION_CLASS | 0x04, /**< GPS is not enabled */ } location_error_e; /** * @brief Location method type. */ typedef enum { LOCATIONS_METHOD_NONE=-1, /**< Undefined method. */ LOCATIONS_METHOD_HYBRID, /**< This method selects the best method available at the moment. */ LOCATIONS_METHOD_GPS, /**< This method uses Global Positioning System. */ LOCATIONS_METHOD_WPS, /**< This method uses Wifi Positioning System. */ LOCATIONS_METHOD_CPS /**< This method uses Cellular Positioning System. */ } location_method_e; /** * @brief Approximate accuracy level of given information. */ typedef enum { LOCATIONS_ACCURACY_NONE=0, /**< Invalid data. */ LOCATIONS_ACCURACY_COUNTRY, /**< Country accuracy level. */ LOCATIONS_ACCURACY_REGION, /**< Regional accuracy level. */ LOCATIONS_ACCURACY_LOCALITY, /**< Local accuracy level. */ LOCATIONS_ACCURACY_POSTALCODE, /**< Postal accuracy level. */ LOCATIONS_ACCURACY_STREET, /**< Street accuracy level. */ LOCATIONS_ACCURACY_DETAILED, /**< Detailed accuracy level. */ } location_accuracy_level_e; /** * @brief Enumerations of the state of the location service. */ typedef enum { LOCATIONS_SERVICE_DISABLED, /**< Service is disabled */ LOCATIONS_SERVICE_ENABLED /**< Service is enabled */ } location_service_state_e; /** * @brief Enumerations of the boundary state. */ typedef enum { LOCATIONS_BOUNDARY_IN, /**< Boundary In (Zone In) */ LOCATIONS_BOUNDARY_OUT /**< Boundary Out (Zone Out) */ } location_boundary_state_e; /** * @brief The location manager handle. */ typedef struct location_manager_s *location_manager_h; /** * @} */ /* * Location Manager */ /** * @addtogroup CAPI_LOCATION_MANAGER_MODULE * @{ */ /** * @brief Called at defined interval with updated position information. * @param[in] latitude The updated latitude [-90.0 ~ 90.0] (degrees) * @param[in] longitude The updated longitude [-180.0 ~ 180.0] (degrees) * @param[in] altitude The updated altitude (meters) * @param[in] timestamp The timestamp (time when measurement took place or 0 if invalid) * @param[in] user_data The user data passed from the call registration function * @pre location_manager_start() will invoke this callback if you register this callback using location_manager_set_position_updated_cb() * @see location_manager_start() * @see location_manager_set_position_updated_cb() */ typedef void(*location_position_updated_cb)(double latitude, double longitude, double altitude, time_t timestamp, void *user_data); /** * @brief Called at defined interval with updated velocity information. * @param[in] speed The updated speed (km/h) * @param[in] direction The updated direction (in degrees from the north) * @param[in] climb The updated climb (km/h) * @param[in] timestamp The timestamp (time when measurement took place or 0 if invalid) * @param[in] user_data The user data passed from the callback registration function * @pre location_manager_start() will invoke this callback if you register this callback using location_manager_set_velocity_updated_cb() * @see location_manager_start() * @see location_manager_set_velocity_updated_cb() */ typedef void(*location_velocity_updated_cb)(double speed, double direction, double climb, time_t timestamp, void *user_data); /** * @brief Called when the state of location service is changed from enabled to disabled or vice versa. * @param[in] state The service state * @param[in] user_data The user data passed from the callback registration function * @pre Either location_manager_start() or location_manager_stop() will invoke this callback if you register this callback using location_manager_set_service_state_changed_cb() * @see location_manager_start() * @see location_manager_stop() * @see location_manager_set_service_state_changed_cb() * @see #location_service_state_e */ typedef void(*location_service_state_changed_cb)(location_service_state_e state, void *user_data); /** * @brief Called when the user defined zones are entered or exited. * @param[in] state The boundary state * @param[in] latitude The updated latitude [-90.0 ~ 90.0] (degrees) * @param[in] longitude The updated longitude [-180.0 ~ 180.0] (degrees) * @param[in] altitude The updated altitude (meters) * @param[in] timestamp The timestamp (time when measurement took place or 0 if invalid) * @param[in] user_data The user data passed from the callback registration function * @pre location_manager_start() will invoke this callback if you register this callback using location_manager_set_zone_changed_cb() * @see #location_boundary_state_e * @see location_manager_start() * @see location_manager_set_zone_changed_cb() */ typedef void(*location_zone_changed_cb)(location_boundary_state_e state, double latitude, double longitude, double altitude, time_t timestamp, void *user_data); /** * @brief Gets called iteratively to notify you of location bounds. * @param[in] bounds The location bounds handle * @param[in] user_data The user data passed from the callback registration function * @pre location_manager_foreach_boundary() will invoke this callback. * @see location_manager_foreach_boundary() */ typedef bool(*location_bounds_cb)(location_bounds_h bounds, void *user_data); /** * @brief Checks whether the given location method is avaliable or not. * @param[in] method The location method to be checked * @return @c true if the specified location method is supported, \n else @c false * @see location_manager_create() * @see location_manager_get_method() */ bool location_manager_is_supported_method(location_method_e method); /** * @brief Creates a new location manager. * @remarks @a manager must be released location_manager_destroy() by you. * @param[in] method The location method * @param[out] manager A location manager handle to be newly created on success * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_OUT_OF_MEMORY Out of memory * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available * @see location_manager_destroy() */ int location_manager_create(location_method_e method, location_manager_h* manager); /** * @brief Releases the location manager. * @param[in] manager The location manager handle * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @see location_manager_create() */ int location_manager_destroy(location_manager_h manager); /** * @brief Starts the location service. * * @remarks There is no limit on number of location managers for which this function was called. * * Calling this function invokes a location service event. When the location service is enabled, the service state change callback * (set using #location_manager_set_service_state_changed_cb()) notifies the user with #LOCATIONS_SERVICE_ENABLED as * the first argument, and the service starts. \n * Started service is a requirement for calling these functions: * * location_manager_get_position(), location_manager_get_velocity(), location_manager_get_accuracy(), * gps_status_get_nmea(), gps_status_get_satellite_count_in_view(), gps_status_foreach_satellites_in_view(), gps_status_get_active_satellite_count(). * * Once you stop the service, using #location_manager_stop(), you can no longer call the functions listed above. * * Starting and stopping the service is in the scope of the given location manager only (if there's more than one manager, * starting and stopping should be executed for each of them separately). * * @param[in] manager The location manager handle * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available * @retval #LOCATIONS_ERROR_NETWORK_FAILED Network failed * @retval #LOCATIONS_ERROR_GPS_SETTING_OFF GPS is not enabled * @post It invokes location_position_updated_cb(), location_velocity_updated_cb(), location_zone_changed_cb(), and location_service_state_changed_cb(). * @see location_manager_stop() * @see location_manager_get_position() * @see location_manager_get_velocity() * @see location_manager_get_accuracy() * @see location_manager_set_service_state_changed_cb() * @see location_manager_set_position_updated_cb() * @see location_position_updated_cb() * @see location_manager_set_velocity_updated_cb() * @see location_velocity_updated_cb() * @see location_manager_set_zone_changed_cb() * @see location_zone_changed_cb() */ int location_manager_start(location_manager_h manager); /** * @brief Stops the location service. * @remarks This function initiates the process of stopping the service. When the process is finished, callback set using * #location_manager_set_service_state_changed_cb() will be called, with #LOCATIONS_SERVICE_DISABLED as first argument. * When that happens, the service is stopped and the user is notified. * * You can stop and start the location manager as needed. * * @param[in] manager The location manager handle * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available * @retval #LOCATIONS_ERROR_NETWORK_FAILED Network failed * @see location_manager_start() * @see location_manager_set_service_state_changed_cb() * @see location_service_state_changed_cb() */ int location_manager_stop(location_manager_h manager); /** * @brief Adds a bounds for a given location manager. * @param[in] manager The location manager handle * @param[in] bounds The location bounds handle * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @retval #LOCATIONS_ERROR_OUT_OF_MEMORY Out of memory * @post It invokes location_manager_set_zone_changed_cb() when a boundary is entered or exited, if you set a callback with location_manager_set_zone_changed_cb(). * @see location_manager_remove_boundary() * @see location_manager_set_zone_changed_cb() * @see location_manager_is_boundary_contains_coordinate() */ int location_manager_add_boundary(location_manager_h manager, const location_bounds_h bounds); /** * @brief Deletes a bounds for a given location manager. * @param[in] manager The location manager handle * @param[in] bounds The location bounds handle * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @retval #LOCATIONS_ERROR_OUT_OF_MEMORY Out of memory * @see location_manager_add_boundary() */ int location_manager_remove_boundary(location_manager_h manager, const location_bounds_h bounds); /** * @brief Retrieves all location bounds by invoking a specific callback for each locatoin bounds * @param[in] manager The location manager handle * @param[in] callback The iteration callback * @param[in] user_data The user data to be passed to the callback function * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @post location_bounds_cb() will be invoked * @see location_manager_add_boundary() * @see location_manager_remove_boundary() * @see location_bounds_cb() */ int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data); /** * @brief Gets the given location manager's method. * * @param[in] manager The location manager handle * @param[out] method The location method * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @see location_manager_create() */ int location_manager_get_method(location_manager_h manager, location_method_e *method); /** * @brief Gets the current position information. * @details * The result is current altitude, latitude, and longitude, with a measurement timestamp. * * If @a altitude is negative, only altitude and latitude are available (fix status is 2D). * If @a altitude is positive, fix status is 3D and returned altitude value is the result of measurement. * * @param[in] manager The location manager handle * @param[out] altitude The current altitude (meters) * @param[out] latitude The current latitude [-90.0 ~ 90.0] (degrees) * @param[out] longitude The current longitude [-180.0 ~ 180.0] (degrees) * @param[out] timestamp The timestamp (time when measurement took place or 0 if valid) * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available * @retval #LOCATIONS_ERROR_GPS_SETTING_OFF GPS is not enabled * @pre The location service state must be #LOCATIONS_SERVICE_ENABLED with location_manager_start() */ int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp); /** * @brief Gets the current velocity information. * @details * The result is current climb, direction, and speed, with a measurement timestamp. * * @param[in] manager The location manager handle * @param[out] climb The climb (km/h) * @param[out] direction The direction, degrees from the north * @param[out] speed The speed (km/h) * @param[out] timestamp The timestamp (time when measurement took place or 0 if invalid) * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available * @retval #LOCATIONS_ERROR_GPS_SETTING_OFF GPS is not enabled * @pre The location service state must be #LOCATIONS_SERVICE_ENABLED with location_manager_start() */ int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp); /** * @brief Gets the current accuracy information. * @param[in] manager The location manager handle * @param[out] level The accuracy level * @param[out] horizontal The horizontal accuracy (meters) * @param[out] vertical The vertical accuracy (meters) * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available * @retval #LOCATIONS_ERROR_GPS_SETTING_OFF GPS is not enabled * @pre The location service state must be #LOCATIONS_SERVICE_ENABLED with location_manager_start() */ int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical); /** * @brief Gets the last position information which is recorded. * @details The @a altitude, @a latitude, @a longitude, and @c timestamp values should be 0, if there is no record of any previous position information. * @details If @a altitude is negative, only altitude and latitude are available (fix status is 2D). * @details If @a altitude is positive, fix status is 3D and returned altitude value is the result of measurement. * @param[in] manager The location manager handle * @param[out] altitude The last altitude (meters) * @param[out] latitude The last latitude [-90.0 ~ 90.0] (degrees) * @param[out] longitude The last longitude [-180.0 ~ 180.0] (degrees) * @param[out] timestamp The timestamp (time when measurement took place or 0 if invalid) * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument * @pre The location manager handle must be created by location_manager_create() */ int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp); /** * @brief Gets the last velocity information which is recorded. * @details * The @a climb, @a direction and @a speed values should be 0, if there is no record of any previous velocity information. * * @param[in] manager The location manager handle * @param[out] climb The last climb (km/h) * @param[out] direction The last direction, degrees from the north * @param[out] speed The last speed (km/h) * @param[out] timestamp The timestamp (time when measurement took place or 0 if invalid) * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument * @pre The location manager handle must be created by location_manager_create() */ int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp); /** * @brief Gets the last accuracy information which is recorded. * @param[in] manager The location manager handle * @param[out] level The last accuracy level * @param[out] horizontal The last horizontal accuracy (meters) * @param[out] vertical The last vertical accuracy (meters) * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument * @pre The location manager handle must be created by location_manager_create() */ int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical); /** * @brief Registers a callback function to be invoked at defined interval with updated position information. * * @param[in] manager The location manager handle * @param[in] callback The callback function to register * @param[in] interval The interval [1 ~ 120] (seconds) * @param[in] user_data The user data to be passed to the callback function * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @post location_position_updated_cb() will be invoked * @see location_manager_unset_position_updated_cb() * @see location_position_updated_cb() */ int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data); /** * @brief Unregisters the callback function. * * @param[in] manager The location manager handle * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @see location_manager_set_position_updated_cb() */ int location_manager_unset_position_updated_cb(location_manager_h manager); /** * @brief Registers a callback function to be invoked at defined interval with updated velocity information. * * @param[in] manager The location manager handle * @param[in] callback The callback function to register * @param[in] interval The interval [1 ~ 120] (seconds) * @param[in] user_data The user data to be passed to the callback function * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @post location_velocity_updated_cb() will be invoked * @see location_manager_unset_velocity_updated_cb() * @see location_velocity_updated_cb() */ int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data); /** * @brief Unregisters the callback function. * * @param[in] manager The location manager handle * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @see location_manager_set_velocity_updated_cb() */ int location_manager_unset_velocity_updated_cb(location_manager_h manager); /** * @brief Registers a callback function to be invoked when the location service state is changed. * * @param[in] manager The location manager handle * @param[in] callback The callback function to register * @param[in] user_data The user data to be passed to the callback function * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @post location_service_state_changed_cb() will be invoked * @see location_manager_unset_service_state_changed_cb() * @see location_service_state_changed_cb() * @see location_manager_start() * @see location_manager_stop() * @see #location_service_state_e */ int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback, void *user_data); /** * @brief Unregisters the callback function. * @param[in] manager The location manager handle * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @see location_manager_set_service_state_changed_cb() */ int location_manager_unset_service_state_changed_cb(location_manager_h manager); /** * @brief Registers a callback function to be invoked when the previously set boundary area is entered or left. * * @param[in] manager The location manager handle * @param[in] callback The callback function to register * @param[in] user_data The user data to be passed to the callback function * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @pre Either location_manager_set_boundary_rect() or location_manager_set_boundary_circle() is called before. * @post location_zone_changed_cb() will be invoked * @see location_manager_unset_zone_changed_cb() * @see location_zone_changed_cb() */ int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data); /** * @brief Unregisters the callback function. * @param[in] manager The location manager handle * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @see location_manager_set_zone_changed_cb() */ int location_manager_unset_zone_changed_cb(location_manager_h manager); /** * @brief Gets the distance in meters between two locations. * @param[in] start_latitude The starting latitude [-90.0 ~ 90.0] (degrees) * @param[in] start_longitude The starting longitude [-180.0 ~ 180.0] (degrees) * @param[in] end_latitude The ending latitude [-90.0 ~ 90.0] (degrees) * @param[in] end_longitude The ending longitude [-180.0 ~ 180.0] (degrees) * @param[out] distance The distance between two locations (meters) * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument */ int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance); /** * @brief Sends command to the server. * @param[in] cmd The command string to be sent * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter */ int location_manager_send_command(const char *cmd); /** * @} */ /* * GPS Status & Satellites */ /** * @addtogroup CAPI_LOCATION_GPS_STATUS_MODULE * @{ */ /** * @brief Called once for each satellite in range. * @param[in] azimuth The azimuth of the satellite (degrees) * @param[in] elevation The elevation of the satellite (meters) * @param[in] prn The PRN of the satellite * @param[in] snr The SNR of the satellite [dB] * @param[in] is_active The flag signaling if satellite is in use * @param[in] user_data The user data passed from the foreach function * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop * @pre gps_status_foreach_satellites_in_view() will invoke this callback. * @pre gps_status_foreach_last_satellites_in_view() will invoke this callback. * @see gps_status_foreach_satellites_in_view() */ typedef bool(*gps_status_get_satellites_cb)(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_active, void *user_data); /** * @brief Called at defined interval with updated satellite information. * @param[out] num_of_active The last number of active satellites * @param[out] num_of_inview The last number of satellites in view * @param[out] timestamp The last timestamp (time when last measurement took place or 0 if invalid) * @param[in] user_data The user data passed from the call registration function * @pre location_manager_start() will invoke this callback if you register this callback using location_manager_set_position_updated_cb() * @see location_manager_start() * @see location_manager_set_position_updated_cb() */ typedef void(*gps_status_satellite_updated_cb)(int num_of_active, int num_of_inview, time_t timestamp, void *user_data); /** * @brief Gets the GPS NMEA data. * @remarks This call is valid only for location managers with #LOCATIONS_METHOD_GPS method.\n * @a nmea must be released with @c free() by you. * @param[in] manager The location manager handle * @param[out] nmea The NMEA data * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument * @retval #LOCATIONS_ERROR_INCORRECT_METHOD Incorrect method * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available * @retval #LOCATIONS_ERROR_OUT_OF_MEMORY Out of memory * @pre The location service state must be #LOCATIONS_SERVICE_ENABLED with location_manager_start() * @see location_manager_start() */ int gps_status_get_nmea(location_manager_h manager, char **nmea); /** * @brief Gets the information of satellites. * @remarks This call is valid only for location managers with #LOCATIONS_METHOD_GPS method. * @param[in] manager The location manager handle * @param[out] num_of_active The number of active satellites * @param[out] num_of_inview The number of satellites in view * @param[out] timestamp The timestamp (time when measurement took place or 0 if invalid) * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument * @retval #LOCATIONS_ERROR_INCORRECT_METHOD Incorrect method * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available * @pre The location service state must be #LOCATIONS_SERVICE_ENABLED with location_manager_start() * @see gps_status_foreach_satellites_in_view() */ int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp); /** * @brief Registers a callback function to be invoked at defined interval with updated satellite information. * * @param[in] manager The location manager handle * @param[in] callback The callback function to register * @param[in] interval The interval [1 ~ 120] (seconds) * @param[in] user_data The user data to be passed to the callback function * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @post gps_status_satellite_updated_cb() will be invoked * @see gps_status_unset_satellite_updated_cb() * @see gps_status_satellite_updated_cb() */ int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data); /** * @brief Unregisters the callback function. * * @param[in] manager The location manager handle * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter * @see gps_status_set_satellite_updated_cb() */ int gps_status_unset_satellite_updated_cb(location_manager_h manager); /** * @brief Invokes the callback function for each satellite. * @remarks This function is valid only for location managers with the #LOCATIONS_METHOD_GPS method. * @param[in] manager The location manager handle * @param[in] callback The iteration callback function * @param[in] user_data The user data to be passed to the callback function * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument * @retval #LOCATIONS_ERROR_INCORRECT_METHOD Incorrect method * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available * @pre The location service state must be #LOCATIONS_SERVICE_ENABLED with location_manager_start() * @post It invokes gps_status_get_satellites_cb(). * @see gps_status_get_satellite() * @see gps_status_get_satellites_cb() */ int gps_status_foreach_satellites_in_view (location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data); /** * @brief Gets the last information of satellites. * @remarks This call is valid only for location managers with #LOCATIONS_METHOD_GPS method. * @param[in] manager The location manager handle * @param[out] num_of_active The last number of active satellites * @param[out] num_of_inview The last number of satellites in view * @param[out] timestamp The last timestamp (time when last measurement took place or 0 if invalid) * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument * @retval #LOCATIONS_ERROR_INCORRECT_METHOD Incorrect method * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available * @pre The location service state must be #LOCATIONS_SERVICE_ENABLED with location_manager_start() * @see gps_status_foreach_satellites_in_view() */ int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp); /** * @brief Invokes the callback function for each last satellite which is recorded. * @remarks This function is valid only for location managers with the #LOCATIONS_METHOD_GPS method. * @param[in] manager The location manager handle * @param[in] callback The iteration callback function * @param[in] user_data The user data to be passed to the callback function * @return 0 on success, otherwise a negative error value. * @retval #LOCATIONS_ERROR_NONE Successful * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument * @retval #LOCATIONS_ERROR_INCORRECT_METHOD Incorrect method * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available * @pre The location service state must be #LOCATIONS_SERVICE_ENABLED with location_manager_start() * @post It invokes gps_status_get_satellites_cb(). * @see gps_status_get_last_satellite() * @see gps_status_get_satellites_cb() */ int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data); /** * @} */ #ifdef __cplusplus } #endif #endif /* __TIZEN_LOCATION_LOCATIONS_H__ */
tizenorg/framework.api.location-manager
TC/testcase/utc_location_location_manager.c
<gh_stars>0 /* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <tet_api.h> #include <locations.h> #include <glib.h> enum { POSITIVE_TC_IDX = 0x01, NEGATIVE_TC_IDX, }; static void startup(void); static void cleanup(void); void (*tet_startup) (void) = startup; void (*tet_cleanup) (void) = cleanup; static void utc_location_location_manager_create_p(void); static void utc_location_location_manager_create_p_02(void); static void utc_location_location_manager_create_p_03(void); static void utc_location_location_manager_create_p_04(void); static void utc_location_location_manager_create_p_05(void); static void utc_location_location_manager_create_n(void); static void utc_location_location_manager_create_n_02(void); static void utc_location_location_manager_create_n_03(void); static void utc_location_location_manager_create_n_04(void); static void utc_location_location_manager_create_n_05(void); static void utc_location_location_manager_create_n_06(void); static void utc_location_location_manager_add_boundary_p(void); static void utc_location_location_manager_add_boundary_n(void); static void utc_location_location_manager_add_boundary_n_02(void); static void utc_location_location_manager_add_boundary_n_03(void); static void utc_location_location_manager_add_boundary_n_04(void); static void utc_location_location_manager_foreach_boundary_p(void); static void utc_location_location_manager_foreach_boundary_n(void); static void utc_location_location_manager_foreach_boundary_n_02(void); static void utc_location_location_manager_foreach_boundary_n_03(void); static void utc_location_location_manager_foreach_boundary_n_04(void); static void utc_location_location_manager_remove_boundary_p(void); static void utc_location_location_manager_remove_boundary_n(void); static void utc_location_location_manager_remove_boundary_n_02(void); static void utc_location_location_manager_remove_boundary_n_03(void); static void utc_location_location_manager_remove_boundary_n_04(void); static void utc_location_location_manager_get_method_p(void); static void utc_location_location_manager_get_method_n(void); static void utc_location_location_manager_get_method_n_02(void); static void utc_location_location_manager_get_method_n_03(void); static void utc_location_location_manager_get_method_n_04(void); static void utc_location_location_manager_get_position_p(void); static void utc_location_location_manager_get_position_n(void); static void utc_location_location_manager_get_position_n_02(void); static void utc_location_location_manager_get_position_n_03(void); static void utc_location_location_manager_get_position_n_04(void); static void utc_location_location_manager_get_position_n_05(void); static void utc_location_location_manager_get_position_n_06(void); static void utc_location_location_manager_get_velocity_p(void); static void utc_location_location_manager_get_velocity_n(void); static void utc_location_location_manager_get_velocity_n_02(void); static void utc_location_location_manager_get_velocity_n_03(void); static void utc_location_location_manager_get_velocity_n_04(void); static void utc_location_location_manager_get_velocity_n_05(void); static void utc_location_location_manager_get_velocity_n_06(void); static void utc_location_location_manager_get_accuracy_p(void); static void utc_location_location_manager_get_accuracy_n(void); static void utc_location_location_manager_get_accuracy_n_02(void); static void utc_location_location_manager_get_accuracy_n_03(void); static void utc_location_location_manager_get_accuracy_n_04(void); static void utc_location_location_manager_get_accuracy_n_05(void); static void utc_location_location_manager_get_accuracy_n_06(void); static void utc_location_location_bounds_foreach_polygon_coords_p(void); static void utc_location_location_bounds_foreach_polygon_coords_n(void); static void utc_location_location_bounds_foreach_polygon_coords_n_02(void); static void utc_location_location_bounds_get_circle_coords_p(void); static void utc_location_location_bounds_get_circle_coords_n(void); static void utc_location_location_bounds_get_circle_coords_n_02(void); static void utc_location_location_bounds_get_circle_coords_n_03(void); static void utc_location_location_bounds_get_rect_coords_p(void); static void utc_location_location_bounds_get_rect_coords_n(void); static void utc_location_location_bounds_get_rect_coords_n_02(void); static void utc_location_location_bounds_get_rect_coords_n_03(void); static void utc_location_location_bounds_contains_coordinates_p(void); static void utc_location_location_bounds_contains_coordinates_p_02(void); static void utc_location_location_bounds_contains_coordinates_n(void); static void utc_location_location_bounds_contains_coordinates_n_02(void); static void utc_location_location_manager_get_last_accuracy_p(void); static void utc_location_location_manager_get_last_accuracy_n(void); static void utc_location_location_manager_get_last_accuracy_n_02(void); static void utc_location_location_manager_get_last_accuracy_n_03(void); static void utc_location_location_manager_get_last_accuracy_n_04(void); static void utc_location_location_manager_get_last_position_p(void); static void utc_location_location_manager_get_last_position_n(void); static void utc_location_location_manager_get_last_position_n_02(void); static void utc_location_location_manager_get_last_position_n_03(void); static void utc_location_location_manager_get_last_position_n_04(void); static void utc_location_location_manager_get_last_position_n_05(void); static void utc_location_location_manager_get_last_velocity_p(void); static void utc_location_location_manager_get_last_velocity_n(void); static void utc_location_location_manager_get_last_velocity_n_02(void); static void utc_location_location_manager_get_last_velocity_n_03(void); static void utc_location_location_manager_get_last_velocity_n_04(void); static void utc_location_location_manager_get_last_velocity_n_05(void); static void utc_location_location_manager_is_supported_method_p(void); static void utc_location_location_manager_is_supported_method_p_02(void); static void utc_location_location_manager_is_supported_method_p_03(void); static void utc_location_location_manager_is_supported_method_p_04(void); static void utc_location_location_manager_is_supported_method_n(void); static void utc_location_location_manager_is_supported_method_n_02(void); static void utc_location_location_manager_send_command_p(void); static void utc_location_location_manager_send_command_n(void); static void utc_location_location_manager_destroy_p(void); static void utc_location_location_manager_destroy_n(void); static void utc_location_location_manager_destroy_n_02(void); struct tet_testlist tet_testlist[] = { {utc_location_location_manager_create_p, POSITIVE_TC_IDX}, {utc_location_location_manager_create_p_02, POSITIVE_TC_IDX}, {utc_location_location_manager_create_p_03, POSITIVE_TC_IDX}, { utc_location_location_manager_create_p_04, POSITIVE_TC_IDX }, // { utc_location_location_manager_create_p_05, POSITIVE_TC_IDX }, // LOCATIONS_METHOD_NONE is a negative TC. {utc_location_location_manager_create_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_create_n_02, NEGATIVE_TC_IDX}, {utc_location_location_manager_create_n_03, NEGATIVE_TC_IDX}, {utc_location_location_manager_create_n_04, NEGATIVE_TC_IDX}, {utc_location_location_manager_create_n_05, NEGATIVE_TC_IDX}, {utc_location_location_manager_create_n_06, NEGATIVE_TC_IDX}, {utc_location_location_manager_add_boundary_p, POSITIVE_TC_IDX}, {utc_location_location_manager_add_boundary_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_add_boundary_n_02, NEGATIVE_TC_IDX}, {utc_location_location_manager_add_boundary_n_03, NEGATIVE_TC_IDX}, {utc_location_location_manager_add_boundary_n_04, NEGATIVE_TC_IDX}, {utc_location_location_manager_foreach_boundary_p, POSITIVE_TC_IDX}, {utc_location_location_manager_foreach_boundary_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_foreach_boundary_n_02, NEGATIVE_TC_IDX}, // { utc_location_location_manager_foreach_boundary_n_03, NEGATIVE_TC_IDX }, // Can't check created location_manager_h {utc_location_location_manager_foreach_boundary_n_04, NEGATIVE_TC_IDX}, {utc_location_location_manager_remove_boundary_p, POSITIVE_TC_IDX}, {utc_location_location_manager_remove_boundary_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_remove_boundary_n_02, NEGATIVE_TC_IDX}, // { utc_location_location_manager_remove_boundary_n_03, NEGATIVE_TC_IDX }, // Can't check created location_manager_h {utc_location_location_manager_remove_boundary_n_04, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_method_p, POSITIVE_TC_IDX}, {utc_location_location_manager_get_method_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_method_n_02, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_method_n_03, NEGATIVE_TC_IDX}, // { utc_location_location_manager_get_method_n_04, NEGATIVE_TC_IDX }, // Can't check created location_manager_h {utc_location_location_manager_get_position_p, POSITIVE_TC_IDX}, {utc_location_location_manager_get_position_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_position_n_02, NEGATIVE_TC_IDX}, // { utc_location_location_manager_get_position_n_03, NEGATIVE_TC_IDX }, // Can't check created location_manager_h {utc_location_location_manager_get_position_n_04, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_position_n_05, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_position_n_06, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_velocity_p, POSITIVE_TC_IDX}, {utc_location_location_manager_get_velocity_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_velocity_n_02, NEGATIVE_TC_IDX}, // { utc_location_location_manager_get_velocity_n_03, NEGATIVE_TC_IDX }, // Can't check created location_manager_h {utc_location_location_manager_get_velocity_n_04, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_velocity_n_05, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_velocity_n_06, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_accuracy_p, POSITIVE_TC_IDX}, {utc_location_location_manager_get_accuracy_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_accuracy_n_02, NEGATIVE_TC_IDX}, // { utc_location_location_manager_get_accuracy_n_03, NEGATIVE_TC_IDX }, // Can't check created location_manager_h {utc_location_location_manager_get_accuracy_n_04, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_accuracy_n_05, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_accuracy_n_06, NEGATIVE_TC_IDX}, {utc_location_location_bounds_foreach_polygon_coords_p, POSITIVE_TC_IDX}, {utc_location_location_bounds_foreach_polygon_coords_n, NEGATIVE_TC_IDX}, {utc_location_location_bounds_foreach_polygon_coords_n_02, NEGATIVE_TC_IDX}, {utc_location_location_bounds_get_circle_coords_p, POSITIVE_TC_IDX}, {utc_location_location_bounds_get_circle_coords_n, NEGATIVE_TC_IDX}, {utc_location_location_bounds_get_circle_coords_n_02, NEGATIVE_TC_IDX}, {utc_location_location_bounds_get_circle_coords_n_03, NEGATIVE_TC_IDX}, {utc_location_location_bounds_get_rect_coords_p, POSITIVE_TC_IDX}, {utc_location_location_bounds_get_rect_coords_n, NEGATIVE_TC_IDX}, {utc_location_location_bounds_get_rect_coords_n_02, NEGATIVE_TC_IDX}, {utc_location_location_bounds_get_rect_coords_n_03, NEGATIVE_TC_IDX}, {utc_location_location_bounds_contains_coordinates_p, POSITIVE_TC_IDX}, {utc_location_location_bounds_contains_coordinates_p_02, POSITIVE_TC_IDX}, {utc_location_location_bounds_contains_coordinates_n, NEGATIVE_TC_IDX}, {utc_location_location_bounds_contains_coordinates_n_02, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_last_accuracy_p, POSITIVE_TC_IDX}, {utc_location_location_manager_get_last_accuracy_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_last_accuracy_n_02, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_last_accuracy_n_03, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_last_accuracy_n_04, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_last_position_p, POSITIVE_TC_IDX}, {utc_location_location_manager_get_last_position_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_last_position_n_02, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_last_position_n_03, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_last_position_n_04, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_last_position_n_05, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_last_velocity_p, POSITIVE_TC_IDX}, {utc_location_location_manager_get_last_velocity_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_last_velocity_n_02, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_last_velocity_n_03, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_last_velocity_n_04, NEGATIVE_TC_IDX}, {utc_location_location_manager_get_last_velocity_n_05, NEGATIVE_TC_IDX}, {utc_location_location_manager_is_supported_method_p, POSITIVE_TC_IDX}, {utc_location_location_manager_is_supported_method_p_02, POSITIVE_TC_IDX}, {utc_location_location_manager_is_supported_method_p_03, POSITIVE_TC_IDX}, {utc_location_location_manager_is_supported_method_p_04, POSITIVE_TC_IDX}, {utc_location_location_manager_is_supported_method_n, NEGATIVE_TC_IDX}, {utc_location_location_manager_is_supported_method_n_02, NEGATIVE_TC_IDX}, {utc_location_location_manager_destroy_p, POSITIVE_TC_IDX}, {utc_location_location_manager_destroy_n, NEGATIVE_TC_IDX}, // { utc_location_location_manager_destroy_n_02, NEGATIVE_TC_IDX }, // Can't check created location_manager_h {NULL, 0}, }; static bool service_enabled = false; static bool touch_foreach_bounds = false; static GMainLoop *g_mainloop = NULL; static GThread *event_thread; gpointer GmainThread(gpointer data) { g_mainloop = g_main_loop_new(NULL, 0); g_main_loop_run(g_mainloop); return NULL; } static void validate_and_next(char *api_name, int act_ret, int ext_ret, char *fail_msg) { dts_message(api_name, "Actual Result : %d, Expected Result : %d", act_ret, ext_ret); if (act_ret != ext_ret) { dts_message(api_name, "Fail Message: %s", fail_msg); dts_fail(api_name); } } static void validate_eq(char *api_name, int act_ret, int ext_ret) { dts_message(api_name, "Actual Result : %d, Expected Result : %d", act_ret, ext_ret); if (act_ret == ext_ret) { dts_pass(api_name); } else { dts_fail(api_name); } } static void wait_for_service(char *api_name) { int timeout = 0; for (timeout; timeout < 60; timeout++) { if (service_enabled) { dts_message(api_name, "Location Service Enabled!!!!"); break; } else { dts_message(api_name, "Location Service Disabled!!!!"); sleep(1); } } } static void wait_for_bounds_foreach(char *api_name) { int timeout = 0; for (timeout; timeout < 30; timeout++) { if (touch_foreach_bounds) { dts_message(api_name, "bound foreach called!!!!"); break; } else { dts_message(api_name, "No bound foreach!!!!"); sleep(1); } } } static void __state_changed_cb(location_service_state_e state, void *user_data) { switch (state) { case LOCATIONS_SERVICE_ENABLED: service_enabled = true; break; case LOCATIONS_SERVICE_DISABLED: service_enabled = false; break; default: break; } } static bool __location_bounds_cb(location_bounds_h bounds, void *user_data) { if (bounds == NULL) printf("bounds ==NULL\n"); else { location_bounds_type_e type; location_bounds_get_type(bounds, &type); dts_message(__func__, "__location_bounds_cb - type : %d!!!!", type); touch_foreach_bounds = TRUE; } return TRUE; } static location_manager_h manager; static location_bounds_h bounds_rect; static location_bounds_h bounds_circle; static location_bounds_h bounds_poly; static void startup(void) { g_setenv("PKG_NAME", "com.samsung.capi-location-manager-test", 1); g_setenv("LOCATION_TEST_ENABLE", "1", 1); #if !GLIB_CHECK_VERSION (2, 31, 0) if (!g_thread_supported()) { g_thread_init(NULL); } #endif event_thread = g_thread_create(GmainThread, NULL, 1, NULL); } static void cleanup(void) { if (manager) { location_manager_unset_service_state_changed_cb(manager); location_manager_stop(manager); location_manager_destroy(manager); manager = NULL; } service_enabled = false; touch_foreach_bounds = false; g_main_loop_quit(g_mainloop); g_thread_join(event_thread); } static void utc_location_location_manager_create_p(void) { int ret; ret = location_manager_create(LOCATIONS_METHOD_HYBRID, &manager); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_create() is failed"); ret = location_manager_set_service_state_changed_cb(manager, __state_changed_cb, NULL); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_set_service_state_changed_cb() is failed"); ret = location_manager_start(manager); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_start() is failed"); wait_for_service(__func__); /* location_manager_stop(manager); //If you call start() and then stop(), service_enabled always set false. location_manager_unset_service_state_changed_cb(manager); */ validate_eq(__func__, service_enabled, true); } static void utc_location_location_manager_create_p_02(void) { int ret; location_manager_h manager_02; ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager_02); /* We don't need it validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_create() is failed"); ret = location_manager_set_service_state_changed_cb(manager_02, __state_changed_cb, NULL); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_set_service_state_changed_cb() is failed"); ret = location_manager_start(manager_02); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_start() is failed"); wait_for_service(__func__); location_manager_stop(manager_02); location_manager_unset_service_state_changed_cb(manager_02); */ location_manager_destroy(manager_02); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_create_p_03(void) { int ret; location_manager_h manager_02; ret = location_manager_create(LOCATIONS_METHOD_WPS, &manager_02); /* We don't need it validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_create() is failed"); ret = location_manager_set_service_state_changed_cb(manager_02, __state_changed_cb, NULL); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_set_service_state_changed_cb() is failed"); ret = location_manager_start(manager_02); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_start() is failed"); wait_for_service(__func__); location_manager_stop(manager_02); location_manager_unset_service_state_changed_cb(manager_02); */ location_manager_destroy(manager_02); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_create_p_04(void) { int ret; location_manager_h manager_02; ret = location_manager_create(LOCATIONS_METHOD_CPS, &manager_02); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_create() is failed"); ret = location_manager_set_service_state_changed_cb(manager_02, __state_changed_cb, NULL); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_set_service_state_changed_cb() is failed"); ret = location_manager_start(manager_02); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_start() is failed"); wait_for_service(__func__); location_manager_stop(manager_02); location_manager_unset_service_state_changed_cb(manager_02); location_manager_destroy(manager_02); validate_eq(__func__, service_enabled, TRUE); } static void utc_location_location_manager_create_p_05(void) { int ret; location_manager_h manager_02; ret = location_manager_create(LOCATIONS_METHOD_NONE, &manager_02); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_create() is failed"); ret = location_manager_set_service_state_changed_cb(manager_02, __state_changed_cb, NULL); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_set_service_state_changed_cb() is failed"); ret = location_manager_start(manager_02); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_start() is failed"); wait_for_service(__func__); location_manager_stop(manager_02); location_manager_unset_service_state_changed_cb(manager_02); location_manager_destroy(manager_02); validate_eq(__func__, service_enabled, TRUE); } static void utc_location_location_manager_create_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_create(LOCATIONS_METHOD_HYBRID, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_create_n_02(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_create(LOCATIONS_METHOD_NONE, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_create_n_03(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_create(LOCATIONS_METHOD_GPS, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_create_n_04(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_create(LOCATIONS_METHOD_WPS, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_create_n_05(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_create(LOCATIONS_METHOD_CPS, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_create_n_06(void) { int ret = LOCATIONS_ERROR_NONE; location_manager_h manager_02; ret = location_manager_create(LOCATIONS_METHOD_CPS + 1, &manager_02); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_add_boundary_p(void) { int ret = LOCATIONS_ERROR_NONE; //Add the circle bounds location_coords_s center; center.latitude = 37.258; center.longitude = 127.056; double radius = 30; ret = location_bounds_create_circle(center, radius, &bounds_circle); validate_and_next(__func__, ret, LOCATION_BOUNDS_ERROR_NONE, "location_bounds_create_circle() is failed"); ret = location_manager_add_boundary(manager, bounds_circle); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_add_boundary() is failed"); //Add the rect bounds location_coords_s left_top; left_top.latitude = 30; left_top.longitude = 30; location_coords_s right_bottom; right_bottom.latitude = 10; right_bottom.longitude = 50; ret = location_bounds_create_rect(left_top, right_bottom, &bounds_rect); validate_and_next(__func__, ret, LOCATION_BOUNDS_ERROR_NONE, "location_bounds_create_rect() is failed"); ret = location_manager_add_boundary(manager, bounds_rect); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_add_boundary() is failed"); //Add the polygon bounds int poly_size = 3; location_coords_s coord_list[poly_size]; coord_list[0].latitude = 10; coord_list[0].longitude = 10; coord_list[1].latitude = 20; coord_list[1].longitude = 20; coord_list[2].latitude = 30; coord_list[2].longitude = 30; ret = location_bounds_create_polygon(coord_list, poly_size, &bounds_poly); validate_and_next(__func__, ret, LOCATION_BOUNDS_ERROR_NONE, "location_bounds_create_polygon() is failed"); ret = location_manager_add_boundary(manager, bounds_poly); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_add_boundary_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_add_boundary(NULL, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_add_boundary_n_02(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_add_boundary(manager, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_add_boundary_n_03(void) { int ret = LOCATIONS_ERROR_NONE; //Add the circle bounds location_coords_s center; center.latitude = 37.258; center.longitude = 127.056; double radius = 30; ret = location_bounds_create_circle(center, radius, &bounds_circle); validate_and_next(__func__, ret, LOCATION_BOUNDS_ERROR_NONE, "location_bounds_create_circle() is failed"); ret = location_manager_add_boundary(NULL, bounds_circle); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_add_boundary_n_04(void) { int ret = LOCATIONS_ERROR_NONE; location_manager_h manager_02; //Add the circle bounds location_coords_s center; center.latitude = 37.258; center.longitude = 127.056; double radius = 30; ret = location_bounds_create_circle(center, radius, &bounds_circle); validate_and_next(__func__, ret, LOCATION_BOUNDS_ERROR_NONE, "location_bounds_create_circle() is failed"); ret = location_manager_add_boundary(manager_02, bounds_circle); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_foreach_boundary_p(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_foreach_boundary(manager, __location_bounds_cb, (void *)manager); validate_and_next(__func__, ret, LOCATION_BOUNDS_ERROR_NONE, "location_manager_foreach_boundary() is failed"); wait_for_bounds_foreach(__func__); validate_eq(__func__, touch_foreach_bounds, TRUE); } static void utc_location_location_manager_foreach_boundary_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_foreach_boundary(NULL, NULL, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_foreach_boundary_n_02(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_foreach_boundary(NULL, __location_bounds_cb, (void *)manager); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_foreach_boundary_n_03(void) { int ret = LOCATIONS_ERROR_NONE; location_manager_h manager_02; ret = location_manager_foreach_boundary(manager_02, __location_bounds_cb, (void *)manager); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_foreach_boundary_n_04(void) { int ret = LOCATIONS_ERROR_NONE; location_manager_h manager_02; ret = location_manager_foreach_boundary(manager, NULL, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_remove_boundary_p(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_remove_boundary(manager, bounds_rect); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_remove_boundary(rect) is failed"); ret = location_manager_remove_boundary(manager, bounds_circle); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_remove_boundary(circle) is failed"); ret = location_manager_remove_boundary(manager, bounds_poly); location_bounds_destroy(bounds_rect); location_bounds_destroy(bounds_circle); location_bounds_destroy(bounds_poly); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_remove_boundary_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_remove_boundary(NULL, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_remove_boundary_n_02(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_remove_boundary(NULL, bounds_rect); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_remove_boundary_n_03(void) { int ret = LOCATIONS_ERROR_NONE; location_manager_h manager_02; ret = location_manager_remove_boundary(manager_02, bounds_rect); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_remove_boundary_n_04(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_remove_boundary(manager, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_method_p(void) { int ret = LOCATIONS_ERROR_NONE; location_method_e method; ret = location_manager_get_method(manager, &method); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_get_method_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_get_method(NULL, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_method_n_02(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_get_method(manager, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_method_n_03(void) { int ret = LOCATIONS_ERROR_NONE; location_method_e method; ret = location_manager_get_method(NULL, &method); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_method_n_04(void) { int ret = LOCATIONS_ERROR_NONE; location_manager_h manager_02; location_method_e method; ret = location_manager_get_method(manager_02, &method); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_position_p(void) { int ret = LOCATIONS_ERROR_NONE; double altitude; double latitude; double longitude; time_t timestamp; ret = location_manager_get_position(manager, &altitude, &latitude, &longitude, &timestamp); dts_message(__func__, "altitude : %lf, latitude : %lf, longitude : %lf, timestamp:%d", latitude, latitude, longitude, timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_get_position_n(void) { int ret = LOCATIONS_ERROR_NONE; double latitude; double longitude; time_t timestamp; ret = location_manager_get_position(manager, NULL, &latitude, &longitude, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_position_n_02(void) { int ret = LOCATIONS_ERROR_NONE; double altitude; double latitude; double longitude; time_t timestamp; ret = location_manager_get_position(NULL, &altitude, &latitude, &longitude, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_position_n_03(void) { int ret = LOCATIONS_ERROR_NONE; double altitude; double latitude; double longitude; time_t timestamp; location_manager_h manager_02; ret = location_manager_get_position(manager_02, &altitude, &latitude, &longitude, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_position_n_04(void) { int ret = LOCATIONS_ERROR_NONE; double altitude; double longitude; time_t timestamp; ret = location_manager_get_position(manager, &altitude, NULL, &longitude, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_position_n_05(void) { int ret = LOCATIONS_ERROR_NONE; double altitude; double latitude; time_t timestamp; ret = location_manager_get_position(manager, &altitude, &latitude, NULL, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_position_n_06(void) { int ret = LOCATIONS_ERROR_NONE; double altitude; double latitude; double longitude; ret = location_manager_get_position(manager, &altitude, &latitude, &longitude, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_velocity_p(void) { int ret = LOCATIONS_ERROR_NONE; int climb; int direction; int speed; time_t timestamp; ret = location_manager_get_velocity(manager, &climb, &direction, &speed, &timestamp); dts_message(__func__, "climb : %lf, direction : %lf, speed : %lf, timestamp:%d", climb, direction, speed, timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_get_velocity_n(void) { int ret = LOCATIONS_ERROR_NONE; int direction; int speed; time_t timestamp; ret = location_manager_get_velocity(manager, NULL, &direction, &speed, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_velocity_n_02(void) { int ret = LOCATIONS_ERROR_NONE; int climb; int direction; int speed; time_t timestamp; ret = location_manager_get_velocity(NULL, &climb, &direction, &speed, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_velocity_n_03(void) { int ret = LOCATIONS_ERROR_NONE; int climb; int direction; int speed; time_t timestamp; location_manager_h manager_02; ret = location_manager_get_velocity(manager_02, &climb, &direction, &speed, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_velocity_n_04(void) { int ret = LOCATIONS_ERROR_NONE; int climb; int speed; time_t timestamp; ret = location_manager_get_velocity(manager, &climb, NULL, &speed, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_velocity_n_05(void) { int ret = LOCATIONS_ERROR_NONE; int climb; int direction; time_t timestamp; ret = location_manager_get_velocity(manager, &climb, &direction, NULL, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_velocity_n_06(void) { int ret = LOCATIONS_ERROR_NONE; int climb; int direction; int speed; ret = location_manager_get_velocity(manager, &climb, &direction, &speed, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_accuracy_p(void) { int ret = LOCATIONS_ERROR_NONE; location_accuracy_level_e level; double horizontal; double vertical; ret = location_manager_get_accuracy(manager, &level, &horizontal, &vertical); dts_message(__func__, "Level : %lf, horizontal : %lf, vertical : %lf", level, horizontal, vertical); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_get_accuracy_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_get_accuracy(manager, NULL, NULL, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_accuracy_n_02(void) { int ret = LOCATIONS_ERROR_NONE; location_accuracy_level_e level; double horizontal; double vertical; ret = location_manager_get_accuracy(NULL, &level, &horizontal, &vertical); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_accuracy_n_03(void) { int ret = LOCATIONS_ERROR_NONE; location_accuracy_level_e level; double horizontal; double vertical; location_manager_h manager_02; ret = location_manager_get_accuracy(manager_02, &level, &horizontal, &vertical); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_accuracy_n_04(void) { int ret = LOCATIONS_ERROR_NONE; double horizontal; double vertical; ret = location_manager_get_accuracy(manager, NULL, &horizontal, &vertical); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_accuracy_n_05(void) { int ret = LOCATIONS_ERROR_NONE; location_accuracy_level_e level; double vertical; ret = location_manager_get_accuracy(manager, &level, NULL, &vertical); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_accuracy_n_06(void) { int ret = LOCATIONS_ERROR_NONE; location_accuracy_level_e level; double horizontal; ret = location_manager_get_accuracy(manager, &level, &horizontal, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static bool capi_poly_coords_cb(location_coords_s coords, void *user_data) { printf("location_bounds_foreach_rect_coords(latitude : %lf, longitude: %lf) \n", coords.latitude, coords.longitude); return TRUE; } static void utc_location_location_bounds_foreach_polygon_coords_p(void) { int ret = LOCATIONS_ERROR_NONE; //Add the polygon bounds int poly_size = 3; location_coords_s coord_list[poly_size]; coord_list[0].latitude = 10; coord_list[0].longitude = 10; coord_list[1].latitude = 20; coord_list[1].longitude = 20; coord_list[2].latitude = 30; coord_list[2].longitude = 30; location_bounds_h bounds_poly; ret = location_bounds_create_polygon(coord_list, poly_size, &bounds_poly); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_bounds_create_polygon() is failed"); ret = location_bounds_foreach_polygon_coords(bounds_poly, capi_poly_coords_cb, NULL); location_bounds_destroy(bounds_poly); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_bounds_foreach_polygon_coords_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_bounds_foreach_polygon_coords(NULL, capi_poly_coords_cb, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_bounds_foreach_polygon_coords_n_02(void) { int ret = LOCATIONS_ERROR_NONE; //Add the polygon bounds int poly_size = 3; location_coords_s coord_list[poly_size]; coord_list[0].latitude = 10; coord_list[0].longitude = 10; coord_list[1].latitude = 20; coord_list[1].longitude = 20; coord_list[2].latitude = 30; coord_list[2].longitude = 30; location_bounds_h bounds_poly; ret = location_bounds_create_polygon(coord_list, poly_size, &bounds_poly); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_bounds_create_polygon() is failed"); ret = location_bounds_foreach_polygon_coords(bounds_poly, NULL, NULL); location_bounds_destroy(bounds_poly); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_bounds_get_circle_coords_p(void) { int ret = LOCATIONS_ERROR_NONE; location_coords_s center; center.latitude = 37.258; center.longitude = 127.056; double radius = 30; location_bounds_h bounds_circle; ret = location_bounds_create_circle(center, radius, &bounds_circle); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_bounds_create_circle() is failed"); location_coords_s center2; double radius2; ret = location_bounds_get_circle_coords(bounds_circle, &center2, &radius2); location_bounds_destroy(bounds_circle); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_bounds_get_circle_coords_n(void) { int ret = LOCATIONS_ERROR_NONE; location_coords_s center2; double radius2; ret = location_bounds_get_circle_coords(NULL, &center2, &radius2); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_bounds_get_circle_coords_n_02(void) { int ret = LOCATIONS_ERROR_NONE; location_coords_s center; center.latitude = 37.258; center.longitude = 127.056; double radius = 30; location_bounds_h bounds_circle; ret = location_bounds_create_circle(center, radius, &bounds_circle); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_bounds_create_circle() is failed"); double radius2; ret = location_bounds_get_circle_coords(bounds_circle, NULL, &radius2); location_bounds_destroy(bounds_circle); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_bounds_get_circle_coords_n_03(void) { int ret = LOCATIONS_ERROR_NONE; location_coords_s center; center.latitude = 37.258; center.longitude = 127.056; double radius = 30; location_bounds_h bounds_circle; ret = location_bounds_create_circle(center, radius, &bounds_circle); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_bounds_create_circle() is failed"); location_coords_s center2; ret = location_bounds_get_circle_coords(bounds_circle, &center2, NULL); location_bounds_destroy(bounds_circle); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_bounds_get_rect_coords_p(void) { int ret = LOCATIONS_ERROR_NONE; //Add the rect bounds location_coords_s left_top; left_top.latitude = 30; left_top.longitude = 30; location_coords_s right_bottom; right_bottom.latitude = 10; right_bottom.longitude = 50; location_bounds_h bounds_rect; ret = location_bounds_create_rect(left_top, right_bottom, &bounds_rect); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_bounds_create_rect() is failed"); location_coords_s left_top2; location_coords_s right_bottom2; ret = location_bounds_get_rect_coords(bounds_rect, &left_top2, &right_bottom2); location_bounds_destroy(bounds_rect); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_bounds_get_rect_coords_n(void) { int ret = LOCATIONS_ERROR_NONE; location_coords_s left_top2; location_coords_s right_bottom2; ret = location_bounds_get_rect_coords(NULL, &left_top2, &right_bottom2); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_bounds_get_rect_coords_n_02(void) { int ret = LOCATIONS_ERROR_NONE; //Add the rect bounds location_coords_s left_top; left_top.latitude = 30; left_top.longitude = 30; location_coords_s right_bottom; right_bottom.latitude = 10; right_bottom.longitude = 50; location_bounds_h bounds_rect; ret = location_bounds_create_rect(left_top, right_bottom, &bounds_rect); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_bounds_create_rect() is failed"); location_coords_s right_bottom2; ret = location_bounds_get_rect_coords(bounds_rect, NULL, &right_bottom2); location_bounds_destroy(bounds_rect); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_bounds_get_rect_coords_n_03(void) { int ret = LOCATIONS_ERROR_NONE; //Add the rect bounds location_coords_s left_top; left_top.latitude = 30; left_top.longitude = 30; location_coords_s right_bottom; right_bottom.latitude = 10; right_bottom.longitude = 50; location_bounds_h bounds_rect; ret = location_bounds_create_rect(left_top, right_bottom, &bounds_rect); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_bounds_create_rect() is failed"); location_coords_s left_top2; ret = location_bounds_get_rect_coords(bounds_rect, &left_top2, NULL); location_bounds_destroy(bounds_rect); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_bounds_contains_coordinates_p(void) { int ret = LOCATIONS_ERROR_NONE; //Add the polygon bounds int poly_size = 3; location_coords_s coord_list[poly_size]; coord_list[0].latitude = 10; coord_list[0].longitude = 10; coord_list[1].latitude = 20; coord_list[1].longitude = 20; coord_list[2].latitude = 30; coord_list[2].longitude = 10; location_bounds_h bounds_poly; ret = location_bounds_create_polygon(coord_list, poly_size, &bounds_poly); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_bounds_create_polygon() is failed"); location_coords_s test_coords; test_coords.latitude = 20; test_coords.longitude = 12; bool contained = FALSE; contained = location_bounds_contains_coordinates(bounds_poly, test_coords); location_bounds_destroy(bounds_poly); validate_eq(__func__, contained, TRUE); } static void utc_location_location_bounds_contains_coordinates_p_02(void) { int ret = LOCATIONS_ERROR_NONE; //Add the polygon bounds int poly_size = 3; location_coords_s coord_list[poly_size]; coord_list[0].latitude = 10; coord_list[0].longitude = 10; coord_list[1].latitude = 20; coord_list[1].longitude = 20; coord_list[2].latitude = 30; coord_list[2].longitude = 10; location_bounds_h bounds_poly; ret = location_bounds_create_polygon(coord_list, poly_size, &bounds_poly); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_bounds_create_polygon() is failed"); location_coords_s test_coords; test_coords.latitude = 50; test_coords.longitude = 50; bool contained = FALSE; contained = location_bounds_contains_coordinates(bounds_poly, test_coords); location_bounds_destroy(bounds_poly); validate_eq(__func__, contained, FALSE); } static void utc_location_location_bounds_contains_coordinates_n(void) { int ret = LOCATIONS_ERROR_NONE; location_coords_s test_coords; test_coords.latitude = 12; test_coords.longitude = 12; ret = location_bounds_contains_coordinates(NULL, test_coords); validate_eq(__func__, ret, FALSE); } static void utc_location_location_bounds_contains_coordinates_n_02(void) { int ret = LOCATIONS_ERROR_NONE; //Add the polygon bounds int poly_size = 3; location_coords_s coord_list[poly_size]; coord_list[0].latitude = 10; coord_list[0].longitude = 10; coord_list[1].latitude = 20; coord_list[1].longitude = 20; coord_list[2].latitude = 30; coord_list[2].longitude = 10; location_bounds_h bounds_poly; ret = location_bounds_create_polygon(coord_list, poly_size, &bounds_poly); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_bounds_create_polygon() is failed"); location_coords_s coord_test; coord_test.latitude = -91; coord_test.longitude = 181; ret = location_bounds_contains_coordinates(bounds_poly, coord_test); location_bounds_destroy(bounds_poly); validate_eq(__func__, ret, FALSE); } static void utc_location_location_manager_get_last_accuracy_p(void) { int ret = LOCATIONS_ERROR_NONE; double horizontal, vertical; location_accuracy_level_e level; ret = location_manager_get_last_accuracy(manager, &level, &horizontal, &vertical); dts_message(__func__, "Level : %d, horizontal: %g, vertical : %g\n", level, horizontal, vertical); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_get_last_accuracy_n(void) { int ret = LOCATIONS_ERROR_NONE; double horizontal, vertical; location_accuracy_level_e level; ret = location_manager_get_last_accuracy(NULL, &level, &horizontal, &vertical); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_last_accuracy_n_02(void) { int ret = LOCATIONS_ERROR_NONE; double horizontal, vertical; ret = location_manager_get_last_accuracy(manager, NULL, &horizontal, &vertical); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_last_accuracy_n_03(void) { int ret = LOCATIONS_ERROR_NONE; double vertical; location_accuracy_level_e level; ret = location_manager_get_last_accuracy(manager, &level, NULL, &vertical); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_last_accuracy_n_04(void) { int ret = LOCATIONS_ERROR_NONE; double horizontal; location_accuracy_level_e level; ret = location_manager_get_last_accuracy(manager, &level, &horizontal, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_last_position_p(void) { int ret = LOCATIONS_ERROR_NONE; double altitude; double latitude; double longitude; time_t timestamp; ret = location_manager_get_last_position(manager, &altitude, &latitude, &longitude, &timestamp); dts_message(__func__, "altitude : %lf, latitude : %lf, longitude : %lf, timestamp:%d", latitude, latitude, longitude, timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_get_last_position_n(void) { int ret = LOCATIONS_ERROR_NONE; double altitude; double latitude; double longitude; time_t timestamp; ret = location_manager_get_last_position(NULL, &altitude, &latitude, &longitude, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_last_position_n_02(void) { int ret = LOCATIONS_ERROR_NONE; double latitude; double longitude; time_t timestamp; ret = location_manager_get_last_position(manager, NULL, &latitude, &longitude, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_last_position_n_03(void) { int ret = LOCATIONS_ERROR_NONE; double altitude; double longitude; time_t timestamp; ret = location_manager_get_last_position(manager, &altitude, NULL, &longitude, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_last_position_n_04(void) { int ret = LOCATIONS_ERROR_NONE; double altitude; double latitude; time_t timestamp; ret = location_manager_get_last_position(manager, &altitude, &latitude, NULL, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_last_position_n_05(void) { int ret = LOCATIONS_ERROR_NONE; double altitude; double latitude; double longitude; ret = location_manager_get_last_position(manager, &altitude, &latitude, &longitude, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_last_velocity_p(void) { int ret = LOCATIONS_ERROR_NONE; int climb; int direction; int speed; time_t timestamp; ret = location_manager_get_last_velocity(manager, &climb, &direction, &speed, &timestamp); dts_message(__func__, "climb : %lf, direction : %lf, speed : %lf, timestamp:%d", climb, direction, speed, timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_get_last_velocity_n(void) { int ret = LOCATIONS_ERROR_NONE; int climb; int direction; int speed; time_t timestamp; ret = location_manager_get_last_velocity(NULL, &climb, &direction, &speed, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_last_velocity_n_02(void) { int ret = LOCATIONS_ERROR_NONE; int direction; int speed; time_t timestamp; ret = location_manager_get_last_velocity(manager, NULL, &direction, &speed, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_last_velocity_n_03(void) { int ret = LOCATIONS_ERROR_NONE; int climb; int speed; time_t timestamp; ret = location_manager_get_last_velocity(manager, &climb, NULL, &speed, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_last_velocity_n_04(void) { int ret = LOCATIONS_ERROR_NONE; int climb; int direction; time_t timestamp; ret = location_manager_get_last_velocity(manager, &climb, &direction, NULL, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_get_last_velocity_n_05(void) { int ret = LOCATIONS_ERROR_NONE; int climb; int direction; int speed; ret = location_manager_get_last_velocity(manager, &climb, &direction, &speed, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_is_supported_method_p(void) { bool supported = FALSE; supported = location_manager_is_supported_method(LOCATIONS_METHOD_HYBRID); validate_eq(__func__, supported, TRUE); } static void utc_location_location_manager_is_supported_method_p_02(void) { bool supported = FALSE; supported = location_manager_is_supported_method(LOCATIONS_METHOD_GPS); validate_eq(__func__, supported, TRUE); } static void utc_location_location_manager_is_supported_method_p_03(void) { bool supported = FALSE; supported = location_manager_is_supported_method(LOCATIONS_METHOD_WPS); validate_eq(__func__, supported, TRUE); } static void utc_location_location_manager_is_supported_method_p_04(void) { bool supported = FALSE; supported = location_manager_is_supported_method(LOCATIONS_METHOD_CPS); validate_eq(__func__, supported, TRUE); } static void utc_location_location_manager_is_supported_method_n(void) { bool supported = FALSE; supported = location_manager_is_supported_method(LOCATIONS_METHOD_NONE); validate_eq(__func__, supported, FALSE); } static void utc_location_location_manager_is_supported_method_n_02(void) { bool supported = FALSE; supported = location_manager_is_supported_method(LOCATIONS_METHOD_CPS + 1); validate_eq(__func__, supported, FALSE); } static void utc_location_location_manager_send_command_p(void) { int ret = LOCATIONS_ERROR_NONE; const *str = "command"; ret = location_manager_send_command(str); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_send_command_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_send_command(NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_destroy_p(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_destroy(manager); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_location_manager_destroy_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = location_manager_destroy(NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_location_manager_destroy_n_02(void) { int ret = LOCATIONS_ERROR_NONE; location_manager_h manager_02; ret = location_manager_destroy(manager_02); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); }
tizenorg/framework.api.location-manager
TC/testcase/utc_location_gps_status.c
<filename>TC/testcase/utc_location_gps_status.c /* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <tet_api.h> #include <locations.h> #include <glib.h> enum { POSITIVE_TC_IDX = 0x01, NEGATIVE_TC_IDX, }; static void startup(void); static void cleanup(void); void (*tet_startup) (void) = startup; void (*tet_cleanup) (void) = cleanup; static void utc_location_gps_status_get_nmea_p(void); static void utc_location_gps_status_get_nmea_n(void); static void utc_location_gps_status_get_nmea_n_02(void); static void utc_location_gps_status_get_nmea_n_03(void); static void utc_location_gps_status_get_satellite_p(void); static void utc_location_gps_status_get_satellite_n(void); static void utc_location_gps_status_get_satellite_n_02(void); static void utc_location_gps_status_get_satellite_n_03(void); static void utc_location_gps_status_get_satellite_n_04(void); static void utc_location_gps_status_get_satellite_n_05(void); static void utc_location_gps_status_get_satellite_n_06(void); static void utc_location_gps_status_foreach_satellites_in_view_p(void); static void utc_location_gps_status_foreach_satellites_in_view_n(void); static void utc_location_gps_status_foreach_satellites_in_view_n_02(void); static void utc_location_gps_status_foreach_satellites_in_view_n_03(void); static void utc_location_gps_status_foreach_last_satellites_in_view_p(void); static void utc_location_gps_status_foreach_last_satellites_in_view_n(void); static void utc_location_gps_status_foreach_last_satellites_in_view_n_02(void); static void utc_location_gps_status_get_last_satellite_p(void); static void utc_location_gps_status_get_last_satellite_n(void); static void utc_location_gps_status_get_last_satellite_n_02(void); static void utc_location_gps_status_get_last_satellite_n_03(void); static void utc_location_gps_status_get_last_satellite_n_04(void); struct tet_testlist tet_testlist[] = { {utc_location_gps_status_get_nmea_p, POSITIVE_TC_IDX}, {utc_location_gps_status_get_nmea_n, NEGATIVE_TC_IDX}, {utc_location_gps_status_get_nmea_n_02, NEGATIVE_TC_IDX}, // {utc_location_gps_status_get_nmea_n_03, NEGATIVE_TC_IDX}, //Can't check created location_manager_h {utc_location_gps_status_get_satellite_p, POSITIVE_TC_IDX}, {utc_location_gps_status_get_satellite_n, NEGATIVE_TC_IDX}, {utc_location_gps_status_get_satellite_n_02, NEGATIVE_TC_IDX}, // {utc_location_gps_status_get_satellite_n_03, NEGATIVE_TC_IDX}, //Can't check created location_manager_h {utc_location_gps_status_get_satellite_n_04, NEGATIVE_TC_IDX}, {utc_location_gps_status_get_satellite_n_05, NEGATIVE_TC_IDX}, {utc_location_gps_status_get_satellite_n_06, NEGATIVE_TC_IDX}, {utc_location_gps_status_foreach_satellites_in_view_p, POSITIVE_TC_IDX}, {utc_location_gps_status_foreach_satellites_in_view_n, NEGATIVE_TC_IDX}, {utc_location_gps_status_foreach_satellites_in_view_n_02, NEGATIVE_TC_IDX}, // {utc_location_gps_status_foreach_satellites_in_view_n_03, NEGATIVE_TC_IDX }, //Can't check created location_manager_h {utc_location_gps_status_foreach_last_satellites_in_view_p, POSITIVE_TC_IDX}, {utc_location_gps_status_foreach_last_satellites_in_view_n, NEGATIVE_TC_IDX}, {utc_location_gps_status_foreach_last_satellites_in_view_n_02, NEGATIVE_TC_IDX}, {utc_location_gps_status_get_last_satellite_p, POSITIVE_TC_IDX}, {utc_location_gps_status_get_last_satellite_n, NEGATIVE_TC_IDX}, {utc_location_gps_status_get_last_satellite_n_02, NEGATIVE_TC_IDX}, {utc_location_gps_status_get_last_satellite_n_03, NEGATIVE_TC_IDX}, {utc_location_gps_status_get_last_satellite_n_04, NEGATIVE_TC_IDX}, {NULL, 0}, }; static GMainLoop *g_mainloop = NULL; static GThread *event_thread; gpointer GmainThread(gpointer data) { g_mainloop = g_main_loop_new(NULL, 0); g_main_loop_run(g_mainloop); return NULL; } static bool service_enabled = false; static void validate_and_next(char *api_name, int act_ret, int ext_ret, char *fail_msg) { dts_message(api_name, "Actual Result : %d, Expected Result : %d", act_ret, ext_ret); if (act_ret != ext_ret) { dts_message(api_name, "Fail Message: %s", fail_msg); dts_fail(api_name); } } static void validate_eq(char *api_name, int act_ret, int ext_ret) { dts_message(api_name, "Actual Result : %d, Expected Result : %d", act_ret, ext_ret); if (act_ret == ext_ret) { dts_pass(api_name); } else { dts_fail(api_name); } } static void unprepare(location_manager_h manager) { location_manager_unset_service_state_changed_cb(manager); location_manager_destroy(manager); service_enabled = false; } static void wait_for_service(char *api_name) { int timeout = 0; for (timeout; timeout < 30; timeout++) { if (service_enabled) { dts_message(api_name, "Location Service Enabled!!!!"); break; } else { dts_message(api_name, "Location Service Disabled!!!!"); sleep(1); } } } static void capi_state_changed_cb(location_service_state_e state, void *user_data) { switch (state) { case LOCATIONS_SERVICE_ENABLED: service_enabled = true; break; case LOCATIONS_SERVICE_DISABLED: service_enabled = false; break; default: break; } } static location_manager_h manager; static void startup(void) { g_setenv("PKG_NAME", "com.samsung.capi-location-gps-status-test", 1); g_setenv("LOCATION_TEST_ENABLE", "1", 1); #if !GLIB_CHECK_VERSION (2, 31, 0) if (!g_thread_supported()) { g_thread_init(NULL); } #endif GError *gerr = NULL; event_thread = g_thread_create(GmainThread, NULL, 1, &gerr); int ret; ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_create() is failed"); /* You don't need it ret = location_manager_set_service_state_changed_cb(manager, capi_state_changed_cb, NULL); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_set_service_state_changed_cb() is failed"); */ ret = location_manager_start(manager); validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_start() is failed"); wait_for_service(__func__); } static void cleanup(void) { unprepare(manager); g_main_loop_quit(g_mainloop); g_thread_join(event_thread); } static void utc_location_gps_status_get_nmea_p(void) { int ret = LOCATIONS_ERROR_NONE; char *nmea; ret = gps_status_get_nmea(manager, &nmea); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_gps_status_get_nmea_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = gps_status_get_nmea(manager, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_gps_status_get_nmea_n_02(void) { int ret = LOCATIONS_ERROR_NONE; char *nmea; ret = gps_status_get_nmea(NULL, &nmea); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_gps_status_get_nmea_n_03(void) { int ret = LOCATIONS_ERROR_NONE; char *nmea; location_manager_h manager_02; ret = gps_status_get_nmea(manager_02, &nmea); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_gps_status_get_satellite_p(void) { int ret = LOCATIONS_ERROR_NONE; int num_of_active, num_of_inview; time_t timestamp; ret = gps_status_get_satellite(manager, &num_of_active, &num_of_inview, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_gps_status_get_satellite_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = gps_status_get_satellite(manager, NULL, NULL, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_gps_status_get_satellite_n_02(void) { int ret = LOCATIONS_ERROR_NONE; int num_of_active, num_of_inview; time_t timestamp; ret = gps_status_get_satellite(NULL, &num_of_active, &num_of_inview, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_gps_status_get_satellite_n_03(void) { int ret = LOCATIONS_ERROR_NONE; int num_of_active, num_of_inview; time_t timestamp; location_manager_h manager_02; ret = gps_status_get_satellite(manager_02, &num_of_active, &num_of_inview, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_gps_status_get_satellite_n_04(void) { int ret = LOCATIONS_ERROR_NONE; int num_of_inview; time_t timestamp; ret = gps_status_get_satellite(manager, NULL, &num_of_inview, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_gps_status_get_satellite_n_05(void) { int ret = LOCATIONS_ERROR_NONE; int num_of_active; time_t timestamp; ret = gps_status_get_satellite(manager, &num_of_active, NULL, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_gps_status_get_satellite_n_06(void) { int ret = LOCATIONS_ERROR_NONE; int num_of_active, num_of_inview; ret = gps_status_get_satellite(manager, &num_of_active, &num_of_inview, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static bool capi_gps_status_get_satellites_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_in_use, void *user_data) { return true; } static void utc_location_gps_status_foreach_satellites_in_view_p(void) { int ret = LOCATIONS_ERROR_NONE; ret = gps_status_foreach_satellites_in_view(manager, capi_gps_status_get_satellites_cb, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_gps_status_foreach_satellites_in_view_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = gps_status_foreach_satellites_in_view(manager, NULL, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_gps_status_foreach_satellites_in_view_n_02(void) { int ret = LOCATIONS_ERROR_NONE; ret = gps_status_foreach_satellites_in_view(NULL, capi_gps_status_get_satellites_cb, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_gps_status_foreach_satellites_in_view_n_03(void) { int ret = LOCATIONS_ERROR_NONE; location_manager_h manager_02; ret = gps_status_foreach_satellites_in_view(manager_02, capi_gps_status_get_satellites_cb, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static bool capi_last_satellites_foreach_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_in_use, void *user_data) { printf("[Last Satellite information] azimuth : %d, elevation : %d, prn :%d, snr : %d, used: %d\n", azimuth, elevation, prn, snr, is_in_use); return true; } static void utc_location_gps_status_foreach_last_satellites_in_view_p(void) { int ret = LOCATIONS_ERROR_NONE; ret = gps_status_foreach_last_satellites_in_view(manager, capi_last_satellites_foreach_cb, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_gps_status_foreach_last_satellites_in_view_n(void) { int ret = LOCATIONS_ERROR_NONE; ret = gps_status_foreach_last_satellites_in_view(manager, NULL, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_gps_status_foreach_last_satellites_in_view_n_02(void) { int ret = LOCATIONS_ERROR_NONE; ret = gps_status_foreach_last_satellites_in_view(NULL, capi_last_satellites_foreach_cb, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_gps_status_get_last_satellite_p(void) { int ret = LOCATIONS_ERROR_NONE; time_t timestamp; int num_of_inview, num_of_active; ret = gps_status_get_last_satellite(manager, &num_of_active, &num_of_inview, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_NONE); } static void utc_location_gps_status_get_last_satellite_n(void) { int ret = LOCATIONS_ERROR_NONE; time_t timestamp; int num_of_inview, num_of_active; ret = gps_status_get_last_satellite(NULL, &num_of_active, &num_of_inview, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_gps_status_get_last_satellite_n_02(void) { int ret = LOCATIONS_ERROR_NONE; time_t timestamp; int num_of_inview; ret = gps_status_get_last_satellite(manager, NULL, &num_of_inview, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_gps_status_get_last_satellite_n_03(void) { int ret = LOCATIONS_ERROR_NONE; time_t timestamp; int num_of_active; ret = gps_status_get_last_satellite(manager, &num_of_active, NULL, &timestamp); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); } static void utc_location_gps_status_get_last_satellite_n_04(void) { int ret = LOCATIONS_ERROR_NONE; int num_of_inview, num_of_active; ret = gps_status_get_last_satellite(manager, &num_of_active, &num_of_inview, NULL); validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER); }
Neo-Desktop/bare-metal-pi
src/includes/kernel/util.h
/** arm-016-util.h */ #ifndef RPI_UTIL_H #define RPI_UTIL_H #define SCREEN_WIDTH 640 #define SCREEN_HEIGHT 480 #define SCREEN_DEPTH 24 /* 16 or 32-bit */ #define COLOUR_DELTA 0.05 /* Float from 0 to 1 incremented by this amount */ #include <math.h> #include <stdlib.h> typedef struct { float r; float g; float b; float a; } colour_t; extern void setColor(volatile unsigned char* fb, colour_t pixel, long x, long y, long pitch); extern int * getCoordinates(); extern double scale_to_x_origin(int); extern int scale_to_y_pixel(double); #endif
Neo-Desktop/bare-metal-pi
src/includes/kernel/util.c
<filename>src/includes/kernel/util.c /** util.c */ #include "util.h" void setColor(volatile unsigned char* fb, colour_t pixel, long x, long y, long pitch) { int pixel_offset = ( x * ( SCREEN_DEPTH >> 3 ) ) + ( y * pitch ); int r = (int)( pixel.r * 0xFF ) & 0xFF; int g = (int)( pixel.g * 0xFF ) & 0xFF; int b = (int)( pixel.b * 0xFF ) & 0xFF; int a = (int)( pixel.a * 0xFF ) & 0xFF; if( SCREEN_DEPTH == 32 ) { /* Four bytes to write */ fb[ pixel_offset++ ] = r; fb[ pixel_offset++ ] = g; fb[ pixel_offset++ ] = b; fb[ pixel_offset++ ] = a; } else if( SCREEN_DEPTH == 24 ) { /* Three bytes to write */ fb[ pixel_offset++ ] = r; fb[ pixel_offset++ ] = g; fb[ pixel_offset++ ] = b; } else if( SCREEN_DEPTH == 16 ) { /* Two bytes to write */ /* Bit pack RGB565 into the 16-bit pixel offset */ *(unsigned short*)&fb[pixel_offset] = ( (r >> 3) << 11 ) | ( ( g >> 2 ) << 5 ) | ( b >> 3 ); } else { /* Palette mode. TODO: Work out a colour scheme for packing rgb into an 8-bit palette! */ } } // Takes a computed sin value and finds what pixel it cooresponds to int scale_to_y_pixel(double y) { return (int) ((SCREEN_HEIGHT / 2) * (1 - y)); } // Takes a horizontal pixel location and finds where it would be in a normal graph 0 < t < 2pi double scale_to_x_origin(int x) { return x * 2 * M_PI / SCREEN_WIDTH; } // Returns the coordinates of the sin function. sin[x] = y coordinate on the horizontal pixel x. int *getCoordinates() { int x = 0; int *yCords = (int*) malloc(sizeof(int) * SCREEN_WIDTH); memset(yCords, 0, SCREEN_WIDTH); for (x = 0; x < SCREEN_WIDTH; ++x) { double float_x = scale_to_x_origin(x); yCords[x] = scale_to_y_pixel(sin(float_x)); } return yCords; }
OwenGranot/Anomaly-Detector
anomaly_detection_util.h
// Returns the variance of X and Y float var(float* x, int size); // Returns the Covariance of X and Y float cov(float* x, float* y, int size); // Returns the Pearson correlation coeffiecient of X and Y float pearson(float* x, float* y, int size); class Line{ public: const float a,b; Line(float a, float b):a(a),b(b) {} float f(float x) { return a*x+b; } }; class Point { public: const float x,y; Point(float x, float y):x(x),y(y){} }; // Performs a linear regression and returns the line equation Line linear_reg(Point** points, int size); // Returns the deviation between point p and the line equation of the points. float dev(Point p, Point** points, int size); // Returns the deviation between point p and the line float dev(Point p, Line l);
Erik-Koning/Arduino_Core_STM32
variants/Generic_L151C8x/PinNamesVar.h
/* SYS_WKUP */ #ifdef PWR_WAKEUP_PIN1 SYS_WKUP1 = PA_0, #endif #ifdef PWR_WAKEUP_PIN2 SYS_WKUP2 = PC_13, #endif #ifdef PWR_WAKEUP_PIN3 SYS_WKUP3 = NC, #endif #ifdef PWR_WAKEUP_PIN4 SYS_WKUP4 = NC, #endif #ifdef PWR_WAKEUP_PIN5 SYS_WKUP5 = NC, #endif #ifdef PWR_WAKEUP_PIN6 SYS_WKUP6 = NC, #endif #ifdef PWR_WAKEUP_PIN7 SYS_WKUP7 = NC, #endif #ifdef PWR_WAKEUP_PIN8 SYS_WKUP8 = NC, #endif /* USB */ #ifdef USBCON USB_DM = PA_11, USB_DP = PA_12, #endif
friniax/Practica01
Main.c
#include <stdio.h> int main () { int aux,a,b,c; int n=10,Arr[n]; for (a=0; a<n; a++) { printf("dame el dato numero: %d \n",a+1); printf("dame el dato numero: %d \n",a+1); scanf("%d",&Arr); } for (a=0;a<n;a++) { for (b=0;b<n-a;b++) { if (Arr[b]>=Arr[b+1]) { aux=Arr[b]; Arr[b]=Arr[b+1]; Arr[b+1]=aux; } } } for (c=0;c<n;c++) { printf(" %d",Arr[c]); } return 0; }
schmitzn/node-packer
node/deps/icu-small/source/common/hash.h
<reponame>schmitzn/node-packer<gh_stars>1000+ // © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ****************************************************************************** * Copyright (C) 1997-2014, International Business Machines * Corporation and others. All Rights Reserved. ****************************************************************************** * Date Name Description * 03/28/00 aliu Creation. ****************************************************************************** */ #ifndef HASH_H #define HASH_H #include "unicode/unistr.h" #include "unicode/uobject.h" #include "cmemory.h" #include "uhash.h" U_NAMESPACE_BEGIN /** * Hashtable is a thin C++ wrapper around UHashtable, a general-purpose void* * hashtable implemented in C. Hashtable is designed to be idiomatic and * easy-to-use in C++. * * Hashtable is an INTERNAL CLASS. */ class U_COMMON_API Hashtable : public UMemory { UHashtable* hash; UHashtable hashObj; inline void init(UHashFunction *keyHash, UKeyComparator *keyComp, UValueComparator *valueComp, UErrorCode& status); inline void initSize(UHashFunction *keyHash, UKeyComparator *keyComp, UValueComparator *valueComp, int32_t size, UErrorCode& status); public: /** * Construct a hashtable * @param ignoreKeyCase If true, keys are case insensitive. * @param status Error code */ inline Hashtable(UBool ignoreKeyCase, UErrorCode& status); /** * Construct a hashtable * @param ignoreKeyCase If true, keys are case insensitive. * @param size initial size allocation * @param status Error code */ inline Hashtable(UBool ignoreKeyCase, int32_t size, UErrorCode& status); /** * Construct a hashtable * @param keyComp Comparator for comparing the keys * @param valueComp Comparator for comparing the values * @param status Error code */ inline Hashtable(UKeyComparator *keyComp, UValueComparator *valueComp, UErrorCode& status); /** * Construct a hashtable * @param status Error code */ inline Hashtable(UErrorCode& status); /** * Construct a hashtable, _disregarding any error_. Use this constructor * with caution. */ inline Hashtable(); /** * Non-virtual destructor; make this virtual if Hashtable is subclassed * in the future. */ inline ~Hashtable(); inline UObjectDeleter *setValueDeleter(UObjectDeleter *fn); inline int32_t count() const; inline void* put(const UnicodeString& key, void* value, UErrorCode& status); inline int32_t puti(const UnicodeString& key, int32_t value, UErrorCode& status); inline void* get(const UnicodeString& key) const; inline int32_t geti(const UnicodeString& key) const; inline void* remove(const UnicodeString& key); inline int32_t removei(const UnicodeString& key); inline void removeAll(void); inline const UHashElement* find(const UnicodeString& key) const; /** * @param pos - must be UHASH_FIRST on first call, and untouched afterwards. * @see uhash_nextElement */ inline const UHashElement* nextElement(int32_t& pos) const; inline UKeyComparator* setKeyComparator(UKeyComparator*keyComp); inline UValueComparator* setValueComparator(UValueComparator* valueComp); inline UBool equals(const Hashtable& that) const; private: Hashtable(const Hashtable &other); // forbid copying of this class Hashtable &operator=(const Hashtable &other); // forbid copying of this class }; /********************************************************************* * Implementation ********************************************************************/ inline void Hashtable::init(UHashFunction *keyHash, UKeyComparator *keyComp, UValueComparator *valueComp, UErrorCode& status) { if (U_FAILURE(status)) { return; } uhash_init(&hashObj, keyHash, keyComp, valueComp, &status); if (U_SUCCESS(status)) { hash = &hashObj; uhash_setKeyDeleter(hash, uprv_deleteUObject); } } inline void Hashtable::initSize(UHashFunction *keyHash, UKeyComparator *keyComp, UValueComparator *valueComp, int32_t size, UErrorCode& status) { if (U_FAILURE(status)) { return; } uhash_initSize(&hashObj, keyHash, keyComp, valueComp, size, &status); if (U_SUCCESS(status)) { hash = &hashObj; uhash_setKeyDeleter(hash, uprv_deleteUObject); } } inline Hashtable::Hashtable(UKeyComparator *keyComp, UValueComparator *valueComp, UErrorCode& status) : hash(0) { init( uhash_hashUnicodeString, keyComp, valueComp, status); } inline Hashtable::Hashtable(UBool ignoreKeyCase, UErrorCode& status) : hash(0) { init(ignoreKeyCase ? uhash_hashCaselessUnicodeString : uhash_hashUnicodeString, ignoreKeyCase ? uhash_compareCaselessUnicodeString : uhash_compareUnicodeString, NULL, status); } inline Hashtable::Hashtable(UBool ignoreKeyCase, int32_t size, UErrorCode& status) : hash(0) { initSize(ignoreKeyCase ? uhash_hashCaselessUnicodeString : uhash_hashUnicodeString, ignoreKeyCase ? uhash_compareCaselessUnicodeString : uhash_compareUnicodeString, NULL, size, status); } inline Hashtable::Hashtable(UErrorCode& status) : hash(0) { init(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, status); } inline Hashtable::Hashtable() : hash(0) { UErrorCode status = U_ZERO_ERROR; init(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, status); } inline Hashtable::~Hashtable() { if (hash != NULL) { uhash_close(hash); } } inline UObjectDeleter *Hashtable::setValueDeleter(UObjectDeleter *fn) { return uhash_setValueDeleter(hash, fn); } inline int32_t Hashtable::count() const { return uhash_count(hash); } inline void* Hashtable::put(const UnicodeString& key, void* value, UErrorCode& status) { return uhash_put(hash, new UnicodeString(key), value, &status); } inline int32_t Hashtable::puti(const UnicodeString& key, int32_t value, UErrorCode& status) { return uhash_puti(hash, new UnicodeString(key), value, &status); } inline void* Hashtable::get(const UnicodeString& key) const { return uhash_get(hash, &key); } inline int32_t Hashtable::geti(const UnicodeString& key) const { return uhash_geti(hash, &key); } inline void* Hashtable::remove(const UnicodeString& key) { return uhash_remove(hash, &key); } inline int32_t Hashtable::removei(const UnicodeString& key) { return uhash_removei(hash, &key); } inline const UHashElement* Hashtable::find(const UnicodeString& key) const { return uhash_find(hash, &key); } inline const UHashElement* Hashtable::nextElement(int32_t& pos) const { return uhash_nextElement(hash, &pos); } inline void Hashtable::removeAll(void) { uhash_removeAll(hash); } inline UKeyComparator* Hashtable::setKeyComparator(UKeyComparator*keyComp){ return uhash_setKeyComparator(hash, keyComp); } inline UValueComparator* Hashtable::setValueComparator(UValueComparator* valueComp){ return uhash_setValueComparator(hash, valueComp); } inline UBool Hashtable::equals(const Hashtable& that)const{ return uhash_equals(hash, that.hash); } U_NAMESPACE_END #endif
schmitzn/node-packer
node/deps/libautoupdate/tests/main.c
<filename>node/deps/libautoupdate/tests/main.c /* * Copyright (c) 2017 <NAME> <<EMAIL>> * * This file is part of libautoupdate, distributed under the MIT License * For full terms see the included LICENSE file */ #include "autoupdate.h" #include "autoupdate_internal.h" #include <limits.h> #include <assert.h> #include <sys/stat.h> #include <stdint.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef _WIN32 #include <Windows.h> #include <wchar.h> #endif #ifdef __linux__ #include <linux/limits.h> #endif #define EXPECT(condition) expect(condition, __FILE__, __LINE__) static void expect(short condition, const char *file, int line) { if (condition) { fprintf(stderr, "."); } else { fprintf(stderr, "x"); fprintf(stderr, "\nFAILED: %s line %d\n", file, line); exit(1); } fflush(stderr); } #ifdef _WIN32 int main(int argc, wchar_t *wargv[]) #else int main(int argc, char *argv[]) #endif { int ret; struct stat statbuf; size_t exec_path_len; char* exec_path; // test autoupdate_exepath #ifdef _WIN32 exec_path_len = 2 * MAX_PATH; #else exec_path_len = 2 * PATH_MAX; #endif exec_path = malloc(exec_path_len); ret = autoupdate_exepath(exec_path, &exec_path_len); EXPECT(0 == ret); ret = stat(exec_path, &statbuf); EXPECT(0 == ret); EXPECT(S_IFREG == (S_IFMT & statbuf.st_mode)); // test autoupdate_should_proceed() autoupdate_should_proceed(); // test autoupdate_should_proceed_24_hours() #ifdef _WIN32 autoupdate_should_proceed_24_hours(argc, wargv, 0); autoupdate_should_proceed_24_hours(argc, wargv, 1); autoupdate_should_proceed_24_hours(argc, wargv, 0); autoupdate_should_proceed_24_hours(argc, wargv, 1); #else autoupdate_should_proceed_24_hours(argc, argv, 0); autoupdate_should_proceed_24_hours(argc, argv, 1); autoupdate_should_proceed_24_hours(argc, argv, 0); autoupdate_should_proceed_24_hours(argc, argv, 1); #endif // test autoupdate() #ifdef _WIN32 autoupdate( argc, wargv, "enclose.io", "80", "/rubyc/rubyc-x64.zip", "---^_^---", 1 ); #endif #ifdef __linux__ autoupdate( argc, argv, "enclose.io", 80, "/rubyc/rubyc-linux-x64.gz", "---^_^---", 1 ); #endif #ifdef __APPLE__ autoupdate( argc, argv, "enclose.io", 80, "/rubyc/rubyc-darwin-x64.gz", "---^_^---", 1 ); #endif // should never reach this point return 1; }
schmitzn/node-packer
node/deps/icu-small/source/i18n/unicode/numsys.h
<filename>node/deps/icu-small/source/i18n/unicode/numsys.h<gh_stars>1-10 // © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* * Copyright (C) 2010-2014, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************************* * * * File NUMSYS.H * * Modification History:* * Date Name Description * ******************************************************************************** */ #ifndef NUMSYS #define NUMSYS #include "unicode/utypes.h" /** * \file * \brief C++ API: NumberingSystem object */ #if !UCONFIG_NO_FORMATTING #include "unicode/format.h" #include "unicode/uobject.h" U_NAMESPACE_BEGIN // can't be #ifndef U_HIDE_INTERNAL_API; needed for char[] field size /** * Size of a numbering system name. * @internal */ constexpr const size_t kInternalNumSysNameCapacity = 8; /** * Defines numbering systems. A numbering system describes the scheme by which * numbers are to be presented to the end user. In its simplest form, a numbering * system describes the set of digit characters that are to be used to display * numbers, such as Western digits, Thai digits, Arabic-Indic digits, etc., in a * positional numbering system with a specified radix (typically 10). * More complicated numbering systems are algorithmic in nature, and require use * of an RBNF formatter ( rule based number formatter ), in order to calculate * the characters to be displayed for a given number. Examples of algorithmic * numbering systems include Roman numerals, Chinese numerals, and Hebrew numerals. * Formatting rules for many commonly used numbering systems are included in * the ICU package, based on the numbering system rules defined in CLDR. * Alternate numbering systems can be specified to a locale by using the * numbers locale keyword. */ class U_I18N_API NumberingSystem : public UObject { public: /** * Default Constructor. * * @stable ICU 4.2 */ NumberingSystem(); /** * Copy constructor. * @stable ICU 4.2 */ NumberingSystem(const NumberingSystem& other); /** * Destructor. * @stable ICU 4.2 */ virtual ~NumberingSystem(); /** * Create the default numbering system associated with the specified locale. * @param inLocale The given locale. * @param status ICU status * @stable ICU 4.2 */ static NumberingSystem* U_EXPORT2 createInstance(const Locale & inLocale, UErrorCode& status); /** * Create the default numbering system associated with the default locale. * @stable ICU 4.2 */ static NumberingSystem* U_EXPORT2 createInstance(UErrorCode& status); /** * Create a numbering system using the specified radix, type, and description. * @param radix The radix (base) for this numbering system. * @param isAlgorithmic TRUE if the numbering system is algorithmic rather than numeric. * @param description The string representing the set of digits used in a numeric system, or the name of the RBNF * ruleset to be used in an algorithmic system. * @param status ICU status * @stable ICU 4.2 */ static NumberingSystem* U_EXPORT2 createInstance(int32_t radix, UBool isAlgorithmic, const UnicodeString& description, UErrorCode& status ); /** * Return a StringEnumeration over all the names of numbering systems known to ICU. * The numbering system names will be in alphabetical (invariant) order. * * The returned StringEnumeration is owned by the caller, who must delete it when * finished with it. * * @stable ICU 4.2 */ static StringEnumeration * U_EXPORT2 getAvailableNames(UErrorCode& status); /** * Create a numbering system from one of the predefined numbering systems specified * by CLDR and known to ICU, such as "latn", "arabext", or "hanidec"; the full list * is returned by unumsys_openAvailableNames. Note that some of the names listed at * http://unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml - e.g. * default, native, traditional, finance - do not identify specific numbering systems, * but rather key values that may only be used as part of a locale, which in turn * defines how they are mapped to a specific numbering system such as "latn" or "hant". * * @param name The name of the numbering system. * @param status ICU status; set to U_UNSUPPORTED_ERROR if numbering system not found. * @return The NumberingSystem instance, or nullptr if not found. * @stable ICU 4.2 */ static NumberingSystem* U_EXPORT2 createInstanceByName(const char* name, UErrorCode& status); /** * Returns the radix of this numbering system. Simple positional numbering systems * typically have radix 10, but might have a radix of e.g. 16 for hexadecimal. The * radix is less well-defined for non-positional algorithmic systems. * @stable ICU 4.2 */ int32_t getRadix() const; /** * Returns the name of this numbering system if it was created using one of the predefined names * known to ICU. Otherwise, returns NULL. * The predefined names are identical to the numbering system names as defined by * the BCP47 definition in Unicode CLDR. * See also, http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml * @stable ICU 4.6 */ const char * getName() const; /** * Returns the description string of this numbering system. For simple * positional systems this is the ordered string of digits (with length matching * the radix), e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D" * for "hanidec"; it would be "0123456789ABCDEF" for hexadecimal. For * algorithmic systems this is the name of the RBNF ruleset used for formatting, * e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for * "grek". * @stable ICU 4.2 */ virtual UnicodeString getDescription() const; /** * Returns TRUE if the given numbering system is algorithmic * * @return TRUE if the numbering system is algorithmic. * Otherwise, return FALSE. * @stable ICU 4.2 */ UBool isAlgorithmic() const; /** * ICU "poor man's RTTI", returns a UClassID for this class. * * @stable ICU 4.2 * */ static UClassID U_EXPORT2 getStaticClassID(void); /** * ICU "poor man's RTTI", returns a UClassID for the actual class. * * @stable ICU 4.2 */ virtual UClassID getDynamicClassID() const; private: UnicodeString desc; int32_t radix; UBool algorithmic; char name[kInternalNumSysNameCapacity+1]; void setRadix(int32_t radix); void setAlgorithmic(UBool algorithmic); void setDesc(const UnicodeString &desc); void setName(const char* name); static UBool isValidDigitString(const UnicodeString &str); UBool hasContiguousDecimalDigits() const; }; U_NAMESPACE_END #endif /* #if !UCONFIG_NO_FORMATTING */ #endif // _NUMSYS //eof
schmitzn/node-packer
node/deps/icu-small/source/i18n/numparse_affixes.h
// © 2018 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html #include "unicode/utypes.h" #if !UCONFIG_NO_FORMATTING #ifndef __NUMPARSE_AFFIXES_H__ #define __NUMPARSE_AFFIXES_H__ #include "cmemory.h" #include "numparse_types.h" #include "numparse_symbols.h" #include "numparse_currency.h" #include "number_affixutils.h" #include "number_currencysymbols.h" U_NAMESPACE_BEGIN namespace numparse { namespace impl { // Forward-declaration of implementation classes for friending class AffixPatternMatcherBuilder; class AffixPatternMatcher; using ::icu::number::impl::AffixPatternProvider; using ::icu::number::impl::TokenConsumer; using ::icu::number::impl::CurrencySymbols; class CodePointMatcher : public NumberParseMatcher, public UMemory { public: CodePointMatcher() = default; // WARNING: Leaves the object in an unusable state CodePointMatcher(UChar32 cp); bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override; bool smokeTest(const StringSegment& segment) const override; UnicodeString toString() const override; private: UChar32 fCp; }; } // namespace impl } // namespace numparse // Export a explicit template instantiations of MaybeStackArray, MemoryPool and CompactUnicodeString. // When building DLLs for Windows this is required even though no direct access leaks out of the i18n library. // (See digitlst.h, pluralaffix.h, datefmt.h, and others for similar examples.) // Note: These need to be outside of the numparse::impl namespace, or Clang will generate a compile error. #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN template class U_I18N_API MaybeStackArray<numparse::impl::CodePointMatcher*, 8>; template class U_I18N_API MaybeStackArray<UChar, 4>; template class U_I18N_API MemoryPool<numparse::impl::CodePointMatcher, 8>; template class U_I18N_API numparse::impl::CompactUnicodeString<4>; #endif namespace numparse { namespace impl { struct AffixTokenMatcherSetupData { const CurrencySymbols& currencySymbols; const DecimalFormatSymbols& dfs; IgnorablesMatcher& ignorables; const Locale& locale; parse_flags_t parseFlags; }; /** * Small helper class that generates matchers for individual tokens for AffixPatternMatcher. * * In Java, this is called AffixTokenMatcherFactory (a "factory"). However, in C++, it is called a * "warehouse", because in addition to generating the matchers, it also retains ownership of them. The * warehouse must stay in scope for the whole lifespan of the AffixPatternMatcher that uses matchers from * the warehouse. * * @author sffc */ // Exported as U_I18N_API for tests class U_I18N_API AffixTokenMatcherWarehouse : public UMemory { public: AffixTokenMatcherWarehouse() = default; // WARNING: Leaves the object in an unusable state AffixTokenMatcherWarehouse(const AffixTokenMatcherSetupData* setupData); NumberParseMatcher& minusSign(); NumberParseMatcher& plusSign(); NumberParseMatcher& percent(); NumberParseMatcher& permille(); NumberParseMatcher& currency(UErrorCode& status); IgnorablesMatcher& ignorables(); NumberParseMatcher* nextCodePointMatcher(UChar32 cp, UErrorCode& status); private: // NOTE: The following field may be unsafe to access after construction is done! const AffixTokenMatcherSetupData* fSetupData; // NOTE: These are default-constructed and should not be used until initialized. MinusSignMatcher fMinusSign; PlusSignMatcher fPlusSign; PercentMatcher fPercent; PermilleMatcher fPermille; CombinedCurrencyMatcher fCurrency; // Use a child class for code point matchers, since it requires non-default operators. MemoryPool<CodePointMatcher> fCodePoints; friend class AffixPatternMatcherBuilder; friend class AffixPatternMatcher; }; class AffixPatternMatcherBuilder : public TokenConsumer, public MutableMatcherCollection { public: AffixPatternMatcherBuilder(const UnicodeString& pattern, AffixTokenMatcherWarehouse& warehouse, IgnorablesMatcher* ignorables); void consumeToken(::icu::number::impl::AffixPatternType type, UChar32 cp, UErrorCode& status) override; /** NOTE: You can build only once! */ AffixPatternMatcher build(); private: ArraySeriesMatcher::MatcherArray fMatchers; int32_t fMatchersLen; int32_t fLastTypeOrCp; const UnicodeString& fPattern; AffixTokenMatcherWarehouse& fWarehouse; IgnorablesMatcher* fIgnorables; void addMatcher(NumberParseMatcher& matcher) override; }; // Exported as U_I18N_API for tests class U_I18N_API AffixPatternMatcher : public ArraySeriesMatcher { public: AffixPatternMatcher() = default; // WARNING: Leaves the object in an unusable state static AffixPatternMatcher fromAffixPattern(const UnicodeString& affixPattern, AffixTokenMatcherWarehouse& warehouse, parse_flags_t parseFlags, bool* success, UErrorCode& status); UnicodeString getPattern() const; bool operator==(const AffixPatternMatcher& other) const; private: CompactUnicodeString<4> fPattern; AffixPatternMatcher(MatcherArray& matchers, int32_t matchersLen, const UnicodeString& pattern); friend class AffixPatternMatcherBuilder; }; class AffixMatcher : public NumberParseMatcher, public UMemory { public: AffixMatcher() = default; // WARNING: Leaves the object in an unusable state AffixMatcher(AffixPatternMatcher* prefix, AffixPatternMatcher* suffix, result_flags_t flags); bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override; void postProcess(ParsedNumber& result) const override; bool smokeTest(const StringSegment& segment) const override; int8_t compareTo(const AffixMatcher& rhs) const; UnicodeString toString() const override; private: AffixPatternMatcher* fPrefix; AffixPatternMatcher* fSuffix; result_flags_t fFlags; }; /** * A C++-only class to retain ownership of the AffixMatchers needed for parsing. */ class AffixMatcherWarehouse { public: AffixMatcherWarehouse() = default; // WARNING: Leaves the object in an unusable state AffixMatcherWarehouse(AffixTokenMatcherWarehouse* tokenWarehouse); void createAffixMatchers(const AffixPatternProvider& patternInfo, MutableMatcherCollection& output, const IgnorablesMatcher& ignorables, parse_flags_t parseFlags, UErrorCode& status); private: // 9 is the limit: positive, zero, and negative, each with prefix, suffix, and prefix+suffix AffixMatcher fAffixMatchers[9]; // 6 is the limit: positive, zero, and negative, a prefix and a suffix for each AffixPatternMatcher fAffixPatternMatchers[6]; // Reference to the warehouse for tokens used by the AffixPatternMatchers AffixTokenMatcherWarehouse* fTokenWarehouse; friend class AffixMatcher; static bool isInteresting(const AffixPatternProvider& patternInfo, const IgnorablesMatcher& ignorables, parse_flags_t parseFlags, UErrorCode& status); }; } // namespace impl } // namespace numparse U_NAMESPACE_END #endif //__NUMPARSE_AFFIXES_H__ #endif /* #if !UCONFIG_NO_FORMATTING */
schmitzn/node-packer
node/deps/icu-small/source/common/unicode/localebuilder.h
<filename>node/deps/icu-small/source/common/unicode/localebuilder.h // © 2018 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html#License #ifndef __LOCALEBUILDER_H__ #define __LOCALEBUILDER_H__ #include "unicode/locid.h" #include "unicode/stringpiece.h" #include "unicode/uobject.h" #include "unicode/utypes.h" #ifndef U_HIDE_DRAFT_API /** * \file * \brief C++ API: Builder API for Locale */ U_NAMESPACE_BEGIN class CharString; /** * <code>LocaleBuilder</code> is used to build instances of <code>Locale</code> * from values configured by the setters. Unlike the <code>Locale</code> * constructors, the <code>LocaleBuilder</code> checks if a value configured by a * setter satisfies the syntax requirements defined by the <code>Locale</code> * class. A <code>Locale</code> object created by a <code>LocaleBuilder</code> is * well-formed and can be transformed to a well-formed IETF BCP 47 language tag * without losing information. * * <p>The following example shows how to create a <code>Locale</code> object * with the <code>LocaleBuilder</code>. * <blockquote> * <pre> * UErrorCode status = U_ZERO_ERROR; * Locale aLocale = LocaleBuilder() * .setLanguage("sr") * .setScript("Latn") * .setRegion("RS") * .build(status); * if (U_SUCCESS(status)) { * // ... * } * </pre> * </blockquote> * * <p>LocaleBuilders can be reused; <code>clear()</code> resets all * fields to their default values. * * <p>LocaleBuilder tracks errors in an internal UErrorCode. For all setters, * except setLanguageTag and setLocale, LocaleBuilder will return immediately * if the internal UErrorCode is in error state. * To reset internal state and error code, call clear method. * The setLanguageTag and setLocale method will first clear the internal * UErrorCode, then track the error of the validation of the input parameter * into the internal UErrorCode. * * @draft ICU 64 */ class U_COMMON_API LocaleBuilder : public UObject { public: /** * Constructs an empty LocaleBuilder. The default value of all * fields, extensions, and private use information is the * empty string. * * @draft ICU 64 */ LocaleBuilder(); /** * Destructor * @draft ICU 64 */ virtual ~LocaleBuilder(); /** * Resets the <code>LocaleBuilder</code> to match the provided * <code>locale</code>. Existing state is discarded. * * <p>All fields of the locale must be well-formed. * <p>This method clears the internal UErrorCode. * * @param locale the locale * @return This builder. * * @draft ICU 64 */ LocaleBuilder& setLocale(const Locale& locale); /** * Resets the LocaleBuilder to match the provided * [Unicode Locale Identifier](http://www.unicode.org/reports/tr35/tr35.html#unicode_locale_id) . * Discards the existing state. the empty string cause the builder to be * reset, like {@link #clear}. Grandfathered tags are converted to their * canonical form before being processed. Otherwise, the <code>language * tag</code> must be well-formed, or else the build() method will later * report an U_ILLEGAL_ARGUMENT_ERROR. * * <p>This method clears the internal UErrorCode. * * @param tag the language tag, defined as * [unicode_locale_id](http://www.unicode.org/reports/tr35/tr35.html#unicode_locale_id). * @return This builder. * @draft ICU 64 */ LocaleBuilder& setLanguageTag(StringPiece tag); /** * Sets the language. If <code>language</code> is the empty string, the * language in this <code>LocaleBuilder</code> is removed. Otherwise, the * <code>language</code> must be well-formed, or else the build() method will * later report an U_ILLEGAL_ARGUMENT_ERROR. * * <p>The syntax of language value is defined as * [unicode_language_subtag](http://www.unicode.org/reports/tr35/tr35.html#unicode_language_subtag). * * @param language the language * @return This builder. * @draft ICU 64 */ LocaleBuilder& setLanguage(StringPiece language); /** * Sets the script. If <code>script</code> is the empty string, the script in * this <code>LocaleBuilder</code> is removed. * Otherwise, the <code>script</code> must be well-formed, or else the build() * method will later report an U_ILLEGAL_ARGUMENT_ERROR. * * <p>The script value is a four-letter script code as * [unicode_script_subtag](http://www.unicode.org/reports/tr35/tr35.html#unicode_script_subtag) * defined by ISO 15924 * * @param script the script * @return This builder. * @draft ICU 64 */ LocaleBuilder& setScript(StringPiece script); /** * Sets the region. If region is the empty string, the region in this * <code>LocaleBuilder</code> is removed. Otherwise, the <code>region</code> * must be well-formed, or else the build() method will later report an * U_ILLEGAL_ARGUMENT_ERROR. * * <p>The region value is defined by * [unicode_region_subtag](http://www.unicode.org/reports/tr35/tr35.html#unicode_region_subtag) * as a two-letter ISO 3166 code or a three-digit UN M.49 area code. * * <p>The region value in the <code>Locale</code> created by the * <code>LocaleBuilder</code> is always normalized to upper case. * * @param region the region * @return This builder. * @draft ICU 64 */ LocaleBuilder& setRegion(StringPiece region); /** * Sets the variant. If variant is the empty string, the variant in this * <code>LocaleBuilder</code> is removed. Otherwise, the <code>variant</code> * must be well-formed, or else the build() method will later report an * U_ILLEGAL_ARGUMENT_ERROR. * * <p><b>Note:</b> This method checks if <code>variant</code> * satisfies the * [unicode_variant_subtag](http://www.unicode.org/reports/tr35/tr35.html#unicode_variant_subtag) * syntax requirements, and normalizes the value to lowercase letters. However, * the <code>Locale</code> class does not impose any syntactic * restriction on variant. To set an ill-formed variant, use a Locale constructor. * If there are multiple unicode_variant_subtag, the caller must concatenate * them with '-' as separator (ex: "foobar-fibar"). * * @param variant the variant * @return This builder. * @draft ICU 64 */ LocaleBuilder& setVariant(StringPiece variant); /** * Sets the extension for the given key. If the value is the empty string, * the extension is removed. Otherwise, the <code>key</code> and * <code>value</code> must be well-formed, or else the build() method will * later report an U_ILLEGAL_ARGUMENT_ERROR. * * <p><b>Note:</b> The key ('u') is used for the Unicode locale extension. * Setting a value for this key replaces any existing Unicode locale key/type * pairs with those defined in the extension. * * <p><b>Note:</b> The key ('x') is used for the private use code. To be * well-formed, the value for this key needs only to have subtags of one to * eight alphanumeric characters, not two to eight as in the general case. * * @param key the extension key * @param value the extension value * @return This builder. * @draft ICU 64 */ LocaleBuilder& setExtension(char key, StringPiece value); /** * Sets the Unicode locale keyword type for the given key. If the type * StringPiece is constructed with a nullptr, the keyword is removed. * If the type is the empty string, the keyword is set without type subtags. * Otherwise, the key and type must be well-formed, or else the build() * method will later report an U_ILLEGAL_ARGUMENT_ERROR. * * <p>Keys and types are converted to lower case. * * <p><b>Note</b>:Setting the 'u' extension via {@link #setExtension} * replaces all Unicode locale keywords with those defined in the * extension. * * @param key the Unicode locale key * @param type the Unicode locale type * @return This builder. * @draft ICU 64 */ LocaleBuilder& setUnicodeLocaleKeyword( StringPiece key, StringPiece type); /** * Adds a unicode locale attribute, if not already present, otherwise * has no effect. The attribute must not be empty string and must be * well-formed or U_ILLEGAL_ARGUMENT_ERROR will be set to status * during the build() call. * * @param attribute the attribute * @return This builder. * @draft ICU 64 */ LocaleBuilder& addUnicodeLocaleAttribute(StringPiece attribute); /** * Removes a unicode locale attribute, if present, otherwise has no * effect. The attribute must not be empty string and must be well-formed * or U_ILLEGAL_ARGUMENT_ERROR will be set to status during the build() call. * * <p>Attribute comparison for removal is case-insensitive. * * @param attribute the attribute * @return This builder. * @draft ICU 64 */ LocaleBuilder& removeUnicodeLocaleAttribute(StringPiece attribute); /** * Resets the builder to its initial, empty state. * <p>This method clears the internal UErrorCode. * * @return this builder * @draft ICU 64 */ LocaleBuilder& clear(); /** * Resets the extensions to their initial, empty state. * Language, script, region and variant are unchanged. * * @return this builder * @draft ICU 64 */ LocaleBuilder& clearExtensions(); /** * Returns an instance of <code>Locale</code> created from the fields set * on this builder. * If any set methods or during the build() call require memory allocation * but fail U_MEMORY_ALLOCATION_ERROR will be set to status. * If any of the fields set by the setters are not well-formed, the status * will be set to U_ILLEGAL_ARGUMENT_ERROR. The state of the builder will * not change after the build() call and the caller is free to keep using * the same builder to build more locales. * * @return a new Locale * @draft ICU 64 */ Locale build(UErrorCode& status); private: UErrorCode status_; char language_[9]; char script_[5]; char region_[4]; CharString *variant_; // Pointer not object so we need not #include internal charstr.h. icu::Locale *extensions_; // Pointer not object. Storage for all other fields. }; U_NAMESPACE_END #endif // U_HIDE_DRAFT_API #endif // __LOCALEBUILDER_H__
schmitzn/node-packer
node/deps/icu-small/source/i18n/rbt.h
<reponame>schmitzn/node-packer // © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ********************************************************************** * Copyright (C) 1999-2007, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * Date Name Description * 11/17/99 aliu Creation. ********************************************************************** */ #ifndef RBT_H #define RBT_H #include "unicode/utypes.h" #if !UCONFIG_NO_TRANSLITERATION #include "unicode/translit.h" #include "unicode/utypes.h" #include "unicode/parseerr.h" #include "unicode/udata.h" #define U_ICUDATA_TRANSLIT U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "translit" U_NAMESPACE_BEGIN class TransliterationRuleData; /** * <code>RuleBasedTransliterator</code> is a transliterator * built from a set of rules as defined for * Transliterator::createFromRules(). * See the C++ class Transliterator documentation for the rule syntax. * * @author <NAME> * @internal Use transliterator factory methods instead since this class will be removed in that release. */ class RuleBasedTransliterator : public Transliterator { private: /** * The data object is immutable, so we can freely share it with * other instances of RBT, as long as we do NOT own this object. * TODO: data is no longer immutable. See bugs #1866, 2155 */ TransliterationRuleData* fData; /** * If true, we own the data object and must delete it. */ UBool isDataOwned; public: /** * Constructs a new transliterator from the given rules. * @param rules rules, separated by ';' * @param direction either FORWARD or REVERSE. * @exception IllegalArgumentException if rules are malformed. * @internal Use transliterator factory methods instead since this class will be removed in that release. */ RuleBasedTransliterator(const UnicodeString& id, const UnicodeString& rules, UTransDirection direction, UnicodeFilter* adoptedFilter, UParseError& parseError, UErrorCode& status); /** * Constructs a new transliterator from the given rules. * @param rules rules, separated by ';' * @param direction either FORWARD or REVERSE. * @exception IllegalArgumentException if rules are malformed. * @internal Use transliterator factory methods instead since this class will be removed in that release. */ /*RuleBasedTransliterator(const UnicodeString& id, const UnicodeString& rules, UTransDirection direction, UnicodeFilter* adoptedFilter, UErrorCode& status);*/ /** * Covenience constructor with no filter. * @internal Use transliterator factory methods instead since this class will be removed in that release. */ /*RuleBasedTransliterator(const UnicodeString& id, const UnicodeString& rules, UTransDirection direction, UErrorCode& status);*/ /** * Covenience constructor with no filter and FORWARD direction. * @internal Use transliterator factory methods instead since this class will be removed in that release. */ /*RuleBasedTransliterator(const UnicodeString& id, const UnicodeString& rules, UErrorCode& status);*/ /** * Covenience constructor with FORWARD direction. * @internal Use transliterator factory methods instead since this class will be removed in that release. */ /*RuleBasedTransliterator(const UnicodeString& id, const UnicodeString& rules, UnicodeFilter* adoptedFilter, UErrorCode& status);*/ private: friend class TransliteratorRegistry; // to access TransliterationRuleData convenience ctor /** * Covenience constructor. * @param id the id for the transliterator. * @param theData the rule data for the transliterator. * @param adoptedFilter the filter for the transliterator */ RuleBasedTransliterator(const UnicodeString& id, const TransliterationRuleData* theData, UnicodeFilter* adoptedFilter = 0); friend class Transliterator; // to access following ct /** * Internal constructor. * @param id the id for the transliterator. * @param theData the rule data for the transliterator. * @param isDataAdopted determine who will own the 'data' object. True, the caller should not delete 'data'. */ RuleBasedTransliterator(const UnicodeString& id, TransliterationRuleData* data, UBool isDataAdopted); public: /** * Copy constructor. * @internal Use transliterator factory methods instead since this class will be removed in that release. */ RuleBasedTransliterator(const RuleBasedTransliterator&); virtual ~RuleBasedTransliterator(); /** * Implement Transliterator API. * @internal Use transliterator factory methods instead since this class will be removed in that release. */ virtual Transliterator* clone(void) const; protected: /** * Implements {@link Transliterator#handleTransliterate}. * @internal Use transliterator factory methods instead since this class will be removed in that release. */ virtual void handleTransliterate(Replaceable& text, UTransPosition& offsets, UBool isIncremental) const; public: /** * Return a representation of this transliterator as source rules. * These rules will produce an equivalent transliterator if used * to construct a new transliterator. * @param result the string to receive the rules. Previous * contents will be deleted. * @param escapeUnprintable if TRUE then convert unprintable * character to their hex escape representations, \uxxxx or * \Uxxxxxxxx. Unprintable characters are those other than * U+000A, U+0020..U+007E. * @internal Use transliterator factory methods instead since this class will be removed in that release. */ virtual UnicodeString& toRules(UnicodeString& result, UBool escapeUnprintable) const; protected: /** * Implement Transliterator framework */ virtual void handleGetSourceSet(UnicodeSet& result) const; public: /** * Override Transliterator framework */ virtual UnicodeSet& getTargetSet(UnicodeSet& result) const; /** * Return the class ID for this class. This is useful only for * comparing to a return value from getDynamicClassID(). For example: * <pre> * . Base* polymorphic_pointer = createPolymorphicObject(); * . if (polymorphic_pointer->getDynamicClassID() == * . Derived::getStaticClassID()) ... * </pre> * @return The class ID for all objects of this class. * @internal Use transliterator factory methods instead since this class will be removed in that release. */ U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void); /** * Returns a unique class ID <b>polymorphically</b>. This method * is to implement a simple version of RTTI, since not all C++ * compilers support genuine RTTI. Polymorphic operator==() and * clone() methods call this method. * * @return The class ID for this object. All objects of a given * class have the same class ID. Objects of other classes have * different class IDs. */ virtual UClassID getDynamicClassID(void) const; private: void _construct(const UnicodeString& rules, UTransDirection direction, UParseError& parseError, UErrorCode& status); }; U_NAMESPACE_END #endif /* #if !UCONFIG_NO_TRANSLITERATION */ #endif