首页编程cubieboard(什么是cubieboard)

cubieboard(什么是cubieboard)

编程之家2024-06-127次浏览

一、怎么开发android framework

一.认识android的架构

cubieboard(什么是cubieboard)

Android其本质就是在标准的Linux系统上增加了Java虚拟机Dalvik,并在Dalvik虚拟机上搭建了一个JAVA的application framework,所有的应用程序都是基于JAVA的application framework之上。

android分为四个层,从高层到低层分别是应用程序层、应用程序框架层、系统运行库层和linux核心层。

二.搭建环境

搭建开发环境

对国内的开发者来说最痛苦的是无法去访问android开发网站。为了更好的认识世界,对程序员来说,会翻墙也是的一门技术,带你去领略墙外的世界,好了,不废话了,国内开发者访问(androiddevtools)上面已经有了所有你要的资源,同时可以下载到我们的主角framework

但是这样的搭建只能去阅读源代码,我们无法去更进一步去实现自己的rom,我们看到锤子的系统在早期的开放rom是自己从新实现了framework的代码,现在看起来他成功了,所以我们还要去搭建android系统的源码编译环境。

cubieboard(什么是cubieboard)

搭建源码编译环境

(这里详细的介绍了如何下载编译)

三.开始主题

在一开始写c程序的时候都有一个运行的入口,比如

#include<iostream>

cubieboard(什么是cubieboard)

#include<cmath>

#include<algorithm>

using namespace std;

//这里的main就是应用的入口

int main(int argc, const char* argv[]){

return 0;

}

在计算机网络原理中我们用socket实现一个服务器端,不断的接听客户端的访问,而且他的代码是这样实现的:

#include<winsock2.h>

#pragma comment(lib,"WS2_32.lib")

#include<stdio.h>

void main()

{

WORD wVersionRequested;//版本号

WSADATA wsaData;

int err;

wVersionRequested= MAKEWORD(2, 2);//2.2版本的套接字

//加载套接字库,如果失败返回

err= WSAStartup(wVersionRequested,&wsaData);

if(err!= 0)

{

return;

}

//判断高低字节是不是2,如果不是2.2的版本则退出

if(LOBYTE(wsaData.wVersion)!= 2||

HIBYTE(wsaData.wVersion)!= 2)

{

return;

}

//创建流式套接字,基于TCP(SOCK_STREAM)

SOCKET socSrv= socket(AF_INET, SOCK_STREAM, 0);

//Socket地址结构体的创建

SOCKADDR_IN addrSrv;

addrSrv.sin_addr.S_un.S_addr= htonl(INADDR_ANY);//转换Unsigned long型为网络字节序格

addrSrv.sin_family= AF_INET;//指定地址簇

addrSrv.sin_port= htons(6000);

//指定端口号,除sin_family参数外,其它参数都是网络字节序,因此需要转换

//将套接字绑定到一个端口号和本地地址上

bind(socSrv,(SOCKADDR*)&addrSrv, sizeof(SOCKADDR));//必须用sizeof,strlen不行

listen(socSrv, 5);

SOCKADDR_IN addrClient;//字义用来接收客户端Socket的结构体

int len= sizeof(SOCKADDR);//初始化参数,这个参数必须进行初始化,sizeof

//循环等待接受客户端发送请求

while(1)

{

//等待客户请求到来;当请求到来后,接受连接请求,

//返回一个新的对应于此次连接的套接字(accept)。

//此时程序在此发生阻塞

SOCKET sockConn= accept(socSrv,(SOCKADDR*)&addrClient,&len);

char sendBuf[100];

sprintf(sendBuf,"Welcome%s to JoyChou",

inet_ntoa(addrClient.sin_addr));//格式化输出

//用返回的套接字和客户端进行通信

send(sockConn, sendBuf, strlen(sendBuf)+1, 0);//多发送一个字节

//接收数据

char recvBuf[100];

recv(sockConn, recvBuf, 100, 0);

printf("%s\\n", recvBuf);

closesocket(sockConn);

}

}

他采用了一个while死循环去监听客户端的请求。

在一遍啰嗦之后,主角终于闪亮的登场了。

先上源代码

public final class ActivityThread{

public static void main(String[] args){

SamplingProfilerIntegration.start();

CloseGuard.setEnabled(false);

Environment.initForCurrentUser();

EventLogger.setReporter(new EventLoggingReporter());

Security.addProvider(new AndroidKeyStoreProvider());

final File configDir= Environment.getUserConfigDirectory(UserHandle.myUserId());

TrustedCertificateStore.setDefaultUserDirectory(configDir);

Process.setArgV0("<pre-initialized>");

Looper.prepareMainLooper();

//从中可以看到为app开辟了一个线程进入了looper之中

ActivityThread thread= new ActivityThread();

thread.attach(false);

if(sMainThreadHandler== null){

sMainThreadHandler= thread.getHandler();

}

AsyncTask.init();

if(false){

Looper.myLooper().setMessageLogging(new

LogPrinter(Log.DEBUG,"ActivityThread"));

}

Looper.loop();

throw new RuntimeException("Main thread loop unexpectedly exited");

}

}

看到源码失望了,没有一个while循环啊,其实用了他方法实现

//用一个looper的机制循环监听响应

Looper.prepareMainLooper();

Looper.loop();

进一步深入代码

public static void loop(){

final Looper me= myLooper();

if(me== null){

throw new RuntimeException("No Looper; Looper.prepare() wasn't called on this thread.");

}

final MessageQueue queue= me.mQueue;

Binder.clearCallingIdentity();

final long ident= Binder.clearCallingIdentity();

//在这里看到了一个循环监听消息

for(;;){

Message msg= queue.next();// might block

if(msg== null){

// No message indicates that the message queue is quitting.

return;

}

Printer logging= me.mLogging;

if(logging!= null){

logging.println(">>>>> Dispatching to"+ msg.target+""+

msg.callback+":"+ msg.what);

}

msg.target.dispatchMessage(msg);

if(logging!= null){

logging.println("<<<<< Finished to"+ msg.target+""+ msg.callback);

}

// Make sure that during the course of dispatching the

// identity of the thread wasn't corrupted.

final long newIdent= Binder.clearCallingIdentity();

if(ident!= newIdent){

Log.wtf(TAG,"Thread identity changed from 0x"

+ Long.toHexString(ident)+" to 0x"

+ Long.toHexString(newIdent)+" while dispatching to"

+ msg.target.getClass().getName()+""

+ msg.callback+" what="+ msg.what);

}

msg.recycleUnchecked();

}

}

二、树莓派和cubieboard3哪个好

这个东西怎么说呢,如果你买了树莓派,因为玩家多,软件一直在升级。可玩性高。

如果是cubieboard也许性能会好些。至少可以流畅的跑android,不过后面很多硬件支持你需要自己写软件,固难多。

我买了树莓派后,曾经想找一款速度更快的,也调查过cubieboard,后来发现都不能达到我的要求。

其实如果你在树莓派里使用risc os,速度还是很快的。就是软件少了很多。

好记星电子词典(好记星电子词典)诺基亚 6680(诺基亚6680好不好用)