Permalink
Browse files

added CallAPI + AddressAPI

  • Loading branch information...
1 parent d10b285 commit 2c6383181ccc848e46e7303e22d40f4ebcc78a7f @juzna committed May 20, 2011
Showing with 265 additions and 33 deletions.
  1. +89 −0 AddressAPI.cpp
  2. +42 −0 AddressAPI.h
  3. +74 −0 CallAPI.cpp
  4. +38 −0 CallAPI.h
  5. +5 −0 helpers/class.sh
  6. +5 −22 linphoneAPI.cpp
  7. +10 −9 linphoneAPI.h
  8. +2 −2 make.sh
View
@@ -0,0 +1,89 @@
+#include "JSObject.h"
+#include "variant_list.h"
+#include "DOM/Document.h"
+
+#include "AddressAPI.h"
+// #include "common.h"
+#include "lock.h"
+
+
+
+#define mmethod(name) make_method(this, &AddressAPI::name)
+#define rmethod(name) registerMethod(#name, make_method(this, &AddressAPI::call_##name))
+#define rmethod2(name, func) registerMethod(#name, make_method(this, &AddressAPI::call_##func))
+#define rproperty(name) registerProperty(#name, make_property(this, &AddressAPI::get_##name, &AddressAPI::set_##name))
+#define rpropertyg(name) registerProperty(#name, make_property(this, &AddressAPI::get_##name))
+
+
+
+AddressAPI::AddressAPI(const FB::BrowserHostPtr& host, LinphoneAddress *address, bool isOwner)
+ : m_host(host), _address(address), _isOwner(isOwner)
+{
+ printf("AddressAPI instance: %u\n", (void *) address);
+
+ // Register exported methods
+ rmethod(toString);
+
+ // Register properties
+ rproperty(scheme);
+ rproperty(displayName);
+ rproperty(username);
+ rproperty(domain);
+ rproperty(port);
+}
+
+AddressAPI::~AddressAPI()
+{
+ printf("deallocating AddressAPI instance\n");
+ if(_isOwner) linphone_address_destroy(_address);
+}
+
+// Scheme
+std::string AddressAPI::get_scheme(void) {
+ return linphone_address_get_scheme(_address);
+}
+
+void AddressAPI::set_scheme(std::string scheme) {
+ // linphone_address_set_scheme(_address, scheme.c_str());
+}
+
+// Display mane
+std::string AddressAPI::get_displayName(void) {
+ return linphone_address_get_display_name(_address);
+}
+
+void AddressAPI::set_displayName(std::string name) {
+ linphone_address_set_display_name(_address, name.c_str());
+}
+
+// Username
+std::string AddressAPI::get_username(void) {
+ return linphone_address_get_username(_address);
+}
+
+void AddressAPI::set_username(std::string username) {
+ linphone_address_set_username(_address, username.c_str());
+}
+
+// domain
+std::string AddressAPI::get_domain(void) {
+ return linphone_address_get_domain(_address);
+}
+
+void AddressAPI::set_domain(std::string domain) {
+ linphone_address_set_domain(_address, domain.c_str());
+}
+
+// Port
+int AddressAPI::get_port(void) {
+ return linphone_address_get_port_int(_address);
+}
+
+void AddressAPI::set_port(int port) {
+ linphone_address_set_port_int(_address, port);
+}
+
+// toString
+std::string AddressAPI::call_toString(void) {
+ return linphone_address_as_string(_address);
+}
View
@@ -0,0 +1,42 @@
+#include <string>
+#include <sstream>
+#include "JSAPIAuto.h"
+#include "BrowserHostWrapper.h"
+
+#ifndef H_AddressAPI
+#define H_AddressAPI
+
+#include "linphoneAPI.h"
+
+
+class AddressAPI : public FB::JSAPIAuto
+{
+public:
+ AddressAPI(const FB::BrowserHostPtr& host, LinphoneAddress*, bool);
+ virtual ~AddressAPI();
+
+ // Exported methods
+ std::string call_toString(void);
+
+ // Property manipulation methods
+ std::string get_scheme(void);
+ void set_scheme(std::string);
+ std::string get_displayName(void);
+ void set_displayName(std::string);
+ std::string get_username(void);
+ void set_username(std::string);
+ std::string get_domain(void);
+ void set_domain(std::string);
+ int get_port(void);
+ void set_port(int);
+
+private:
+ linphoneWeakPtr m_plugin;
+ FB::BrowserHostPtr m_host;
+ bool _isOwner; // Whether we're owner of LinphoneAddress memory
+ LinphoneAddress *_address;
+
+};
+
+#endif // H_AddressAPI
+
View
@@ -0,0 +1,74 @@
+#include "JSObject.h"
+#include "variant_list.h"
+#include "DOM/Document.h"
+
+#include "CallAPI.h"
+// #include "common.h"
+#include "lock.h"
+
+
+
+#define mmethod(name) make_method(this, &CallAPI::name)
+#define rmethod(name) registerMethod(#name, make_method(this, &CallAPI::call_##name))
+#define rmethod2(name, func) registerMethod(#name, make_method(this, &CallAPI::call_##func))
+#define rproperty(name) registerProperty(#name, make_property(this, &CallAPI::get_##name, &CallAPI::set_##name))
+#define rpropertyg(name) registerProperty(#name, make_property(this, &CallAPI::get_##name))
+
+
+
+CallAPI::CallAPI(const FB::BrowserHostPtr& host, LinphoneCore **lin, LinphoneCall *call)
+ : m_host(host), _lin(lin), _call(call)
+{
+ printf("CallAPI instance: %u\n", (void *) call);
+
+ // Register exported methods
+ rmethod(accept);
+ rmethod(terminate);
+ rmethod(resume);
+ rmethod(pause);
+
+ // Register properties
+ rpropertyg(state);
+ rpropertyg(reason);
+ rpropertyg(duration);
+ rpropertyg(paused);
+}
+
+CallAPI::~CallAPI()
+{
+ printf("deallocating CallAPI instance\n");
+}
+
+bool CallAPI::call_accept(void) {
+ return linphone_core_accept_call(*_lin, _call);
+}
+
+bool CallAPI::call_terminate(void) {
+ return linphone_core_terminate_call(*_lin, _call);
+}
+
+bool CallAPI::call_pause(void) {
+ return linphone_core_pause_call(*_lin, _call);
+}
+
+bool CallAPI::call_resume(void) {
+ return linphone_core_resume_call(*_lin, _call);
+}
+
+// Property manipulation methods
+int CallAPI::get_state(void) {
+ return linphone_call_get_state(_call);
+}
+
+int CallAPI::get_reason(void) {
+ return linphone_call_get_reason(_call);
+}
+
+int CallAPI::get_duration(void) {
+ return linphone_call_get_duration(_call);
+}
+
+bool CallAPI::get_paused(void) {
+ return linphone_call_get_state(_call) == LinphoneCallPaused;
+}
+
View
@@ -0,0 +1,38 @@
+#include <string>
+#include <sstream>
+#include "JSAPIAuto.h"
+#include "BrowserHostWrapper.h"
+
+#ifndef H_CallAPI
+#define H_CallAPI
+
+#include "linphoneAPI.h"
+
+
+class CallAPI : public FB::JSAPIAuto
+{
+public:
+ CallAPI(const FB::BrowserHostPtr&, LinphoneCore **, LinphoneCall*);
+ virtual ~CallAPI();
+
+ // Exported methods
+ bool call_accept(void);
+ bool call_terminate(void);
+ bool call_pause(void);
+ bool call_resume(void);
+
+ // Property manipulation methods
+ int get_state(void);
+ int get_reason(void);
+ int get_duration(void);
+ bool get_paused(void);
+
+private:
+ linphoneWeakPtr m_plugin;
+ FB::BrowserHostPtr m_host;
+
+ LinphoneCore **_lin;
+ LinphoneCall *_call;
+};
+
+#endif // H_CallAPI
View
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+X=$1
+cat sampleAPI.h | sed s/sampleAPI/${X}API/g > ${X}API.h
+cat sampleAPI.cpp | sed s/sampleAPI/${X}API/g > ${X}API.cpp
View
@@ -43,6 +43,10 @@ linphoneAPI::linphoneAPI(const linphonePtr& plugin, const FB::BrowserHostPtr& ho
rpropertyg(running);
rpropertyg(registered);
rpropertyg(sample);
+ rpropertyg(inCall);
+ rproperty(videoEnabled);
+ rproperty(videoPreviewEnabled);
+
// Initialize mutex
pthread_mutex_init(&mutex, NULL);
@@ -291,7 +295,7 @@ bool linphoneAPI::call_call(std::string uri) {
FB::JSAPIPtr linphoneAPI::get_sample(void) {
// Create instance if not yet exists
if(!_sample.use_count()) {
- _sample.reset(new sampleAPI(m_host));
+ _sample = boost::make_shared<sampleAPI>(m_host); //reset(new sampleAPI(m_host));
}
return _sample;
@@ -300,22 +304,6 @@ FB::JSAPIPtr linphoneAPI::get_sample(void) {
/*
-// Read/Write property testString
-std::string linphoneAPI::get_testString()
-{
- return m_testString;
-}
-void linphoneAPI::set_testString(const std::string& val)
-{
- m_testString = val;
-}
-
-// Read-only property version
-std::string linphoneAPI::get_version()
-{
- return "CURRENT_VERSION";
-}
-
// Method echo
FB::variant linphoneAPI::echo(const FB::variant& msg)
{
@@ -324,10 +312,5 @@ FB::variant linphoneAPI::echo(const FB::variant& msg)
return msg;
}
-void linphoneAPI::testEvent(const FB::variant& var)
-{
- fire_fired(var, true, 1);
-}
-
*/
View
@@ -18,6 +18,10 @@
#ifndef H_linphoneAPI
#define H_linphoneAPI
+#include "lock.h"
+#define Lo Lock lck(&mutex, NULL);
+
+
class linphoneAPI : public FB::JSAPIAuto
{
public:
@@ -40,6 +44,11 @@ class linphoneAPI : public FB::JSAPIAuto
bool get_running(void);
bool get_registered(void);
FB::JSAPIPtr get_sample(void);
+ bool get_inCall(void) { Lo; return linphone_core_in_call(lin); }
+ bool get_videoEnabled(void) { Lo; return linphone_core_video_enabled(lin); }
+ void set_videoEnabled(bool x) { Lo; linphone_core_enable_video(lin, x, x); }
+ bool get_videoPreviewEnabled(void) { Lo; return linphone_core_video_preview_enabled(lin); }
+ void set_videoPreviewEnabled(bool x) { Lo; linphone_core_enable_video_preview(lin, x); }
void lock() { pthread_mutex_lock(&mutex); }
@@ -49,12 +58,6 @@ class linphoneAPI : public FB::JSAPIAuto
/*
- // Read/Write property ${PROPERTY.ident}
- std::string get_testString();
- void set_testString(const std::string& val);
-
- // Read-only property ${PROPERTY.ident}
- std::string get_version();
// Method echo
FB::variant echo(const FB::variant& msg);
@@ -63,9 +66,7 @@ class linphoneAPI : public FB::JSAPIAuto
FB_JSAPI_EVENT(fired, 3, (const FB::variant&, bool, int));
FB_JSAPI_EVENT(echo, 2, (const FB::variant&, const int));
FB_JSAPI_EVENT(notify, 0, ());
-
- // Method test-event
- void testEvent(const FB::variant& s); */
+*/
private:
linphoneWeakPtr m_plugin;
View
@@ -1,8 +1,8 @@
#!/bin/bash
cd ../../;
-#./prepmake.sh;
+./prepmake.sh;
cd build;
make linphone
-cp ./bin/linphone/nplinphone.so /home/juzna/.mozilla/plugins/
+#cp ./bin/linphone/nplinphone.so /home/juzna/.mozilla/plugins/

0 comments on commit 2c63831

Please sign in to comment.